@vercel/build-utils 5.0.4 → 5.0.7
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/dist/fs/run-user-scripts.js +57 -54
- package/dist/index.js +58 -55
- package/package.json +2 -3
@@ -189,62 +189,44 @@ async function getNodeVersion(destPath, _nodeVersion, config = {}, meta = {}) {
|
|
189
189
|
exports.getNodeVersion = getNodeVersion;
|
190
190
|
async function scanParentDirs(destPath, readPackageJson = false) {
|
191
191
|
assert_1.default(path_1.default.isAbsolute(destPath));
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
192
|
+
const pkgJsonPath = await walkParentDirs({
|
193
|
+
base: '/',
|
194
|
+
start: destPath,
|
195
|
+
filename: 'package.json',
|
196
|
+
});
|
197
|
+
const packageJson = readPackageJson && pkgJsonPath
|
198
|
+
? JSON.parse(await fs_extra_1.default.readFile(pkgJsonPath, 'utf8'))
|
199
|
+
: undefined;
|
200
|
+
const [yarnLockPath, npmLockPath, pnpmLockPath] = await walkParentDirsMulti({
|
201
|
+
base: '/',
|
202
|
+
start: destPath,
|
203
|
+
filenames: ['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'],
|
204
|
+
});
|
196
205
|
let lockfileVersion;
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
fs_extra_1.default
|
211
|
-
.readJson(path_1.default.join(currentDestPath, 'package-lock.json'))
|
212
|
-
.catch(error => {
|
213
|
-
// If the file doesn't exist, fail gracefully otherwise error
|
214
|
-
if (error.code === 'ENOENT') {
|
215
|
-
return null;
|
216
|
-
}
|
217
|
-
throw error;
|
218
|
-
}),
|
219
|
-
fs_extra_1.default.pathExists(path_1.default.join(currentDestPath, 'yarn.lock')),
|
220
|
-
read_config_file_1.readConfigFile(path_1.default.join(currentDestPath, 'pnpm-lock.yaml')),
|
221
|
-
]);
|
222
|
-
// Priority order is Yarn > pnpm > npm
|
223
|
-
// - find highest priority lock file and use that
|
224
|
-
if (hasYarnLock) {
|
225
|
-
cliType = 'yarn';
|
226
|
-
}
|
227
|
-
else if (pnpmLockYaml) {
|
228
|
-
cliType = 'pnpm';
|
229
|
-
// just ensure that it is read as a number and not a string
|
230
|
-
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
231
|
-
}
|
232
|
-
else if (packageLockJson) {
|
233
|
-
cliType = 'npm';
|
234
|
-
lockfileVersion = packageLockJson.lockfileVersion;
|
235
|
-
}
|
236
|
-
// Only stop iterating if a lockfile was found, because it's possible
|
237
|
-
// that the lockfile is in a higher path than where the `package.json`
|
238
|
-
// file was found.
|
239
|
-
if (packageLockJson || hasYarnLock || pnpmLockYaml) {
|
240
|
-
break;
|
241
|
-
}
|
242
|
-
}
|
243
|
-
const newDestPath = path_1.default.dirname(currentDestPath);
|
244
|
-
if (currentDestPath === newDestPath)
|
245
|
-
break;
|
246
|
-
currentDestPath = newDestPath;
|
206
|
+
let cliType = 'yarn';
|
207
|
+
const [hasYarnLock, packageLockJson, pnpmLockYaml] = await Promise.all([
|
208
|
+
Boolean(yarnLockPath),
|
209
|
+
npmLockPath
|
210
|
+
? read_config_file_1.readConfigFile(npmLockPath)
|
211
|
+
: null,
|
212
|
+
pnpmLockPath
|
213
|
+
? read_config_file_1.readConfigFile(pnpmLockPath)
|
214
|
+
: null,
|
215
|
+
]);
|
216
|
+
// Priority order is Yarn > pnpm > npm
|
217
|
+
if (hasYarnLock) {
|
218
|
+
cliType = 'yarn';
|
247
219
|
}
|
220
|
+
else if (pnpmLockYaml) {
|
221
|
+
cliType = 'pnpm';
|
222
|
+
// just ensure that it is read as a number and not a string
|
223
|
+
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
224
|
+
}
|
225
|
+
else if (packageLockJson) {
|
226
|
+
cliType = 'npm';
|
227
|
+
lockfileVersion = packageLockJson.lockfileVersion;
|
228
|
+
}
|
229
|
+
const packageJsonPath = pkgJsonPath || undefined;
|
248
230
|
return { cliType, packageJson, lockfileVersion, packageJsonPath };
|
249
231
|
}
|
250
232
|
exports.scanParentDirs = scanParentDirs;
|
@@ -259,10 +241,31 @@ async function walkParentDirs({ base, start, filename, }) {
|
|
259
241
|
return fullPath;
|
260
242
|
}
|
261
243
|
parent = path_1.default.dirname(current);
|
244
|
+
if (parent === current) {
|
245
|
+
// Reached root directory of the filesystem
|
246
|
+
break;
|
247
|
+
}
|
262
248
|
}
|
263
249
|
return null;
|
264
250
|
}
|
265
251
|
exports.walkParentDirs = walkParentDirs;
|
252
|
+
async function walkParentDirsMulti({ base, start, filenames, }) {
|
253
|
+
let parent = '';
|
254
|
+
for (let current = start; base.length <= current.length; current = parent) {
|
255
|
+
const fullPaths = filenames.map(f => path_1.default.join(current, f));
|
256
|
+
const existResults = await Promise.all(fullPaths.map(f => fs_extra_1.default.pathExists(f)));
|
257
|
+
const foundOneOrMore = existResults.some(b => b);
|
258
|
+
if (foundOneOrMore) {
|
259
|
+
return fullPaths.map((f, i) => (existResults[i] ? f : undefined));
|
260
|
+
}
|
261
|
+
parent = path_1.default.dirname(current);
|
262
|
+
if (parent === current) {
|
263
|
+
// Reached root directory of the filesystem
|
264
|
+
break;
|
265
|
+
}
|
266
|
+
}
|
267
|
+
return [];
|
268
|
+
}
|
266
269
|
function isSet(v) {
|
267
270
|
return v?.constructor?.name === 'Set';
|
268
271
|
}
|
package/dist/index.js
CHANGED
@@ -30999,62 +30999,44 @@ async function getNodeVersion(destPath, _nodeVersion, config = {}, meta = {}) {
|
|
30999
30999
|
exports.getNodeVersion = getNodeVersion;
|
31000
31000
|
async function scanParentDirs(destPath, readPackageJson = false) {
|
31001
31001
|
assert_1.default(path_1.default.isAbsolute(destPath));
|
31002
|
-
|
31003
|
-
|
31004
|
-
|
31005
|
-
|
31002
|
+
const pkgJsonPath = await walkParentDirs({
|
31003
|
+
base: '/',
|
31004
|
+
start: destPath,
|
31005
|
+
filename: 'package.json',
|
31006
|
+
});
|
31007
|
+
const packageJson = readPackageJson && pkgJsonPath
|
31008
|
+
? JSON.parse(await fs_extra_1.default.readFile(pkgJsonPath, 'utf8'))
|
31009
|
+
: undefined;
|
31010
|
+
const [yarnLockPath, npmLockPath, pnpmLockPath] = await walkParentDirsMulti({
|
31011
|
+
base: '/',
|
31012
|
+
start: destPath,
|
31013
|
+
filenames: ['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'],
|
31014
|
+
});
|
31006
31015
|
let lockfileVersion;
|
31007
|
-
|
31008
|
-
|
31009
|
-
|
31010
|
-
|
31011
|
-
|
31012
|
-
|
31013
|
-
|
31014
|
-
|
31015
|
-
|
31016
|
-
|
31017
|
-
|
31018
|
-
|
31019
|
-
|
31020
|
-
|
31021
|
-
|
31022
|
-
|
31023
|
-
|
31024
|
-
|
31025
|
-
|
31026
|
-
|
31027
|
-
|
31028
|
-
|
31029
|
-
|
31030
|
-
|
31031
|
-
]);
|
31032
|
-
// Priority order is Yarn > pnpm > npm
|
31033
|
-
// - find highest priority lock file and use that
|
31034
|
-
if (hasYarnLock) {
|
31035
|
-
cliType = 'yarn';
|
31036
|
-
}
|
31037
|
-
else if (pnpmLockYaml) {
|
31038
|
-
cliType = 'pnpm';
|
31039
|
-
// just ensure that it is read as a number and not a string
|
31040
|
-
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
31041
|
-
}
|
31042
|
-
else if (packageLockJson) {
|
31043
|
-
cliType = 'npm';
|
31044
|
-
lockfileVersion = packageLockJson.lockfileVersion;
|
31045
|
-
}
|
31046
|
-
// Only stop iterating if a lockfile was found, because it's possible
|
31047
|
-
// that the lockfile is in a higher path than where the `package.json`
|
31048
|
-
// file was found.
|
31049
|
-
if (packageLockJson || hasYarnLock || pnpmLockYaml) {
|
31050
|
-
break;
|
31051
|
-
}
|
31052
|
-
}
|
31053
|
-
const newDestPath = path_1.default.dirname(currentDestPath);
|
31054
|
-
if (currentDestPath === newDestPath)
|
31055
|
-
break;
|
31056
|
-
currentDestPath = newDestPath;
|
31057
|
-
}
|
31016
|
+
let cliType = 'yarn';
|
31017
|
+
const [hasYarnLock, packageLockJson, pnpmLockYaml] = await Promise.all([
|
31018
|
+
Boolean(yarnLockPath),
|
31019
|
+
npmLockPath
|
31020
|
+
? read_config_file_1.readConfigFile(npmLockPath)
|
31021
|
+
: null,
|
31022
|
+
pnpmLockPath
|
31023
|
+
? read_config_file_1.readConfigFile(pnpmLockPath)
|
31024
|
+
: null,
|
31025
|
+
]);
|
31026
|
+
// Priority order is Yarn > pnpm > npm
|
31027
|
+
if (hasYarnLock) {
|
31028
|
+
cliType = 'yarn';
|
31029
|
+
}
|
31030
|
+
else if (pnpmLockYaml) {
|
31031
|
+
cliType = 'pnpm';
|
31032
|
+
// just ensure that it is read as a number and not a string
|
31033
|
+
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
31034
|
+
}
|
31035
|
+
else if (packageLockJson) {
|
31036
|
+
cliType = 'npm';
|
31037
|
+
lockfileVersion = packageLockJson.lockfileVersion;
|
31038
|
+
}
|
31039
|
+
const packageJsonPath = pkgJsonPath || undefined;
|
31058
31040
|
return { cliType, packageJson, lockfileVersion, packageJsonPath };
|
31059
31041
|
}
|
31060
31042
|
exports.scanParentDirs = scanParentDirs;
|
@@ -31069,10 +31051,31 @@ async function walkParentDirs({ base, start, filename, }) {
|
|
31069
31051
|
return fullPath;
|
31070
31052
|
}
|
31071
31053
|
parent = path_1.default.dirname(current);
|
31054
|
+
if (parent === current) {
|
31055
|
+
// Reached root directory of the filesystem
|
31056
|
+
break;
|
31057
|
+
}
|
31072
31058
|
}
|
31073
31059
|
return null;
|
31074
31060
|
}
|
31075
31061
|
exports.walkParentDirs = walkParentDirs;
|
31062
|
+
async function walkParentDirsMulti({ base, start, filenames, }) {
|
31063
|
+
let parent = '';
|
31064
|
+
for (let current = start; base.length <= current.length; current = parent) {
|
31065
|
+
const fullPaths = filenames.map(f => path_1.default.join(current, f));
|
31066
|
+
const existResults = await Promise.all(fullPaths.map(f => fs_extra_1.default.pathExists(f)));
|
31067
|
+
const foundOneOrMore = existResults.some(b => b);
|
31068
|
+
if (foundOneOrMore) {
|
31069
|
+
return fullPaths.map((f, i) => (existResults[i] ? f : undefined));
|
31070
|
+
}
|
31071
|
+
parent = path_1.default.dirname(current);
|
31072
|
+
if (parent === current) {
|
31073
|
+
// Reached root directory of the filesystem
|
31074
|
+
break;
|
31075
|
+
}
|
31076
|
+
}
|
31077
|
+
return [];
|
31078
|
+
}
|
31076
31079
|
function isSet(v) {
|
31077
31080
|
return v?.constructor?.name === 'Set';
|
31078
31081
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/build-utils",
|
3
|
-
"version": "5.0.
|
3
|
+
"version": "5.0.7",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.js",
|
@@ -35,7 +35,6 @@
|
|
35
35
|
"aggregate-error": "3.0.1",
|
36
36
|
"async-retry": "1.2.3",
|
37
37
|
"async-sema": "2.1.4",
|
38
|
-
"boxen": "4.2.0",
|
39
38
|
"cross-spawn": "6.0.5",
|
40
39
|
"end-of-stream": "1.4.1",
|
41
40
|
"fs-extra": "10.0.0",
|
@@ -49,5 +48,5 @@
|
|
49
48
|
"typescript": "4.3.4",
|
50
49
|
"yazl": "2.5.1"
|
51
50
|
},
|
52
|
-
"gitHead": "
|
51
|
+
"gitHead": "e8c7db59cf2746422f1f7e14cc6b7f901c243d50"
|
53
52
|
}
|