@atlaspack/package-manager 2.14.19 → 2.14.21-typescript-08dcc1c9b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +201 -0
- package/lib/JSONParseStream.js +1 -2
- package/lib/NodePackageManager.js +44 -24
- package/lib/Npm.js +2 -1
- package/lib/Pnpm.js +18 -4
- package/lib/Yarn.js +17 -3
- package/lib/getCurrentPackageManager.js +3 -1
- package/lib/installPackage.js +1 -0
- package/lib/nodejsConditions.js +6 -0
- package/lib/promiseFromProcess.js +2 -0
- package/package.json +15 -15
- package/src/{JSONParseStream.js → JSONParseStream.ts} +8 -7
- package/src/{MockPackageInstaller.js → MockPackageInstaller.ts} +4 -6
- package/src/{NodePackageManager.js → NodePackageManager.ts} +72 -51
- package/src/{Npm.js → Npm.ts} +9 -9
- package/src/{Pnpm.js → Pnpm.ts} +68 -50
- package/src/{Yarn.js → Yarn.ts} +38 -25
- package/src/{getCurrentPackageManager.js → getCurrentPackageManager.ts} +9 -4
- package/src/{index.js → index.ts} +0 -2
- package/src/{installPackage.js → installPackage.ts} +5 -6
- package/src/{nodejsConditions.js → nodejsConditions.ts} +6 -3
- package/src/promiseFromProcess.ts +23 -0
- package/src/{utils.js → utils.ts} +21 -11
- package/src/{validateModuleSpecifier.js → validateModuleSpecifier.ts} +0 -2
- package/test/{NodePackageManager.test.js → NodePackageManager.test.ts} +13 -15
- package/test/{getCurrentPackageManager.test.js → getCurrentPackageManager.test.ts} +0 -1
- package/test/{validateModuleSpecifiers.test.js → validateModuleSpecifiers.test.ts} +2 -3
- package/tsconfig.json +4 -0
- package/lib/index.d.ts +0 -10
- package/src/promiseFromProcess.js +0 -19
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
|
}
|
package/src/{Yarn.js → Yarn.ts}
RENAMED
@@ -1,41 +1,49 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
|
3
1
|
import type {PackageInstaller, InstallerOptions} from '@atlaspack/types';
|
4
2
|
|
3
|
+
// @ts-expect-error TS7016
|
5
4
|
import commandExists from 'command-exists';
|
5
|
+
// @ts-expect-error TS7016
|
6
6
|
import spawn from 'cross-spawn';
|
7
7
|
import {registerSerializableClass} from '@atlaspack/build-cache';
|
8
8
|
import logger from '@atlaspack/logger';
|
9
|
+
// @ts-expect-error TS7016
|
9
10
|
import split from 'split2';
|
10
11
|
import JSONParseStream from './JSONParseStream';
|
11
12
|
import promiseFromProcess from './promiseFromProcess';
|
12
13
|
import {exec, npmSpecifierFromModuleRequest} from './utils';
|
13
14
|
|
14
|
-
// $FlowFixMe
|
15
15
|
import pkg from '../package.json';
|
16
16
|
|
17
17
|
const YARN_CMD = 'yarn';
|
18
18
|
|
19
19
|
type YarnStdOutMessage =
|
20
|
-
| {
|
21
|
-
|
22
|
-
data: {
|
23
|
-
message: string
|
24
|
-
current: number
|
25
|
-
total: number
|
26
|
-
|
27
|
-
|
28
|
-
| {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
20
|
+
| {
|
21
|
+
readonly type: 'step';
|
22
|
+
data: {
|
23
|
+
message: string;
|
24
|
+
current: number;
|
25
|
+
total: number;
|
26
|
+
};
|
27
|
+
}
|
28
|
+
| {
|
29
|
+
readonly type: 'success';
|
30
|
+
data: string;
|
31
|
+
}
|
32
|
+
| {
|
33
|
+
readonly type: 'info';
|
34
|
+
data: string;
|
35
|
+
}
|
36
|
+
| {
|
37
|
+
readonly type: 'tree' | 'progressStart' | 'progressTick';
|
38
|
+
};
|
39
|
+
|
40
|
+
type YarnStdErrMessage = {
|
41
|
+
readonly type: 'error' | 'warning';
|
42
|
+
data: string;
|
43
|
+
};
|
44
|
+
|
45
|
+
let hasYarn: boolean | null | undefined;
|
46
|
+
let yarnVersion: number | null | undefined;
|
39
47
|
|
40
48
|
export class Yarn implements PackageInstaller {
|
41
49
|
static async exists(): Promise<boolean> {
|
@@ -45,7 +53,7 @@ export class Yarn implements PackageInstaller {
|
|
45
53
|
|
46
54
|
try {
|
47
55
|
hasYarn = Boolean(await commandExists('yarn'));
|
48
|
-
} catch (err) {
|
56
|
+
} catch (err: any) {
|
49
57
|
hasYarn = false;
|
50
58
|
}
|
51
59
|
|
@@ -59,6 +67,7 @@ export class Yarn implements PackageInstaller {
|
|
59
67
|
}: InstallerOptions): Promise<void> {
|
60
68
|
if (yarnVersion == null) {
|
61
69
|
let version = await exec('yarn --version');
|
70
|
+
// @ts-expect-error TS2345
|
62
71
|
yarnVersion = parseInt(version.stdout, 10);
|
63
72
|
}
|
64
73
|
|
@@ -76,7 +85,7 @@ export class Yarn implements PackageInstaller {
|
|
76
85
|
// When Parcel is run by Yarn (e.g. via package.json scripts), several environment variables are
|
77
86
|
// added. When parcel in turn calls Yarn again, these can cause Yarn to behave stragely, so we
|
78
87
|
// filter them out when installing packages.
|
79
|
-
let env = {};
|
88
|
+
let env: Record<string, any> = {};
|
80
89
|
for (let key in process.env) {
|
81
90
|
if (
|
82
91
|
!key.startsWith('npm_') &&
|
@@ -92,7 +101,9 @@ export class Yarn implements PackageInstaller {
|
|
92
101
|
installProcess.stdout
|
93
102
|
// Invoking yarn with --json provides streaming, newline-delimited JSON output.
|
94
103
|
.pipe(split())
|
104
|
+
// @ts-expect-error TS2554
|
95
105
|
.pipe(new JSONParseStream())
|
106
|
+
// @ts-expect-error TS7006
|
96
107
|
.on('error', (e) => {
|
97
108
|
logger.error(e, '@atlaspack/package-manager');
|
98
109
|
})
|
@@ -119,7 +130,9 @@ export class Yarn implements PackageInstaller {
|
|
119
130
|
|
120
131
|
installProcess.stderr
|
121
132
|
.pipe(split())
|
133
|
+
// @ts-expect-error TS2554
|
122
134
|
.pipe(new JSONParseStream())
|
135
|
+
// @ts-expect-error TS7006
|
123
136
|
.on('error', (e) => {
|
124
137
|
logger.error(e, '@atlaspack/package-manager');
|
125
138
|
})
|
@@ -144,7 +157,7 @@ export class Yarn implements PackageInstaller {
|
|
144
157
|
|
145
158
|
try {
|
146
159
|
return await promiseFromProcess(installProcess);
|
147
|
-
} catch (e) {
|
160
|
+
} catch (e: any) {
|
148
161
|
throw new Error('Yarn failed to install modules:' + e.message);
|
149
162
|
}
|
150
163
|
}
|
@@ -1,8 +1,13 @@
|
|
1
|
-
// @flow
|
2
|
-
|
3
1
|
export default function getCurrentPackageManager(
|
4
|
-
|
5
|
-
|
2
|
+
// @ts-expect-error TS2322
|
3
|
+
userAgent: string | null = process.env.npm_config_user_agent,
|
4
|
+
):
|
5
|
+
| {
|
6
|
+
name: string;
|
7
|
+
version: string;
|
8
|
+
}
|
9
|
+
| null
|
10
|
+
| undefined {
|
6
11
|
if (!userAgent) {
|
7
12
|
return undefined;
|
8
13
|
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
// @flow
|
2
|
-
|
3
1
|
import type {FilePath, PackageJSON} from '@atlaspack/types';
|
4
2
|
import type {
|
5
3
|
ModuleRequest,
|
@@ -62,7 +60,7 @@ async function install(
|
|
62
60
|
packagePath: fromPkgPath,
|
63
61
|
fs,
|
64
62
|
});
|
65
|
-
} catch (err) {
|
63
|
+
} catch (err: any) {
|
66
64
|
throw new Error(`Failed to install ${moduleNames}: ${err.message}`);
|
67
65
|
}
|
68
66
|
|
@@ -88,7 +86,7 @@ async function installPeerDependencies(
|
|
88
86
|
module: ModuleRequest,
|
89
87
|
from: FilePath,
|
90
88
|
projectRoot: FilePath,
|
91
|
-
options,
|
89
|
+
options: InstallOptions,
|
92
90
|
) {
|
93
91
|
const {resolved} = await packageManager.resolve(module.name, from);
|
94
92
|
const modulePkg: PackageJSON = nullthrows(
|
@@ -112,6 +110,7 @@ async function installPeerDependencies(
|
|
112
110
|
if (!semver.satisfies(pkg.version, range)) {
|
113
111
|
throw new ThrowableDiagnostic({
|
114
112
|
diagnostic: {
|
113
|
+
// @ts-expect-error TS2345
|
115
114
|
message: md`Could not install the peer dependency "${name}" for "${module.name}", installed version ${pkg.version} is incompatible with ${range}`,
|
116
115
|
origin: '@atlaspack/package-manager',
|
117
116
|
codeFrames: [
|
@@ -205,7 +204,7 @@ export function _addToInstallQueue(
|
|
205
204
|
filePath: FilePath,
|
206
205
|
projectRoot: FilePath,
|
207
206
|
options?: InstallOptions,
|
208
|
-
): Promise<
|
207
|
+
): Promise<unknown> {
|
209
208
|
modules = modules.map((request) => ({
|
210
209
|
name: validateModuleSpecifier(request.name),
|
211
210
|
range: request.range,
|
@@ -248,7 +247,7 @@ export function installPackage(
|
|
248
247
|
filePath: FilePath,
|
249
248
|
projectRoot: FilePath,
|
250
249
|
options?: InstallOptions,
|
251
|
-
): Promise<
|
250
|
+
): Promise<unknown> {
|
252
251
|
if (WorkerFarm.isWorker()) {
|
253
252
|
let workerApi = WorkerFarm.getWorkerApi();
|
254
253
|
// TODO this should really be `__filename` but without the rewriting.
|
@@ -1,8 +1,8 @@
|
|
1
|
-
// @flow
|
2
1
|
import process from 'process';
|
3
2
|
|
4
3
|
// https://nodejs.org/api/packages.html#conditional-exports
|
5
4
|
// TODO We don't support { "type": "module" }
|
5
|
+
// @ts-expect-error TS4104
|
6
6
|
export const defaultNodejsConditions: Array<string> = Object.freeze([
|
7
7
|
'node-addons',
|
8
8
|
'node',
|
@@ -12,24 +12,27 @@ export const defaultNodejsConditions: Array<string> = Object.freeze([
|
|
12
12
|
'default',
|
13
13
|
]);
|
14
14
|
|
15
|
-
let envConditions:
|
15
|
+
let envConditions: undefined | Array<string> = undefined;
|
16
16
|
|
17
17
|
/** @description Gets the export conditions from NODE_OPTIONS and node arguments */
|
18
18
|
export function getConditionsFromEnv(): Array<string> {
|
19
19
|
if (!envConditions) {
|
20
|
-
const conditions = [];
|
20
|
+
const conditions: Array<never> = [];
|
21
21
|
|
22
22
|
for (const arg of [
|
23
23
|
...process.execArgv,
|
24
24
|
...(process.env.NODE_OPTIONS || '').split(' '),
|
25
25
|
]) {
|
26
26
|
if (arg.startsWith('--conditions=')) {
|
27
|
+
// @ts-expect-error TS2345
|
27
28
|
conditions.push(arg.substring(13));
|
28
29
|
}
|
29
30
|
}
|
30
31
|
|
32
|
+
// @ts-expect-error TS4104
|
31
33
|
envConditions = Object.freeze([...conditions, ...defaultNodejsConditions]);
|
32
34
|
}
|
33
35
|
|
36
|
+
// @ts-expect-error TS2322
|
34
37
|
return envConditions;
|
35
38
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type {ChildProcess} from 'child_process';
|
2
|
+
|
3
|
+
export default function promiseFromProcess(
|
4
|
+
childProcess: ChildProcess,
|
5
|
+
): Promise<void> {
|
6
|
+
return new Promise(
|
7
|
+
(
|
8
|
+
resolve: (result: Promise<undefined> | undefined) => void,
|
9
|
+
reject: (error?: any) => void,
|
10
|
+
) => {
|
11
|
+
childProcess.on('error', reject);
|
12
|
+
childProcess.on('close', (code) => {
|
13
|
+
if (code !== 0) {
|
14
|
+
reject(new Error('Child process failed'));
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
|
18
|
+
// @ts-expect-error TS2794
|
19
|
+
resolve();
|
20
|
+
});
|
21
|
+
},
|
22
|
+
);
|
23
|
+
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
|
3
1
|
import type {FilePath, ModuleRequest} from '@atlaspack/types';
|
4
2
|
import type {FileSystem} from '@atlaspack/fs';
|
5
3
|
|
@@ -11,8 +9,12 @@ import {promisify} from 'util';
|
|
11
9
|
|
12
10
|
export const exec: (
|
13
11
|
command: string,
|
14
|
-
|
15
|
-
|
12
|
+
// @ts-expect-error TS2503
|
13
|
+
options?: child_process.execOpts,
|
14
|
+
) => Promise<{
|
15
|
+
stdout: string | Buffer;
|
16
|
+
stderr: string | Buffer;
|
17
|
+
}> = _exec
|
16
18
|
? promisify(_exec)
|
17
19
|
: // _exec is undefined in browser builds
|
18
20
|
_exec;
|
@@ -25,10 +27,10 @@ export function npmSpecifierFromModuleRequest(
|
|
25
27
|
: moduleRequest.name;
|
26
28
|
}
|
27
29
|
|
28
|
-
export function moduleRequestsFromDependencyMap(dependencyMap: {
|
29
|
-
[string]: string
|
30
|
-
|
31
|
-
return Object.entries(dependencyMap).map(([name, range]) => {
|
30
|
+
export function moduleRequestsFromDependencyMap(dependencyMap: {
|
31
|
+
[key: string]: string;
|
32
|
+
}): Array<ModuleRequest> {
|
33
|
+
return Object.entries(dependencyMap).map(([name, range]: [any, any]) => {
|
32
34
|
invariant(typeof range === 'string');
|
33
35
|
return {
|
34
36
|
name,
|
@@ -42,7 +44,15 @@ export async function getConflictingLocalDependencies(
|
|
42
44
|
name: string,
|
43
45
|
local: FilePath,
|
44
46
|
projectRoot: FilePath,
|
45
|
-
): Promise
|
47
|
+
): Promise<
|
48
|
+
| {
|
49
|
+
json: string;
|
50
|
+
filePath: FilePath;
|
51
|
+
fields: Array<string>;
|
52
|
+
}
|
53
|
+
| null
|
54
|
+
| undefined
|
55
|
+
> {
|
46
56
|
let pkgPath = await resolveConfig(fs, local, ['package.json'], projectRoot);
|
47
57
|
if (pkgPath == null) {
|
48
58
|
return;
|
@@ -52,7 +62,7 @@ export async function getConflictingLocalDependencies(
|
|
52
62
|
let pkg;
|
53
63
|
try {
|
54
64
|
pkg = JSON.parse(pkgStr);
|
55
|
-
} catch (e) {
|
65
|
+
} catch (e: any) {
|
56
66
|
// TODO: codeframe
|
57
67
|
throw new ThrowableDiagnostic({
|
58
68
|
diagnostic: {
|
@@ -72,7 +82,7 @@ export async function getConflictingLocalDependencies(
|
|
72
82
|
});
|
73
83
|
}
|
74
84
|
|
75
|
-
let fields = [];
|
85
|
+
let fields: Array<string> = [];
|
76
86
|
for (let field of ['dependencies', 'devDependencies', 'peerDependencies']) {
|
77
87
|
if (
|
78
88
|
typeof pkg[field] === 'object' &&
|
@@ -1,5 +1,3 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
|
3
1
|
import {MemoryFS, NodeFS, OverlayFS} from '@atlaspack/fs';
|
4
2
|
import assert from 'assert';
|
5
3
|
import invariant from 'assert';
|
@@ -14,11 +12,11 @@ import {MockPackageInstaller, NodePackageManager} from '../src';
|
|
14
12
|
const FIXTURES_DIR = path.join(__dirname, 'fixtures');
|
15
13
|
const ROOT_DIR = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
16
14
|
|
17
|
-
function normalize(res) {
|
15
|
+
function normalize(res: any) {
|
18
16
|
return {
|
19
17
|
...res,
|
20
18
|
invalidateOnFileCreate:
|
21
|
-
res?.invalidateOnFileCreate?.sort((a, b) => {
|
19
|
+
res?.invalidateOnFileCreate?.sort((a: any, b: any) => {
|
22
20
|
let ax =
|
23
21
|
a.filePath ??
|
24
22
|
a.glob ??
|
@@ -36,15 +34,15 @@ function normalize(res) {
|
|
36
34
|
};
|
37
35
|
}
|
38
36
|
|
39
|
-
function check(resolved, expected) {
|
37
|
+
function check(resolved: any, expected: any) {
|
40
38
|
assert.deepEqual(normalize(resolved), normalize(expected));
|
41
39
|
}
|
42
40
|
|
43
41
|
describe('NodePackageManager', function () {
|
44
|
-
let fs;
|
45
|
-
let packageManager;
|
46
|
-
let packageInstaller;
|
47
|
-
let workerFarm;
|
42
|
+
let fs: any;
|
43
|
+
let packageManager: any;
|
44
|
+
let packageInstaller: any;
|
45
|
+
let workerFarm: any;
|
48
46
|
|
49
47
|
// These can sometimes take a lil while
|
50
48
|
this.timeout(20000);
|
@@ -77,6 +75,7 @@ describe('NodePackageManager', function () {
|
|
77
75
|
type: 1,
|
78
76
|
invalidateOnFileChange: new Set([
|
79
77
|
path.join(FIXTURES_DIR, 'has-foo/node_modules/foo/package.json'),
|
78
|
+
path.join(ROOT_DIR, '/packages/core/package-manager/tsconfig.json'),
|
80
79
|
path.join(ROOT_DIR, 'tsconfig.json'),
|
81
80
|
]),
|
82
81
|
invalidateOnFileCreate: [
|
@@ -132,6 +131,7 @@ describe('NodePackageManager', function () {
|
|
132
131
|
type: 1,
|
133
132
|
invalidateOnFileChange: new Set([
|
134
133
|
path.join(FIXTURES_DIR, 'has-foo/node_modules/a/package.json'),
|
134
|
+
path.join(ROOT_DIR, '/packages/core/package-manager/tsconfig.json'),
|
135
135
|
path.join(ROOT_DIR, 'tsconfig.json'),
|
136
136
|
]),
|
137
137
|
invalidateOnFileCreate: [
|
@@ -163,7 +163,6 @@ describe('NodePackageManager', function () {
|
|
163
163
|
it('does not autoinstall packages that are already listed in package.json', async () => {
|
164
164
|
packageInstaller.register('a', fs, path.join(FIXTURES_DIR, 'packages/a'));
|
165
165
|
|
166
|
-
// $FlowFixMe assert.rejects is Node 10+
|
167
166
|
await assert.rejects(
|
168
167
|
() =>
|
169
168
|
packageManager.resolve(
|
@@ -171,7 +170,7 @@ describe('NodePackageManager', function () {
|
|
171
170
|
path.join(FIXTURES_DIR, 'has-a-not-yet-installed/index.js'),
|
172
171
|
{shouldAutoInstall: true},
|
173
172
|
),
|
174
|
-
(err) => {
|
173
|
+
(err: any) => {
|
175
174
|
invariant(err instanceof ThrowableDiagnostic);
|
176
175
|
assert(err.message.includes('Run your package manager'));
|
177
176
|
return true;
|
@@ -252,7 +251,6 @@ describe('NodePackageManager', function () {
|
|
252
251
|
path.join(FIXTURES_DIR, 'has-foo/index.js'),
|
253
252
|
);
|
254
253
|
|
255
|
-
// $FlowFixMe assert.rejects is Node 10+
|
256
254
|
await assert.rejects(
|
257
255
|
() =>
|
258
256
|
packageManager.resolve(
|
@@ -262,7 +260,7 @@ describe('NodePackageManager', function () {
|
|
262
260
|
range: '^2.0.0',
|
263
261
|
},
|
264
262
|
),
|
265
|
-
(err) => {
|
263
|
+
(err: any) => {
|
266
264
|
invariant(err instanceof ThrowableDiagnostic);
|
267
265
|
assert.equal(
|
268
266
|
err.message,
|
@@ -305,6 +303,7 @@ describe('NodePackageManager', function () {
|
|
305
303
|
FIXTURES_DIR,
|
306
304
|
'has-foo/subpackage/node_modules/foo/package.json',
|
307
305
|
),
|
306
|
+
path.join(ROOT_DIR, '/packages/core/package-manager/tsconfig.json'),
|
308
307
|
path.join(ROOT_DIR, 'tsconfig.json'),
|
309
308
|
]),
|
310
309
|
invalidateOnFileCreate: [
|
@@ -364,7 +363,6 @@ describe('NodePackageManager', function () {
|
|
364
363
|
path.join(FIXTURES_DIR, 'packages/peers-2.0'),
|
365
364
|
);
|
366
365
|
|
367
|
-
// $FlowFixMe assert.rejects is Node 10+
|
368
366
|
await assert.rejects(
|
369
367
|
() =>
|
370
368
|
packageManager.resolve(
|
@@ -375,7 +373,7 @@ describe('NodePackageManager', function () {
|
|
375
373
|
shouldAutoInstall: true,
|
376
374
|
},
|
377
375
|
),
|
378
|
-
(err) => {
|
376
|
+
(err: any) => {
|
379
377
|
assert(err instanceof ThrowableDiagnostic);
|
380
378
|
assert.equal(
|
381
379
|
err.message,
|
@@ -1,4 +1,3 @@
|
|
1
|
-
// @flow
|
2
1
|
import assert from 'assert';
|
3
2
|
|
4
3
|
import validateModuleSpecifier from '../src/validateModuleSpecifier';
|
@@ -15,7 +14,7 @@ describe('Validate Module Specifiers', () => {
|
|
15
14
|
];
|
16
15
|
|
17
16
|
assert.deepEqual(
|
18
|
-
modules.map((module) => validateModuleSpecifier(module)),
|
17
|
+
modules.map((module: any) => validateModuleSpecifier(module)),
|
19
18
|
[
|
20
19
|
'@atlaspack/transformer-posthtml',
|
21
20
|
'@some-org/package@v1.0.0',
|
@@ -31,7 +30,7 @@ describe('Validate Module Specifiers', () => {
|
|
31
30
|
let modules = ['./somewhere.js', './hello/world.js', '~/hello/world.js'];
|
32
31
|
|
33
32
|
assert.deepEqual(
|
34
|
-
modules.map((module) => validateModuleSpecifier(module)),
|
33
|
+
modules.map((module: any) => validateModuleSpecifier(module)),
|
35
34
|
['', '', ''],
|
36
35
|
);
|
37
36
|
});
|
package/tsconfig.json
ADDED