@atlaspack/package-manager 2.14.5-canary.16 → 2.14.5-canary.160

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/lib/JSONParseStream.js +52 -0
  3. package/lib/MockPackageInstaller.js +79 -0
  4. package/lib/NodePackageManager.js +602 -0
  5. package/lib/Npm.js +106 -0
  6. package/lib/Pnpm.js +185 -0
  7. package/lib/Yarn.js +160 -0
  8. package/lib/getCurrentPackageManager.js +20 -0
  9. package/lib/index.js +64 -5211
  10. package/lib/installPackage.js +223 -0
  11. package/lib/nodejsConditions.js +41 -0
  12. package/lib/promiseFromProcess.js +20 -0
  13. package/lib/types/JSONParseStream.d.ts +6 -0
  14. package/lib/types/MockPackageInstaller.d.ts +14 -0
  15. package/lib/types/NodePackageManager.d.ts +36 -0
  16. package/lib/types/Npm.d.ts +4 -0
  17. package/lib/types/Pnpm.d.ts +5 -0
  18. package/lib/types/Yarn.d.ts +5 -0
  19. package/lib/types/getCurrentPackageManager.d.ts +4 -0
  20. package/lib/types/index.d.ts +10 -0
  21. package/lib/types/installPackage.d.ts +5 -0
  22. package/lib/types/nodejsConditions.d.ts +3 -0
  23. package/lib/types/promiseFromProcess.d.ts +2 -0
  24. package/lib/types/utils.d.ts +15 -0
  25. package/lib/types/validateModuleSpecifier.d.ts +1 -0
  26. package/lib/utils.js +101 -0
  27. package/lib/validateModuleSpecifier.js +14 -0
  28. package/package.json +17 -19
  29. package/src/{JSONParseStream.js → JSONParseStream.ts} +8 -7
  30. package/src/{MockPackageInstaller.js → MockPackageInstaller.ts} +4 -6
  31. package/src/{NodePackageManager.js → NodePackageManager.ts} +88 -57
  32. package/src/{Npm.js → Npm.ts} +9 -9
  33. package/src/{Pnpm.js → Pnpm.ts} +68 -50
  34. package/src/{Yarn.js → Yarn.ts} +38 -25
  35. package/src/{getCurrentPackageManager.js → getCurrentPackageManager.ts} +9 -4
  36. package/src/{index.js → index.ts} +0 -2
  37. package/src/{installPackage.js → installPackage.ts} +5 -6
  38. package/src/{nodejsConditions.js → nodejsConditions.ts} +6 -3
  39. package/src/promiseFromProcess.ts +23 -0
  40. package/src/{utils.js → utils.ts} +21 -11
  41. package/src/{validateModuleSpecifier.js → validateModuleSpecifier.ts} +0 -2
  42. package/test/{NodePackageManager.test.js → NodePackageManager.test.ts} +19 -16
  43. package/test/{getCurrentPackageManager.test.js → getCurrentPackageManager.test.ts} +0 -1
  44. package/test/{validateModuleSpecifiers.test.js → validateModuleSpecifiers.test.ts} +2 -3
  45. package/tsconfig.json +4 -0
  46. package/index.d.ts +0 -40
  47. package/lib/index.d.ts +0 -10
  48. package/lib/index.js.map +0 -1
  49. 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
- const ENTRIES =
45
- MAIN |
46
- (process.env.ATLASPACK_BUILD_ENV !== 'production' ||
47
- process.env.ATLASPACK_SELF_BUILD
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: ?PackageInstaller;
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?: ?PackageInstaller,
72
+ installer?: PackageInstaller | null,
75
73
  ) {
76
74
  this.fs = fs;
77
75
  this.projectRoot = projectRoot;
78
76
  this.installer = installer;
79
77
 
80
- // $FlowFixMe - no type for _extensions
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
- // $FlowFixMe[prop-missing]
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: ?PackageInstaller,
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?: ?SemverRange,
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
- // $FlowFixMe[prop-missing]
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
- // $FlowFixMe
185
+ // @ts-expect-error TS2339
188
186
  let m = new Module(filePath, Module._cache[from] || module.parent);
189
187
 
190
- // $FlowFixMe _extensions not in type
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
- // $FlowFixMe[prop-missing]
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
- // $FlowFixMe
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
- // $FlowFixMe
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
- // $FlowFixMe
225
+ // @ts-expect-error TS2339
228
226
  !Module._extensions[extname]
229
227
  ) {
228
+ // @ts-expect-error TS2339
230
229
  let compile = m._compile;
231
- m._compile = (code, filename) => {
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
- // $FlowFixMe
237
- Module._extensions[extname] = (m, filename) => {
238
- // $FlowFixMe
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
- // $FlowFixMe
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
- // $FlowFixMe[prop-missing]
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
- // $FlowFixMe
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?: ?SemverRange,
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
- // $FlowFixMe - needed for loadParcelPlugin
296
+ // @ts-expect-error TS2339
297
297
  err.code = 'MODULE_NOT_FOUND';
298
298
  throw err;
299
299
  } else {
@@ -322,6 +322,7 @@ export class NodePackageManager implements PackageManager {
322
322
 
323
323
  throw new ThrowableDiagnostic({
324
324
  diagnostic: conflicts.fields.map((field) => ({
325
+ // @ts-expect-error TS2345
325
326
  message: md`Could not find module "${name}", but it was listed in package.json. Run your package manager first.`,
326
327
  origin: '@atlaspack/package-manager',
327
328
  codeFrames: [
@@ -363,6 +364,7 @@ export class NodePackageManager implements PackageManager {
363
364
  } else if (conflicts != null) {
364
365
  throw new ThrowableDiagnostic({
365
366
  diagnostic: {
367
+ // @ts-expect-error TS2345
366
368
  message: md`Could not find module "${name}" satisfying ${range}.`,
367
369
  origin: '@atlaspack/package-manager',
368
370
  codeFrames: [
@@ -385,8 +387,10 @@ export class NodePackageManager implements PackageManager {
385
387
  }
386
388
 
387
389
  let version = pkg?.version;
390
+ // @ts-expect-error TS2345
388
391
  let message = md`Could not resolve package "${name}" that satisfies ${range}.`;
389
392
  if (version != null) {
393
+ // @ts-expect-error TS2345
390
394
  message += md` Found ${version}.`;
391
395
  }
392
396
 
@@ -476,7 +480,10 @@ export class NodePackageManager implements PackageManager {
476
480
  };
477
481
 
478
482
  let seen = new Set();
479
- let addKey = (name, from) => {
483
+ let addKey = (
484
+ name: DependencySpecifier,
485
+ from: FilePath | DependencySpecifier,
486
+ ) => {
480
487
  let basedir = path.dirname(from);
481
488
  let key = basedir + ':' + name;
482
489
  if (seen.has(key)) {
@@ -489,6 +496,7 @@ export class NodePackageManager implements PackageManager {
489
496
  return;
490
497
  }
491
498
 
499
+ // @ts-expect-error TS2345
492
500
  res.invalidateOnFileCreate.push(...resolved.invalidateOnFileCreate);
493
501
  res.invalidateOnFileChange.add(resolved.resolved);
494
502
 
@@ -510,15 +518,19 @@ export class NodePackageManager implements PackageManager {
510
518
  // cannot be intercepted. Instead, ask the resolver to parse the file and recursively analyze the deps.
511
519
  if (resolved.type === 2) {
512
520
  let invalidations = this.resolver.getInvalidations(resolved.resolved);
521
+ // @ts-expect-error TS7006
513
522
  invalidations.invalidateOnFileChange.forEach((i) =>
514
523
  res.invalidateOnFileChange.add(i),
515
524
  );
525
+ // @ts-expect-error TS7006
516
526
  invalidations.invalidateOnFileCreate.forEach((i) =>
527
+ // @ts-expect-error TS2345
517
528
  res.invalidateOnFileCreate.push(i),
518
529
  );
519
530
  res.invalidateOnStartup ||= invalidations.invalidateOnStartup;
520
531
  if (res.invalidateOnStartup) {
521
532
  logger.warn({
533
+ // @ts-expect-error TS2345
522
534
  message: md`${path.relative(
523
535
  this.projectRoot,
524
536
  resolved.resolved,
@@ -528,7 +540,9 @@ export class NodePackageManager implements PackageManager {
528
540
  }
529
541
  }
530
542
 
543
+ // @ts-expect-error TS2345
531
544
  invalidationsCache.set(resolved.resolved, res);
545
+ // @ts-expect-error TS2322
532
546
  return res;
533
547
  }
534
548
 
@@ -542,7 +556,10 @@ export class NodePackageManager implements PackageManager {
542
556
  invalidate(name: DependencySpecifier, from: FilePath) {
543
557
  let seen = new Set();
544
558
 
545
- let invalidate = (name, from) => {
559
+ let invalidate = (
560
+ name: DependencySpecifier,
561
+ from: FilePath | DependencySpecifier,
562
+ ) => {
546
563
  let basedir = path.dirname(from);
547
564
  let key = basedir + ':' + name;
548
565
  if (seen.has(key)) {
@@ -555,12 +572,24 @@ export class NodePackageManager implements PackageManager {
555
572
  return;
556
573
  }
557
574
 
575
+ // During testing don't invalidate Atlaspack modules because
576
+ // this causes failures due to multiple instances of the same module
577
+ // existing simultaniously. This is fine when using babe;-register because
578
+ // it has an internal module cache that NodePacakageManager does not invalidate
579
+ // but fails when using compiled Atlaspack packages in integration tests
580
+ if (
581
+ process.env.ATLASPACK_BUILD_ENV === 'test' &&
582
+ name.startsWith('@atlaspack/')
583
+ ) {
584
+ return;
585
+ }
586
+
558
587
  invalidationsCache.delete(resolved.resolved);
559
588
 
560
- // $FlowFixMe
589
+ // @ts-expect-error TS2339
561
590
  let module = Module._cache[resolved.resolved];
562
591
  if (module) {
563
- // $FlowFixMe
592
+ // @ts-expect-error TS2339
564
593
  delete Module._cache[resolved.resolved];
565
594
  }
566
595
 
@@ -594,17 +623,18 @@ export class NodePackageManager implements PackageManager {
594
623
  // Invalidate whenever the .pnp.js file changes.
595
624
  // TODO: only when we actually resolve a node_modules package?
596
625
  if (process.versions.pnp != null && res.invalidateOnFileChange) {
597
- // $FlowFixMe[prop-missing]
626
+ // @ts-expect-error TS2339
598
627
  let pnp = Module.findPnpApi(path.dirname(from));
599
628
  res.invalidateOnFileChange.push(pnp.resolveToUnqualified('pnpapi', null));
600
629
  }
601
630
 
602
631
  if (res.error) {
603
632
  let e = new Error(`Could not resolve module "${name}" from "${from}"`);
604
- // $FlowFixMe
633
+ // @ts-expect-error TS2339
605
634
  e.code = 'MODULE_NOT_FOUND';
606
635
  throw e;
607
636
  }
637
+ // @ts-expect-error TS7034
608
638
  let getPkg;
609
639
  switch (res.resolution.type) {
610
640
  case 'Path':
@@ -626,6 +656,7 @@ export class NodePackageManager implements PackageManager {
626
656
  invalidateOnFileCreate: res.invalidateOnFileCreate,
627
657
  type: res.moduleType,
628
658
  get pkg() {
659
+ // @ts-expect-error TS7005
629
660
  return getPkg();
630
661
  },
631
662
  };
@@ -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<{name: string, ...}>,
92
- |};
88
+ type NPMResults = {
89
+ added: Array<{
90
+ name: string;
91
+ }>;
92
+ };
93
93
 
94
94
  registerSerializableClass(`${pkg.version}:Npm`, Npm);
@@ -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
- +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;
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
  }