@atlaspack/package-manager 2.12.1-canary.3354
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/LICENSE +201 -0
- package/index.d.ts +40 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +5188 -0
- package/lib/index.js.map +1 -0
- package/package.json +68 -0
- package/src/JSONParseStream.js +39 -0
- package/src/MockPackageInstaller.js +94 -0
- package/src/NodePackageManager.js +639 -0
- package/src/Npm.js +94 -0
- package/src/Pnpm.js +194 -0
- package/src/Yarn.js +157 -0
- package/src/getCurrentPackageManager.js +17 -0
- package/src/index.js +19 -0
- package/src/installPackage.js +284 -0
- package/src/promiseFromProcess.js +19 -0
- package/src/utils.js +93 -0
- package/src/validateModuleSpecifier.js +12 -0
- package/test/NodePackageManager.test.js +384 -0
- package/test/fixtures/empty/package.json +1 -0
- package/test/fixtures/has-a-not-yet-installed/package.json +5 -0
- package/test/fixtures/has-foo/node_modules/foo/index.js +1 -0
- package/test/fixtures/has-foo/node_modules/foo/package.json +3 -0
- package/test/fixtures/has-foo/node_modules/index.js +0 -0
- package/test/fixtures/has-foo/package.json +5 -0
- package/test/fixtures/has-foo/subpackage/package.json +1 -0
- package/test/fixtures/packages/a/index.js +1 -0
- package/test/fixtures/packages/a/package.json +3 -0
- package/test/fixtures/packages/foo-2.0/index.js +1 -0
- package/test/fixtures/packages/foo-2.0/package.json +4 -0
- package/test/fixtures/packages/peers/index.js +1 -0
- package/test/fixtures/packages/peers/package.json +7 -0
- package/test/fixtures/packages/peers-2.0/index.js +1 -0
- package/test/fixtures/packages/peers-2.0/package.json +7 -0
- package/test/getCurrentPackageManager.test.js +28 -0
- package/test/validateModuleSpecifiers.test.js +38 -0
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaspack/package-manager",
|
|
3
|
+
"version": "2.12.1-canary.3354+7bb54d46a",
|
|
4
|
+
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
|
+
},
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"source": "src/index.js",
|
|
15
|
+
"types": "index.d.ts",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">= 16.0.0"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build-ts": "mkdir -p lib && flow-to-ts src/index.js > lib/index.d.ts",
|
|
21
|
+
"check-ts": "tsc --noEmit index.d.ts",
|
|
22
|
+
"test": "mocha test"
|
|
23
|
+
},
|
|
24
|
+
"targets": {
|
|
25
|
+
"types": false,
|
|
26
|
+
"main": {
|
|
27
|
+
"includeNodeModules": {
|
|
28
|
+
"@atlaspack/core": false,
|
|
29
|
+
"@atlaspack/diagnostic": false,
|
|
30
|
+
"@atlaspack/fs": false,
|
|
31
|
+
"@atlaspack/logger": false,
|
|
32
|
+
"@atlaspack/node-resolver-core": false,
|
|
33
|
+
"@atlaspack/types": false,
|
|
34
|
+
"@atlaspack/utils": false,
|
|
35
|
+
"@atlaspack/workers": false,
|
|
36
|
+
"@swc/core": false,
|
|
37
|
+
"semver": false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3354+7bb54d46a",
|
|
43
|
+
"@atlaspack/fs": "2.12.1-canary.3354+7bb54d46a",
|
|
44
|
+
"@atlaspack/logger": "2.12.1-canary.3354+7bb54d46a",
|
|
45
|
+
"@atlaspack/node-resolver-core": "3.3.1-canary.3354+7bb54d46a",
|
|
46
|
+
"@atlaspack/types": "2.12.1-canary.3354+7bb54d46a",
|
|
47
|
+
"@atlaspack/utils": "2.12.1-canary.3354+7bb54d46a",
|
|
48
|
+
"@atlaspack/workers": "2.12.1-canary.3354+7bb54d46a",
|
|
49
|
+
"@swc/core": "^1.3.36",
|
|
50
|
+
"semver": "^7.5.2"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"command-exists": "^1.2.6",
|
|
54
|
+
"cross-spawn": "^6.0.4",
|
|
55
|
+
"nullthrows": "^1.1.1",
|
|
56
|
+
"split2": "^3.1.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@atlaspack/core": "2.12.1-canary.3354+7bb54d46a"
|
|
60
|
+
},
|
|
61
|
+
"browser": {
|
|
62
|
+
"./src/NodePackageManager.js": false,
|
|
63
|
+
"./src/Npm.js": false,
|
|
64
|
+
"./src/Pnpm.js": false,
|
|
65
|
+
"./src/Yarn.js": false
|
|
66
|
+
},
|
|
67
|
+
"gitHead": "7bb54d46a00c5ba9cdbc2ee426dcbe82c8d79a3e"
|
|
68
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import type {JSONObject} from '@atlaspack/types';
|
|
4
|
+
|
|
5
|
+
import logger from '@atlaspack/logger';
|
|
6
|
+
import {Transform} from 'stream';
|
|
7
|
+
|
|
8
|
+
// Transforms chunks of json strings to parsed objects.
|
|
9
|
+
// Pair with split2 to parse stream of newline-delimited text.
|
|
10
|
+
export default class JSONParseStream extends Transform {
|
|
11
|
+
constructor(options: mixed) {
|
|
12
|
+
super({...options, objectMode: true});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// $FlowFixMe We are in object mode, so we emit objects, not strings
|
|
16
|
+
_transform(
|
|
17
|
+
chunk: Buffer | string,
|
|
18
|
+
encoding: string,
|
|
19
|
+
callback: (err: ?Error, parsed: ?JSONObject) => mixed,
|
|
20
|
+
) {
|
|
21
|
+
try {
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = JSON.parse(chunk.toString());
|
|
25
|
+
} catch (e) {
|
|
26
|
+
// Be permissive and ignoreJSON parse errors in case there was
|
|
27
|
+
// a non-JSON line in the package manager's stdout.
|
|
28
|
+
logger.verbose({
|
|
29
|
+
message: 'Ignored invalid JSON message: ' + chunk.toString(),
|
|
30
|
+
origin: '@atlaspack/package-manager',
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
callback(null, parsed);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
callback(err);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ModuleRequest,
|
|
5
|
+
PackageInstaller,
|
|
6
|
+
InstallerOptions,
|
|
7
|
+
} from '@atlaspack/types';
|
|
8
|
+
import type {FileSystem} from '@atlaspack/fs';
|
|
9
|
+
import type {FilePath} from '@atlaspack/types';
|
|
10
|
+
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import {ncp} from '@atlaspack/fs';
|
|
13
|
+
import {registerSerializableClass} from '@atlaspack/core';
|
|
14
|
+
import pkg from '../package.json';
|
|
15
|
+
import {moduleRequestsFromDependencyMap} from './utils';
|
|
16
|
+
|
|
17
|
+
type Package = {|
|
|
18
|
+
fs: FileSystem,
|
|
19
|
+
packagePath: FilePath,
|
|
20
|
+
|};
|
|
21
|
+
|
|
22
|
+
// This PackageInstaller implementation simply copies files from one filesystem to another.
|
|
23
|
+
// Mostly useful for testing purposes.
|
|
24
|
+
export class MockPackageInstaller implements PackageInstaller {
|
|
25
|
+
packages: Map<string, Package> = new Map<string, Package>();
|
|
26
|
+
|
|
27
|
+
register(packageName: string, fs: FileSystem, packagePath: FilePath) {
|
|
28
|
+
this.packages.set(packageName, {fs, packagePath});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async install({
|
|
32
|
+
modules,
|
|
33
|
+
fs,
|
|
34
|
+
cwd,
|
|
35
|
+
packagePath,
|
|
36
|
+
saveDev = true,
|
|
37
|
+
}: InstallerOptions): Promise<void> {
|
|
38
|
+
if (packagePath == null) {
|
|
39
|
+
packagePath = path.join(cwd, 'package.json');
|
|
40
|
+
await fs.writeFile(packagePath, '{}');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let pkg = JSON.parse(await fs.readFile(packagePath, 'utf8'));
|
|
44
|
+
let key = saveDev ? 'devDependencies' : 'dependencies';
|
|
45
|
+
|
|
46
|
+
if (!pkg[key]) {
|
|
47
|
+
pkg[key] = {};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (let module of modules) {
|
|
51
|
+
pkg[key][module.name] =
|
|
52
|
+
'^' + (await this.installPackage(module, fs, packagePath));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await fs.writeFile(packagePath, JSON.stringify(pkg));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async installPackage(
|
|
59
|
+
moduleRequest: ModuleRequest,
|
|
60
|
+
fs: FileSystem,
|
|
61
|
+
packagePath: FilePath,
|
|
62
|
+
): Promise<any> {
|
|
63
|
+
let pkg = this.packages.get(moduleRequest.name);
|
|
64
|
+
if (!pkg) {
|
|
65
|
+
throw new Error('Unknown package ' + moduleRequest.name);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let dest = path.join(
|
|
69
|
+
path.dirname(packagePath),
|
|
70
|
+
'node_modules',
|
|
71
|
+
moduleRequest.name,
|
|
72
|
+
);
|
|
73
|
+
await ncp(pkg.fs, pkg.packagePath, fs, dest);
|
|
74
|
+
|
|
75
|
+
let packageJSON = JSON.parse(
|
|
76
|
+
await fs.readFile(path.join(dest, 'package.json'), 'utf8'),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (packageJSON.dependencies != null) {
|
|
80
|
+
for (let dep of moduleRequestsFromDependencyMap(
|
|
81
|
+
packageJSON.dependencies,
|
|
82
|
+
)) {
|
|
83
|
+
await this.installPackage(dep, fs, packagePath);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return packageJSON.version;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
registerSerializableClass(
|
|
92
|
+
`${pkg.version}:MockPackageInstaller`,
|
|
93
|
+
MockPackageInstaller,
|
|
94
|
+
);
|