@atlaspack/package-manager 2.14.18-noselfbuild-3f2849b52.0 → 2.14.18-noselfbuild-342bd6c75.0

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.
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._addToInstallQueue = _addToInstallQueue;
7
+ exports.installPackage = installPackage;
8
+ function _assert() {
9
+ const data = _interopRequireDefault(require("assert"));
10
+ _assert = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _path() {
16
+ const data = _interopRequireDefault(require("path"));
17
+ _path = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
22
+ function _nullthrows() {
23
+ const data = _interopRequireDefault(require("nullthrows"));
24
+ _nullthrows = function () {
25
+ return data;
26
+ };
27
+ return data;
28
+ }
29
+ function _semver() {
30
+ const data = _interopRequireDefault(require("semver"));
31
+ _semver = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
36
+ function _diagnostic() {
37
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
38
+ _diagnostic = function () {
39
+ return data;
40
+ };
41
+ return data;
42
+ }
43
+ function _logger() {
44
+ const data = _interopRequireDefault(require("@atlaspack/logger"));
45
+ _logger = function () {
46
+ return data;
47
+ };
48
+ return data;
49
+ }
50
+ function _utils() {
51
+ const data = require("@atlaspack/utils");
52
+ _utils = function () {
53
+ return data;
54
+ };
55
+ return data;
56
+ }
57
+ function _workers() {
58
+ const data = _interopRequireDefault(require("@atlaspack/workers"));
59
+ _workers = function () {
60
+ return data;
61
+ };
62
+ return data;
63
+ }
64
+ var _Npm = require("./Npm");
65
+ var _Yarn = require("./Yarn");
66
+ var _Pnpm = require("./Pnpm");
67
+ var _utils2 = require("./utils");
68
+ var _getCurrentPackageManager = _interopRequireDefault(require("./getCurrentPackageManager"));
69
+ var _validateModuleSpecifier = _interopRequireDefault(require("./validateModuleSpecifier"));
70
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
71
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
72
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
+ async function install(fs, packageManager, modules, from, projectRoot, options = {}) {
74
+ let {
75
+ installPeers = true,
76
+ saveDev = true,
77
+ packageInstaller
78
+ } = options;
79
+ let moduleNames = modules.map(m => m.name).join(', ');
80
+ _logger().default.progress(`Installing ${moduleNames}...`);
81
+ let fromPkgPath = await (0, _utils().resolveConfig)(fs, from, ['package.json'], projectRoot);
82
+ let cwd = fromPkgPath ? _path().default.dirname(fromPkgPath) : fs.cwd();
83
+ if (!packageInstaller) {
84
+ packageInstaller = await determinePackageInstaller(fs, from, projectRoot);
85
+ }
86
+ try {
87
+ await packageInstaller.install({
88
+ modules,
89
+ saveDev,
90
+ cwd,
91
+ packagePath: fromPkgPath,
92
+ fs
93
+ });
94
+ } catch (err) {
95
+ throw new Error(`Failed to install ${moduleNames}: ${err.message}`);
96
+ }
97
+ if (installPeers) {
98
+ await Promise.all(modules.map(m => installPeerDependencies(fs, packageManager, m, from, projectRoot, options)));
99
+ }
100
+ }
101
+ async function installPeerDependencies(fs, packageManager, module, from, projectRoot, options) {
102
+ const {
103
+ resolved
104
+ } = await packageManager.resolve(module.name, from);
105
+ const modulePkg = (0, _nullthrows().default)(await (0, _utils().loadConfig)(fs, resolved, ['package.json'], projectRoot)).config;
106
+ const peers = modulePkg.peerDependencies || {};
107
+ let modules = [];
108
+ for (let [name, range] of Object.entries(peers)) {
109
+ (0, _assert().default)(typeof range === 'string');
110
+ let conflicts = await (0, _utils2.getConflictingLocalDependencies)(fs, name, from, projectRoot);
111
+ if (conflicts) {
112
+ let {
113
+ pkg
114
+ } = await packageManager.resolve(name, from);
115
+ (0, _assert().default)(pkg);
116
+ if (!_semver().default.satisfies(pkg.version, range)) {
117
+ throw new (_diagnostic().default)({
118
+ diagnostic: {
119
+ message: (0, _diagnostic().md)`Could not install the peer dependency "${name}" for "${module.name}", installed version ${pkg.version} is incompatible with ${range}`,
120
+ origin: '@atlaspack/package-manager',
121
+ codeFrames: [{
122
+ filePath: conflicts.filePath,
123
+ language: 'json',
124
+ code: conflicts.json,
125
+ codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(conflicts.json, conflicts.fields.map(field => ({
126
+ key: `/${field}/${(0, _diagnostic().encodeJSONKeyComponent)(name)}`,
127
+ type: 'key',
128
+ message: 'Found this conflicting local requirement.'
129
+ })))
130
+ }]
131
+ }
132
+ });
133
+ }
134
+ continue;
135
+ }
136
+ modules.push({
137
+ name,
138
+ range
139
+ });
140
+ }
141
+ if (modules.length) {
142
+ await install(fs, packageManager, modules, from, projectRoot, Object.assign({}, options, {
143
+ installPeers: false
144
+ }));
145
+ }
146
+ }
147
+ async function determinePackageInstaller(fs, filepath, projectRoot) {
148
+ var _getCurrentPackageMan;
149
+ let configFile = await (0, _utils().resolveConfig)(fs, filepath, ['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock'], projectRoot);
150
+ let configName = configFile && _path().default.basename(configFile);
151
+
152
+ // Always use the package manager that seems to be used in the project,
153
+ // falling back to a different one wouldn't update the existing lockfile.
154
+ if (configName === 'package-lock.json') {
155
+ return new _Npm.Npm();
156
+ } else if (configName === 'pnpm-lock.yaml') {
157
+ return new _Pnpm.Pnpm();
158
+ } else if (configName === 'yarn.lock') {
159
+ return new _Yarn.Yarn();
160
+ }
161
+ let currentPackageManager = (_getCurrentPackageMan = (0, _getCurrentPackageManager.default)()) === null || _getCurrentPackageMan === void 0 ? void 0 : _getCurrentPackageMan.name;
162
+ if (currentPackageManager === 'npm') {
163
+ return new _Npm.Npm();
164
+ } else if (currentPackageManager === 'yarn') {
165
+ return new _Yarn.Yarn();
166
+ } else if (currentPackageManager === 'pnpm') {
167
+ return new _Pnpm.Pnpm();
168
+ }
169
+ if (await _Yarn.Yarn.exists()) {
170
+ return new _Yarn.Yarn();
171
+ } else if (await _Pnpm.Pnpm.exists()) {
172
+ return new _Pnpm.Pnpm();
173
+ } else {
174
+ return new _Npm.Npm();
175
+ }
176
+ }
177
+ let queue = new (_utils().PromiseQueue)({
178
+ maxConcurrent: 1
179
+ });
180
+ let modulesInstalling = new Set();
181
+
182
+ // Exported so that it may be invoked from the worker api below.
183
+ // Do not call this directly! This can result in concurrent package installations
184
+ // across multiple instances of the package manager.
185
+ function _addToInstallQueue(fs, packageManager, modules, filePath, projectRoot, options) {
186
+ modules = modules.map(request => ({
187
+ name: (0, _validateModuleSpecifier.default)(request.name),
188
+ range: request.range
189
+ }));
190
+
191
+ // Wrap PromiseQueue and track modules that are currently installing.
192
+ // If a request comes in for a module that is currently installing, don't bother
193
+ // enqueuing it.
194
+ let modulesToInstall = modules.filter(m => !modulesInstalling.has(getModuleRequestKey(m)));
195
+ if (modulesToInstall.length) {
196
+ for (let m of modulesToInstall) {
197
+ modulesInstalling.add(getModuleRequestKey(m));
198
+ }
199
+ queue.add(() => install(fs, packageManager, modulesToInstall, filePath, projectRoot, options).then(() => {
200
+ for (let m of modulesToInstall) {
201
+ modulesInstalling.delete(getModuleRequestKey(m));
202
+ }
203
+ }));
204
+ }
205
+ return queue.run();
206
+ }
207
+ function installPackage(fs, packageManager, modules, filePath, projectRoot, options) {
208
+ if (_workers().default.isWorker()) {
209
+ let workerApi = _workers().default.getWorkerApi();
210
+ // TODO this should really be `__filename` but without the rewriting.
211
+ let bundlePath = process.env.ATLASPACK_BUILD_ENV === 'production' && !process.env.ATLASPACK_SELF_BUILD ? _path().default.join(__dirname, '..', 'lib/index.js') : __filename;
212
+ return workerApi.callMaster({
213
+ location: bundlePath,
214
+ args: [fs, packageManager, modules, filePath, projectRoot, options],
215
+ method: '_addToInstallQueue'
216
+ });
217
+ }
218
+ return _addToInstallQueue(fs, packageManager, modules, filePath, projectRoot, options);
219
+ }
220
+ function getModuleRequestKey(moduleRequest) {
221
+ return [moduleRequest.name, moduleRequest.range].join('@');
222
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.defaultNodejsConditions = void 0;
7
+ exports.getConditionsFromEnv = getConditionsFromEnv;
8
+ function _process() {
9
+ const data = _interopRequireDefault(require("process"));
10
+ _process = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ // https://nodejs.org/api/packages.html#conditional-exports
17
+ // TODO We don't support { "type": "module" }
18
+ const defaultNodejsConditions = exports.defaultNodejsConditions = Object.freeze(['node-addons', 'node',
19
+ // 'import',
20
+ 'require', 'module-sync', 'default']);
21
+ let envConditions = undefined;
22
+
23
+ /** @description Gets the export conditions from NODE_OPTIONS and node arguments */
24
+ function getConditionsFromEnv() {
25
+ if (!envConditions) {
26
+ const conditions = [];
27
+ for (const arg of [..._process().default.execArgv, ...(_process().default.env.NODE_OPTIONS || '').split(' ')]) {
28
+ if (arg.startsWith('--conditions=')) {
29
+ conditions.push(arg.substring(13));
30
+ }
31
+ }
32
+ envConditions = Object.freeze([...conditions, ...defaultNodejsConditions]);
33
+ }
34
+ return envConditions;
35
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = promiseFromProcess;
7
+ function promiseFromProcess(childProcess) {
8
+ return new Promise((resolve, reject) => {
9
+ childProcess.on('error', reject);
10
+ childProcess.on('close', code => {
11
+ if (code !== 0) {
12
+ reject(new Error('Child process failed'));
13
+ return;
14
+ }
15
+ resolve();
16
+ });
17
+ });
18
+ }
package/lib/utils.js ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.exec = void 0;
7
+ exports.getConflictingLocalDependencies = getConflictingLocalDependencies;
8
+ exports.moduleRequestsFromDependencyMap = moduleRequestsFromDependencyMap;
9
+ exports.npmSpecifierFromModuleRequest = npmSpecifierFromModuleRequest;
10
+ function _assert() {
11
+ const data = _interopRequireDefault(require("assert"));
12
+ _assert = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _diagnostic() {
18
+ const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
19
+ _diagnostic = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _utils() {
25
+ const data = require("@atlaspack/utils");
26
+ _utils = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _child_process() {
32
+ const data = require("child_process");
33
+ _child_process = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _util() {
39
+ const data = require("util");
40
+ _util = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
+ const exec = exports.exec = _child_process().exec ? (0, _util().promisify)(_child_process().exec) :
47
+ // _exec is undefined in browser builds
48
+ _child_process().exec;
49
+ function npmSpecifierFromModuleRequest(moduleRequest) {
50
+ return moduleRequest.range != null ? [moduleRequest.name, moduleRequest.range].join('@') : moduleRequest.name;
51
+ }
52
+ function moduleRequestsFromDependencyMap(dependencyMap) {
53
+ return Object.entries(dependencyMap).map(([name, range]) => {
54
+ (0, _assert().default)(typeof range === 'string');
55
+ return {
56
+ name,
57
+ range
58
+ };
59
+ });
60
+ }
61
+ async function getConflictingLocalDependencies(fs, name, local, projectRoot) {
62
+ let pkgPath = await (0, _utils().resolveConfig)(fs, local, ['package.json'], projectRoot);
63
+ if (pkgPath == null) {
64
+ return;
65
+ }
66
+ let pkgStr = await fs.readFile(pkgPath, 'utf8');
67
+ let pkg;
68
+ try {
69
+ pkg = JSON.parse(pkgStr);
70
+ } catch (e) {
71
+ // TODO: codeframe
72
+ throw new (_diagnostic().default)({
73
+ diagnostic: {
74
+ message: 'Failed to parse package.json',
75
+ origin: '@atlaspack/package-manager'
76
+ }
77
+ });
78
+ }
79
+ if (typeof pkg !== 'object' || pkg == null) {
80
+ // TODO: codeframe
81
+ throw new (_diagnostic().default)({
82
+ diagnostic: {
83
+ message: 'Expected package.json contents to be an object.',
84
+ origin: '@atlaspack/package-manager'
85
+ }
86
+ });
87
+ }
88
+ let fields = [];
89
+ for (let field of ['dependencies', 'devDependencies', 'peerDependencies']) {
90
+ if (typeof pkg[field] === 'object' && pkg[field] != null && pkg[field][name] != null) {
91
+ fields.push(field);
92
+ }
93
+ }
94
+ if (fields.length > 0) {
95
+ return {
96
+ filePath: pkgPath,
97
+ json: pkgStr,
98
+ fields
99
+ };
100
+ }
101
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = validateModuleSpecifier;
7
+ const MODULE_REGEX = /^((@[^/\s]+\/){0,1}([^/\s.~]+[^/\s]*)){1}(@[^/\s]+){0,1}/;
8
+ function validateModuleSpecifier(moduleName) {
9
+ let matches = MODULE_REGEX.exec(moduleName);
10
+ if (matches) {
11
+ return matches[0];
12
+ }
13
+ return '';
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/package-manager",
3
- "version": "2.14.18-noselfbuild-3f2849b52.0",
3
+ "version": "2.14.18-noselfbuild-342bd6c75.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -39,21 +39,19 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@atlaspack/build-cache": "2.13.4-noselfbuild-3f2849b52.0",
43
- "@atlaspack/diagnostic": "2.14.2-noselfbuild-3f2849b52.0",
44
- "@atlaspack/fs": "2.15.13-noselfbuild-3f2849b52.0",
45
- "@atlaspack/logger": "2.14.13-noselfbuild-3f2849b52.0",
46
- "@atlaspack/node-resolver-core": "3.5.18-noselfbuild-3f2849b52.0",
47
- "@atlaspack/types": "2.15.8-noselfbuild-3f2849b52.0",
48
- "@atlaspack/utils": "2.16.2-noselfbuild-3f2849b52.0",
49
- "@atlaspack/workers": "2.14.18-noselfbuild-3f2849b52.0",
42
+ "@atlaspack/build-cache": "2.13.4-noselfbuild-342bd6c75.0",
43
+ "@atlaspack/diagnostic": "2.14.2-noselfbuild-342bd6c75.0",
44
+ "@atlaspack/fs": "2.15.13-noselfbuild-342bd6c75.0",
45
+ "@atlaspack/logger": "2.14.13-noselfbuild-342bd6c75.0",
46
+ "@atlaspack/node-resolver-core": "3.5.18-noselfbuild-342bd6c75.0",
47
+ "@atlaspack/types": "2.15.8-noselfbuild-342bd6c75.0",
48
+ "@atlaspack/utils": "2.16.2-noselfbuild-342bd6c75.0",
49
+ "@atlaspack/workers": "2.14.18-noselfbuild-342bd6c75.0",
50
50
  "@swc/core": "^1.10.0",
51
- "semver": "^7.5.2"
52
- },
53
- "devDependencies": {
54
51
  "command-exists": "^1.2.6",
55
52
  "cross-spawn": "^6.0.4",
56
53
  "nullthrows": "^1.1.1",
54
+ "semver": "^7.5.2",
57
55
  "split2": "^3.1.1"
58
56
  },
59
57
  "browser": {
@@ -63,5 +61,5 @@
63
61
  "./src/Yarn.js": false
64
62
  },
65
63
  "type": "commonjs",
66
- "gitHead": "3f2849b52d0a62d716f1c6cb3a92656e1e4fa18a"
64
+ "gitHead": "342bd6c75293750e0f0a7636ddc8dfe30707efb6"
67
65
  }
@@ -41,14 +41,10 @@ import {transformSync} from '@swc/core';
41
41
  // Package.json fields. Must match package_json.rs.
42
42
  const MAIN = 1 << 0;
43
43
  const SOURCE = 1 << 2;
44
- const ENTRIES =
45
- process.env.ATLASPACK_REGISTER_USE_LIB === 'true'
46
- ? MAIN
47
- : MAIN |
48
- (process.env.ATLASPACK_BUILD_ENV !== 'production' ||
49
- process.env.ATLASPACK_SELF_BUILD
50
- ? SOURCE
51
- : 0);
44
+ let ENTRIES = MAIN;
45
+ if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
46
+ ENTRIES |= SOURCE;
47
+ }
52
48
 
53
49
  const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
54
50
 
@@ -12,6 +12,7 @@ import {WORKER_PATH} from '@atlaspack/core';
12
12
  import {MockPackageInstaller, NodePackageManager} from '../src';
13
13
 
14
14
  const FIXTURES_DIR = path.join(__dirname, 'fixtures');
15
+ const ROOT_DIR = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
15
16
 
16
17
  function normalize(res) {
17
18
  return {
@@ -76,6 +77,7 @@ describe('NodePackageManager', function () {
76
77
  type: 1,
77
78
  invalidateOnFileChange: new Set([
78
79
  path.join(FIXTURES_DIR, 'has-foo/node_modules/foo/package.json'),
80
+ path.join(ROOT_DIR, 'tsconfig.json'),
79
81
  ]),
80
82
  invalidateOnFileCreate: [
81
83
  {
@@ -130,6 +132,7 @@ describe('NodePackageManager', function () {
130
132
  type: 1,
131
133
  invalidateOnFileChange: new Set([
132
134
  path.join(FIXTURES_DIR, 'has-foo/node_modules/a/package.json'),
135
+ path.join(ROOT_DIR, 'tsconfig.json'),
133
136
  ]),
134
137
  invalidateOnFileCreate: [
135
138
  {
@@ -302,6 +305,7 @@ describe('NodePackageManager', function () {
302
305
  FIXTURES_DIR,
303
306
  'has-foo/subpackage/node_modules/foo/package.json',
304
307
  ),
308
+ path.join(ROOT_DIR, 'tsconfig.json'),
305
309
  ]),
306
310
  invalidateOnFileCreate: [
307
311
  {