Skip to content

Commit

Permalink
pre-commit hook to check urls in package-lock.json (#192)
Browse files Browse the repository at this point in the history
* pre-commit hook to check internal artifactory url

* updated regex

* updated regex
  • Loading branch information
Achal1607 authored Jul 31, 2024
1 parent 30067b2 commit 9f958e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 20 additions & 2 deletions vscode/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { build } = require("esbuild");
const fs = require('fs');
const path = require('path');

const baseConfig = {
bundle: true,
Expand Down Expand Up @@ -28,7 +30,21 @@ const watchConfig = {
},
},
};


const NON_NPM_ARTIFACTORY = new RegExp(
String.raw`"resolved"\s*:\s*"http[s]*://(?!registry.npmjs.org)[^"]+"`,
"g"
);

const checkAritfactoryUrl = () => {
const data = fs.readFileSync(path.resolve(__dirname, 'package-lock.json'), { encoding: 'utf-8' });
if (NON_NPM_ARTIFACTORY.test(data)) {
throw new Error("Found references to the internal registry in the file package-lock.json. Please fix it");
} else {
console.log('No internal artifactory references found.');
}
}

(async () => {
const args = process.argv.slice(2);
try {
Expand All @@ -40,13 +56,15 @@ const watchConfig = {
...watchConfig,
});
console.log("[watch] build finished");
} else if(args.includes("--artifactory-check")){
checkAritfactoryUrl();
} else {
// Build source code
await build(scriptConfig);
console.log("build complete");
}
} catch (err) {
process.stderr.write(err.stderr);
process.stderr.write(err.message);
process.exit(1);
}
})();
5 changes: 3 additions & 2 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,9 @@
"test": "node ./out/test/runTest.js",
"nbcode": "node ./out/nbcode.js",
"nbjavac": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install .*nbjavac.*",
"apisupport": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install '(org.netbeans.libs.xerces|org.netbeans.modules.editor.structure|org.netbeans.modules.xml|org.netbeans.modules.xml.axi|org.netbeans.modules.xml.retriever|org.netbeans.modules.xml.schema.model|org.netbeans.modules.xml.tax|org.netbeans.modules.xml.text|org.netbeans.modules.ant.browsetask|.*apisupport.*|org.netbeans.modules.debugger.jpda.ant)' && node ./out/nbcode.js -J-Dnetbeans.close=true --modules --enable .*apisupport.ant"
},
"apisupport": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install '(org.netbeans.libs.xerces|org.netbeans.modules.editor.structure|org.netbeans.modules.xml|org.netbeans.modules.xml.axi|org.netbeans.modules.xml.retriever|org.netbeans.modules.xml.schema.model|org.netbeans.modules.xml.tax|org.netbeans.modules.xml.text|org.netbeans.modules.ant.browsetask|.*apisupport.*|org.netbeans.modules.debugger.jpda.ant)' && node ./out/nbcode.js -J-Dnetbeans.close=true --modules --enable .*apisupport.ant",
"artifactory:check": "node ./esbuild.js --artifactory-check"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^9.0.0",
Expand Down

0 comments on commit 9f958e4

Please sign in to comment.