@atlaspack/package-manager 2.14.21 → 2.14.22-typescript-17c3d1dec.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.
- package/LICENSE +201 -0
- package/lib/JSONParseStream.d.ts +6 -0
- package/lib/JSONParseStream.js +1 -2
- package/lib/MockPackageInstaller.d.ts +14 -0
- package/lib/NodePackageManager.d.ts +36 -0
- package/lib/NodePackageManager.js +44 -24
- package/lib/Npm.d.ts +4 -0
- package/lib/Npm.js +2 -1
- package/lib/Pnpm.d.ts +5 -0
- package/lib/Pnpm.js +18 -4
- package/lib/Yarn.d.ts +5 -0
- package/lib/Yarn.js +17 -3
- package/lib/getCurrentPackageManager.d.ts +4 -0
- package/lib/getCurrentPackageManager.js +3 -1
- package/lib/index.d.ts +8 -8
- package/lib/installPackage.d.ts +5 -0
- package/lib/installPackage.js +1 -0
- package/lib/nodejsConditions.d.ts +3 -0
- package/lib/nodejsConditions.js +6 -0
- package/lib/promiseFromProcess.d.ts +2 -0
- package/lib/promiseFromProcess.js +2 -0
- package/lib/utils.d.ts +15 -0
- package/lib/validateModuleSpecifier.d.ts +1 -0
- package/package.json +17 -17
- package/src/{JSONParseStream.js → JSONParseStream.ts} +8 -7
- package/src/{MockPackageInstaller.js → MockPackageInstaller.ts} +4 -6
- package/src/{NodePackageManager.js → NodePackageManager.ts} +72 -51
- package/src/{Npm.js → Npm.ts} +9 -9
- package/src/{Pnpm.js → Pnpm.ts} +68 -50
- package/src/{Yarn.js → Yarn.ts} +38 -25
- package/src/{getCurrentPackageManager.js → getCurrentPackageManager.ts} +9 -4
- package/src/{index.js → index.ts} +0 -2
- package/src/{installPackage.js → installPackage.ts} +5 -6
- package/src/{nodejsConditions.js → nodejsConditions.ts} +6 -3
- package/src/promiseFromProcess.ts +23 -0
- package/src/{utils.js → utils.ts} +21 -11
- package/src/{validateModuleSpecifier.js → validateModuleSpecifier.ts} +0 -2
- package/test/{NodePackageManager.test.js → NodePackageManager.test.ts} +13 -15
- package/test/{getCurrentPackageManager.test.js → getCurrentPackageManager.test.ts} +0 -1
- package/test/{validateModuleSpecifiers.test.js → validateModuleSpecifiers.test.ts} +2 -3
- package/tsconfig.json +4 -0
- package/index.d.ts +0 -40
- package/src/promiseFromProcess.js +0 -19
package/lib/index.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import type { PackageManagerResolveResult } from
|
2
|
-
export type { PackageManager, Invalidations, PackageInstaller, ModuleRequest } from
|
3
|
-
export * from
|
4
|
-
export * from
|
5
|
-
export * from
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export { _addToInstallQueue } from
|
1
|
+
import type { PackageManagerResolveResult } from '@atlaspack/types';
|
2
|
+
export type { PackageManager, Invalidations, PackageInstaller, ModuleRequest, } from '@atlaspack/types';
|
3
|
+
export * from './Npm';
|
4
|
+
export * from './Pnpm';
|
5
|
+
export * from './Yarn';
|
6
|
+
export * from './MockPackageInstaller';
|
7
|
+
export * from './NodePackageManager';
|
8
|
+
export { _addToInstallQueue } from './installPackage';
|
9
9
|
export type { PackageManagerResolveResult };
|
10
10
|
export type { PackageManagerResolveResult as ResolveResult };
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { FilePath } from '@atlaspack/types';
|
2
|
+
import type { ModuleRequest, PackageManager, InstallOptions } from '@atlaspack/types';
|
3
|
+
import type { FileSystem } from '@atlaspack/fs';
|
4
|
+
export declare function _addToInstallQueue(fs: FileSystem, packageManager: PackageManager, modules: Array<ModuleRequest>, filePath: FilePath, projectRoot: FilePath, options?: InstallOptions): Promise<unknown>;
|
5
|
+
export declare function installPackage(fs: FileSystem, packageManager: PackageManager, modules: Array<ModuleRequest>, filePath: FilePath, projectRoot: FilePath, options?: InstallOptions): Promise<unknown>;
|
package/lib/installPackage.js
CHANGED
@@ -116,6 +116,7 @@ async function installPeerDependencies(fs, packageManager, module, from, project
|
|
116
116
|
if (!_semver().default.satisfies(pkg.version, range)) {
|
117
117
|
throw new (_diagnostic().default)({
|
118
118
|
diagnostic: {
|
119
|
+
// @ts-expect-error TS2345
|
119
120
|
message: (0, _diagnostic().md)`Could not install the peer dependency "${name}" for "${module.name}", installed version ${pkg.version} is incompatible with ${range}`,
|
120
121
|
origin: '@atlaspack/package-manager',
|
121
122
|
codeFrames: [{
|
package/lib/nodejsConditions.js
CHANGED
@@ -15,6 +15,7 @@ function _process() {
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
16
|
// https://nodejs.org/api/packages.html#conditional-exports
|
17
17
|
// TODO We don't support { "type": "module" }
|
18
|
+
// @ts-expect-error TS4104
|
18
19
|
const defaultNodejsConditions = exports.defaultNodejsConditions = Object.freeze(['node-addons', 'node',
|
19
20
|
// 'import',
|
20
21
|
'require', 'module-sync', 'default']);
|
@@ -26,10 +27,15 @@ function getConditionsFromEnv() {
|
|
26
27
|
const conditions = [];
|
27
28
|
for (const arg of [..._process().default.execArgv, ...(_process().default.env.NODE_OPTIONS || '').split(' ')]) {
|
28
29
|
if (arg.startsWith('--conditions=')) {
|
30
|
+
// @ts-expect-error TS2345
|
29
31
|
conditions.push(arg.substring(13));
|
30
32
|
}
|
31
33
|
}
|
34
|
+
|
35
|
+
// @ts-expect-error TS4104
|
32
36
|
envConditions = Object.freeze([...conditions, ...defaultNodejsConditions]);
|
33
37
|
}
|
38
|
+
|
39
|
+
// @ts-expect-error TS2322
|
34
40
|
return envConditions;
|
35
41
|
}
|
package/lib/utils.d.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { FilePath, ModuleRequest } from '@atlaspack/types';
|
2
|
+
import type { FileSystem } from '@atlaspack/fs';
|
3
|
+
export declare const exec: (command: string, options?: child_process.execOpts) => Promise<{
|
4
|
+
stdout: string | Buffer;
|
5
|
+
stderr: string | Buffer;
|
6
|
+
}>;
|
7
|
+
export declare function npmSpecifierFromModuleRequest(moduleRequest: ModuleRequest): string;
|
8
|
+
export declare function moduleRequestsFromDependencyMap(dependencyMap: {
|
9
|
+
[key: string]: string;
|
10
|
+
}): Array<ModuleRequest>;
|
11
|
+
export declare function getConflictingLocalDependencies(fs: FileSystem, name: string, local: FilePath, projectRoot: FilePath): Promise<{
|
12
|
+
json: string;
|
13
|
+
filePath: FilePath;
|
14
|
+
fields: Array<string>;
|
15
|
+
} | null | undefined>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export default function validateModuleSpecifier(moduleName: string): string;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/package-manager",
|
3
|
-
"version": "2.14.
|
3
|
+
"version": "2.14.22-typescript-17c3d1dec.0",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
6
6
|
"publishConfig": {
|
@@ -10,15 +10,14 @@
|
|
10
10
|
"type": "git",
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
12
12
|
},
|
13
|
-
"main": "lib/index.js",
|
14
|
-
"source": "src/index.
|
15
|
-
"types": "index.d.ts",
|
13
|
+
"main": "./lib/index.js",
|
14
|
+
"source": "./src/index.ts",
|
15
|
+
"types": "./lib/index.d.ts",
|
16
16
|
"engines": {
|
17
17
|
"node": ">= 16.0.0"
|
18
18
|
},
|
19
19
|
"scripts": {
|
20
|
-
"
|
21
|
-
"check-ts": "tsc --noEmit index.d.ts",
|
20
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src",
|
22
21
|
"test": "mocha test"
|
23
22
|
},
|
24
23
|
"targets": {
|
@@ -39,19 +38,19 @@
|
|
39
38
|
}
|
40
39
|
},
|
41
40
|
"dependencies": {
|
42
|
-
"@atlaspack/build-cache": "2.13.
|
43
|
-
"@atlaspack/diagnostic": "2.14.
|
44
|
-
"@atlaspack/fs": "2.15.
|
45
|
-
"@atlaspack/logger": "2.14.
|
46
|
-
"@atlaspack/node-resolver-core": "3.5.
|
47
|
-
"@atlaspack/types": "2.15.
|
48
|
-
"@atlaspack/utils": "2.17.
|
49
|
-
"@atlaspack/workers": "2.14.
|
41
|
+
"@atlaspack/build-cache": "2.13.4-typescript-17c3d1dec.0",
|
42
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-17c3d1dec.0",
|
43
|
+
"@atlaspack/fs": "2.15.17-typescript-17c3d1dec.0",
|
44
|
+
"@atlaspack/logger": "2.14.14-typescript-17c3d1dec.0",
|
45
|
+
"@atlaspack/node-resolver-core": "3.5.22-typescript-17c3d1dec.0",
|
46
|
+
"@atlaspack/types": "2.15.12-typescript-17c3d1dec.0",
|
47
|
+
"@atlaspack/utils": "2.17.4-typescript-17c3d1dec.0",
|
48
|
+
"@atlaspack/workers": "2.14.22-typescript-17c3d1dec.0",
|
50
49
|
"@swc/core": "^1.10.0",
|
51
|
-
"semver": "^7.5.2",
|
52
50
|
"command-exists": "^1.2.6",
|
53
51
|
"cross-spawn": "^6.0.4",
|
54
52
|
"nullthrows": "^1.1.1",
|
53
|
+
"semver": "^7.5.2",
|
55
54
|
"split2": "^3.1.1"
|
56
55
|
},
|
57
56
|
"browser": {
|
@@ -60,5 +59,6 @@
|
|
60
59
|
"./src/Pnpm.js": false,
|
61
60
|
"./src/Yarn.js": false
|
62
61
|
},
|
63
|
-
"type": "commonjs"
|
64
|
-
|
62
|
+
"type": "commonjs",
|
63
|
+
"gitHead": "17c3d1decf641e688fcfe3ca985e80e9897b7573"
|
64
|
+
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
|
3
1
|
import type {JSONObject} from '@atlaspack/types';
|
4
2
|
|
5
3
|
import logger from '@atlaspack/logger';
|
@@ -8,21 +6,24 @@ import {Transform} from 'stream';
|
|
8
6
|
// Transforms chunks of json strings to parsed objects.
|
9
7
|
// Pair with split2 to parse stream of newline-delimited text.
|
10
8
|
export default class JSONParseStream extends Transform {
|
11
|
-
constructor(options:
|
9
|
+
constructor(options: unknown) {
|
10
|
+
// @ts-expect-error TS2698
|
12
11
|
super({...options, objectMode: true});
|
13
12
|
}
|
14
13
|
|
15
|
-
// $FlowFixMe We are in object mode, so we emit objects, not strings
|
16
14
|
_transform(
|
17
15
|
chunk: Buffer | string,
|
18
16
|
encoding: string,
|
19
|
-
callback: (
|
17
|
+
callback: (
|
18
|
+
err?: Error | null | undefined,
|
19
|
+
parsed?: JSONObject | null | undefined,
|
20
|
+
) => unknown,
|
20
21
|
) {
|
21
22
|
try {
|
22
23
|
let parsed;
|
23
24
|
try {
|
24
25
|
parsed = JSON.parse(chunk.toString());
|
25
|
-
} catch (e) {
|
26
|
+
} catch (e: any) {
|
26
27
|
// Be permissive and ignoreJSON parse errors in case there was
|
27
28
|
// a non-JSON line in the package manager's stdout.
|
28
29
|
logger.verbose({
|
@@ -32,7 +33,7 @@ export default class JSONParseStream extends Transform {
|
|
32
33
|
return;
|
33
34
|
}
|
34
35
|
callback(null, parsed);
|
35
|
-
} catch (err) {
|
36
|
+
} catch (err: any) {
|
36
37
|
callback(err);
|
37
38
|
}
|
38
39
|
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
// @flow
|
2
|
-
|
3
1
|
import type {
|
4
2
|
ModuleRequest,
|
5
3
|
PackageInstaller,
|
@@ -14,10 +12,10 @@ import {ncp} from '@atlaspack/fs';
|
|
14
12
|
import pkg from '../package.json';
|
15
13
|
import {moduleRequestsFromDependencyMap} from './utils';
|
16
14
|
|
17
|
-
type Package = {
|
18
|
-
fs: FileSystem
|
19
|
-
packagePath: FilePath
|
20
|
-
|
15
|
+
type Package = {
|
16
|
+
fs: FileSystem;
|
17
|
+
packagePath: FilePath;
|
18
|
+
};
|
21
19
|
|
22
20
|
// This PackageInstaller implementation simply copies files from one filesystem to another.
|
23
21
|
// Mostly useful for testing purposes.
|
@@ -1,4 +1,3 @@
|
|
1
|
-
// @flow
|
2
1
|
import type {
|
3
2
|
FilePath,
|
4
3
|
DependencySpecifier,
|
@@ -62,25 +61,27 @@ const invalidationsCache = new Map<string, Invalidations>();
|
|
62
61
|
export class NodePackageManager implements PackageManager {
|
63
62
|
fs: FileSystem;
|
64
63
|
projectRoot: FilePath;
|
65
|
-
installer:
|
64
|
+
installer: PackageInstaller | null | undefined;
|
65
|
+
// @ts-expect-error TS2749
|
66
66
|
resolver: ResolverBase;
|
67
67
|
currentExtensions: Array<string>;
|
68
68
|
|
69
69
|
constructor(
|
70
70
|
fs: FileSystem,
|
71
71
|
projectRoot: FilePath,
|
72
|
-
installer?:
|
72
|
+
installer?: PackageInstaller | null,
|
73
73
|
) {
|
74
74
|
this.fs = fs;
|
75
75
|
this.projectRoot = projectRoot;
|
76
76
|
this.installer = installer;
|
77
77
|
|
78
|
-
//
|
78
|
+
// @ts-expect-error TS2339
|
79
79
|
this.currentExtensions = Object.keys(Module._extensions).map((e) =>
|
80
80
|
e.substring(1),
|
81
81
|
);
|
82
82
|
}
|
83
83
|
|
84
|
+
// @ts-expect-error TS2749
|
84
85
|
_createResolver(): ResolverBase {
|
85
86
|
return new ResolverBase(this.projectRoot, {
|
86
87
|
fs:
|
@@ -97,8 +98,8 @@ export class NodePackageManager implements PackageManager {
|
|
97
98
|
packageExports: true,
|
98
99
|
moduleDirResolver:
|
99
100
|
process.versions.pnp != null
|
100
|
-
? (module, from) => {
|
101
|
-
//
|
101
|
+
? (module: any, from: any) => {
|
102
|
+
// @ts-expect-error TS2339
|
102
103
|
let pnp = Module.findPnpApi(path.dirname(from));
|
103
104
|
|
104
105
|
return pnp.resolveToUnqualified(
|
@@ -117,12 +118,12 @@ export class NodePackageManager implements PackageManager {
|
|
117
118
|
return new NodePackageManager(opts.fs, opts.projectRoot, opts.installer);
|
118
119
|
}
|
119
120
|
|
120
|
-
serialize(): {
|
121
|
-
$$raw: boolean
|
122
|
-
fs: FileSystem
|
123
|
-
projectRoot: FilePath
|
124
|
-
installer:
|
125
|
-
|
121
|
+
serialize(): {
|
122
|
+
$$raw: boolean;
|
123
|
+
fs: FileSystem;
|
124
|
+
projectRoot: FilePath;
|
125
|
+
installer: PackageInstaller | null | undefined;
|
126
|
+
} {
|
126
127
|
return {
|
127
128
|
$$raw: false,
|
128
129
|
fs: this.fs,
|
@@ -134,11 +135,11 @@ export class NodePackageManager implements PackageManager {
|
|
134
135
|
async require(
|
135
136
|
name: DependencySpecifier,
|
136
137
|
from: FilePath,
|
137
|
-
opts
|
138
|
-
range?:
|
139
|
-
shouldAutoInstall?: boolean
|
140
|
-
saveDev?: boolean
|
141
|
-
|
|
138
|
+
opts?: {
|
139
|
+
range?: SemverRange | null | undefined;
|
140
|
+
shouldAutoInstall?: boolean;
|
141
|
+
saveDev?: boolean;
|
142
|
+
} | null,
|
142
143
|
): Promise<any> {
|
143
144
|
let {resolved, type} = await this.resolve(name, from, opts);
|
144
145
|
if (type === 2) {
|
@@ -155,10 +156,10 @@ export class NodePackageManager implements PackageManager {
|
|
155
156
|
|
156
157
|
// On Windows, Node requires absolute paths to be file URLs.
|
157
158
|
if (process.platform === 'win32' && path.isAbsolute(resolved)) {
|
159
|
+
// @ts-expect-error TS2322
|
158
160
|
resolved = pathToFileURL(resolved);
|
159
161
|
}
|
160
162
|
|
161
|
-
// $FlowFixMe
|
162
163
|
return import(resolved);
|
163
164
|
}
|
164
165
|
return this.load(resolved, from);
|
@@ -172,20 +173,19 @@ export class NodePackageManager implements PackageManager {
|
|
172
173
|
load(filePath: FilePath, from: FilePath): any {
|
173
174
|
if (!path.isAbsolute(filePath)) {
|
174
175
|
// Node builtin module
|
175
|
-
// $FlowFixMe
|
176
176
|
return require(filePath);
|
177
177
|
}
|
178
178
|
|
179
|
-
//
|
179
|
+
// @ts-expect-error TS2339
|
180
180
|
const cachedModule = Module._cache[filePath];
|
181
181
|
if (cachedModule !== undefined) {
|
182
182
|
return cachedModule.exports;
|
183
183
|
}
|
184
184
|
|
185
|
-
//
|
185
|
+
// @ts-expect-error TS2339
|
186
186
|
let m = new Module(filePath, Module._cache[from] || module.parent);
|
187
187
|
|
188
|
-
//
|
188
|
+
// @ts-expect-error TS2339
|
189
189
|
const extensions = Object.keys(Module._extensions);
|
190
190
|
// This handles supported extensions changing due to, for example, esbuild/register being used
|
191
191
|
// We assume that the extension list will change in size - as these tools usually add support for
|
@@ -195,23 +195,23 @@ export class NodePackageManager implements PackageManager {
|
|
195
195
|
this.resolver = this._createResolver();
|
196
196
|
}
|
197
197
|
|
198
|
-
//
|
198
|
+
// @ts-expect-error TS2339
|
199
199
|
Module._cache[filePath] = m;
|
200
200
|
|
201
201
|
// Patch require within this module so it goes through our require
|
202
|
-
m.require = (id) => {
|
202
|
+
m.require = (id: any) => {
|
203
203
|
return this.requireSync(id, filePath);
|
204
204
|
};
|
205
205
|
|
206
206
|
// Patch `fs.readFileSync` temporarily so that it goes through our file system
|
207
207
|
let {readFileSync, statSync} = nativeFS;
|
208
|
-
//
|
209
|
-
nativeFS.readFileSync = (filename, encoding) => {
|
208
|
+
// @ts-expect-error TS2322
|
209
|
+
nativeFS.readFileSync = (filename: any, encoding: any) => {
|
210
210
|
return this.fs.readFileSync(filename, encoding);
|
211
211
|
};
|
212
212
|
|
213
|
-
//
|
214
|
-
nativeFS.statSync = (filename) => {
|
213
|
+
// @ts-expect-error TS2540
|
214
|
+
nativeFS.statSync = (filename: any) => {
|
215
215
|
return this.fs.statSync(filename);
|
216
216
|
};
|
217
217
|
|
@@ -222,35 +222,37 @@ export class NodePackageManager implements PackageManager {
|
|
222
222
|
extname === '.tsx' ||
|
223
223
|
extname === '.mts' ||
|
224
224
|
extname === '.cts') &&
|
225
|
-
//
|
225
|
+
// @ts-expect-error TS2339
|
226
226
|
!Module._extensions[extname]
|
227
227
|
) {
|
228
|
+
// @ts-expect-error TS2339
|
228
229
|
let compile = m._compile;
|
229
|
-
|
230
|
+
// @ts-expect-error TS2339
|
231
|
+
m._compile = (code: any, filename: any) => {
|
230
232
|
let out = transformSync(code, {filename, module: {type: 'commonjs'}});
|
231
233
|
compile.call(m, out.code, filename);
|
232
234
|
};
|
233
235
|
|
234
|
-
//
|
235
|
-
Module._extensions[extname] = (m, filename) => {
|
236
|
-
//
|
236
|
+
// @ts-expect-error TS2339
|
237
|
+
Module._extensions[extname] = (m: any, filename: any) => {
|
238
|
+
// @ts-expect-error TS2339
|
237
239
|
delete Module._extensions[extname];
|
238
|
-
//
|
240
|
+
// @ts-expect-error TS2339
|
239
241
|
Module._extensions['.js'](m, filename);
|
240
242
|
};
|
241
243
|
}
|
242
244
|
}
|
243
245
|
|
244
246
|
try {
|
247
|
+
// @ts-expect-error TS2339
|
245
248
|
m.load(filePath);
|
246
|
-
} catch (err) {
|
247
|
-
//
|
249
|
+
} catch (err: any) {
|
250
|
+
// @ts-expect-error TS2339
|
248
251
|
delete Module._cache[filePath];
|
249
252
|
throw err;
|
250
253
|
} finally {
|
251
|
-
// $FlowFixMe
|
252
254
|
nativeFS.readFileSync = readFileSync;
|
253
|
-
//
|
255
|
+
// @ts-expect-error TS2540
|
254
256
|
nativeFS.statSync = statSync;
|
255
257
|
}
|
256
258
|
|
@@ -260,11 +262,11 @@ export class NodePackageManager implements PackageManager {
|
|
260
262
|
async resolve(
|
261
263
|
id: DependencySpecifier,
|
262
264
|
from: FilePath,
|
263
|
-
options?:
|
264
|
-
range?:
|
265
|
-
shouldAutoInstall?: boolean
|
266
|
-
saveDev?: boolean
|
267
|
-
|
|
265
|
+
options?: {
|
266
|
+
range?: SemverRange | null | undefined;
|
267
|
+
shouldAutoInstall?: boolean;
|
268
|
+
saveDev?: boolean;
|
269
|
+
} | null,
|
268
270
|
): Promise<PackageManagerResolveResult> {
|
269
271
|
let basedir = path.dirname(from);
|
270
272
|
let key = basedir + ':' + id;
|
@@ -273,7 +275,7 @@ export class NodePackageManager implements PackageManager {
|
|
273
275
|
let [name] = getModuleParts(id);
|
274
276
|
try {
|
275
277
|
resolved = this.resolveInternal(id, from);
|
276
|
-
} catch (e) {
|
278
|
+
} catch (e: any) {
|
277
279
|
if (
|
278
280
|
e.code !== 'MODULE_NOT_FOUND' ||
|
279
281
|
options?.shouldAutoInstall !== true ||
|
@@ -291,7 +293,7 @@ export class NodePackageManager implements PackageManager {
|
|
291
293
|
],
|
292
294
|
},
|
293
295
|
});
|
294
|
-
//
|
296
|
+
// @ts-expect-error TS2339
|
295
297
|
err.code = 'MODULE_NOT_FOUND';
|
296
298
|
throw err;
|
297
299
|
} else {
|
@@ -320,6 +322,7 @@ export class NodePackageManager implements PackageManager {
|
|
320
322
|
|
321
323
|
throw new ThrowableDiagnostic({
|
322
324
|
diagnostic: conflicts.fields.map((field) => ({
|
325
|
+
// @ts-expect-error TS2345
|
323
326
|
message: md`Could not find module "${name}", but it was listed in package.json. Run your package manager first.`,
|
324
327
|
origin: '@atlaspack/package-manager',
|
325
328
|
codeFrames: [
|
@@ -361,6 +364,7 @@ export class NodePackageManager implements PackageManager {
|
|
361
364
|
} else if (conflicts != null) {
|
362
365
|
throw new ThrowableDiagnostic({
|
363
366
|
diagnostic: {
|
367
|
+
// @ts-expect-error TS2345
|
364
368
|
message: md`Could not find module "${name}" satisfying ${range}.`,
|
365
369
|
origin: '@atlaspack/package-manager',
|
366
370
|
codeFrames: [
|
@@ -383,8 +387,10 @@ export class NodePackageManager implements PackageManager {
|
|
383
387
|
}
|
384
388
|
|
385
389
|
let version = pkg?.version;
|
390
|
+
// @ts-expect-error TS2345
|
386
391
|
let message = md`Could not resolve package "${name}" that satisfies ${range}.`;
|
387
392
|
if (version != null) {
|
393
|
+
// @ts-expect-error TS2345
|
388
394
|
message += md` Found ${version}.`;
|
389
395
|
}
|
390
396
|
|
@@ -474,7 +480,10 @@ export class NodePackageManager implements PackageManager {
|
|
474
480
|
};
|
475
481
|
|
476
482
|
let seen = new Set();
|
477
|
-
let addKey = (
|
483
|
+
let addKey = (
|
484
|
+
name: DependencySpecifier,
|
485
|
+
from: FilePath | DependencySpecifier,
|
486
|
+
) => {
|
478
487
|
let basedir = path.dirname(from);
|
479
488
|
let key = basedir + ':' + name;
|
480
489
|
if (seen.has(key)) {
|
@@ -487,6 +496,7 @@ export class NodePackageManager implements PackageManager {
|
|
487
496
|
return;
|
488
497
|
}
|
489
498
|
|
499
|
+
// @ts-expect-error TS2345
|
490
500
|
res.invalidateOnFileCreate.push(...resolved.invalidateOnFileCreate);
|
491
501
|
res.invalidateOnFileChange.add(resolved.resolved);
|
492
502
|
|
@@ -508,15 +518,19 @@ export class NodePackageManager implements PackageManager {
|
|
508
518
|
// cannot be intercepted. Instead, ask the resolver to parse the file and recursively analyze the deps.
|
509
519
|
if (resolved.type === 2) {
|
510
520
|
let invalidations = this.resolver.getInvalidations(resolved.resolved);
|
521
|
+
// @ts-expect-error TS7006
|
511
522
|
invalidations.invalidateOnFileChange.forEach((i) =>
|
512
523
|
res.invalidateOnFileChange.add(i),
|
513
524
|
);
|
525
|
+
// @ts-expect-error TS7006
|
514
526
|
invalidations.invalidateOnFileCreate.forEach((i) =>
|
527
|
+
// @ts-expect-error TS2345
|
515
528
|
res.invalidateOnFileCreate.push(i),
|
516
529
|
);
|
517
530
|
res.invalidateOnStartup ||= invalidations.invalidateOnStartup;
|
518
531
|
if (res.invalidateOnStartup) {
|
519
532
|
logger.warn({
|
533
|
+
// @ts-expect-error TS2345
|
520
534
|
message: md`${path.relative(
|
521
535
|
this.projectRoot,
|
522
536
|
resolved.resolved,
|
@@ -526,7 +540,9 @@ export class NodePackageManager implements PackageManager {
|
|
526
540
|
}
|
527
541
|
}
|
528
542
|
|
543
|
+
// @ts-expect-error TS2345
|
529
544
|
invalidationsCache.set(resolved.resolved, res);
|
545
|
+
// @ts-expect-error TS2322
|
530
546
|
return res;
|
531
547
|
}
|
532
548
|
|
@@ -540,7 +556,10 @@ export class NodePackageManager implements PackageManager {
|
|
540
556
|
invalidate(name: DependencySpecifier, from: FilePath) {
|
541
557
|
let seen = new Set();
|
542
558
|
|
543
|
-
let invalidate = (
|
559
|
+
let invalidate = (
|
560
|
+
name: DependencySpecifier,
|
561
|
+
from: FilePath | DependencySpecifier,
|
562
|
+
) => {
|
544
563
|
let basedir = path.dirname(from);
|
545
564
|
let key = basedir + ':' + name;
|
546
565
|
if (seen.has(key)) {
|
@@ -567,10 +586,10 @@ export class NodePackageManager implements PackageManager {
|
|
567
586
|
|
568
587
|
invalidationsCache.delete(resolved.resolved);
|
569
588
|
|
570
|
-
//
|
589
|
+
// @ts-expect-error TS2339
|
571
590
|
let module = Module._cache[resolved.resolved];
|
572
591
|
if (module) {
|
573
|
-
//
|
592
|
+
// @ts-expect-error TS2339
|
574
593
|
delete Module._cache[resolved.resolved];
|
575
594
|
}
|
576
595
|
|
@@ -604,17 +623,18 @@ export class NodePackageManager implements PackageManager {
|
|
604
623
|
// Invalidate whenever the .pnp.js file changes.
|
605
624
|
// TODO: only when we actually resolve a node_modules package?
|
606
625
|
if (process.versions.pnp != null && res.invalidateOnFileChange) {
|
607
|
-
//
|
626
|
+
// @ts-expect-error TS2339
|
608
627
|
let pnp = Module.findPnpApi(path.dirname(from));
|
609
628
|
res.invalidateOnFileChange.push(pnp.resolveToUnqualified('pnpapi', null));
|
610
629
|
}
|
611
630
|
|
612
631
|
if (res.error) {
|
613
632
|
let e = new Error(`Could not resolve module "${name}" from "${from}"`);
|
614
|
-
//
|
633
|
+
// @ts-expect-error TS2339
|
615
634
|
e.code = 'MODULE_NOT_FOUND';
|
616
635
|
throw e;
|
617
636
|
}
|
637
|
+
// @ts-expect-error TS7034
|
618
638
|
let getPkg;
|
619
639
|
switch (res.resolution.type) {
|
620
640
|
case 'Path':
|
@@ -636,6 +656,7 @@ export class NodePackageManager implements PackageManager {
|
|
636
656
|
invalidateOnFileCreate: res.invalidateOnFileCreate,
|
637
657
|
type: res.moduleType,
|
638
658
|
get pkg() {
|
659
|
+
// @ts-expect-error TS7005
|
639
660
|
return getPkg();
|
640
661
|
},
|
641
662
|
};
|
package/src/{Npm.js → Npm.ts}
RENAMED
@@ -1,15 +1,13 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
|
3
1
|
import type {PackageInstaller, InstallerOptions} from '@atlaspack/types';
|
4
2
|
|
5
3
|
import path from 'path';
|
4
|
+
// @ts-expect-error TS7016
|
6
5
|
import spawn from 'cross-spawn';
|
7
6
|
import logger from '@atlaspack/logger';
|
8
7
|
import {registerSerializableClass} from '@atlaspack/build-cache';
|
9
8
|
import promiseFromProcess from './promiseFromProcess';
|
10
9
|
import {npmSpecifierFromModuleRequest} from './utils';
|
11
10
|
|
12
|
-
// $FlowFixMe
|
13
11
|
import pkg from '../package.json';
|
14
12
|
|
15
13
|
const NPM_CMD = 'npm';
|
@@ -35,7 +33,7 @@ export class Npm implements PackageInstaller {
|
|
35
33
|
// When Parcel is run by npm (e.g. via package.json scripts), several environment variables are
|
36
34
|
// added. When parcel in turn calls npm again, these can cause npm to behave stragely, so we
|
37
35
|
// filter them out when installing packages.
|
38
|
-
let env = {};
|
36
|
+
let env: Record<string, any> = {};
|
39
37
|
for (let key in process.env) {
|
40
38
|
if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
41
39
|
env[key] = process.env[key];
|
@@ -48,7 +46,7 @@ export class Npm implements PackageInstaller {
|
|
48
46
|
stdout += buf.toString();
|
49
47
|
});
|
50
48
|
|
51
|
-
let stderr = [];
|
49
|
+
let stderr: Array<string> = [];
|
52
50
|
installProcess.stderr.on('data', (buf: Buffer) => {
|
53
51
|
stderr.push(buf.toString().trim());
|
54
52
|
});
|
@@ -76,7 +74,7 @@ export class Npm implements PackageInstaller {
|
|
76
74
|
});
|
77
75
|
}
|
78
76
|
}
|
79
|
-
} catch (e) {
|
77
|
+
} catch (e: any) {
|
80
78
|
throw new Error(
|
81
79
|
'npm failed to install modules: ' +
|
82
80
|
e.message +
|
@@ -87,8 +85,10 @@ export class Npm implements PackageInstaller {
|
|
87
85
|
}
|
88
86
|
}
|
89
87
|
|
90
|
-
type NPMResults = {
|
91
|
-
added: Array<{
|
92
|
-
|
88
|
+
type NPMResults = {
|
89
|
+
added: Array<{
|
90
|
+
name: string;
|
91
|
+
}>;
|
92
|
+
};
|
93
93
|
|
94
94
|
registerSerializableClass(`${pkg.version}:Npm`, Npm);
|