Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ignore-native-addons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arethetypeswrong/core": patch
---

Ignore native Node.js addon (`.node`) files during package analysis.
6 changes: 5 additions & 1 deletion packages/core/src/createPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions packages/core/test/createPackage.test.ts
Original file line number Diff line number Diff line change
@@ -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));
});
});