@atlaspack/package-manager 2.14.21-typescript-bc4459c37.0 → 2.14.21
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 +11 -0
- package/index.d.ts +40 -0
- package/lib/JSONParseStream.js +2 -1
- package/lib/NodePackageManager.js +24 -44
- package/lib/Npm.js +1 -2
- package/lib/Pnpm.js +4 -18
- package/lib/Yarn.js +3 -17
- package/lib/getCurrentPackageManager.js +1 -3
- package/lib/index.d.ts +8 -8
- package/lib/installPackage.js +0 -1
- package/lib/nodejsConditions.js +0 -6
- package/lib/promiseFromProcess.js +0 -2
- package/package.json +17 -17
- package/src/{JSONParseStream.ts → JSONParseStream.js} +7 -8
- package/src/{MockPackageInstaller.ts → MockPackageInstaller.js} +6 -4
- package/src/{NodePackageManager.ts → NodePackageManager.js} +51 -72
- package/src/{Npm.ts → Npm.js} +9 -9
- package/src/{Pnpm.ts → Pnpm.js} +50 -68
- package/src/{Yarn.ts → Yarn.js} +25 -38
- package/src/{getCurrentPackageManager.ts → getCurrentPackageManager.js} +4 -9
- package/src/{index.ts → index.js} +2 -0
- package/src/{installPackage.ts → installPackage.js} +6 -5
- package/src/{nodejsConditions.ts → nodejsConditions.js} +3 -6
- package/src/promiseFromProcess.js +19 -0
- package/src/{utils.ts → utils.js} +11 -21
- package/src/{validateModuleSpecifier.ts → validateModuleSpecifier.js} +2 -0
- package/test/{NodePackageManager.test.ts → NodePackageManager.test.js} +15 -13
- package/test/{getCurrentPackageManager.test.ts → getCurrentPackageManager.test.js} +1 -0
- package/test/{validateModuleSpecifiers.test.ts → validateModuleSpecifiers.test.js} +3 -2
- package/LICENSE +0 -201
- package/lib/JSONParseStream.d.ts +0 -6
- package/lib/MockPackageInstaller.d.ts +0 -14
- package/lib/NodePackageManager.d.ts +0 -36
- package/lib/Npm.d.ts +0 -4
- package/lib/Pnpm.d.ts +0 -5
- package/lib/Yarn.d.ts +0 -5
- package/lib/getCurrentPackageManager.d.ts +0 -4
- package/lib/installPackage.d.ts +0 -5
- package/lib/nodejsConditions.d.ts +0 -3
- package/lib/promiseFromProcess.d.ts +0 -2
- package/lib/utils.d.ts +0 -15
- package/lib/validateModuleSpecifier.d.ts +0 -1
- package/src/promiseFromProcess.ts +0 -23
- package/tsconfig.json +0 -4
@@ -1,3 +1,4 @@
|
|
1
|
+
// @flow
|
1
2
|
import type {
|
2
3
|
FilePath,
|
3
4
|
DependencySpecifier,
|
@@ -61,27 +62,25 @@ const invalidationsCache = new Map<string, Invalidations>();
|
|
61
62
|
export class NodePackageManager implements PackageManager {
|
62
63
|
fs: FileSystem;
|
63
64
|
projectRoot: FilePath;
|
64
|
-
installer: PackageInstaller
|
65
|
-
// @ts-expect-error TS2749
|
65
|
+
installer: ?PackageInstaller;
|
66
66
|
resolver: ResolverBase;
|
67
67
|
currentExtensions: Array<string>;
|
68
68
|
|
69
69
|
constructor(
|
70
70
|
fs: FileSystem,
|
71
71
|
projectRoot: FilePath,
|
72
|
-
installer?: PackageInstaller
|
72
|
+
installer?: ?PackageInstaller,
|
73
73
|
) {
|
74
74
|
this.fs = fs;
|
75
75
|
this.projectRoot = projectRoot;
|
76
76
|
this.installer = installer;
|
77
77
|
|
78
|
-
//
|
78
|
+
// $FlowFixMe - no type for _extensions
|
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
|
85
84
|
_createResolver(): ResolverBase {
|
86
85
|
return new ResolverBase(this.projectRoot, {
|
87
86
|
fs:
|
@@ -98,8 +97,8 @@ export class NodePackageManager implements PackageManager {
|
|
98
97
|
packageExports: true,
|
99
98
|
moduleDirResolver:
|
100
99
|
process.versions.pnp != null
|
101
|
-
? (module
|
102
|
-
//
|
100
|
+
? (module, from) => {
|
101
|
+
// $FlowFixMe[prop-missing]
|
103
102
|
let pnp = Module.findPnpApi(path.dirname(from));
|
104
103
|
|
105
104
|
return pnp.resolveToUnqualified(
|
@@ -118,12 +117,12 @@ export class NodePackageManager implements PackageManager {
|
|
118
117
|
return new NodePackageManager(opts.fs, opts.projectRoot, opts.installer);
|
119
118
|
}
|
120
119
|
|
121
|
-
serialize(): {
|
122
|
-
$$raw: boolean
|
123
|
-
fs: FileSystem
|
124
|
-
projectRoot: FilePath
|
125
|
-
installer: PackageInstaller
|
126
|
-
} {
|
120
|
+
serialize(): {|
|
121
|
+
$$raw: boolean,
|
122
|
+
fs: FileSystem,
|
123
|
+
projectRoot: FilePath,
|
124
|
+
installer: ?PackageInstaller,
|
125
|
+
|} {
|
127
126
|
return {
|
128
127
|
$$raw: false,
|
129
128
|
fs: this.fs,
|
@@ -135,11 +134,11 @@ export class NodePackageManager implements PackageManager {
|
|
135
134
|
async require(
|
136
135
|
name: DependencySpecifier,
|
137
136
|
from: FilePath,
|
138
|
-
opts
|
139
|
-
range?: SemverRange
|
140
|
-
shouldAutoInstall?: boolean
|
141
|
-
saveDev?: boolean
|
142
|
-
}
|
137
|
+
opts: ?{|
|
138
|
+
range?: ?SemverRange,
|
139
|
+
shouldAutoInstall?: boolean,
|
140
|
+
saveDev?: boolean,
|
141
|
+
|},
|
143
142
|
): Promise<any> {
|
144
143
|
let {resolved, type} = await this.resolve(name, from, opts);
|
145
144
|
if (type === 2) {
|
@@ -156,10 +155,10 @@ export class NodePackageManager implements PackageManager {
|
|
156
155
|
|
157
156
|
// On Windows, Node requires absolute paths to be file URLs.
|
158
157
|
if (process.platform === 'win32' && path.isAbsolute(resolved)) {
|
159
|
-
// @ts-expect-error TS2322
|
160
158
|
resolved = pathToFileURL(resolved);
|
161
159
|
}
|
162
160
|
|
161
|
+
// $FlowFixMe
|
163
162
|
return import(resolved);
|
164
163
|
}
|
165
164
|
return this.load(resolved, from);
|
@@ -173,19 +172,20 @@ export class NodePackageManager implements PackageManager {
|
|
173
172
|
load(filePath: FilePath, from: FilePath): any {
|
174
173
|
if (!path.isAbsolute(filePath)) {
|
175
174
|
// Node builtin module
|
175
|
+
// $FlowFixMe
|
176
176
|
return require(filePath);
|
177
177
|
}
|
178
178
|
|
179
|
-
//
|
179
|
+
// $FlowFixMe[prop-missing]
|
180
180
|
const cachedModule = Module._cache[filePath];
|
181
181
|
if (cachedModule !== undefined) {
|
182
182
|
return cachedModule.exports;
|
183
183
|
}
|
184
184
|
|
185
|
-
//
|
185
|
+
// $FlowFixMe
|
186
186
|
let m = new Module(filePath, Module._cache[from] || module.parent);
|
187
187
|
|
188
|
-
//
|
188
|
+
// $FlowFixMe _extensions not in type
|
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
|
+
// $FlowFixMe[prop-missing]
|
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) => {
|
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
|
208
|
+
// $FlowFixMe
|
209
|
+
nativeFS.readFileSync = (filename, encoding) => {
|
210
210
|
return this.fs.readFileSync(filename, encoding);
|
211
211
|
};
|
212
212
|
|
213
|
-
//
|
214
|
-
nativeFS.statSync = (filename
|
213
|
+
// $FlowFixMe
|
214
|
+
nativeFS.statSync = (filename) => {
|
215
215
|
return this.fs.statSync(filename);
|
216
216
|
};
|
217
217
|
|
@@ -222,37 +222,35 @@ export class NodePackageManager implements PackageManager {
|
|
222
222
|
extname === '.tsx' ||
|
223
223
|
extname === '.mts' ||
|
224
224
|
extname === '.cts') &&
|
225
|
-
//
|
225
|
+
// $FlowFixMe
|
226
226
|
!Module._extensions[extname]
|
227
227
|
) {
|
228
|
-
// @ts-expect-error TS2339
|
229
228
|
let compile = m._compile;
|
230
|
-
|
231
|
-
m._compile = (code: any, filename: any) => {
|
229
|
+
m._compile = (code, filename) => {
|
232
230
|
let out = transformSync(code, {filename, module: {type: 'commonjs'}});
|
233
231
|
compile.call(m, out.code, filename);
|
234
232
|
};
|
235
233
|
|
236
|
-
//
|
237
|
-
Module._extensions[extname] = (m
|
238
|
-
//
|
234
|
+
// $FlowFixMe
|
235
|
+
Module._extensions[extname] = (m, filename) => {
|
236
|
+
// $FlowFixMe
|
239
237
|
delete Module._extensions[extname];
|
240
|
-
//
|
238
|
+
// $FlowFixMe
|
241
239
|
Module._extensions['.js'](m, filename);
|
242
240
|
};
|
243
241
|
}
|
244
242
|
}
|
245
243
|
|
246
244
|
try {
|
247
|
-
// @ts-expect-error TS2339
|
248
245
|
m.load(filePath);
|
249
|
-
} catch (err
|
250
|
-
//
|
246
|
+
} catch (err) {
|
247
|
+
// $FlowFixMe[prop-missing]
|
251
248
|
delete Module._cache[filePath];
|
252
249
|
throw err;
|
253
250
|
} finally {
|
251
|
+
// $FlowFixMe
|
254
252
|
nativeFS.readFileSync = readFileSync;
|
255
|
-
//
|
253
|
+
// $FlowFixMe
|
256
254
|
nativeFS.statSync = statSync;
|
257
255
|
}
|
258
256
|
|
@@ -262,11 +260,11 @@ export class NodePackageManager implements PackageManager {
|
|
262
260
|
async resolve(
|
263
261
|
id: DependencySpecifier,
|
264
262
|
from: FilePath,
|
265
|
-
options?: {
|
266
|
-
range?: SemverRange
|
267
|
-
shouldAutoInstall?: boolean
|
268
|
-
saveDev?: boolean
|
269
|
-
}
|
263
|
+
options?: ?{|
|
264
|
+
range?: ?SemverRange,
|
265
|
+
shouldAutoInstall?: boolean,
|
266
|
+
saveDev?: boolean,
|
267
|
+
|},
|
270
268
|
): Promise<PackageManagerResolveResult> {
|
271
269
|
let basedir = path.dirname(from);
|
272
270
|
let key = basedir + ':' + id;
|
@@ -275,7 +273,7 @@ export class NodePackageManager implements PackageManager {
|
|
275
273
|
let [name] = getModuleParts(id);
|
276
274
|
try {
|
277
275
|
resolved = this.resolveInternal(id, from);
|
278
|
-
} catch (e
|
276
|
+
} catch (e) {
|
279
277
|
if (
|
280
278
|
e.code !== 'MODULE_NOT_FOUND' ||
|
281
279
|
options?.shouldAutoInstall !== true ||
|
@@ -293,7 +291,7 @@ export class NodePackageManager implements PackageManager {
|
|
293
291
|
],
|
294
292
|
},
|
295
293
|
});
|
296
|
-
//
|
294
|
+
// $FlowFixMe - needed for loadParcelPlugin
|
297
295
|
err.code = 'MODULE_NOT_FOUND';
|
298
296
|
throw err;
|
299
297
|
} else {
|
@@ -322,7 +320,6 @@ export class NodePackageManager implements PackageManager {
|
|
322
320
|
|
323
321
|
throw new ThrowableDiagnostic({
|
324
322
|
diagnostic: conflicts.fields.map((field) => ({
|
325
|
-
// @ts-expect-error TS2345
|
326
323
|
message: md`Could not find module "${name}", but it was listed in package.json. Run your package manager first.`,
|
327
324
|
origin: '@atlaspack/package-manager',
|
328
325
|
codeFrames: [
|
@@ -364,7 +361,6 @@ export class NodePackageManager implements PackageManager {
|
|
364
361
|
} else if (conflicts != null) {
|
365
362
|
throw new ThrowableDiagnostic({
|
366
363
|
diagnostic: {
|
367
|
-
// @ts-expect-error TS2345
|
368
364
|
message: md`Could not find module "${name}" satisfying ${range}.`,
|
369
365
|
origin: '@atlaspack/package-manager',
|
370
366
|
codeFrames: [
|
@@ -387,10 +383,8 @@ export class NodePackageManager implements PackageManager {
|
|
387
383
|
}
|
388
384
|
|
389
385
|
let version = pkg?.version;
|
390
|
-
// @ts-expect-error TS2345
|
391
386
|
let message = md`Could not resolve package "${name}" that satisfies ${range}.`;
|
392
387
|
if (version != null) {
|
393
|
-
// @ts-expect-error TS2345
|
394
388
|
message += md` Found ${version}.`;
|
395
389
|
}
|
396
390
|
|
@@ -480,10 +474,7 @@ export class NodePackageManager implements PackageManager {
|
|
480
474
|
};
|
481
475
|
|
482
476
|
let seen = new Set();
|
483
|
-
let addKey = (
|
484
|
-
name: DependencySpecifier,
|
485
|
-
from: FilePath | DependencySpecifier,
|
486
|
-
) => {
|
477
|
+
let addKey = (name, from) => {
|
487
478
|
let basedir = path.dirname(from);
|
488
479
|
let key = basedir + ':' + name;
|
489
480
|
if (seen.has(key)) {
|
@@ -496,7 +487,6 @@ export class NodePackageManager implements PackageManager {
|
|
496
487
|
return;
|
497
488
|
}
|
498
489
|
|
499
|
-
// @ts-expect-error TS2345
|
500
490
|
res.invalidateOnFileCreate.push(...resolved.invalidateOnFileCreate);
|
501
491
|
res.invalidateOnFileChange.add(resolved.resolved);
|
502
492
|
|
@@ -518,19 +508,15 @@ export class NodePackageManager implements PackageManager {
|
|
518
508
|
// cannot be intercepted. Instead, ask the resolver to parse the file and recursively analyze the deps.
|
519
509
|
if (resolved.type === 2) {
|
520
510
|
let invalidations = this.resolver.getInvalidations(resolved.resolved);
|
521
|
-
// @ts-expect-error TS7006
|
522
511
|
invalidations.invalidateOnFileChange.forEach((i) =>
|
523
512
|
res.invalidateOnFileChange.add(i),
|
524
513
|
);
|
525
|
-
// @ts-expect-error TS7006
|
526
514
|
invalidations.invalidateOnFileCreate.forEach((i) =>
|
527
|
-
// @ts-expect-error TS2345
|
528
515
|
res.invalidateOnFileCreate.push(i),
|
529
516
|
);
|
530
517
|
res.invalidateOnStartup ||= invalidations.invalidateOnStartup;
|
531
518
|
if (res.invalidateOnStartup) {
|
532
519
|
logger.warn({
|
533
|
-
// @ts-expect-error TS2345
|
534
520
|
message: md`${path.relative(
|
535
521
|
this.projectRoot,
|
536
522
|
resolved.resolved,
|
@@ -540,9 +526,7 @@ export class NodePackageManager implements PackageManager {
|
|
540
526
|
}
|
541
527
|
}
|
542
528
|
|
543
|
-
// @ts-expect-error TS2345
|
544
529
|
invalidationsCache.set(resolved.resolved, res);
|
545
|
-
// @ts-expect-error TS2322
|
546
530
|
return res;
|
547
531
|
}
|
548
532
|
|
@@ -556,10 +540,7 @@ export class NodePackageManager implements PackageManager {
|
|
556
540
|
invalidate(name: DependencySpecifier, from: FilePath) {
|
557
541
|
let seen = new Set();
|
558
542
|
|
559
|
-
let invalidate = (
|
560
|
-
name: DependencySpecifier,
|
561
|
-
from: FilePath | DependencySpecifier,
|
562
|
-
) => {
|
543
|
+
let invalidate = (name, from) => {
|
563
544
|
let basedir = path.dirname(from);
|
564
545
|
let key = basedir + ':' + name;
|
565
546
|
if (seen.has(key)) {
|
@@ -586,10 +567,10 @@ export class NodePackageManager implements PackageManager {
|
|
586
567
|
|
587
568
|
invalidationsCache.delete(resolved.resolved);
|
588
569
|
|
589
|
-
//
|
570
|
+
// $FlowFixMe
|
590
571
|
let module = Module._cache[resolved.resolved];
|
591
572
|
if (module) {
|
592
|
-
//
|
573
|
+
// $FlowFixMe
|
593
574
|
delete Module._cache[resolved.resolved];
|
594
575
|
}
|
595
576
|
|
@@ -623,18 +604,17 @@ export class NodePackageManager implements PackageManager {
|
|
623
604
|
// Invalidate whenever the .pnp.js file changes.
|
624
605
|
// TODO: only when we actually resolve a node_modules package?
|
625
606
|
if (process.versions.pnp != null && res.invalidateOnFileChange) {
|
626
|
-
//
|
607
|
+
// $FlowFixMe[prop-missing]
|
627
608
|
let pnp = Module.findPnpApi(path.dirname(from));
|
628
609
|
res.invalidateOnFileChange.push(pnp.resolveToUnqualified('pnpapi', null));
|
629
610
|
}
|
630
611
|
|
631
612
|
if (res.error) {
|
632
613
|
let e = new Error(`Could not resolve module "${name}" from "${from}"`);
|
633
|
-
//
|
614
|
+
// $FlowFixMe
|
634
615
|
e.code = 'MODULE_NOT_FOUND';
|
635
616
|
throw e;
|
636
617
|
}
|
637
|
-
// @ts-expect-error TS7034
|
638
618
|
let getPkg;
|
639
619
|
switch (res.resolution.type) {
|
640
620
|
case 'Path':
|
@@ -656,7 +636,6 @@ export class NodePackageManager implements PackageManager {
|
|
656
636
|
invalidateOnFileCreate: res.invalidateOnFileCreate,
|
657
637
|
type: res.moduleType,
|
658
638
|
get pkg() {
|
659
|
-
// @ts-expect-error TS7005
|
660
639
|
return getPkg();
|
661
640
|
},
|
662
641
|
};
|
package/src/{Npm.ts → Npm.js}
RENAMED
@@ -1,13 +1,15 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
1
3
|
import type {PackageInstaller, InstallerOptions} from '@atlaspack/types';
|
2
4
|
|
3
5
|
import path from 'path';
|
4
|
-
// @ts-expect-error TS7016
|
5
6
|
import spawn from 'cross-spawn';
|
6
7
|
import logger from '@atlaspack/logger';
|
7
8
|
import {registerSerializableClass} from '@atlaspack/build-cache';
|
8
9
|
import promiseFromProcess from './promiseFromProcess';
|
9
10
|
import {npmSpecifierFromModuleRequest} from './utils';
|
10
11
|
|
12
|
+
// $FlowFixMe
|
11
13
|
import pkg from '../package.json';
|
12
14
|
|
13
15
|
const NPM_CMD = 'npm';
|
@@ -33,7 +35,7 @@ export class Npm implements PackageInstaller {
|
|
33
35
|
// When Parcel is run by npm (e.g. via package.json scripts), several environment variables are
|
34
36
|
// added. When parcel in turn calls npm again, these can cause npm to behave stragely, so we
|
35
37
|
// filter them out when installing packages.
|
36
|
-
let env
|
38
|
+
let env = {};
|
37
39
|
for (let key in process.env) {
|
38
40
|
if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
39
41
|
env[key] = process.env[key];
|
@@ -46,7 +48,7 @@ export class Npm implements PackageInstaller {
|
|
46
48
|
stdout += buf.toString();
|
47
49
|
});
|
48
50
|
|
49
|
-
let stderr
|
51
|
+
let stderr = [];
|
50
52
|
installProcess.stderr.on('data', (buf: Buffer) => {
|
51
53
|
stderr.push(buf.toString().trim());
|
52
54
|
});
|
@@ -74,7 +76,7 @@ export class Npm implements PackageInstaller {
|
|
74
76
|
});
|
75
77
|
}
|
76
78
|
}
|
77
|
-
} catch (e
|
79
|
+
} catch (e) {
|
78
80
|
throw new Error(
|
79
81
|
'npm failed to install modules: ' +
|
80
82
|
e.message +
|
@@ -85,10 +87,8 @@ export class Npm implements PackageInstaller {
|
|
85
87
|
}
|
86
88
|
}
|
87
89
|
|
88
|
-
type NPMResults = {
|
89
|
-
added: Array<{
|
90
|
-
|
91
|
-
}>;
|
92
|
-
};
|
90
|
+
type NPMResults = {|
|
91
|
+
added: Array<{name: string, ...}>,
|
92
|
+
|};
|
93
93
|
|
94
94
|
registerSerializableClass(`${pkg.version}:Npm`, Npm);
|
package/src/{Pnpm.ts → Pnpm.js}
RENAMED
@@ -1,83 +1,70 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
1
3
|
import type {PackageInstaller, InstallerOptions} from '@atlaspack/types';
|
2
4
|
|
3
5
|
import path from 'path';
|
4
6
|
import fs from 'fs';
|
5
|
-
// @ts-expect-error TS7016
|
6
7
|
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
|
12
11
|
import split from 'split2';
|
13
12
|
import JSONParseStream from './JSONParseStream';
|
14
13
|
import promiseFromProcess from './promiseFromProcess';
|
15
14
|
import {exec, npmSpecifierFromModuleRequest} from './utils';
|
16
15
|
|
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
|
-
|
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;
|
32
|
+
| {|
|
33
|
+
+name: 'pnpm:progress',
|
34
|
+
packageId: string,
|
35
|
+
status: 'fetched' | 'found_in_store' | 'resolved',
|
36
|
+
|}
|
37
|
+
| {|
|
38
|
+
+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
|
+
| {|+name: 'pnpm:importing', from: string, method: string, to: string|}
|
55
|
+
| {|+name: 'pnpm:link', target: string, link: string|}
|
56
|
+
| {|+name: 'pnpm:stats', prefix: string, removed?: number, added?: number|};
|
57
|
+
|
58
|
+
type PNPMResults = {|
|
59
|
+
level: LogLevel,
|
60
|
+
prefix?: string,
|
61
|
+
message?: string,
|
62
|
+
...ErrorLog,
|
63
|
+
...PNPMLog,
|
64
|
+
|};
|
65
|
+
|
66
|
+
let hasPnpm: ?boolean;
|
67
|
+
let pnpmVersion: ?number;
|
81
68
|
|
82
69
|
export class Pnpm implements PackageInstaller {
|
83
70
|
static async exists(): Promise<boolean> {
|
@@ -87,7 +74,7 @@ export class Pnpm implements PackageInstaller {
|
|
87
74
|
|
88
75
|
try {
|
89
76
|
hasPnpm = Boolean(await commandExists('pnpm'));
|
90
|
-
} catch (err
|
77
|
+
} catch (err) {
|
91
78
|
hasPnpm = false;
|
92
79
|
}
|
93
80
|
|
@@ -101,7 +88,6 @@ export class Pnpm implements PackageInstaller {
|
|
101
88
|
}: InstallerOptions): Promise<void> {
|
102
89
|
if (pnpmVersion == null) {
|
103
90
|
let version = await exec('pnpm --version');
|
104
|
-
// @ts-expect-error TS2345
|
105
91
|
pnpmVersion = parseInt(version.stdout, 10);
|
106
92
|
}
|
107
93
|
|
@@ -120,7 +106,7 @@ export class Pnpm implements PackageInstaller {
|
|
120
106
|
}
|
121
107
|
args = args.concat(modules.map(npmSpecifierFromModuleRequest));
|
122
108
|
|
123
|
-
let env
|
109
|
+
let env = {};
|
124
110
|
for (let key in process.env) {
|
125
111
|
if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
126
112
|
env[key] = process.env[key];
|
@@ -136,9 +122,7 @@ export class Pnpm implements PackageInstaller {
|
|
136
122
|
});
|
137
123
|
installProcess.stdout
|
138
124
|
.pipe(split())
|
139
|
-
// @ts-expect-error TS2554
|
140
125
|
.pipe(new JSONParseStream())
|
141
|
-
// @ts-expect-error TS7006
|
142
126
|
.on('error', (e) => {
|
143
127
|
logger.warn({
|
144
128
|
origin: '@atlaspack/package-manager',
|
@@ -164,13 +148,11 @@ export class Pnpm implements PackageInstaller {
|
|
164
148
|
}
|
165
149
|
});
|
166
150
|
|
167
|
-
let stderr
|
151
|
+
let stderr = [];
|
168
152
|
installProcess.stderr
|
169
|
-
// @ts-expect-error TS7006
|
170
153
|
.on('data', (str) => {
|
171
154
|
stderr.push(str.toString());
|
172
155
|
})
|
173
|
-
// @ts-expect-error TS7006
|
174
156
|
.on('error', (e) => {
|
175
157
|
logger.warn({
|
176
158
|
origin: '@atlaspack/package-manager',
|
@@ -199,7 +181,7 @@ export class Pnpm implements PackageInstaller {
|
|
199
181
|
message,
|
200
182
|
});
|
201
183
|
}
|
202
|
-
} catch (e
|
184
|
+
} catch (e) {
|
203
185
|
throw new Error('pnpm failed to install modules');
|
204
186
|
}
|
205
187
|
}
|