Skip to content

Commit ab2afe3

Browse files
committed
fix(scripts): count react-native and an index.js behind an empty main
A package whose only entry is `react-native`, or one with an empty `main` and an index.js, ships code and has to keep its notice.
1 parent 6709821 commit ab2afe3

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎scripts/lib/third-party-licenses.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,16 @@ describe("third-party license generation", () => {
251251
main: "./dist/index.mjs",
252252
exports: { ".": { types: "./dist/index.d.mts", import: "./dist/index.mjs" } },
253253
},
254+
hasIndexJs: false,
254255
},
255-
{ shape: "only a stylesheet", entry: { main: "", style: "dist/theme.css" } },
256-
])("keeps a package that declares types but ships $shape", async ({ entry }) => {
256+
{ shape: "only a stylesheet", entry: { main: "", style: "dist/theme.css" }, hasIndexJs: false },
257+
{
258+
shape: "only a react-native entry",
259+
entry: { main: "", "react-native": "lib/index.native.js" },
260+
hasIndexJs: false,
261+
},
262+
{ shape: "an index.js behind an empty main", entry: { main: "" }, hasIndexJs: true },
263+
])("keeps a package that declares types but ships $shape", async ({ entry, hasIndexJs }) => {
257264
const fixture = await createFixture();
258265
await writeJson(NodePath.join(fixture.dependencyRoot, "package.json"), {
259266
name: "demo-dependency",
@@ -263,6 +270,7 @@ describe("third-party license generation", () => {
263270
...entry,
264271
repository: "example/demo-dependency",
265272
});
273+
if (!hasIndexJs) await NodeFSP.rm(NodePath.join(fixture.dependencyRoot, "index.js"));
266274

267275
const manifest = await generateThirdPartyLicenseManifest({
268276
configFile: fixture.configFile,

‎scripts/lib/third-party-licenses.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interface PackageJson {
5656
readonly module?: unknown;
5757
readonly name?: unknown;
5858
readonly optionalDependencies?: Readonly<Record<string, string>>;
59+
readonly "react-native"?: unknown;
5960
readonly repository?: unknown;
6061
readonly sass?: unknown;
6162
readonly style?: unknown;
@@ -573,15 +574,16 @@ async function isTypeOnlyPackage(packageJson: PackageJson, packageRoot: string):
573574
packageJson.main,
574575
packageJson.module,
575576
packageJson.browser,
577+
packageJson["react-native"],
576578
packageJson.bin,
577579
packageJson.style,
578580
packageJson.sass,
579581
];
580582
if (entries.some(isDeclared) || targets.some((target) => !isTypeDeclaration(target))) {
581583
return false;
582584
}
583-
// Without `main` or `exports`, Node still loads the package's index.js.
584-
return packageJson.main !== undefined || packageJson.exports !== undefined
585+
// Without `exports`, Node still loads the package's index.js, an empty `main` included.
586+
return packageJson.exports !== undefined && packageJson.exports !== null
585587
? true
586588
: !(await fileExists(NodePath.join(packageRoot, "index.js")));
587589
}

0 commit comments

Comments
 (0)