Skip to content

Commit 978d09a

Browse files
Merge pull request #744 from bryceosterhaus/743
2 parents 57c1e12 + 6d4afb2 commit 978d09a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

projects/npm-tools/packages/npm-scripts/src/scripts/check/preflight.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {SpawnError} = require('../../utils/spawnSync');
88
const checkConfigFileNames = require('./preflight/checkConfigFileNames');
99
const checkPackageJSONFiles = require('./preflight/checkPackageJSONFiles');
1010
const checkTypeScriptTypeArtifacts = require('./preflight/checkTypeScriptTypeArtifacts');
11+
const checkYarnLock = require('./preflight/checkYarnLock');
1112

1213
/**
1314
* Runs the "preflight" checks (basically everything that is not already covered
@@ -18,6 +19,7 @@ async function preflight() {
1819
...checkConfigFileNames(),
1920
...checkPackageJSONFiles(),
2021
...(await checkTypeScriptTypeArtifacts()),
22+
...checkYarnLock(),
2123
];
2224

2325
if (errors.length) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
3+
* SPDX-License-Identifier: BSD-3-Clause
4+
*/
5+
6+
const {readFileSync} = require('fs');
7+
const path = require('path');
8+
9+
const findRoot = require('../../../utils/findRoot');
10+
11+
const LOCAL_REGISTRY_REGEX = /^\s+resolved\s".*(localhost|127.0.0.1).*$/gm;
12+
13+
function checkYarnLock() {
14+
const yarnLock = path.join(findRoot(), 'yarn.lock');
15+
16+
if (!yarnLock) {
17+
return [];
18+
}
19+
20+
const yarnLockContent = readFileSync(yarnLock, 'utf8');
21+
22+
return LOCAL_REGISTRY_REGEX.test(yarnLockContent)
23+
? ['Error: `yarn.lock` contains references to local npm registry.']
24+
: [];
25+
}
26+
27+
module.exports = checkYarnLock;

0 commit comments

Comments
 (0)