Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function toHaveBinaryLinks(received, ...inputs) {
const pkg = Package.lazy(received);
const links =
process.platform === "win32"
? inputs.reduce(
(acc, input) => [
...acc,
input,
// cmd.exe
[input, "cmd"].join("."),
// powershell
[input, "ps1"].join("."),
],
[]
)
: inputs;
const expectedName = `expected ${pkg.name}`;
function symlinkBinary(srcPackageRef, destPackageRef) {
return Promise.all([Package.lazy(srcPackageRef), Package.lazy(destPackageRef)]).then(
([srcPackage, destPackage]) => {
const actions = Object.keys(srcPackage.bin).map(name => {
const srcLocation = srcPackage.contents
? path.resolve(srcPackage.location, srcPackage.contents)
: srcPackage.location;
const src = path.join(srcLocation, srcPackage.bin[name]);
const dst = path.join(destPackage.binLocation, name);
// Symlink all declared binaries, even if they don't exist (yet). We will
// assume the package author knows what they're doing and that the binaries
// will be generated during a later build phase (potentially source compiled from
// another language).
return { src, dst };
});
if (actions.length === 0) {
function toHaveExecutables(received, ...files) {
const pkg = Package.lazy(received);
const expectedFiles = `expected ${files.join(", ")}`;
const expectedAction = "to be executable";
const expectation = `${expectedFiles} ${expectedAction}`;
// eslint-disable-next-line prefer-destructuring
const X_OK = (fs.constants || fs).X_OK;
const failed = files.filter(file => {
try {
return fs.accessSync(path.join(pkg.location, file), X_OK);
} catch (_) {
return true;
}
});
const pass = failed.length === 0;
return (received, name, range, options) => {
const pkg = Package.lazy(received);
const noDeps = typeof pkg[dependencyType] !== "object";
const id = [name, range].filter(Boolean).join("@");
const exact = options && options.exact;
const expectedName = `expected ${pkg.name}`;
const expectedAction = `to ${verb} on ${id}`;
const expectation = `${expectedName} ${expectedAction}`;
const json = JSON.stringify(pkg[dependencyType], null, 2);
if (noDeps) {
return {
message: () => `${expectation} but no ${dependencyType} specified`,
pass: false,
};
}
function packDirectory(_pkg, dir, _opts) {
const pkg = Package.lazy(_pkg, dir);
const opts = PackConfig(_opts);
opts.log.verbose("pack-directory", path.relative(".", pkg.contents));
let chain = Promise.resolve();
if (opts.ignorePrepublish !== true) {
chain = chain.then(() => runLifecycle(pkg, "prepublish", opts));
}
chain = chain.then(() => runLifecycle(pkg, "prepare", opts));
if (opts.lernaCommand === "publish") {
chain = chain.then(() => pkg.refresh());
chain = chain.then(() => runLifecycle(pkg, "prepublishOnly", opts));
chain = chain.then(() => pkg.refresh());