forked from redhat-developer/vscode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepo.mjs
More file actions
69 lines (57 loc) · 1.99 KB
/
Copy pathrepo.mjs
File metadata and controls
69 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
import fs from 'fs-extra';
import { getProjectPath, handleError, setupMainExecution } from './utils.mjs';
const NON_NPM_REPOSITORY_RE = new RegExp(
String.raw`"resolved":\s*"https://.+/registry.npmjs.org/`,
"g"
);
async function repoCheck() {
console.log('Checking package-lock.json for internal registry references...');
try {
const packageLockPath = getProjectPath('package-lock.json');
const data = fs.readFileSync(packageLockPath, { encoding: "utf-8" });
if (NON_NPM_REPOSITORY_RE.test(data)) {
console.error("Found references to the internal registry in the file package-lock.json. Please fix it with 'npm run repo:fix'");
process.exit(1);
} else {
console.log('No internal registry references found');
}
} catch (error) {
handleError(error, 'checking repository');
}
}
async function repoFix() {
console.log('Fixing package-lock.json registry references...');
try {
const packageLockPath = getProjectPath('package-lock.json');
const data = fs.readFileSync(packageLockPath, { encoding: "utf-8" });
const newData = data.replace(NON_NPM_REPOSITORY_RE, `"resolved": "https://registry.npmjs.org/`);
if (data !== newData) {
fs.writeFileSync(packageLockPath, newData, {
encoding: "utf-8",
});
console.log('Successfully fixed package-lock.json');
} else {
console.log('Nothing to fix');
}
} catch (error) {
handleError(error, 'fixing repository');
}
}
// Main execution
async function main() {
const command = process.argv[2];
switch (command) {
case 'check':
await repoCheck();
break;
case 'fix':
await repoFix();
break;
default:
console.log('Usage: node repo.js [check|fix]');
process.exit(1);
}
}
setupMainExecution(main);
export { repoCheck, repoFix };