diff --git a/internal/linker/index.js b/internal/linker/index.js index c5fca5a105..6ff8f4275f 100644 --- a/internal/linker/index.js +++ b/internal/linker/index.js @@ -1,4 +1,12 @@ -/* THIS FILE GENERATED FROM .ts; see BUILD.bazel */ /* clang-format off */(function (factory) { +/* THIS FILE GENERATED FROM .ts; see BUILD.bazel */ /* clang-format off */var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; @@ -33,25 +41,31 @@ Include as much of the build output as you can without disclosing anything confi `); } function symlink(target, path) { - if (fs.existsSync(path)) { - // We assume here that the path is already linked to the correct target. - // Could add some logic that asserts it here, but we want to avoid an extra - // filesystem access so we should only do it under some kind of strict mode. - return; - } - log_verbose(`symlink( ${path} -> ${target} )`); - // Use junction on Windows since symlinks require elevated permissions. - // We only link to directories so junctions work for us. - fs.symlinkSync(target, path, 'junction'); - if (VERBOSE_LOGS) { - // Be verbose about creating a bad symlink - // Maybe this should fail in production as well, but again we want to avoid - // any unneeded file I/O - if (!fs.existsSync(path)) { - log_verbose('ERROR\n***\nLooks like we created a bad symlink:' + - `\n pwd ${process.cwd()}\n target ${target}\n***`); + return __awaiter(this, void 0, void 0, function* () { + log_verbose(`symlink( ${path} -> ${target} )`); + // Use junction on Windows since symlinks require elevated permissions. + // We only link to directories so junctions work for us. + try { + yield fs.promises.symlink(target, path, 'junction'); } - } + catch (e) { + if (e.code !== 'ENOENT') { + throw e; + } + // We assume here that the path is already linked to the correct target. + // Could add some logic that asserts it here, but we want to avoid an extra + // filesystem access so we should only do it under some kind of strict mode. + } + if (VERBOSE_LOGS) { + // Be verbose about creating a bad symlink + // Maybe this should fail in production as well, but again we want to avoid + // any unneeded file I/O + if (!fs.existsSync(path)) { + log_verbose('ERROR\n***\nLooks like we created a bad symlink:' + + `\n pwd ${process.cwd()}\n target ${target}\n***`); + } + } + }); } /** * Resolve a root directory string to the actual location on disk @@ -150,57 +164,82 @@ Include as much of the build output as you can without disclosing anything confi } } exports.Runfiles = Runfiles; - function main(args, runfiles) { - if (!args || args.length < 1) - throw new Error('link_node_modules.js requires one argument: modulesManifest path'); - const [modulesManifest] = args; - let { root, modules, workspace } = JSON.parse(fs.readFileSync(modulesManifest)); - modules = modules || {}; - log_verbose(`module manifest: workspace ${workspace}, root ${root} with first-party packages\n`, modules); - const rootDir = resolveRoot(root, runfiles); - log_verbose('resolved root', root, 'to', rootDir); - // Bazel starts actions with pwd=execroot/my_wksp - const workspaceDir = path.resolve('.'); - // Convert from runfiles path - // this_wksp/path/to/file OR other_wksp/path/to/file - // to execroot path - // path/to/file OR external/other_wksp/path/to/file - function toWorkspaceDir(p) { - if (p.startsWith(workspace + path.sep)) { - return p.substring(workspace.length + 1); + // There is no fs.promises.exists function because + // node core is of the opinion that exists is always too racey to rely on. + function exists(p) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield fs.promises.stat(p); + return true; } - return path.join('external', p); - } - // Create the $pwd/node_modules directory that node will resolve from - symlink(rootDir, 'node_modules'); - process.chdir(rootDir); - // Symlinks to packages need to reach back to the workspace/runfiles directory - const workspaceRelative = path.relative('.', workspaceDir); - const runfilesRelative = runfiles.dir ? path.relative('.', runfiles.dir) : undefined; - // Now add symlinks to each of our first-party packages so they appear under the node_modules tree - for (const m of Object.keys(modules)) { - let target; - // Look in the runfiles first - // TODO: this could be a method in the Runfiles class - if (runfiles.manifest) { - target = runfiles.lookupDirectory(modules[m]); + catch (e) { + if (e.code === 'ENOENT') { + return false; + } + throw e; } - else if (runfilesRelative) { - target = path.join(runfilesRelative, modules[m]); + }); + } + function main(args, runfiles) { + return __awaiter(this, void 0, void 0, function* () { + if (!args || args.length < 1) + throw new Error('link_node_modules.js requires one argument: modulesManifest path'); + const [modulesManifest] = args; + let { root, modules, workspace } = JSON.parse(fs.readFileSync(modulesManifest)); + modules = modules || {}; + log_verbose(`module manifest: workspace ${workspace}, root ${root} with first-party packages\n`, modules); + const rootDir = resolveRoot(root, runfiles); + log_verbose('resolved root', root, 'to', rootDir); + // Bazel starts actions with pwd=execroot/my_wksp + const workspaceDir = path.resolve('.'); + // Convert from runfiles path + // this_wksp/path/to/file OR other_wksp/path/to/file + // to execroot path + // path/to/file OR external/other_wksp/path/to/file + function toWorkspaceDir(p) { + if (p.startsWith(workspace + path.sep)) { + return p.substring(workspace.length + 1); + } + return path.join('external', p); } - // It sucks that we have to do a FS call here. - // TODO: could we know which packages are statically linked?? - if (!target || !fs.existsSync(target)) { - // Try the execroot - target = path.join(workspaceRelative, toWorkspaceDir(modules[m])); + // Create the $pwd/node_modules directory that node will resolve from + yield symlink(rootDir, 'node_modules'); + process.chdir(rootDir); + // Symlinks to packages need to reach back to the workspace/runfiles directory + const workspaceRelative = path.relative('.', workspaceDir); + const runfilesRelative = runfiles.dir ? path.relative('.', runfiles.dir) : undefined; + // Now add symlinks to each of our first-party packages so they appear under the node_modules tree + const links = []; + const linkModule = (name, modulePath) => __awaiter(this, void 0, void 0, function* () { + let target; + // Look in the runfiles first + // TODO: this could be a method in the Runfiles class + if (runfiles.manifest) { + target = runfiles.lookupDirectory(modulePath); + } + else if (runfilesRelative) { + target = path.join(runfilesRelative, modulePath); + } + // It sucks that we have to do a FS call here. + // TODO: could we know which packages are statically linked?? + if (!target || !(yield exists(target))) { + // Try the execroot + target = path.join(workspaceRelative, toWorkspaceDir(modulePath)); + } + yield symlink(target, name); + }); + for (const m of Object.keys(modules)) { + links.push(linkModule(m, modules[m])); } - symlink(target, m); - } - return 0; + yield Promise.all(links); + return 0; + }); } exports.main = main; if (require.main === module) { - process.exitCode = main(process.argv.slice(2), new Runfiles()); + (() => __awaiter(this, void 0, void 0, function* () { + process.exitCode = yield main(process.argv.slice(2), new Runfiles()); + }))(); } }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlua19ub2RlX21vZHVsZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9pbnRlcm5hbC9saW5rZXIvbGlua19ub2RlX21vZHVsZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7SUFBQTs7OztPQUlHO0lBQ0gseUJBQXlCO0lBQ3pCLDZCQUE2QjtJQUU3QixnRUFBZ0U7SUFDaEUsTUFBTSxZQUFZLEdBQUcsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsY0FBYyxDQUFDLENBQUM7SUFFbkQsU0FBUyxXQUFXLENBQUMsR0FBRyxDQUFXO1FBQ2pDLElBQUksWUFBWTtZQUFFLE9BQU8sQ0FBQyxLQUFLLENBQUMsd0JBQXdCLEVBQUUsR0FBRyxDQUFDLENBQUMsQ0FBQztJQUNsRSxDQUFDO0lBRUQsU0FBUyxLQUFLLENBQUMsQ0FBUztRQUN0QixNQUFNLElBQUksS0FBSyxDQUFDOzs7Ozs7SUFNZCxDQUFDO0dBQ0YsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztJQUVELFNBQVMsT0FBTyxDQUFDLE1BQWMsRUFBRSxJQUFZO1FBQzNDLElBQUksRUFBRSxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsRUFBRTtZQUN2Qix3RUFBd0U7WUFDeEUsMkVBQTJFO1lBQzNFLDRFQUE0RTtZQUM1RSxPQUFPO1NBQ1I7UUFDRCxXQUFXLENBQUMsWUFBWSxJQUFJLE9BQU8sTUFBTSxJQUFJLENBQUMsQ0FBQztRQUMvQyx1RUFBdUU7UUFDdkUsd0RBQXdEO1FBQ3hELEVBQUUsQ0FB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