@vitus-labs/tools-rolldown 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/lib/bin/run-build.js +0 -0
- package/lib/bin/run-watch.js +0 -0
- package/lib/rolldown/config.js +47 -6
- package/lib/rolldown/config.js.map +1 -1
- package/lib/rolldown/createBuildPipeline.js +62 -33
- package/lib/rolldown/createBuildPipeline.js.map +1 -1
- package/lib/rolldown/index.js +2 -2
- package/lib/rolldown/index.js.map +1 -1
- package/lib/scripts/build.js +11 -9
- package/lib/scripts/build.js.map +1 -1
- package/lib/types/rolldown/config.d.ts +9 -6
- package/lib/types/rolldown/config.d.ts.map +1 -1
- package/lib/types/rolldown/createBuildPipeline.d.ts.map +1 -1
- package/lib/types/rolldown/index.d.ts +2 -2
- package/lib/types/rolldown/index.d.ts.map +1 -1
- package/lib/types/scripts/build.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/rolldown/config.ts +54 -7
- package/src/rolldown/createBuildPipeline.test.ts +122 -3
- package/src/rolldown/createBuildPipeline.ts +70 -34
- package/src/rolldown/index.ts +2 -2
- package/src/scripts/build.test.ts +116 -39
- package/src/scripts/build.ts +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 1.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`3605125`](https://github.com/vitus-labs/tools/commit/36051255315da3d87a2a6b8d6b7ecd8cb9f718f9) Thanks [@vitbokisch](https://github.com/vitbokisch)! - **rolldown**: Auto-derive build entries from package.json subpath exports (e.g., `"./devtools"`, `"./validation/zod"`). Generates separate `.d.ts` declarations per subpath.
|
|
8
|
+
|
|
9
|
+
**vitest**: Export `DEFAULT_COVERAGE_EXCLUDE` and `DEFAULT_COVERAGE_INCLUDE` for `mergeConfig` compatibility. Add `coverageInclude` option.
|
|
10
|
+
|
|
11
|
+
**all**: Switch to `workspace:^` protocol, custom publish script with OIDC provenance.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`3605125`](https://github.com/vitus-labs/tools/commit/36051255315da3d87a2a6b8d6b7ecd8cb9f718f9)]:
|
|
16
|
+
- @vitus-labs/tools-core@1.14.0
|
|
17
|
+
|
|
3
18
|
## 1.13.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/lib/bin/run-build.js
CHANGED
|
File without changes
|
package/lib/bin/run-watch.js
CHANGED
|
File without changes
|
package/lib/rolldown/config.js
CHANGED
|
@@ -98,16 +98,13 @@ const rolldownConfig = ({ file, format, env, platform, input: entryInput, }) =>
|
|
|
98
98
|
};
|
|
99
99
|
return buildOutput;
|
|
100
100
|
};
|
|
101
|
-
const
|
|
102
|
-
const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings;
|
|
103
|
-
if (!CONFIG.typescript || !typesFilePath)
|
|
104
|
-
return null;
|
|
101
|
+
const createDtsConfig = (typesFilePath, inputFile) => {
|
|
105
102
|
const lastSlash = typesFilePath.lastIndexOf('/');
|
|
106
103
|
const dir = lastSlash >= 0 ? typesFilePath.substring(0, lastSlash) : '.';
|
|
107
104
|
const entryFileName = lastSlash >= 0 ? typesFilePath.substring(lastSlash + 1) : typesFilePath;
|
|
108
105
|
return {
|
|
109
106
|
file: typesFilePath,
|
|
110
|
-
input:
|
|
107
|
+
input: inputFile,
|
|
111
108
|
tsconfig: 'tsconfig.json',
|
|
112
109
|
resolve: {
|
|
113
110
|
extensions: CONFIG.extensions,
|
|
@@ -126,6 +123,50 @@ const buildDts = () => {
|
|
|
126
123
|
},
|
|
127
124
|
};
|
|
128
125
|
};
|
|
126
|
+
/** Check if exports object uses subpath keys */
|
|
127
|
+
const isSubpathExports = (obj) => Object.keys(obj).some((k) => k === '.' || k.startsWith('./'));
|
|
128
|
+
/** Resolve input .ts file from a subpath export key */
|
|
129
|
+
const resolveSubpathInput = (exportPath) => {
|
|
130
|
+
if (exportPath === '.')
|
|
131
|
+
return `${CONFIG.sourceDir}/index.ts`;
|
|
132
|
+
const subpath = exportPath.slice(2);
|
|
133
|
+
return `${CONFIG.sourceDir}/${subpath}`;
|
|
134
|
+
};
|
|
135
|
+
const buildDts = () => {
|
|
136
|
+
if (!CONFIG.typescript)
|
|
137
|
+
return null;
|
|
138
|
+
// Simple case: no subpath exports
|
|
139
|
+
const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings;
|
|
140
|
+
if (typesFilePath) {
|
|
141
|
+
return createDtsConfig(typesFilePath, `${CONFIG.sourceDir}/index.ts`);
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
};
|
|
145
|
+
/** Build DTS configs for all subpath exports that have a `types` field */
|
|
146
|
+
const buildAllDts = () => {
|
|
147
|
+
if (!CONFIG.typescript)
|
|
148
|
+
return [];
|
|
149
|
+
const exportsOptions = PKG.exports;
|
|
150
|
+
if (!exportsOptions ||
|
|
151
|
+
typeof exportsOptions !== 'object' ||
|
|
152
|
+
!isSubpathExports(exportsOptions)) {
|
|
153
|
+
const single = buildDts();
|
|
154
|
+
return single ? [single] : [];
|
|
155
|
+
}
|
|
156
|
+
const results = [];
|
|
157
|
+
for (const [exportPath, exportConfig] of Object.entries(exportsOptions)) {
|
|
158
|
+
if (!exportConfig || typeof exportConfig !== 'object')
|
|
159
|
+
continue;
|
|
160
|
+
const typesPath = exportConfig.types;
|
|
161
|
+
if (!typesPath)
|
|
162
|
+
continue;
|
|
163
|
+
const inputFile = `${resolveSubpathInput(exportPath)}.ts`
|
|
164
|
+
.replace('/index.ts.ts', '/index.ts')
|
|
165
|
+
.replace('.ts.ts', '.ts');
|
|
166
|
+
results.push(createDtsConfig(typesPath, inputFile));
|
|
167
|
+
}
|
|
168
|
+
return results;
|
|
169
|
+
};
|
|
129
170
|
export default rolldownConfig;
|
|
130
|
-
export { buildDts };
|
|
171
|
+
export { buildAllDts, buildDts };
|
|
131
172
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/rolldown/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,QAAQ,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE3D,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC5C,MAAM,kBAAkB,GAAa,EAAE,CAAA;IAEvC,IAAK,SAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAY,EAAE,EAAE;YACzC,kBAAkB,CAAC,IAAI,CAAC,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,QAAgB,EAC4B,EAAE;IAC9C,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,MAAM,CAAA;IACtC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC5C,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAoB,EAAE,EAAE;IACjD,MAAM,OAAO,GAAqB,EAAE,CAAA;IAEpC,4CAA4C;IAC5C,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAG,I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import filesize from 'rollup-plugin-filesize'\nimport { visualizer } from 'rollup-plugin-visualizer'\nimport { CONFIG, PKG, PLATFORMS } from '../config/index.js'\n\nconst defineExtensions = (platform: string) => {\n const platformExtensions: string[] = []\n\n if ((PLATFORMS as readonly string[]).includes(platform)) {\n CONFIG.extensions.forEach((item: string) => {\n platformExtensions.push(`.${platform}${item}`)\n })\n }\n\n return platformExtensions.concat(CONFIG.extensions)\n}\n\nconst mapPlatform = (\n platform: string,\n): 'node' | 'browser' | 'neutral' | undefined => {\n if (platform === 'node') return 'node'\n if (platform === 'browser') return 'browser'\n return 'neutral'\n}\n\nconst loadPlugins = ({ file }: { file: string }) => {\n const plugins: RolldownPlugin[] = []\n\n // generate visualised graphs in dist folder\n if (CONFIG.visualise) {\n const filePath = file.split('/')\n const fileName = filePath.pop()\n\n const visualiserOptions = {\n title: `${PKG.name} - ${fileName}`,\n filename: `${filePath.join('/')}/${\n CONFIG.visualise.outputDir\n }/${fileName}.html`,\n template: CONFIG.visualise.template,\n gzipSize: CONFIG.visualise.gzipSize,\n }\n\n plugins.push(visualizer(visualiserOptions) as RolldownPlugin)\n }\n\n if (CONFIG.filesize) {\n plugins.push(filesize() as RolldownPlugin)\n }\n\n return plugins\n}\n\nconst buildDefineOptions = (env: string, platform: string) => {\n if (!CONFIG.replaceGlobals) return undefined\n\n const defineOptions: Record<string, string> = {\n __VERSION__: JSON.stringify(PKG.version),\n __NODE__: JSON.stringify(platform === 'node'),\n __WEB__: JSON.stringify(\n ['node', 'browser', 'universal'].includes(platform),\n ),\n __BROWSER__: JSON.stringify(platform === 'browser'),\n __NATIVE__: JSON.stringify(platform === 'native'),\n __CLIENT__: JSON.stringify(['native', 'browser'].includes(platform)),\n }\n\n if (env === 'production') {\n defineOptions['process.env.NODE_ENV'] = JSON.stringify(env)\n }\n\n return defineOptions\n}\n\nconst rolldownConfig = ({\n file,\n format,\n env,\n platform,\n input: entryInput,\n}: Record<string, any>) => {\n const extensions = defineExtensions(platform)\n const builtinPlugins = loadPlugins({ file })\n const userPlugins = (CONFIG.plugins || []) as RolldownPlugin[]\n const define = buildDefineOptions(env, platform)\n\n const lastSlash = file.lastIndexOf('/')\n const dir = lastSlash >= 0 ? file.substring(0, lastSlash) : '.'\n const entryFileName = lastSlash >= 0 ? file.substring(lastSlash + 1) : file\n\n const external = CONFIG.bundleAll\n ? []\n : [...PKG.externalDependencies, ...CONFIG.external]\n\n const buildOutput = {\n input: entryInput || CONFIG.sourceDir,\n platform: mapPlatform(platform),\n tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,\n resolve: {\n extensions,\n alias: CONFIG.alias || undefined,\n },\n transform: define ? { define } : undefined,\n output: {\n dir,\n entryFileNames: entryFileName,\n format,\n globals: swapGlobals(CONFIG.globals),\n sourcemap: true,\n sourcemapIgnoreList: (relativeSourcePath: string) =>\n relativeSourcePath.includes('node_modules'),\n exports: ['cjs', 'umd', 'iife'].includes(format)\n ? ('named' as const)\n : undefined,\n name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,\n esModule: true,\n minify: env === 'production',\n banner: CONFIG.banner || undefined,\n footer: CONFIG.footer || undefined,\n },\n external,\n treeshake: {\n moduleSideEffects: false,\n },\n plugins: [...builtinPlugins, ...userPlugins],\n }\n\n return buildOutput\n}\n\nconst buildDts = () => {\n const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings\n\n if (!CONFIG.typescript || !typesFilePath) return null\n\n const lastSlash = typesFilePath.lastIndexOf('/')\n const dir = lastSlash >= 0 ? typesFilePath.substring(0, lastSlash) : '.'\n const entryFileName =\n lastSlash >= 0 ? typesFilePath.substring(lastSlash + 1) : typesFilePath\n\n return {\n file: typesFilePath,\n input: `${CONFIG.sourceDir}/index.ts`,\n tsconfig: 'tsconfig.json',\n resolve: {\n extensions: CONFIG.extensions,\n },\n external: CONFIG.bundleAll\n ? []\n : [...PKG.externalDependencies, ...CONFIG.external],\n plugins: [...(dts({ tsconfig: 'tsconfig.json' }) as RolldownPlugin[])],\n output: {\n dir,\n entryFileNames: entryFileName,\n chunkFileNames: '[name].d.ts',\n format: 'es' as const,\n sourcemap: false,\n esModule: true,\n },\n }\n}\n\nexport default rolldownConfig\nexport { buildDts }\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/rolldown/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,QAAQ,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE3D,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC5C,MAAM,kBAAkB,GAAa,EAAE,CAAA;IAEvC,IAAK,SAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAY,EAAE,EAAE;YACzC,kBAAkB,CAAC,IAAI,CAAC,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,QAAgB,EAC4B,EAAE;IAC9C,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,MAAM,CAAA;IACtC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC5C,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAoB,EAAE,EAAE;IACjD,MAAM,OAAO,GAAqB,EAAE,CAAA;IAEpC,4CAA4C;IAC5C,IAAI,M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D,MAAM,SAAS,GAAI,YAAuC,CAAC,KAAK,CAAA;QAChE,IAAI,CAAC,SAAS;YAAE,SAAQ;QACxB,MAAM,SAAS,GAAG,GAAG,mBAAmB,CAAC,UAAU,CAAC,KAAK;aACtD,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC;aACpC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QAC3B,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;IACrD,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,eAAe,cAAc,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAA","sourcesContent":["import { swapGlobals } from '@vitus-labs/tools-core'\nimport type { RolldownPlugin } from 'rolldown'\nimport { dts } from 'rolldown-plugin-dts'\nimport filesize from 'rollup-plugin-filesize'\nimport { visualizer } from 'rollup-plugin-visualizer'\nimport { CONFIG, PKG, PLATFORMS } from '../config/index.js'\n\nconst defineExtensions = (platform: string) => {\n const platformExtensions: string[] = []\n\n if ((PLATFORMS as readonly string[]).includes(platform)) {\n CONFIG.extensions.forEach((item: string) => {\n platformExtensions.push(`.${platform}${item}`)\n })\n }\n\n return platformExtensions.concat(CONFIG.extensions)\n}\n\nconst mapPlatform = (\n platform: string,\n): 'node' | 'browser' | 'neutral' | undefined => {\n if (platform === 'node') return 'node'\n if (platform === 'browser') return 'browser'\n return 'neutral'\n}\n\nconst loadPlugins = ({ file }: { file: string }) => {\n const plugins: RolldownPlugin[] = []\n\n // generate visualised graphs in dist folder\n if (CONFIG.visualise) {\n const filePath = file.split('/')\n const fileName = filePath.pop()\n\n const visualiserOptions = {\n title: `${PKG.name} - ${fileName}`,\n filename: `${filePath.join('/')}/${\n CONFIG.visualise.outputDir\n }/${fileName}.html`,\n template: CONFIG.visualise.template,\n gzipSize: CONFIG.visualise.gzipSize,\n }\n\n plugins.push(visualizer(visualiserOptions) as RolldownPlugin)\n }\n\n if (CONFIG.filesize) {\n plugins.push(filesize() as RolldownPlugin)\n }\n\n return plugins\n}\n\nconst buildDefineOptions = (env: string, platform: string) => {\n if (!CONFIG.replaceGlobals) return undefined\n\n const defineOptions: Record<string, string> = {\n __VERSION__: JSON.stringify(PKG.version),\n __NODE__: JSON.stringify(platform === 'node'),\n __WEB__: JSON.stringify(\n ['node', 'browser', 'universal'].includes(platform),\n ),\n __BROWSER__: JSON.stringify(platform === 'browser'),\n __NATIVE__: JSON.stringify(platform === 'native'),\n __CLIENT__: JSON.stringify(['native', 'browser'].includes(platform)),\n }\n\n if (env === 'production') {\n defineOptions['process.env.NODE_ENV'] = JSON.stringify(env)\n }\n\n return defineOptions\n}\n\nconst rolldownConfig = ({\n file,\n format,\n env,\n platform,\n input: entryInput,\n}: Record<string, any>) => {\n const extensions = defineExtensions(platform)\n const builtinPlugins = loadPlugins({ file })\n const userPlugins = (CONFIG.plugins || []) as RolldownPlugin[]\n const define = buildDefineOptions(env, platform)\n\n const lastSlash = file.lastIndexOf('/')\n const dir = lastSlash >= 0 ? file.substring(0, lastSlash) : '.'\n const entryFileName = lastSlash >= 0 ? file.substring(lastSlash + 1) : file\n\n const external = CONFIG.bundleAll\n ? []\n : [...PKG.externalDependencies, ...CONFIG.external]\n\n const buildOutput = {\n input: entryInput || CONFIG.sourceDir,\n platform: mapPlatform(platform),\n tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,\n resolve: {\n extensions,\n alias: CONFIG.alias || undefined,\n },\n transform: define ? { define } : undefined,\n output: {\n dir,\n entryFileNames: entryFileName,\n format,\n globals: swapGlobals(CONFIG.globals),\n sourcemap: true,\n sourcemapIgnoreList: (relativeSourcePath: string) =>\n relativeSourcePath.includes('node_modules'),\n exports: ['cjs', 'umd', 'iife'].includes(format)\n ? ('named' as const)\n : undefined,\n name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,\n esModule: true,\n minify: env === 'production',\n banner: CONFIG.banner || undefined,\n footer: CONFIG.footer || undefined,\n },\n external,\n treeshake: {\n moduleSideEffects: false,\n },\n plugins: [...builtinPlugins, ...userPlugins],\n }\n\n return buildOutput\n}\n\nconst createDtsConfig = (typesFilePath: string, inputFile: string) => {\n const lastSlash = typesFilePath.lastIndexOf('/')\n const dir = lastSlash >= 0 ? typesFilePath.substring(0, lastSlash) : '.'\n const entryFileName =\n lastSlash >= 0 ? typesFilePath.substring(lastSlash + 1) : typesFilePath\n\n return {\n file: typesFilePath,\n input: inputFile,\n tsconfig: 'tsconfig.json',\n resolve: {\n extensions: CONFIG.extensions,\n },\n external: CONFIG.bundleAll\n ? []\n : [...PKG.externalDependencies, ...CONFIG.external],\n plugins: [...(dts({ tsconfig: 'tsconfig.json' }) as RolldownPlugin[])],\n output: {\n dir,\n entryFileNames: entryFileName,\n chunkFileNames: '[name].d.ts',\n format: 'es' as const,\n sourcemap: false,\n esModule: true,\n },\n }\n}\n\n/** Check if exports object uses subpath keys */\nconst isSubpathExports = (obj: Record<string, any>): boolean =>\n Object.keys(obj).some((k) => k === '.' || k.startsWith('./'))\n\n/** Resolve input .ts file from a subpath export key */\nconst resolveSubpathInput = (exportPath: string): string => {\n if (exportPath === '.') return `${CONFIG.sourceDir}/index.ts`\n const subpath = exportPath.slice(2)\n return `${CONFIG.sourceDir}/${subpath}`\n}\n\nconst buildDts = (): ReturnType<typeof createDtsConfig> | null => {\n if (!CONFIG.typescript) return null\n\n // Simple case: no subpath exports\n const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings\n if (typesFilePath) {\n return createDtsConfig(typesFilePath, `${CONFIG.sourceDir}/index.ts`)\n }\n\n return null\n}\n\n/** Build DTS configs for all subpath exports that have a `types` field */\nconst buildAllDts = (): ReturnType<typeof createDtsConfig>[] => {\n if (!CONFIG.typescript) return []\n\n const exportsOptions = PKG.exports\n if (\n !exportsOptions ||\n typeof exportsOptions !== 'object' ||\n !isSubpathExports(exportsOptions)\n ) {\n const single = buildDts()\n return single ? [single] : []\n }\n\n const results: ReturnType<typeof createDtsConfig>[] = []\n for (const [exportPath, exportConfig] of Object.entries(exportsOptions)) {\n if (!exportConfig || typeof exportConfig !== 'object') continue\n const typesPath = (exportConfig as Record<string, string>).types\n if (!typesPath) continue\n const inputFile = `${resolveSubpathInput(exportPath)}.ts`\n .replace('/index.ts.ts', '/index.ts')\n .replace('.ts.ts', '.ts')\n results.push(createDtsConfig(typesPath, inputFile))\n }\n\n return results\n}\n\nexport default rolldownConfig\nexport { buildAllDts, buildDts }\n"]}
|
|
@@ -31,46 +31,75 @@ const BUILD_VARIANTS = {
|
|
|
31
31
|
'umd:main': { format: 'umd', env: 'development' },
|
|
32
32
|
unpkg: { format: 'umd', env: 'production' },
|
|
33
33
|
};
|
|
34
|
+
/** Check if an exports object uses subpath keys (e.g. ".", "./devtools") */
|
|
35
|
+
const isSubpathExports = (obj) => Object.keys(obj).some((k) => k === '.' || k.startsWith('./'));
|
|
36
|
+
/** Resolve the source input file for a subpath export using convention:
|
|
37
|
+
* "." → "src/index.ts", "./devtools" → "src/devtools/index.ts",
|
|
38
|
+
* "./validation/zod" → "src/validation/zod.ts" (file) or "src/validation/zod/index.ts" (dir) */
|
|
39
|
+
const resolveSubpathInput = (exportPath) => {
|
|
40
|
+
if (exportPath === '.')
|
|
41
|
+
return `${CONFIG.sourceDir}/index.ts`;
|
|
42
|
+
const subpath = exportPath.slice(2); // strip "./"
|
|
43
|
+
return `${CONFIG.sourceDir}/${subpath}`;
|
|
44
|
+
};
|
|
45
|
+
/** Extract build variants from a single export's condition object */
|
|
46
|
+
const parseConditions = (conditions, input) => {
|
|
47
|
+
const result = [];
|
|
48
|
+
const base = input ? { input } : {};
|
|
49
|
+
if (conditions.import) {
|
|
50
|
+
result.push({ file: conditions.import, ...BUILD_VARIANTS.module, ...base });
|
|
51
|
+
}
|
|
52
|
+
if (conditions.require) {
|
|
53
|
+
result.push({
|
|
54
|
+
file: conditions.require,
|
|
55
|
+
format: 'cjs',
|
|
56
|
+
env: 'development',
|
|
57
|
+
platform: 'universal',
|
|
58
|
+
...base,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (conditions.node) {
|
|
62
|
+
result.push({
|
|
63
|
+
file: conditions.node,
|
|
64
|
+
...BUILD_VARIANTS.module,
|
|
65
|
+
platform: 'node',
|
|
66
|
+
...base,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (conditions.default && !conditions.import) {
|
|
70
|
+
result.push({ file: conditions.default, ...BUILD_VARIANTS.module, ...base });
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
/** Parse subpath exports object into build variants */
|
|
75
|
+
const parseSubpathExports = (exportsOptions) => {
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const [exportPath, exportConfig] of Object.entries(exportsOptions)) {
|
|
78
|
+
if (typeof exportConfig === 'string') {
|
|
79
|
+
result.push({
|
|
80
|
+
file: exportConfig,
|
|
81
|
+
input: resolveSubpathInput(exportPath),
|
|
82
|
+
...BUILD_VARIANTS.module,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else if (typeof exportConfig === 'object') {
|
|
86
|
+
const input = resolveSubpathInput(exportPath);
|
|
87
|
+
result.push(...parseConditions(exportConfig, input));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
34
92
|
const getExportsOptions = () => {
|
|
35
93
|
const exportsOptions = PKG.exports;
|
|
36
94
|
if (!exportsOptions)
|
|
37
95
|
return [];
|
|
38
96
|
if (typeof exportsOptions === 'string') {
|
|
39
|
-
return [
|
|
40
|
-
{
|
|
41
|
-
file: PKG.exports,
|
|
42
|
-
...BUILD_VARIANTS.module,
|
|
43
|
-
},
|
|
44
|
-
];
|
|
97
|
+
return [{ file: PKG.exports, ...BUILD_VARIANTS.module }];
|
|
45
98
|
}
|
|
46
99
|
if (typeof exportsOptions === 'object') {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
file: exportsOptions.import,
|
|
51
|
-
...BUILD_VARIANTS.module,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (exportsOptions.require) {
|
|
55
|
-
result.push({
|
|
56
|
-
file: exportsOptions.require,
|
|
57
|
-
...BUILD_VARIANTS.main,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (exportsOptions.node) {
|
|
61
|
-
result.push({
|
|
62
|
-
file: exportsOptions.node,
|
|
63
|
-
...BUILD_VARIANTS.module,
|
|
64
|
-
platform: 'node',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (exportsOptions.default) {
|
|
68
|
-
result.push({
|
|
69
|
-
file: exportsOptions.default,
|
|
70
|
-
...BUILD_VARIANTS.module,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
100
|
+
return isSubpathExports(exportsOptions)
|
|
101
|
+
? parseSubpathExports(exportsOptions)
|
|
102
|
+
: parseConditions(exportsOptions);
|
|
74
103
|
}
|
|
75
104
|
return [];
|
|
76
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildPipeline.js","sourceRoot":"","sources":["../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAE5C,MAAM,uBAAuB,GAAG,GAAG,EAAE;IACnC,OAAO,GAAG,CAAC,cAAc,CAAC,KAAK,GAAG,CAAC,MAAM,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IAChD,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAE9B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAiC,CAAC,CAAC,IAAI,CAC/D,CAAC,CAAC,GAAG,EAAE,KAAK,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SAAS;iBACpB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAyC,EAAE,EAAE,CAAC,CAAC;YACxE,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,IAAI;YAC5B,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,aAAa;YAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,WAAW;YACvC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC,CAAA;IACL,CAAC;IAED,OAAO,CAAC,GAAG,wBAAwB,EAAE,EAAE,GAAG,0BAA0B,EAAE,CAAC,CAAA;AACzE,CAAC,CAAA;AAED,eAAe,mBAAmB,CAAA","sourcesContent":["import { CONFIG, PKG } from '../config/index.js'\n\nconst isESModuleOnly = PKG.type === 'module'\n\nconst hasDifferentNativeBuild = () => {\n return PKG['react-native'] !== PKG.module\n}\n\nconst hasDifferentBrowserBuild = (type: string) => {\n if (!PKG.browser) return false\n\n return Object.entries(PKG.browser as Record<string, string>).some(\n ([key, value]) => {\n const source = key.substring(2)\n const output = value.substring(2)\n\n return source !== PKG[type] && source !== output\n },\n )\n}\n\nconst BUILD_VARIANTS: Record<\n string,\n { format: string; env: string; platform?: string }\n> = {\n main: {\n format: isESModuleOnly ? 'es' : 'cjs',\n env: 'development',\n platform: 'universal',\n },\n module: {\n format: 'es',\n env: 'development',\n platform: 'universal',\n },\n 'react-native': {\n format: 'es',\n env: 'development',\n platform: 'native',\n },\n 'umd:main': { format: 'umd', env: 'development' },\n unpkg: { format: 'umd', env: 'production' },\n}\n\nconst getExportsOptions = () => {\n const exportsOptions = PKG.exports\n\n if (!exportsOptions) return []\n\n if (typeof exportsOptions === 'string') {\n return [\n {\n file: PKG.exports,\n ...BUILD_VARIANTS.module,\n },\n ]\n }\n\n if (typeof exportsOptions === 'object') {\n const result: Record<string, any>[] = []\n\n if (exportsOptions.import) {\n result.push({\n file: exportsOptions.import,\n ...BUILD_VARIANTS.module,\n })\n }\n\n if (exportsOptions.require) {\n result.push({\n file: exportsOptions.require,\n ...BUILD_VARIANTS.main,\n })\n }\n\n if (exportsOptions.node) {\n result.push({\n file: exportsOptions.node,\n ...BUILD_VARIANTS.module,\n platform: 'node',\n })\n }\n\n if (exportsOptions.default) {\n result.push({\n file: exportsOptions.default,\n ...BUILD_VARIANTS.module,\n })\n }\n\n return result\n }\n\n return []\n}\n\nconst createBasicBuildVariants = () => {\n let result: Record<string, any>[] = []\n\n if (isESModuleOnly) result = [...getExportsOptions()]\n\n Object.keys(BUILD_VARIANTS).forEach((key) => {\n const PKGOutDir = PKG[key]\n\n if (PKGOutDir) {\n const hasBrowserBuild = hasDifferentBrowserBuild(key)\n const hasNativeBuild = hasDifferentNativeBuild()\n\n // create a helper function for adding a build variant to an array\n const add = (props = {}) => {\n result.push({ ...BUILD_VARIANTS[key], file: PKGOutDir, ...props })\n }\n\n if (key === 'react-native') {\n // add a separate RN build only if output path differs from module path\n if (hasNativeBuild) {\n add()\n }\n } else if (hasBrowserBuild) {\n // if has a different browser build, set default platform to node\n // as there is going to be created a separate browser build as well\n add({ platform: 'node' })\n } else {\n add()\n }\n }\n })\n\n return result\n}\n\nconst createBrowserBuildVariants = () => {\n const result: Record<string, any>[] = []\n if (!PKG.browser) return result\n\n Object.entries(PKG.browser as Record<string, string>).forEach(\n ([key, value]) => {\n const source = key.substring(2) // strip './' from the beginning of path\n const output = value.substring(2) // strip './' from the beginning of path\n\n Object.keys(BUILD_VARIANTS).forEach((item) => {\n if (PKG[item] === source && source !== output) {\n result.push({\n ...BUILD_VARIANTS[item],\n file: output,\n platform: 'browser',\n })\n }\n })\n },\n )\n\n return result\n}\n\nconst createBuildPipeline = () => {\n if (Array.isArray(CONFIG.entries) && CONFIG.entries.length > 0) {\n return CONFIG.entries.map((entry: Record<string, string | undefined>) => ({\n format: entry.format || 'es',\n env: entry.env || 'development',\n platform: entry.platform || 'universal',\n file: entry.file,\n input: entry.input,\n }))\n }\n\n return [...createBasicBuildVariants(), ...createBrowserBuildVariants()]\n}\n\nexport default createBuildPipeline\n"]}
|
|
1
|
+
{"version":3,"file":"createBuildPipeline.js","sourceRoot":"","sources":["../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAE5C,MAAM,uBAAuB,GAAG,GAAG,EAAE;IACnC,OAAO,GAAG,CAAC,cAAc,CAAC,KAAK,GAAG,CAAC,MAAM,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IAChD,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAE9B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAiC,CAAC,CAAC,IAAI,CAC/D,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACf,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAEjC,OAAO,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,KAAK,MAAM,CAAA;IAClD,CAAC,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,cAAc,GAGhB;IACF,IAAI,EAAE;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AC;gBAC9C,MAAM,CAAC,IAAI,CAAC;oBACV,GAAG,cAAc,CAAC,IAAI,CAAC;oBACvB,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,SAAS;iBACpB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAyC,EAAE,EAAE,CAAC,CAAC;YACxE,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,IAAI;YAC5B,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,aAAa;YAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,WAAW;YACvC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC,CAAA;IACL,CAAC;IAED,OAAO,CAAC,GAAG,wBAAwB,EAAE,EAAE,GAAG,0BAA0B,EAAE,CAAC,CAAA;AACzE,CAAC,CAAA;AAED,eAAe,mBAAmB,CAAA","sourcesContent":["import { CONFIG, PKG } from '../config/index.js'\n\nconst isESModuleOnly = PKG.type === 'module'\n\nconst hasDifferentNativeBuild = () => {\n return PKG['react-native'] !== PKG.module\n}\n\nconst hasDifferentBrowserBuild = (type: string) => {\n if (!PKG.browser) return false\n\n return Object.entries(PKG.browser as Record<string, string>).some(\n ([key, value]) => {\n const source = key.substring(2)\n const output = value.substring(2)\n\n return source !== PKG[type] && source !== output\n },\n )\n}\n\nconst BUILD_VARIANTS: Record<\n string,\n { format: string; env: string; platform?: string }\n> = {\n main: {\n format: isESModuleOnly ? 'es' : 'cjs',\n env: 'development',\n platform: 'universal',\n },\n module: {\n format: 'es',\n env: 'development',\n platform: 'universal',\n },\n 'react-native': {\n format: 'es',\n env: 'development',\n platform: 'native',\n },\n 'umd:main': { format: 'umd', env: 'development' },\n unpkg: { format: 'umd', env: 'production' },\n}\n\n/** Check if an exports object uses subpath keys (e.g. \".\", \"./devtools\") */\nconst isSubpathExports = (obj: Record<string, any>): boolean =>\n Object.keys(obj).some((k) => k === '.' || k.startsWith('./'))\n\n/** Resolve the source input file for a subpath export using convention:\n * \".\" → \"src/index.ts\", \"./devtools\" → \"src/devtools/index.ts\",\n * \"./validation/zod\" → \"src/validation/zod.ts\" (file) or \"src/validation/zod/index.ts\" (dir) */\nconst resolveSubpathInput = (exportPath: string): string => {\n if (exportPath === '.') return `${CONFIG.sourceDir}/index.ts`\n const subpath = exportPath.slice(2) // strip \"./\"\n return `${CONFIG.sourceDir}/${subpath}`\n}\n\n/** Extract build variants from a single export's condition object */\nconst parseConditions = (\n conditions: Record<string, any>,\n input?: string,\n): Record<string, any>[] => {\n const result: Record<string, any>[] = []\n const base = input ? { input } : {}\n\n if (conditions.import) {\n result.push({ file: conditions.import, ...BUILD_VARIANTS.module, ...base })\n }\n if (conditions.require) {\n result.push({\n file: conditions.require,\n format: 'cjs',\n env: 'development',\n platform: 'universal',\n ...base,\n })\n }\n if (conditions.node) {\n result.push({\n file: conditions.node,\n ...BUILD_VARIANTS.module,\n platform: 'node',\n ...base,\n })\n }\n if (conditions.default && !conditions.import) {\n result.push({ file: conditions.default, ...BUILD_VARIANTS.module, ...base })\n }\n\n return result\n}\n\n/** Parse subpath exports object into build variants */\nconst parseSubpathExports = (\n exportsOptions: Record<string, any>,\n): Record<string, any>[] => {\n const result: Record<string, any>[] = []\n\n for (const [exportPath, exportConfig] of Object.entries(exportsOptions)) {\n if (typeof exportConfig === 'string') {\n result.push({\n file: exportConfig,\n input: resolveSubpathInput(exportPath),\n ...BUILD_VARIANTS.module,\n })\n } else if (typeof exportConfig === 'object') {\n const input = resolveSubpathInput(exportPath)\n result.push(...parseConditions(exportConfig, input))\n }\n }\n\n return result\n}\n\nconst getExportsOptions = () => {\n const exportsOptions = PKG.exports\n\n if (!exportsOptions) return []\n\n if (typeof exportsOptions === 'string') {\n return [{ file: PKG.exports, ...BUILD_VARIANTS.module }]\n }\n\n if (typeof exportsOptions === 'object') {\n return isSubpathExports(exportsOptions)\n ? parseSubpathExports(exportsOptions)\n : parseConditions(exportsOptions)\n }\n\n return []\n}\n\nconst createBasicBuildVariants = () => {\n let result: Record<string, any>[] = []\n\n if (isESModuleOnly) result = [...getExportsOptions()]\n\n Object.keys(BUILD_VARIANTS).forEach((key) => {\n const PKGOutDir = PKG[key]\n\n if (PKGOutDir) {\n const hasBrowserBuild = hasDifferentBrowserBuild(key)\n const hasNativeBuild = hasDifferentNativeBuild()\n\n // create a helper function for adding a build variant to an array\n const add = (props = {}) => {\n result.push({ ...BUILD_VARIANTS[key], file: PKGOutDir, ...props })\n }\n\n if (key === 'react-native') {\n // add a separate RN build only if output path differs from module path\n if (hasNativeBuild) {\n add()\n }\n } else if (hasBrowserBuild) {\n // if has a different browser build, set default platform to node\n // as there is going to be created a separate browser build as well\n add({ platform: 'node' })\n } else {\n add()\n }\n }\n })\n\n return result\n}\n\nconst createBrowserBuildVariants = () => {\n const result: Record<string, any>[] = []\n if (!PKG.browser) return result\n\n Object.entries(PKG.browser as Record<string, string>).forEach(\n ([key, value]) => {\n const source = key.substring(2) // strip './' from the beginning of path\n const output = value.substring(2) // strip './' from the beginning of path\n\n Object.keys(BUILD_VARIANTS).forEach((item) => {\n if (PKG[item] === source && source !== output) {\n result.push({\n ...BUILD_VARIANTS[item],\n file: output,\n platform: 'browser',\n })\n }\n })\n },\n )\n\n return result\n}\n\nconst createBuildPipeline = () => {\n if (Array.isArray(CONFIG.entries) && CONFIG.entries.length > 0) {\n return CONFIG.entries.map((entry: Record<string, string | undefined>) => ({\n format: entry.format || 'es',\n env: entry.env || 'development',\n platform: entry.platform || 'universal',\n file: entry.file,\n input: entry.input,\n }))\n }\n\n return [...createBasicBuildVariants(), ...createBrowserBuildVariants()]\n}\n\nexport default createBuildPipeline\n"]}
|
package/lib/rolldown/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import config, { buildDts } from './config.js';
|
|
1
|
+
import config, { buildAllDts, buildDts } from './config.js';
|
|
2
2
|
import createBuildPipeline from './createBuildPipeline.js';
|
|
3
|
-
export { buildDts, config, createBuildPipeline };
|
|
3
|
+
export { buildAllDts, buildDts, config, createBuildPipeline };
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rolldown/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rolldown/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,mBAAmB,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA","sourcesContent":["import config, { buildAllDts, buildDts } from './config.js'\nimport createBuildPipeline from './createBuildPipeline.js'\n\nexport { buildAllDts, buildDts, config, createBuildPipeline }\n"]}
|
package/lib/scripts/build.js
CHANGED
|
@@ -4,7 +4,7 @@ import chalk from 'chalk';
|
|
|
4
4
|
import { rimraf } from 'rimraf';
|
|
5
5
|
import { rolldown } from 'rolldown';
|
|
6
6
|
import { CONFIG, PKG } from '../config/index.js';
|
|
7
|
-
import {
|
|
7
|
+
import { buildAllDts, createBuildPipeline, config as rolldownConfig, } from '../rolldown/index.js';
|
|
8
8
|
const { log } = console;
|
|
9
9
|
const allBuilds = createBuildPipeline();
|
|
10
10
|
const allBuildsCount = allBuilds.length;
|
|
@@ -75,16 +75,18 @@ const fixDtsCodeSplit = (outDir, entryName) => {
|
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
const generateDeclarations = async () => {
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
78
|
+
const dtsConfigs = buildAllDts();
|
|
79
|
+
if (dtsConfigs.length === 0)
|
|
80
80
|
return;
|
|
81
81
|
log(`\n${dim('Generating')} declarations...`);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
for (const dtsFile of dtsConfigs) {
|
|
83
|
+
const tscStart = performance.now();
|
|
84
|
+
const { output, file, ...input } = dtsFile;
|
|
85
|
+
await build({ inputOptions: input, outputOptions: output });
|
|
86
|
+
fixDtsCodeSplit(output.dir, output.entryFileNames);
|
|
87
|
+
const tscDuration = Math.round(performance.now() - tscStart);
|
|
88
|
+
log(` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`);
|
|
89
|
+
}
|
|
88
90
|
};
|
|
89
91
|
const runBuild = async () => {
|
|
90
92
|
const start = performance.now();
|
package/lib/scripts/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/scripts/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EACL,
|
|
1
|
+
{"version":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ync, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\nimport chalk from 'chalk'\nimport { rimraf } from 'rimraf'\nimport { rolldown } from 'rolldown'\nimport { CONFIG, PKG } from '../config/index.js'\nimport {\n buildAllDts,\n createBuildPipeline,\n config as rolldownConfig,\n} from '../rolldown/index.js'\n\nconst { log } = console\nconst allBuilds = createBuildPipeline()\nconst allBuildsCount = allBuilds.length\n\nconst FORMAT_LABEL: Record<string, string> = {\n cjs: 'CJS',\n es: 'ESM',\n umd: 'UMD',\n iife: 'IIFE',\n}\n\nconst label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)\nconst dim = chalk.dim\nconst bold = chalk.bold\n\nasync function build({\n inputOptions,\n outputOptions,\n}: {\n inputOptions: any\n outputOptions: any\n}) {\n const bundle = await rolldown(inputOptions)\n await bundle.write(outputOptions)\n await bundle.close()\n}\n\nconst createBuilds = async () => {\n let p = Promise.resolve()\n\n allBuilds.forEach((item: Record<string, any>) => {\n const { output, ...input } = rolldownConfig(item)\n const format = FORMAT_LABEL[output.format] || output.format\n p = p.then(() => {\n const start = performance.now()\n\n return build({ inputOptions: input, outputOptions: output })\n .then(() => {\n const duration = Math.round(performance.now() - start)\n log(\n ` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`,\n )\n })\n .catch((e) => {\n log(`\\n${chalk.bold.red('Build failed')}`)\n log(chalk.gray(` Format: ${format}`))\n log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`))\n log(e)\n throw e\n })\n })\n })\n\n return p\n}\n\nconst copyStaticFiles = () => {\n if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0) return\n\n log(`\\n${dim('Copying')} static files...\\n`)\n for (const { from, to } of CONFIG.copyFiles as {\n from: string\n to: string\n }[]) {\n cpSync(from, to, { recursive: true })\n log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`)\n }\n}\n\nconst fixDtsCodeSplit = (outDir: string, entryName: string) => {\n const entryPath = join(outDir, entryName)\n const allDts = readdirSync(outDir).filter(\n (f) => f.endsWith('.d.ts') && f !== entryName,\n )\n\n if (allDts.length !== 1 || !allDts[0]) return\n\n const chunkPath = join(outDir, allDts[0])\n const chunkSize = statSync(chunkPath).size\n const entrySize = statSync(entryPath).size\n\n if (chunkSize > entrySize) {\n unlinkSync(entryPath)\n renameSync(chunkPath, entryPath)\n try {\n unlinkSync(`${entryPath}.map`)\n renameSync(`${chunkPath}.map`, `${entryPath}.map`)\n } catch {\n // sourcemap may not exist\n }\n }\n}\n\nconst generateDeclarations = async () => {\n const dtsConfigs = buildAllDts()\n if (dtsConfigs.length === 0) return\n\n log(`\\n${dim('Generating')} declarations...`)\n\n for (const dtsFile of dtsConfigs) {\n const tscStart = performance.now()\n const { output, file, ...input } = dtsFile\n await build({ inputOptions: input, outputOptions: output })\n fixDtsCodeSplit(output.dir as string, output.entryFileNames as string)\n\n const tscDuration = Math.round(performance.now() - tscStart)\n log(\n ` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`,\n )\n }\n}\n\nconst runBuild = async () => {\n const start = performance.now()\n\n log(\n `\\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\\n`,\n )\n\n log(`${dim('Cleaning')} ${CONFIG.outputDir}/`)\n rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`)\n\n log(\n `${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\\n`,\n )\n\n await createBuilds()\n copyStaticFiles()\n await generateDeclarations()\n\n const total = Math.round(performance.now() - start)\n log(`\\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\\n`)\n}\n\nexport { runBuild }\n"]}
|
|
@@ -30,8 +30,8 @@ declare const rolldownConfig: ({ file, format, env, platform, input: entryInput,
|
|
|
30
30
|
};
|
|
31
31
|
plugins: RolldownPlugin[];
|
|
32
32
|
};
|
|
33
|
-
declare const
|
|
34
|
-
file:
|
|
33
|
+
declare const createDtsConfig: (typesFilePath: string, inputFile: string) => {
|
|
34
|
+
file: string;
|
|
35
35
|
input: string;
|
|
36
36
|
tsconfig: string;
|
|
37
37
|
resolve: {
|
|
@@ -40,14 +40,17 @@ declare const buildDts: () => {
|
|
|
40
40
|
external: any[];
|
|
41
41
|
plugins: RolldownPlugin[];
|
|
42
42
|
output: {
|
|
43
|
-
dir:
|
|
44
|
-
entryFileNames:
|
|
43
|
+
dir: string;
|
|
44
|
+
entryFileNames: string;
|
|
45
45
|
chunkFileNames: string;
|
|
46
46
|
format: "es";
|
|
47
47
|
sourcemap: boolean;
|
|
48
48
|
esModule: boolean;
|
|
49
49
|
};
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
|
+
declare const buildDts: () => ReturnType<typeof createDtsConfig> | null;
|
|
52
|
+
/** Build DTS configs for all subpath exports that have a `types` field */
|
|
53
|
+
declare const buildAllDts: () => ReturnType<typeof createDtsConfig>[];
|
|
51
54
|
export default rolldownConfig;
|
|
52
|
-
export { buildDts };
|
|
55
|
+
export { buildAllDts, buildDts };
|
|
53
56
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/rolldown/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AA0E9C,QAAA,MAAM,cAAc,GAAI,qDAMrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;;;;;;;;;;;;;kDA6B0B,MAAM;;;;;;;;;;;;;CAmBrD,CAAA;AAED,QAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/rolldown/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AA0E9C,QAAA,MAAM,cAAc,GAAI,qDAMrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;;;;;;;;;;;;;kDA6B0B,MAAM;;;;;;;;;;;;;CAmBrD,CAAA;AAED,QAAA,MAAM,eAAe,GAAI,eAAe,MAAM,EAAE,WAAW,MAAM;;;;;;;;;;;;;;;;;CA0BhE,CAAA;AAaD,QAAA,MAAM,QAAQ,QAAO,UAAU,CAAC,OAAO,eAAe,CAAC,GAAG,IAUzD,CAAA;AAED,0EAA0E;AAC1E,QAAA,MAAM,WAAW,QAAO,UAAU,CAAC,OAAO,eAAe,CAAC,EAyBzD,CAAA;AAED,eAAe,cAAc,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildPipeline.d.ts","sourceRoot":"","sources":["../../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createBuildPipeline.d.ts","sourceRoot":"","sources":["../../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AA+LA,QAAA,MAAM,mBAAmB,WAYxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import config, { buildDts } from './config.js';
|
|
1
|
+
import config, { buildAllDts, buildDts } from './config.js';
|
|
2
2
|
import createBuildPipeline from './createBuildPipeline.js';
|
|
3
|
-
export { buildDts, config, createBuildPipeline };
|
|
3
|
+
export { buildAllDts, buildDts, config, createBuildPipeline };
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rolldown/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rolldown/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,mBAAmB,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AA4HA,QAAA,MAAM,QAAQ,qBAoBb,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/tools-rolldown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@vitus-labs/tools-core": "1.
|
|
40
|
+
"@vitus-labs/tools-core": "^1.12.0",
|
|
41
41
|
"chalk": "^5.6.2",
|
|
42
42
|
"rimraf": "^6.1.3",
|
|
43
43
|
"rolldown": "^1.0.0-rc.9",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"rollup-plugin-visualizer": "^7.0.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@vitus-labs/tools-typescript": "1.
|
|
49
|
+
"@vitus-labs/tools-typescript": "^1.12.0",
|
|
50
50
|
"typescript": "^5.9.3"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/rolldown/config.ts
CHANGED
|
@@ -129,11 +129,7 @@ const rolldownConfig = ({
|
|
|
129
129
|
return buildOutput
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
const
|
|
133
|
-
const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings
|
|
134
|
-
|
|
135
|
-
if (!CONFIG.typescript || !typesFilePath) return null
|
|
136
|
-
|
|
132
|
+
const createDtsConfig = (typesFilePath: string, inputFile: string) => {
|
|
137
133
|
const lastSlash = typesFilePath.lastIndexOf('/')
|
|
138
134
|
const dir = lastSlash >= 0 ? typesFilePath.substring(0, lastSlash) : '.'
|
|
139
135
|
const entryFileName =
|
|
@@ -141,7 +137,7 @@ const buildDts = () => {
|
|
|
141
137
|
|
|
142
138
|
return {
|
|
143
139
|
file: typesFilePath,
|
|
144
|
-
input:
|
|
140
|
+
input: inputFile,
|
|
145
141
|
tsconfig: 'tsconfig.json',
|
|
146
142
|
resolve: {
|
|
147
143
|
extensions: CONFIG.extensions,
|
|
@@ -161,5 +157,56 @@ const buildDts = () => {
|
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
159
|
|
|
160
|
+
/** Check if exports object uses subpath keys */
|
|
161
|
+
const isSubpathExports = (obj: Record<string, any>): boolean =>
|
|
162
|
+
Object.keys(obj).some((k) => k === '.' || k.startsWith('./'))
|
|
163
|
+
|
|
164
|
+
/** Resolve input .ts file from a subpath export key */
|
|
165
|
+
const resolveSubpathInput = (exportPath: string): string => {
|
|
166
|
+
if (exportPath === '.') return `${CONFIG.sourceDir}/index.ts`
|
|
167
|
+
const subpath = exportPath.slice(2)
|
|
168
|
+
return `${CONFIG.sourceDir}/${subpath}`
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const buildDts = (): ReturnType<typeof createDtsConfig> | null => {
|
|
172
|
+
if (!CONFIG.typescript) return null
|
|
173
|
+
|
|
174
|
+
// Simple case: no subpath exports
|
|
175
|
+
const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings
|
|
176
|
+
if (typesFilePath) {
|
|
177
|
+
return createDtsConfig(typesFilePath, `${CONFIG.sourceDir}/index.ts`)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return null
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Build DTS configs for all subpath exports that have a `types` field */
|
|
184
|
+
const buildAllDts = (): ReturnType<typeof createDtsConfig>[] => {
|
|
185
|
+
if (!CONFIG.typescript) return []
|
|
186
|
+
|
|
187
|
+
const exportsOptions = PKG.exports
|
|
188
|
+
if (
|
|
189
|
+
!exportsOptions ||
|
|
190
|
+
typeof exportsOptions !== 'object' ||
|
|
191
|
+
!isSubpathExports(exportsOptions)
|
|
192
|
+
) {
|
|
193
|
+
const single = buildDts()
|
|
194
|
+
return single ? [single] : []
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const results: ReturnType<typeof createDtsConfig>[] = []
|
|
198
|
+
for (const [exportPath, exportConfig] of Object.entries(exportsOptions)) {
|
|
199
|
+
if (!exportConfig || typeof exportConfig !== 'object') continue
|
|
200
|
+
const typesPath = (exportConfig as Record<string, string>).types
|
|
201
|
+
if (!typesPath) continue
|
|
202
|
+
const inputFile = `${resolveSubpathInput(exportPath)}.ts`
|
|
203
|
+
.replace('/index.ts.ts', '/index.ts')
|
|
204
|
+
.replace('.ts.ts', '.ts')
|
|
205
|
+
results.push(createDtsConfig(typesPath, inputFile))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return results
|
|
209
|
+
}
|
|
210
|
+
|
|
164
211
|
export default rolldownConfig
|
|
165
|
-
export { buildDts }
|
|
212
|
+
export { buildAllDts, buildDts }
|
|
@@ -12,7 +12,7 @@ const { mockPKG } = vi.hoisted(() => ({
|
|
|
12
12
|
|
|
13
13
|
vi.mock('../config/index.js', () => ({
|
|
14
14
|
PKG: mockPKG,
|
|
15
|
-
CONFIG: {},
|
|
15
|
+
CONFIG: { sourceDir: 'src' },
|
|
16
16
|
PLATFORMS: ['browser', 'node', 'web', 'native'],
|
|
17
17
|
}))
|
|
18
18
|
|
|
@@ -117,15 +117,16 @@ describe('createBuildPipeline', () => {
|
|
|
117
117
|
createBuildPipeline = mod.default
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
it('should include node and default
|
|
120
|
+
it('should include node export and skip default when import exists', () => {
|
|
121
121
|
const builds = createBuildPipeline()
|
|
122
122
|
|
|
123
123
|
const nodeBuild = builds.find((b) => b.file === './lib/node.js')
|
|
124
124
|
expect(nodeBuild).toBeDefined()
|
|
125
125
|
expect(nodeBuild.platform).toBe('node')
|
|
126
126
|
|
|
127
|
+
// default is skipped when import is present (avoids duplicate builds)
|
|
127
128
|
const defaultBuild = builds.find((b) => b.file === './lib/default.js')
|
|
128
|
-
expect(defaultBuild).
|
|
129
|
+
expect(defaultBuild).toBeUndefined()
|
|
129
130
|
})
|
|
130
131
|
})
|
|
131
132
|
|
|
@@ -203,6 +204,124 @@ describe('createBuildPipeline', () => {
|
|
|
203
204
|
})
|
|
204
205
|
})
|
|
205
206
|
|
|
207
|
+
describe('with subpath exports', () => {
|
|
208
|
+
let createBuildPipeline: () => any[]
|
|
209
|
+
|
|
210
|
+
beforeEach(async () => {
|
|
211
|
+
vi.resetModules()
|
|
212
|
+
mockPKG.type = 'module'
|
|
213
|
+
delete mockPKG.main
|
|
214
|
+
delete mockPKG.module
|
|
215
|
+
mockPKG.exports = {
|
|
216
|
+
'.': {
|
|
217
|
+
types: './lib/types/index.d.ts',
|
|
218
|
+
import: './lib/index.js',
|
|
219
|
+
},
|
|
220
|
+
'./devtools': {
|
|
221
|
+
types: './lib/types/devtools/index.d.ts',
|
|
222
|
+
import: './lib/devtools/index.js',
|
|
223
|
+
},
|
|
224
|
+
'./validation/zod': {
|
|
225
|
+
types: './lib/types/validation/zod.d.ts',
|
|
226
|
+
import: './lib/validation/zod.js',
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
const mod = await import('./createBuildPipeline.js')
|
|
230
|
+
createBuildPipeline = mod.default
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('should create builds for all subpath exports', () => {
|
|
234
|
+
const builds = createBuildPipeline()
|
|
235
|
+
|
|
236
|
+
expect(builds).toHaveLength(3)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
it('should set correct input for root export', () => {
|
|
240
|
+
const builds = createBuildPipeline()
|
|
241
|
+
const root = builds.find((b) => b.file === './lib/index.js')
|
|
242
|
+
|
|
243
|
+
expect(root).toBeDefined()
|
|
244
|
+
expect(root.input).toBe('src/index.ts')
|
|
245
|
+
expect(root.format).toBe('es')
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('should set correct input for subpath export', () => {
|
|
249
|
+
const builds = createBuildPipeline()
|
|
250
|
+
const devtools = builds.find((b) => b.file === './lib/devtools/index.js')
|
|
251
|
+
|
|
252
|
+
expect(devtools).toBeDefined()
|
|
253
|
+
expect(devtools.input).toBe('src/devtools')
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
it('should set correct input for nested subpath export', () => {
|
|
257
|
+
const builds = createBuildPipeline()
|
|
258
|
+
const zod = builds.find((b) => b.file === './lib/validation/zod.js')
|
|
259
|
+
|
|
260
|
+
expect(zod).toBeDefined()
|
|
261
|
+
expect(zod.input).toBe('src/validation/zod')
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
describe('with subpath exports having multiple conditions', () => {
|
|
266
|
+
let createBuildPipeline: () => any[]
|
|
267
|
+
|
|
268
|
+
beforeEach(async () => {
|
|
269
|
+
vi.resetModules()
|
|
270
|
+
mockPKG.type = 'module'
|
|
271
|
+
delete mockPKG.main
|
|
272
|
+
delete mockPKG.module
|
|
273
|
+
mockPKG.exports = {
|
|
274
|
+
'.': {
|
|
275
|
+
import: './lib/index.js',
|
|
276
|
+
require: './lib/index.cjs',
|
|
277
|
+
},
|
|
278
|
+
}
|
|
279
|
+
const mod = await import('./createBuildPipeline.js')
|
|
280
|
+
createBuildPipeline = mod.default
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
it('should create builds for each condition', () => {
|
|
284
|
+
const builds = createBuildPipeline()
|
|
285
|
+
|
|
286
|
+
const esBuild = builds.find((b) => b.file === './lib/index.js')
|
|
287
|
+
expect(esBuild).toBeDefined()
|
|
288
|
+
expect(esBuild.format).toBe('es')
|
|
289
|
+
|
|
290
|
+
const cjsBuild = builds.find((b) => b.file === './lib/index.cjs')
|
|
291
|
+
expect(cjsBuild).toBeDefined()
|
|
292
|
+
expect(cjsBuild.format).toBe('cjs')
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
describe('with subpath string export', () => {
|
|
297
|
+
let createBuildPipeline: () => any[]
|
|
298
|
+
|
|
299
|
+
beforeEach(async () => {
|
|
300
|
+
vi.resetModules()
|
|
301
|
+
mockPKG.type = 'module'
|
|
302
|
+
delete mockPKG.main
|
|
303
|
+
delete mockPKG.module
|
|
304
|
+
mockPKG.exports = {
|
|
305
|
+
'.': './lib/index.js',
|
|
306
|
+
'./utils': './lib/utils.js',
|
|
307
|
+
}
|
|
308
|
+
const mod = await import('./createBuildPipeline.js')
|
|
309
|
+
createBuildPipeline = mod.default
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('should handle string subpath exports', () => {
|
|
313
|
+
const builds = createBuildPipeline()
|
|
314
|
+
|
|
315
|
+
const root = builds.find((b) => b.file === './lib/index.js')
|
|
316
|
+
expect(root).toBeDefined()
|
|
317
|
+
expect(root.input).toBe('src/index.ts')
|
|
318
|
+
|
|
319
|
+
const utils = builds.find((b) => b.file === './lib/utils.js')
|
|
320
|
+
expect(utils).toBeDefined()
|
|
321
|
+
expect(utils.input).toBe('src/utils')
|
|
322
|
+
})
|
|
323
|
+
})
|
|
324
|
+
|
|
206
325
|
describe('with UMD builds', () => {
|
|
207
326
|
let createBuildPipeline: () => any[]
|
|
208
327
|
|
|
@@ -42,53 +42,89 @@ const BUILD_VARIANTS: Record<
|
|
|
42
42
|
unpkg: { format: 'umd', env: 'production' },
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/** Check if an exports object uses subpath keys (e.g. ".", "./devtools") */
|
|
46
|
+
const isSubpathExports = (obj: Record<string, any>): boolean =>
|
|
47
|
+
Object.keys(obj).some((k) => k === '.' || k.startsWith('./'))
|
|
48
|
+
|
|
49
|
+
/** Resolve the source input file for a subpath export using convention:
|
|
50
|
+
* "." → "src/index.ts", "./devtools" → "src/devtools/index.ts",
|
|
51
|
+
* "./validation/zod" → "src/validation/zod.ts" (file) or "src/validation/zod/index.ts" (dir) */
|
|
52
|
+
const resolveSubpathInput = (exportPath: string): string => {
|
|
53
|
+
if (exportPath === '.') return `${CONFIG.sourceDir}/index.ts`
|
|
54
|
+
const subpath = exportPath.slice(2) // strip "./"
|
|
55
|
+
return `${CONFIG.sourceDir}/${subpath}`
|
|
56
|
+
}
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
/** Extract build variants from a single export's condition object */
|
|
59
|
+
const parseConditions = (
|
|
60
|
+
conditions: Record<string, any>,
|
|
61
|
+
input?: string,
|
|
62
|
+
): Record<string, any>[] => {
|
|
63
|
+
const result: Record<string, any>[] = []
|
|
64
|
+
const base = input ? { input } : {}
|
|
49
65
|
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
if (conditions.import) {
|
|
67
|
+
result.push({ file: conditions.import, ...BUILD_VARIANTS.module, ...base })
|
|
68
|
+
}
|
|
69
|
+
if (conditions.require) {
|
|
70
|
+
result.push({
|
|
71
|
+
file: conditions.require,
|
|
72
|
+
format: 'cjs',
|
|
73
|
+
env: 'development',
|
|
74
|
+
platform: 'universal',
|
|
75
|
+
...base,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
if (conditions.node) {
|
|
79
|
+
result.push({
|
|
80
|
+
file: conditions.node,
|
|
81
|
+
...BUILD_VARIANTS.module,
|
|
82
|
+
platform: 'node',
|
|
83
|
+
...base,
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
if (conditions.default && !conditions.import) {
|
|
87
|
+
result.push({ file: conditions.default, ...BUILD_VARIANTS.module, ...base })
|
|
57
88
|
}
|
|
58
89
|
|
|
59
|
-
|
|
60
|
-
|
|
90
|
+
return result
|
|
91
|
+
}
|
|
61
92
|
|
|
62
|
-
|
|
93
|
+
/** Parse subpath exports object into build variants */
|
|
94
|
+
const parseSubpathExports = (
|
|
95
|
+
exportsOptions: Record<string, any>,
|
|
96
|
+
): Record<string, any>[] => {
|
|
97
|
+
const result: Record<string, any>[] = []
|
|
98
|
+
|
|
99
|
+
for (const [exportPath, exportConfig] of Object.entries(exportsOptions)) {
|
|
100
|
+
if (typeof exportConfig === 'string') {
|
|
63
101
|
result.push({
|
|
64
|
-
file:
|
|
102
|
+
file: exportConfig,
|
|
103
|
+
input: resolveSubpathInput(exportPath),
|
|
65
104
|
...BUILD_VARIANTS.module,
|
|
66
105
|
})
|
|
106
|
+
} else if (typeof exportConfig === 'object') {
|
|
107
|
+
const input = resolveSubpathInput(exportPath)
|
|
108
|
+
result.push(...parseConditions(exportConfig, input))
|
|
67
109
|
}
|
|
110
|
+
}
|
|
68
111
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
file: exportsOptions.require,
|
|
72
|
-
...BUILD_VARIANTS.main,
|
|
73
|
-
})
|
|
74
|
-
}
|
|
112
|
+
return result
|
|
113
|
+
}
|
|
75
114
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
file: exportsOptions.node,
|
|
79
|
-
...BUILD_VARIANTS.module,
|
|
80
|
-
platform: 'node',
|
|
81
|
-
})
|
|
82
|
-
}
|
|
115
|
+
const getExportsOptions = () => {
|
|
116
|
+
const exportsOptions = PKG.exports
|
|
83
117
|
|
|
84
|
-
|
|
85
|
-
result.push({
|
|
86
|
-
file: exportsOptions.default,
|
|
87
|
-
...BUILD_VARIANTS.module,
|
|
88
|
-
})
|
|
89
|
-
}
|
|
118
|
+
if (!exportsOptions) return []
|
|
90
119
|
|
|
91
|
-
|
|
120
|
+
if (typeof exportsOptions === 'string') {
|
|
121
|
+
return [{ file: PKG.exports, ...BUILD_VARIANTS.module }]
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (typeof exportsOptions === 'object') {
|
|
125
|
+
return isSubpathExports(exportsOptions)
|
|
126
|
+
? parseSubpathExports(exportsOptions)
|
|
127
|
+
: parseConditions(exportsOptions)
|
|
92
128
|
}
|
|
93
129
|
|
|
94
130
|
return []
|
package/src/rolldown/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import config, { buildDts } from './config.js'
|
|
1
|
+
import config, { buildAllDts, buildDts } from './config.js'
|
|
2
2
|
import createBuildPipeline from './createBuildPipeline.js'
|
|
3
3
|
|
|
4
|
-
export { buildDts, config, createBuildPipeline }
|
|
4
|
+
export { buildAllDts, buildDts, config, createBuildPipeline }
|
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
mockReaddirSync,
|
|
8
8
|
mockCreateBuildPipeline,
|
|
9
9
|
mockRolldownConfig,
|
|
10
|
-
|
|
10
|
+
mockBuildAllDts,
|
|
11
11
|
} = vi.hoisted(() => ({
|
|
12
12
|
mockRolldown: vi.fn(),
|
|
13
13
|
mockBundleWrite: vi.fn(),
|
|
@@ -15,7 +15,7 @@ const {
|
|
|
15
15
|
mockReaddirSync: vi.fn(),
|
|
16
16
|
mockCreateBuildPipeline: vi.fn(),
|
|
17
17
|
mockRolldownConfig: vi.fn(),
|
|
18
|
-
|
|
18
|
+
mockBuildAllDts: vi.fn(),
|
|
19
19
|
}))
|
|
20
20
|
|
|
21
21
|
vi.mock('rolldown', () => ({ rolldown: mockRolldown }))
|
|
@@ -25,6 +25,7 @@ vi.mock('node:fs', () => ({
|
|
|
25
25
|
renameSync: vi.fn(),
|
|
26
26
|
statSync: vi.fn(),
|
|
27
27
|
unlinkSync: vi.fn(),
|
|
28
|
+
cpSync: vi.fn(),
|
|
28
29
|
}))
|
|
29
30
|
|
|
30
31
|
vi.mock('../config/index.js', () => ({
|
|
@@ -35,7 +36,7 @@ vi.mock('../config/index.js', () => ({
|
|
|
35
36
|
vi.mock('../rolldown/index.js', () => ({
|
|
36
37
|
createBuildPipeline: mockCreateBuildPipeline,
|
|
37
38
|
config: mockRolldownConfig,
|
|
38
|
-
|
|
39
|
+
buildAllDts: mockBuildAllDts,
|
|
39
40
|
}))
|
|
40
41
|
|
|
41
42
|
describe('build', () => {
|
|
@@ -66,7 +67,7 @@ describe('build', () => {
|
|
|
66
67
|
format: item.format,
|
|
67
68
|
},
|
|
68
69
|
}))
|
|
69
|
-
|
|
70
|
+
mockBuildAllDts.mockReturnValue([])
|
|
70
71
|
})
|
|
71
72
|
|
|
72
73
|
it('should execute build pipeline successfully', async () => {
|
|
@@ -80,16 +81,18 @@ describe('build', () => {
|
|
|
80
81
|
expect(mockBundleClose).toHaveBeenCalled()
|
|
81
82
|
})
|
|
82
83
|
|
|
83
|
-
it('should generate DTS when
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
it('should generate DTS when buildAllDts returns configs', async () => {
|
|
85
|
+
mockBuildAllDts.mockReturnValue([
|
|
86
|
+
{
|
|
87
|
+
file: './lib/index.d.ts',
|
|
88
|
+
input: 'src/index.ts',
|
|
89
|
+
output: {
|
|
90
|
+
dir: 'lib',
|
|
91
|
+
entryFileNames: 'index.d.ts',
|
|
92
|
+
format: 'es',
|
|
93
|
+
},
|
|
91
94
|
},
|
|
92
|
-
|
|
95
|
+
])
|
|
93
96
|
|
|
94
97
|
vi.resetModules()
|
|
95
98
|
const { runBuild } = await import('./build.js')
|
|
@@ -111,15 +114,17 @@ describe('build', () => {
|
|
|
111
114
|
format: item.format,
|
|
112
115
|
},
|
|
113
116
|
}))
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
mockBuildAllDts.mockReturnValue([
|
|
118
|
+
{
|
|
119
|
+
file: './lib/index.d.ts',
|
|
120
|
+
input: 'src/index.ts',
|
|
121
|
+
output: {
|
|
122
|
+
dir: 'lib',
|
|
123
|
+
entryFileNames: 'index.d.ts',
|
|
124
|
+
format: 'es',
|
|
125
|
+
},
|
|
121
126
|
},
|
|
122
|
-
|
|
127
|
+
])
|
|
123
128
|
|
|
124
129
|
await runBuild()
|
|
125
130
|
|
|
@@ -128,15 +133,17 @@ describe('build', () => {
|
|
|
128
133
|
})
|
|
129
134
|
|
|
130
135
|
it('should handle DTS chunk consolidation', async () => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
mockBuildAllDts.mockReturnValue([
|
|
137
|
+
{
|
|
138
|
+
file: './lib/index.d.ts',
|
|
139
|
+
input: 'src/index.ts',
|
|
140
|
+
output: {
|
|
141
|
+
dir: 'lib',
|
|
142
|
+
entryFileNames: 'index.d.ts',
|
|
143
|
+
format: 'es',
|
|
144
|
+
},
|
|
138
145
|
},
|
|
139
|
-
|
|
146
|
+
])
|
|
140
147
|
|
|
141
148
|
vi.resetModules()
|
|
142
149
|
const { runBuild } = await import('./build.js')
|
|
@@ -158,15 +165,17 @@ describe('build', () => {
|
|
|
158
165
|
format: item.format,
|
|
159
166
|
},
|
|
160
167
|
}))
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
mockBuildAllDts.mockReturnValue([
|
|
169
|
+
{
|
|
170
|
+
file: './lib/index.d.ts',
|
|
171
|
+
input: 'src/index.ts',
|
|
172
|
+
output: {
|
|
173
|
+
dir: 'lib',
|
|
174
|
+
entryFileNames: 'index.d.ts',
|
|
175
|
+
format: 'es',
|
|
176
|
+
},
|
|
168
177
|
},
|
|
169
|
-
|
|
178
|
+
])
|
|
170
179
|
mockReaddirSync.mockReturnValue(['chunk-abc.d.ts'])
|
|
171
180
|
vi.mocked(statSync).mockImplementation((p: any) => {
|
|
172
181
|
if (String(p).includes('chunk'))
|
|
@@ -196,7 +205,7 @@ describe('build', () => {
|
|
|
196
205
|
format: item.format,
|
|
197
206
|
},
|
|
198
207
|
}))
|
|
199
|
-
|
|
208
|
+
mockBuildAllDts.mockReturnValue([])
|
|
200
209
|
|
|
201
210
|
await expect(runBuild()).rejects.toThrow('rolldown failed')
|
|
202
211
|
})
|
|
@@ -236,11 +245,79 @@ describe('build', () => {
|
|
|
236
245
|
format: item.format,
|
|
237
246
|
},
|
|
238
247
|
}))
|
|
239
|
-
|
|
248
|
+
mockBuildAllDts.mockReturnValue([])
|
|
240
249
|
|
|
241
250
|
await runBuild()
|
|
242
251
|
|
|
243
252
|
expect(mockRolldownConfig).toHaveBeenCalledTimes(2)
|
|
244
253
|
expect(mockRolldown).toHaveBeenCalledTimes(2)
|
|
245
254
|
})
|
|
255
|
+
|
|
256
|
+
it('should generate multiple DTS for subpath exports', async () => {
|
|
257
|
+
mockBuildAllDts.mockReturnValue([
|
|
258
|
+
{
|
|
259
|
+
file: './lib/types/index.d.ts',
|
|
260
|
+
input: 'src/index.ts',
|
|
261
|
+
output: {
|
|
262
|
+
dir: 'lib/types',
|
|
263
|
+
entryFileNames: 'index.d.ts',
|
|
264
|
+
format: 'es',
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
file: './lib/types/devtools/index.d.ts',
|
|
269
|
+
input: 'src/devtools/index.ts',
|
|
270
|
+
output: {
|
|
271
|
+
dir: 'lib/types/devtools',
|
|
272
|
+
entryFileNames: 'index.d.ts',
|
|
273
|
+
format: 'es',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
])
|
|
277
|
+
|
|
278
|
+
vi.resetModules()
|
|
279
|
+
const { runBuild } = await import('./build.js')
|
|
280
|
+
vi.clearAllMocks()
|
|
281
|
+
|
|
282
|
+
mockRolldown.mockResolvedValue({
|
|
283
|
+
write: mockBundleWrite,
|
|
284
|
+
close: mockBundleClose,
|
|
285
|
+
})
|
|
286
|
+
mockBundleWrite.mockResolvedValue(undefined)
|
|
287
|
+
mockBundleClose.mockResolvedValue(undefined)
|
|
288
|
+
mockReaddirSync.mockReturnValue([])
|
|
289
|
+
mockRolldownConfig.mockImplementation((item: any) => ({
|
|
290
|
+
input: 'src',
|
|
291
|
+
output: {
|
|
292
|
+
dir: 'lib',
|
|
293
|
+
entryFileNames: 'index.js',
|
|
294
|
+
format: item.format,
|
|
295
|
+
},
|
|
296
|
+
}))
|
|
297
|
+
mockBuildAllDts.mockReturnValue([
|
|
298
|
+
{
|
|
299
|
+
file: './lib/types/index.d.ts',
|
|
300
|
+
input: 'src/index.ts',
|
|
301
|
+
output: {
|
|
302
|
+
dir: 'lib/types',
|
|
303
|
+
entryFileNames: 'index.d.ts',
|
|
304
|
+
format: 'es',
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
file: './lib/types/devtools/index.d.ts',
|
|
309
|
+
input: 'src/devtools/index.ts',
|
|
310
|
+
output: {
|
|
311
|
+
dir: 'lib/types/devtools',
|
|
312
|
+
entryFileNames: 'index.d.ts',
|
|
313
|
+
format: 'es',
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
])
|
|
317
|
+
|
|
318
|
+
await runBuild()
|
|
319
|
+
|
|
320
|
+
// 1 main build + 2 DTS builds = 3 rolldown calls
|
|
321
|
+
expect(mockRolldown).toHaveBeenCalledTimes(3)
|
|
322
|
+
})
|
|
246
323
|
})
|
package/src/scripts/build.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { rimraf } from 'rimraf'
|
|
|
5
5
|
import { rolldown } from 'rolldown'
|
|
6
6
|
import { CONFIG, PKG } from '../config/index.js'
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
buildAllDts,
|
|
9
9
|
createBuildPipeline,
|
|
10
10
|
config as rolldownConfig,
|
|
11
11
|
} from '../rolldown/index.js'
|
|
@@ -104,20 +104,22 @@ const fixDtsCodeSplit = (outDir: string, entryName: string) => {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
const generateDeclarations = async () => {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
107
|
+
const dtsConfigs = buildAllDts()
|
|
108
|
+
if (dtsConfigs.length === 0) return
|
|
109
109
|
|
|
110
110
|
log(`\n${dim('Generating')} declarations...`)
|
|
111
|
-
const tscStart = performance.now()
|
|
112
111
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
for (const dtsFile of dtsConfigs) {
|
|
113
|
+
const tscStart = performance.now()
|
|
114
|
+
const { output, file, ...input } = dtsFile
|
|
115
|
+
await build({ inputOptions: input, outputOptions: output })
|
|
116
|
+
fixDtsCodeSplit(output.dir as string, output.entryFileNames as string)
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
const tscDuration = Math.round(performance.now() - tscStart)
|
|
119
|
+
log(
|
|
120
|
+
` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`,
|
|
121
|
+
)
|
|
122
|
+
}
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
const runBuild = async () => {
|