@atlaspack/package-manager 2.14.31 → 2.14.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Npm.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Npm = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ // @ts-expect-error TS7016
9
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
10
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
11
+ const build_cache_1 = require("@atlaspack/build-cache");
12
+ const promiseFromProcess_1 = __importDefault(require("./promiseFromProcess"));
13
+ const utils_1 = require("./utils");
14
+ const package_json_1 = __importDefault(require("../package.json"));
15
+ const NPM_CMD = 'npm';
16
+ class Npm {
17
+ async install({ modules, cwd, fs, packagePath, saveDev = true, }) {
18
+ // npm doesn't auto-create a package.json when installing,
19
+ // so create an empty one if needed.
20
+ if (packagePath == null) {
21
+ await fs.writeFile(path_1.default.join(cwd, 'package.json'), '{}');
22
+ }
23
+ let args = ['install', '--json', saveDev ? '--save-dev' : '--save'].concat(modules.map(utils_1.npmSpecifierFromModuleRequest));
24
+ // When Parcel is run by npm (e.g. via package.json scripts), several environment variables are
25
+ // added. When parcel in turn calls npm again, these can cause npm to behave stragely, so we
26
+ // filter them out when installing packages.
27
+ let env = {};
28
+ for (let key in process.env) {
29
+ if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
30
+ env[key] = process.env[key];
31
+ }
32
+ }
33
+ let installProcess = (0, cross_spawn_1.default)(NPM_CMD, args, { cwd, env });
34
+ let stdout = '';
35
+ installProcess.stdout.on('data', (buf) => {
36
+ stdout += buf.toString();
37
+ });
38
+ let stderr = [];
39
+ installProcess.stderr.on('data', (buf) => {
40
+ stderr.push(buf.toString().trim());
41
+ });
42
+ try {
43
+ await (0, promiseFromProcess_1.default)(installProcess);
44
+ let results = JSON.parse(stdout);
45
+ let addedCount = results.added.length;
46
+ if (addedCount > 0) {
47
+ logger_1.default.log({
48
+ origin: '@atlaspack/package-manager',
49
+ message: `Added ${addedCount} packages via npm`,
50
+ });
51
+ }
52
+ // Since we succeeded, stderr might have useful information not included
53
+ // in the json written to stdout. It's also not necessary to log these as
54
+ // errors as they often aren't.
55
+ for (let message of stderr) {
56
+ if (message.length > 0) {
57
+ logger_1.default.log({
58
+ origin: '@atlaspack/package-manager',
59
+ message,
60
+ });
61
+ }
62
+ }
63
+ }
64
+ catch (e) {
65
+ throw new Error('npm failed to install modules: ' +
66
+ e.message +
67
+ ' - ' +
68
+ stderr.join('\n'));
69
+ }
70
+ }
71
+ }
72
+ exports.Npm = Npm;
73
+ (0, build_cache_1.registerSerializableClass)(`${package_json_1.default.version}:Npm`, Npm);
package/dist/Pnpm.js ADDED
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Pnpm = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ // @ts-expect-error TS7016
10
+ const command_exists_1 = __importDefault(require("command-exists"));
11
+ // @ts-expect-error TS7016
12
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
13
+ const build_cache_1 = require("@atlaspack/build-cache");
14
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
15
+ // @ts-expect-error TS7016
16
+ const split2_1 = __importDefault(require("split2"));
17
+ const JSONParseStream_1 = __importDefault(require("./JSONParseStream"));
18
+ const promiseFromProcess_1 = __importDefault(require("./promiseFromProcess"));
19
+ const utils_1 = require("./utils");
20
+ const package_json_1 = __importDefault(require("../package.json"));
21
+ const PNPM_CMD = 'pnpm';
22
+ let hasPnpm;
23
+ let pnpmVersion;
24
+ class Pnpm {
25
+ static async exists() {
26
+ if (hasPnpm != null) {
27
+ return hasPnpm;
28
+ }
29
+ try {
30
+ hasPnpm = Boolean(await (0, command_exists_1.default)('pnpm'));
31
+ }
32
+ catch (err) {
33
+ hasPnpm = false;
34
+ }
35
+ return hasPnpm;
36
+ }
37
+ async install({ modules, cwd, saveDev = true, }) {
38
+ if (pnpmVersion == null) {
39
+ let version = await (0, utils_1.exec)('pnpm --version');
40
+ // @ts-expect-error TS2345
41
+ pnpmVersion = parseInt(version.stdout, 10);
42
+ }
43
+ let args = ['add', '--reporter', 'ndjson'];
44
+ if (saveDev) {
45
+ args.push('-D');
46
+ }
47
+ if (pnpmVersion >= 7) {
48
+ if (fs_1.default.existsSync(path_1.default.join(cwd, 'pnpm-workspace.yaml'))) {
49
+ // installs in workspace root (regardless of cwd)
50
+ args.push('-w');
51
+ }
52
+ }
53
+ else {
54
+ // ignores workspace root check
55
+ args.push('-W');
56
+ }
57
+ args = args.concat(modules.map(utils_1.npmSpecifierFromModuleRequest));
58
+ let env = {};
59
+ for (let key in process.env) {
60
+ if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
61
+ env[key] = process.env[key];
62
+ }
63
+ }
64
+ let addedCount = 0, removedCount = 0;
65
+ let installProcess = (0, cross_spawn_1.default)(PNPM_CMD, args, {
66
+ cwd,
67
+ env,
68
+ });
69
+ installProcess.stdout
70
+ .pipe((0, split2_1.default)())
71
+ // @ts-expect-error TS2554
72
+ .pipe(new JSONParseStream_1.default())
73
+ // @ts-expect-error TS7006
74
+ .on('error', (e) => {
75
+ logger_1.default.warn({
76
+ origin: '@atlaspack/package-manager',
77
+ message: e.chunk,
78
+ stack: e.stack,
79
+ });
80
+ })
81
+ .on('data', (json) => {
82
+ if (json.level === 'error') {
83
+ logger_1.default.error({
84
+ origin: '@atlaspack/package-manager',
85
+ message: json.err.message,
86
+ stack: json.err.stack,
87
+ });
88
+ }
89
+ else if (json.level === 'info' && typeof json.message === 'string') {
90
+ logger_1.default.info({
91
+ origin: '@atlaspack/package-manager',
92
+ message: prefix(json.message),
93
+ });
94
+ }
95
+ else if (json.name === 'pnpm:stats') {
96
+ addedCount += json.added ?? 0;
97
+ removedCount += json.removed ?? 0;
98
+ }
99
+ });
100
+ let stderr = [];
101
+ installProcess.stderr
102
+ // @ts-expect-error TS7006
103
+ .on('data', (str) => {
104
+ stderr.push(str.toString());
105
+ })
106
+ // @ts-expect-error TS7006
107
+ .on('error', (e) => {
108
+ logger_1.default.warn({
109
+ origin: '@atlaspack/package-manager',
110
+ message: e.message,
111
+ });
112
+ });
113
+ try {
114
+ await (0, promiseFromProcess_1.default)(installProcess);
115
+ if (addedCount > 0 || removedCount > 0) {
116
+ logger_1.default.log({
117
+ origin: '@atlaspack/package-manager',
118
+ message: `Added ${addedCount} ${removedCount > 0 ? `and removed ${removedCount} ` : ''}packages via pnpm`,
119
+ });
120
+ }
121
+ // Since we succeeded, stderr might have useful information not included
122
+ // in the json written to stdout. It's also not necessary to log these as
123
+ // errors as they often aren't.
124
+ for (let message of stderr) {
125
+ logger_1.default.log({
126
+ origin: '@atlaspack/package-manager',
127
+ message,
128
+ });
129
+ }
130
+ }
131
+ catch (e) {
132
+ throw new Error('pnpm failed to install modules');
133
+ }
134
+ }
135
+ }
136
+ exports.Pnpm = Pnpm;
137
+ function prefix(message) {
138
+ return 'pnpm: ' + message;
139
+ }
140
+ (0, build_cache_1.registerSerializableClass)(`${package_json_1.default.version}:Pnpm`, Pnpm);
package/dist/Yarn.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Yarn = void 0;
7
+ // @ts-expect-error TS7016
8
+ const command_exists_1 = __importDefault(require("command-exists"));
9
+ // @ts-expect-error TS7016
10
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
11
+ const build_cache_1 = require("@atlaspack/build-cache");
12
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
13
+ // @ts-expect-error TS7016
14
+ const split2_1 = __importDefault(require("split2"));
15
+ const JSONParseStream_1 = __importDefault(require("./JSONParseStream"));
16
+ const promiseFromProcess_1 = __importDefault(require("./promiseFromProcess"));
17
+ const utils_1 = require("./utils");
18
+ const package_json_1 = __importDefault(require("../package.json"));
19
+ const YARN_CMD = 'yarn';
20
+ let hasYarn;
21
+ let yarnVersion;
22
+ class Yarn {
23
+ static async exists() {
24
+ if (hasYarn != null) {
25
+ return hasYarn;
26
+ }
27
+ try {
28
+ hasYarn = Boolean(await (0, command_exists_1.default)('yarn'));
29
+ }
30
+ catch (err) {
31
+ hasYarn = false;
32
+ }
33
+ return hasYarn;
34
+ }
35
+ async install({ modules, cwd, saveDev = true, }) {
36
+ if (yarnVersion == null) {
37
+ let version = await (0, utils_1.exec)('yarn --version');
38
+ // @ts-expect-error TS2345
39
+ yarnVersion = parseInt(version.stdout, 10);
40
+ }
41
+ let args = ['add', '--json'].concat(modules.map(utils_1.npmSpecifierFromModuleRequest));
42
+ if (saveDev) {
43
+ args.push('-D');
44
+ if (yarnVersion < 2) {
45
+ args.push('-W');
46
+ }
47
+ }
48
+ // When Parcel is run by Yarn (e.g. via package.json scripts), several environment variables are
49
+ // added. When parcel in turn calls Yarn again, these can cause Yarn to behave stragely, so we
50
+ // filter them out when installing packages.
51
+ let env = {};
52
+ for (let key in process.env) {
53
+ if (!key.startsWith('npm_') &&
54
+ key !== 'YARN_WRAP_OUTPUT' &&
55
+ key !== 'INIT_CWD' &&
56
+ key !== 'NODE_ENV') {
57
+ env[key] = process.env[key];
58
+ }
59
+ }
60
+ let installProcess = (0, cross_spawn_1.default)(YARN_CMD, args, { cwd, env });
61
+ installProcess.stdout
62
+ // Invoking yarn with --json provides streaming, newline-delimited JSON output.
63
+ .pipe((0, split2_1.default)())
64
+ // @ts-expect-error TS2554
65
+ .pipe(new JSONParseStream_1.default())
66
+ // @ts-expect-error TS7006
67
+ .on('error', (e) => {
68
+ logger_1.default.error(e, '@atlaspack/package-manager');
69
+ })
70
+ .on('data', (message) => {
71
+ switch (message.type) {
72
+ case 'step':
73
+ logger_1.default.progress(prefix(`[${message.data.current}/${message.data.total}] ${message.data.message}`));
74
+ return;
75
+ case 'success':
76
+ case 'info':
77
+ logger_1.default.info({
78
+ origin: '@atlaspack/package-manager',
79
+ message: prefix(message.data),
80
+ });
81
+ return;
82
+ default:
83
+ // ignore
84
+ }
85
+ });
86
+ installProcess.stderr
87
+ .pipe((0, split2_1.default)())
88
+ // @ts-expect-error TS2554
89
+ .pipe(new JSONParseStream_1.default())
90
+ // @ts-expect-error TS7006
91
+ .on('error', (e) => {
92
+ logger_1.default.error(e, '@atlaspack/package-manager');
93
+ })
94
+ .on('data', (message) => {
95
+ switch (message.type) {
96
+ case 'warning':
97
+ logger_1.default.warn({
98
+ origin: '@atlaspack/package-manager',
99
+ message: prefix(message.data),
100
+ });
101
+ return;
102
+ case 'error':
103
+ logger_1.default.error({
104
+ origin: '@atlaspack/package-manager',
105
+ message: prefix(message.data),
106
+ });
107
+ return;
108
+ default:
109
+ // ignore
110
+ }
111
+ });
112
+ try {
113
+ return await (0, promiseFromProcess_1.default)(installProcess);
114
+ }
115
+ catch (e) {
116
+ throw new Error('Yarn failed to install modules:' + e.message);
117
+ }
118
+ }
119
+ }
120
+ exports.Yarn = Yarn;
121
+ function prefix(message) {
122
+ return 'yarn: ' + message;
123
+ }
124
+ (0, build_cache_1.registerSerializableClass)(`${package_json_1.default.version}:Yarn`, Yarn);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getCurrentPackageManager;
4
+ function getCurrentPackageManager(
5
+ // @ts-expect-error TS2322
6
+ userAgent = process.env.npm_config_user_agent) {
7
+ if (!userAgent) {
8
+ return undefined;
9
+ }
10
+ const pmSpec = userAgent.split(' ')[0];
11
+ const separatorPos = pmSpec.lastIndexOf('/');
12
+ const name = pmSpec.substring(0, separatorPos);
13
+ return {
14
+ name: name,
15
+ version: pmSpec.substring(separatorPos + 1),
16
+ };
17
+ }
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports._addToInstallQueue = void 0;
18
+ __exportStar(require("./Npm"), exports);
19
+ __exportStar(require("./Pnpm"), exports);
20
+ __exportStar(require("./Yarn"), exports);
21
+ __exportStar(require("./MockPackageInstaller"), exports);
22
+ __exportStar(require("./NodePackageManager"), exports);
23
+ var installPackage_1 = require("./installPackage");
24
+ Object.defineProperty(exports, "_addToInstallQueue", { enumerable: true, get: function () { return installPackage_1._addToInstallQueue; } });
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports._addToInstallQueue = _addToInstallQueue;
40
+ exports.installPackage = installPackage;
41
+ const assert_1 = __importDefault(require("assert"));
42
+ const path_1 = __importDefault(require("path"));
43
+ const nullthrows_1 = __importDefault(require("nullthrows"));
44
+ const semver_1 = __importDefault(require("semver"));
45
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
46
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
47
+ const utils_1 = require("@atlaspack/utils");
48
+ const workers_1 = __importDefault(require("@atlaspack/workers"));
49
+ const Npm_1 = require("./Npm");
50
+ const Yarn_1 = require("./Yarn");
51
+ const Pnpm_1 = require("./Pnpm");
52
+ const utils_2 = require("./utils");
53
+ const getCurrentPackageManager_1 = __importDefault(require("./getCurrentPackageManager"));
54
+ const validateModuleSpecifier_1 = __importDefault(require("./validateModuleSpecifier"));
55
+ async function install(fs, packageManager, modules, from, projectRoot, options = {}) {
56
+ let { installPeers = true, saveDev = true, packageInstaller } = options;
57
+ let moduleNames = modules.map((m) => m.name).join(', ');
58
+ logger_1.default.progress(`Installing ${moduleNames}...`);
59
+ let fromPkgPath = await (0, utils_1.resolveConfig)(fs, from, ['package.json'], projectRoot);
60
+ let cwd = fromPkgPath ? path_1.default.dirname(fromPkgPath) : fs.cwd();
61
+ if (!packageInstaller) {
62
+ packageInstaller = await determinePackageInstaller(fs, from, projectRoot);
63
+ }
64
+ try {
65
+ await packageInstaller.install({
66
+ modules,
67
+ saveDev,
68
+ cwd,
69
+ packagePath: fromPkgPath,
70
+ fs,
71
+ });
72
+ }
73
+ catch (err) {
74
+ throw new Error(`Failed to install ${moduleNames}: ${err.message}`);
75
+ }
76
+ if (installPeers) {
77
+ await Promise.all(modules.map((m) => installPeerDependencies(fs, packageManager, m, from, projectRoot, options)));
78
+ }
79
+ }
80
+ async function installPeerDependencies(fs, packageManager, module, from, projectRoot, options) {
81
+ const { resolved } = await packageManager.resolve(module.name, from);
82
+ const modulePkg = (0, nullthrows_1.default)(await (0, utils_1.loadConfig)(fs, resolved, ['package.json'], projectRoot)).config;
83
+ const peers = modulePkg.peerDependencies || {};
84
+ let modules = [];
85
+ for (let [name, range] of Object.entries(peers)) {
86
+ (0, assert_1.default)(typeof range === 'string');
87
+ let conflicts = await (0, utils_2.getConflictingLocalDependencies)(fs, name, from, projectRoot);
88
+ if (conflicts) {
89
+ let { pkg } = await packageManager.resolve(name, from);
90
+ (0, assert_1.default)(pkg);
91
+ if (!semver_1.default.satisfies(pkg.version, range)) {
92
+ throw new diagnostic_1.default({
93
+ diagnostic: {
94
+ message: (0, diagnostic_1.md) `Could not install the peer dependency "${name}" for "${module.name}", installed version ${pkg.version} is incompatible with ${range}`,
95
+ origin: '@atlaspack/package-manager',
96
+ codeFrames: [
97
+ {
98
+ filePath: conflicts.filePath,
99
+ language: 'json',
100
+ code: conflicts.json,
101
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(conflicts.json, conflicts.fields.map((field) => ({
102
+ key: `/${field}/${(0, diagnostic_1.encodeJSONKeyComponent)(name)}`,
103
+ type: 'key',
104
+ message: 'Found this conflicting local requirement.',
105
+ }))),
106
+ },
107
+ ],
108
+ },
109
+ });
110
+ }
111
+ continue;
112
+ }
113
+ modules.push({ name, range });
114
+ }
115
+ if (modules.length) {
116
+ await install(fs, packageManager, modules, from, projectRoot, Object.assign({}, options, { installPeers: false }));
117
+ }
118
+ }
119
+ async function determinePackageInstaller(fs, filepath, projectRoot) {
120
+ let configFile = await (0, utils_1.resolveConfig)(fs, filepath, ['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock'], projectRoot);
121
+ let configName = configFile && path_1.default.basename(configFile);
122
+ // Always use the package manager that seems to be used in the project,
123
+ // falling back to a different one wouldn't update the existing lockfile.
124
+ if (configName === 'package-lock.json') {
125
+ return new Npm_1.Npm();
126
+ }
127
+ else if (configName === 'pnpm-lock.yaml') {
128
+ return new Pnpm_1.Pnpm();
129
+ }
130
+ else if (configName === 'yarn.lock') {
131
+ return new Yarn_1.Yarn();
132
+ }
133
+ let currentPackageManager = (0, getCurrentPackageManager_1.default)()?.name;
134
+ if (currentPackageManager === 'npm') {
135
+ return new Npm_1.Npm();
136
+ }
137
+ else if (currentPackageManager === 'yarn') {
138
+ return new Yarn_1.Yarn();
139
+ }
140
+ else if (currentPackageManager === 'pnpm') {
141
+ return new Pnpm_1.Pnpm();
142
+ }
143
+ if (await Yarn_1.Yarn.exists()) {
144
+ return new Yarn_1.Yarn();
145
+ }
146
+ else if (await Pnpm_1.Pnpm.exists()) {
147
+ return new Pnpm_1.Pnpm();
148
+ }
149
+ else {
150
+ return new Npm_1.Npm();
151
+ }
152
+ }
153
+ let queue = new utils_1.PromiseQueue({ maxConcurrent: 1 });
154
+ let modulesInstalling = new Set();
155
+ // Exported so that it may be invoked from the worker api below.
156
+ // Do not call this directly! This can result in concurrent package installations
157
+ // across multiple instances of the package manager.
158
+ function _addToInstallQueue(fs, packageManager, modules, filePath, projectRoot, options) {
159
+ modules = modules.map((request) => ({
160
+ name: (0, validateModuleSpecifier_1.default)(request.name),
161
+ range: request.range,
162
+ }));
163
+ // Wrap PromiseQueue and track modules that are currently installing.
164
+ // If a request comes in for a module that is currently installing, don't bother
165
+ // enqueuing it.
166
+ let modulesToInstall = modules.filter((m) => !modulesInstalling.has(getModuleRequestKey(m)));
167
+ if (modulesToInstall.length) {
168
+ for (let m of modulesToInstall) {
169
+ modulesInstalling.add(getModuleRequestKey(m));
170
+ }
171
+ queue.add(() => install(fs, packageManager, modulesToInstall, filePath, projectRoot, options).then(() => {
172
+ for (let m of modulesToInstall) {
173
+ modulesInstalling.delete(getModuleRequestKey(m));
174
+ }
175
+ }));
176
+ }
177
+ return queue.run();
178
+ }
179
+ function installPackage(fs, packageManager, modules, filePath, projectRoot, options) {
180
+ if (workers_1.default.isWorker()) {
181
+ let workerApi = workers_1.default.getWorkerApi();
182
+ // TODO this should really be `__filename` but without the rewriting.
183
+ let bundlePath = process.env.ATLASPACK_BUILD_ENV === 'production' &&
184
+ !process.env.ATLASPACK_SELF_BUILD
185
+ ? path_1.default.join(__dirname, '..', 'lib/index.js')
186
+ : __filename;
187
+ return workerApi.callMaster({
188
+ location: bundlePath,
189
+ args: [fs, packageManager, modules, filePath, projectRoot, options],
190
+ method: '_addToInstallQueue',
191
+ });
192
+ }
193
+ return _addToInstallQueue(fs, packageManager, modules, filePath, projectRoot, options);
194
+ }
195
+ function getModuleRequestKey(moduleRequest) {
196
+ return [moduleRequest.name, moduleRequest.range].join('@');
197
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defaultNodejsConditions = void 0;
7
+ exports.getConditionsFromEnv = getConditionsFromEnv;
8
+ const process_1 = __importDefault(require("process"));
9
+ // https://nodejs.org/api/packages.html#conditional-exports
10
+ // TODO We don't support { "type": "module" }
11
+ // @ts-expect-error TS4104
12
+ exports.defaultNodejsConditions = Object.freeze([
13
+ 'node-addons',
14
+ 'node',
15
+ // 'import',
16
+ 'require',
17
+ 'module-sync',
18
+ 'default',
19
+ ]);
20
+ let envConditions = undefined;
21
+ /** @description Gets the export conditions from NODE_OPTIONS and node arguments */
22
+ function getConditionsFromEnv() {
23
+ if (!envConditions) {
24
+ const conditions = [];
25
+ for (const arg of [
26
+ ...process_1.default.execArgv,
27
+ ...(process_1.default.env.NODE_OPTIONS || '').split(' '),
28
+ ]) {
29
+ if (arg.startsWith('--conditions=')) {
30
+ // @ts-expect-error TS2345
31
+ conditions.push(arg.substring(13));
32
+ }
33
+ }
34
+ // @ts-expect-error TS4104
35
+ envConditions = Object.freeze([...conditions, ...exports.defaultNodejsConditions]);
36
+ }
37
+ // @ts-expect-error TS2322
38
+ return envConditions;
39
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = promiseFromProcess;
4
+ function promiseFromProcess(childProcess) {
5
+ return new Promise((resolve, reject) => {
6
+ childProcess.on('error', reject);
7
+ childProcess.on('close', (code) => {
8
+ if (code !== 0) {
9
+ reject(new Error('Child process failed'));
10
+ return;
11
+ }
12
+ // @ts-expect-error TS2794
13
+ resolve();
14
+ });
15
+ });
16
+ }