Skip to content

Commit ed9ae06

Browse files
authored
Add a PR-time check for non-standard NPM registries (#3134)
* Add a script for checking non-standard NPM registries * github/workflows/pr-verify: run repo:check after install
1 parent 34c5219 commit ed9ae06

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

.github/workflows/pr-verify.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- run: wget http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz
2525
- run: mkdir server && tar -xvzf jdt-language-server-latest.tar.gz -C ./server && rm jdt-language-server-latest.tar.gz
2626
- run: npm install
27+
- run: npm run repo:check
2728
- run: npm run compile
2829
- run: npm run vscode:prepublish
2930
- run: vsce package

gulpfile.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const originalTestFolder = path.join(__dirname, 'test', 'resources', 'projects',
1414
const tempTestFolder = path.join(__dirname, 'test-temp');
1515
const testSettings = path.join(tempTestFolder, '.vscode', 'settings.json');
1616
const JDT_LS_SNAPSHOT_URL = "http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz"
17+
const NON_NPM_REPOSITORY_RE = new RegExp(
18+
String.raw`"resolved":\s*"https://.+/registry.npmjs.org/`,
19+
"g"
20+
);
1721
//...
1822

1923
gulp.task('clean_jre', function (done) {
@@ -216,6 +220,32 @@ gulp.task('prepare_pre_release', function (done) {
216220
done();
217221
});
218222

223+
gulp.task('repo_check', function (done) {
224+
const data = fse.readFileSync("./package-lock.json", { encoding: "utf-8" });
225+
226+
if (NON_NPM_REPOSITORY_RE.test(data)) {
227+
done(new Error("Found references to the internal registry in the file package-lock.json. Please fix it with 'npm run repo:fix'"));
228+
} else {
229+
done();
230+
}
231+
});
232+
233+
gulp.task('repo_fix', function (done) {
234+
const data = fse.readFileSync("./package-lock.json", { encoding: "utf-8" });
235+
const newData = data.replace(NON_NPM_REPOSITORY_RE, `"resolved": "https://registry.npmjs.org/`);
236+
237+
if (data !== newData) {
238+
fse.writeFileSync("./package-lock.json", newData, {
239+
encoding: "utf-8",
240+
});
241+
console.log(`successfully fixed package-lock.json`);
242+
} else {
243+
console.log("nothing to fix");
244+
}
245+
246+
done();
247+
});
248+
219249
function isWin() {
220250
return /^win/.test(process.platform);
221251
}
@@ -252,4 +282,4 @@ function build_server_fn(){
252282
gulp.src(server_dir + '/org.eclipse.jdt.ls.product/distro/*.tar.gz')
253283
.pipe(decompress())
254284
.pipe(gulp.dest('./server'));
255-
}
285+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,9 @@
14481448
"build": "./node_modules/.bin/gulp build_or_download",
14491449
"fast-build-server": "./node_modules/.bin/gulp dev_server",
14501450
"watch-server": "./node_modules/.bin/gulp watch_server",
1451-
"eslint": "eslint --ignore-path .eslintignore --ext .js,.ts,.tsx ."
1451+
"eslint": "eslint --ignore-path .eslintignore --ext .js,.ts,.tsx .",
1452+
"repo:check": "./node_modules/.bin/gulp repo_check",
1453+
"repo:fix": "./node_modules/.bin/gulp repo_fix"
14521454
},
14531455
"devDependencies": {
14541456
"@types/fs-extra": "^8.0.0",

0 commit comments

Comments
 (0)