Skip to content

Commit

Permalink
attempt to surface JSPM dependencies in package.json and wire-up Snyk…
Browse files Browse the repository at this point in the history
… job to use this workaround
  • Loading branch information
twrichards committed Jun 13, 2023
1 parent ce636f1 commit cf9a8ea
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .github/workflows/snyk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ on:


jobs:
security:
snyk-V2-and-scala:
uses: guardian/.github/.github/workflows/sbt-node-snyk.yml@main
with:
ORG: guardian
JAVA_VERSION: 8
EXCLUDE: package-lock.json # exclude V1, since it has its own special job below (because of JSPM)
secrets:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

snyk-V1-only:
uses: guardian/.github/.github/workflows/sbt-node-snyk.yml@main
with:
ORG: guardian
JAVA_VERSION: 8
EXCLUDE: fronts-client # exclude V2, since it's captured by the main job above
SKIP_SBT: true # exclude scala, since it's captured by the main job above
NODE_PACKAGE_JSON_FILES_MISSING_LOCK: v1_jspm_snyk_workaround/package.json v1_jspm_snyk_workaround/result/package.json
secrets:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ metals.sbt
.bloop
.bsp

v1_jspm_snyk_workaround/package-lock.json
v1_jspm_snyk_workaround/result
32 changes: 32 additions & 0 deletions v1_jspm_snyk_workaround/jspm-snyk-workaround.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require("fs");

const outputDirName = "result"
const outputPath = `${outputDirName}/package.json`;

const packageJson = JSON.parse(String(fs.readFileSync("../package.json")));

const jspmDependencies = Object.fromEntries(
Object.values(packageJson.jspm.dependencies) // values because we don't care about what JSPM called them (i.e. the keys)
.filter(_ => !_.includes("systemjs"))
.map(jspmDepString => {
const [source, nameAtVersion] = jspmDepString.split(":");
const [name, version] = nameAtVersion.split("@");
return [
name.split("/").slice(-1), // last part (e.g. 'fastselect' if 'dbrekalo/fastselect')
source === "github" ? `git+/~https://github.com/${name}.git#${version}` : version
]
})
);

const newPackageJson = {
...packageJson,
dependencies: {
...packageJson.dependencies,
...jspmDependencies
}
};

fs.mkdirSync(outputDirName, {recursive: true});
fs.writeFileSync(outputPath, JSON.stringify(newPackageJson, null, 2));

console.log(`Wrote alternate package.json for V1 to v1_jspm_workaround/${outputPath} , which surfaces the JSPM dependencies`)
5 changes: 5 additions & 0 deletions v1_jspm_snyk_workaround/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"preinstall": "node jspm-snyk-workaround.js"
}
}

0 comments on commit cf9a8ea

Please sign in to comment.