check-package-lock 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +1 -1
- package/LICENSE +1 -0
- package/README.md +46 -46
- package/eslint.config.js +17 -0
- package/index.js +12 -7
- package/package.json +49 -47
- package/test/index.js +26 -85
package/.circleci/config.yml
CHANGED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
# check-package-lock
|
|
2
|
-
Checks the package-lock.json file for http:// links
|
|
3
|
-
|
|
4
|
-
## What does it do?
|
|
5
|
-
check-package-lock can check if the package-lock.json file contain insecure http:// links
|
|
6
|
-
|
|
7
|
-
## Usage
|
|
8
|
-
To check the package-lock.json file in the current folder:
|
|
9
|
-
```
|
|
10
|
-
npm install -g check-package-lock
|
|
11
|
-
check-package-lock
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
To check the package-lock.json file in another folder:
|
|
15
|
-
```
|
|
16
|
-
npm install -g check-package-lock
|
|
17
|
-
check-package-lock --folder 'nodefolder'
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Exit codes
|
|
21
|
-
```
|
|
22
|
-
0 = No errors
|
|
23
|
-
1 = Errors were founds in the package-lock.json files
|
|
24
|
-
2 = package-lock.json was not found
|
|
25
|
-
3 = Folder specified does not exists
|
|
26
|
-
4 = Folder specified is not a folder
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Continuous Integration
|
|
30
|
-
check-package-lock can be used in CI environments to check your package-lock.json file before merging a pull request
|
|
31
|
-
|
|
32
|
-
## Badges
|
|
33
|
-
|
|
34
|
-
[](https://circleci.com/gh/gemal/node-check-package-lock)
|
|
35
|
-
|
|
36
|
-
[](https://codecov.io/gh/gemal/node-check-package-lock)
|
|
37
|
-
|
|
38
|
-
[](https://github.styleci.io/repos/183420925)
|
|
39
|
-
|
|
40
|
-
[](https://snyk.io/test/github/gemal/node-check-package-lock)
|
|
41
|
-
|
|
42
|
-
[](https://lgtm.com/projects/g/gemal/node-check-package-lock/alerts/)
|
|
43
|
-
|
|
44
|
-
[](https://www.codefactor.io/repository/github/gemal/node-check-package-lock)
|
|
45
|
-
|
|
46
|
-
[](https://deepscan.io/dashboard#view=project&tid=14204&pid=17307&bid=392368)
|
|
1
|
+
# check-package-lock
|
|
2
|
+
Checks the package-lock.json file for http:// links
|
|
3
|
+
|
|
4
|
+
## What does it do?
|
|
5
|
+
check-package-lock can check if the package-lock.json file contain insecure http:// links
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
To check the package-lock.json file in the current folder:
|
|
9
|
+
```
|
|
10
|
+
npm install -g check-package-lock
|
|
11
|
+
check-package-lock
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
To check the package-lock.json file in another folder:
|
|
15
|
+
```
|
|
16
|
+
npm install -g check-package-lock
|
|
17
|
+
check-package-lock --folder 'nodefolder'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Exit codes
|
|
21
|
+
```
|
|
22
|
+
0 = No errors
|
|
23
|
+
1 = Errors were founds in the package-lock.json files
|
|
24
|
+
2 = package-lock.json was not found
|
|
25
|
+
3 = Folder specified does not exists
|
|
26
|
+
4 = Folder specified is not a folder
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## CI - Continuous Integration
|
|
30
|
+
check-package-lock can be used in CI environments to check your package-lock.json file before merging a pull request
|
|
31
|
+
|
|
32
|
+
## Badges
|
|
33
|
+
|
|
34
|
+
[](https://circleci.com/gh/gemal/node-check-package-lock)
|
|
35
|
+
|
|
36
|
+
[](https://codecov.io/gh/gemal/node-check-package-lock)
|
|
37
|
+
|
|
38
|
+
[](https://github.styleci.io/repos/183420925)
|
|
39
|
+
|
|
40
|
+
[](https://snyk.io/test/github/gemal/node-check-package-lock)
|
|
41
|
+
|
|
42
|
+
[](https://lgtm.com/projects/g/gemal/node-check-package-lock/alerts/)
|
|
43
|
+
|
|
44
|
+
[](https://www.codefactor.io/repository/github/gemal/node-check-package-lock)
|
|
45
|
+
|
|
46
|
+
[](https://deepscan.io/dashboard#view=project&tid=14204&pid=17307&bid=392368)
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import globals from "globals";
|
|
2
|
+
import js from "@eslint/js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
languageOptions: {
|
|
8
|
+
globals: {
|
|
9
|
+
process: "readonly",
|
|
10
|
+
describe: "readonly",
|
|
11
|
+
it: "readonly",
|
|
12
|
+
...globals.browser
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
js.configs.recommended,
|
|
17
|
+
];
|
package/index.js
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { program } from 'commander';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
|
|
10
|
+
// Define __filename and __dirname for ES modules
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Check a folder.
|
|
@@ -17,7 +22,7 @@ function checkFolder() {
|
|
|
17
22
|
}
|
|
18
23
|
const pack = fullpath + 'package-lock.json';
|
|
19
24
|
if (fs.existsSync(pack)) {
|
|
20
|
-
const filecontent = fs.readFileSync(pack, {encoding: 'utf-8'});
|
|
25
|
+
const filecontent = fs.readFileSync(pack, { encoding: 'utf-8' });
|
|
21
26
|
if (filecontent.indexOf('http://registry.npmjs.org') > -1) { // lgtm [js/incomplete-url-substring-sanitization]
|
|
22
27
|
console.log(pack + ' is NOT OK. It contains references to http://registry.npmjs.org');
|
|
23
28
|
console.log('In order to fix this do:');
|
|
@@ -31,13 +36,13 @@ function checkFolder() {
|
|
|
31
36
|
return 0;
|
|
32
37
|
}
|
|
33
38
|
} else {
|
|
34
|
-
console.log(pack + ' does not
|
|
39
|
+
console.log(pack + ' does not exist');
|
|
35
40
|
return 2;
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
program
|
|
40
|
-
.version(
|
|
45
|
+
.version(JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))).version)
|
|
41
46
|
.description('Checks the package-lock.json file for http:// links')
|
|
42
47
|
.option('-f, --folder <folder>', 'Folder with package-lock.json file')
|
|
43
48
|
.parse(process.argv);
|
|
@@ -54,7 +59,7 @@ if (options.folder) {
|
|
|
54
59
|
process.exitCode = 4;
|
|
55
60
|
}
|
|
56
61
|
} else {
|
|
57
|
-
console.log('Oops! Folder does not
|
|
62
|
+
console.log('Oops! Folder does not exist: ' + options.folder);
|
|
58
63
|
process.exitCode = 3;
|
|
59
64
|
}
|
|
60
65
|
} else {
|
package/package.json
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "check-package-lock",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Checks the package-lock.json file for http:// links",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/gemal/node-check-package-lock"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "mocha"
|
|
12
|
-
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"package
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "check-package-lock",
|
|
3
|
+
"version": "1.11.0",
|
|
4
|
+
"description": "Checks the package-lock.json file for insecure http:// links",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/gemal/node-check-package-lock"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "mocha"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"author": "Henrik Gemal <henrik@gemal.dk> (http://gemal.dk/)",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"bin": {
|
|
17
|
+
"check-package-lock": "index.js"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/gemal/node-check-package-lock/issues"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"package",
|
|
24
|
+
"package-lock",
|
|
25
|
+
"check",
|
|
26
|
+
"cli",
|
|
27
|
+
"lock",
|
|
28
|
+
"http",
|
|
29
|
+
"automate",
|
|
30
|
+
"ci"
|
|
31
|
+
],
|
|
32
|
+
"homepage": "https://github.com/gemal/node-check-package-lock",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^12.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@eslint/js": "^9.13.0",
|
|
38
|
+
"chai": "^5.1.2",
|
|
39
|
+
"child_process": "^1.0.2",
|
|
40
|
+
"codecov": "^3.8.2",
|
|
41
|
+
"eslint": "^9.13.0",
|
|
42
|
+
"expect": "^29.2.2",
|
|
43
|
+
"globals": "^15.11.0",
|
|
44
|
+
"lintspaces-cli": "^1.0.0",
|
|
45
|
+
"mocha": "^10.0.0",
|
|
46
|
+
"nyc": "^17.1.0",
|
|
47
|
+
"snyk": "^1.594.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/test/index.js
CHANGED
|
@@ -1,115 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { exec } from "node:child_process";
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const spawn = require('child_process').spawn;
|
|
8
|
-
const expect = require('chai').expect;
|
|
6
|
+
// Define __filename and __dirname in ES modules
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
9
|
|
|
10
10
|
describe('index.js', function() {
|
|
11
|
-
// eslint-disable-next-line no-invalid-this
|
|
12
11
|
this.timeout(8000);
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
function runTest(args, expectedExitCode, expectedOutput, done) {
|
|
14
|
+
const command = `node ${path.join(__dirname, '../index.js')} ${args.join(' ')}`;
|
|
15
|
+
exec(command, { cwd: path.join(__dirname, '../') }, (error, stdout) => {
|
|
16
|
+
if (error) {
|
|
17
|
+
expect(error.code).to.equal(expectedExitCode);
|
|
18
|
+
} else {
|
|
19
|
+
expect(stdout).to.match(expectedOutput);
|
|
20
|
+
}
|
|
22
21
|
done();
|
|
23
|
-
}).stdout.on('data', function(data) {
|
|
24
|
-
out += data;
|
|
25
22
|
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
it('should exit 1 having problems', function(done) {
|
|
26
|
+
runTest(['--folder', 'test/test1'], 1, /package-lock.json is NOT OK/, done);
|
|
26
27
|
});
|
|
27
28
|
|
|
28
29
|
it('should exit 0 having no problems', function(done) {
|
|
29
|
-
|
|
30
|
-
spawn('node', [path.join(__dirname, '../index.js'), '--folder', 'test/test2'], {
|
|
31
|
-
cwd: path.join(__dirname, '../'),
|
|
32
|
-
}).on('exit', function(code) {
|
|
33
|
-
assert.strictEqual(code, 0);
|
|
34
|
-
expect(out).to.match(/package-lock.json is OK/);
|
|
35
|
-
done();
|
|
36
|
-
}).stdout.on('data', function(data) {
|
|
37
|
-
out += data;
|
|
38
|
-
});
|
|
30
|
+
runTest(['--folder', 'test/test2'], 0, /package-lock.json is OK/, done);
|
|
39
31
|
});
|
|
40
32
|
|
|
41
33
|
it('should exit 0 having no problems with slash', function(done) {
|
|
42
|
-
|
|
43
|
-
spawn('node', [path.join(__dirname, '../index.js'), '--folder', 'test/test2/'], {
|
|
44
|
-
cwd: path.join(__dirname, '../'),
|
|
45
|
-
}).on('exit', function(code) {
|
|
46
|
-
assert.strictEqual(code, 0);
|
|
47
|
-
expect(out).to.match(/package-lock.json is OK/);
|
|
48
|
-
done();
|
|
49
|
-
}).stdout.on('data', function(data) {
|
|
50
|
-
out += data;
|
|
51
|
-
});
|
|
34
|
+
runTest(['--folder', 'test/test2/'], 0, /package-lock.json is OK/, done);
|
|
52
35
|
});
|
|
53
36
|
|
|
54
37
|
it('should exit 0 having no problems without folder', function(done) {
|
|
55
|
-
|
|
56
|
-
spawn('node', [path.join(__dirname, '../index.js')], {
|
|
57
|
-
cwd: path.join(__dirname, '../'),
|
|
58
|
-
}).on('exit', function(code) {
|
|
59
|
-
assert.strictEqual(code, 0);
|
|
60
|
-
expect(out).to.match(/package-lock.json is OK/);
|
|
61
|
-
done();
|
|
62
|
-
}).stdout.on('data', function(data) {
|
|
63
|
-
out += data;
|
|
64
|
-
});
|
|
38
|
+
runTest([], 0, /package-lock.json is OK/, done);
|
|
65
39
|
});
|
|
66
40
|
|
|
67
41
|
it('should exit 1 having problems', function(done) {
|
|
68
|
-
|
|
69
|
-
spawn('node', [path.join(__dirname, '../index.js'), '--folder', 'test/test3'], {
|
|
70
|
-
cwd: path.join(__dirname, '../'),
|
|
71
|
-
}).on('exit', function(code) {
|
|
72
|
-
assert.strictEqual(code, 1);
|
|
73
|
-
expect(out).to.match(/package-lock.json is NOT OK/);
|
|
74
|
-
expect(out).to.match(/Delete the node_modules folder/);
|
|
75
|
-
done();
|
|
76
|
-
}).stdout.on('data', function(data) {
|
|
77
|
-
out += data;
|
|
78
|
-
});
|
|
42
|
+
runTest(['--folder', 'test/test3'], 1, /package-lock.json is NOT OK/, done);
|
|
79
43
|
});
|
|
80
44
|
|
|
81
45
|
it('should exit 1 having problems with no file', function(done) {
|
|
82
|
-
|
|
83
|
-
spawn('node', [path.join(__dirname, '../index.js'), '--folder', 'test'], {
|
|
84
|
-
cwd: path.join(__dirname, '../'),
|
|
85
|
-
}).on('exit', function(code) {
|
|
86
|
-
assert.strictEqual(code, 2);
|
|
87
|
-
expect(out).to.match(/package-lock.json does not exists/);
|
|
88
|
-
done();
|
|
89
|
-
}).stdout.on('data', function(data) {
|
|
90
|
-
out += data;
|
|
91
|
-
});
|
|
46
|
+
runTest(['--folder', 'test'], 2, /package-lock.json does not exists/, done);
|
|
92
47
|
});
|
|
93
48
|
|
|
94
49
|
it('should exit 3 if folder does not exist', function(done) {
|
|
95
|
-
|
|
96
|
-
cwd: path.join(__dirname, '../'),
|
|
97
|
-
}).on('exit', function(code) {
|
|
98
|
-
assert.strictEqual(code, 3);
|
|
99
|
-
}).stdout.on('data', function(data) {
|
|
100
|
-
assert.strictEqual(data.toString(), 'Oops! Folder does not exists: 404\n');
|
|
101
|
-
done();
|
|
102
|
-
});
|
|
50
|
+
runTest(['--folder', '404'], 3, /Oops! Folder does not exists: 404\n/, done);
|
|
103
51
|
});
|
|
104
52
|
|
|
105
53
|
it('should exit 4 if folder is not a folder', function(done) {
|
|
106
|
-
|
|
107
|
-
cwd: path.join(__dirname, '../'),
|
|
108
|
-
}).on('exit', function(code) {
|
|
109
|
-
assert.strictEqual(code, 4);
|
|
110
|
-
}).stdout.on('data', function(data) {
|
|
111
|
-
assert.strictEqual(data.toString(), 'Oops! Folder is not a real folder: test/index.js\n');
|
|
112
|
-
done();
|
|
113
|
-
});
|
|
54
|
+
runTest(['--folder', 'test/index.js'], 4, /Oops! Folder is not a real folder: test\/index.js\n/, done);
|
|
114
55
|
});
|
|
115
56
|
});
|