Skip to content

Commit febdc37

Browse files
committed
Update Node test workflow
1 parent d1e22d3 commit febdc37

File tree

12 files changed

+152
-148
lines changed

12 files changed

+152
-148
lines changed

.config/rollup.base.config.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ function ${SOCKET_INTEROP}(e) {
293293
).map(o => ({
294294
...o,
295295
chunkFileNames: '[name].js',
296-
manualChunks: id =>
297-
id.includes(SLASH_NODE_MODULES_SLASH) ? 'vendor' : null
296+
manualChunks: id_ =>
297+
normalizeId(id_).includes(SLASH_NODE_MODULES_SLASH) ? 'vendor' : null
298298
}))
299299

300300
// Replace hard-coded absolute paths in source with hard-coded relative paths.

.github/workflows/test.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,5 @@ jobs:
2424
with:
2525
no-lockfile: true
2626
npm-test-script: 'test-ci'
27-
node-versions: '20'
28-
# We currently have some issues on Windows that will have to wait to be fixed
29-
# os: 'ubuntu-latest,windows-latest'
30-
os: 'ubuntu-latest'
27+
node-versions: '20,22'
28+
os: 'ubuntu-latest,windows-latest'

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
"lint:fix": "npm run lint -- --fix && npm run lint:fix:fast",
5252
"lint:fix:fast": "prettier --cache --log-level warn --write .",
5353
"prepare": "husky && custompatch",
54-
"test": "run-s check build:* test:*",
55-
"test:c8": "c8 --reporter=none node --test 'test/socket-npm.test.cjs'",
54+
"test": "run-s check build:* test:* test:coverage:*",
5655
"test-ci": "run-s build:* test:*",
5756
"test:unit": "tap-run",
58-
"test:coverage": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include 'dist/{module-sync,require}/*.js' --exclude 'dist/require/vendor.js' report"
57+
"test:coverage:c8": "c8 --reporter=none node --test 'test/socket-npm.test.cjs'",
58+
"test:coverage:merge": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include 'dist/{module-sync,require}/*.js' --exclude 'dist/require/vendor.js' report"
5959
},
6060
"dependencies": {
6161
"@apideck/better-ajv-errors": "^0.3.6",

src/commands/cdxgen.ts

+15-23
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { existsSync, promises as fs } from 'node:fs'
22
import path from 'node:path'
33

4-
import spawn from '@npmcli/promise-spawn'
54
import colors from 'yoctocolors-cjs'
65
import yargsParse from 'yargs-parser'
6+
import { runBin } from '@socketsecurity/registry/lib/npm'
77
import { pluralize } from '@socketsecurity/registry/lib/words'
88

99
import constants from '../constants'
@@ -12,8 +12,6 @@ import type { CliSubcommand } from '../utils/meow-with-subcommands'
1212

1313
const { cdxgenBinPath, synpBinPath } = constants
1414

15-
const { execPath } = process
16-
1715
const {
1816
SBOM_SIGN_ALGORITHM, // Algorithm. Example: RS512
1917
SBOM_SIGN_PRIVATE_KEY, // Location to the RSA private key
@@ -176,11 +174,10 @@ export const cdxgen: CliSubcommand = {
176174
// Use synp to create a package-lock.json from the yarn.lock,
177175
// based on the node_modules folder, for a more accurate SBOM.
178176
try {
179-
await spawn(
180-
execPath,
181-
[await fs.realpath(synpBinPath), '--source-file', './yarn.lock'],
182-
{ shell: true }
183-
)
177+
await runBin(await fs.realpath(synpBinPath), [
178+
'--source-file',
179+
'./yarn.lock'
180+
])
184181
yargv.type = 'npm'
185182
cleanupPackageLock = true
186183
} catch {}
@@ -189,23 +186,18 @@ export const cdxgen: CliSubcommand = {
189186
if (yargv.output === undefined) {
190187
yargv.output = 'socket-cdx.json'
191188
}
192-
await spawn(
193-
execPath,
194-
[await fs.realpath(cdxgenBinPath), ...argvToArray(yargv)],
195-
{
196-
env: {
197-
NODE_ENV: '',
198-
SBOM_SIGN_ALGORITHM,
199-
SBOM_SIGN_PRIVATE_KEY,
200-
SBOM_SIGN_PUBLIC_KEY
201-
},
202-
shell: true,
203-
stdio: 'inherit'
204-
}
205-
)
189+
await runBin(await fs.realpath(cdxgenBinPath), argvToArray(yargv), {
190+
env: {
191+
NODE_ENV: '',
192+
SBOM_SIGN_ALGORITHM,
193+
SBOM_SIGN_PRIVATE_KEY,
194+
SBOM_SIGN_PUBLIC_KEY
195+
},
196+
stdio: 'inherit'
197+
})
206198
if (cleanupPackageLock) {
207199
try {
208-
await fs.unlink('./package-lock.json')
200+
await fs.rm('./package-lock.json')
209201
} catch {}
210202
}
211203
const fullOutputPath = path.join(process.cwd(), yargv.output)

src/commands/npm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import constants from '../constants'
66

77
import type { CliSubcommand } from '../utils/meow-with-subcommands'
88

9-
const { distPath } = constants
9+
const { distPath, execPath } = constants
1010

1111
const description = 'npm wrapper functionality'
1212

@@ -16,7 +16,7 @@ export const npm: CliSubcommand = {
1616
const wrapperPath = path.join(distPath, 'npm-cli.js')
1717
process.exitCode = 1
1818
const spawnPromise = spawn(
19-
process.execPath,
19+
execPath,
2020
[
2121
// Lazily access constants.nodeNoWarningsFlags.
2222
...constants.nodeNoWarningsFlags,

src/commands/npx.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import constants from '../constants'
66

77
import type { CliSubcommand } from '../utils/meow-with-subcommands'
88

9-
const { distPath } = constants
9+
const { distPath, execPath } = constants
1010

1111
const description = 'npx wrapper functionality'
1212

@@ -16,7 +16,7 @@ export const npx: CliSubcommand = {
1616
const wrapperPath = path.join(distPath, 'npx-cli.js')
1717
process.exitCode = 1
1818
const spawnPromise = spawn(
19-
process.execPath,
19+
execPath,
2020
[
2121
// Lazily access constants.nodeNoWarningsFlags.
2222
...constants.nodeNoWarningsFlags,

src/commands/optimize.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ import type { Spinner } from '@socketregistry/yocto-spinner'
4242

4343
type PackageJson = Awaited<ReturnType<typeof readPackageJson>>
4444

45-
const { UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE, distPath } = constants
45+
const { UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE, distPath, execPath } =
46+
constants
4647

4748
const COMMAND_TITLE = 'Socket Optimize'
4849
const OVERRIDES_FIELD_NAME = 'overrides'
@@ -902,15 +903,15 @@ export const optimize: CliSubcommand = {
902903
}
903904
}
904905
await spawn(
905-
process.execPath,
906+
execPath,
906907
[wrapperPath, 'install', '--silent'],
907908
npmSpawnOptions
908909
)
909910
// TODO: This is a temporary workaround for a `npm ci` bug where it
910911
// will error out after Socket Optimize generates a lock file. More
911912
// investigation is needed.
912913
await spawn(
913-
process.execPath,
914+
execPath,
914915
[
915916
wrapperPath,
916917
'install',

src/shadow/npm-cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import constants from '../constants'
99
import { installLinks } from './link'
1010
import { findRoot } from '../utils/path-resolve'
1111

12-
const { distPath, shadowBinPath } = constants
12+
const { distPath, execPath, shadowBinPath } = constants
1313

1414
const npmPath = installLinks(shadowBinPath, 'npm')
1515
const injectionPath = path.join(distPath, 'npm-injection.js')
@@ -40,7 +40,7 @@ if (
4040

4141
process.exitCode = 1
4242
const spawnPromise = spawn(
43-
process.execPath,
43+
execPath,
4444
[
4545
// Lazily access constants.nodeNoWarningsFlags.
4646
...constants.nodeNoWarningsFlags,

src/shadow/npx-cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import spawn from '@npmcli/promise-spawn'
77
import constants from '../constants'
88
import { installLinks } from './link'
99

10-
const { distPath, shadowBinPath } = constants
10+
const { distPath, execPath, shadowBinPath } = constants
1111

1212
const npxPath = installLinks(shadowBinPath, 'npx')
1313
const injectionPath = path.join(distPath, 'npm-injection.js')
1414

1515
process.exitCode = 1
1616
const spawnPromise = spawn(
17-
process.execPath,
17+
execPath,
1818
[
1919
// Lazily access constants.nodeNoWarningsFlags.
2020
...constants.nodeNoWarningsFlags,

0 commit comments

Comments
 (0)