@b9g/libuild 0.1.17 → 0.1.19
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 +17 -1
- package/package.json +1 -1
- package/src/libuild.cjs +64 -2444
- package/src/libuild.js +63 -37
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) {
|
|
@@ -784,18 +808,14 @@ async function resolveWorkspaceVersion(packageName, workspaceSpec, cwd) {
|
|
|
784
808
|
`./${packageBaseName}/package.json`
|
|
785
809
|
];
|
|
786
810
|
for (const pkgPath of possiblePaths) {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
return `^${pkgJson.version}`;
|
|
795
|
-
}
|
|
811
|
+
const resolvedPath = Path3.resolve(cwd, pkgPath);
|
|
812
|
+
if (await fileExists(resolvedPath)) {
|
|
813
|
+
const pkgContent = await FS3.readFile(resolvedPath, "utf-8");
|
|
814
|
+
const pkgJson = JSON.parse(pkgContent);
|
|
815
|
+
if (pkgJson.name === packageName) {
|
|
816
|
+
console.info(` Resolved workspace:* dependency "${packageName}" to ^${pkgJson.version}`);
|
|
817
|
+
return `^${pkgJson.version}`;
|
|
796
818
|
}
|
|
797
|
-
} catch {
|
|
798
|
-
continue;
|
|
799
819
|
}
|
|
800
820
|
}
|
|
801
821
|
console.warn(`\u26A0\uFE0F WARNING: Could not resolve workspace dependency "${packageName}" - keeping as workspace:*`);
|
|
@@ -844,22 +864,14 @@ async function cleanPackageJSON(pkg, mainEntry, options, cwd, distDir) {
|
|
|
844
864
|
"types",
|
|
845
865
|
"files",
|
|
846
866
|
"sideEffects",
|
|
847
|
-
"browserslist"
|
|
867
|
+
"browserslist",
|
|
868
|
+
"private"
|
|
848
869
|
];
|
|
849
870
|
const pathFields = ["files", "types", "scripts"];
|
|
850
871
|
for (const field of fieldsToKeep) {
|
|
851
872
|
if (pkg[field] !== void 0) {
|
|
852
873
|
if (field === "scripts") {
|
|
853
|
-
|
|
854
|
-
const filteredScripts = {};
|
|
855
|
-
for (const [scriptName, scriptValue] of Object.entries(pkg[field] || {})) {
|
|
856
|
-
if (npmLifecycleScripts.includes(scriptName)) {
|
|
857
|
-
filteredScripts[scriptName] = scriptValue;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
if (Object.keys(filteredScripts).length > 0) {
|
|
861
|
-
cleaned[field] = transformSrcToDist(filteredScripts);
|
|
862
|
-
}
|
|
874
|
+
continue;
|
|
863
875
|
} else if (field === "bin") {
|
|
864
876
|
cleaned[field] = transformBinPaths(pkg[field]);
|
|
865
877
|
} else if (pathFields.includes(field)) {
|
|
@@ -925,9 +937,10 @@ async function build2(cwd, save = false) {
|
|
|
925
937
|
if (pkg.bin) {
|
|
926
938
|
await validateBinPaths(pkg.bin, cwd, save, "bin");
|
|
927
939
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
console.warn("
|
|
940
|
+
const hasPublishGuard = pkg.private || pkg.scripts?.prepublishOnly?.includes("exit 1");
|
|
941
|
+
if (!hasPublishGuard && !save) {
|
|
942
|
+
console.warn("\u26A0\uFE0F WARNING: Root package.json lacks publish protection - this could lead to accidental publishing");
|
|
943
|
+
console.warn(" Run 'libuild build --save' to add publish protection, or manually add a prepublishOnly script");
|
|
931
944
|
}
|
|
932
945
|
const gitignorePath = Path3.join(cwd, ".gitignore");
|
|
933
946
|
if (await fileExists(gitignorePath)) {
|
|
@@ -1015,8 +1028,10 @@ async function build2(cwd, save = false) {
|
|
|
1015
1028
|
throw error;
|
|
1016
1029
|
}
|
|
1017
1030
|
const externalDeps = [
|
|
1018
|
-
"*.json"
|
|
1031
|
+
"*.json",
|
|
1019
1032
|
// Let Node.js handle JSON imports natively
|
|
1033
|
+
"esbuild"
|
|
1034
|
+
// Explicit external to suppress require.resolve warning from esbuild's own code
|
|
1020
1035
|
];
|
|
1021
1036
|
const entryPoints = [];
|
|
1022
1037
|
const umdEntries = [];
|
|
@@ -1189,10 +1204,22 @@ async function build2(cwd, save = false) {
|
|
|
1189
1204
|
});
|
|
1190
1205
|
}
|
|
1191
1206
|
const autoDiscoveredFiles = [];
|
|
1207
|
+
const ambientDtsFiles = [];
|
|
1208
|
+
if (await fileExists(srcDir)) {
|
|
1209
|
+
const srcFiles = await FS3.readdir(srcDir);
|
|
1210
|
+
ambientDtsFiles.push(...srcFiles.filter((f) => f.endsWith(".d.ts")));
|
|
1211
|
+
}
|
|
1192
1212
|
console.info(" Generating package.json...");
|
|
1193
1213
|
const cleanedPkg = await cleanPackageJSON(pkg, mainEntry, options, cwd, distDir);
|
|
1194
1214
|
const exportsResult = await generateExports(entries, mainEntry, options, pkg.exports, distDir, allBinEntries);
|
|
1195
1215
|
cleanedPkg.exports = fixExportsForDist(exportsResult.exports);
|
|
1216
|
+
for (const dtsFile of ambientDtsFiles) {
|
|
1217
|
+
const baseName = Path3.basename(dtsFile, ".d.ts");
|
|
1218
|
+
const exportKey = `./${baseName}.d.ts`;
|
|
1219
|
+
if (!cleanedPkg.exports[exportKey]) {
|
|
1220
|
+
cleanedPkg.exports[exportKey] = `./src/${dtsFile}`;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1196
1223
|
if (exportsResult.staleExports.length > 0) {
|
|
1197
1224
|
console.warn(`\u26A0\uFE0F WARNING: Found ${exportsResult.staleExports.length} stale export(s) pointing to missing src/ files:`);
|
|
1198
1225
|
for (const staleExport of exportsResult.staleExports) {
|
|
@@ -1225,16 +1252,12 @@ async function build2(cwd, save = false) {
|
|
|
1225
1252
|
await FS3.copyFile(srcPath, Path3.join(distDir, file));
|
|
1226
1253
|
}
|
|
1227
1254
|
}
|
|
1228
|
-
if (
|
|
1229
|
-
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const srcPath = Path3.join(srcDir, dtsFile);
|
|
1235
|
-
const destPath = Path3.join(distSrcDir, dtsFile);
|
|
1236
|
-
await FS3.copyFile(srcPath, destPath);
|
|
1237
|
-
}
|
|
1255
|
+
if (ambientDtsFiles.length > 0) {
|
|
1256
|
+
console.info(` Copying ${ambientDtsFiles.length} ambient .d.ts file(s)...`);
|
|
1257
|
+
for (const dtsFile of ambientDtsFiles) {
|
|
1258
|
+
const srcPath = Path3.join(srcDir, dtsFile);
|
|
1259
|
+
const destPath = Path3.join(distSrcDir, dtsFile);
|
|
1260
|
+
await FS3.copyFile(srcPath, destPath);
|
|
1238
1261
|
}
|
|
1239
1262
|
}
|
|
1240
1263
|
const commonFiles = ["README.md", "LICENSE", "CHANGELOG.md", "COPYING", "AUTHORS"];
|
|
@@ -1299,7 +1322,10 @@ async function build2(cwd, save = false) {
|
|
|
1299
1322
|
if (save) {
|
|
1300
1323
|
console.info(" Updating root package.json...");
|
|
1301
1324
|
const rootPkg2 = { ...pkg };
|
|
1302
|
-
rootPkg2.
|
|
1325
|
+
if (!rootPkg2.scripts) {
|
|
1326
|
+
rootPkg2.scripts = {};
|
|
1327
|
+
}
|
|
1328
|
+
rootPkg2.scripts.prepublishOnly = "echo 'ERROR: Cannot publish from root directory. Use libuild publish instead.' && exit 1";
|
|
1303
1329
|
if (options.formats.cjs) {
|
|
1304
1330
|
rootPkg2.main = `./dist/src/${mainEntry}.cjs`;
|
|
1305
1331
|
}
|