@@ -6,6 +6,56 @@ const { glob } = require('glob');
6
6
const { promisify } = require ( 'util' ) ;
7
7
const execFile = promisify ( childProcess . execFile ) ;
8
8
9
+ const PACKAGE_LOCK_PATH = path . join ( __dirname , '..' , 'package-lock.json' ) ;
10
+
11
+ /**
12
+ * "node_modules/@vscode/vsce-sign" package which is a dev dependency used for
13
+ * publishing extension declares platform specific optionalDependencies, namely
14
+ * the following:
15
+ * - "@vscode/vsce-sign-alpine-arm64"
16
+ * - "@vscode/vsce-sign-alpine-x64"
17
+ * - "@vscode/vsce-sign-darwin-arm64"
18
+ * - "@vscode/vsce-sign-darwin-x64"
19
+ * - "@vscode/vsce-sign-linux-arm"
20
+ * - "@vscode/vsce-sign-linux-arm64"
21
+ * - "@vscode/vsce-sign-linux-x64"
22
+ * - "@vscode/vsce-sign-win32-arm64"
23
+ * - "@vscode/vsce-sign-win32-x64"
24
+ *
25
+ * Snyk requires what is declared in package-lock.json to be also present in
26
+ * installed node_modules but this will never happen because for any platform,
27
+ * other platform specific deps will always be missing which means Snyk will
28
+ * always fail in this case.
29
+ *
30
+ * Because we always install with `npm ci --omit=optional`, with this method we
31
+ * try to remove these identified problematic optionalDependencies before
32
+ * running the Snyk tests and once the tests are finished, we restore the
33
+ * original state back using npm hooks.
34
+ */
35
+ async function removeProblematicOptionalDepsFromPackageLock ( ) {
36
+ const packageLockContent = JSON . parse (
37
+ await fs . readFile ( PACKAGE_LOCK_PATH , 'utf-8' ) ,
38
+ ) ;
39
+
40
+ const vsceSignPackage =
41
+ packageLockContent . packages ?. [ 'node_modules/@vscode/vsce-sign' ] ;
42
+
43
+ if ( ! vsceSignPackage || ! vsceSignPackage . optionalDependencies ) {
44
+ console . info ( 'No problematic optional dependencies to fix' ) ;
45
+ return ;
46
+ }
47
+
48
+ // Temporarily remove the optional dependencies
49
+ vsceSignPackage [ 'optionalDependencies' ] = { } ;
50
+
51
+ // We write the actual package-lock path but restoring of the original file is
52
+ // handled by npm hooks.
53
+ await fs . writeFile (
54
+ PACKAGE_LOCK_PATH ,
55
+ JSON . stringify ( packageLockContent , null , 2 ) ,
56
+ ) ;
57
+ }
58
+
9
59
async function snykTest ( cwd ) {
10
60
const tmpPath = path . join ( os . tmpdir ( ) , 'tempfile-' + Date . now ( ) ) ;
11
61
@@ -17,9 +67,8 @@ async function snykTest(cwd) {
17
67
await execFile (
18
68
'npx' ,
19
69
[
20
- 'snyk' ,
70
+ 'snyk@latest ' ,
21
71
'test' ,
22
- '--all-projects' ,
23
72
'--severity-threshold=low' ,
24
73
'--dev' ,
25
74
`--json-file-output=${ tmpPath } ` ,
@@ -47,6 +96,7 @@ async function snykTest(cwd) {
47
96
async function main ( ) {
48
97
const rootPath = path . resolve ( __dirname , '..' ) ;
49
98
await fs . mkdir ( path . join ( rootPath , `.sbom` ) , { recursive : true } ) ;
99
+ await removeProblematicOptionalDepsFromPackageLock ( ) ;
50
100
const results = await snykTest ( rootPath ) ;
51
101
52
102
await fs . writeFile (
0 commit comments