@devries-cameron20 / t3code-1 / commits / 972e39266a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(scripts): leave type-only packages out of third-party notices (#14627)

Leonel Rivas committed Oct 18, 2026 at 12:28 UTC 972e39266a7059225c41a5b73f781c692e68c79a
2 files changed +169 -1
scripts/lib/third-party-licenses.test.ts
+84
@@ -330,6 +330,90 @@ describe("third-party license generation", () => {
330 expect(manifest.entries.some((entry) => entry.name === "demo-dependency")).toBe(true);
331 });
332
333 + it("leaves type-only packages out of the notices but still walks their dependencies", async () => {
334 + const fixture = await createFixture();
335 + const modules = NodePath.join(fixture.root, "node_modules");
336 + const write = async (name: string, packageJson: Record<string, unknown>) => {
337 + await writeJson(NodePath.join(modules, name, "package.json"), {
338 + name,
339 + version: "1.0.0",
340 + license: "MIT",
341 + ...packageJson,
342 + });
343 + await NodeFSP.writeFile(NodePath.join(modules, name, "LICENSE"), `${name} license\n`, "utf8");
344 + };
345 + await writeJson(fixture.appManifest, {
346 + name: "fixture-app",
347 + dependencies: { "demo-dependency": "1.2.3", "@types/demo": "1.0.0" },
348 + });
349 + // The DefinitelyTyped shape, and the csstype / undici-types one it pulls in.
350 + await write("@types/demo", {
351 + main: "",
352 + types: "index.d.ts",
353 + exports: {
354 + ".": { types: { import: "./index.d.mts", default: "./index.d.ts" } },
355 + "./package.json": "./package.json",
356 + },
357 + dependencies: { "demo-css-types": "1.0.0", "demo-runtime": "1.0.0" },
358 + });
359 + await write("demo-css-types", { main: "", types: "index.d.ts" });
360 + await write("demo-runtime", { main: "index.js" });
361 +
362 + const manifest = await generateThirdPartyLicenseManifest({
363 + configFile: fixture.configFile,
364 + packageManifests: [{ bundle: "web", path: fixture.appManifest }],
365 + });
366 +
367 + const names = manifest.entries.map((entry) => entry.name);
368 + expect(names).toContain("demo-dependency");
369 + expect(names).toContain("demo-runtime");
370 + expect(names).not.toContain("@types/demo");
371 + expect(names).not.toContain("demo-css-types");
372 + });
373 +
374 + it.each([
375 + {
376 + shape: "a JS entry next to its declarations",
377 + // The @shikijs/types shape: a types condition next to a real JS entry.
378 + entry: {
379 + main: "./dist/index.mjs",
380 + exports: { ".": { types: "./dist/index.d.mts", import: "./dist/index.mjs" } },
381 + },
382 + indexFile: null,
383 + },
384 + { shape: "only a stylesheet", entry: { main: "", style: "dist/theme.css" }, indexFile: null },
385 + {
386 + shape: "only a react-native entry",
387 + entry: { main: "", "react-native": "lib/index.native.js" },
388 + indexFile: null,
389 + },
390 + { shape: "an index.js behind an empty main", entry: { main: "" }, indexFile: "index.js" },
391 + { shape: "an index.node addon and no main", entry: {}, indexFile: "index.node" },
392 + ])("keeps a package that declares types but ships $shape", async ({ entry, indexFile }) => {
393 + const fixture = await createFixture();
394 + await writeJson(NodePath.join(fixture.dependencyRoot, "package.json"), {
395 + name: "demo-dependency",
396 + version: "1.2.3",
397 + license: "MIT",
398 + types: "./dist/index.d.mts",
399 + ...entry,
400 + repository: "example/demo-dependency",
401 + });
402 + if (indexFile !== "index.js") {
403 + await NodeFSP.rm(NodePath.join(fixture.dependencyRoot, "index.js"));
404 + }
405 + if (indexFile !== null) {
406 + await NodeFSP.writeFile(NodePath.join(fixture.dependencyRoot, indexFile), "", "utf8");
407 + }
408 +
409 + const manifest = await generateThirdPartyLicenseManifest({
410 + configFile: fixture.configFile,
411 + packageManifests: [{ bundle: "web", path: fixture.appManifest }],
412 + });
413 +
414 + expect(manifest.entries.some((entry) => entry.name === "demo-dependency")).toBe(true);
415 + });
416 +
417 it("includes custom notices selected by the dev server bundle", async () => {
418 const fixture = await createFixture();
419 await writeJson(fixture.configFile, {
scripts/lib/third-party-licenses.ts
+85 -1
@@ -45,13 +45,23 @@ interface GeneratedNoticeConfigEntry {
45 }
46
47 interface PackageJson {
48 + readonly bin?: unknown;
49 + readonly browser?: unknown;
50 readonly dependencies?: Readonly<Record<string, string>>;
51 + readonly exports?: unknown;
52 readonly homepage?: unknown;
53 readonly license?: unknown;
54 readonly licenses?: unknown;
55 + readonly main?: unknown;
56 + readonly module?: unknown;
57 readonly name?: unknown;
58 readonly optionalDependencies?: Readonly<Record<string, string>>;
59 + readonly "react-native"?: unknown;
60 readonly repository?: unknown;
61 + readonly sass?: unknown;
62 + readonly style?: unknown;
63 + readonly types?: unknown;
64 + readonly typings?: unknown;
65 readonly version?: unknown;
66 }
67
@@ -510,6 +520,76 @@ function dependencyNames(packageJson: PackageJson): ReadonlyArray<string> {
520 ].sort((left, right) => left.localeCompare(right));
521 }
522
523 +interface ExportTarget {
524 + readonly path: string;
525 + readonly underTypesCondition: boolean;
526 +}
527 +
528 +function exportTargets(value: unknown, underTypesCondition = false): ReadonlyArray<ExportTarget> {
529 + if (typeof value === "string") return [{ path: value, underTypesCondition }];
530 + if (Array.isArray(value))
531 + return value.flatMap((item) => exportTargets(item, underTypesCondition));
532 + if (value === null || typeof value !== "object") return [];
533 + return Object.entries(value).flatMap(([key, item]) =>
534 + exportTargets(item, underTypesCondition || key.startsWith("types") || key === "typings"),
535 + );
536 +}
537 +
538 +/** Declarations, or the package's own manifest that many packages also export. Neither is code. */
539 +function isTypeDeclaration(target: ExportTarget): boolean {
540 + return (
541 + target.underTypesCondition ||
542 + /\.d\.[cm]?ts$/u.test(target.path) ||
543 + target.path === "./package.json"
544 + );
545 +}
546 +
547 +function isDeclared(value: unknown): boolean {
548 + if (typeof value === "string") return value.trim() !== "";
549 + return value !== null && typeof value === "object" && Object.keys(value).length > 0;
550 +}
551 +
552 +async function fileExists(path: string): Promise<boolean> {
553 + try {
554 + await NodeFSP.access(path);
555 + return true;
556 + } catch {
557 + return false;
558 + }
559 +}
560 +
561 +/**
562 + * A package that only describes types (DefinitelyTyped, csstype, undici-types): it declares types
563 + * and has no JS entry, so nothing of it ships. A types condition or a name with "types" in it is not
564 + * enough on its own: `@shikijs/types` exports real code next to its declarations.
565 + */
566 +async function isTypeOnlyPackage(packageJson: PackageJson, packageRoot: string): Promise<boolean> {
567 + const targets = exportTargets(packageJson.exports);
568 + const declaresTypes =
569 + isDeclared(packageJson.types) ||
570 + isDeclared(packageJson.typings) ||
571 + targets.some(isTypeDeclaration);
572 + if (!declaresTypes) return false;
573 + const entries = [
574 + packageJson.main,
575 + packageJson.module,
576 + packageJson.browser,
577 + packageJson["react-native"],
578 + packageJson.bin,
579 + packageJson.style,
580 + packageJson.sass,
581 + ];
582 + if (entries.some(isDeclared) || targets.some((target) => !isTypeDeclaration(target))) {
583 + return false;
584 + }
585 + // Without `exports`, Node still loads the package's index file, an empty `main` included.
586 + if (packageJson.exports !== undefined && packageJson.exports !== null) return true;
587 + for (const indexFile of ["index.js", "index.json", "index.node"]) {
588 + if (await fileExists(NodePath.join(packageRoot, indexFile))) return false;
589 + }
590 + return true;
591 +}
592 +
593 async function collectProductionDependencyPackages(
594 packageManifests: ReadonlyArray<ThirdPartyLicensePackageManifest>,
595 ): Promise<PackageCollection> {
@@ -530,7 +610,11 @@ async function collectProductionDependencyPackages(
610 const dependencyPackageJsonPath = NodePath.join(resolved.packageRoot, "package.json");
611 const name =
612 typeof resolved.packageJson.name === "string" ? resolved.packageJson.name : dependencyName;
533 - if (!name.startsWith(FIRST_PARTY_PACKAGE_PREFIX)) {
613 + // Type-only packages ship nothing, but what they depend on may, so the walk goes on below.
614 + if (
615 + !name.startsWith(FIRST_PARTY_PACKAGE_PREFIX) &&
616 + !(await isTypeOnlyPackage(resolved.packageJson, resolved.packageRoot))
617 + ) {
618 const identity = packageIdentity(resolved.packageJson, resolved.packageRoot);
619 const existing = collection.byIdentity.get(identity);
620 if (existing) {