Skip to content

Commit f8072a8

Browse files
committed
Build: Added node 8 support.
1 parent 4306b35 commit f8072a8

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

misc/admin/lib/cmds/hoist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const log_1 = require("../log");
1717
const dependencies = local_1.getDependencies(null, (name) => {
1818
return !path_1.isEthers(name);
1919
});
20-
console.log(log_1.colorify.bold(`Hoisting ${dependencies.length} dependencies into root package...`));
20+
console.log(log_1.colorify.bold(`Hoisting ${Object.keys(dependencies).length} dependencies into root package...`));
2121
local_1.updateJson(path_1.dirs.rootPackageJsonPath, { dependencies });
2222
});
2323
})().catch((error) => {

misc/admin/lib/cmds/link.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const path_1 = require("path");
1717
const local_1 = require("../local");
1818
const log_1 = require("../log");
1919
const path_2 = require("../path");
20+
const utils_1 = require("../utils");
2021
function link(existing, path) {
2122
try {
2223
const current = fs_1.default.readlinkSync(path);
@@ -33,7 +34,7 @@ function link(existing, path) {
3334
}
3435
// Link
3536
const dir = path_1.dirname(path);
36-
fs_1.default.mkdirSync(dir, { recursive: true });
37+
utils_1.mkdir(dir);
3738
fs_1.default.symlinkSync(existing, path);
3839
}
3940
(function () {
@@ -46,7 +47,7 @@ function link(existing, path) {
4647
link(path_2.getPackagePath(name), path_1.resolve(path_2.dirs.root, "node_modules", name));
4748
// e.g. /packages/abi/node_modules => /.package_node_modules/abi/
4849
const nodeModules = path_1.resolve(nodeModulesBase, path_2.getDirname(name));
49-
fs_1.default.mkdirSync(nodeModules, { recursive: true });
50+
utils_1.mkdir(nodeModules);
5051
link(nodeModules, path_1.resolve(path_2.getPackagePath(name), "node_modules"));
5152
});
5253
path_2.packages.forEach((name) => {

misc/admin/lib/utils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export declare function atomicWrite(path: string, value: string | Uint8Array): v
66
export declare function loadJson(path: string): any;
77
export declare function saveJson(filename: string, data: any, sort?: boolean): any;
88
export declare function resolveProperties(props: Record<string, Promise<any>>): Promise<Record<string, any>>;
9+
export declare function mkdir(path: string): void;

misc/admin/lib/utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,22 @@ function resolveProperties(props) {
8383
});
8484
}
8585
exports.resolveProperties = resolveProperties;
86+
// Node 8 does not support recursive mkdir... Remove this in v6.
87+
function mkdir(path) {
88+
let bail = 0;
89+
const dirs = [];
90+
while (path !== "/") {
91+
if (bail++ > 50) {
92+
throw new Error("something bad happened...");
93+
}
94+
if (fs_1.default.existsSync(path)) {
95+
break;
96+
}
97+
dirs.push(path);
98+
path = path_1.dirname(path);
99+
}
100+
while (dirs.length) {
101+
fs_1.default.mkdirSync(dirs.pop());
102+
}
103+
}
104+
exports.mkdir = mkdir;

misc/admin/src.ts/cmds/hoist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { colorify } from "../log";
88
return !isEthers(name);
99
});
1010

11-
console.log(colorify.bold(`Hoisting ${ dependencies.length } dependencies into root package...`));
11+
console.log(colorify.bold(`Hoisting ${ Object.keys(dependencies).length } dependencies into root package...`));
1212

1313
updateJson(dirs.rootPackageJsonPath, { dependencies });
1414
})().catch((error) => {

misc/admin/src.ts/cmds/link.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { dirname, resolve } from "path";
44
import { getDependencies } from "../local";
55
import { colorify } from "../log";
66
import { dirs, getDirname, getPackagePath, packages } from "../path";
7+
import { mkdir } from "../utils";
78

89
function link(existing: string, path: string): void {
910
try {
@@ -19,7 +20,7 @@ function link(existing: string, path: string): void {
1920

2021
// Link
2122
const dir = dirname(path);
22-
fs.mkdirSync(dir, { recursive: true });
23+
mkdir(dir);
2324
fs.symlinkSync(existing, path);
2425
}
2526

@@ -36,7 +37,7 @@ function link(existing: string, path: string): void {
3637

3738
// e.g. /packages/abi/node_modules => /.package_node_modules/abi/
3839
const nodeModules = resolve(nodeModulesBase, getDirname(name));
39-
fs.mkdirSync(nodeModules, { recursive: true });
40+
mkdir(nodeModules);
4041
link(nodeModules, resolve(getPackagePath(name), "node_modules"));
4142
});
4243

misc/admin/src.ts/utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "fs";
2-
import { resolve } from "path";
2+
import { dirname, resolve } from "path";
33

44
import { createHash } from "crypto";
55

@@ -66,3 +66,20 @@ export async function resolveProperties(props: Record<string, Promise<any>>): Pr
6666
return accum;
6767
}, <Record<string, any>>{});
6868
}
69+
70+
// Node 8 does not support recursive mkdir... Remove this in v6.
71+
export function mkdir(path: string): void {
72+
let bail = 0;
73+
const dirs = [ ];
74+
while (path !== "/") {
75+
if (bail++ > 50) { throw new Error("something bad happened..."); }
76+
77+
if (fs.existsSync(path)) { break; }
78+
dirs.push(path);
79+
path = dirname(path);
80+
}
81+
82+
while (dirs.length) {
83+
fs.mkdirSync(dirs.pop());
84+
}
85+
}

0 commit comments

Comments
 (0)