Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit hook to check urls in package-lock.json #192

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "(?!https://registry.npmjs.org).*"`,
sid-srini marked this conversation as resolved.
Show resolved Hide resolved
"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