@yarnpkg/pnpify
Version:
49 lines (46 loc) • 2.22 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@yarnpkg/core");
const fslib_1 = require("@yarnpkg/fslib");
const clipanion_1 = require("clipanion");
const dynamicRequire_1 = require("../dynamicRequire");
// eslint-disable-next-line arca/no-default-export
class RunCommand extends clipanion_1.Command {
constructor() {
super(...arguments);
this.cwd = clipanion_1.Option.String(`--cwd`, process.cwd(), {
description: `The directory to run the command in`,
});
this.commandName = clipanion_1.Option.String();
this.args = clipanion_1.Option.Proxy();
}
async execute() {
let { NODE_OPTIONS } = process.env;
NODE_OPTIONS = `${NODE_OPTIONS || ``} --require ${JSON.stringify(dynamicRequire_1.dynamicRequire.resolve(`@yarnpkg/pnpify`))}`.trim();
const { code } = await core_1.execUtils.pipevp(this.commandName, this.args, {
cwd: fslib_1.npath.toPortablePath(this.cwd),
stderr: this.context.stderr,
stdin: this.context.stdin,
stdout: this.context.stdout,
env: { ...process.env, NODE_OPTIONS },
});
return code;
}
}
RunCommand.paths = [
[`run`],
clipanion_1.Command.Default,
];
RunCommand.usage = clipanion_1.Command.Usage({
description: `run a command with a virtual node_modules folder`,
details: `
When a non-PnP-compliant project tries to access the \`node_modules\` directories (for example through \`readdir\` or \`readFile\`), PnPify intercepts those calls and converts them into calls to the PnP API. Then, based on the result, it simulates the existence of a virtual \`node_modules\` folder that the underlying tool will then consume - still unaware that the files are extracted from a virtual filesystem.
The \`run\` keyword can be omitted if the executed command doesn't conflict with built-in commands.
For more details on PnPify, please consult the dedicated page from our website: https://yarnpkg.com/advanced/pnpify.
`,
examples: [[
`Run Angular using PnPify`,
`$0 ng build`,
]],
});
exports.default = RunCommand;
;