From f8072a8004370ae5c008732e54685c642c6eb632 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Wed, 23 Sep 2020 00:23:02 -0400 Subject: [PATCH] Build: Added node 8 support. --- misc/admin/lib/cmds/hoist.js | 2 +- misc/admin/lib/cmds/link.js | 5 +++-- misc/admin/lib/utils.d.ts | 1 + misc/admin/lib/utils.js | 19 +++++++++++++++++++ misc/admin/src.ts/cmds/hoist.ts | 2 +- misc/admin/src.ts/cmds/link.ts | 5 +++-- misc/admin/src.ts/utils.ts | 19 ++++++++++++++++++- 7 files changed, 46 insertions(+), 7 deletions(-) diff --git a/misc/admin/lib/cmds/hoist.js b/misc/admin/lib/cmds/hoist.js index 7cba2f087..fa25ef9c2 100644 --- a/misc/admin/lib/cmds/hoist.js +++ b/misc/admin/lib/cmds/hoist.js @@ -17,7 +17,7 @@ const log_1 = require("../log"); const dependencies = local_1.getDependencies(null, (name) => { return !path_1.isEthers(name); }); - console.log(log_1.colorify.bold(`Hoisting ${dependencies.length} dependencies into root package...`)); + console.log(log_1.colorify.bold(`Hoisting ${Object.keys(dependencies).length} dependencies into root package...`)); local_1.updateJson(path_1.dirs.rootPackageJsonPath, { dependencies }); }); })().catch((error) => { diff --git a/misc/admin/lib/cmds/link.js b/misc/admin/lib/cmds/link.js index b9f58ded1..0030fd017 100644 --- a/misc/admin/lib/cmds/link.js +++ b/misc/admin/lib/cmds/link.js @@ -17,6 +17,7 @@ const path_1 = require("path"); const local_1 = require("../local"); const log_1 = require("../log"); const path_2 = require("../path"); +const utils_1 = require("../utils"); function link(existing, path) { try { const current = fs_1.default.readlinkSync(path); @@ -33,7 +34,7 @@ function link(existing, path) { } // Link const dir = path_1.dirname(path); - fs_1.default.mkdirSync(dir, { recursive: true }); + utils_1.mkdir(dir); fs_1.default.symlinkSync(existing, path); } (function () { @@ -46,7 +47,7 @@ function link(existing, path) { link(path_2.getPackagePath(name), path_1.resolve(path_2.dirs.root, "node_modules", name)); // e.g. /packages/abi/node_modules => /.package_node_modules/abi/ const nodeModules = path_1.resolve(nodeModulesBase, path_2.getDirname(name)); - fs_1.default.mkdirSync(nodeModules, { recursive: true }); + utils_1.mkdir(nodeModules); link(nodeModules, path_1.resolve(path_2.getPackagePath(name), "node_modules")); }); path_2.packages.forEach((name) => { diff --git a/misc/admin/lib/utils.d.ts b/misc/admin/lib/utils.d.ts index 0dd62baaf..317cd3bf9 100644 --- a/misc/admin/lib/utils.d.ts +++ b/misc/admin/lib/utils.d.ts @@ -6,3 +6,4 @@ export declare function atomicWrite(path: string, value: string | Uint8Array): v export declare function loadJson(path: string): any; export declare function saveJson(filename: string, data: any, sort?: boolean): any; export declare function resolveProperties(props: Record>): Promise>; +export declare function mkdir(path: string): void; diff --git a/misc/admin/lib/utils.js b/misc/admin/lib/utils.js index 77109d646..ac605af9d 100644 --- a/misc/admin/lib/utils.js +++ b/misc/admin/lib/utils.js @@ -83,3 +83,22 @@ function resolveProperties(props) { }); } exports.resolveProperties = resolveProperties; +// Node 8 does not support recursive mkdir... Remove this in v6. +function mkdir(path) { + let bail = 0; + const dirs = []; + while (path !== "/") { + if (bail++ > 50) { + throw new Error("something bad happened..."); + } + if (fs_1.default.existsSync(path)) { + break; + } + dirs.push(path); + path = path_1.dirname(path); + } + while (dirs.length) { + fs_1.default.mkdirSync(dirs.pop()); + } +} +exports.mkdir = mkdir; diff --git a/misc/admin/src.ts/cmds/hoist.ts b/misc/admin/src.ts/cmds/hoist.ts index ff669f5cb..a5b8d1f4f 100644 --- a/misc/admin/src.ts/cmds/hoist.ts +++ b/misc/admin/src.ts/cmds/hoist.ts @@ -8,7 +8,7 @@ import { colorify } from "../log"; return !isEthers(name); }); - console.log(colorify.bold(`Hoisting ${ dependencies.length } dependencies into root package...`)); + console.log(colorify.bold(`Hoisting ${ Object.keys(dependencies).length } dependencies into root package...`)); updateJson(dirs.rootPackageJsonPath, { dependencies }); })().catch((error) => { diff --git a/misc/admin/src.ts/cmds/link.ts b/misc/admin/src.ts/cmds/link.ts index 282811ce8..11b095cef 100644 --- a/misc/admin/src.ts/cmds/link.ts +++ b/misc/admin/src.ts/cmds/link.ts @@ -4,6 +4,7 @@ import { dirname, resolve } from "path"; import { getDependencies } from "../local"; import { colorify } from "../log"; import { dirs, getDirname, getPackagePath, packages } from "../path"; +import { mkdir } from "../utils"; function link(existing: string, path: string): void { try { @@ -19,7 +20,7 @@ function link(existing: string, path: string): void { // Link const dir = dirname(path); - fs.mkdirSync(dir, { recursive: true }); + mkdir(dir); fs.symlinkSync(existing, path); } @@ -36,7 +37,7 @@ function link(existing: string, path: string): void { // e.g. /packages/abi/node_modules => /.package_node_modules/abi/ const nodeModules = resolve(nodeModulesBase, getDirname(name)); - fs.mkdirSync(nodeModules, { recursive: true }); + mkdir(nodeModules); link(nodeModules, resolve(getPackagePath(name), "node_modules")); }); diff --git a/misc/admin/src.ts/utils.ts b/misc/admin/src.ts/utils.ts index 89cde48a5..a5c6bb19e 100644 --- a/misc/admin/src.ts/utils.ts +++ b/misc/admin/src.ts/utils.ts @@ -1,5 +1,5 @@ import fs from "fs"; -import { resolve } from "path"; +import { dirname, resolve } from "path"; import { createHash } from "crypto"; @@ -66,3 +66,20 @@ export async function resolveProperties(props: Record>): Pr return accum; }, >{}); } + +// Node 8 does not support recursive mkdir... Remove this in v6. +export function mkdir(path: string): void { + let bail = 0; + const dirs = [ ]; + while (path !== "/") { + if (bail++ > 50) { throw new Error("something bad happened..."); } + + if (fs.existsSync(path)) { break; } + dirs.push(path); + path = dirname(path); + } + + while (dirs.length) { + fs.mkdirSync(dirs.pop()); + } +}