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

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 +597 -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 +222 -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} +83 -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} +4 -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
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._addToInstallQueue = _addToInstallQueue;
7
+ exports.installPackage = installPackage;
8
+ function _assert() {
9
+ const data = _interopRequireDefault(require("assert"));
10
+ _assert = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _path() {
16
+ const data = _interopRequireDefault(require("path"));
17
+ _path = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
22
+ function _nullthrows() {
23
+ const data = _interopRequireDefault(require("nullthrows"));
24
+ _nullthrows = function () {
25
+ return data;
26
+ };
27
+ return data;
28
+ }
29
+ function _semver() {
30
+ const data = _interopRequireDefault(require("semver"));
31
+ _semver = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
36
+ function _diagnostic() {
37
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
38
+ _diagnostic = function () {
39
+ return data;
40
+ };
41
+ return data;
42
+ }
43
+ function _logger() {
44
+ const data = _interopRequireDefault(require("@atlaspack/logger"));
45
+ _logger = function () {
46
+ return data;
47
+ };
48
+ return data;
49
+ }
50
+ function _utils() {
51
+ const data = require("@atlaspack/utils");
52
+ _utils = function () {
53
+ return data;
54
+ };
55
+ return data;
56
+ }
57
+ function _workers() {
58
+ const data = _interopRequireDefault(require("@atlaspack/workers"));
59
+ _workers = function () {
60
+ return data;
61
+ };
62
+ return data;
63
+ }
64
+ var _Npm = require("./Npm");
65
+ var _Yarn = require("./Yarn");
66
+ var _Pnpm = require("./Pnpm");
67
+ var _utils2 = require("./utils");
68
+ var _getCurrentPackageManager = _interopRequireDefault(require("./getCurrentPackageManager"));
69
+ var _validateModuleSpecifier = _interopRequireDefault(require("./validateModuleSpecifier"));
70
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
71
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
72
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
+ async function install(fs, packageManager, modules, from, projectRoot, options = {}) {
74
+ let {
75
+ installPeers = true,
76
+ saveDev = true,
77
+ packageInstaller
78
+ } = options;
79
+ let moduleNames = modules.map(m => m.name).join(', ');
80
+ _logger().default.progress(`Installing ${moduleNames}...`);
81
+ let fromPkgPath = await (0, _utils().resolveConfig)(fs, from, ['package.json'], projectRoot);
82
+ let cwd = fromPkgPath ? _path().default.dirname(fromPkgPath) : fs.cwd();
83
+ if (!packageInstaller) {
84
+ packageInstaller = await determinePackageInstaller(fs, from, projectRoot);
85
+ }
86
+ try {
87
+ await packageInstaller.install({
88
+ modules,
89
+ saveDev,
90
+ cwd,
91
+ packagePath: fromPkgPath,
92
+ fs
93
+ });
94
+ } catch (err) {
95
+ throw new Error(`Failed to install ${moduleNames}: ${err.message}`);
96
+ }
97
+ if (installPeers) {
98
+ await Promise.all(modules.map(m => installPeerDependencies(fs, packageManager, m, from, projectRoot, options)));
99
+ }
100
+ }
101
+ async function installPeerDependencies(fs, packageManager, module, from, projectRoot, options) {
102
+ const {
103
+ resolved
104
+ } = await packageManager.resolve(module.name, from);
105
+ const modulePkg = (0, _nullthrows().default)(await (0, _utils().loadConfig)(fs, resolved, ['package.json'], projectRoot)).config;
106
+ const peers = modulePkg.peerDependencies || {};
107
+ let modules = [];
108
+ for (let [name, range] of Object.entries(peers)) {
109
+ (0, _assert().default)(typeof range === 'string');
110
+ let conflicts = await (0, _utils2.getConflictingLocalDependencies)(fs, name, from, projectRoot);
111
+ if (conflicts) {
112
+ let {
113
+ pkg
114
+ } = await packageManager.resolve(name, from);
115
+ (0, _assert().default)(pkg);
116
+ if (!_semver().default.satisfies(pkg.version, range)) {
117
+ throw new (_diagnostic().default)({
118
+ diagnostic: {
119
+ message: (0, _diagnostic().md)`Could not install the peer dependency "${name}" for "${module.name}", installed version ${pkg.version} is incompatible with ${range}`,
120
+ origin: '@atlaspack/package-manager',
121
+ codeFrames: [{
122
+ filePath: conflicts.filePath,
123
+ language: 'json',
124
+ code: conflicts.json,
125
+ codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(conflicts.json, conflicts.fields.map(field => ({
126
+ key: `/${field}/${(0, _diagnostic().encodeJSONKeyComponent)(name)}`,
127
+ type: 'key',
128
+ message: 'Found this conflicting local requirement.'
129
+ })))
130
+ }]
131
+ }
132
+ });
133
+ }
134
+ continue;
135
+ }
136
+ modules.push({
137
+ name,
138
+ range
139
+ });
140
+ }
141
+ if (modules.length) {
142
+ await install(fs, packageManager, modules, from, projectRoot, Object.assign({}, options, {
143
+ installPeers: false
144
+ }));
145
+ }
146
+ }
147
+ async function determinePackageInstaller(fs, filepath, projectRoot) {
148
+ var _getCurrentPackageMan;
149
+ let configFile = await (0, _utils().resolveConfig)(fs, filepath, ['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock'], projectRoot);
150
+ let configName = configFile && _path().default.basename(configFile);
151
+
152
+ // Always use the package manager that seems to be used in the project,
153
+ // falling back to a different one wouldn't update the existing lockfile.
154
+ if (configName === 'package-lock.json') {
155
+ return new _Npm.Npm();
156
+ } else if (configName === 'pnpm-lock.yaml') {
157
+ return new _Pnpm.Pnpm();
158
+ } else if (configName === 'yarn.lock') {
159
+ return new _Yarn.Yarn();
160
+ }
161
+ let currentPackageManager = (_getCurrentPackageMan = (0, _getCurrentPackageManager.default)()) === null || _getCurrentPackageMan === void 0 ? void 0 : _getCurrentPackageMan.name;
162
+ if (currentPackageManager === 'npm') {
163
+ return new _Npm.Npm();
164
+ } else if (currentPackageManager === 'yarn') {
165
+ return new _Yarn.Yarn();
166
+ } else if (currentPackageManager === 'pnpm') {
167
+ return new _Pnpm.Pnpm();
168
+ }
169
+ if (await _Yarn.Yarn.exists()) {
170
+ return new _Yarn.Yarn();
171
+ } else if (await _Pnpm.Pnpm.exists()) {
172
+ return new _Pnpm.Pnpm();
173
+ } else {
174
+ return new _Npm.Npm();
175
+ }
176
+ }
177
+ let queue = new (_utils().PromiseQueue)({
178
+ maxConcurrent: 1
179
+ });
180
+ let modulesInstalling = new Set();
181
+
182
+ // Exported so that it may be invoked from the worker api below.
183
+ // Do not call this directly! This can result in concurrent package installations
184
+ // across multiple instances of the package manager.
185
+ function _addToInstallQueue(fs, packageManager, modules, filePath, projectRoot, options) {
186
+ modules = modules.map(request => ({
187
+ name: (0, _validateModuleSpecifier.default)(request.name),
188
+ range: request.range
189
+ }));
190
+
191
+ // Wrap PromiseQueue and track modules that are currently installing.
192
+ // If a request comes in for a module that is currently installing, don't bother
193
+ // enqueuing it.
194
+ let modulesToInstall = modules.filter(m => !modulesInstalling.has(getModuleRequestKey(m)));
195
+ if (modulesToInstall.length) {
196
+ for (let m of modulesToInstall) {
197
+ modulesInstalling.add(getModuleRequestKey(m));
198
+ }
199
+ queue.add(() => install(fs, packageManager, modulesToInstall, filePath, projectRoot, options).then(() => {
200
+ for (let m of modulesToInstall) {
201
+ modulesInstalling.delete(getModuleRequestKey(m));
202
+ }
203
+ }));
204
+ }
205
+ return queue.run();
206
+ }
207
+ function installPackage(fs, packageManager, modules, filePath, projectRoot, options) {
208
+ if (_workers().default.isWorker()) {
209
+ let workerApi = _workers().default.getWorkerApi();
210
+ // TODO this should really be `__filename` but without the rewriting.
211
+ let bundlePath = process.env.ATLASPACK_BUILD_ENV === 'production' && !process.env.ATLASPACK_SELF_BUILD ? _path().default.join(__dirname, '..', 'lib/index.js') : __filename;
212
+ return workerApi.callMaster({
213
+ location: bundlePath,
214
+ args: [fs, packageManager, modules, filePath, projectRoot, options],
215
+ method: '_addToInstallQueue'
216
+ });
217
+ }
218
+ return _addToInstallQueue(fs, packageManager, modules, filePath, projectRoot, options);
219
+ }
220
+ function getModuleRequestKey(moduleRequest) {
221
+ return [moduleRequest.name, moduleRequest.range].join('@');
222
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.defaultNodejsConditions = void 0;
7
+ exports.getConditionsFromEnv = getConditionsFromEnv;
8
+ function _process() {
9
+ const data = _interopRequireDefault(require("process"));
10
+ _process = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ // https://nodejs.org/api/packages.html#conditional-exports
17
+ // TODO We don't support { "type": "module" }
18
+ // @ts-expect-error TS4104
19
+ const defaultNodejsConditions = exports.defaultNodejsConditions = Object.freeze(['node-addons', 'node',
20
+ // 'import',
21
+ 'require', 'module-sync', 'default']);
22
+ let envConditions = undefined;
23
+
24
+ /** @description Gets the export conditions from NODE_OPTIONS and node arguments */
25
+ function getConditionsFromEnv() {
26
+ if (!envConditions) {
27
+ const conditions = [];
28
+ for (const arg of [..._process().default.execArgv, ...(_process().default.env.NODE_OPTIONS || '').split(' ')]) {
29
+ if (arg.startsWith('--conditions=')) {
30
+ // @ts-expect-error TS2345
31
+ conditions.push(arg.substring(13));
32
+ }
33
+ }
34
+
35
+ // @ts-expect-error TS4104
36
+ envConditions = Object.freeze([...conditions, ...defaultNodejsConditions]);
37
+ }
38
+
39
+ // @ts-expect-error TS2322
40
+ return envConditions;
41
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = promiseFromProcess;
7
+ function promiseFromProcess(childProcess) {
8
+ return new Promise((resolve, reject) => {
9
+ childProcess.on('error', reject);
10
+ childProcess.on('close', code => {
11
+ if (code !== 0) {
12
+ reject(new Error('Child process failed'));
13
+ return;
14
+ }
15
+
16
+ // @ts-expect-error TS2794
17
+ resolve();
18
+ });
19
+ });
20
+ }
@@ -0,0 +1,6 @@
1
+ import type { JSONObject } from '@atlaspack/types';
2
+ import { Transform } from 'stream';
3
+ export default class JSONParseStream extends Transform {
4
+ constructor(options: unknown);
5
+ _transform(chunk: Buffer | string, encoding: string, callback: (err?: Error | null | undefined, parsed?: JSONObject | null | undefined) => unknown): void;
6
+ }
@@ -0,0 +1,14 @@
1
+ import type { ModuleRequest, PackageInstaller, InstallerOptions } from '@atlaspack/types';
2
+ import type { FileSystem } from '@atlaspack/fs';
3
+ import type { FilePath } from '@atlaspack/types';
4
+ type Package = {
5
+ fs: FileSystem;
6
+ packagePath: FilePath;
7
+ };
8
+ export declare class MockPackageInstaller implements PackageInstaller {
9
+ packages: Map<string, Package>;
10
+ register(packageName: string, fs: FileSystem, packagePath: FilePath): void;
11
+ install({ modules, fs, cwd, packagePath, saveDev, }: InstallerOptions): Promise<void>;
12
+ installPackage(moduleRequest: ModuleRequest, fs: FileSystem, packagePath: FilePath): Promise<any>;
13
+ }
14
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { FilePath, DependencySpecifier, SemverRange } from '@atlaspack/types';
2
+ import type { FileSystem } from '@atlaspack/fs';
3
+ import type { ModuleRequest, PackageManager, PackageInstaller, InstallOptions, Invalidations, PackageManagerResolveResult } from '@atlaspack/types';
4
+ export declare class NodePackageManager implements PackageManager {
5
+ fs: FileSystem;
6
+ projectRoot: FilePath;
7
+ installer: PackageInstaller | null | undefined;
8
+ resolver: ResolverBase;
9
+ currentExtensions: Array<string>;
10
+ constructor(fs: FileSystem, projectRoot: FilePath, installer?: PackageInstaller | null);
11
+ _createResolver(): ResolverBase;
12
+ static deserialize(opts: any): NodePackageManager;
13
+ serialize(): {
14
+ $$raw: boolean;
15
+ fs: FileSystem;
16
+ projectRoot: FilePath;
17
+ installer: PackageInstaller | null | undefined;
18
+ };
19
+ require(name: DependencySpecifier, from: FilePath, opts?: {
20
+ range?: SemverRange | null | undefined;
21
+ shouldAutoInstall?: boolean;
22
+ saveDev?: boolean;
23
+ } | null): Promise<any>;
24
+ requireSync(name: DependencySpecifier, from: FilePath): any;
25
+ load(filePath: FilePath, from: FilePath): any;
26
+ resolve(id: DependencySpecifier, from: FilePath, options?: {
27
+ range?: SemverRange | null | undefined;
28
+ shouldAutoInstall?: boolean;
29
+ saveDev?: boolean;
30
+ } | null): Promise<PackageManagerResolveResult>;
31
+ resolveSync(name: DependencySpecifier, from: FilePath): PackageManagerResolveResult;
32
+ install(modules: Array<ModuleRequest>, from: FilePath, opts?: InstallOptions): Promise<void>;
33
+ getInvalidations(name: DependencySpecifier, from: FilePath): Invalidations;
34
+ invalidate(name: DependencySpecifier, from: FilePath): void;
35
+ resolveInternal(name: string, from: string): PackageManagerResolveResult;
36
+ }
@@ -0,0 +1,4 @@
1
+ import type { PackageInstaller, InstallerOptions } from '@atlaspack/types';
2
+ export declare class Npm implements PackageInstaller {
3
+ install({ modules, cwd, fs, packagePath, saveDev, }: InstallerOptions): Promise<void>;
4
+ }
@@ -0,0 +1,5 @@
1
+ import type { PackageInstaller, InstallerOptions } from '@atlaspack/types';
2
+ export declare class Pnpm implements PackageInstaller {
3
+ static exists(): Promise<boolean>;
4
+ install({ modules, cwd, saveDev, }: InstallerOptions): Promise<void>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { PackageInstaller, InstallerOptions } from '@atlaspack/types';
2
+ export declare class Yarn implements PackageInstaller {
3
+ static exists(): Promise<boolean>;
4
+ install({ modules, cwd, saveDev, }: InstallerOptions): Promise<void>;
5
+ }
@@ -0,0 +1,4 @@
1
+ export default function getCurrentPackageManager(userAgent?: string | null): {
2
+ name: string;
3
+ version: string;
4
+ } | null | undefined;
@@ -0,0 +1,10 @@
1
+ import type { PackageManagerResolveResult } from '@atlaspack/types';
2
+ export type { PackageManager, Invalidations, PackageInstaller, ModuleRequest, } from '@atlaspack/types';
3
+ export * from './Npm';
4
+ export * from './Pnpm';
5
+ export * from './Yarn';
6
+ export * from './MockPackageInstaller';
7
+ export * from './NodePackageManager';
8
+ export { _addToInstallQueue } from './installPackage';
9
+ export type { PackageManagerResolveResult };
10
+ export type { PackageManagerResolveResult as ResolveResult };
@@ -0,0 +1,5 @@
1
+ import type { FilePath } from '@atlaspack/types';
2
+ import type { ModuleRequest, PackageManager, InstallOptions } from '@atlaspack/types';
3
+ import type { FileSystem } from '@atlaspack/fs';
4
+ export declare function _addToInstallQueue(fs: FileSystem, packageManager: PackageManager, modules: Array<ModuleRequest>, filePath: FilePath, projectRoot: FilePath, options?: InstallOptions): Promise<unknown>;
5
+ export declare function installPackage(fs: FileSystem, packageManager: PackageManager, modules: Array<ModuleRequest>, filePath: FilePath, projectRoot: FilePath, options?: InstallOptions): Promise<unknown>;
@@ -0,0 +1,3 @@
1
+ export declare const defaultNodejsConditions: Array<string>;
2
+ /** @description Gets the export conditions from NODE_OPTIONS and node arguments */
3
+ export declare function getConditionsFromEnv(): Array<string>;
@@ -0,0 +1,2 @@
1
+ import type { ChildProcess } from 'child_process';
2
+ export default function promiseFromProcess(childProcess: ChildProcess): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import type { FilePath, ModuleRequest } from '@atlaspack/types';
2
+ import type { FileSystem } from '@atlaspack/fs';
3
+ export declare const exec: (command: string, options?: child_process.execOpts) => Promise<{
4
+ stdout: string | Buffer;
5
+ stderr: string | Buffer;
6
+ }>;
7
+ export declare function npmSpecifierFromModuleRequest(moduleRequest: ModuleRequest): string;
8
+ export declare function moduleRequestsFromDependencyMap(dependencyMap: {
9
+ [key: string]: string;
10
+ }): Array<ModuleRequest>;
11
+ export declare function getConflictingLocalDependencies(fs: FileSystem, name: string, local: FilePath, projectRoot: FilePath): Promise<{
12
+ json: string;
13
+ filePath: FilePath;
14
+ fields: Array<string>;
15
+ } | null | undefined>;
@@ -0,0 +1 @@
1
+ export default function validateModuleSpecifier(moduleName: string): string;
package/lib/utils.js ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.exec = void 0;
7
+ exports.getConflictingLocalDependencies = getConflictingLocalDependencies;
8
+ exports.moduleRequestsFromDependencyMap = moduleRequestsFromDependencyMap;
9
+ exports.npmSpecifierFromModuleRequest = npmSpecifierFromModuleRequest;
10
+ function _assert() {
11
+ const data = _interopRequireDefault(require("assert"));
12
+ _assert = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _diagnostic() {
18
+ const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
19
+ _diagnostic = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _utils() {
25
+ const data = require("@atlaspack/utils");
26
+ _utils = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _child_process() {
32
+ const data = require("child_process");
33
+ _child_process = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _util() {
39
+ const data = require("util");
40
+ _util = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
+ const exec = exports.exec = _child_process().exec ? (0, _util().promisify)(_child_process().exec) :
47
+ // _exec is undefined in browser builds
48
+ _child_process().exec;
49
+ function npmSpecifierFromModuleRequest(moduleRequest) {
50
+ return moduleRequest.range != null ? [moduleRequest.name, moduleRequest.range].join('@') : moduleRequest.name;
51
+ }
52
+ function moduleRequestsFromDependencyMap(dependencyMap) {
53
+ return Object.entries(dependencyMap).map(([name, range]) => {
54
+ (0, _assert().default)(typeof range === 'string');
55
+ return {
56
+ name,
57
+ range
58
+ };
59
+ });
60
+ }
61
+ async function getConflictingLocalDependencies(fs, name, local, projectRoot) {
62
+ let pkgPath = await (0, _utils().resolveConfig)(fs, local, ['package.json'], projectRoot);
63
+ if (pkgPath == null) {
64
+ return;
65
+ }
66
+ let pkgStr = await fs.readFile(pkgPath, 'utf8');
67
+ let pkg;
68
+ try {
69
+ pkg = JSON.parse(pkgStr);
70
+ } catch (e) {
71
+ // TODO: codeframe
72
+ throw new (_diagnostic().default)({
73
+ diagnostic: {
74
+ message: 'Failed to parse package.json',
75
+ origin: '@atlaspack/package-manager'
76
+ }
77
+ });
78
+ }
79
+ if (typeof pkg !== 'object' || pkg == null) {
80
+ // TODO: codeframe
81
+ throw new (_diagnostic().default)({
82
+ diagnostic: {
83
+ message: 'Expected package.json contents to be an object.',
84
+ origin: '@atlaspack/package-manager'
85
+ }
86
+ });
87
+ }
88
+ let fields = [];
89
+ for (let field of ['dependencies', 'devDependencies', 'peerDependencies']) {
90
+ if (typeof pkg[field] === 'object' && pkg[field] != null && pkg[field][name] != null) {
91
+ fields.push(field);
92
+ }
93
+ }
94
+ if (fields.length > 0) {
95
+ return {
96
+ filePath: pkgPath,
97
+ json: pkgStr,
98
+ fields
99
+ };
100
+ }
101
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = validateModuleSpecifier;
7
+ const MODULE_REGEX = /^((@[^/\s]+\/){0,1}([^/\s.~]+[^/\s]*)){1}(@[^/\s]+){0,1}/;
8
+ function validateModuleSpecifier(moduleName) {
9
+ let matches = MODULE_REGEX.exec(moduleName);
10
+ if (matches) {
11
+ return matches[0];
12
+ }
13
+ return '';
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/package-manager",
3
- "version": "2.14.5-canary.16+4b2b575b9",
3
+ "version": "2.14.5-canary.161+ee040bb64",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -10,16 +10,16 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "lib/index.js",
14
- "source": "src/index.js",
15
- "types": "index.d.ts",
13
+ "main": "./lib/index.js",
14
+ "source": "./src/index.ts",
15
+ "types": "./lib/types/index.d.ts",
16
16
  "engines": {
17
17
  "node": ">= 16.0.0"
18
18
  },
19
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"
20
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src",
21
+ "test": "mocha test",
22
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
23
23
  },
24
24
  "targets": {
25
25
  "types": false,
@@ -39,21 +39,19 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@atlaspack/build-cache": "2.13.3-canary.84+4b2b575b9",
43
- "@atlaspack/diagnostic": "2.14.1-canary.84+4b2b575b9",
44
- "@atlaspack/fs": "2.14.5-canary.16+4b2b575b9",
45
- "@atlaspack/logger": "2.14.5-canary.16+4b2b575b9",
46
- "@atlaspack/node-resolver-core": "3.5.5-canary.16+4b2b575b9",
47
- "@atlaspack/types": "2.14.5-canary.16+4b2b575b9",
48
- "@atlaspack/utils": "2.14.5-canary.16+4b2b575b9",
49
- "@atlaspack/workers": "2.14.5-canary.16+4b2b575b9",
42
+ "@atlaspack/build-cache": "2.13.3-canary.229+ee040bb64",
43
+ "@atlaspack/diagnostic": "2.14.1-canary.229+ee040bb64",
44
+ "@atlaspack/fs": "2.14.5-canary.161+ee040bb64",
45
+ "@atlaspack/logger": "2.14.5-canary.161+ee040bb64",
46
+ "@atlaspack/node-resolver-core": "3.5.5-canary.161+ee040bb64",
47
+ "@atlaspack/types": "2.14.5-canary.161+ee040bb64",
48
+ "@atlaspack/utils": "2.14.5-canary.161+ee040bb64",
49
+ "@atlaspack/workers": "2.14.5-canary.161+ee040bb64",
50
50
  "@swc/core": "^1.10.0",
51
- "semver": "^7.5.2"
52
- },
53
- "devDependencies": {
54
51
  "command-exists": "^1.2.6",
55
52
  "cross-spawn": "^6.0.4",
56
53
  "nullthrows": "^1.1.1",
54
+ "semver": "^7.5.2",
57
55
  "split2": "^3.1.1"
58
56
  },
59
57
  "browser": {
@@ -63,5 +61,5 @@
63
61
  "./src/Yarn.js": false
64
62
  },
65
63
  "type": "commonjs",
66
- "gitHead": "4b2b575b98951f2dcf0c45ed8e94359b23b43815"
64
+ "gitHead": "ee040bb6428f29b57d892ddd8107e29077d08ffd"
67
65
  }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {JSONObject} from '@atlaspack/types';
4
2
 
5
3
  import logger from '@atlaspack/logger';
@@ -8,21 +6,24 @@ import {Transform} from 'stream';
8
6
  // Transforms chunks of json strings to parsed objects.
9
7
  // Pair with split2 to parse stream of newline-delimited text.
10
8
  export default class JSONParseStream extends Transform {
11
- constructor(options: mixed) {
9
+ constructor(options: unknown) {
10
+ // @ts-expect-error TS2698
12
11
  super({...options, objectMode: true});
13
12
  }
14
13
 
15
- // $FlowFixMe We are in object mode, so we emit objects, not strings
16
14
  _transform(
17
15
  chunk: Buffer | string,
18
16
  encoding: string,
19
- callback: (err: ?Error, parsed: ?JSONObject) => mixed,
17
+ callback: (
18
+ err?: Error | null | undefined,
19
+ parsed?: JSONObject | null | undefined,
20
+ ) => unknown,
20
21
  ) {
21
22
  try {
22
23
  let parsed;
23
24
  try {
24
25
  parsed = JSON.parse(chunk.toString());
25
- } catch (e) {
26
+ } catch (e: any) {
26
27
  // Be permissive and ignoreJSON parse errors in case there was
27
28
  // a non-JSON line in the package manager's stdout.
28
29
  logger.verbose({
@@ -32,7 +33,7 @@ export default class JSONParseStream extends Transform {
32
33
  return;
33
34
  }
34
35
  callback(null, parsed);
35
- } catch (err) {
36
+ } catch (err: any) {
36
37
  callback(err);
37
38
  }
38
39
  }
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {
4
2
  ModuleRequest,
5
3
  PackageInstaller,
@@ -14,10 +12,10 @@ import {ncp} from '@atlaspack/fs';
14
12
  import pkg from '../package.json';
15
13
  import {moduleRequestsFromDependencyMap} from './utils';
16
14
 
17
- type Package = {|
18
- fs: FileSystem,
19
- packagePath: FilePath,
20
- |};
15
+ type Package = {
16
+ fs: FileSystem;
17
+ packagePath: FilePath;
18
+ };
21
19
 
22
20
  // This PackageInstaller implementation simply copies files from one filesystem to another.
23
21
  // Mostly useful for testing purposes.