diff --git a/.github/scripts/docker/should-smoke-build.mjs b/.github/scripts/docker/should-smoke-build.mjs index ecb622420ed..6d69e0d3672 100644 --- a/.github/scripts/docker/should-smoke-build.mjs +++ b/.github/scripts/docker/should-smoke-build.mjs @@ -18,11 +18,7 @@ const ROOT_MANIFEST = 'package.json'; const NODES_BASE_MANIFEST = 'packages/nodes-base/package.json'; const EDIT_IMAGE_NATIVE_PACKAGES = new Set([ '@napi-rs/canvas', - '@napi-rs/canvas-linux-arm64-musl', - '@napi-rs/canvas-linux-x64-musl', '@napi-rs/image', - '@napi-rs/image-linux-arm64-musl', - '@napi-rs/image-linux-x64-musl', ]); const BUMP_ONLY = [/^pnpm-workspace\.yaml$/, /^pnpm-lock\.yaml$/, /(^|\/)package\.json$/]; diff --git a/knip.ts b/knip.ts index 2ddae9ed5e2..7dd2a0752fb 100644 --- a/knip.ts +++ b/knip.ts @@ -134,11 +134,6 @@ const config: KnipConfig = { }), 'packages/nodes-base': pkg({ ignoreDependencies: [ - // napi-rs wrappers load these platform bindings dynamically at runtime. - '@napi-rs/canvas-linux-arm64-musl', - '@napi-rs/canvas-linux-x64-musl', - '@napi-rs/image-linux-arm64-musl', - '@napi-rs/image-linux-x64-musl', // Pins the pg version that pg-promise resolves for npm installs of the published package. 'pg', ], diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 117c625100d..c9612fd5e87 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -968,11 +968,7 @@ "@n8n/imap": "workspace:*", "@n8n/utils": "workspace:*", "@napi-rs/canvas": "catalog:", - "@napi-rs/canvas-linux-arm64-musl": "catalog:", - "@napi-rs/canvas-linux-x64-musl": "catalog:", "@napi-rs/image": "catalog:", - "@napi-rs/image-linux-arm64-musl": "catalog:", - "@napi-rs/image-linux-x64-musl": "catalog:", "@thednp/dommatrix": "^3.1.1", "alasql": "4.4.0", "amqplib": "0.10.6", diff --git a/packages/quality/policy/code-health/src/single-instance/verify-npm-install.test.ts b/packages/quality/policy/code-health/src/single-instance/verify-npm-install.test.ts index 23868d9aff9..63e418bb36d 100644 --- a/packages/quality/policy/code-health/src/single-instance/verify-npm-install.test.ts +++ b/packages/quality/policy/code-health/src/single-instance/verify-npm-install.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from 'vitest'; import { resolve } from 'node:path'; import { - buildNpmInstallOverrides, closureOf, expectedNpmDuplicateReason, findWorkspacePackageJsonFiles, @@ -65,18 +64,6 @@ describe('expectedNpmDuplicateReason', () => { }); }); -describe('buildNpmInstallOverrides', () => { - it('uses local tarballs and excludes Docker-only native bindings', () => { - expect(buildNpmInstallOverrides(['a'], { a: '/tmp/a.tgz' })).toMatchObject({ - a: 'file:/tmp/a.tgz', - '@napi-rs/canvas-linux-arm64-musl': 'npm:empty-npm-package@1.0.0', - '@napi-rs/canvas-linux-x64-musl': 'npm:empty-npm-package@1.0.0', - '@napi-rs/image-linux-arm64-musl': 'npm:empty-npm-package@1.0.0', - '@napi-rs/image-linux-x64-musl': 'npm:empty-npm-package@1.0.0', - }); - }); -}); - /** Build a WorkspacePkg fixture from `[depName, section]` pairs (only names + sections matter). */ function ws(name: string, deps: Array<[string, string]>) { return { diff --git a/packages/quality/policy/code-health/src/single-instance/verify-npm-install.ts b/packages/quality/policy/code-health/src/single-instance/verify-npm-install.ts index 3e60fe2803c..7b1df015a46 100644 --- a/packages/quality/policy/code-health/src/single-instance/verify-npm-install.ts +++ b/packages/quality/policy/code-health/src/single-instance/verify-npm-install.ts @@ -28,14 +28,6 @@ const ROOT_TRIGGERS = [ const CLOSURE_SECTIONS = new Set(PUBLISHED_SECTIONS); -// Remove these once n8n-nodes-base no longer publishes platform bindings as regular dependencies. -const NPM_INSTALL_EXCLUSIONS = [ - '@napi-rs/canvas-linux-arm64-musl', - '@napi-rs/canvas-linux-x64-musl', - '@napi-rs/image-linux-arm64-musl', - '@napi-rs/image-linux-x64-musl', -]; -const NPM_INSTALL_EXCLUSION_REPLACEMENT = 'empty-npm-package'; const NPM_INSTALL_ALLOWLIST_FILE = 'packages/quality/policy/code-health/src/single-instance/verify-npm-install.ts'; const NPM_INSTALL_ALLOWLIST_NAME = 'EXPECTED_NPM_DUPLICATES'; @@ -96,22 +88,6 @@ export function expectedNpmDuplicateReason(duplicate: ExplainedDuplicate): strin return expected.reason; } -/** Replace Docker-only bindings that npm rejects outside their target platform. */ -export function buildNpmInstallOverrides( - packages: string[], - tarballByName: Record, -): Record { - const localPackages = packages.map((name): [string, string] => [ - name, - `file:${tarballByName[name]}`, - ]); - const exclusions = NPM_INSTALL_EXCLUSIONS.map((name): [string, string] => [ - name, - `npm:${NPM_INSTALL_EXCLUSION_REPLACEMENT}@1.0.0`, - ]); - return Object.fromEntries([...localPackages, ...exclusions]); -} - /** True when a changed file can shift dependency resolution repo-wide, forcing a full check. */ export function filesTriggerFullRun(files: string[]): boolean { return files.some((f) => ROOT_TRIGGERS.some((t) => f === t || f.startsWith(t))); @@ -430,7 +406,7 @@ export async function runVerifyNpmInstall(args: string[], rootDir: string): Prom // Scratch project: install targets as file: deps, force ALL packed workspace deps to their // local tarballs. Third-party deps resolve from the real npm registry. const fileDep = (n: string): [string, string] => [n, `file:${tarballByName[n]}`]; - const overrides = buildNpmInstallOverrides(toPack, tarballByName); + const overrides = Object.fromEntries(toPack.map(fileDep)); const deps = Object.fromEntries(targets.map(fileDep)); writeFileSync( join(scratch, 'package.json'), @@ -478,9 +454,7 @@ export async function runVerifyNpmInstall(args: string[], rootDir: string): Prom const failures = curatedDuplicates.filter((duplicate) => !duplicate.allowed); const explained = attributed.filter((dup) => failures.some((f) => f.name === dup.name)); - const nonCurated = duplicates.filter( - (d) => !d.isCurated && d.name !== NPM_INSTALL_EXCLUSION_REPLACEMENT, - ); + const nonCurated = duplicates.filter((d) => !d.isCurated); if (nonCurated.length > 0) { groupStart(`Other duplicated packages (report-only, NOT enforced — ${nonCurated.length})`); for (const d of nonCurated) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5eca311a3c9..b583f967109 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -344,21 +344,9 @@ catalogs: '@napi-rs/canvas': specifier: 1.0.11 version: 1.0.11 - '@napi-rs/canvas-linux-arm64-musl': - specifier: 1.0.11 - version: 1.0.11 - '@napi-rs/canvas-linux-x64-musl': - specifier: 1.0.11 - version: 1.0.11 '@napi-rs/image': specifier: 1.15.0 version: 1.15.0 - '@napi-rs/image-linux-arm64-musl': - specifier: 1.15.0 - version: 1.15.0 - '@napi-rs/image-linux-x64-musl': - specifier: 1.15.0 - version: 1.15.0 '@openrouter/ai-sdk-provider': specifier: ^3.0.0 version: 3.0.0 @@ -8476,21 +8464,9 @@ importers: '@napi-rs/canvas': specifier: 'catalog:' version: 1.0.11 - '@napi-rs/canvas-linux-arm64-musl': - specifier: 'catalog:' - version: 1.0.11 - '@napi-rs/canvas-linux-x64-musl': - specifier: 'catalog:' - version: 1.0.11 '@napi-rs/image': specifier: 'catalog:' version: 1.15.0 - '@napi-rs/image-linux-arm64-musl': - specifier: 'catalog:' - version: 1.15.0 - '@napi-rs/image-linux-x64-musl': - specifier: 'catalog:' - version: 1.15.0 '@smithy/node-http-handler': specifier: 4.5.0 version: 4.5.0 @@ -29881,7 +29857,8 @@ snapshots: '@napi-rs/canvas-linux-arm64-gnu@1.0.11': optional: true - '@napi-rs/canvas-linux-arm64-musl@1.0.11': {} + '@napi-rs/canvas-linux-arm64-musl@1.0.11': + optional: true '@napi-rs/canvas-linux-riscv64-gnu@1.0.11': optional: true @@ -29889,7 +29866,8 @@ snapshots: '@napi-rs/canvas-linux-x64-gnu@1.0.11': optional: true - '@napi-rs/canvas-linux-x64-musl@1.0.11': {} + '@napi-rs/canvas-linux-x64-musl@1.0.11': + optional: true '@napi-rs/canvas-win32-arm64-msvc@1.0.11': optional: true @@ -29929,12 +29907,14 @@ snapshots: '@napi-rs/image-linux-arm64-gnu@1.15.0': optional: true - '@napi-rs/image-linux-arm64-musl@1.15.0': {} + '@napi-rs/image-linux-arm64-musl@1.15.0': + optional: true '@napi-rs/image-linux-x64-gnu@1.15.0': optional: true - '@napi-rs/image-linux-x64-musl@1.15.0': {} + '@napi-rs/image-linux-x64-musl@1.15.0': + optional: true '@napi-rs/image-win32-arm64-msvc@1.15.0': optional: true diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 8414371cf42..b1e36f6ecc1 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -121,11 +121,7 @@ catalog: '@mozilla/readability': ^0.6.0 '@n8n_io/ai-assistant-sdk': 1.27.0 '@napi-rs/canvas': 1.0.11 - '@napi-rs/canvas-linux-arm64-musl': 1.0.11 - '@napi-rs/canvas-linux-x64-musl': 1.0.11 '@napi-rs/image': 1.15.0 - '@napi-rs/image-linux-arm64-musl': 1.15.0 - '@napi-rs/image-linux-x64-musl': 1.15.0 '@openrouter/ai-sdk-provider': ^3.0.0 '@opentelemetry/api': 1.9.1 '@opentelemetry/sdk-trace-base': 2.10.0 diff --git a/scripts/build-n8n.mjs b/scripts/build-n8n.mjs index 22cec67c773..c095a33b73c 100755 --- a/scripts/build-n8n.mjs +++ b/scripts/build-n8n.mjs @@ -8,7 +8,7 @@ * 4. Create a pruned production deployment in 'compiled' */ -import { $, echo, fs, chalk } from 'zx'; +import { $, echo, fs, chalk, YAML } from 'zx'; import path from 'path'; import os from 'os'; @@ -239,6 +239,59 @@ try { await verifyNoPnpmIntermediateLinks(config.compiledAppDir); await removePnpmDeployFiles(config.compiledAppDir); + // The napi-rs wrappers list their native bindings as optional dependencies, so + // `--no-optional` drops them. They cannot be regular dependencies of a published + // package: npm rejects every binding that does not match the host. Add the musl + // bindings for both image architectures, because the build host does not always + // match the image platform. The wrapper pins the exact version it loads, and the + // tarball must match the integrity that pnpm-lock.yaml records for that version. + // The bindings go to the top-level node_modules: the wrapper finds them there, and + // cdxgen inventories only that level for the release SBOM. + echo(chalk.yellow('INFO: Adding musl bindings for @napi-rs/canvas and @napi-rs/image...')); + // pnpm-lock.yaml holds two documents: pnpm's own install, then the workspace. + const lockfilePackages = Object.assign( + {}, + ...YAML.parseAllDocuments( + await fs.readFile(path.join(config.rootDir, 'pnpm-lock.yaml'), 'utf8'), + ).map((doc) => doc.toJS()?.packages), + ); + const virtualStoreDir = path.join(config.compiledAppDir, 'node_modules/.pnpm'); + const scopeDir = path.join(config.compiledAppDir, 'node_modules/@napi-rs'); + const bindingTarballDir = await fs.mkdtemp(path.join(os.tmpdir(), 'n8n-napi-bindings-')); + for (const name of ['canvas', 'image']) { + const entries = (await fs.readdir(virtualStoreDir)).filter((e) => + e.startsWith(`@napi-rs+${name}@`), + ); + // One top-level directory per binding holds one version only. + if (entries.length !== 1) { + throw new Error(`Expected one @napi-rs/${name} in the closure, found ${entries.length}`); + } + const { optionalDependencies } = await fs.readJson( + path.join(virtualStoreDir, entries[0], 'node_modules/@napi-rs', name, 'package.json'), + ); + for (const arch of ['x64', 'arm64']) { + const binding = `@napi-rs/${name}-linux-${arch}-musl`; + const version = optionalDependencies[binding]; + if (!version) throw new Error(`@napi-rs/${name} does not list ${binding}`); + + const expected = lockfilePackages[`${binding}@${version}`]?.resolution?.integrity; + if (!expected) throw new Error(`pnpm-lock.yaml has no integrity for ${binding}@${version}`); + + const [{ filename, integrity }] = JSON.parse( + (await $`npm pack ${binding}@${version} --pack-destination ${bindingTarballDir} --json`) + .stdout, + ); + if (integrity !== expected) { + throw new Error(`${binding}@${version} does not match the pnpm-lock.yaml integrity`); + } + const bindingDir = path.join(scopeDir, `${name}-linux-${arch}-musl`); + await fs.ensureDir(bindingDir); + await $`tar -xzf ${path.join(bindingTarballDir, filename)} -C ${bindingDir} --strip-components=1`; + } + } + await fs.remove(bindingTarballDir); + echo(chalk.green('✅ musl bindings added')); + // Strip test/example/benchmark dirs shipped inside production deps that lack a // `files` field in their package.json. These are valid runtime deps but their // authors published full source trees; syft inventories the subdirs as phantom @@ -422,6 +475,11 @@ try { '*agent-browser/bin/*linux-musl*', // The launcher that package.json's `bin` resolves to. '*agent-browser/bin/agent-browser.js', + // Edit Image v2 fails without these. + '*/@napi-rs/canvas-linux-x64-musl/*.node', + '*/@napi-rs/canvas-linux-arm64-musl/*.node', + '*/@napi-rs/image-linux-x64-musl/*.node', + '*/@napi-rs/image-linux-arm64-musl/*.node', ]; echo(chalk.yellow('INFO: Verifying Runtime assets'));