Skip to content

Commit a0882cc

Browse files
authored
chore: collect demo data with npm-ls args (#1230)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 8ed0ae7 commit a0882cc

File tree

5 files changed

+69
-37
lines changed

5 files changed

+69
-37
lines changed

.github/workflows/npm-ls_demo-results.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313

1414
jobs:
1515
demo-results:
16-
name: '${{ matrix.subject }} npm${{ matrix.npm-version }} node${{ matrix.node-version }} ${{ matrix.os }}'
16+
name: '${{ matrix.subject }} ${{matrix.additional_npm-ls_args}} | npm${{ matrix.npm-version }} node${{ matrix.node-version }} ${{ matrix.os }}'
1717
runs-on: ${{ matrix.os }}
1818
strategy:
1919
fail-fast: false # gather all the results !
@@ -24,16 +24,17 @@ jobs:
2424
# - bundled-dependencies
2525
# - dev-dependencies
2626
# - juice-shop
27-
- local-dependencies
27+
# - local-dependencies
2828
- local-workspaces
2929
# - package-integrity
3030
# - package-with-build-id
31+
additional_npm-ls_args: [ '' ]
3132
npm-version:
3233
## see https://www.npmjs.com/package/npm?activeTab=versions
3334
## see also: https://github.com/npm/cli/releases
34-
- '10' # https://github.com/npm/cli/releases/tag/v10.0.0-pre.0
35-
- '9' # Current
36-
- '8' # Latest
35+
- '10' # Current
36+
- '9' # Legacy
37+
- '8' # Legacy
3738
- '7' # Legacy
3839
- '6' # Legacy
3940
node-version:
@@ -48,6 +49,22 @@ jobs:
4849
- ubuntu-latest
4950
- windows-latest
5051
- macos-latest
52+
include:
53+
- subject: local-workspaces
54+
additional_npm-ls_args: '-w my-local-e'
55+
npm-version: '10' # Current
56+
node-version: '22' # Current
57+
os: ubuntu-latest
58+
- subject: local-workspaces
59+
additional_npm-ls_args: '-w my-local -w my-local-e'
60+
npm-version: '10' # Current
61+
node-version: '22' # Current
62+
os: ubuntu-latest
63+
- subject: local-workspaces
64+
additional_npm-ls_args: '--workspaces'
65+
npm-version: '10' # Current
66+
node-version: '22' # Current
67+
os: ubuntu-latest
5168
exclude:
5269
- # macos-latest no longer supports node14
5370
os: macos-latest
@@ -81,7 +98,7 @@ jobs:
8198
- name: prepare output
8299
run: |
83100
mkdir -p '${{ env.RESULTS_DIR }}'
84-
echo 'OUT_FILE_PREFIX=${{ env.RESULTS_DIR }}/npm-ls_npm${{ matrix.npm-version }}_node${{ matrix.node-version }}_${{ matrix.os }}' >> $GITHUB_ENV
101+
echo 'OUT_FILE_PREFIX=${{ env.RESULTS_DIR }}/npm-ls${{ matrix.additional_npm-ls_args }}_npm${{ matrix.npm-version }}_node${{ matrix.node-version }}_${{ matrix.os }}' >> $GITHUB_ENV
85102
working-directory: '${{ env.DEMO_ROOT_DIR}}/${{ matrix.subject }}'
86103
shell: bash # don't want to write tht code twice, windows and unix-like
87104
- name: Setup Node.js ${{ matrix.node-version }}
@@ -103,15 +120,15 @@ jobs:
103120
# important: the command in use is the same used by the internal builders of this project
104121
run: >
105122
npm --prefix project
106-
ls --json --all --long
107-
2> ${{ env.OUT_FILE_PREFIX }}.err.log
108-
1> ${{ env.OUT_FILE_PREFIX }}.json
123+
ls --json --all --long ${{ matrix.additional_npm-ls_args }}
124+
2> '${{ env.OUT_FILE_PREFIX }}.err.log'
125+
1> '${{ env.OUT_FILE_PREFIX }}.json'
109126
working-directory: '${{ env.DEMO_ROOT_DIR}}/${{ matrix.subject }}'
110127
- name: Artifact RESULTS
111128
# see https://github.com/actions/upload-artifact
112129
uses: actions/upload-artifact@v4
113130
with:
114-
name: '${{ env.RESULTS_ARTIFACT }}_${{ matrix.subject }}_npm${{ matrix.npm-version }}_node${{ matrix.node-version }}_${{ matrix.os }}'
131+
name: '${{ env.RESULTS_ARTIFACT }}_${{ matrix.subject }}${{ matrix.additional_npm-ls_args }}_npm${{ matrix.npm-version }}_node${{ matrix.node-version }}_${{ matrix.os }}'
115132
path: '${{ env.DEMO_ROOT_DIR}}/*/${{ env.RESULTS_DIR }}'
116133
if-no-files-found: error
117134
retention-days: 3

tests/_data/npm-ls_demo-results/_duplicates-cleaner/remove-duplicates.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { fileURLToPath } from 'node:url'
2727
const __dirname = dirname(fileURLToPath(import.meta.url))
2828
const dirDemoRes = dirname(__dirname)
2929

30-
const fnamePattern = /^npm-ls_npm(?<npm>\d+)_node(?<node>\d+)_(?<os>.+)\.json$/
30+
const fnamePattern = /^npm-ls(?<args>.*?)_npm(?<npm>\d+)_node(?<node>\d+)_(?<os>.+)\.json$/
3131

3232
/** @type {Object.<string, Object.<string, string[]>>} */
3333
const files = {}
@@ -41,33 +41,40 @@ for (const dirDemoResE of readdirSync(dirDemoRes)) {
4141
if (!fnameMatch) {
4242
continue
4343
}
44-
if (!Object.hasOwn(files, fnameMatch.groups.npm)) {
45-
files[fnameMatch.groups.npm] = {}
44+
let _t = files
45+
if (!Object.hasOwn(_t, fnameMatch.groups.args)) {
46+
_t[fnameMatch.groups.args] = {}
4647
}
47-
if (!Object.hasOwn(files[fnameMatch.groups.npm], fnameMatch.groups.os)) {
48-
files[fnameMatch.groups.npm][fnameMatch.groups.os] = []
48+
_t = _t[fnameMatch.groups.args]
49+
if (!Object.hasOwn(_t, fnameMatch.groups.npm)) {
50+
_t[fnameMatch.groups.npm] = {}
4951
}
50-
files[fnameMatch.groups.npm][fnameMatch.groups.os].push(
51-
join(dirResults, dirResultsE)
52-
)
52+
_t = _t[fnameMatch.groups.npm]
53+
if (!Object.hasOwn(_t, fnameMatch.groups.os)) {
54+
_t[fnameMatch.groups.os] = []
55+
}
56+
_t = _t[fnameMatch.groups.os]
57+
_t.push(join(dirResults, dirResultsE))
5358
}
5459
} catch (e) {
5560
continue
5661
}
5762
}
5863

59-
for (const filesByOs of Object.values(files)) {
60-
for (const filePaths of Object.values(filesByOs)) {
61-
const fileHashes = new Set()
62-
for (const filePath of filePaths) {
63-
const fileHash = await hashFile(filePath)
64-
if (fileHashes.has(fileHash)) {
65-
console.info('DELETE:', fileHash, filePath)
66-
unlinkSync(filePath)
67-
continue
64+
for (const filesByAs of Object.values(files)) {
65+
for (const filesByOs of Object.values(filesByAs)) {
66+
for (const filePaths of Object.values(filesByOs)) {
67+
const fileHashes = new Set()
68+
for (const filePath of filePaths) {
69+
const fileHash = await hashFile(filePath)
70+
if (fileHashes.has(fileHash)) {
71+
console.info('DELETE:', fileHash, filePath)
72+
unlinkSync(filePath)
73+
continue
74+
}
75+
fileHashes.add(fileHash)
76+
console.info('KEEP:', fileHash, filePath)
6877
}
69-
fileHashes.add(fileHash)
70-
console.info('KEEP:', fileHash, filePath)
7178
}
7279
}
7380
}

tests/_data/npm-ls_demo-results/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
const { sync: glob } = require('fast-glob')
2121

2222
const fileGlob = '*/CI_results/*.json'
23-
const filePattern = /\/(?<subject>[^/]+?)\/CI_results\/npm-ls_npm(?<npm>.+?)_node(?<node>.+?)_(?<os>.+?).json$/i
23+
const filePattern = /\/(?<subject>[^/]+?)\/CI_results\/npm-ls(?<args>.*?)_npm(?<npm>.+?)_node(?<node>.+?)_(?<os>.+?).json$/i
2424
/** @type {import('fast-glob').OptionsInternal} */
2525
const globOptions = { absolute: true, caseSensitiveMatch: false, cwd: __dirname, deep: 3, onlyFiles: true, unique: true }
2626

2727
let cached
2828

2929
/**
30-
* @return {{path:string, subject?:string, npm?:string, node?:string, os?:string}[]}
30+
* @return {{path:string, subject?:string, args?:string, npm?:string, node?:string, os?:string}[]}
3131
*/
3232
function index () {
3333
if (cached === undefined) {

tests/_data/npm-ls_replacement/demo-results.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ process.exitCode = Number(process.env.CT_EXIT_CODE || 0)
3030

3131
const index = require('../npm-ls_demo-results').index()
3232

33-
const { CT_SUBJECT: subject, CT_NPM: npm, CT_NODE: node, CT_OS: os } = process.env
34-
const matches = index.filter(i => i.subject === subject && i.npm === npm && i.node === node && i.os === os)
35-
assert.strictEqual(matches.length, 1, 'did not find exactly 1 match')
33+
const { CT_SUBJECT: subject, CT_ARGS: args = '', CT_NPM: npm, CT_NODE: node, CT_OS: os } = process.env
34+
const matches = index.filter(i =>
35+
i.subject === subject &&
36+
i.args === args &&
37+
i.npm === npm &&
38+
i.node === node &&
39+
i.os === os)
40+
assert.strictEqual(matches.length, 1, `did not find exactly 1 match: ${JSON.stringify(matches)}`)
3641

3742
const { path } = matches[0]
3843

tests/integration/cli.from-collected.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ describe('integration.cli.from-collected', () => {
188188
describe.each(useCases)('$subject', (ud) => {
189189
mkdirSync(join(tmpRootRun, ud.subject))
190190

191-
test.each(demoCases)('$subject npm$npm node$node $os', async (dd) => {
192-
const expectedOutSnap = resolve(demoResultsRoot, ud.subject, `${dd.subject}_npm${dd.npm}_node${dd.node}_${dd.os}.snap.json`)
193-
const logFileBase = join(tmpRootRun, ud.subject, `${dd.subject}_npm${dd.npm}_node${dd.node}_${dd.os}`)
191+
test.each(demoCases)('$subject $args npm$npm node$node $os', async (dd) => {
192+
const expectedOutSnap = resolve(demoResultsRoot, ud.subject, `${dd.subject}${dd.args}_npm${dd.npm}_node${dd.node}_${dd.os}.snap.json`)
193+
const logFileBase = join(tmpRootRun, ud.subject, `${dd.subject}${dd.args}_npm${dd.npm}_node${dd.node}_${dd.os}`)
194194
const cwd = resolve(projectTestRootPath, '_data', 'dummy_projects')
195195

196196
const { res, outFile, errFile } = runCLI([
@@ -205,12 +205,15 @@ describe('integration.cli.from-collected', () => {
205205
'--package-lock-only',
206206
// case-specific args
207207
...ud.args,
208+
// explicit args
209+
...(dd.args === '' ? [] : dd.args.split(' ')),
208210
'--',
209211
// just some dummy project
210212
join('with-lockfile', 'package.json')
211213
], logFileBase, cwd, {
212214
CT_VERSION: `${dd.npm}.99.0`,
213215
CT_SUBJECT: dd.subject,
216+
CT_ARGS: dd.args,
214217
CT_NPM: dd.npm,
215218
CT_NODE: dd.node,
216219
CT_OS: dd.os,

0 commit comments

Comments
 (0)