@atlaspack/package-manager 2.14.18-noselfbuild-3f2849b52.0 → 2.14.18-noselfbuild-342bd6c75.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/lib/JSONParseStream.js +53 -0
- package/lib/MockPackageInstaller.js +79 -0
- package/lib/NodePackageManager.js +582 -0
- package/lib/Npm.js +105 -0
- package/lib/Pnpm.js +171 -0
- package/lib/Yarn.js +146 -0
- package/lib/getCurrentPackageManager.js +18 -0
- package/lib/index.js +64 -5218
- package/lib/installPackage.js +222 -0
- package/lib/nodejsConditions.js +35 -0
- package/lib/promiseFromProcess.js +18 -0
- package/lib/utils.js +101 -0
- package/lib/validateModuleSpecifier.js +14 -0
- package/package.json +11 -13
- package/src/NodePackageManager.js +4 -8
- package/test/NodePackageManager.test.js +4 -0
- package/lib/index.js.map +0 -1
package/lib/Pnpm.js
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Pnpm = void 0;
|
7
|
+
function _path() {
|
8
|
+
const data = _interopRequireDefault(require("path"));
|
9
|
+
_path = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _fs() {
|
15
|
+
const data = _interopRequireDefault(require("fs"));
|
16
|
+
_fs = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _commandExists() {
|
22
|
+
const data = _interopRequireDefault(require("command-exists"));
|
23
|
+
_commandExists = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
function _crossSpawn() {
|
29
|
+
const data = _interopRequireDefault(require("cross-spawn"));
|
30
|
+
_crossSpawn = function () {
|
31
|
+
return data;
|
32
|
+
};
|
33
|
+
return data;
|
34
|
+
}
|
35
|
+
function _buildCache() {
|
36
|
+
const data = require("@atlaspack/build-cache");
|
37
|
+
_buildCache = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
function _logger() {
|
43
|
+
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
44
|
+
_logger = function () {
|
45
|
+
return data;
|
46
|
+
};
|
47
|
+
return data;
|
48
|
+
}
|
49
|
+
function _split() {
|
50
|
+
const data = _interopRequireDefault(require("split2"));
|
51
|
+
_split = function () {
|
52
|
+
return data;
|
53
|
+
};
|
54
|
+
return data;
|
55
|
+
}
|
56
|
+
var _JSONParseStream = _interopRequireDefault(require("./JSONParseStream"));
|
57
|
+
var _promiseFromProcess = _interopRequireDefault(require("./promiseFromProcess"));
|
58
|
+
var _utils = require("./utils");
|
59
|
+
var _package = _interopRequireDefault(require("../package.json"));
|
60
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
61
|
+
// $FlowFixMe
|
62
|
+
const PNPM_CMD = 'pnpm';
|
63
|
+
let hasPnpm;
|
64
|
+
let pnpmVersion;
|
65
|
+
class Pnpm {
|
66
|
+
static async exists() {
|
67
|
+
if (hasPnpm != null) {
|
68
|
+
return hasPnpm;
|
69
|
+
}
|
70
|
+
try {
|
71
|
+
hasPnpm = Boolean(await (0, _commandExists().default)('pnpm'));
|
72
|
+
} catch (err) {
|
73
|
+
hasPnpm = false;
|
74
|
+
}
|
75
|
+
return hasPnpm;
|
76
|
+
}
|
77
|
+
async install({
|
78
|
+
modules,
|
79
|
+
cwd,
|
80
|
+
saveDev = true
|
81
|
+
}) {
|
82
|
+
if (pnpmVersion == null) {
|
83
|
+
let version = await (0, _utils.exec)('pnpm --version');
|
84
|
+
pnpmVersion = parseInt(version.stdout, 10);
|
85
|
+
}
|
86
|
+
let args = ['add', '--reporter', 'ndjson'];
|
87
|
+
if (saveDev) {
|
88
|
+
args.push('-D');
|
89
|
+
}
|
90
|
+
if (pnpmVersion >= 7) {
|
91
|
+
if (_fs().default.existsSync(_path().default.join(cwd, 'pnpm-workspace.yaml'))) {
|
92
|
+
// installs in workspace root (regardless of cwd)
|
93
|
+
args.push('-w');
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
// ignores workspace root check
|
97
|
+
args.push('-W');
|
98
|
+
}
|
99
|
+
args = args.concat(modules.map(_utils.npmSpecifierFromModuleRequest));
|
100
|
+
let env = {};
|
101
|
+
for (let key in process.env) {
|
102
|
+
if (!key.startsWith('npm_') && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
103
|
+
env[key] = process.env[key];
|
104
|
+
}
|
105
|
+
}
|
106
|
+
let addedCount = 0,
|
107
|
+
removedCount = 0;
|
108
|
+
let installProcess = (0, _crossSpawn().default)(PNPM_CMD, args, {
|
109
|
+
cwd,
|
110
|
+
env
|
111
|
+
});
|
112
|
+
installProcess.stdout.pipe((0, _split().default)()).pipe(new _JSONParseStream.default()).on('error', e => {
|
113
|
+
_logger().default.warn({
|
114
|
+
origin: '@atlaspack/package-manager',
|
115
|
+
message: e.chunk,
|
116
|
+
stack: e.stack
|
117
|
+
});
|
118
|
+
}).on('data', json => {
|
119
|
+
if (json.level === 'error') {
|
120
|
+
_logger().default.error({
|
121
|
+
origin: '@atlaspack/package-manager',
|
122
|
+
message: json.err.message,
|
123
|
+
stack: json.err.stack
|
124
|
+
});
|
125
|
+
} else if (json.level === 'info' && typeof json.message === 'string') {
|
126
|
+
_logger().default.info({
|
127
|
+
origin: '@atlaspack/package-manager',
|
128
|
+
message: prefix(json.message)
|
129
|
+
});
|
130
|
+
} else if (json.name === 'pnpm:stats') {
|
131
|
+
addedCount += json.added ?? 0;
|
132
|
+
removedCount += json.removed ?? 0;
|
133
|
+
}
|
134
|
+
});
|
135
|
+
let stderr = [];
|
136
|
+
installProcess.stderr.on('data', str => {
|
137
|
+
stderr.push(str.toString());
|
138
|
+
}).on('error', e => {
|
139
|
+
_logger().default.warn({
|
140
|
+
origin: '@atlaspack/package-manager',
|
141
|
+
message: e.message
|
142
|
+
});
|
143
|
+
});
|
144
|
+
try {
|
145
|
+
await (0, _promiseFromProcess.default)(installProcess);
|
146
|
+
if (addedCount > 0 || removedCount > 0) {
|
147
|
+
_logger().default.log({
|
148
|
+
origin: '@atlaspack/package-manager',
|
149
|
+
message: `Added ${addedCount} ${removedCount > 0 ? `and removed ${removedCount} ` : ''}packages via pnpm`
|
150
|
+
});
|
151
|
+
}
|
152
|
+
|
153
|
+
// Since we succeeded, stderr might have useful information not included
|
154
|
+
// in the json written to stdout. It's also not necessary to log these as
|
155
|
+
// errors as they often aren't.
|
156
|
+
for (let message of stderr) {
|
157
|
+
_logger().default.log({
|
158
|
+
origin: '@atlaspack/package-manager',
|
159
|
+
message
|
160
|
+
});
|
161
|
+
}
|
162
|
+
} catch (e) {
|
163
|
+
throw new Error('pnpm failed to install modules');
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
exports.Pnpm = Pnpm;
|
168
|
+
function prefix(message) {
|
169
|
+
return 'pnpm: ' + message;
|
170
|
+
}
|
171
|
+
(0, _buildCache().registerSerializableClass)(`${_package.default.version}:Pnpm`, Pnpm);
|
package/lib/Yarn.js
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Yarn = void 0;
|
7
|
+
function _commandExists() {
|
8
|
+
const data = _interopRequireDefault(require("command-exists"));
|
9
|
+
_commandExists = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _crossSpawn() {
|
15
|
+
const data = _interopRequireDefault(require("cross-spawn"));
|
16
|
+
_crossSpawn = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _buildCache() {
|
22
|
+
const data = require("@atlaspack/build-cache");
|
23
|
+
_buildCache = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
function _logger() {
|
29
|
+
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
30
|
+
_logger = function () {
|
31
|
+
return data;
|
32
|
+
};
|
33
|
+
return data;
|
34
|
+
}
|
35
|
+
function _split() {
|
36
|
+
const data = _interopRequireDefault(require("split2"));
|
37
|
+
_split = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
var _JSONParseStream = _interopRequireDefault(require("./JSONParseStream"));
|
43
|
+
var _promiseFromProcess = _interopRequireDefault(require("./promiseFromProcess"));
|
44
|
+
var _utils = require("./utils");
|
45
|
+
var _package = _interopRequireDefault(require("../package.json"));
|
46
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
47
|
+
// $FlowFixMe
|
48
|
+
const YARN_CMD = 'yarn';
|
49
|
+
let hasYarn;
|
50
|
+
let yarnVersion;
|
51
|
+
class Yarn {
|
52
|
+
static async exists() {
|
53
|
+
if (hasYarn != null) {
|
54
|
+
return hasYarn;
|
55
|
+
}
|
56
|
+
try {
|
57
|
+
hasYarn = Boolean(await (0, _commandExists().default)('yarn'));
|
58
|
+
} catch (err) {
|
59
|
+
hasYarn = false;
|
60
|
+
}
|
61
|
+
return hasYarn;
|
62
|
+
}
|
63
|
+
async install({
|
64
|
+
modules,
|
65
|
+
cwd,
|
66
|
+
saveDev = true
|
67
|
+
}) {
|
68
|
+
if (yarnVersion == null) {
|
69
|
+
let version = await (0, _utils.exec)('yarn --version');
|
70
|
+
yarnVersion = parseInt(version.stdout, 10);
|
71
|
+
}
|
72
|
+
let args = ['add', '--json'].concat(modules.map(_utils.npmSpecifierFromModuleRequest));
|
73
|
+
if (saveDev) {
|
74
|
+
args.push('-D');
|
75
|
+
if (yarnVersion < 2) {
|
76
|
+
args.push('-W');
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
// When Parcel is run by Yarn (e.g. via package.json scripts), several environment variables are
|
81
|
+
// added. When parcel in turn calls Yarn again, these can cause Yarn to behave stragely, so we
|
82
|
+
// filter them out when installing packages.
|
83
|
+
let env = {};
|
84
|
+
for (let key in process.env) {
|
85
|
+
if (!key.startsWith('npm_') && key !== 'YARN_WRAP_OUTPUT' && key !== 'INIT_CWD' && key !== 'NODE_ENV') {
|
86
|
+
env[key] = process.env[key];
|
87
|
+
}
|
88
|
+
}
|
89
|
+
let installProcess = (0, _crossSpawn().default)(YARN_CMD, args, {
|
90
|
+
cwd,
|
91
|
+
env
|
92
|
+
});
|
93
|
+
installProcess.stdout
|
94
|
+
// Invoking yarn with --json provides streaming, newline-delimited JSON output.
|
95
|
+
.pipe((0, _split().default)()).pipe(new _JSONParseStream.default()).on('error', e => {
|
96
|
+
_logger().default.error(e, '@atlaspack/package-manager');
|
97
|
+
}).on('data', message => {
|
98
|
+
switch (message.type) {
|
99
|
+
case 'step':
|
100
|
+
_logger().default.progress(prefix(`[${message.data.current}/${message.data.total}] ${message.data.message}`));
|
101
|
+
return;
|
102
|
+
case 'success':
|
103
|
+
case 'info':
|
104
|
+
_logger().default.info({
|
105
|
+
origin: '@atlaspack/package-manager',
|
106
|
+
message: prefix(message.data)
|
107
|
+
});
|
108
|
+
return;
|
109
|
+
default:
|
110
|
+
// ignore
|
111
|
+
}
|
112
|
+
});
|
113
|
+
|
114
|
+
installProcess.stderr.pipe((0, _split().default)()).pipe(new _JSONParseStream.default()).on('error', e => {
|
115
|
+
_logger().default.error(e, '@atlaspack/package-manager');
|
116
|
+
}).on('data', message => {
|
117
|
+
switch (message.type) {
|
118
|
+
case 'warning':
|
119
|
+
_logger().default.warn({
|
120
|
+
origin: '@atlaspack/package-manager',
|
121
|
+
message: prefix(message.data)
|
122
|
+
});
|
123
|
+
return;
|
124
|
+
case 'error':
|
125
|
+
_logger().default.error({
|
126
|
+
origin: '@atlaspack/package-manager',
|
127
|
+
message: prefix(message.data)
|
128
|
+
});
|
129
|
+
return;
|
130
|
+
default:
|
131
|
+
// ignore
|
132
|
+
}
|
133
|
+
});
|
134
|
+
|
135
|
+
try {
|
136
|
+
return await (0, _promiseFromProcess.default)(installProcess);
|
137
|
+
} catch (e) {
|
138
|
+
throw new Error('Yarn failed to install modules:' + e.message);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
exports.Yarn = Yarn;
|
143
|
+
function prefix(message) {
|
144
|
+
return 'yarn: ' + message;
|
145
|
+
}
|
146
|
+
(0, _buildCache().registerSerializableClass)(`${_package.default.version}:Yarn`, Yarn);
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = getCurrentPackageManager;
|
7
|
+
function getCurrentPackageManager(userAgent = process.env.npm_config_user_agent) {
|
8
|
+
if (!userAgent) {
|
9
|
+
return undefined;
|
10
|
+
}
|
11
|
+
const pmSpec = userAgent.split(' ')[0];
|
12
|
+
const separatorPos = pmSpec.lastIndexOf('/');
|
13
|
+
const name = pmSpec.substring(0, separatorPos);
|
14
|
+
return {
|
15
|
+
name: name,
|
16
|
+
version: pmSpec.substring(separatorPos + 1)
|
17
|
+
};
|
18
|
+
}
|