ethers.js/misc/admin/lib/cmds/link.js

66 lines
3.0 KiB
JavaScript
Raw Normal View History

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = require("path");
const local_1 = require("../local");
2020-09-23 05:54:48 +03:00
const log_1 = require("../log");
const path_2 = require("../path");
2020-09-23 07:23:02 +03:00
const utils_1 = require("../utils");
function link(existing, path) {
try {
const current = fs_1.default.readlinkSync(path);
// Alerady linked
if (current === existing) {
return;
}
fs_1.default.unlinkSync(path);
}
catch (error) {
if (error.code !== "ENOENT") {
throw error;
}
}
// Link
2021-10-16 09:29:27 +03:00
const dir = (0, path_1.dirname)(path);
(0, utils_1.mkdir)(dir);
2021-03-31 02:59:47 +03:00
fs_1.default.symlinkSync(existing, path, "junction");
}
(function () {
return __awaiter(this, void 0, void 0, function* () {
2020-09-23 05:54:48 +03:00
console.log(log_1.colorify.bold(`Linking ${path_2.packages.length} package node_modules rat nests...`));
2021-10-16 09:29:27 +03:00
const nodeModulesBase = (0, path_1.resolve)(path_2.dirs.root, ".package_node_modules");
// Make a symlink in the ROOT/node_mpdules to each package in this repo
path_2.packages.forEach((name) => {
// e.g. /node_modules/@ethersproject/abi => /packages/abi
2021-10-16 09:29:27 +03:00
link((0, path_2.getPackagePath)(name), (0, path_1.resolve)(path_2.dirs.root, "node_modules", name));
// e.g. /packages/abi/node_modules => /.package_node_modules/abi/
2021-10-16 09:29:27 +03:00
const nodeModules = (0, path_1.resolve)(nodeModulesBase, (0, path_2.getDirname)(name));
(0, utils_1.mkdir)(nodeModules);
link(nodeModules, (0, path_1.resolve)((0, path_2.getPackagePath)(name), "node_modules"));
});
path_2.packages.forEach((name) => {
2021-10-16 09:29:27 +03:00
const nodeModules = (0, path_1.resolve)(nodeModulesBase, (0, path_2.getDirname)(name));
const deps = (0, local_1.getDependencies)(name);
Object.keys(deps).forEach((name) => {
2021-10-16 09:29:27 +03:00
link((0, path_1.resolve)(path_2.dirs.root, "node_modules", name), (0, path_1.resolve)(nodeModules, name));
});
});
});
})().catch((error) => {
console.log(`Error running ${process.argv[0]}: ${error.message}`);
process.exit(1);
});
;