@b9g/libuild 0.1.19 → 0.1.21

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 CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.21] - 2025-12-22
6
+
7
+ ### Fixed
8
+ - **Internal module .d.ts generation** - Fixed issue where .d.ts files were not generated for internal modules (e.g., `src/impl/utils.ts`), causing broken import paths in published packages. TypeScript now follows imports to generate declarations for all modules, not just entry points.
9
+ - **Module augmentation in .d.ts** - Fixed `declare module` blocks (module augmentation) not appearing in published type definitions. This resolves [#1](https://github.com/bikeshaving/libuild/issues/1).
10
+ - **Symlink path consistency** - Fixed path mismatches on macOS where `/tmp` symlinks to `/private/tmp`, which could cause .d.ts files to be emitted to wrong locations.
11
+
12
+ ### Changed
13
+ - **Chunk files location** - ESM code splitting chunks are now placed in `dist/src/_chunks/` instead of the dist root, keeping the package structure cleaner.
14
+
15
+ ## [0.1.20] - 2025-12-08
16
+
17
+ ### Fixed
18
+ - **Ambient .d.ts export validation** - Fixed validation error when using `--save` with ambient .d.ts files. The build now correctly handles both `./src/` and `./dist/src/` paths for ambient declarations in exports.
19
+
5
20
  ## [0.1.19] - 2025-12-08
6
21
 
7
22
  ### Added
package/README.md CHANGED
@@ -44,7 +44,9 @@ libuild publish
44
44
  - **Structure-preserving**: `src/index.ts` → `dist/src/index.js` (maintains src/ directory)
45
45
  - **ESM**: `.js` files with ES module syntax
46
46
  - **CommonJS**: `.cjs` files for Node.js compatibility
47
- - **TypeScript**: `.d.ts` declaration files (when TypeScript is available)
47
+ - **TypeScript**: `.d.ts` declaration files for all modules (when TypeScript is available)
48
+ - **Module augmentation**: `declare module` blocks are preserved in .d.ts output
49
+ - **Code splitting**: Dynamic imports create chunks in `dist/src/_chunks/`
48
50
  - **Clean package.json**: Optimized for consumers (no dev scripts)
49
51
 
50
52
  ### Format Control
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/libuild",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Zero-config library builds",
5
5
  "keywords": [
6
6
  "build",
package/src/libuild.cjs CHANGED
@@ -9561,11 +9561,11 @@ ${lanes.join("\n")}
9561
9561
  return toComponents;
9562
9562
  }
9563
9563
  const components = toComponents.slice(start);
9564
- const relative = [];
9564
+ const relative2 = [];
9565
9565
  for (; start < fromComponents.length; start++) {
9566
- relative.push("..");
9566
+ relative2.push("..");
9567
9567
  }
9568
- return ["", ...relative, ...components];
9568
+ return ["", ...relative2, ...components];
9569
9569
  }
9570
9570
  function getRelativePathFromDirectory(fromDirectory, to, getCanonicalFileNameOrIgnoreCase) {
9571
9571
  Debug.assert(getRootLength(fromDirectory) > 0 === getRootLength(to) > 0, "Paths must either both be absolute or both be relative");
@@ -48268,11 +48268,11 @@ ${lanes.join("\n")}
48268
48268
  if (i < rootLength) {
48269
48269
  return void 0;
48270
48270
  }
48271
- const sep2 = directory.lastIndexOf(directorySeparator, i - 1);
48272
- if (sep2 === -1) {
48271
+ const sep3 = directory.lastIndexOf(directorySeparator, i - 1);
48272
+ if (sep3 === -1) {
48273
48273
  return void 0;
48274
48274
  }
48275
- return directory.substr(0, Math.max(sep2, rootLength));
48275
+ return directory.substr(0, Math.max(sep3, rootLength));
48276
48276
  }
48277
48277
  }
48278
48278
  }
@@ -54210,9 +54210,9 @@ ${lanes.join("\n")}
54210
54210
  if (!startsWithDirectory(target, realPathDirectory, getCanonicalFileName)) {
54211
54211
  return;
54212
54212
  }
54213
- const relative = getRelativePathFromDirectory(realPathDirectory, target, getCanonicalFileName);
54213
+ const relative2 = getRelativePathFromDirectory(realPathDirectory, target, getCanonicalFileName);
54214
54214
  for (const symlinkDirectory of symlinkDirectories) {
54215
- const option = resolvePath(symlinkDirectory, relative);
54215
+ const option = resolvePath(symlinkDirectory, relative2);
54216
54216
  const result2 = cb(option, target === referenceRedirect);
54217
54217
  shouldFilterIgnoredPaths = true;
54218
54218
  if (result2)
@@ -124419,7 +124419,7 @@ ${lanes.join("\n")}
124419
124419
  }
124420
124420
  }
124421
124421
  function createImportCallExpressionAMD(arg, containsLexicalThis) {
124422
- const resolve3 = factory2.createUniqueName("resolve");
124422
+ const resolve2 = factory2.createUniqueName("resolve");
124423
124423
  const reject = factory2.createUniqueName("reject");
124424
124424
  const parameters = [
124425
124425
  factory2.createParameterDeclaration(
@@ -124428,7 +124428,7 @@ ${lanes.join("\n")}
124428
124428
  /*dotDotDotToken*/
124429
124429
  void 0,
124430
124430
  /*name*/
124431
- resolve3
124431
+ resolve2
124432
124432
  ),
124433
124433
  factory2.createParameterDeclaration(
124434
124434
  /*modifiers*/
@@ -124445,7 +124445,7 @@ ${lanes.join("\n")}
124445
124445
  factory2.createIdentifier("require"),
124446
124446
  /*typeArguments*/
124447
124447
  void 0,
124448
- [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve3, reject]
124448
+ [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve2, reject]
124449
124449
  )
124450
124450
  )
124451
124451
  ]);
@@ -212324,8 +212324,8 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
212324
212324
  installPackage(options) {
212325
212325
  this.packageInstallId++;
212326
212326
  const request = { kind: "installPackage", ...options, id: this.packageInstallId };
212327
- const promise = new Promise((resolve3, reject) => {
212328
- (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve3, reject });
212327
+ const promise = new Promise((resolve2, reject) => {
212328
+ (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve2, reject });
212329
212329
  });
212330
212330
  this.installer.send(request);
212331
212331
  return promise;
@@ -212725,41 +212725,28 @@ function dtsPlugin(options) {
212725
212725
  } catch (error) {
212726
212726
  return;
212727
212727
  }
212728
- const tsFiles = entryFiles.filter((file) => {
212729
- if (!file.endsWith(".ts"))
212730
- return false;
212731
- return options.entryPoints.some((entryPoint) => {
212732
- try {
212733
- const fs = require("fs");
212734
- const normalizedEntry = fs.realpathSync(Path2.resolve(entryPoint));
212735
- const normalizedFile = fs.realpathSync(Path2.resolve(file));
212736
- return normalizedEntry === normalizedFile;
212737
- } catch {
212738
- const normalizedEntry = Path2.resolve(entryPoint);
212739
- const normalizedFile = Path2.resolve(file);
212740
- return normalizedEntry === normalizedFile;
212741
- }
212742
- });
212743
- });
212728
+ const tsFiles = entryFiles.filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts"));
212744
212729
  if (tsFiles.length === 0) {
212745
212730
  return;
212746
212731
  }
212732
+ await FS2.mkdir(options.outDir, { recursive: true });
212733
+ const fs = await import("fs");
212734
+ const resolvedRootDir = fs.realpathSync(options.rootDir);
212735
+ const resolvedOutDir = fs.realpathSync(options.outDir);
212736
+ const resolvedTsFiles = tsFiles.map((f) => fs.realpathSync(f));
212747
212737
  try {
212748
- await FS2.mkdir(options.outDir, { recursive: true });
212749
212738
  const compilerOptions = {
212750
212739
  declaration: true,
212751
212740
  emitDeclarationOnly: true,
212752
- outDir: options.outDir,
212741
+ outDir: resolvedOutDir,
212742
+ rootDir: resolvedRootDir,
212753
212743
  skipLibCheck: true,
212754
212744
  esModuleInterop: true,
212755
212745
  target: TS.ScriptTarget.ES2020,
212756
212746
  module: TS.ModuleKind.ESNext,
212757
- isolatedModules: true,
212758
- // Prevent cross-file type dependencies
212759
- noResolve: true
212760
- // Don't resolve imports - only process the specific files
212747
+ moduleResolution: TS.ModuleResolutionKind.Bundler
212761
212748
  };
212762
- const program = TS.createProgram(tsFiles, compilerOptions);
212749
+ const program = TS.createProgram(resolvedTsFiles, compilerOptions);
212763
212750
  const emitResult = program.emit();
212764
212751
  if (emitResult.diagnostics.length > 0) {
212765
212752
  const diagnostics = TS.formatDiagnosticsWithColorAndContext(emitResult.diagnostics, {
@@ -212787,17 +212774,20 @@ ${diagnostics}`,
212787
212774
  detail: void 0
212788
212775
  });
212789
212776
  }
212790
- await addTripleSlashReferences(tsFiles, options.outDir);
212791
- await addAmbientReferences(tsFiles, options.outDir, options.rootDir);
212777
+ await addTripleSlashReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
212778
+ await addAmbientReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
212792
212779
  });
212793
212780
  }
212794
212781
  };
212795
212782
  }
212796
- async function addTripleSlashReferences(tsFiles, outDir) {
212783
+ async function addTripleSlashReferences(tsFiles, outDir, rootDir) {
212797
212784
  for (const tsFile of tsFiles) {
212785
+ const relativePath = Path2.relative(rootDir, tsFile);
212786
+ const relativeDir = Path2.dirname(relativePath);
212798
212787
  const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
212799
- const jsPath = Path2.join(outDir, `${baseName}.js`);
212800
- const dtsPath = Path2.join(outDir, `${baseName}.d.ts`);
212788
+ const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
212789
+ const jsPath = Path2.join(outputSubDir, `${baseName}.js`);
212790
+ const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
212801
212791
  const [jsExists, dtsExists] = await Promise.all([
212802
212792
  FS2.access(jsPath).then(() => true).catch(() => false),
212803
212793
  FS2.access(dtsPath).then(() => true).catch(() => false)
@@ -212834,13 +212824,17 @@ async function addAmbientReferences(tsFiles, outDir, rootDir) {
212834
212824
  if (ambientFiles.length === 0)
212835
212825
  return;
212836
212826
  for (const tsFile of tsFiles) {
212827
+ const relativePath = Path2.relative(rootDir, tsFile);
212828
+ const relativeDir = Path2.dirname(relativePath);
212837
212829
  const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
212838
- const dtsPath = Path2.join(outDir, `${baseName}.d.ts`);
212830
+ const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
212831
+ const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
212839
212832
  const dtsExists = await FS2.access(dtsPath).then(() => true).catch(() => false);
212840
212833
  if (!dtsExists)
212841
212834
  continue;
212842
212835
  const content = await FS2.readFile(dtsPath, "utf-8");
212843
- const references = ambientFiles.map((ambientFile) => `/// <reference path="./${ambientFile}" />`).join("\n");
212836
+ const relativeToRoot = relativeDir === "." ? "./" : "../".repeat(relativeDir.split(Path2.sep).length);
212837
+ const references = ambientFiles.map((ambientFile) => `/// <reference path="${relativeToRoot}${ambientFile}" />`).join("\n");
212844
212838
  const modifiedContent = `${references}
212845
212839
  ${content}`;
212846
212840
  await FS2.writeFile(dtsPath, modifiedContent);
@@ -213059,6 +213053,9 @@ async function generateExports(entries, mainEntry, options, existingExports = {}
213059
213053
  if (existing === "./package.json" || existing.endsWith("/package.json")) {
213060
213054
  return existing;
213061
213055
  }
213056
+ if (existing.endsWith(".d.ts") && existing.match(/\.\/(?:dist\/)?src\/[^/]+\.d\.ts$/)) {
213057
+ return existing;
213058
+ }
213062
213059
  const match = existing.match(/\.\/src\/([^/]+\.(?:ts|js))$/);
213063
213060
  if (match) {
213064
213061
  const filename = match[1];
@@ -213697,6 +213694,8 @@ async function build2(cwd, save = false) {
213697
213694
  outdir: distDir,
213698
213695
  outbase: cwd,
213699
213696
  // Preserve src/ and bin/ directory structure
213697
+ chunkNames: "src/_chunks/[name]-[hash]",
213698
+ // Put chunks in a subdirectory
213700
213699
  format: "esm",
213701
213700
  outExtension: { ".js": ".js" },
213702
213701
  bundle: true,
@@ -213729,17 +213728,19 @@ async function build2(cwd, save = false) {
213729
213728
  ]
213730
213729
  });
213731
213730
  if (options.formats.cjs) {
213732
- const distFiles = await FS3.readdir(distDir);
213733
- const chunkFiles = distFiles.filter(
213734
- (f) => f.endsWith(".js") && !f.endsWith(".d.ts") && (f.startsWith("chunk-") || f.includes("-") && !f.startsWith("package"))
213735
- );
213736
- if (chunkFiles.length > 0) {
213737
- console.info(`
213731
+ const chunksDir = Path3.join(distSrcDir, "_chunks");
213732
+ const chunksExist = await FS3.stat(chunksDir).then(() => true, () => false);
213733
+ if (chunksExist) {
213734
+ const chunkFiles = await FS3.readdir(chunksDir);
213735
+ const jsChunks = chunkFiles.filter((f) => f.endsWith(".js"));
213736
+ if (jsChunks.length > 0) {
213737
+ console.info(`
213738
213738
  \u26A0\uFE0F Code splitting detected - CommonJS build will bundle dynamic imports inline`);
213739
- console.info(` ESM build: ${chunkFiles.length} chunk file(s) created for lazy loading`);
213740
- console.info(` CJS build: Dynamic imports bundled inline (no chunks)`);
213741
- console.info(` To get code splitting benefits, use ESM imports or remove "main" field
213739
+ console.info(` ESM build: ${jsChunks.length} chunk file(s) created for lazy loading`);
213740
+ console.info(` CJS build: Dynamic imports bundled inline (no chunks)`);
213741
+ console.info(` To get code splitting benefits, use ESM imports or remove "main" field
213742
213742
  `);
213743
+ }
213743
213744
  }
213744
213745
  }
213745
213746
  if (binEntryPoints.length > 0) {
@@ -213819,14 +213820,14 @@ async function build2(cwd, save = false) {
213819
213820
  console.info(" Generating package.json...");
213820
213821
  const cleanedPkg = await cleanPackageJSON(pkg, mainEntry, options, cwd, distDir);
213821
213822
  const exportsResult = await generateExports(entries, mainEntry, options, pkg.exports, distDir, allBinEntries);
213822
- cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
213823
213823
  for (const dtsFile of ambientDtsFiles) {
213824
213824
  const baseName = Path3.basename(dtsFile, ".d.ts");
213825
213825
  const exportKey = `./${baseName}.d.ts`;
213826
- if (!cleanedPkg.exports[exportKey]) {
213827
- cleanedPkg.exports[exportKey] = `./src/${dtsFile}`;
213826
+ if (!exportsResult.exports[exportKey]) {
213827
+ exportsResult.exports[exportKey] = `./src/${dtsFile}`;
213828
213828
  }
213829
213829
  }
213830
+ cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
213830
213831
  if (exportsResult.staleExports.length > 0) {
213831
213832
  console.warn(`\u26A0\uFE0F WARNING: Found ${exportsResult.staleExports.length} stale export(s) pointing to missing src/ files:`);
213832
213833
  for (const staleExport of exportsResult.staleExports) {
@@ -214078,8 +214079,8 @@ async function publish(cwd, save = true, extraArgs = []) {
214078
214079
  cwd: distDir,
214079
214080
  stdio: "inherit"
214080
214081
  });
214081
- const exitCode = await new Promise((resolve3) => {
214082
- proc.on("close", resolve3);
214082
+ const exitCode = await new Promise((resolve2) => {
214083
+ proc.on("close", resolve2);
214083
214084
  });
214084
214085
  if (exitCode === 0) {
214085
214086
  const distPkg2 = JSON.parse(await FS3.readFile(distPkgPath, "utf-8"));
package/src/libuild.js CHANGED
@@ -1,12 +1,4 @@
1
1
  /// <reference types="./libuild.d.ts" />
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
-
10
2
  // src/libuild.ts
11
3
  import * as FS3 from "fs/promises";
12
4
  import * as Path3 from "path";
@@ -118,41 +110,28 @@ function dtsPlugin(options) {
118
110
  } catch (error) {
119
111
  return;
120
112
  }
121
- const tsFiles = entryFiles.filter((file) => {
122
- if (!file.endsWith(".ts"))
123
- return false;
124
- return options.entryPoints.some((entryPoint) => {
125
- try {
126
- const fs = __require("fs");
127
- const normalizedEntry = fs.realpathSync(Path2.resolve(entryPoint));
128
- const normalizedFile = fs.realpathSync(Path2.resolve(file));
129
- return normalizedEntry === normalizedFile;
130
- } catch {
131
- const normalizedEntry = Path2.resolve(entryPoint);
132
- const normalizedFile = Path2.resolve(file);
133
- return normalizedEntry === normalizedFile;
134
- }
135
- });
136
- });
113
+ const tsFiles = entryFiles.filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts"));
137
114
  if (tsFiles.length === 0) {
138
115
  return;
139
116
  }
117
+ await FS2.mkdir(options.outDir, { recursive: true });
118
+ const fs = await import("fs");
119
+ const resolvedRootDir = fs.realpathSync(options.rootDir);
120
+ const resolvedOutDir = fs.realpathSync(options.outDir);
121
+ const resolvedTsFiles = tsFiles.map((f) => fs.realpathSync(f));
140
122
  try {
141
- await FS2.mkdir(options.outDir, { recursive: true });
142
123
  const compilerOptions = {
143
124
  declaration: true,
144
125
  emitDeclarationOnly: true,
145
- outDir: options.outDir,
126
+ outDir: resolvedOutDir,
127
+ rootDir: resolvedRootDir,
146
128
  skipLibCheck: true,
147
129
  esModuleInterop: true,
148
130
  target: TS.ScriptTarget.ES2020,
149
131
  module: TS.ModuleKind.ESNext,
150
- isolatedModules: true,
151
- // Prevent cross-file type dependencies
152
- noResolve: true
153
- // Don't resolve imports - only process the specific files
132
+ moduleResolution: TS.ModuleResolutionKind.Bundler
154
133
  };
155
- const program = TS.createProgram(tsFiles, compilerOptions);
134
+ const program = TS.createProgram(resolvedTsFiles, compilerOptions);
156
135
  const emitResult = program.emit();
157
136
  if (emitResult.diagnostics.length > 0) {
158
137
  const diagnostics = TS.formatDiagnosticsWithColorAndContext(emitResult.diagnostics, {
@@ -180,17 +159,20 @@ ${diagnostics}`,
180
159
  detail: void 0
181
160
  });
182
161
  }
183
- await addTripleSlashReferences(tsFiles, options.outDir);
184
- await addAmbientReferences(tsFiles, options.outDir, options.rootDir);
162
+ await addTripleSlashReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
163
+ await addAmbientReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
185
164
  });
186
165
  }
187
166
  };
188
167
  }
189
- async function addTripleSlashReferences(tsFiles, outDir) {
168
+ async function addTripleSlashReferences(tsFiles, outDir, rootDir) {
190
169
  for (const tsFile of tsFiles) {
170
+ const relativePath = Path2.relative(rootDir, tsFile);
171
+ const relativeDir = Path2.dirname(relativePath);
191
172
  const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
192
- const jsPath = Path2.join(outDir, `${baseName}.js`);
193
- const dtsPath = Path2.join(outDir, `${baseName}.d.ts`);
173
+ const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
174
+ const jsPath = Path2.join(outputSubDir, `${baseName}.js`);
175
+ const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
194
176
  const [jsExists, dtsExists] = await Promise.all([
195
177
  FS2.access(jsPath).then(() => true).catch(() => false),
196
178
  FS2.access(dtsPath).then(() => true).catch(() => false)
@@ -227,13 +209,17 @@ async function addAmbientReferences(tsFiles, outDir, rootDir) {
227
209
  if (ambientFiles.length === 0)
228
210
  return;
229
211
  for (const tsFile of tsFiles) {
212
+ const relativePath = Path2.relative(rootDir, tsFile);
213
+ const relativeDir = Path2.dirname(relativePath);
230
214
  const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
231
- const dtsPath = Path2.join(outDir, `${baseName}.d.ts`);
215
+ const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
216
+ const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
232
217
  const dtsExists = await FS2.access(dtsPath).then(() => true).catch(() => false);
233
218
  if (!dtsExists)
234
219
  continue;
235
220
  const content = await FS2.readFile(dtsPath, "utf-8");
236
- const references = ambientFiles.map((ambientFile) => `/// <reference path="./${ambientFile}" />`).join("\n");
221
+ const relativeToRoot = relativeDir === "." ? "./" : "../".repeat(relativeDir.split(Path2.sep).length);
222
+ const references = ambientFiles.map((ambientFile) => `/// <reference path="${relativeToRoot}${ambientFile}" />`).join("\n");
237
223
  const modifiedContent = `${references}
238
224
  ${content}`;
239
225
  await FS2.writeFile(dtsPath, modifiedContent);
@@ -452,6 +438,9 @@ async function generateExports(entries, mainEntry, options, existingExports = {}
452
438
  if (existing === "./package.json" || existing.endsWith("/package.json")) {
453
439
  return existing;
454
440
  }
441
+ if (existing.endsWith(".d.ts") && existing.match(/\.\/(?:dist\/)?src\/[^/]+\.d\.ts$/)) {
442
+ return existing;
443
+ }
455
444
  const match = existing.match(/\.\/src\/([^/]+\.(?:ts|js))$/);
456
445
  if (match) {
457
446
  const filename = match[1];
@@ -1090,6 +1079,8 @@ async function build2(cwd, save = false) {
1090
1079
  outdir: distDir,
1091
1080
  outbase: cwd,
1092
1081
  // Preserve src/ and bin/ directory structure
1082
+ chunkNames: "src/_chunks/[name]-[hash]",
1083
+ // Put chunks in a subdirectory
1093
1084
  format: "esm",
1094
1085
  outExtension: { ".js": ".js" },
1095
1086
  bundle: true,
@@ -1122,17 +1113,19 @@ async function build2(cwd, save = false) {
1122
1113
  ]
1123
1114
  });
1124
1115
  if (options.formats.cjs) {
1125
- const distFiles = await FS3.readdir(distDir);
1126
- const chunkFiles = distFiles.filter(
1127
- (f) => f.endsWith(".js") && !f.endsWith(".d.ts") && (f.startsWith("chunk-") || f.includes("-") && !f.startsWith("package"))
1128
- );
1129
- if (chunkFiles.length > 0) {
1130
- console.info(`
1116
+ const chunksDir = Path3.join(distSrcDir, "_chunks");
1117
+ const chunksExist = await FS3.stat(chunksDir).then(() => true, () => false);
1118
+ if (chunksExist) {
1119
+ const chunkFiles = await FS3.readdir(chunksDir);
1120
+ const jsChunks = chunkFiles.filter((f) => f.endsWith(".js"));
1121
+ if (jsChunks.length > 0) {
1122
+ console.info(`
1131
1123
  \u26A0\uFE0F Code splitting detected - CommonJS build will bundle dynamic imports inline`);
1132
- console.info(` ESM build: ${chunkFiles.length} chunk file(s) created for lazy loading`);
1133
- console.info(` CJS build: Dynamic imports bundled inline (no chunks)`);
1134
- console.info(` To get code splitting benefits, use ESM imports or remove "main" field
1124
+ console.info(` ESM build: ${jsChunks.length} chunk file(s) created for lazy loading`);
1125
+ console.info(` CJS build: Dynamic imports bundled inline (no chunks)`);
1126
+ console.info(` To get code splitting benefits, use ESM imports or remove "main" field
1135
1127
  `);
1128
+ }
1136
1129
  }
1137
1130
  }
1138
1131
  if (binEntryPoints.length > 0) {
@@ -1212,14 +1205,14 @@ async function build2(cwd, save = false) {
1212
1205
  console.info(" Generating package.json...");
1213
1206
  const cleanedPkg = await cleanPackageJSON(pkg, mainEntry, options, cwd, distDir);
1214
1207
  const exportsResult = await generateExports(entries, mainEntry, options, pkg.exports, distDir, allBinEntries);
1215
- cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
1216
1208
  for (const dtsFile of ambientDtsFiles) {
1217
1209
  const baseName = Path3.basename(dtsFile, ".d.ts");
1218
1210
  const exportKey = `./${baseName}.d.ts`;
1219
- if (!cleanedPkg.exports[exportKey]) {
1220
- cleanedPkg.exports[exportKey] = `./src/${dtsFile}`;
1211
+ if (!exportsResult.exports[exportKey]) {
1212
+ exportsResult.exports[exportKey] = `./src/${dtsFile}`;
1221
1213
  }
1222
1214
  }
1215
+ cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
1223
1216
  if (exportsResult.staleExports.length > 0) {
1224
1217
  console.warn(`\u26A0\uFE0F WARNING: Found ${exportsResult.staleExports.length} stale export(s) pointing to missing src/ files:`);
1225
1218
  for (const staleExport of exportsResult.staleExports) {
@@ -1471,8 +1464,8 @@ async function publish(cwd, save = true, extraArgs = []) {
1471
1464
  cwd: distDir,
1472
1465
  stdio: "inherit"
1473
1466
  });
1474
- const exitCode = await new Promise((resolve3) => {
1475
- proc.on("close", resolve3);
1467
+ const exitCode = await new Promise((resolve2) => {
1468
+ proc.on("close", resolve2);
1476
1469
  });
1477
1470
  if (exitCode === 0) {
1478
1471
  const distPkg2 = JSON.parse(await FS3.readFile(distPkgPath, "utf-8"));
@@ -0,0 +1,8 @@
1
+ import * as ESBuild from "esbuild";
2
+ export interface TypeScriptPluginOptions {
3
+ tsConfigPath?: string;
4
+ outDir: string;
5
+ rootDir: string;
6
+ entryPoints: string[];
7
+ }
8
+ export declare function dtsPlugin(options: TypeScriptPluginOptions): ESBuild.Plugin;
@@ -0,0 +1,7 @@
1
+ import * as ESBuild from "esbuild";
2
+ export interface ExternalEntrypointsOptions {
3
+ entryNames: string[];
4
+ currentEntry?: string;
5
+ outputExtension: string;
6
+ }
7
+ export declare function externalEntrypointsPlugin(options: ExternalEntrypointsOptions): ESBuild.Plugin;
@@ -0,0 +1,8 @@
1
+ interface UMDPluginOptions {
2
+ globalName: string;
3
+ }
4
+ export declare function umdPlugin(options: UMDPluginOptions): {
5
+ name: string;
6
+ setup(build: any): void;
7
+ };
8
+ export {};