Skip to content

Commit 1abf368

Browse files
t3dotggclaude
andauthored
fix(build): builds no longer fail when GitHub's CDN times out on license templates (pingdotgg#26440)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 96a330c commit 1abf368

12 files changed

Lines changed: 76 additions & 94 deletions

File tree

‎apps/mobile/metro.config.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ async function generateMobileThirdPartyLicenses() {
5656
const manifest = await generateThirdPartyLicenseManifest({
5757
configFile: path.join(workspaceRoot, "third-party-licenses.config.json"),
5858
packageManifests: [{ bundle: "mobile", path: path.join(__dirname, "package.json") }],
59-
allowMissingGeneratedNotices:
60-
process.env.NODE_ENV !== "production" &&
61-
process.env.EAS_BUILD !== "true" &&
62-
process.env.T3CODE_LICENSES_STRICT !== "1",
6359
});
6460

6561
await Promise.all([

‎docs/internals/open-source-licenses.md‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ Expo and React Native. That is conservative and can include build tooling that i
2525
the final JavaScript bundle, but it avoids dropping a notice when platform bundling changes.
2626

2727
The build fails when a collected package has no distributable license identifier or contains no
28-
license or notice text. Generated notices use license templates from the pinned SPDX License List.
29-
Strict web and EAS builds download a missing template into the gitignored `.generated/` cache;
30-
`pnpm licenses:sync` can warm that cache explicitly. Local web and Metro development do not make a
31-
network request and omit generated rows until the cache exists. This keeps dev startup optional
32-
while preventing incomplete release artifacts.
28+
license or notice text. Generated notices use license templates from the pinned SPDX License List,
29+
committed under `third-party-licenses/spdx/`. Builds never fetch them, so a network blip cannot
30+
fail a build. A build fails when a configured template is missing; run `vp run licenses:sync` to
31+
download it, then commit the new file.
3332

3433
## Custom notices and package overrides
3534

@@ -103,6 +102,5 @@ The `@react-grab/cli` override uses the root React Grab repository's MIT license
103102
npm archive omits both its license field and license file. Keep the override until the published
104103
CLI package carries that metadata itself.
105104

106-
Generated mobile files live under `apps/mobile/.generated/`, while fetched SPDX templates live
107-
under the repository `.generated/` directory. Both are ignored. Do not commit or edit them;
108-
updating dependencies or configuration is enough for the next strict build to refresh the output.
105+
Generated mobile files live under `apps/mobile/.generated/` and are ignored. Do not commit or edit
106+
them; updating dependencies or configuration is enough for the next build to refresh the output.

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,12 @@ describe("third-party license generation", () => {
161161
});
162162
});
163163

164-
it("renders generated notices from the ignored SPDX cache", async () => {
164+
it("renders generated notices from the committed SPDX templates", async () => {
165165
const fixture = await createFixture();
166-
await writeJson(
167-
NodePath.join(fixture.root, ".generated/third-party-licenses/spdx/v3.28.0/MIT.json"),
168-
{
169-
licenseId: "MIT",
170-
licenseText: "MIT License\n\nCopyright (c) <year> <copyright holders>\n\nPermission text",
171-
},
172-
);
166+
await writeJson(NodePath.join(fixture.root, "third-party-licenses/spdx/v3.28.0/MIT.json"), {
167+
licenseId: "MIT",
168+
licenseText: "MIT License\n\nCopyright (c) <year> <copyright holders>\n\nPermission text",
169+
});
173170
await writeJson(fixture.configFile, {
174171
customNotices: [
175172
{
@@ -364,10 +361,7 @@ describe("third-party license generation", () => {
364361
await NodeFSP.rm(NodePath.join(fixture.dependencyRoot, "LICENSE"));
365362
for (const licenseId of ["Apache-2.0", "BSD-3-Clause"]) {
366363
await writeJson(
367-
NodePath.join(
368-
fixture.root,
369-
`.generated/third-party-licenses/spdx/v3.28.0/${licenseId}.json`,
370-
),
364+
NodePath.join(fixture.root, `third-party-licenses/spdx/v3.28.0/${licenseId}.json`),
371365
{ licenseId, licenseText: `${licenseId} terms` },
372366
);
373367
}

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

Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { Plugin } from "vite-plus";
1010
const THIRD_PARTY_LICENSES_FILE_NAME = "third-party-licenses.json";
1111
const SPDX_LICENSE_LIST_VERSION = "v3.28.0";
1212
const SPDX_LICENSE_LIST_REVISION = "c4a7237ec8f4654e867546f9f409749300f1bf4c";
13-
const GENERATED_NOTICE_CACHE_DIRECTORY = ".generated/third-party-licenses/spdx";
13+
const SPDX_TEMPLATE_DIRECTORY = "third-party-licenses/spdx";
1414

1515
export interface ThirdPartyLicenseEntry {
1616
readonly bundles: ReadonlyArray<string>;
@@ -312,10 +312,10 @@ async function readConfig(configFile: string | URL | undefined): Promise<{
312312
};
313313
}
314314

315-
function spdxLicenseCachePath(configDirectory: string, licenseId: string): string {
315+
function spdxTemplatePath(configDirectory: string, licenseId: string): string {
316316
return NodePath.join(
317317
configDirectory,
318-
GENERATED_NOTICE_CACHE_DIRECTORY,
318+
SPDX_TEMPLATE_DIRECTORY,
319319
SPDX_LICENSE_LIST_VERSION,
320320
`${licenseId}.json`,
321321
);
@@ -333,12 +333,12 @@ function decodeSpdxLicenseDetails(value: unknown, expectedLicenseId: string): Sp
333333
return { licenseId: expectedLicenseId, licenseText: value.licenseText.trim() };
334334
}
335335

336-
async function readCachedSpdxLicense(
336+
async function readSpdxLicense(
337337
configDirectory: string,
338338
licenseId: string,
339339
): Promise<SpdxLicenseDetails | null> {
340340
try {
341-
const source = await NodeFSP.readFile(spdxLicenseCachePath(configDirectory, licenseId), "utf8");
341+
const source = await NodeFSP.readFile(spdxTemplatePath(configDirectory, licenseId), "utf8");
342342
return decodeSpdxLicenseDetails(JSON.parse(source) as unknown, licenseId);
343343
} catch (error) {
344344
const code = isRecord(error) && typeof error.code === "string" ? error.code : null;
@@ -347,10 +347,7 @@ async function readCachedSpdxLicense(
347347
}
348348
}
349349

350-
async function downloadSpdxLicense(
351-
configDirectory: string,
352-
licenseId: string,
353-
): Promise<SpdxLicenseDetails> {
350+
async function downloadSpdxLicense(configDirectory: string, licenseId: string): Promise<void> {
354351
const url = `https://raw.githubusercontent.com/spdx/license-list-data/${SPDX_LICENSE_LIST_REVISION}/json/details/${encodeURIComponent(licenseId)}.json`;
355352
const response = await fetch(url);
356353
if (!response.ok) {
@@ -359,20 +356,9 @@ async function downloadSpdxLicense(
359356
);
360357
}
361358
const details = decodeSpdxLicenseDetails((await response.json()) as unknown, licenseId);
362-
const cachePath = spdxLicenseCachePath(configDirectory, licenseId);
363-
await NodeFSP.mkdir(NodePath.dirname(cachePath), { recursive: true });
364-
await NodeFSP.writeFile(cachePath, `${JSON.stringify(details)}\n`, "utf8");
365-
return details;
366-
}
367-
368-
async function resolveSpdxLicense(
369-
configDirectory: string,
370-
licenseId: string,
371-
allowMissing: boolean,
372-
): Promise<SpdxLicenseDetails | null> {
373-
const cached = await readCachedSpdxLicense(configDirectory, licenseId);
374-
if (cached || allowMissing) return cached;
375-
return downloadSpdxLicense(configDirectory, licenseId);
359+
const templatePath = spdxTemplatePath(configDirectory, licenseId);
360+
await NodeFSP.mkdir(NodePath.dirname(templatePath), { recursive: true });
361+
await NodeFSP.writeFile(templatePath, `${JSON.stringify(details, null, 2)}\n`, "utf8");
376362
}
377363

378364
function renderGeneratedNotice(config: GeneratedNoticeConfigEntry, licenseText: string): string {
@@ -397,17 +383,19 @@ function renderGeneratedNotice(config: GeneratedNoticeConfigEntry, licenseText:
397383
async function generatedNoticeText(
398384
configs: ReadonlyArray<GeneratedNoticeConfigEntry>,
399385
configDirectory: string,
400-
allowMissing: boolean,
401-
): Promise<string | null> {
386+
): Promise<string> {
402387
const sections = await Promise.all(
403388
configs.map(async (config) => {
404-
const details = await resolveSpdxLicense(configDirectory, config.licenseId, allowMissing);
405-
return details ? renderGeneratedNotice(config, details.licenseText) : null;
389+
const details = await readSpdxLicense(configDirectory, config.licenseId);
390+
if (!details) {
391+
throw new Error(
392+
`SPDX license template ${config.licenseId} is missing. Run \`vp run licenses:sync\` and commit ${SPDX_TEMPLATE_DIRECTORY}.`,
393+
);
394+
}
395+
return renderGeneratedNotice(config, details.licenseText);
406396
}),
407397
);
408-
return sections.some((section) => section === null)
409-
? null
410-
: (sections as ReadonlyArray<string>).join("\n\n---\n\n");
398+
return sections.join("\n\n---\n\n");
411399
}
412400

413401
function configuredGeneratedNotices(
@@ -426,7 +414,13 @@ async function syncConfiguredGeneratedNotices(
426414
const licenseIds = [
427415
...new Set(configuredGeneratedNotices(config).map((notice) => notice.licenseId)),
428416
].sort((left, right) => left.localeCompare(right));
429-
await Promise.all(licenseIds.map((licenseId) => resolveSpdxLicense(directory, licenseId, false)));
417+
await Promise.all(
418+
licenseIds.map(async (licenseId) => {
419+
if (!(await readSpdxLicense(directory, licenseId))) {
420+
await downloadSpdxLicense(directory, licenseId);
421+
}
422+
}),
423+
);
430424
}
431425

432426
export async function syncThirdPartyLicenseNotices(configFile: string | URL): Promise<void> {
@@ -844,8 +838,7 @@ async function packageEntry(
844838
configDirectory: string,
845839
packageNotices: Map<string, Promise<string | null>>,
846840
repositoryNotices: ReadonlyMap<string, string>,
847-
allowMissingGeneratedNotices: boolean,
848-
): Promise<ThirdPartyLicenseEntry | null> {
841+
): Promise<ThirdPartyLicenseEntry> {
849842
const name =
850843
typeof collected.packageJson.name === "string"
851844
? collected.packageJson.name
@@ -867,19 +860,14 @@ async function packageEntry(
867860

868861
const repositoryKey = repositoryNoticeKey(collected.packageJson, license);
869862
const noticeText = override?.generatedNotices
870-
? await generatedNoticeText(
871-
override.generatedNotices,
872-
configDirectory,
873-
allowMissingGeneratedNotices,
874-
)
863+
? await generatedNoticeText(override.generatedNotices, configDirectory)
875864
: override?.noticeFile
876865
? (
877866
await NodeFSP.readFile(NodePath.resolve(configDirectory, override.noticeFile), "utf8")
878867
).trim()
879868
: ((await packageNoticeText(collected.packageRoot, packageNotices)) ??
880869
(repositoryKey ? repositoryNotices.get(repositoryKey) : undefined));
881870
if (!noticeText) {
882-
if (override?.generatedNotices && allowMissingGeneratedNotices) return null;
883871
throw new Error(
884872
`${name}@${version} does not include a license or notice file. Add a package override with "noticeFile" or "generatedNotice" in the third-party license config.`,
885873
);
@@ -900,7 +888,6 @@ async function customEntries(
900888
config: ThirdPartyLicensesConfig,
901889
configDirectory: string,
902890
includedBundles: ReadonlySet<string>,
903-
allowMissingGeneratedNotices: boolean,
904891
): Promise<ReadonlyArray<ThirdPartyLicenseEntry>> {
905892
const deviceToolVersions: unknown = JSON.parse(
906893
await NodeFSP.readFile(
@@ -920,11 +907,7 @@ async function customEntries(
920907
)
921908
.map(async (notice) => {
922909
const noticeText = notice.generatedNotices
923-
? await generatedNoticeText(
924-
notice.generatedNotices,
925-
configDirectory,
926-
allowMissingGeneratedNotices,
927-
)
910+
? await generatedNoticeText(notice.generatedNotices, configDirectory)
928911
: (
929912
await Promise.all(
930913
notice.noticeFiles!.map(async (noticeFile) => {
@@ -938,10 +921,6 @@ async function customEntries(
938921
}),
939922
)
940923
).join("\n\n---\n\n");
941-
if (noticeText === null) {
942-
if (allowMissingGeneratedNotices) return null;
943-
throw new Error(`Could not generate custom third-party notice "${notice.name}".`);
944-
}
945924
if (noticeText.length === 0) {
946925
throw new Error(`Custom third-party notice "${notice.name}" is empty.`);
947926
}
@@ -961,7 +940,7 @@ async function customEntries(
961940
};
962941
}),
963942
);
964-
return entries.flatMap((entry) => (entry ? [entry] : []));
943+
return entries;
965944
}
966945

967946
function entrySort(left: ThirdPartyLicenseEntry, right: ThirdPartyLicenseEntry): number {
@@ -990,15 +969,11 @@ export async function generateThirdPartyLicenseManifest(input: {
990969
readonly packageManifests: ReadonlyArray<ThirdPartyLicensePackageManifest>;
991970
readonly bundledModuleIds?: ReadonlyArray<string>;
992971
readonly bundleName?: string;
993-
readonly allowMissingGeneratedNotices?: boolean;
994972
}): Promise<ThirdPartyLicenseManifest> {
995973
const [{ config, directory }, collection] = await Promise.all([
996974
readConfig(input.configFile),
997975
collectProductionDependencyPackages(input.packageManifests),
998976
]);
999-
if (!(input.allowMissingGeneratedNotices ?? false)) {
1000-
await syncConfiguredGeneratedNotices(config, directory);
1001-
}
1002977
if (input.bundledModuleIds && input.bundleName) {
1003978
await addBundledModulePackages(collection, input.bundledModuleIds, input.bundleName);
1004979
}
@@ -1008,14 +983,7 @@ export async function generateThirdPartyLicenseManifest(input: {
1008983

1009984
const packageEntryResults = await Promise.allSettled(
1010985
[...collection.byIdentity.values()].map((collected) =>
1011-
packageEntry(
1012-
collected,
1013-
config,
1014-
directory,
1015-
packageNotices,
1016-
repositoryNotices,
1017-
input.allowMissingGeneratedNotices ?? false,
1018-
),
986+
packageEntry(collected, config, directory, packageNotices, repositoryNotices),
1019987
),
1020988
);
1021989
const failures = packageEntryResults.flatMap((result) =>
@@ -1029,16 +997,11 @@ export async function generateThirdPartyLicenseManifest(input: {
1029997
);
1030998
}
1031999
const packageEntries = packageEntryResults.flatMap((result) =>
1032-
result.status === "fulfilled" && result.value ? [result.value] : [],
1000+
result.status === "fulfilled" ? [result.value] : [],
10331001
);
10341002
const includedBundles = new Set(input.packageManifests.map((manifest) => manifest.bundle));
10351003
if (input.bundleName) includedBundles.add(input.bundleName);
1036-
const manualEntries = await customEntries(
1037-
config,
1038-
directory,
1039-
includedBundles,
1040-
input.allowMissingGeneratedNotices ?? false,
1041-
);
1004+
const manualEntries = await customEntries(config, directory, includedBundles);
10421005
const entries = [...packageEntries, ...manualEntries].sort(entrySort);
10431006
assertUniqueEntries(entries);
10441007
return {
@@ -1074,7 +1037,6 @@ export function thirdPartyLicensesPlugin(options: ThirdPartyLicensesPluginOption
10741037
manifestPromise ??= generateThirdPartyLicenseManifest({
10751038
packageManifests: options.packageManifests,
10761039
bundleName: options.bundleName,
1077-
allowMissingGeneratedNotices: true,
10781040
...(options.configFile !== undefined ? { configFile: options.configFile } : {}),
10791041
}).catch((error: unknown) => {
10801042
manifestPromise = null;

0 commit comments

Comments
 (0)