robuild 0.0.12 → 0.0.14
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/README.md +1 -1
- package/dist/_chunks/build-Ck2ABQml.mjs +3 -0
- package/dist/_chunks/{build-BFnZNGy3.mjs → build-Dtx2Wt3D.mjs} +189 -581
- package/dist/_chunks/{config-BDpkh_pL.d.mts → config-BOcpEsqS.d.mts} +0 -26
- package/dist/_chunks/{package-cVx6ZWao.mjs → package-Bz3LfrXJ.mjs} +4 -4
- package/dist/cli.mjs +2 -13
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +4 -4
- /package/dist/_chunks/{config-B_2eqpNJ.mjs → config-C1aXyI1S.mjs} +0 -0
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ English | <a href="./README-zh.md">简体中文</a>
|
|
|
21
21
|
🎯 **TypeScript**: First-class TypeScript support with `.d.ts` generation
|
|
22
22
|
🔄 **Dual mode**: Bundle or transform your source code
|
|
23
23
|
🚀 **Stub mode**: Lightning-fast development with file linking
|
|
24
|
-
|
|
24
|
+
📤 **Exports**: Automatic package.json exports generation
|
|
25
25
|
|
|
26
26
|
## Installation
|
|
27
27
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { builtinModules } from "node:module";
|
|
2
2
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
import { consola } from "consola";
|
|
5
4
|
import { colors } from "consola/utils";
|
|
6
5
|
import prettyBytes from "pretty-bytes";
|
|
7
6
|
import { cp, mkdir, readFile, readdir, symlink, writeFile } from "node:fs/promises";
|
|
7
|
+
import { consola } from "consola";
|
|
8
8
|
import { defu } from "defu";
|
|
9
9
|
import { resolveModulePath } from "exsolve";
|
|
10
10
|
import { parseSync } from "oxc-parser";
|
|
11
|
-
import { rolldown } from "rolldown";
|
|
11
|
+
import { rolldown, watch } from "rolldown";
|
|
12
12
|
import { dts } from "rolldown-plugin-dts";
|
|
13
13
|
import { existsSync, promises, readdirSync, statSync } from "node:fs";
|
|
14
14
|
import { glob } from "glob";
|
|
@@ -20,18 +20,27 @@ import { transform } from "oxc-transform";
|
|
|
20
20
|
import { glob as glob$1 } from "tinyglobby";
|
|
21
21
|
import { exec } from "node:child_process";
|
|
22
22
|
import { promisify } from "node:util";
|
|
23
|
-
import { watch } from "chokidar";
|
|
24
|
-
import "minimatch";
|
|
25
23
|
|
|
26
24
|
//#region src/features/advanced-build.ts
|
|
27
25
|
/**
|
|
28
26
|
* Create skip node_modules plugin
|
|
29
27
|
*/
|
|
30
|
-
function createSkipNodeModulesPlugin() {
|
|
28
|
+
function createSkipNodeModulesPlugin(options) {
|
|
29
|
+
const noExternalPatterns = options?.noExternal || [];
|
|
30
|
+
const shouldInline = (id) => {
|
|
31
|
+
for (const pattern of noExternalPatterns) if (typeof pattern === "string") {
|
|
32
|
+
if (id === pattern || id.startsWith(`${pattern}/`)) return true;
|
|
33
|
+
} else if (pattern instanceof RegExp) {
|
|
34
|
+
if (pattern.test(id)) return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
31
38
|
return {
|
|
32
39
|
name: "skip-node-modules",
|
|
33
40
|
resolveId: async (id, importer) => {
|
|
34
|
-
if (
|
|
41
|
+
if (shouldInline(id)) return null;
|
|
42
|
+
if (!importer) return null;
|
|
43
|
+
if (id.includes("node_modules") || !id.startsWith(".") && !id.startsWith("/") && !id.startsWith("\\")) return {
|
|
35
44
|
id,
|
|
36
45
|
external: true
|
|
37
46
|
};
|
|
@@ -43,7 +52,7 @@ function createSkipNodeModulesPlugin() {
|
|
|
43
52
|
* Unbundle mode: preserve file structure without bundling
|
|
44
53
|
*/
|
|
45
54
|
async function unbundleTransform(ctx, entry) {
|
|
46
|
-
const inputDir = join(ctx.pkgDir, entry.input);
|
|
55
|
+
const inputDir = isAbsolute(entry.input) ? entry.input : join(ctx.pkgDir, entry.input);
|
|
47
56
|
const outputDir = join(ctx.pkgDir, entry.outDir || "dist");
|
|
48
57
|
await processDirectoryUnbundled(inputDir, outputDir, entry);
|
|
49
58
|
}
|
|
@@ -91,7 +100,7 @@ async function processFileUnbundled(inputPath, outputPath, entry) {
|
|
|
91
100
|
/**
|
|
92
101
|
* Transform imports for unbundle mode
|
|
93
102
|
*/
|
|
94
|
-
function transformImportsForUnbundle(content,
|
|
103
|
+
function transformImportsForUnbundle(content, _filePath, entry) {
|
|
95
104
|
let transformedContent = content;
|
|
96
105
|
transformedContent = transformedContent.replace(/from\s+['"]([^'"]+)['"]/g, (match, importPath) => {
|
|
97
106
|
if (importPath.startsWith(".")) {
|
|
@@ -221,11 +230,11 @@ function createGlobImportPlugin(options = {}) {
|
|
|
221
230
|
let transformedCode = code;
|
|
222
231
|
while ((match = globImportRegex.exec(code)) !== null) {
|
|
223
232
|
hasGlobImports = true;
|
|
224
|
-
const [fullMatch,
|
|
233
|
+
const [fullMatch, , pattern, optionsStr] = match;
|
|
225
234
|
let globOptions = {};
|
|
226
235
|
if (optionsStr) try {
|
|
227
236
|
globOptions = parseGlobOptions(optionsStr);
|
|
228
|
-
} catch
|
|
237
|
+
} catch {
|
|
229
238
|
console.warn("Failed to parse glob options:", optionsStr);
|
|
230
239
|
}
|
|
231
240
|
const isEager = globOptions.eager ?? eager;
|
|
@@ -251,7 +260,7 @@ async function generateGlobImport(pattern, importer, eager, asUrls, allowedPatte
|
|
|
251
260
|
try {
|
|
252
261
|
const absolutePattern = resolve(importerDir, pattern);
|
|
253
262
|
files = await glob(absolutePattern, { ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
254
|
-
} catch
|
|
263
|
+
} catch {
|
|
255
264
|
if (pattern.includes("*.js")) files = [resolve(importerDir, pattern.replace("*", "module1")), resolve(importerDir, pattern.replace("*", "module2"))];
|
|
256
265
|
}
|
|
257
266
|
if (eager) return generateEagerImport(files, importerDir, asUrls);
|
|
@@ -335,7 +344,7 @@ function addHashToFilename(filename, content, hashLength = 8) {
|
|
|
335
344
|
* Check if filename already has hash
|
|
336
345
|
*/
|
|
337
346
|
function hasHash(filename) {
|
|
338
|
-
return /-[a-f0-9]{8}(
|
|
347
|
+
return /-[a-f0-9]{8}(?:\.|$)/.test(filename);
|
|
339
348
|
}
|
|
340
349
|
|
|
341
350
|
//#endregion
|
|
@@ -401,7 +410,12 @@ async function transformWithLoader(filePath, content, loader, options) {
|
|
|
401
410
|
case "jsx":
|
|
402
411
|
case "ts":
|
|
403
412
|
case "tsx": return content;
|
|
404
|
-
case "json":
|
|
413
|
+
case "json": try {
|
|
414
|
+
const parsed = JSON.parse(content);
|
|
415
|
+
return `export default ${JSON.stringify(parsed)}`;
|
|
416
|
+
} catch {
|
|
417
|
+
return `export default ${JSON.stringify(content)}`;
|
|
418
|
+
}
|
|
405
419
|
case "css": return transformCssContent(content, options);
|
|
406
420
|
case "text": return `export default ${JSON.stringify(content)}`;
|
|
407
421
|
case "file": return transformFileContent(filePath, options);
|
|
@@ -437,7 +451,7 @@ function transformFileContent(filePath, options) {
|
|
|
437
451
|
/**
|
|
438
452
|
* Transform file content to data URL
|
|
439
453
|
*/
|
|
440
|
-
function transformDataUrlContent(filePath, content,
|
|
454
|
+
function transformDataUrlContent(filePath, content, _options) {
|
|
441
455
|
const ext = extname(filePath).toLowerCase();
|
|
442
456
|
const mimeType = getMimeType(ext);
|
|
443
457
|
const base64 = Buffer.from(content).toString("base64");
|
|
@@ -447,7 +461,7 @@ function transformDataUrlContent(filePath, content, options) {
|
|
|
447
461
|
/**
|
|
448
462
|
* Transform binary file content
|
|
449
463
|
*/
|
|
450
|
-
function transformBinaryContent(filePath,
|
|
464
|
+
function transformBinaryContent(filePath, _options) {
|
|
451
465
|
const fileName = filePath.split("/").pop() || "binary";
|
|
452
466
|
return `export default ${JSON.stringify(fileName)}`;
|
|
453
467
|
}
|
|
@@ -457,7 +471,7 @@ function transformBinaryContent(filePath, options) {
|
|
|
457
471
|
function extractCssClassNames(content) {
|
|
458
472
|
const classRegex = /\.([a-z_-][\w-]*)/gi;
|
|
459
473
|
const matches = content.match(classRegex) || [];
|
|
460
|
-
return
|
|
474
|
+
return Array.from(new Set(matches.map((match) => match.slice(1))));
|
|
461
475
|
}
|
|
462
476
|
/**
|
|
463
477
|
* Get MIME type for file extension
|
|
@@ -498,13 +512,15 @@ function createLoaderPlugin(loaders) {
|
|
|
498
512
|
return {
|
|
499
513
|
name: "loaders",
|
|
500
514
|
load: async (id) => {
|
|
515
|
+
const ext = extname(id);
|
|
501
516
|
const loader = getLoaderForFile(id, loaders);
|
|
502
517
|
if (loader === "js" || loader === "jsx" || loader === "ts" || loader === "tsx") return null;
|
|
518
|
+
if (loader === "json" && !loaders?.[ext]) return null;
|
|
503
519
|
try {
|
|
504
520
|
const content = await readFile(id, "utf-8");
|
|
505
|
-
const options = loaders?.[
|
|
521
|
+
const options = loaders?.[ext]?.options;
|
|
506
522
|
return await transformWithLoader(id, content, loader, options);
|
|
507
|
-
} catch
|
|
523
|
+
} catch {
|
|
508
524
|
return null;
|
|
509
525
|
}
|
|
510
526
|
}
|
|
@@ -732,7 +748,7 @@ function createShimsPlugin(config = true) {
|
|
|
732
748
|
return {
|
|
733
749
|
name: "shims",
|
|
734
750
|
transform: async (code, id) => {
|
|
735
|
-
if (!/\.(js|mjs|cjs|ts|mts|cts|jsx|tsx)$/.test(id)) return null;
|
|
751
|
+
if (!/\.(?:js|mjs|cjs|ts|mts|cts|jsx|tsx)$/.test(id)) return null;
|
|
736
752
|
const needs = detectShimNeeds(code);
|
|
737
753
|
if (!needs.needsDirname && !needs.needsRequire && !needs.needsExports && !needs.needsEnv) return null;
|
|
738
754
|
const transformedCode = transformWithShims(code, shimsConfig);
|
|
@@ -741,88 +757,6 @@ function createShimsPlugin(config = true) {
|
|
|
741
757
|
};
|
|
742
758
|
}
|
|
743
759
|
|
|
744
|
-
//#endregion
|
|
745
|
-
//#region src/utils.ts
|
|
746
|
-
function fmtPath(path) {
|
|
747
|
-
return resolve(path).replace(process.cwd(), ".");
|
|
748
|
-
}
|
|
749
|
-
function analyzeDir(dir) {
|
|
750
|
-
if (Array.isArray(dir)) {
|
|
751
|
-
let totalSize$1 = 0;
|
|
752
|
-
let totalFiles = 0;
|
|
753
|
-
for (const d of dir) {
|
|
754
|
-
const { size, files: files$1 } = analyzeDir(d);
|
|
755
|
-
totalSize$1 += size;
|
|
756
|
-
totalFiles += files$1;
|
|
757
|
-
}
|
|
758
|
-
return {
|
|
759
|
-
size: totalSize$1,
|
|
760
|
-
files: totalFiles
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
let totalSize = 0;
|
|
764
|
-
const files = readdirSync(dir, {
|
|
765
|
-
withFileTypes: true,
|
|
766
|
-
recursive: true
|
|
767
|
-
});
|
|
768
|
-
for (const file of files) {
|
|
769
|
-
const fullPath = join(file.parentPath, file.name);
|
|
770
|
-
if (file.isFile()) {
|
|
771
|
-
const { size } = statSync(fullPath);
|
|
772
|
-
totalSize += size;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
return {
|
|
776
|
-
size: totalSize,
|
|
777
|
-
files: files.length
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
async function distSize(dir, entry) {
|
|
781
|
-
const build$1 = await rolldown({
|
|
782
|
-
input: join(dir, entry),
|
|
783
|
-
plugins: [],
|
|
784
|
-
platform: "neutral",
|
|
785
|
-
external: (id) => id[0] !== "." && !id.startsWith(dir)
|
|
786
|
-
});
|
|
787
|
-
const { output } = await build$1.generate({ inlineDynamicImports: true });
|
|
788
|
-
const code = output[0].code;
|
|
789
|
-
const { code: minified } = await minify(entry, code);
|
|
790
|
-
return {
|
|
791
|
-
size: Buffer.byteLength(code),
|
|
792
|
-
minSize: Buffer.byteLength(minified),
|
|
793
|
-
minGzipSize: gzipSync(minified).length
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
async function sideEffectSize(dir, entry) {
|
|
797
|
-
const virtualEntry = {
|
|
798
|
-
name: "virtual-entry",
|
|
799
|
-
async resolveId(id, importer, opts) {
|
|
800
|
-
if (id === "#entry") return { id };
|
|
801
|
-
const resolved = await this.resolve(id, importer, opts);
|
|
802
|
-
if (!resolved) return null;
|
|
803
|
-
resolved.moduleSideEffects = null;
|
|
804
|
-
return resolved;
|
|
805
|
-
},
|
|
806
|
-
load(id) {
|
|
807
|
-
if (id === "#entry") return `import * as _lib from "${join(dir, entry)}";`;
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
const build$1 = await rolldown({
|
|
811
|
-
input: "#entry",
|
|
812
|
-
platform: "neutral",
|
|
813
|
-
external: (id) => id[0] !== "." && !id.startsWith(dir),
|
|
814
|
-
plugins: [virtualEntry]
|
|
815
|
-
});
|
|
816
|
-
const { output } = await build$1.generate({ inlineDynamicImports: true });
|
|
817
|
-
if (process.env.INSPECT_BUILD) {
|
|
818
|
-
console.log("---------[side effects]---------");
|
|
819
|
-
console.log(entry);
|
|
820
|
-
console.log(output[0].code);
|
|
821
|
-
console.log("-------------------------------");
|
|
822
|
-
}
|
|
823
|
-
return Buffer.byteLength(output[0].code.trim());
|
|
824
|
-
}
|
|
825
|
-
|
|
826
760
|
//#endregion
|
|
827
761
|
//#region src/features/node-protocol.ts
|
|
828
762
|
/**
|
|
@@ -915,7 +849,7 @@ function transformNodeProtocol(code, nodeProtocol) {
|
|
|
915
849
|
}
|
|
916
850
|
|
|
917
851
|
//#endregion
|
|
918
|
-
//#region src/
|
|
852
|
+
//#region src/plugins/node-protocol.ts
|
|
919
853
|
/**
|
|
920
854
|
* Rolldown plugin for Node.js protocol handling
|
|
921
855
|
*/
|
|
@@ -933,7 +867,7 @@ function nodeProtocolPlugin(nodeProtocol) {
|
|
|
933
867
|
}
|
|
934
868
|
|
|
935
869
|
//#endregion
|
|
936
|
-
//#region src/
|
|
870
|
+
//#region src/plugins/shebang.ts
|
|
937
871
|
const SHEBANG_RE = /^#![^\n]*/;
|
|
938
872
|
function shebangPlugin() {
|
|
939
873
|
return {
|
|
@@ -956,6 +890,88 @@ async function makeExecutable(filePath) {
|
|
|
956
890
|
await promises.chmod(filePath, 493).catch(() => {});
|
|
957
891
|
}
|
|
958
892
|
|
|
893
|
+
//#endregion
|
|
894
|
+
//#region src/utils.ts
|
|
895
|
+
function fmtPath(path) {
|
|
896
|
+
return resolve(path).replace(process.cwd(), ".");
|
|
897
|
+
}
|
|
898
|
+
function analyzeDir(dir) {
|
|
899
|
+
if (Array.isArray(dir)) {
|
|
900
|
+
let totalSize$1 = 0;
|
|
901
|
+
let totalFiles = 0;
|
|
902
|
+
for (const d of dir) {
|
|
903
|
+
const { size, files: files$1 } = analyzeDir(d);
|
|
904
|
+
totalSize$1 += size;
|
|
905
|
+
totalFiles += files$1;
|
|
906
|
+
}
|
|
907
|
+
return {
|
|
908
|
+
size: totalSize$1,
|
|
909
|
+
files: totalFiles
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
let totalSize = 0;
|
|
913
|
+
const files = readdirSync(dir, {
|
|
914
|
+
withFileTypes: true,
|
|
915
|
+
recursive: true
|
|
916
|
+
});
|
|
917
|
+
for (const file of files) {
|
|
918
|
+
const fullPath = join(file.parentPath, file.name);
|
|
919
|
+
if (file.isFile()) {
|
|
920
|
+
const { size } = statSync(fullPath);
|
|
921
|
+
totalSize += size;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return {
|
|
925
|
+
size: totalSize,
|
|
926
|
+
files: files.length
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
async function distSize(dir, entry) {
|
|
930
|
+
const build$1 = await rolldown({
|
|
931
|
+
input: join(dir, entry),
|
|
932
|
+
plugins: [],
|
|
933
|
+
platform: "neutral",
|
|
934
|
+
external: (id) => id[0] !== "." && !id.startsWith(dir)
|
|
935
|
+
});
|
|
936
|
+
const { output } = await build$1.generate({ inlineDynamicImports: true });
|
|
937
|
+
const code = output[0].code;
|
|
938
|
+
const { code: minified } = minify(entry, code);
|
|
939
|
+
return {
|
|
940
|
+
size: Buffer.byteLength(code),
|
|
941
|
+
minSize: Buffer.byteLength(minified),
|
|
942
|
+
minGzipSize: gzipSync(minified).length
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
async function sideEffectSize(dir, entry) {
|
|
946
|
+
const virtualEntry = {
|
|
947
|
+
name: "virtual-entry",
|
|
948
|
+
async resolveId(id, importer, opts) {
|
|
949
|
+
if (id === "#entry") return { id };
|
|
950
|
+
const resolved = await this.resolve(id, importer, opts);
|
|
951
|
+
if (!resolved) return null;
|
|
952
|
+
resolved.moduleSideEffects = null;
|
|
953
|
+
return resolved;
|
|
954
|
+
},
|
|
955
|
+
load(id) {
|
|
956
|
+
if (id === "#entry") return `import * as _lib from "${join(dir, entry)}";`;
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
const build$1 = await rolldown({
|
|
960
|
+
input: "#entry",
|
|
961
|
+
platform: "neutral",
|
|
962
|
+
external: (id) => id[0] !== "." && !id.startsWith(dir),
|
|
963
|
+
plugins: [virtualEntry]
|
|
964
|
+
});
|
|
965
|
+
const { output } = await build$1.generate({ inlineDynamicImports: true });
|
|
966
|
+
if (process.env.INSPECT_BUILD) {
|
|
967
|
+
console.log("---------[side effects]---------");
|
|
968
|
+
console.log(entry);
|
|
969
|
+
console.log(output[0].code);
|
|
970
|
+
console.log("-------------------------------");
|
|
971
|
+
}
|
|
972
|
+
return Buffer.byteLength(output[0].code.trim());
|
|
973
|
+
}
|
|
974
|
+
|
|
959
975
|
//#endregion
|
|
960
976
|
//#region src/builders/bundle.ts
|
|
961
977
|
/**
|
|
@@ -1060,7 +1076,7 @@ async function rolldownBuild(ctx, entry, hooks, config) {
|
|
|
1060
1076
|
externalDeps = externalDeps.filter((dep) => {
|
|
1061
1077
|
if (typeof dep === "string") return !excludedNames.has(dep);
|
|
1062
1078
|
if (dep instanceof RegExp) {
|
|
1063
|
-
for (const name of excludedNames) if (dep.source.startsWith(`^${escapeRegExp(name)}/`)) return false;
|
|
1079
|
+
for (const name of Array.from(excludedNames)) if (dep.source.startsWith(`^${escapeRegExp(name)}/`)) return false;
|
|
1064
1080
|
return true;
|
|
1065
1081
|
}
|
|
1066
1082
|
return true;
|
|
@@ -1119,7 +1135,7 @@ async function rolldownBuild(ctx, entry, hooks, config) {
|
|
|
1119
1135
|
});
|
|
1120
1136
|
}
|
|
1121
1137
|
if (entry.skipNodeModules) {
|
|
1122
|
-
const skipPlugin = createSkipNodeModulesPlugin();
|
|
1138
|
+
const skipPlugin = createSkipNodeModulesPlugin({ noExternal: ["@oxc-project/runtime"] });
|
|
1123
1139
|
if (skipPlugin.resolveId) rolldownPlugins.push({
|
|
1124
1140
|
name: "skip-node-modules",
|
|
1125
1141
|
resolveId: skipPlugin.resolveId
|
|
@@ -1489,176 +1505,6 @@ async function transformModule(entryPath, entry) {
|
|
|
1489
1505
|
return transformed;
|
|
1490
1506
|
}
|
|
1491
1507
|
|
|
1492
|
-
//#endregion
|
|
1493
|
-
//#region src/features/exports.ts
|
|
1494
|
-
/**
|
|
1495
|
-
* Generate package.json exports field based on build configuration
|
|
1496
|
-
*/
|
|
1497
|
-
async function generatePackageExports(packageRoot, buildConfig, exportsConfig = { enabled: true }) {
|
|
1498
|
-
if (!exportsConfig.enabled) return {};
|
|
1499
|
-
const exports = {};
|
|
1500
|
-
const baseDir = exportsConfig.baseDir || "dist";
|
|
1501
|
-
if (exportsConfig.custom) Object.assign(exports, exportsConfig.custom);
|
|
1502
|
-
if (buildConfig.entries) for (const entry of buildConfig.entries) {
|
|
1503
|
-
const exportEntries = await generateExportFromEntry(packageRoot, entry, baseDir, exportsConfig.includeTypes);
|
|
1504
|
-
for (const exportEntry of exportEntries) exports[exportEntry.key] = createExportValue(exportEntry);
|
|
1505
|
-
}
|
|
1506
|
-
if (!exports["."] && !exports["./index"]) {
|
|
1507
|
-
const mainExport = await findMainExport(packageRoot, baseDir);
|
|
1508
|
-
if (mainExport) exports["."] = mainExport;
|
|
1509
|
-
}
|
|
1510
|
-
return exports;
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Generate export entries from a build entry
|
|
1514
|
-
*/
|
|
1515
|
-
async function generateExportFromEntry(packageRoot, entry, baseDir, includeTypes) {
|
|
1516
|
-
const exports = [];
|
|
1517
|
-
if (entry.type === "bundle") {
|
|
1518
|
-
const exportKey = getExportKey(entry.input);
|
|
1519
|
-
const exportEntry = { key: exportKey };
|
|
1520
|
-
if (Array.isArray(entry.format)) for (const format of entry.format) {
|
|
1521
|
-
const outputPath = getOutputPath(entry, format, baseDir);
|
|
1522
|
-
assignFormatToExport(exportEntry, format, outputPath);
|
|
1523
|
-
}
|
|
1524
|
-
else if (entry.format) {
|
|
1525
|
-
const outputPath = getOutputPath(entry, entry.format, baseDir);
|
|
1526
|
-
assignFormatToExport(exportEntry, entry.format, outputPath);
|
|
1527
|
-
}
|
|
1528
|
-
if (includeTypes && entry.dts) {
|
|
1529
|
-
const typesPath = getTypesPath(entry, baseDir);
|
|
1530
|
-
exportEntry.types = typesPath;
|
|
1531
|
-
}
|
|
1532
|
-
exports.push(exportEntry);
|
|
1533
|
-
} else if (entry.type === "transform") {
|
|
1534
|
-
const transformExports = await discoverTransformExports(packageRoot, entry, baseDir, includeTypes);
|
|
1535
|
-
exports.push(...transformExports);
|
|
1536
|
-
}
|
|
1537
|
-
return exports;
|
|
1538
|
-
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Get export key from input path
|
|
1541
|
-
*/
|
|
1542
|
-
function getExportKey(input) {
|
|
1543
|
-
if (input === "index.ts" || input === "src/index.ts") return ".";
|
|
1544
|
-
let key = input.replace(/\.(ts|js|tsx|jsx)$/, "");
|
|
1545
|
-
key = key.replace(/^src\//, "");
|
|
1546
|
-
return key === "index" ? "." : `./${key}`;
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Get output path for a specific format
|
|
1550
|
-
*/
|
|
1551
|
-
function getOutputPath(entry, format, baseDir) {
|
|
1552
|
-
const extension = getExtensionForFormat(format);
|
|
1553
|
-
const basename$1 = getBasename(entry.input);
|
|
1554
|
-
if (format === "cjs") return `./${baseDir}/cjs/${basename$1}${extension}`;
|
|
1555
|
-
else if (format === "esm") return `./${baseDir}/${basename$1}${extension}`;
|
|
1556
|
-
else return `./${baseDir}/${format}/${basename$1}${extension}`;
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Get file extension for format
|
|
1560
|
-
*/
|
|
1561
|
-
function getExtensionForFormat(format) {
|
|
1562
|
-
switch (format) {
|
|
1563
|
-
case "esm": return ".mjs";
|
|
1564
|
-
case "cjs": return ".cjs";
|
|
1565
|
-
case "iife":
|
|
1566
|
-
case "umd": return ".js";
|
|
1567
|
-
default: return ".js";
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* Get basename from input path
|
|
1572
|
-
*/
|
|
1573
|
-
function getBasename(input) {
|
|
1574
|
-
return input.replace(/\.(ts|js|tsx|jsx)$/, "").replace(/^src\//, "");
|
|
1575
|
-
}
|
|
1576
|
-
/**
|
|
1577
|
-
* Get types path for entry
|
|
1578
|
-
*/
|
|
1579
|
-
function getTypesPath(entry, baseDir) {
|
|
1580
|
-
const basename$1 = getBasename(entry.input);
|
|
1581
|
-
return `./${baseDir}/${basename$1}.d.ts`;
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Assign format-specific path to export entry
|
|
1585
|
-
*/
|
|
1586
|
-
function assignFormatToExport(exportEntry, format, path) {
|
|
1587
|
-
switch (format) {
|
|
1588
|
-
case "esm":
|
|
1589
|
-
exportEntry.import = path;
|
|
1590
|
-
break;
|
|
1591
|
-
case "cjs":
|
|
1592
|
-
exportEntry.require = path;
|
|
1593
|
-
break;
|
|
1594
|
-
default:
|
|
1595
|
-
exportEntry.import = path;
|
|
1596
|
-
break;
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
/**
|
|
1600
|
-
* Create export value from export entry
|
|
1601
|
-
*/
|
|
1602
|
-
function createExportValue(entry) {
|
|
1603
|
-
const value = {};
|
|
1604
|
-
if (entry.types) value.types = entry.types;
|
|
1605
|
-
if (entry.import) value.import = entry.import;
|
|
1606
|
-
if (entry.require) value.require = entry.require;
|
|
1607
|
-
const keys = Object.keys(value);
|
|
1608
|
-
if (keys.length === 1 && !entry.types) return value[keys[0]];
|
|
1609
|
-
return value;
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Discover exports from transform entries
|
|
1613
|
-
*/
|
|
1614
|
-
async function discoverTransformExports(packageRoot, entry, baseDir, includeTypes) {
|
|
1615
|
-
const exports = [];
|
|
1616
|
-
const exportKey = getExportKey(entry.input);
|
|
1617
|
-
const exportEntry = {
|
|
1618
|
-
key: exportKey,
|
|
1619
|
-
import: `./${baseDir}/${getBasename(entry.input)}.mjs`
|
|
1620
|
-
};
|
|
1621
|
-
if (includeTypes && entry.dts) exportEntry.types = getTypesPath(entry, baseDir);
|
|
1622
|
-
exports.push(exportEntry);
|
|
1623
|
-
return exports;
|
|
1624
|
-
}
|
|
1625
|
-
/**
|
|
1626
|
-
* Find main export file
|
|
1627
|
-
*/
|
|
1628
|
-
async function findMainExport(packageRoot, baseDir) {
|
|
1629
|
-
const possibleMains = [
|
|
1630
|
-
"index.mjs",
|
|
1631
|
-
"index.js",
|
|
1632
|
-
"index.cjs"
|
|
1633
|
-
];
|
|
1634
|
-
for (const main of possibleMains) try {
|
|
1635
|
-
join(packageRoot, baseDir, main);
|
|
1636
|
-
const value = {};
|
|
1637
|
-
if (main.endsWith(".mjs")) value.import = `./${baseDir}/${main}`;
|
|
1638
|
-
else if (main.endsWith(".cjs")) value.require = `./${baseDir}/${main}`;
|
|
1639
|
-
else value.import = `./${baseDir}/${main}`;
|
|
1640
|
-
return value;
|
|
1641
|
-
} catch {
|
|
1642
|
-
continue;
|
|
1643
|
-
}
|
|
1644
|
-
return null;
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* Update package.json with generated exports
|
|
1648
|
-
*/
|
|
1649
|
-
async function updatePackageJsonExports(packageRoot, exports) {
|
|
1650
|
-
const packageJsonPath = join(packageRoot, "package.json");
|
|
1651
|
-
try {
|
|
1652
|
-
const content = await readFile(packageJsonPath, "utf-8");
|
|
1653
|
-
const packageJson = JSON.parse(content);
|
|
1654
|
-
packageJson.exports = exports;
|
|
1655
|
-
const updatedContent = `${JSON.stringify(packageJson, null, 2)}\n`;
|
|
1656
|
-
await writeFile(packageJsonPath, updatedContent, "utf-8");
|
|
1657
|
-
} catch (error) {
|
|
1658
|
-
throw new Error(`Failed to update package.json: ${error}`);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
1508
|
//#endregion
|
|
1663
1509
|
//#region src/features/logger.ts
|
|
1664
1510
|
/**
|
|
@@ -1894,263 +1740,80 @@ function convertExternal(external) {
|
|
|
1894
1740
|
}
|
|
1895
1741
|
|
|
1896
1742
|
//#endregion
|
|
1897
|
-
//#region src/
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
*/
|
|
1901
|
-
async function discoverWorkspacePackages(workspaceRoot, patterns = ["packages/*", "apps/*"]) {
|
|
1902
|
-
const packages = [];
|
|
1903
|
-
for (const pattern of patterns) {
|
|
1904
|
-
const packagePaths = await glob(pattern, {
|
|
1905
|
-
cwd: workspaceRoot,
|
|
1906
|
-
onlyDirectories: true
|
|
1907
|
-
});
|
|
1908
|
-
for (const packagePath of packagePaths) {
|
|
1909
|
-
const fullPath = resolve(workspaceRoot, packagePath);
|
|
1910
|
-
const packageJsonPath = join(fullPath, "package.json");
|
|
1911
|
-
try {
|
|
1912
|
-
const packageJsonContent = await readFile(packageJsonPath, "utf-8");
|
|
1913
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1914
|
-
packages.push({
|
|
1915
|
-
name: packageJson.name || packagePath,
|
|
1916
|
-
path: fullPath,
|
|
1917
|
-
packageJson
|
|
1918
|
-
});
|
|
1919
|
-
} catch {
|
|
1920
|
-
continue;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
return packages;
|
|
1925
|
-
}
|
|
1926
|
-
/**
|
|
1927
|
-
* Filter workspace packages based on filter patterns
|
|
1928
|
-
*/
|
|
1929
|
-
function filterWorkspacePackages(packages, filter, exclude) {
|
|
1930
|
-
let filtered = packages;
|
|
1931
|
-
if (filter) {
|
|
1932
|
-
const filters = Array.isArray(filter) ? filter : [filter];
|
|
1933
|
-
filtered = filtered.filter((pkg) => filters.some((f) => matchesPattern(pkg.name, f) || matchesPattern(pkg.path, f)));
|
|
1934
|
-
}
|
|
1935
|
-
if (exclude) {
|
|
1936
|
-
const excludes = Array.isArray(exclude) ? exclude : [exclude];
|
|
1937
|
-
filtered = filtered.filter((pkg) => !excludes.some((e) => matchesPattern(pkg.name, e) || matchesPattern(pkg.path, e)));
|
|
1938
|
-
}
|
|
1939
|
-
return filtered;
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* Check if a string matches a pattern (supports wildcards)
|
|
1943
|
-
*/
|
|
1944
|
-
function matchesPattern(str, pattern) {
|
|
1945
|
-
const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".").replace(/\[([^\]]+)\]/g, "[$1]");
|
|
1946
|
-
const regex = /* @__PURE__ */ new RegExp(`^${regexPattern}$`);
|
|
1947
|
-
return regex.test(str);
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Load workspace configuration from package.json or workspace config file
|
|
1951
|
-
*/
|
|
1952
|
-
async function loadWorkspaceConfig(workspaceRoot) {
|
|
1953
|
-
try {
|
|
1954
|
-
const packageJsonPath = join(workspaceRoot, "package.json");
|
|
1955
|
-
const packageJsonContent = await readFile(packageJsonPath, "utf-8");
|
|
1956
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1957
|
-
if (packageJson.workspaces) {
|
|
1958
|
-
const workspaces = Array.isArray(packageJson.workspaces) ? packageJson.workspaces : packageJson.workspaces.packages || [];
|
|
1959
|
-
return { packages: workspaces };
|
|
1960
|
-
}
|
|
1961
|
-
try {
|
|
1962
|
-
const { load } = await import("js-yaml");
|
|
1963
|
-
const pnpmWorkspacePath = join(workspaceRoot, "pnpm-workspace.yaml");
|
|
1964
|
-
const pnpmWorkspaceContent = await readFile(pnpmWorkspacePath, "utf-8");
|
|
1965
|
-
const pnpmWorkspace = load(pnpmWorkspaceContent);
|
|
1966
|
-
if (pnpmWorkspace?.packages) return { packages: pnpmWorkspace.packages };
|
|
1967
|
-
} catch {}
|
|
1968
|
-
try {
|
|
1969
|
-
const lernaJsonPath = join(workspaceRoot, "lerna.json");
|
|
1970
|
-
const lernaJsonContent = await readFile(lernaJsonPath, "utf-8");
|
|
1971
|
-
const lernaJson = JSON.parse(lernaJsonContent);
|
|
1972
|
-
if (lernaJson.packages) return { packages: lernaJson.packages };
|
|
1973
|
-
} catch {}
|
|
1974
|
-
return null;
|
|
1975
|
-
} catch {
|
|
1976
|
-
return null;
|
|
1977
|
-
}
|
|
1743
|
+
//#region src/watch.ts
|
|
1744
|
+
function normalizePath$1(path, resolveFrom) {
|
|
1745
|
+
return typeof path === "string" && isAbsolute(path) ? path : path instanceof URL ? fileURLToPath(path) : resolve(resolveFrom || ".", path || ".");
|
|
1978
1746
|
}
|
|
1979
1747
|
/**
|
|
1980
|
-
*
|
|
1748
|
+
* Perform watch build using rolldown's built-in watch mode
|
|
1981
1749
|
*/
|
|
1982
|
-
async function
|
|
1983
|
-
await
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
/**
|
|
1989
|
-
* Normalize ignore patterns
|
|
1990
|
-
*/
|
|
1991
|
-
function normalizeIgnorePatterns(patterns) {
|
|
1992
|
-
return patterns.map((pattern) => {
|
|
1993
|
-
if (pattern.startsWith("./")) return pattern.slice(2);
|
|
1994
|
-
if (pattern.startsWith("/")) return pattern.slice(1);
|
|
1995
|
-
return pattern;
|
|
1996
|
-
});
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1999
|
-
//#endregion
|
|
2000
|
-
//#region src/watch.ts
|
|
2001
|
-
/**
|
|
2002
|
-
* Start watching files and rebuild on changes
|
|
2003
|
-
*/
|
|
2004
|
-
async function startWatch(config, ctx, buildFn) {
|
|
2005
|
-
const watchOptions = config.watch || {};
|
|
2006
|
-
if (!watchOptions.enabled) throw new Error("Watch mode is not enabled");
|
|
2007
|
-
const watchCtx = {
|
|
2008
|
-
config,
|
|
2009
|
-
ctx,
|
|
2010
|
-
buildFn,
|
|
2011
|
-
isBuilding: false,
|
|
2012
|
-
pendingRebuild: false
|
|
2013
|
-
};
|
|
2014
|
-
const watchPatterns = await getWatchPatterns(config, ctx, watchOptions);
|
|
2015
|
-
const ignorePatterns = getIgnorePatterns(config, watchOptions);
|
|
2016
|
-
consola.info(`👀 Starting watch mode...`);
|
|
2017
|
-
consola.info(`📁 Watching: ${colors.dim(watchPatterns.join(", "))}`);
|
|
2018
|
-
if (ignorePatterns.length > 0) consola.info(`🚫 Ignoring: ${colors.dim(ignorePatterns.join(", "))}`);
|
|
2019
|
-
const delay = watchOptions.delay ?? 100;
|
|
2020
|
-
if (delay > 0) consola.info(`⏱️ Rebuild delay: ${colors.dim(`${delay}ms`)}`);
|
|
2021
|
-
const watcher = watch(watchPatterns, {
|
|
2022
|
-
ignored: ignorePatterns,
|
|
2023
|
-
ignoreInitial: watchOptions.ignoreInitial ?? false,
|
|
2024
|
-
persistent: true,
|
|
2025
|
-
followSymlinks: false,
|
|
2026
|
-
cwd: ctx.pkgDir
|
|
2027
|
-
});
|
|
2028
|
-
watcher.on("change", (path) => handleFileChange(watchCtx, path, "changed"));
|
|
2029
|
-
watcher.on("add", (path) => {
|
|
2030
|
-
if (watchOptions.watchNewFiles !== false) handleFileChange(watchCtx, path, "added");
|
|
1750
|
+
async function performWatchBuild(config, ctx, startTime) {
|
|
1751
|
+
const { performBuild: performBuild$1 } = await import("./build-Ck2ABQml.mjs");
|
|
1752
|
+
await performBuild$1(config, ctx, startTime);
|
|
1753
|
+
const bundleEntries = (config.entries || []).filter((entry) => {
|
|
1754
|
+
if (typeof entry === "string") return !entry.endsWith("/");
|
|
1755
|
+
return entry.type === "bundle";
|
|
2031
1756
|
});
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
if (process.env.DEBUG) {
|
|
2037
|
-
watcher.on("addDir", (path) => consola.debug(`📁 Directory added: ${path}`));
|
|
2038
|
-
watcher.on("unlinkDir", (path) => consola.debug(`📁 Directory removed: ${path}`));
|
|
1757
|
+
if (bundleEntries.length > 0) await startRolldownWatch(ctx, bundleEntries);
|
|
1758
|
+
else {
|
|
1759
|
+
logger.warn("Transform-only watch mode not yet implemented with rolldown");
|
|
1760
|
+
return new Promise(() => {});
|
|
2039
1761
|
}
|
|
2040
|
-
await new Promise((resolve$1) => {
|
|
2041
|
-
watcher.on("ready", () => {
|
|
2042
|
-
const watchedPaths = watcher.getWatched();
|
|
2043
|
-
const totalFiles = Object.values(watchedPaths).reduce((sum, files) => sum + files.length, 0);
|
|
2044
|
-
consola.success(`🚀 Watch mode ready - watching ${totalFiles} files`);
|
|
2045
|
-
consola.info(`💡 Press ${colors.cyan("Ctrl+C")} to stop watching`);
|
|
2046
|
-
resolve$1();
|
|
2047
|
-
});
|
|
2048
|
-
});
|
|
2049
|
-
return () => {
|
|
2050
|
-
if (watchCtx.rebuildTimer) clearTimeout(watchCtx.rebuildTimer);
|
|
2051
|
-
return watcher.close();
|
|
2052
|
-
};
|
|
2053
1762
|
}
|
|
2054
1763
|
/**
|
|
2055
|
-
*
|
|
1764
|
+
* Start rolldown watch mode for bundle entries
|
|
2056
1765
|
*/
|
|
2057
|
-
function
|
|
2058
|
-
|
|
2059
|
-
const
|
|
2060
|
-
const
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
if (watchCtx.isBuilding) return;
|
|
2077
|
-
if (!watchCtx.pendingRebuild) return;
|
|
2078
|
-
watchCtx.isBuilding = true;
|
|
2079
|
-
watchCtx.pendingRebuild = false;
|
|
2080
|
-
try {
|
|
2081
|
-
consola.info(`🔄 Rebuilding...`);
|
|
2082
|
-
const start = Date.now();
|
|
2083
|
-
const buildConfig = {
|
|
2084
|
-
...config,
|
|
2085
|
-
watch: {
|
|
2086
|
-
...config.watch,
|
|
2087
|
-
enabled: false
|
|
1766
|
+
async function startRolldownWatch(ctx, bundleEntries) {
|
|
1767
|
+
logger.info("🚧 Using rolldown built-in watch mode...");
|
|
1768
|
+
const watchConfigs = [];
|
|
1769
|
+
for (const rawEntry of bundleEntries) {
|
|
1770
|
+
let entry;
|
|
1771
|
+
if (typeof rawEntry === "string") {
|
|
1772
|
+
const [input, outDir] = rawEntry.split(":");
|
|
1773
|
+
entry = {
|
|
1774
|
+
type: "bundle",
|
|
1775
|
+
input,
|
|
1776
|
+
outDir: outDir || "dist"
|
|
1777
|
+
};
|
|
1778
|
+
} else entry = rawEntry;
|
|
1779
|
+
entry.input = Array.isArray(entry.input) ? entry.input.map((i) => normalizePath$1(i, ctx.pkgDir)) : normalizePath$1(entry.input, ctx.pkgDir);
|
|
1780
|
+
const watchConfig = {
|
|
1781
|
+
input: Array.isArray(entry.input) ? entry.input[0] : entry.input,
|
|
1782
|
+
output: {
|
|
1783
|
+
dir: entry.outDir,
|
|
1784
|
+
format: "esm"
|
|
2088
1785
|
}
|
|
2089
1786
|
};
|
|
2090
|
-
|
|
2091
|
-
const duration = Date.now() - start;
|
|
2092
|
-
consola.success(`✅ Rebuild completed in ${duration}ms`);
|
|
2093
|
-
} catch (error) {
|
|
2094
|
-
consola.error("❌ Rebuild failed:");
|
|
2095
|
-
if (error instanceof Error) {
|
|
2096
|
-
consola.error(` ${error.message}`);
|
|
2097
|
-
if (process.env.DEBUG && error.stack) consola.debug(error.stack);
|
|
2098
|
-
} else consola.error(` ${String(error)}`);
|
|
2099
|
-
consola.info("👀 Still watching for changes...");
|
|
2100
|
-
} finally {
|
|
2101
|
-
watchCtx.isBuilding = false;
|
|
2102
|
-
if (watchCtx.pendingRebuild) setTimeout(() => triggerRebuild(watchCtx), watchCtx.config.watch?.delay ?? 100);
|
|
1787
|
+
watchConfigs.push(watchConfig);
|
|
2103
1788
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
} else if (entry.type === "transform") patterns.push(`${entry.input}/**/*`);
|
|
2123
|
-
else {
|
|
2124
|
-
const inputs = Array.isArray(entry.input) ? entry.input : [entry.input];
|
|
2125
|
-
for (const inputFile of inputs) {
|
|
2126
|
-
patterns.push(inputFile);
|
|
2127
|
-
const dir = inputFile.substring(0, inputFile.lastIndexOf("/"));
|
|
2128
|
-
if (dir) patterns.push(`${dir}/**/*`);
|
|
1789
|
+
const watcher = watch(watchConfigs);
|
|
1790
|
+
watcher.on("event", (event) => {
|
|
1791
|
+
switch (event.code) {
|
|
1792
|
+
case "START":
|
|
1793
|
+
logger.info("🔄 Rebuilding...");
|
|
1794
|
+
break;
|
|
1795
|
+
case "BUNDLE_START":
|
|
1796
|
+
logger.info("📦 Bundling...");
|
|
1797
|
+
break;
|
|
1798
|
+
case "BUNDLE_END":
|
|
1799
|
+
logger.success("✅ Bundle complete");
|
|
1800
|
+
break;
|
|
1801
|
+
case "END":
|
|
1802
|
+
logger.success("🎉 Watch rebuild complete");
|
|
1803
|
+
break;
|
|
1804
|
+
case "ERROR":
|
|
1805
|
+
logger.error("❌ Build error:", event.error);
|
|
1806
|
+
break;
|
|
2129
1807
|
}
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
"**/node_modules/**",
|
|
2140
|
-
"**/dist/**",
|
|
2141
|
-
"**/build/**",
|
|
2142
|
-
"**/coverage/**",
|
|
2143
|
-
"**/.git/**",
|
|
2144
|
-
"**/.DS_Store",
|
|
2145
|
-
"**/Thumbs.db",
|
|
2146
|
-
"**/*.log",
|
|
2147
|
-
"**/tmp/**",
|
|
2148
|
-
"**/temp/**"
|
|
2149
|
-
];
|
|
2150
|
-
const allIgnores = [...defaultIgnores];
|
|
2151
|
-
if (watchOptions.exclude && watchOptions.exclude.length > 0) allIgnores.push(...watchOptions.exclude);
|
|
2152
|
-
if (config.ignoreWatch && config.ignoreWatch.length > 0) allIgnores.push(...normalizeIgnorePatterns(config.ignoreWatch));
|
|
2153
|
-
return allIgnores;
|
|
1808
|
+
});
|
|
1809
|
+
const cleanup = async () => {
|
|
1810
|
+
consola.info("🛑 Stopping watch mode...");
|
|
1811
|
+
await watcher.close();
|
|
1812
|
+
process.exit(0);
|
|
1813
|
+
};
|
|
1814
|
+
process.on("SIGINT", cleanup);
|
|
1815
|
+
process.on("SIGTERM", cleanup);
|
|
1816
|
+
return new Promise(() => {});
|
|
2154
1817
|
}
|
|
2155
1818
|
|
|
2156
1819
|
//#endregion
|
|
@@ -2168,7 +1831,6 @@ async function build(config) {
|
|
|
2168
1831
|
pkg,
|
|
2169
1832
|
pkgDir
|
|
2170
1833
|
};
|
|
2171
|
-
if (config.workspace) return buildWorkspace(config, pkgDir);
|
|
2172
1834
|
let finalConfig = config;
|
|
2173
1835
|
if (config.fromVite) {
|
|
2174
1836
|
logger.verbose("Loading configuration from Vite config file");
|
|
@@ -2180,16 +1842,8 @@ async function build(config) {
|
|
|
2180
1842
|
}
|
|
2181
1843
|
if (finalConfig.watch?.enabled) {
|
|
2182
1844
|
logger.info(`👀 Starting watch mode for \`${ctx.pkg.name || "<no name>"}\` (\`${ctx.pkgDir}\`)`);
|
|
2183
|
-
await
|
|
2184
|
-
|
|
2185
|
-
const cleanup = () => {
|
|
2186
|
-
consola.info("🛑 Stopping watch mode...");
|
|
2187
|
-
stopWatch();
|
|
2188
|
-
process.exit(0);
|
|
2189
|
-
};
|
|
2190
|
-
process.on("SIGINT", cleanup);
|
|
2191
|
-
process.on("SIGTERM", cleanup);
|
|
2192
|
-
return new Promise(() => {});
|
|
1845
|
+
await performWatchBuild(finalConfig, ctx, startTime);
|
|
1846
|
+
return;
|
|
2193
1847
|
}
|
|
2194
1848
|
logger.info(`📦 Building \`${ctx.pkg.name || "<no name>"}\` (\`${ctx.pkgDir}\`)`);
|
|
2195
1849
|
await performBuild(finalConfig, ctx, startTime);
|
|
@@ -2239,56 +1893,10 @@ async function performBuild(config, ctx, startTime) {
|
|
|
2239
1893
|
function normalizePath(path, resolveFrom) {
|
|
2240
1894
|
return typeof path === "string" && isAbsolute(path) ? path : path instanceof URL ? fileURLToPath(path) : resolve(resolveFrom || ".", path || ".");
|
|
2241
1895
|
}
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
async function buildWorkspace(config, workspaceRoot) {
|
|
2246
|
-
logger.info("🏢 Building workspace packages...");
|
|
2247
|
-
const workspaceConfig = await loadWorkspaceConfig(workspaceRoot);
|
|
2248
|
-
if (!workspaceConfig) throw new Error("No workspace configuration found");
|
|
2249
|
-
const allPackages = await discoverWorkspacePackages(workspaceRoot, workspaceConfig.packages);
|
|
2250
|
-
if (allPackages.length === 0) {
|
|
2251
|
-
logger.warn("No packages found in workspace");
|
|
2252
|
-
return;
|
|
2253
|
-
}
|
|
2254
|
-
const filteredPackages = filterWorkspacePackages(allPackages, config.filter || config.workspace?.filter, config.workspace?.exclude);
|
|
2255
|
-
if (filteredPackages.length === 0) {
|
|
2256
|
-
logger.warn("No packages match the filter criteria");
|
|
2257
|
-
return;
|
|
2258
|
-
}
|
|
2259
|
-
logger.info(`Building ${filteredPackages.length} packages`);
|
|
2260
|
-
const buildPackage = async (pkg) => {
|
|
2261
|
-
logger.info(`📦 Building ${pkg.name}...`);
|
|
2262
|
-
try {
|
|
2263
|
-
const packageConfig = {
|
|
2264
|
-
...config,
|
|
2265
|
-
cwd: pkg.path,
|
|
2266
|
-
workspace: void 0
|
|
2267
|
-
};
|
|
2268
|
-
await build(packageConfig);
|
|
2269
|
-
if (config.exports?.enabled) {
|
|
2270
|
-
const exportsConfig = {
|
|
2271
|
-
enabled: true,
|
|
2272
|
-
...config.exports
|
|
2273
|
-
};
|
|
2274
|
-
const exports = await generatePackageExports(pkg.path, packageConfig, exportsConfig);
|
|
2275
|
-
if (config.exports.autoUpdate) {
|
|
2276
|
-
await updatePackageJsonExports(pkg.path, exports);
|
|
2277
|
-
logger.info(`Updated exports for ${pkg.name}`);
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
logger.success(`Built ${pkg.name}`);
|
|
2281
|
-
} catch (error) {
|
|
2282
|
-
logger.error(`Failed to build ${pkg.name}:`, error);
|
|
2283
|
-
throw error;
|
|
2284
|
-
}
|
|
2285
|
-
};
|
|
2286
|
-
await buildWorkspacePackages(filteredPackages, buildPackage);
|
|
2287
|
-
logger.success(`Successfully built ${filteredPackages.length} packages`);
|
|
2288
|
-
}
|
|
2289
|
-
function readJSON(specifier) {
|
|
2290
|
-
return import(specifier, { with: { type: "json" } }).then((r) => r.default);
|
|
1896
|
+
async function readJSON(specifier) {
|
|
1897
|
+
const module = await import(specifier, { with: { type: "json" } });
|
|
1898
|
+
return module.default;
|
|
2291
1899
|
}
|
|
2292
1900
|
|
|
2293
1901
|
//#endregion
|
|
2294
|
-
export { build };
|
|
1902
|
+
export { build, performBuild };
|
|
@@ -445,35 +445,9 @@ interface BuildConfig {
|
|
|
445
445
|
*/
|
|
446
446
|
fromVite?: boolean;
|
|
447
447
|
/**
|
|
448
|
-
* Workspace configuration for monorepo support.
|
|
449
|
-
*/
|
|
450
|
-
workspace?: WorkspaceConfig;
|
|
451
|
-
/**
|
|
452
448
|
* Package exports generation configuration.
|
|
453
449
|
*/
|
|
454
450
|
exports?: ExportsConfig;
|
|
455
|
-
/**
|
|
456
|
-
* Package filter for workspace builds.
|
|
457
|
-
*/
|
|
458
|
-
filter?: string | string[];
|
|
459
|
-
}
|
|
460
|
-
interface WorkspaceConfig {
|
|
461
|
-
/**
|
|
462
|
-
* Workspace package patterns.
|
|
463
|
-
*/
|
|
464
|
-
packages?: string[];
|
|
465
|
-
/**
|
|
466
|
-
* Package filter patterns.
|
|
467
|
-
*/
|
|
468
|
-
filter?: string | string[];
|
|
469
|
-
/**
|
|
470
|
-
* Package exclude patterns.
|
|
471
|
-
*/
|
|
472
|
-
exclude?: string | string[];
|
|
473
|
-
/**
|
|
474
|
-
* Build packages in dependency order.
|
|
475
|
-
*/
|
|
476
|
-
dependencyOrder?: boolean;
|
|
477
451
|
}
|
|
478
452
|
interface ExportsConfig {
|
|
479
453
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region package.json
|
|
2
2
|
var name = "robuild";
|
|
3
3
|
var type = "module";
|
|
4
|
-
var version = "0.0.
|
|
4
|
+
var version = "0.0.14";
|
|
5
5
|
var packageManager = "pnpm@10.11.1";
|
|
6
6
|
var description = "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc";
|
|
7
7
|
var license = "MIT";
|
|
@@ -15,8 +15,8 @@ var types = "./dist/index.d.mts";
|
|
|
15
15
|
var bin = "./dist/cli.mjs";
|
|
16
16
|
var files = ["dist"];
|
|
17
17
|
var scripts = {
|
|
18
|
-
"build": "pnpm robuild",
|
|
19
|
-
"dev": "pnpm
|
|
18
|
+
"build": "pnpm test:types && pnpm robuild",
|
|
19
|
+
"dev": "pnpm test",
|
|
20
20
|
"lint": "eslint .",
|
|
21
21
|
"lint:fix": "automd && eslint . --fix",
|
|
22
22
|
"robuild": "esno src/cli.ts",
|
|
@@ -24,7 +24,7 @@ var scripts = {
|
|
|
24
24
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
25
25
|
"test": "vitest run",
|
|
26
26
|
"test:watch": "vitest",
|
|
27
|
-
"test:types": "tsc --noEmit --skipLibCheck",
|
|
27
|
+
"test:types": "tsc --noEmit --skipLibCheck src/**/*.ts",
|
|
28
28
|
"docs:dev": "vitepress dev docs",
|
|
29
29
|
"docs:build": "vitepress build docs",
|
|
30
30
|
"docs:preview": "vitepress preview docs",
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { build } from "./_chunks/build-
|
|
2
|
+
import { build } from "./_chunks/build-Dtx2Wt3D.mjs";
|
|
3
3
|
import { consola } from "consola";
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
import { loadConfig } from "c12";
|
|
@@ -50,11 +50,6 @@ const args = parseArgs({
|
|
|
50
50
|
multiple: true
|
|
51
51
|
},
|
|
52
52
|
"from-vite": { type: "boolean" },
|
|
53
|
-
"workspace": { type: "boolean" },
|
|
54
|
-
"filter": {
|
|
55
|
-
type: "string",
|
|
56
|
-
multiple: true
|
|
57
|
-
},
|
|
58
53
|
"generate-exports": { type: "boolean" },
|
|
59
54
|
"cjs-default": { type: "string" },
|
|
60
55
|
"shims": { type: "boolean" },
|
|
@@ -85,8 +80,7 @@ Options:
|
|
|
85
80
|
--fail-on-warn Fail build on warnings
|
|
86
81
|
--ignore-watch <pattern> Ignore patterns in watch mode (can be used multiple times)
|
|
87
82
|
--from-vite Load configuration from Vite config file
|
|
88
|
-
|
|
89
|
-
--filter <pattern> Filter workspace packages by name or path pattern (can be used multiple times)
|
|
83
|
+
|
|
90
84
|
--generate-exports Generate package.json exports field
|
|
91
85
|
--cjs-default <mode> CommonJS default export handling: true, false, auto (default: auto)
|
|
92
86
|
--shims Enable CJS/ESM compatibility shims
|
|
@@ -168,11 +162,6 @@ if (args.values["on-success"]) buildConfig.onSuccess = args.values["on-success"]
|
|
|
168
162
|
if (args.values["fail-on-warn"]) buildConfig.failOnWarn = true;
|
|
169
163
|
if (args.values["ignore-watch"]) buildConfig.ignoreWatch = args.values["ignore-watch"];
|
|
170
164
|
if (args.values["from-vite"]) buildConfig.fromVite = true;
|
|
171
|
-
if (args.values.workspace) buildConfig.workspace = {
|
|
172
|
-
packages: ["packages/*", "apps/*"],
|
|
173
|
-
...config.workspace
|
|
174
|
-
};
|
|
175
|
-
if (args.values.filter) buildConfig.filter = args.values.filter;
|
|
176
165
|
if (args.values["generate-exports"]) buildConfig.exports = {
|
|
177
166
|
enabled: true,
|
|
178
167
|
includeTypes: true,
|
package/dist/config.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { defineConfig } from "./_chunks/config-
|
|
1
|
+
import { defineConfig } from "./_chunks/config-BOcpEsqS.mjs";
|
|
2
2
|
export { defineConfig };
|
package/dist/config.mjs
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { build } from "./_chunks/build-
|
|
2
|
-
import { defineConfig } from "./_chunks/config-
|
|
1
|
+
import { build } from "./_chunks/build-Dtx2Wt3D.mjs";
|
|
2
|
+
import { defineConfig } from "./_chunks/config-C1aXyI1S.mjs";
|
|
3
3
|
|
|
4
4
|
export { build, defineConfig };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "robuild",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.14",
|
|
5
5
|
"packageManager": "pnpm@10.11.1",
|
|
6
6
|
"description": "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc",
|
|
7
7
|
"license": "MIT",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "pnpm robuild",
|
|
21
|
-
"dev": "pnpm
|
|
20
|
+
"build": "pnpm test:types && pnpm robuild",
|
|
21
|
+
"dev": "pnpm test",
|
|
22
22
|
"lint": "eslint .",
|
|
23
23
|
"lint:fix": "automd && eslint . --fix",
|
|
24
24
|
"robuild": "esno src/cli.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
27
27
|
"test": "vitest run",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
|
-
"test:types": "tsc --noEmit --skipLibCheck",
|
|
29
|
+
"test:types": "tsc --noEmit --skipLibCheck src/**/*.ts",
|
|
30
30
|
"docs:dev": "vitepress dev docs",
|
|
31
31
|
"docs:build": "vitepress build docs",
|
|
32
32
|
"docs:preview": "vitepress preview docs",
|
|
File without changes
|