@b9g/libuild 0.1.18 → 0.1.20

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,13 +2,26 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.1.18] - 2025-12-01
5
+ ## [0.1.20] - 2025-12-08
6
6
 
7
- ### Changed
8
- - **prepublishOnly guards** - Replaced `private: true` with `prepublishOnly` script guards as the standard publish protection mechanism. Dist packages now include helpful error messages when accidentally publishing from wrong directory. The `private` field is now properly copied to dist/ for actual private packages, enabling libuild to work with private packages while maintaining publish protection.
7
+ ### Fixed
8
+ - **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.
9
+
10
+ ## [0.1.19] - 2025-12-08
11
+
12
+ ### Added
13
+ - **Ambient .d.ts exports** - Ambient TypeScript declaration files (*.d.ts) in src/ are now automatically added to the exports map, making them discoverable and importable by consumers.
14
+ - **Triple-slash references for ambient types** - Generated .d.ts files now include triple-slash reference directives to ambient .d.ts files, ensuring TypeScript can find ambient type declarations.
9
15
 
10
16
  ### Fixed
11
- - **Private package publishing** - Fixed bug where packages marked with `private: true` could still be published via `libuild publish`. npm now correctly handles private package rejection.
17
+ - **Hard fail on invalid workspace package.json** - Invalid JSON in workspace dependencies now causes build to fail immediately with clear error instead of silently continuing with a warning.
18
+
19
+ ## [0.1.18] - 2025-12-02
20
+
21
+ ### Changed
22
+ - **BREAKING: Scripts not copied to dist** - Scripts field is no longer copied to dist/package.json as they don't work correctly in the dist context (can't reference other scripts that were filtered out). This fixes the issue where prepublishOnly guards would block `libuild publish`. Users who need install scripts (postinstall, etc.) can manually add them to dist/package.json if needed.
23
+ - **prepublishOnly guards for root** - Root package.json gets `prepublishOnly` guard (via `--save`) to prevent accidental publishing from root directory.
24
+ - **Copy private field** - The `private` field is now properly copied from root to dist/, enabling actual private packages to work with libuild while npm prevents their publication.
12
25
 
13
26
  ## [0.1.17] - 2025-11-25
14
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/libuild",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Zero-config library builds",
5
5
  "keywords": [
6
6
  "build",
package/src/libuild.cjs CHANGED
@@ -212788,6 +212788,7 @@ ${diagnostics}`,
212788
212788
  });
212789
212789
  }
212790
212790
  await addTripleSlashReferences(tsFiles, options.outDir);
212791
+ await addAmbientReferences(tsFiles, options.outDir, options.rootDir);
212791
212792
  });
212792
212793
  }
212793
212794
  };
@@ -212822,6 +212823,29 @@ ${content}`;
212822
212823
  await FS2.writeFile(jsPath, modifiedContent);
212823
212824
  }
212824
212825
  }
212826
+ async function addAmbientReferences(tsFiles, outDir, rootDir) {
212827
+ let ambientFiles = [];
212828
+ try {
212829
+ const files = await FS2.readdir(rootDir);
212830
+ ambientFiles = files.filter((f) => f.endsWith(".d.ts"));
212831
+ } catch {
212832
+ return;
212833
+ }
212834
+ if (ambientFiles.length === 0)
212835
+ return;
212836
+ for (const tsFile of tsFiles) {
212837
+ const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
212838
+ const dtsPath = Path2.join(outDir, `${baseName}.d.ts`);
212839
+ const dtsExists = await FS2.access(dtsPath).then(() => true).catch(() => false);
212840
+ if (!dtsExists)
212841
+ continue;
212842
+ const content = await FS2.readFile(dtsPath, "utf-8");
212843
+ const references = ambientFiles.map((ambientFile) => `/// <reference path="./${ambientFile}" />`).join("\n");
212844
+ const modifiedContent = `${references}
212845
+ ${content}`;
212846
+ await FS2.writeFile(dtsPath, modifiedContent);
212847
+ }
212848
+ }
212825
212849
 
212826
212850
  // src/libuild.ts
212827
212851
  function generateRuntimeBanner(pkg) {
@@ -213035,6 +213059,9 @@ async function generateExports(entries, mainEntry, options, existingExports = {}
213035
213059
  if (existing === "./package.json" || existing.endsWith("/package.json")) {
213036
213060
  return existing;
213037
213061
  }
213062
+ if (existing.endsWith(".d.ts") && existing.match(/\.\/(?:dist\/)?src\/[^/]+\.d\.ts$/)) {
213063
+ return existing;
213064
+ }
213038
213065
  const match = existing.match(/\.\/src\/([^/]+\.(?:ts|js))$/);
213039
213066
  if (match) {
213040
213067
  const filename = match[1];
@@ -213391,18 +213418,14 @@ async function resolveWorkspaceVersion(packageName, workspaceSpec, cwd) {
213391
213418
  `./${packageBaseName}/package.json`
213392
213419
  ];
213393
213420
  for (const pkgPath of possiblePaths) {
213394
- try {
213395
- const resolvedPath = Path3.resolve(cwd, pkgPath);
213396
- if (await fileExists(resolvedPath)) {
213397
- const pkgContent = await FS3.readFile(resolvedPath, "utf-8");
213398
- const pkgJson = JSON.parse(pkgContent);
213399
- if (pkgJson.name === packageName) {
213400
- console.info(` Resolved workspace:* dependency "${packageName}" to ^${pkgJson.version}`);
213401
- return `^${pkgJson.version}`;
213402
- }
213421
+ const resolvedPath = Path3.resolve(cwd, pkgPath);
213422
+ if (await fileExists(resolvedPath)) {
213423
+ const pkgContent = await FS3.readFile(resolvedPath, "utf-8");
213424
+ const pkgJson = JSON.parse(pkgContent);
213425
+ if (pkgJson.name === packageName) {
213426
+ console.info(` Resolved workspace:* dependency "${packageName}" to ^${pkgJson.version}`);
213427
+ return `^${pkgJson.version}`;
213403
213428
  }
213404
- } catch {
213405
- continue;
213406
213429
  }
213407
213430
  }
213408
213431
  console.warn(`\u26A0\uFE0F WARNING: Could not resolve workspace dependency "${packageName}" - keeping as workspace:*`);
@@ -213791,9 +213814,21 @@ async function build2(cwd, save = false) {
213791
213814
  });
213792
213815
  }
213793
213816
  const autoDiscoveredFiles = [];
213817
+ const ambientDtsFiles = [];
213818
+ if (await fileExists(srcDir)) {
213819
+ const srcFiles = await FS3.readdir(srcDir);
213820
+ ambientDtsFiles.push(...srcFiles.filter((f) => f.endsWith(".d.ts")));
213821
+ }
213794
213822
  console.info(" Generating package.json...");
213795
213823
  const cleanedPkg = await cleanPackageJSON(pkg, mainEntry, options, cwd, distDir);
213796
213824
  const exportsResult = await generateExports(entries, mainEntry, options, pkg.exports, distDir, allBinEntries);
213825
+ for (const dtsFile of ambientDtsFiles) {
213826
+ const baseName = Path3.basename(dtsFile, ".d.ts");
213827
+ const exportKey = `./${baseName}.d.ts`;
213828
+ if (!exportsResult.exports[exportKey]) {
213829
+ exportsResult.exports[exportKey] = `./src/${dtsFile}`;
213830
+ }
213831
+ }
213797
213832
  cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
213798
213833
  if (exportsResult.staleExports.length > 0) {
213799
213834
  console.warn(`\u26A0\uFE0F WARNING: Found ${exportsResult.staleExports.length} stale export(s) pointing to missing src/ files:`);
@@ -213827,16 +213862,12 @@ async function build2(cwd, save = false) {
213827
213862
  await FS3.copyFile(srcPath, Path3.join(distDir, file));
213828
213863
  }
213829
213864
  }
213830
- if (await fileExists(srcDir)) {
213831
- const srcFiles = await FS3.readdir(srcDir);
213832
- const ambientDtsFiles = srcFiles.filter((f) => f.endsWith(".d.ts"));
213833
- if (ambientDtsFiles.length > 0) {
213834
- console.info(` Copying ${ambientDtsFiles.length} ambient .d.ts file(s)...`);
213835
- for (const dtsFile of ambientDtsFiles) {
213836
- const srcPath = Path3.join(srcDir, dtsFile);
213837
- const destPath = Path3.join(distSrcDir, dtsFile);
213838
- await FS3.copyFile(srcPath, destPath);
213839
- }
213865
+ if (ambientDtsFiles.length > 0) {
213866
+ console.info(` Copying ${ambientDtsFiles.length} ambient .d.ts file(s)...`);
213867
+ for (const dtsFile of ambientDtsFiles) {
213868
+ const srcPath = Path3.join(srcDir, dtsFile);
213869
+ const destPath = Path3.join(distSrcDir, dtsFile);
213870
+ await FS3.copyFile(srcPath, destPath);
213840
213871
  }
213841
213872
  }
213842
213873
  const commonFiles = ["README.md", "LICENSE", "CHANGELOG.md", "COPYING", "AUTHORS"];
package/src/libuild.js CHANGED
@@ -181,6 +181,7 @@ ${diagnostics}`,
181
181
  });
182
182
  }
183
183
  await addTripleSlashReferences(tsFiles, options.outDir);
184
+ await addAmbientReferences(tsFiles, options.outDir, options.rootDir);
184
185
  });
185
186
  }
186
187
  };
@@ -215,6 +216,29 @@ ${content}`;
215
216
  await FS2.writeFile(jsPath, modifiedContent);
216
217
  }
217
218
  }
219
+ async function addAmbientReferences(tsFiles, outDir, rootDir) {
220
+ let ambientFiles = [];
221
+ try {
222
+ const files = await FS2.readdir(rootDir);
223
+ ambientFiles = files.filter((f) => f.endsWith(".d.ts"));
224
+ } catch {
225
+ return;
226
+ }
227
+ if (ambientFiles.length === 0)
228
+ return;
229
+ for (const tsFile of tsFiles) {
230
+ const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
231
+ const dtsPath = Path2.join(outDir, `${baseName}.d.ts`);
232
+ const dtsExists = await FS2.access(dtsPath).then(() => true).catch(() => false);
233
+ if (!dtsExists)
234
+ continue;
235
+ const content = await FS2.readFile(dtsPath, "utf-8");
236
+ const references = ambientFiles.map((ambientFile) => `/// <reference path="./${ambientFile}" />`).join("\n");
237
+ const modifiedContent = `${references}
238
+ ${content}`;
239
+ await FS2.writeFile(dtsPath, modifiedContent);
240
+ }
241
+ }
218
242
 
219
243
  // src/libuild.ts
220
244
  function generateRuntimeBanner(pkg) {
@@ -428,6 +452,9 @@ async function generateExports(entries, mainEntry, options, existingExports = {}
428
452
  if (existing === "./package.json" || existing.endsWith("/package.json")) {
429
453
  return existing;
430
454
  }
455
+ if (existing.endsWith(".d.ts") && existing.match(/\.\/(?:dist\/)?src\/[^/]+\.d\.ts$/)) {
456
+ return existing;
457
+ }
431
458
  const match = existing.match(/\.\/src\/([^/]+\.(?:ts|js))$/);
432
459
  if (match) {
433
460
  const filename = match[1];
@@ -784,18 +811,14 @@ async function resolveWorkspaceVersion(packageName, workspaceSpec, cwd) {
784
811
  `./${packageBaseName}/package.json`
785
812
  ];
786
813
  for (const pkgPath of possiblePaths) {
787
- try {
788
- const resolvedPath = Path3.resolve(cwd, pkgPath);
789
- if (await fileExists(resolvedPath)) {
790
- const pkgContent = await FS3.readFile(resolvedPath, "utf-8");
791
- const pkgJson = JSON.parse(pkgContent);
792
- if (pkgJson.name === packageName) {
793
- console.info(` Resolved workspace:* dependency "${packageName}" to ^${pkgJson.version}`);
794
- return `^${pkgJson.version}`;
795
- }
814
+ const resolvedPath = Path3.resolve(cwd, pkgPath);
815
+ if (await fileExists(resolvedPath)) {
816
+ const pkgContent = await FS3.readFile(resolvedPath, "utf-8");
817
+ const pkgJson = JSON.parse(pkgContent);
818
+ if (pkgJson.name === packageName) {
819
+ console.info(` Resolved workspace:* dependency "${packageName}" to ^${pkgJson.version}`);
820
+ return `^${pkgJson.version}`;
796
821
  }
797
- } catch {
798
- continue;
799
822
  }
800
823
  }
801
824
  console.warn(`\u26A0\uFE0F WARNING: Could not resolve workspace dependency "${packageName}" - keeping as workspace:*`);
@@ -1184,9 +1207,21 @@ async function build2(cwd, save = false) {
1184
1207
  });
1185
1208
  }
1186
1209
  const autoDiscoveredFiles = [];
1210
+ const ambientDtsFiles = [];
1211
+ if (await fileExists(srcDir)) {
1212
+ const srcFiles = await FS3.readdir(srcDir);
1213
+ ambientDtsFiles.push(...srcFiles.filter((f) => f.endsWith(".d.ts")));
1214
+ }
1187
1215
  console.info(" Generating package.json...");
1188
1216
  const cleanedPkg = await cleanPackageJSON(pkg, mainEntry, options, cwd, distDir);
1189
1217
  const exportsResult = await generateExports(entries, mainEntry, options, pkg.exports, distDir, allBinEntries);
1218
+ for (const dtsFile of ambientDtsFiles) {
1219
+ const baseName = Path3.basename(dtsFile, ".d.ts");
1220
+ const exportKey = `./${baseName}.d.ts`;
1221
+ if (!exportsResult.exports[exportKey]) {
1222
+ exportsResult.exports[exportKey] = `./src/${dtsFile}`;
1223
+ }
1224
+ }
1190
1225
  cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
1191
1226
  if (exportsResult.staleExports.length > 0) {
1192
1227
  console.warn(`\u26A0\uFE0F WARNING: Found ${exportsResult.staleExports.length} stale export(s) pointing to missing src/ files:`);
@@ -1220,16 +1255,12 @@ async function build2(cwd, save = false) {
1220
1255
  await FS3.copyFile(srcPath, Path3.join(distDir, file));
1221
1256
  }
1222
1257
  }
1223
- if (await fileExists(srcDir)) {
1224
- const srcFiles = await FS3.readdir(srcDir);
1225
- const ambientDtsFiles = srcFiles.filter((f) => f.endsWith(".d.ts"));
1226
- if (ambientDtsFiles.length > 0) {
1227
- console.info(` Copying ${ambientDtsFiles.length} ambient .d.ts file(s)...`);
1228
- for (const dtsFile of ambientDtsFiles) {
1229
- const srcPath = Path3.join(srcDir, dtsFile);
1230
- const destPath = Path3.join(distSrcDir, dtsFile);
1231
- await FS3.copyFile(srcPath, destPath);
1232
- }
1258
+ if (ambientDtsFiles.length > 0) {
1259
+ console.info(` Copying ${ambientDtsFiles.length} ambient .d.ts file(s)...`);
1260
+ for (const dtsFile of ambientDtsFiles) {
1261
+ const srcPath = Path3.join(srcDir, dtsFile);
1262
+ const destPath = Path3.join(distSrcDir, dtsFile);
1263
+ await FS3.copyFile(srcPath, destPath);
1233
1264
  }
1234
1265
  }
1235
1266
  const commonFiles = ["README.md", "LICENSE", "CHANGELOG.md", "COPYING", "AUTHORS"];