@atlaspack/package-manager 2.14.5-canary.16 → 2.14.5-canary.161
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/CHANGELOG.md +228 -0
- package/lib/JSONParseStream.js +52 -0
- package/lib/MockPackageInstaller.js +79 -0
- package/lib/NodePackageManager.js +597 -0
- package/lib/Npm.js +106 -0
- package/lib/Pnpm.js +185 -0
- package/lib/Yarn.js +160 -0
- package/lib/getCurrentPackageManager.js +20 -0
- package/lib/index.js +64 -5211
- package/lib/installPackage.js +222 -0
- package/lib/nodejsConditions.js +41 -0
- package/lib/promiseFromProcess.js +20 -0
- package/lib/types/JSONParseStream.d.ts +6 -0
- package/lib/types/MockPackageInstaller.d.ts +14 -0
- package/lib/types/NodePackageManager.d.ts +36 -0
- package/lib/types/Npm.d.ts +4 -0
- package/lib/types/Pnpm.d.ts +5 -0
- package/lib/types/Yarn.d.ts +5 -0
- package/lib/types/getCurrentPackageManager.d.ts +4 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/installPackage.d.ts +5 -0
- package/lib/types/nodejsConditions.d.ts +3 -0
- package/lib/types/promiseFromProcess.d.ts +2 -0
- package/lib/types/utils.d.ts +15 -0
- package/lib/types/validateModuleSpecifier.d.ts +1 -0
- package/lib/utils.js +101 -0
- package/lib/validateModuleSpecifier.js +14 -0
- package/package.json +17 -19
- package/src/{JSONParseStream.js → JSONParseStream.ts} +8 -7
- package/src/{MockPackageInstaller.js → MockPackageInstaller.ts} +4 -6
- package/src/{NodePackageManager.js → NodePackageManager.ts} +83 -57
- 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} +4 -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} +19 -16
- 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/lib/index.d.ts +0 -10
- package/lib/index.js.map +0 -1
- package/src/promiseFromProcess.js +0 -19
@@ -1,4 +1,3 @@
|
|
1
|
-
// @flow
|
2
1
|
import type {
|
3
2
|
FilePath,
|
4
3
|
DependencySpecifier,
|
@@ -41,12 +40,10 @@ import {transformSync} from '@swc/core';
|
|
41
40
|
// Package.json fields. Must match package_json.rs.
|
42
41
|
const MAIN = 1 << 0;
|
43
42
|
const SOURCE = 1 << 2;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
? SOURCE
|
49
|
-
: 0);
|
43
|
+
let ENTRIES = MAIN;
|
44
|
+
if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
|
45
|
+
ENTRIES |= SOURCE;
|
46
|
+
}
|
50
47
|
|
51
48
|
const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
|
52
49
|
|
@@ -64,25 +61,27 @@ const invalidationsCache = new Map<string, Invalidations>();
|
|
64
61
|
export class NodePackageManager implements PackageManager {
|
65
62
|
fs: FileSystem;
|
66
63
|
projectRoot: FilePath;
|
67
|
-
installer:
|
64
|
+
installer: PackageInstaller | null | undefined;
|
65
|
+
// @ts-expect-error TS2749
|
68
66
|
resolver: ResolverBase;
|
69
67
|
currentExtensions: Array<string>;
|
70
68
|
|
71
69
|
constructor(
|
72
70
|
fs: FileSystem,
|
73
71
|
projectRoot: FilePath,
|
74
|
-
installer?:
|
72
|
+
installer?: PackageInstaller | null,
|
75
73
|
) {
|
76
74
|
this.fs = fs;
|
77
75
|
this.projectRoot = projectRoot;
|
78
76
|
this.installer = installer;
|
79
77
|
|
80
|
-
//
|
78
|
+
// @ts-expect-error TS2339
|
81
79
|
this.currentExtensions = Object.keys(Module._extensions).map((e) =>
|
82
80
|
e.substring(1),
|
83
81
|
);
|
84
82
|
}
|
85
83
|
|
84
|
+
// @ts-expect-error TS2749
|
86
85
|
_createResolver(): ResolverBase {
|
87
86
|
return new ResolverBase(this.projectRoot, {
|
88
87
|
fs:
|
@@ -99,8 +98,8 @@ export class NodePackageManager implements PackageManager {
|
|
99
98
|
packageExports: true,
|
100
99
|
moduleDirResolver:
|
101
100
|
process.versions.pnp != null
|
102
|
-
? (module, from) => {
|
103
|
-
//
|
101
|
+
? (module: any, from: any) => {
|
102
|
+
// @ts-expect-error TS2339
|
104
103
|
let pnp = Module.findPnpApi(path.dirname(from));
|
105
104
|
|
106
105
|
return pnp.resolveToUnqualified(
|
@@ -119,12 +118,12 @@ export class NodePackageManager implements PackageManager {
|
|
119
118
|
return new NodePackageManager(opts.fs, opts.projectRoot, opts.installer);
|
120
119
|
}
|
121
120
|
|
122
|
-
serialize(): {
|
123
|
-
$$raw: boolean
|
124
|
-
fs: FileSystem
|
125
|
-
projectRoot: FilePath
|
126
|
-
installer:
|
127
|
-
|
121
|
+
serialize(): {
|
122
|
+
$$raw: boolean;
|
123
|
+
fs: FileSystem;
|
124
|
+
projectRoot: FilePath;
|
125
|
+
installer: PackageInstaller | null | undefined;
|
126
|
+
} {
|
128
127
|
return {
|
129
128
|
$$raw: false,
|
130
129
|
fs: this.fs,
|
@@ -136,11 +135,11 @@ export class NodePackageManager implements PackageManager {
|
|
136
135
|
async require(
|
137
136
|
name: DependencySpecifier,
|
138
137
|
from: FilePath,
|
139
|
-
opts
|
140
|
-
range?:
|
141
|
-
shouldAutoInstall?: boolean
|
142
|
-
saveDev?: boolean
|
143
|
-
|
|
138
|
+
opts?: {
|
139
|
+
range?: SemverRange | null | undefined;
|
140
|
+
shouldAutoInstall?: boolean;
|
141
|
+
saveDev?: boolean;
|
142
|
+
} | null,
|
144
143
|
): Promise<any> {
|
145
144
|
let {resolved, type} = await this.resolve(name, from, opts);
|
146
145
|
if (type === 2) {
|
@@ -157,10 +156,10 @@ export class NodePackageManager implements PackageManager {
|
|
157
156
|
|
158
157
|
// On Windows, Node requires absolute paths to be file URLs.
|
159
158
|
if (process.platform === 'win32' && path.isAbsolute(resolved)) {
|
159
|
+
// @ts-expect-error TS2322
|
160
160
|
resolved = pathToFileURL(resolved);
|
161
161
|
}
|
162
162
|
|
163
|
-
// $FlowFixMe
|
164
163
|
return import(resolved);
|
165
164
|
}
|
166
165
|
return this.load(resolved, from);
|
@@ -174,20 +173,19 @@ export class NodePackageManager implements PackageManager {
|
|
174
173
|
load(filePath: FilePath, from: FilePath): any {
|
175
174
|
if (!path.isAbsolute(filePath)) {
|
176
175
|
// Node builtin module
|
177
|
-
// $FlowFixMe
|
178
176
|
return require(filePath);
|
179
177
|
}
|
180
178
|
|
181
|
-
//
|
179
|
+
// @ts-expect-error TS2339
|
182
180
|
const cachedModule = Module._cache[filePath];
|
183
181
|
if (cachedModule !== undefined) {
|
184
182
|
return cachedModule.exports;
|
185
183
|
}
|
186
184
|
|
187
|
-
//
|
185
|
+
// @ts-expect-error TS2339
|
188
186
|
let m = new Module(filePath, Module._cache[from] || module.parent);
|
189
187
|
|
190
|
-
//
|
188
|
+
// @ts-expect-error TS2339
|
191
189
|
const extensions = Object.keys(Module._extensions);
|
192
190
|
// This handles supported extensions changing due to, for example, esbuild/register being used
|
193
191
|
// We assume that the extension list will change in size - as these tools usually add support for
|
@@ -197,23 +195,23 @@ export class NodePackageManager implements PackageManager {
|
|
197
195
|
this.resolver = this._createResolver();
|
198
196
|
}
|
199
197
|
|
200
|
-
//
|
198
|
+
// @ts-expect-error TS2339
|
201
199
|
Module._cache[filePath] = m;
|
202
200
|
|
203
201
|
// Patch require within this module so it goes through our require
|
204
|
-
m.require = (id) => {
|
202
|
+
m.require = (id: any) => {
|
205
203
|
return this.requireSync(id, filePath);
|
206
204
|
};
|
207
205
|
|
208
206
|
// Patch `fs.readFileSync` temporarily so that it goes through our file system
|
209
207
|
let {readFileSync, statSync} = nativeFS;
|
210
|
-
//
|
211
|
-
nativeFS.readFileSync = (filename, encoding) => {
|
208
|
+
// @ts-expect-error TS2322
|
209
|
+
nativeFS.readFileSync = (filename: any, encoding: any) => {
|
212
210
|
return this.fs.readFileSync(filename, encoding);
|
213
211
|
};
|
214
212
|
|
215
|
-
//
|
216
|
-
nativeFS.statSync = (filename) => {
|
213
|
+
// @ts-expect-error TS2540
|
214
|
+
nativeFS.statSync = (filename: any) => {
|
217
215
|
return this.fs.statSync(filename);
|
218
216
|
};
|
219
217
|
|
@@ -224,35 +222,37 @@ export class NodePackageManager implements PackageManager {
|
|
224
222
|
extname === '.tsx' ||
|
225
223
|
extname === '.mts' ||
|
226
224
|
extname === '.cts') &&
|
227
|
-
//
|
225
|
+
// @ts-expect-error TS2339
|
228
226
|
!Module._extensions[extname]
|
229
227
|
) {
|
228
|
+
// @ts-expect-error TS2339
|
230
229
|
let compile = m._compile;
|
231
|
-
|
230
|
+
// @ts-expect-error TS2339
|
231
|
+
m._compile = (code: any, filename: any) => {
|
232
232
|
let out = transformSync(code, {filename, module: {type: 'commonjs'}});
|
233
233
|
compile.call(m, out.code, filename);
|
234
234
|
};
|
235
235
|
|
236
|
-
//
|
237
|
-
Module._extensions[extname] = (m, filename) => {
|
238
|
-
//
|
236
|
+
// @ts-expect-error TS2339
|
237
|
+
Module._extensions[extname] = (m: any, filename: any) => {
|
238
|
+
// @ts-expect-error TS2339
|
239
239
|
delete Module._extensions[extname];
|
240
|
-
//
|
240
|
+
// @ts-expect-error TS2339
|
241
241
|
Module._extensions['.js'](m, filename);
|
242
242
|
};
|
243
243
|
}
|
244
244
|
}
|
245
245
|
|
246
246
|
try {
|
247
|
+
// @ts-expect-error TS2339
|
247
248
|
m.load(filePath);
|
248
|
-
} catch (err) {
|
249
|
-
//
|
249
|
+
} catch (err: any) {
|
250
|
+
// @ts-expect-error TS2339
|
250
251
|
delete Module._cache[filePath];
|
251
252
|
throw err;
|
252
253
|
} finally {
|
253
|
-
// $FlowFixMe
|
254
254
|
nativeFS.readFileSync = readFileSync;
|
255
|
-
//
|
255
|
+
// @ts-expect-error TS2540
|
256
256
|
nativeFS.statSync = statSync;
|
257
257
|
}
|
258
258
|
|
@@ -262,11 +262,11 @@ export class NodePackageManager implements PackageManager {
|
|
262
262
|
async resolve(
|
263
263
|
id: DependencySpecifier,
|
264
264
|
from: FilePath,
|
265
|
-
options?:
|
266
|
-
range?:
|
267
|
-
shouldAutoInstall?: boolean
|
268
|
-
saveDev?: boolean
|
269
|
-
|
|
265
|
+
options?: {
|
266
|
+
range?: SemverRange | null | undefined;
|
267
|
+
shouldAutoInstall?: boolean;
|
268
|
+
saveDev?: boolean;
|
269
|
+
} | null,
|
270
270
|
): Promise<PackageManagerResolveResult> {
|
271
271
|
let basedir = path.dirname(from);
|
272
272
|
let key = basedir + ':' + id;
|
@@ -275,7 +275,7 @@ export class NodePackageManager implements PackageManager {
|
|
275
275
|
let [name] = getModuleParts(id);
|
276
276
|
try {
|
277
277
|
resolved = this.resolveInternal(id, from);
|
278
|
-
} catch (e) {
|
278
|
+
} catch (e: any) {
|
279
279
|
if (
|
280
280
|
e.code !== 'MODULE_NOT_FOUND' ||
|
281
281
|
options?.shouldAutoInstall !== true ||
|
@@ -293,7 +293,7 @@ export class NodePackageManager implements PackageManager {
|
|
293
293
|
],
|
294
294
|
},
|
295
295
|
});
|
296
|
-
//
|
296
|
+
// @ts-expect-error TS2339
|
297
297
|
err.code = 'MODULE_NOT_FOUND';
|
298
298
|
throw err;
|
299
299
|
} else {
|
@@ -476,7 +476,10 @@ export class NodePackageManager implements PackageManager {
|
|
476
476
|
};
|
477
477
|
|
478
478
|
let seen = new Set();
|
479
|
-
let addKey = (
|
479
|
+
let addKey = (
|
480
|
+
name: DependencySpecifier,
|
481
|
+
from: FilePath | DependencySpecifier,
|
482
|
+
) => {
|
480
483
|
let basedir = path.dirname(from);
|
481
484
|
let key = basedir + ':' + name;
|
482
485
|
if (seen.has(key)) {
|
@@ -489,6 +492,7 @@ export class NodePackageManager implements PackageManager {
|
|
489
492
|
return;
|
490
493
|
}
|
491
494
|
|
495
|
+
// @ts-expect-error TS2345
|
492
496
|
res.invalidateOnFileCreate.push(...resolved.invalidateOnFileCreate);
|
493
497
|
res.invalidateOnFileChange.add(resolved.resolved);
|
494
498
|
|
@@ -510,10 +514,13 @@ export class NodePackageManager implements PackageManager {
|
|
510
514
|
// cannot be intercepted. Instead, ask the resolver to parse the file and recursively analyze the deps.
|
511
515
|
if (resolved.type === 2) {
|
512
516
|
let invalidations = this.resolver.getInvalidations(resolved.resolved);
|
517
|
+
// @ts-expect-error TS7006
|
513
518
|
invalidations.invalidateOnFileChange.forEach((i) =>
|
514
519
|
res.invalidateOnFileChange.add(i),
|
515
520
|
);
|
521
|
+
// @ts-expect-error TS7006
|
516
522
|
invalidations.invalidateOnFileCreate.forEach((i) =>
|
523
|
+
// @ts-expect-error TS2345
|
517
524
|
res.invalidateOnFileCreate.push(i),
|
518
525
|
);
|
519
526
|
res.invalidateOnStartup ||= invalidations.invalidateOnStartup;
|
@@ -528,7 +535,9 @@ export class NodePackageManager implements PackageManager {
|
|
528
535
|
}
|
529
536
|
}
|
530
537
|
|
538
|
+
// @ts-expect-error TS2345
|
531
539
|
invalidationsCache.set(resolved.resolved, res);
|
540
|
+
// @ts-expect-error TS2322
|
532
541
|
return res;
|
533
542
|
}
|
534
543
|
|
@@ -542,7 +551,10 @@ export class NodePackageManager implements PackageManager {
|
|
542
551
|
invalidate(name: DependencySpecifier, from: FilePath) {
|
543
552
|
let seen = new Set();
|
544
553
|
|
545
|
-
let invalidate = (
|
554
|
+
let invalidate = (
|
555
|
+
name: DependencySpecifier,
|
556
|
+
from: FilePath | DependencySpecifier,
|
557
|
+
) => {
|
546
558
|
let basedir = path.dirname(from);
|
547
559
|
let key = basedir + ':' + name;
|
548
560
|
if (seen.has(key)) {
|
@@ -555,12 +567,24 @@ export class NodePackageManager implements PackageManager {
|
|
555
567
|
return;
|
556
568
|
}
|
557
569
|
|
570
|
+
// During testing don't invalidate Atlaspack modules because
|
571
|
+
// this causes failures due to multiple instances of the same module
|
572
|
+
// existing simultaniously. This is fine when using babe;-register because
|
573
|
+
// it has an internal module cache that NodePacakageManager does not invalidate
|
574
|
+
// but fails when using compiled Atlaspack packages in integration tests
|
575
|
+
if (
|
576
|
+
process.env.ATLASPACK_BUILD_ENV === 'test' &&
|
577
|
+
name.startsWith('@atlaspack/')
|
578
|
+
) {
|
579
|
+
return;
|
580
|
+
}
|
581
|
+
|
558
582
|
invalidationsCache.delete(resolved.resolved);
|
559
583
|
|
560
|
-
//
|
584
|
+
// @ts-expect-error TS2339
|
561
585
|
let module = Module._cache[resolved.resolved];
|
562
586
|
if (module) {
|
563
|
-
//
|
587
|
+
// @ts-expect-error TS2339
|
564
588
|
delete Module._cache[resolved.resolved];
|
565
589
|
}
|
566
590
|
|
@@ -594,17 +618,18 @@ export class NodePackageManager implements PackageManager {
|
|
594
618
|
// Invalidate whenever the .pnp.js file changes.
|
595
619
|
// TODO: only when we actually resolve a node_modules package?
|
596
620
|
if (process.versions.pnp != null && res.invalidateOnFileChange) {
|
597
|
-
//
|
621
|
+
// @ts-expect-error TS2339
|
598
622
|
let pnp = Module.findPnpApi(path.dirname(from));
|
599
623
|
res.invalidateOnFileChange.push(pnp.resolveToUnqualified('pnpapi', null));
|
600
624
|
}
|
601
625
|
|
602
626
|
if (res.error) {
|
603
627
|
let e = new Error(`Could not resolve module "${name}" from "${from}"`);
|
604
|
-
//
|
628
|
+
// @ts-expect-error TS2339
|
605
629
|
e.code = 'MODULE_NOT_FOUND';
|
606
630
|
throw e;
|
607
631
|
}
|
632
|
+
// @ts-expect-error TS7034
|
608
633
|
let getPkg;
|
609
634
|
switch (res.resolution.type) {
|
610
635
|
case 'Path':
|
@@ -626,6 +651,7 @@ export class NodePackageManager implements PackageManager {
|
|
626
651
|
invalidateOnFileCreate: res.invalidateOnFileCreate,
|
627
652
|
type: res.moduleType,
|
628
653
|
get pkg() {
|
654
|
+
// @ts-expect-error TS7005
|
629
655
|
return getPkg();
|
630
656
|
},
|
631
657
|
};
|
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);
|
package/src/{Pnpm.js → Pnpm.ts}
RENAMED
@@ -1,70 +1,83 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
|
3
1
|
import type {PackageInstaller, InstallerOptions} from '@atlaspack/types';
|
4
2
|
|
5
3
|
import path from 'path';
|
6
4
|
import fs from 'fs';
|
5
|
+
// @ts-expect-error TS7016
|
7
6
|
import commandExists from 'command-exists';
|
7
|
+
// @ts-expect-error TS7016
|
8
8
|
import spawn from 'cross-spawn';
|
9
9
|
import {registerSerializableClass} from '@atlaspack/build-cache';
|
10
10
|
import logger from '@atlaspack/logger';
|
11
|
+
// @ts-expect-error TS7016
|
11
12
|
import split from 'split2';
|
12
13
|
import JSONParseStream from './JSONParseStream';
|
13
14
|
import promiseFromProcess from './promiseFromProcess';
|
14
15
|
import {exec, npmSpecifierFromModuleRequest} from './utils';
|
15
16
|
|
16
|
-
// $FlowFixMe
|
17
17
|
import pkg from '../package.json';
|
18
18
|
|
19
19
|
const PNPM_CMD = 'pnpm';
|
20
20
|
|
21
21
|
type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
22
22
|
|
23
|
-
type ErrorLog = {
|
24
|
-
err: {
|
25
|
-
message: string
|
26
|
-
code: string
|
27
|
-
stack: string
|
28
|
-
|
29
|
-
|
23
|
+
type ErrorLog = {
|
24
|
+
err: {
|
25
|
+
message: string;
|
26
|
+
code: string;
|
27
|
+
stack: string;
|
28
|
+
};
|
29
|
+
};
|
30
30
|
|
31
31
|
type PNPMLog =
|
32
|
-
| {
|
33
|
-
|
34
|
-
packageId: string
|
35
|
-
status: 'fetched' | 'found_in_store' | 'resolved'
|
36
|
-
|
37
|
-
| {
|
38
|
-
|
39
|
-
added?: {
|
40
|
-
id?: string
|
41
|
-
name: string
|
42
|
-
realName: string
|
43
|
-
version?: string
|
44
|
-
dependencyType?: 'prod' | 'dev' | 'optional'
|
45
|
-
latest?: string
|
46
|
-
linkedFrom?: string
|
47
|
-
|
48
|
-
removed?: {
|
49
|
-
name: string
|
50
|
-
version?: string
|
51
|
-
dependencyType?: 'prod' | 'dev' | 'optional'
|
52
|
-
|
53
|
-
|
54
|
-
| {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
32
|
+
| {
|
33
|
+
readonly name: 'pnpm:progress';
|
34
|
+
packageId: string;
|
35
|
+
status: 'fetched' | 'found_in_store' | 'resolved';
|
36
|
+
}
|
37
|
+
| {
|
38
|
+
readonly name: 'pnpm:root';
|
39
|
+
added?: {
|
40
|
+
id?: string;
|
41
|
+
name: string;
|
42
|
+
realName: string;
|
43
|
+
version?: string;
|
44
|
+
dependencyType?: 'prod' | 'dev' | 'optional';
|
45
|
+
latest?: string;
|
46
|
+
linkedFrom?: string;
|
47
|
+
};
|
48
|
+
removed?: {
|
49
|
+
name: string;
|
50
|
+
version?: string;
|
51
|
+
dependencyType?: 'prod' | 'dev' | 'optional';
|
52
|
+
};
|
53
|
+
}
|
54
|
+
| {
|
55
|
+
readonly name: 'pnpm:importing';
|
56
|
+
from: string;
|
57
|
+
method: string;
|
58
|
+
to: string;
|
59
|
+
}
|
60
|
+
| {
|
61
|
+
readonly name: 'pnpm:link';
|
62
|
+
target: string;
|
63
|
+
link: string;
|
64
|
+
}
|
65
|
+
| {
|
66
|
+
readonly name: 'pnpm:stats';
|
67
|
+
prefix: string;
|
68
|
+
removed?: number;
|
69
|
+
added?: number;
|
70
|
+
};
|
71
|
+
|
72
|
+
type PNPMResults = {
|
73
|
+
level: LogLevel;
|
74
|
+
prefix?: string;
|
75
|
+
message?: string;
|
76
|
+
} & ErrorLog &
|
77
|
+
PNPMLog;
|
78
|
+
|
79
|
+
let hasPnpm: boolean | null | undefined;
|
80
|
+
let pnpmVersion: number | null | undefined;
|
68
81
|
|
69
82
|
export class Pnpm implements PackageInstaller {
|
70
83
|
static async exists(): Promise<boolean> {
|
@@ -74,7 +87,7 @@ export class Pnpm implements PackageInstaller {
|
|
74
87
|
|
75
88
|
try {
|
76
89
|
hasPnpm = Boolean(await commandExists('pnpm'));
|
77
|
-
} catch (err) {
|
90
|
+
} catch (err: any) {
|
78
91
|
hasPnpm = false;
|
79
92
|
}
|
80
93
|
|
@@ -88,6 +101,7 @@ export class Pnpm implements PackageInstaller {
|
|
88
101
|
}: InstallerOptions): Promise<void> {
|
89
102
|
if (pnpmVersion == null) {
|
90
103
|
let version = await exec('pnpm --version');
|
104
|
+
// @ts-expect-error TS2345
|
91
105
|
pnpmVersion = parseInt(version.stdout, 10);
|
92
106
|
}
|
93
107
|
|
@@ -106,7 +120,7 @@ export class Pnpm implements PackageInstaller {
|
|
106
120
|
}
|
107
121
|
args = args.concat(modules.map(npmSpecifierFromModuleRequest));
|
108
122
|
|
109
|
-
let env = {};
|
123
|
+
let env: Record<string, any> = {};
|
110
124
|
for (let key in process.env) {
|
111
125
|
if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
112
126
|
env[key] = process.env[key];
|
@@ -122,7 +136,9 @@ export class Pnpm implements PackageInstaller {
|
|
122
136
|
});
|
123
137
|
installProcess.stdout
|
124
138
|
.pipe(split())
|
139
|
+
// @ts-expect-error TS2554
|
125
140
|
.pipe(new JSONParseStream())
|
141
|
+
// @ts-expect-error TS7006
|
126
142
|
.on('error', (e) => {
|
127
143
|
logger.warn({
|
128
144
|
origin: '@atlaspack/package-manager',
|
@@ -148,11 +164,13 @@ export class Pnpm implements PackageInstaller {
|
|
148
164
|
}
|
149
165
|
});
|
150
166
|
|
151
|
-
let stderr = [];
|
167
|
+
let stderr: Array<any> = [];
|
152
168
|
installProcess.stderr
|
169
|
+
// @ts-expect-error TS7006
|
153
170
|
.on('data', (str) => {
|
154
171
|
stderr.push(str.toString());
|
155
172
|
})
|
173
|
+
// @ts-expect-error TS7006
|
156
174
|
.on('error', (e) => {
|
157
175
|
logger.warn({
|
158
176
|
origin: '@atlaspack/package-manager',
|
@@ -181,7 +199,7 @@ export class Pnpm implements PackageInstaller {
|
|
181
199
|
message,
|
182
200
|
});
|
183
201
|
}
|
184
|
-
} catch (e) {
|
202
|
+
} catch (e: any) {
|
185
203
|
throw new Error('pnpm failed to install modules');
|
186
204
|
}
|
187
205
|
}
|