Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
const optionalChaining = require("es5-ext/optional-chaining")
, { resolve } = require("path")
, readFile = require("fs2/read-file")
, writeFile = require("fs2/write-file")
, got = require("got")
, tar = require("tar")
, log = require("log").get("npm-cross-link")
, runProgram = require("../../../../run-program")
, resolveNpmAuthToken = require("../../resolve-npm-auth-token");
module.exports = {
isApplicable: (name, version, externalContext) =>
optionalChaining(externalContext, "metadata", "versions", version),
resolveCacheName: version => version,
prepare: async (tmpDir, name, version, versionMetaData) => {
// Regular npm publication
const npmAuthToken = (await resolveNpmAuthToken(versionMetaData.dist.tarball)) || "";
await new Promise((promiseResolve, promiseReject) => {
const stream = got
.stream(versionMetaData.dist.tarball, {
headers: { Authorization: `Bearer ${ npmAuthToken }` }
})
.pipe(tar.x({ cwd: tmpDir, strip: 1 }));
"use strict";
const optionalChaining = require("es5-ext/optional-chaining")
, { join, resolve } = require("path")
, copyDir = require("fs2/copy-dir")
, isDirectory = require("fs2/is-directory")
, symlink = require("fs2/symlink")
, rm = require("fs2/rm")
, log = require("log").get("npm-cross-link")
, getPackageJson = require("../../../get-package-json")
, muteErrorIfOptional = require("../mute-error-if-optional")
, prepareDependency = require("./prepare")
, resolveBinariesDict = require("./resolve-binaries-dict");
const mapBinaries = async ({ name, path, dependentContext }) => {
const binDict = resolveBinariesDict(path);
if (!binDict) return;
await Promise.all(
Object.entries(binDict).map(async ([targetName, linkedPath]) => {
const targetPath = resolve(dependentContext.path, "node_modules/.bin", targetName);
await rm(targetPath, { loose: true, force: true, recursive: true });
await symlink(join("../", name, linkedPath), targetPath, {
type: "junction",
intermediate: true
});
"use strict";
const log = require("log").get("npm-cross-link");
module.exports = async (dependencyContext, operation) => {
try {
return await operation();
} catch (error) {
const { isOptional, name, dependentContext } = dependencyContext;
if (isOptional) {
log.warn(
"%s optional %s dependency failed to install (ignoring): %#s",
dependentContext.name, name, error.stack
);
return null;
}
throw error;
}
};
"use strict";
const ensureArray = require("es5-ext/array/valid-array")
, isValue = require("es5-ext/object/is-value")
, ensureObject = require("es5-ext/object/valid-object")
, ensurePlainFunction = require("es5-ext/object/ensure-plain-function")
, ensureString = require("es5-ext/object/validate-stringifiable-value")
, { resolve } = require("path")
, { homedir } = require("os")
, log = require("log").get("npm-cross-link:configuration").debug;
module.exports = userConfiguration => {
log.debug("user input: %O", userConfiguration);
const configuration = {};
configuration.packagesPath = userConfiguration.packagesPath
? resolve(ensureString(userConfiguration.packagesPath))
: resolve(homedir(), "npm-packages");
log("packages path: %s", configuration.packagesPath);
ensureObject(userConfiguration.packagesMeta);
const packagesMeta = (configuration.packagesMeta = Object.create(null));
for (const [packageName, userPackageMeta] of Object.entries(userConfiguration.packagesMeta)) {
ensureObject(userPackageMeta);
const packageMeta = (packagesMeta[packageName] = {});
"use strict";
const isObject = require("es5-ext/object/is-object")
, spawn = require("child-process-ext/spawn")
, log = require("log").get("npm-cross-link");
module.exports = (command, args, options = {}) => {
if (!isObject(options)) options = {};
const { logger } = options;
const promise = spawn(command, args, { cwd: options.cwd, split: Boolean(logger) });
if (logger) {
if (promise.stdout) promise.stdout.on("data", data => logger.info(String(data)));
if (promise.stderr) promise.stderr.on("data", data => logger.notice(String(data)));
}
return promise.catch(error => {
log.warn("%s failed for %s, %O with %#s", command, args.join(" "), options, error.message);
throw error;
});
};
"use strict";
const { resolve } = require("path")
, log = require("log").get("npm-cross-link")
, isSymlink = require("fs2/is-symlink")
, rm = require("fs2/rm")
, cleanupNpmInstall = require("../cleanup-npm-install")
, getNpmModulesPath = require("../../get-npm-modules-path")
, runProgram = require("../../run-program");
module.exports = async packageContext => {
const { path, name, installationJobs, isNameMismatch } = packageContext;
const symlinkPath = resolve(await getNpmModulesPath(), name);
if (await isSymlink(symlinkPath, { linkPath: path })) {
if (isNameMismatch) await rm(symlinkPath, { loose: true, recursive: true, force: true });
return;
}
if (isNameMismatch) return;
installationJobs.add("link");
"use strict";
const ensureString = require("es5-ext/object/validate-stringifiable-value")
, { resolve } = require("path")
, { readFileSync } = require("fs")
, log = require("log").get("npm-cross-link");
module.exports = path => {
const packageMetaPath = resolve(ensureString(path), "package.json");
try {
return JSON.parse(readFileSync(packageMetaPath));
} catch (error) {
if (error.code !== "ENOENT") {
log.error("resolving package.json at %s crashed with: %#s", path, error.message);
}
return null;
}
};
#!/usr/bin/env node
"use strict";
require("log-node")({ defaultNamespace: "webmake" });
const count = require("es5-ext/object/count")
, { resolve } = require("path")
, log = require("log").get("webmake")
, webmake = require("..");
const { isArray } = Array, { now } = Date;
const optimist = require("optimist").usage("Usage: $0 [options] [<input>] [<output>]", {
"name": { string: true, description: "Expose program in your namespace with given name" },
"amd": { boolean: true, description: "Expose bundle as AMD module" },
"cjs": { boolean: true, description: "Expose bundle as CJS module" },
"ext": { string: true, description: "Optional extensions" },
"ignore-errors": { boolean: true, description: "Ignore unparsable require calls" },
"use-strict": { boolean: true, description: "Enforce strict mode" },
"include": {
string: true,
description:
"Additional module(s) that should be included (and are not picked by the parser)"
},</output>
"use strict";
const optionalChaining = require("es5-ext/optional-chaining")
, { resolve } = require("path")
, log = require("log").get("npm-cross-link")
, isDirectory = require("fs2/is-directory")
, rm = require("fs2/rm")
, NpmCrossLinkError = require("../../npm-cross-link-error")
, setupRepository = require("../../setup-repository")
, getPackageJson = require("../../get-package-json")
, cleanupNpmInstall = require("../cleanup-npm-install")
, removeNonDirectDependencies = require("../remove-non-direct-dependencies")
, npmLink = require("./npm-link")
, finalize = require("./finalize");
module.exports = async (packageContext, userConfiguration, inputOptions, progressData) => {
const { name } = packageContext;
const { hooks, packagesPath, packagesMeta } = userConfiguration;
const { ongoing } = progressData;
if (!packagesMeta[name]) {
throw new NpmCrossLinkError(
"use strict";
const { resolve } = require("path")
, readdir = require("fs2/readdir")
, rename = require("fs2/rename")
, rm = require("fs2/rm")
, log = require("log").get("npm-cross-link")
, runProgram = require("../../../../run-program");
module.exports = {
isApplicable: () => true,
resolveCacheName: () => null,
prepare: async (tmpDir, name, version) => {
await runProgram("npm", ["install", `${ name }@${ version }`], {
cwd: tmpDir,
logger: log.levelRoot.get("npm:install")
});
const sourcePath = resolve(tmpDir, "node_modules", name);
await Promise.all(
(await readdir(sourcePath)).map(filename => {
if (filename === "." || filename === "..") return null;
return rename(resolve(sourcePath, filename), resolve(tmpDir, filename));
})