@b9g/libuild 0.1.16 → 0.1.18
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 +16 -0
- package/package.json +1 -1
- package/src/libuild.cjs +31 -2429
- package/src/libuild.js +30 -22
package/src/libuild.js
CHANGED
|
@@ -398,20 +398,17 @@ async function generateExports(entries, mainEntry, options, existingExports = {}
|
|
|
398
398
|
async function createExportEntry(entry) {
|
|
399
399
|
if (entry.startsWith("bin/")) {
|
|
400
400
|
const binEntry = entry.replace("bin/", "");
|
|
401
|
-
const exportEntry = {
|
|
402
|
-
import: `./bin/${binEntry}.js`
|
|
403
|
-
};
|
|
401
|
+
const exportEntry = {};
|
|
404
402
|
if (distDir) {
|
|
405
403
|
const dtsPath = Path3.join(distDir, "bin", `${binEntry}.d.ts`);
|
|
406
404
|
if (await fileExists(dtsPath)) {
|
|
407
405
|
exportEntry.types = `./bin/${binEntry}.d.ts`;
|
|
408
406
|
}
|
|
409
407
|
}
|
|
408
|
+
exportEntry.import = `./bin/${binEntry}.js`;
|
|
410
409
|
return exportEntry;
|
|
411
410
|
} else {
|
|
412
|
-
const exportEntry = {
|
|
413
|
-
import: `./src/${entry}.js`
|
|
414
|
-
};
|
|
411
|
+
const exportEntry = {};
|
|
415
412
|
if (distDir) {
|
|
416
413
|
const dtsPath = Path3.join(distDir, "src", `${entry}.d.ts`);
|
|
417
414
|
const exists = await fileExists(dtsPath);
|
|
@@ -419,6 +416,7 @@ async function generateExports(entries, mainEntry, options, existingExports = {}
|
|
|
419
416
|
exportEntry.types = `./src/${entry}.d.ts`;
|
|
420
417
|
}
|
|
421
418
|
}
|
|
419
|
+
exportEntry.import = `./src/${entry}.js`;
|
|
422
420
|
if (options.formats.cjs) {
|
|
423
421
|
exportEntry.require = `./src/${entry}.cjs`;
|
|
424
422
|
}
|
|
@@ -846,22 +844,14 @@ async function cleanPackageJSON(pkg, mainEntry, options, cwd, distDir) {
|
|
|
846
844
|
"types",
|
|
847
845
|
"files",
|
|
848
846
|
"sideEffects",
|
|
849
|
-
"browserslist"
|
|
847
|
+
"browserslist",
|
|
848
|
+
"private"
|
|
850
849
|
];
|
|
851
850
|
const pathFields = ["files", "types", "scripts"];
|
|
852
851
|
for (const field of fieldsToKeep) {
|
|
853
852
|
if (pkg[field] !== void 0) {
|
|
854
853
|
if (field === "scripts") {
|
|
855
|
-
|
|
856
|
-
const filteredScripts = {};
|
|
857
|
-
for (const [scriptName, scriptValue] of Object.entries(pkg[field] || {})) {
|
|
858
|
-
if (npmLifecycleScripts.includes(scriptName)) {
|
|
859
|
-
filteredScripts[scriptName] = scriptValue;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
if (Object.keys(filteredScripts).length > 0) {
|
|
863
|
-
cleaned[field] = transformSrcToDist(filteredScripts);
|
|
864
|
-
}
|
|
854
|
+
continue;
|
|
865
855
|
} else if (field === "bin") {
|
|
866
856
|
cleaned[field] = transformBinPaths(pkg[field]);
|
|
867
857
|
} else if (pathFields.includes(field)) {
|
|
@@ -927,9 +917,10 @@ async function build2(cwd, save = false) {
|
|
|
927
917
|
if (pkg.bin) {
|
|
928
918
|
await validateBinPaths(pkg.bin, cwd, save, "bin");
|
|
929
919
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
console.warn("
|
|
920
|
+
const hasPublishGuard = pkg.private || pkg.scripts?.prepublishOnly?.includes("exit 1");
|
|
921
|
+
if (!hasPublishGuard && !save) {
|
|
922
|
+
console.warn("\u26A0\uFE0F WARNING: Root package.json lacks publish protection - this could lead to accidental publishing");
|
|
923
|
+
console.warn(" Run 'libuild build --save' to add publish protection, or manually add a prepublishOnly script");
|
|
933
924
|
}
|
|
934
925
|
const gitignorePath = Path3.join(cwd, ".gitignore");
|
|
935
926
|
if (await fileExists(gitignorePath)) {
|
|
@@ -1017,8 +1008,10 @@ async function build2(cwd, save = false) {
|
|
|
1017
1008
|
throw error;
|
|
1018
1009
|
}
|
|
1019
1010
|
const externalDeps = [
|
|
1020
|
-
"*.json"
|
|
1011
|
+
"*.json",
|
|
1021
1012
|
// Let Node.js handle JSON imports natively
|
|
1013
|
+
"esbuild"
|
|
1014
|
+
// Explicit external to suppress require.resolve warning from esbuild's own code
|
|
1022
1015
|
];
|
|
1023
1016
|
const entryPoints = [];
|
|
1024
1017
|
const umdEntries = [];
|
|
@@ -1227,6 +1220,18 @@ async function build2(cwd, save = false) {
|
|
|
1227
1220
|
await FS3.copyFile(srcPath, Path3.join(distDir, file));
|
|
1228
1221
|
}
|
|
1229
1222
|
}
|
|
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
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1230
1235
|
const commonFiles = ["README.md", "LICENSE", "CHANGELOG.md", "COPYING", "AUTHORS"];
|
|
1231
1236
|
if (pkg.files && Array.isArray(pkg.files)) {
|
|
1232
1237
|
for (const commonFile of commonFiles) {
|
|
@@ -1289,7 +1294,10 @@ async function build2(cwd, save = false) {
|
|
|
1289
1294
|
if (save) {
|
|
1290
1295
|
console.info(" Updating root package.json...");
|
|
1291
1296
|
const rootPkg2 = { ...pkg };
|
|
1292
|
-
rootPkg2.
|
|
1297
|
+
if (!rootPkg2.scripts) {
|
|
1298
|
+
rootPkg2.scripts = {};
|
|
1299
|
+
}
|
|
1300
|
+
rootPkg2.scripts.prepublishOnly = "echo 'ERROR: Cannot publish from root directory. Use libuild publish instead.' && exit 1";
|
|
1293
1301
|
if (options.formats.cjs) {
|
|
1294
1302
|
rootPkg2.main = `./dist/src/${mainEntry}.cjs`;
|
|
1295
1303
|
}
|