Build: Added node 8 support.

This commit is contained in:
Richard Moore 2020-09-23 00:23:02 -04:00
parent 4306b3563a
commit f8072a8004
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
7 changed files with 46 additions and 7 deletions

@ -17,7 +17,7 @@ const log_1 = require("../log");
const dependencies = local_1.getDependencies(null, (name) => { const dependencies = local_1.getDependencies(null, (name) => {
return !path_1.isEthers(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 }); local_1.updateJson(path_1.dirs.rootPackageJsonPath, { dependencies });
}); });
})().catch((error) => { })().catch((error) => {

@ -17,6 +17,7 @@ const path_1 = require("path");
const local_1 = require("../local"); const local_1 = require("../local");
const log_1 = require("../log"); const log_1 = require("../log");
const path_2 = require("../path"); const path_2 = require("../path");
const utils_1 = require("../utils");
function link(existing, path) { function link(existing, path) {
try { try {
const current = fs_1.default.readlinkSync(path); const current = fs_1.default.readlinkSync(path);
@ -33,7 +34,7 @@ function link(existing, path) {
} }
// Link // Link
const dir = path_1.dirname(path); const dir = path_1.dirname(path);
fs_1.default.mkdirSync(dir, { recursive: true }); utils_1.mkdir(dir);
fs_1.default.symlinkSync(existing, path); fs_1.default.symlinkSync(existing, path);
} }
(function () { (function () {
@ -46,7 +47,7 @@ function link(existing, path) {
link(path_2.getPackagePath(name), path_1.resolve(path_2.dirs.root, "node_modules", name)); 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/ // e.g. /packages/abi/node_modules => /.package_node_modules/abi/
const nodeModules = path_1.resolve(nodeModulesBase, path_2.getDirname(name)); 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")); link(nodeModules, path_1.resolve(path_2.getPackagePath(name), "node_modules"));
}); });
path_2.packages.forEach((name) => { path_2.packages.forEach((name) => {

@ -6,3 +6,4 @@ export declare function atomicWrite(path: string, value: string | Uint8Array): v
export declare function loadJson(path: string): any; export declare function loadJson(path: string): any;
export declare function saveJson(filename: string, data: any, sort?: boolean): any; export declare function saveJson(filename: string, data: any, sort?: boolean): any;
export declare function resolveProperties(props: Record<string, Promise<any>>): Promise<Record<string, any>>; export declare function resolveProperties(props: Record<string, Promise<any>>): Promise<Record<string, any>>;
export declare function mkdir(path: string): void;

@ -83,3 +83,22 @@ function resolveProperties(props) {
}); });
} }
exports.resolveProperties = resolveProperties; 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;

@ -8,7 +8,7 @@ import { colorify } from "../log";
return !isEthers(name); 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 }); updateJson(dirs.rootPackageJsonPath, { dependencies });
})().catch((error) => { })().catch((error) => {

@ -4,6 +4,7 @@ import { dirname, resolve } from "path";
import { getDependencies } from "../local"; import { getDependencies } from "../local";
import { colorify } from "../log"; import { colorify } from "../log";
import { dirs, getDirname, getPackagePath, packages } from "../path"; import { dirs, getDirname, getPackagePath, packages } from "../path";
import { mkdir } from "../utils";
function link(existing: string, path: string): void { function link(existing: string, path: string): void {
try { try {
@ -19,7 +20,7 @@ function link(existing: string, path: string): void {
// Link // Link
const dir = dirname(path); const dir = dirname(path);
fs.mkdirSync(dir, { recursive: true }); mkdir(dir);
fs.symlinkSync(existing, path); 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/ // e.g. /packages/abi/node_modules => /.package_node_modules/abi/
const nodeModules = resolve(nodeModulesBase, getDirname(name)); const nodeModules = resolve(nodeModulesBase, getDirname(name));
fs.mkdirSync(nodeModules, { recursive: true }); mkdir(nodeModules);
link(nodeModules, resolve(getPackagePath(name), "node_modules")); link(nodeModules, resolve(getPackagePath(name), "node_modules"));
}); });

@ -1,5 +1,5 @@
import fs from "fs"; import fs from "fs";
import { resolve } from "path"; import { dirname, resolve } from "path";
import { createHash } from "crypto"; import { createHash } from "crypto";
@ -66,3 +66,20 @@ export async function resolveProperties(props: Record<string, Promise<any>>): Pr
return accum; return accum;
}, <Record<string, any>>{}); }, <Record<string, any>>{});
} }
// 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());
}
}