Skip to content

Commit f34a289

Browse files
authored
feat: automate bundled dependency license aggregation for npm releases (#790)
Add a shared rolldown plugin (`scripts/generate-license.ts`) that scans chunk moduleIds to identify bundled node_modules packages, reads their license info, and generates LICENSE.md matching Vite's format. Integrated into all three published packages (cli, core, test) with post-build validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Medium risk because it changes the build pipeline for all published packages and can fail releases if dependency resolution/scanning misses packages or can’t locate license files (especially across pnpm layouts). No runtime code paths are modified. > > **Overview** > Adds a shared `scripts/generate-license.ts` utility that scans built artifacts for `//#region ...node_modules...` markers, resolves referenced packages (including pnpm store layouts), reads their metadata/license texts, and emits a Vite-style aggregated `LICENSE.md`. > > Integrates this generator into the `cli`, `core`, and `test` build scripts (with package-specific `bundledPaths`, `resolveFrom`, and `extraPackages`), updates `.gitignore` to ignore generated `LICENSE.md`, and makes builds fail if the license file isn’t produced. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0ab46c8. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 377631f commit f34a289

6 files changed

Lines changed: 602 additions & 0 deletions

File tree

packages/cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/npm
22
/artifacts
33
/LICENSE
4+
/LICENSE.md
45
/skills/vite-plus/docs

packages/cli/build.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
ModuleKind,
3838
} from 'typescript';
3939

40+
import { generateLicenseFile } from '../../scripts/generate-license.ts';
41+
4042
const projectDir = dirname(fileURLToPath(import.meta.url));
4143
const TEST_PACKAGE_NAME = '@voidzero-dev/vite-plus-test';
4244
const CORE_PACKAGE_NAME = '@voidzero-dev/vite-plus-core';
@@ -59,6 +61,17 @@ const napiArgs = process.argv
5961
if (!skipTs) {
6062
await buildCli();
6163
buildGlobalModules();
64+
generateLicenseFile({
65+
title: 'Vite-Plus CLI license',
66+
packageName: 'Vite-Plus',
67+
outputPath: join(projectDir, 'LICENSE.md'),
68+
coreLicensePath: join(projectDir, '..', '..', 'LICENSE'),
69+
bundledPaths: [join(projectDir, 'dist', 'global')],
70+
resolveFrom: [projectDir],
71+
});
72+
if (!existsSync(join(projectDir, 'LICENSE.md'))) {
73+
throw new Error('LICENSE.md was not generated during build');
74+
}
6275
}
6376
// Build native first - TypeScript may depend on the generated binding types
6477
if (!skipNative) {

packages/core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/LICENSE
2+
/LICENSE.md

packages/core/build.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { build, type BuildOptions } from 'rolldown';
1515
import { dts } from 'rolldown-plugin-dts';
1616
import { glob } from 'tinyglobby';
1717

18+
import { generateLicenseFile } from '../../scripts/generate-license.ts';
1819
import { buildCjsDeps } from './build-support/build-cjs-deps';
1920
import { replaceThirdPartyCjsRequires } from './build-support/find-create-require';
2021
import { RewriteImportsPlugin } from './build-support/rewrite-imports';
@@ -51,6 +52,41 @@ await buildVite();
5152
await bundleTsdown();
5253
await brandTsdown();
5354
await bundleVitepress();
55+
generateLicenseFile({
56+
title: 'Vite-Plus core license',
57+
packageName: 'Vite-Plus',
58+
outputPath: join(projectDir, 'LICENSE.md'),
59+
coreLicensePath: join(projectDir, '..', '..', 'LICENSE'),
60+
bundledPaths: [join(projectDir, 'dist')],
61+
resolveFrom: [
62+
projectDir,
63+
join(projectDir, '..', '..'),
64+
join(projectDir, '..', '..', 'rolldown'),
65+
join(projectDir, '..', '..', 'rolldown-vite'),
66+
],
67+
extraPackages: [
68+
{
69+
packageDir: rolldownSourceDir,
70+
licensePath: join(projectDir, '..', '..', 'rolldown', 'LICENSE'),
71+
},
72+
{
73+
packageDir: rolldownPluginUtilsDir,
74+
licensePath: join(projectDir, '..', '..', 'rolldown', 'LICENSE'),
75+
},
76+
{
77+
packageDir: rolldownViteSourceDir,
78+
},
79+
{
80+
packageDir: tsdownSourceDir,
81+
},
82+
{
83+
packageDir: join(projectDir, '..', '..', 'node_modules', 'vitepress'),
84+
},
85+
],
86+
});
87+
if (!existsSync(join(projectDir, 'LICENSE.md'))) {
88+
throw new Error('LICENSE.md was not generated during build');
89+
}
5490
await mergePackageJson();
5591
await syncLicenseFromRoot();
5692

packages/test/build.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
// - BUNDLE only leaf deps (chai, etc.) to reduce install size
3737
// - Separate entries prevent __vite__injectQuery errors in browser
3838

39+
import { existsSync } from 'node:fs';
3940
import {
4041
copyFile,
4142
glob as fsGlob,
@@ -55,6 +56,7 @@ import { format } from 'oxfmt';
5556
import { build } from 'rolldown';
5657
import { dts } from 'rolldown-plugin-dts';
5758

59+
import { generateLicenseFile } from '../../scripts/generate-license.ts';
5860
import pkg from './package.json' with { type: 'json' };
5961

6062
const projectDir = dirname(fileURLToPath(import.meta.url));
@@ -222,6 +224,23 @@ await patchChaiTypeReference();
222224
await patchMockerHoistedModule();
223225
const pluginExports = await createPluginExports();
224226
await mergePackageJson(pluginExports);
227+
generateLicenseFile({
228+
title: 'Vite-Plus test license',
229+
packageName: 'Vite-Plus',
230+
outputPath: join(projectDir, 'LICENSE.md'),
231+
coreLicensePath: join(projectDir, '..', '..', 'LICENSE'),
232+
bundledPaths: [distDir],
233+
resolveFrom: [projectDir, join(projectDir, '..', '..')],
234+
extraPackages: [
235+
{ packageDir: vitestSourceDir },
236+
...VITEST_PACKAGES_TO_COPY.map((packageName) => ({
237+
packageDir: resolve(projectDir, 'node_modules', packageName),
238+
})),
239+
],
240+
});
241+
if (!existsSync(join(projectDir, 'LICENSE.md'))) {
242+
throw new Error('LICENSE.md was not generated during build');
243+
}
225244
await syncLicenseFromRoot();
226245
await validateExternalDeps();
227246

0 commit comments

Comments
 (0)