@atlaspack/package-manager 2.14.5-canary.36 → 2.14.5-canary.360

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 (63) hide show
  1. package/CHANGELOG.md +491 -0
  2. package/dist/JSONParseStream.js +37 -0
  3. package/dist/MockPackageInstaller.js +54 -0
  4. package/dist/NodePackageManager.js +559 -0
  5. package/dist/Npm.js +73 -0
  6. package/dist/Pnpm.js +140 -0
  7. package/dist/Yarn.js +124 -0
  8. package/dist/getCurrentPackageManager.js +17 -0
  9. package/dist/index.js +24 -0
  10. package/dist/installPackage.js +197 -0
  11. package/dist/nodejsConditions.js +39 -0
  12. package/dist/promiseFromProcess.js +16 -0
  13. package/dist/utils.js +76 -0
  14. package/dist/validateModuleSpecifier.js +11 -0
  15. package/lib/JSONParseStream.js +52 -0
  16. package/lib/MockPackageInstaller.js +79 -0
  17. package/lib/NodePackageManager.js +621 -0
  18. package/lib/Npm.js +106 -0
  19. package/lib/Pnpm.js +185 -0
  20. package/lib/Yarn.js +160 -0
  21. package/lib/getCurrentPackageManager.js +20 -0
  22. package/lib/index.js +64 -5211
  23. package/lib/installPackage.js +222 -0
  24. package/lib/nodejsConditions.js +41 -0
  25. package/lib/promiseFromProcess.js +20 -0
  26. package/lib/types/JSONParseStream.d.ts +6 -0
  27. package/lib/types/MockPackageInstaller.d.ts +14 -0
  28. package/lib/types/NodePackageManager.d.ts +37 -0
  29. package/lib/types/Npm.d.ts +4 -0
  30. package/lib/types/Pnpm.d.ts +5 -0
  31. package/lib/types/Yarn.d.ts +5 -0
  32. package/lib/types/getCurrentPackageManager.d.ts +4 -0
  33. package/lib/types/index.d.ts +10 -0
  34. package/lib/types/installPackage.d.ts +5 -0
  35. package/lib/types/nodejsConditions.d.ts +3 -0
  36. package/lib/types/promiseFromProcess.d.ts +2 -0
  37. package/lib/types/utils.d.ts +15 -0
  38. package/lib/types/validateModuleSpecifier.d.ts +1 -0
  39. package/lib/utils.js +101 -0
  40. package/lib/validateModuleSpecifier.js +14 -0
  41. package/package.json +17 -20
  42. package/src/{JSONParseStream.js → JSONParseStream.ts} +8 -7
  43. package/src/{MockPackageInstaller.js → MockPackageInstaller.ts} +4 -6
  44. package/src/{NodePackageManager.js → NodePackageManager.ts} +125 -73
  45. package/src/{Npm.js → Npm.ts} +9 -9
  46. package/src/{Pnpm.js → Pnpm.ts} +68 -50
  47. package/src/{Yarn.js → Yarn.ts} +38 -25
  48. package/src/{getCurrentPackageManager.js → getCurrentPackageManager.ts} +9 -4
  49. package/src/{index.js → index.ts} +0 -2
  50. package/src/{installPackage.js → installPackage.ts} +4 -6
  51. package/src/{nodejsConditions.js → nodejsConditions.ts} +6 -3
  52. package/src/promiseFromProcess.ts +23 -0
  53. package/src/{utils.js → utils.ts} +21 -11
  54. package/src/{validateModuleSpecifier.js → validateModuleSpecifier.ts} +0 -2
  55. package/test/{NodePackageManager.test.js → NodePackageManager.test.ts} +19 -16
  56. package/test/{getCurrentPackageManager.test.js → getCurrentPackageManager.test.ts} +0 -1
  57. package/test/{validateModuleSpecifiers.test.js → validateModuleSpecifiers.test.ts} +2 -3
  58. package/tsconfig.json +33 -0
  59. package/tsconfig.tsbuildinfo +1 -0
  60. package/index.d.ts +0 -40
  61. package/lib/index.d.ts +0 -10
  62. package/lib/index.js.map +0 -1
  63. package/src/promiseFromProcess.js +0 -19
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {
3
2
  FilePath,
4
3
  DependencySpecifier,
@@ -41,14 +40,13 @@ 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}`;
49
+ const compileExtensions = new Set(['.ts', '.tsx', '.mts', '.cts']);
52
50
 
53
51
  // There can be more than one instance of NodePackageManager, but node has only a single module cache.
54
52
  // Therefore, the resolution cache and the map of parent to child modules should also be global.
@@ -64,25 +62,34 @@ const invalidationsCache = new Map<string, Invalidations>();
64
62
  export class NodePackageManager implements PackageManager {
65
63
  fs: FileSystem;
66
64
  projectRoot: FilePath;
67
- installer: ?PackageInstaller;
65
+ installer: PackageInstaller | null | undefined;
66
+ // @ts-expect-error TS2749
68
67
  resolver: ResolverBase;
69
68
  currentExtensions: Array<string>;
69
+ atlaspackLinkRoot: string | null;
70
70
 
71
71
  constructor(
72
72
  fs: FileSystem,
73
73
  projectRoot: FilePath,
74
- installer?: ?PackageInstaller,
74
+ installer?: PackageInstaller | null,
75
75
  ) {
76
76
  this.fs = fs;
77
77
  this.projectRoot = projectRoot;
78
78
  this.installer = installer;
79
79
 
80
- // $FlowFixMe - no type for _extensions
80
+ // If using src then assume we're linked and find the link root dir
81
+ this.atlaspackLinkRoot =
82
+ process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
83
+ ? path.resolve(__dirname, '../../../..')
84
+ : null;
85
+
86
+ // @ts-expect-error TS2339
81
87
  this.currentExtensions = Object.keys(Module._extensions).map((e) =>
82
88
  e.substring(1),
83
89
  );
84
90
  }
85
91
 
92
+ // @ts-expect-error TS2749
86
93
  _createResolver(): ResolverBase {
87
94
  return new ResolverBase(this.projectRoot, {
88
95
  fs:
@@ -99,8 +106,8 @@ export class NodePackageManager implements PackageManager {
99
106
  packageExports: true,
100
107
  moduleDirResolver:
101
108
  process.versions.pnp != null
102
- ? (module, from) => {
103
- // $FlowFixMe[prop-missing]
109
+ ? (module: any, from: any) => {
110
+ // @ts-expect-error TS2339
104
111
  let pnp = Module.findPnpApi(path.dirname(from));
105
112
 
106
113
  return pnp.resolveToUnqualified(
@@ -119,12 +126,12 @@ export class NodePackageManager implements PackageManager {
119
126
  return new NodePackageManager(opts.fs, opts.projectRoot, opts.installer);
120
127
  }
121
128
 
122
- serialize(): {|
123
- $$raw: boolean,
124
- fs: FileSystem,
125
- projectRoot: FilePath,
126
- installer: ?PackageInstaller,
127
- |} {
129
+ serialize(): {
130
+ $$raw: boolean;
131
+ fs: FileSystem;
132
+ projectRoot: FilePath;
133
+ installer: PackageInstaller | null | undefined;
134
+ } {
128
135
  return {
129
136
  $$raw: false,
130
137
  fs: this.fs,
@@ -136,11 +143,11 @@ export class NodePackageManager implements PackageManager {
136
143
  async require(
137
144
  name: DependencySpecifier,
138
145
  from: FilePath,
139
- opts: ?{|
140
- range?: ?SemverRange,
141
- shouldAutoInstall?: boolean,
142
- saveDev?: boolean,
143
- |},
146
+ opts?: {
147
+ range?: SemverRange | null | undefined;
148
+ shouldAutoInstall?: boolean;
149
+ saveDev?: boolean;
150
+ } | null,
144
151
  ): Promise<any> {
145
152
  let {resolved, type} = await this.resolve(name, from, opts);
146
153
  if (type === 2) {
@@ -157,10 +164,10 @@ export class NodePackageManager implements PackageManager {
157
164
 
158
165
  // On Windows, Node requires absolute paths to be file URLs.
159
166
  if (process.platform === 'win32' && path.isAbsolute(resolved)) {
167
+ // @ts-expect-error TS2322
160
168
  resolved = pathToFileURL(resolved);
161
169
  }
162
170
 
163
- // $FlowFixMe
164
171
  return import(resolved);
165
172
  }
166
173
  return this.load(resolved, from);
@@ -174,20 +181,19 @@ export class NodePackageManager implements PackageManager {
174
181
  load(filePath: FilePath, from: FilePath): any {
175
182
  if (!path.isAbsolute(filePath)) {
176
183
  // Node builtin module
177
- // $FlowFixMe
178
184
  return require(filePath);
179
185
  }
180
186
 
181
- // $FlowFixMe[prop-missing]
187
+ // @ts-expect-error TS2339
182
188
  const cachedModule = Module._cache[filePath];
183
189
  if (cachedModule !== undefined) {
184
190
  return cachedModule.exports;
185
191
  }
186
192
 
187
- // $FlowFixMe
193
+ // @ts-expect-error TS2339
188
194
  let m = new Module(filePath, Module._cache[from] || module.parent);
189
195
 
190
- // $FlowFixMe _extensions not in type
196
+ // @ts-expect-error TS2339
191
197
  const extensions = Object.keys(Module._extensions);
192
198
  // This handles supported extensions changing due to, for example, esbuild/register being used
193
199
  // We assume that the extension list will change in size - as these tools usually add support for
@@ -197,62 +203,82 @@ export class NodePackageManager implements PackageManager {
197
203
  this.resolver = this._createResolver();
198
204
  }
199
205
 
200
- // $FlowFixMe[prop-missing]
206
+ // @ts-expect-error TS2339
201
207
  Module._cache[filePath] = m;
202
208
 
203
209
  // Patch require within this module so it goes through our require
204
- m.require = (id) => {
210
+ m.require = (id: any) => {
205
211
  return this.requireSync(id, filePath);
206
212
  };
207
213
 
208
214
  // Patch `fs.readFileSync` temporarily so that it goes through our file system
209
215
  let {readFileSync, statSync} = nativeFS;
210
- // $FlowFixMe
211
- nativeFS.readFileSync = (filename, encoding) => {
216
+ // @ts-expect-error TS2322
217
+ nativeFS.readFileSync = (filename: any, encoding: any) => {
212
218
  return this.fs.readFileSync(filename, encoding);
213
219
  };
214
220
 
215
- // $FlowFixMe
216
- nativeFS.statSync = (filename) => {
221
+ // @ts-expect-error TS2540
222
+ nativeFS.statSync = (filename: any) => {
217
223
  return this.fs.statSync(filename);
218
224
  };
219
225
 
220
- if (!filePath.includes(NODE_MODULES)) {
221
- let extname = path.extname(filePath);
222
- if (
223
- (extname === '.ts' ||
224
- extname === '.tsx' ||
225
- extname === '.mts' ||
226
- extname === '.cts') &&
227
- // $FlowFixMe
228
- !Module._extensions[extname]
229
- ) {
230
- let compile = m._compile;
231
- m._compile = (code, filename) => {
232
- let out = transformSync(code, {filename, module: {type: 'commonjs'}});
233
- compile.call(m, out.code, filename);
234
- };
226
+ let extname = path.extname(filePath);
235
227
 
236
- // $FlowFixMe
237
- Module._extensions[extname] = (m, filename) => {
238
- // $FlowFixMe
239
- delete Module._extensions[extname];
240
- // $FlowFixMe
241
- Module._extensions['.js'](m, filename);
242
- };
228
+ function shouldCompile(atlaspackLinkRoot: string | null): boolean {
229
+ if (filePath.includes(NODE_MODULES)) {
230
+ // Don't compile node_modules
231
+ return false;
232
+ }
233
+
234
+ if (!compileExtensions.has(extname)) {
235
+ // Ignore non-TS files
236
+ return false;
237
+ }
238
+
239
+ if (atlaspackLinkRoot != null) {
240
+ // If we're linked, only compile files outside the linked atlaspack
241
+ // as those are handled by @atlaspack/babel-register
242
+ return !filePath.startsWith(atlaspackLinkRoot);
243
243
  }
244
+
245
+ // @ts-expect-error TS2339
246
+ // Lastly make sure there's no existing loader for this extension
247
+ return !Module._extensions[extname];
248
+ }
249
+
250
+ if (shouldCompile(this.atlaspackLinkRoot)) {
251
+ // @ts-expect-error TS2339
252
+ let compile = m._compile;
253
+ // @ts-expect-error TS2339
254
+ m._compile = (code: any, filename: any) => {
255
+ let out = transformSync(code, {
256
+ filename,
257
+ module: {type: 'commonjs'},
258
+ env: {targets: {node: '18'}},
259
+ });
260
+ compile.call(m, out.code, filename);
261
+ };
262
+
263
+ // @ts-expect-error TS2339
264
+ Module._extensions[extname] = (m: any, filename: any) => {
265
+ // @ts-expect-error TS2339
266
+ delete Module._extensions[extname];
267
+ // @ts-expect-error TS2339
268
+ Module._extensions['.js'](m, filename);
269
+ };
244
270
  }
245
271
 
246
272
  try {
273
+ // @ts-expect-error TS2339
247
274
  m.load(filePath);
248
- } catch (err) {
249
- // $FlowFixMe[prop-missing]
275
+ } catch (err: any) {
276
+ // @ts-expect-error TS2339
250
277
  delete Module._cache[filePath];
251
278
  throw err;
252
279
  } finally {
253
- // $FlowFixMe
254
280
  nativeFS.readFileSync = readFileSync;
255
- // $FlowFixMe
281
+ // @ts-expect-error TS2540
256
282
  nativeFS.statSync = statSync;
257
283
  }
258
284
 
@@ -262,11 +288,11 @@ export class NodePackageManager implements PackageManager {
262
288
  async resolve(
263
289
  id: DependencySpecifier,
264
290
  from: FilePath,
265
- options?: ?{|
266
- range?: ?SemverRange,
267
- shouldAutoInstall?: boolean,
268
- saveDev?: boolean,
269
- |},
291
+ options?: {
292
+ range?: SemverRange | null | undefined;
293
+ shouldAutoInstall?: boolean;
294
+ saveDev?: boolean;
295
+ } | null,
270
296
  ): Promise<PackageManagerResolveResult> {
271
297
  let basedir = path.dirname(from);
272
298
  let key = basedir + ':' + id;
@@ -275,7 +301,7 @@ export class NodePackageManager implements PackageManager {
275
301
  let [name] = getModuleParts(id);
276
302
  try {
277
303
  resolved = this.resolveInternal(id, from);
278
- } catch (e) {
304
+ } catch (e: any) {
279
305
  if (
280
306
  e.code !== 'MODULE_NOT_FOUND' ||
281
307
  options?.shouldAutoInstall !== true ||
@@ -293,7 +319,7 @@ export class NodePackageManager implements PackageManager {
293
319
  ],
294
320
  },
295
321
  });
296
- // $FlowFixMe - needed for loadParcelPlugin
322
+ // @ts-expect-error TS2339
297
323
  err.code = 'MODULE_NOT_FOUND';
298
324
  throw err;
299
325
  } else {
@@ -476,7 +502,10 @@ export class NodePackageManager implements PackageManager {
476
502
  };
477
503
 
478
504
  let seen = new Set();
479
- let addKey = (name, from) => {
505
+ let addKey = (
506
+ name: DependencySpecifier,
507
+ from: FilePath | DependencySpecifier,
508
+ ) => {
480
509
  let basedir = path.dirname(from);
481
510
  let key = basedir + ':' + name;
482
511
  if (seen.has(key)) {
@@ -489,6 +518,7 @@ export class NodePackageManager implements PackageManager {
489
518
  return;
490
519
  }
491
520
 
521
+ // @ts-expect-error TS2345
492
522
  res.invalidateOnFileCreate.push(...resolved.invalidateOnFileCreate);
493
523
  res.invalidateOnFileChange.add(resolved.resolved);
494
524
 
@@ -510,10 +540,13 @@ export class NodePackageManager implements PackageManager {
510
540
  // cannot be intercepted. Instead, ask the resolver to parse the file and recursively analyze the deps.
511
541
  if (resolved.type === 2) {
512
542
  let invalidations = this.resolver.getInvalidations(resolved.resolved);
543
+ // @ts-expect-error TS7006
513
544
  invalidations.invalidateOnFileChange.forEach((i) =>
514
545
  res.invalidateOnFileChange.add(i),
515
546
  );
547
+ // @ts-expect-error TS7006
516
548
  invalidations.invalidateOnFileCreate.forEach((i) =>
549
+ // @ts-expect-error TS2345
517
550
  res.invalidateOnFileCreate.push(i),
518
551
  );
519
552
  res.invalidateOnStartup ||= invalidations.invalidateOnStartup;
@@ -528,7 +561,9 @@ export class NodePackageManager implements PackageManager {
528
561
  }
529
562
  }
530
563
 
564
+ // @ts-expect-error TS2345
531
565
  invalidationsCache.set(resolved.resolved, res);
566
+ // @ts-expect-error TS2322
532
567
  return res;
533
568
  }
534
569
 
@@ -542,7 +577,10 @@ export class NodePackageManager implements PackageManager {
542
577
  invalidate(name: DependencySpecifier, from: FilePath) {
543
578
  let seen = new Set();
544
579
 
545
- let invalidate = (name, from) => {
580
+ let invalidate = (
581
+ name: DependencySpecifier,
582
+ from: FilePath | DependencySpecifier,
583
+ ) => {
546
584
  let basedir = path.dirname(from);
547
585
  let key = basedir + ':' + name;
548
586
  if (seen.has(key)) {
@@ -555,12 +593,24 @@ export class NodePackageManager implements PackageManager {
555
593
  return;
556
594
  }
557
595
 
596
+ // During testing don't invalidate Atlaspack modules because
597
+ // this causes failures due to multiple instances of the same module
598
+ // existing simultaniously. This is fine when using babe;-register because
599
+ // it has an internal module cache that NodePacakageManager does not invalidate
600
+ // but fails when using compiled Atlaspack packages in integration tests
601
+ if (
602
+ process.env.ATLASPACK_BUILD_ENV === 'test' &&
603
+ name.startsWith('@atlaspack/')
604
+ ) {
605
+ return;
606
+ }
607
+
558
608
  invalidationsCache.delete(resolved.resolved);
559
609
 
560
- // $FlowFixMe
610
+ // @ts-expect-error TS2339
561
611
  let module = Module._cache[resolved.resolved];
562
612
  if (module) {
563
- // $FlowFixMe
613
+ // @ts-expect-error TS2339
564
614
  delete Module._cache[resolved.resolved];
565
615
  }
566
616
 
@@ -594,17 +644,18 @@ export class NodePackageManager implements PackageManager {
594
644
  // Invalidate whenever the .pnp.js file changes.
595
645
  // TODO: only when we actually resolve a node_modules package?
596
646
  if (process.versions.pnp != null && res.invalidateOnFileChange) {
597
- // $FlowFixMe[prop-missing]
647
+ // @ts-expect-error TS2339
598
648
  let pnp = Module.findPnpApi(path.dirname(from));
599
649
  res.invalidateOnFileChange.push(pnp.resolveToUnqualified('pnpapi', null));
600
650
  }
601
651
 
602
652
  if (res.error) {
603
653
  let e = new Error(`Could not resolve module "${name}" from "${from}"`);
604
- // $FlowFixMe
654
+ // @ts-expect-error TS2339
605
655
  e.code = 'MODULE_NOT_FOUND';
606
656
  throw e;
607
657
  }
658
+ // @ts-expect-error TS7034
608
659
  let getPkg;
609
660
  switch (res.resolution.type) {
610
661
  case 'Path':
@@ -626,6 +677,7 @@ export class NodePackageManager implements PackageManager {
626
677
  invalidateOnFileCreate: res.invalidateOnFileCreate,
627
678
  type: res.moduleType,
628
679
  get pkg() {
680
+ // @ts-expect-error TS7005
629
681
  return getPkg();
630
682
  },
631
683
  };
@@ -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
  }