diff --git a/.changeset/ignore-native-addons.md b/.changeset/ignore-native-addons.md new file mode 100644 index 0000000..e15d4ed --- /dev/null +++ b/.changeset/ignore-native-addons.md @@ -0,0 +1,5 @@ +--- +"@arethetypeswrong/core": patch +--- + +Ignore native Node.js addon (`.node`) files during package analysis. diff --git a/packages/core/src/createPackage.ts b/packages/core/src/createPackage.ts index 5d0864e..f323e29 100644 --- a/packages/core/src/createPackage.ts +++ b/packages/core/src/createPackage.ts @@ -22,7 +22,11 @@ export class Package { resolvedUrl?: string, typesPackage?: Package["typesPackage"], ) { - this.#files = files; + for (const path in files) { + if (!path.endsWith(".node")) { + this.#files[path] = files[path]; + } + } this.packageName = packageName; this.packageVersion = packageVersion; this.resolvedUrl = resolvedUrl; diff --git a/packages/core/test/createPackage.test.ts b/packages/core/test/createPackage.test.ts new file mode 100644 index 0000000..736b750 --- /dev/null +++ b/packages/core/test/createPackage.test.ts @@ -0,0 +1,36 @@ +import assert from "node:assert"; +import { describe, test } from "node:test"; +import { checkPackage, Package } from "@arethetypeswrong/core"; + +describe("Package", () => { + test("ignores native addons without affecting package analysis", async () => { + const packageRoot = "/node_modules/test"; + const files = { + [`${packageRoot}/package.json`]: JSON.stringify({ + name: "test", + version: "1.0.0", + main: "index.js", + types: "index.d.ts", + }), + [`${packageRoot}/index.js`]: "exports.answer = 42;", + [`${packageRoot}/index.d.ts`]: "export declare const answer: number;", + [`${packageRoot}/loader.node.js`]: "export const loadsNativeAddon = true;", + }; + const packageWithoutNativeAddon = new Package(files, "test", "1.0.0"); + const packageWithNativeAddon = new Package( + { + ...files, + [`${packageRoot}/build/Release/addon.node`]: new Uint8Array([0, 1, 2, 3]), + }, + "test", + "1.0.0", + ); + + assert.strictEqual(packageWithNativeAddon.fileExists(`${packageRoot}/build/Release/addon.node`), false); + assert.deepStrictEqual(packageWithNativeAddon.listFiles(), packageWithoutNativeAddon.listFiles()); + for (const path of Object.keys(files)) { + assert.strictEqual(packageWithNativeAddon.readFile(path), packageWithoutNativeAddon.readFile(path)); + } + assert.deepStrictEqual(await checkPackage(packageWithNativeAddon), await checkPackage(packageWithoutNativeAddon)); + }); +});