@b9g/libuild 0.1.20 → 0.1.22
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 +15 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/libuild.cjs +59 -55
- package/src/libuild.js +46 -50
- package/src/plugins/dts.d.ts +8 -0
- package/src/plugins/external.d.ts +7 -0
- package/src/plugins/umd.d.ts +8 -0
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.22] - 2025-12-22
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **Bin imports from src polluting source tree** - Fixed .d.ts files being emitted to source directories when bin entries import from `../src/`. This caused lint failures and polluted the src/ folder. Fixes [#2](https://github.com/bikeshaving/libuild/issues/2).
|
|
9
|
+
|
|
10
|
+
## [0.1.21] - 2025-12-22
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **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.
|
|
14
|
+
- **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).
|
|
15
|
+
- **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.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- **Chunk files location** - ESM code splitting chunks are now placed in `dist/src/_chunks/` instead of the dist root, keeping the package structure cleaner.
|
|
19
|
+
|
|
5
20
|
## [0.1.20] - 2025-12-08
|
|
6
21
|
|
|
7
22
|
### Fixed
|
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
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
|
|
9564
|
+
const relative2 = [];
|
|
9565
9565
|
for (; start < fromComponents.length; start++) {
|
|
9566
|
-
|
|
9566
|
+
relative2.push("..");
|
|
9567
9567
|
}
|
|
9568
|
-
return ["", ...
|
|
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
|
|
48272
|
-
if (
|
|
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(
|
|
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
|
|
54213
|
+
const relative2 = getRelativePathFromDirectory(realPathDirectory, target, getCanonicalFileName);
|
|
54214
54214
|
for (const symlinkDirectory of symlinkDirectories) {
|
|
54215
|
-
const option = resolvePath(symlinkDirectory,
|
|
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
|
|
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
|
-
|
|
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()]),
|
|
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((
|
|
212328
|
-
(this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve:
|
|
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,42 +212725,35 @@ function dtsPlugin(options) {
|
|
|
212725
212725
|
} catch (error) {
|
|
212726
212726
|
return;
|
|
212727
212727
|
}
|
|
212728
|
-
|
|
212729
|
-
|
|
212730
|
-
|
|
212731
|
-
|
|
212732
|
-
|
|
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
|
+
await FS2.mkdir(options.outDir, { recursive: true });
|
|
212729
|
+
const fs = await import("fs");
|
|
212730
|
+
const resolvedRootDir = fs.realpathSync(options.rootDir);
|
|
212731
|
+
const resolvedOutDir = fs.realpathSync(options.outDir);
|
|
212732
|
+
const tsFiles = entryFiles.filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts")).map((f) => fs.realpathSync(f)).filter((f) => f.startsWith(resolvedRootDir + Path2.sep));
|
|
212744
212733
|
if (tsFiles.length === 0) {
|
|
212745
212734
|
return;
|
|
212746
212735
|
}
|
|
212736
|
+
const resolvedTsFiles = tsFiles;
|
|
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:
|
|
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
|
-
|
|
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(
|
|
212763
|
-
const
|
|
212749
|
+
const program = TS.createProgram(resolvedTsFiles, compilerOptions);
|
|
212750
|
+
const writeFile4 = (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
|
212751
|
+
if (!fileName.startsWith(resolvedOutDir + Path2.sep)) {
|
|
212752
|
+
return;
|
|
212753
|
+
}
|
|
212754
|
+
TS.sys.writeFile(fileName, data, writeByteOrderMark);
|
|
212755
|
+
};
|
|
212756
|
+
const emitResult = program.emit(void 0, writeFile4);
|
|
212764
212757
|
if (emitResult.diagnostics.length > 0) {
|
|
212765
212758
|
const diagnostics = TS.formatDiagnosticsWithColorAndContext(emitResult.diagnostics, {
|
|
212766
212759
|
getCanonicalFileName: (path) => path,
|
|
@@ -212787,17 +212780,20 @@ ${diagnostics}`,
|
|
|
212787
212780
|
detail: void 0
|
|
212788
212781
|
});
|
|
212789
212782
|
}
|
|
212790
|
-
await addTripleSlashReferences(
|
|
212791
|
-
await addAmbientReferences(
|
|
212783
|
+
await addTripleSlashReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
|
|
212784
|
+
await addAmbientReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
|
|
212792
212785
|
});
|
|
212793
212786
|
}
|
|
212794
212787
|
};
|
|
212795
212788
|
}
|
|
212796
|
-
async function addTripleSlashReferences(tsFiles, outDir) {
|
|
212789
|
+
async function addTripleSlashReferences(tsFiles, outDir, rootDir) {
|
|
212797
212790
|
for (const tsFile of tsFiles) {
|
|
212791
|
+
const relativePath = Path2.relative(rootDir, tsFile);
|
|
212792
|
+
const relativeDir = Path2.dirname(relativePath);
|
|
212798
212793
|
const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
|
|
212799
|
-
const
|
|
212800
|
-
const
|
|
212794
|
+
const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
|
|
212795
|
+
const jsPath = Path2.join(outputSubDir, `${baseName}.js`);
|
|
212796
|
+
const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
|
|
212801
212797
|
const [jsExists, dtsExists] = await Promise.all([
|
|
212802
212798
|
FS2.access(jsPath).then(() => true).catch(() => false),
|
|
212803
212799
|
FS2.access(dtsPath).then(() => true).catch(() => false)
|
|
@@ -212834,13 +212830,17 @@ async function addAmbientReferences(tsFiles, outDir, rootDir) {
|
|
|
212834
212830
|
if (ambientFiles.length === 0)
|
|
212835
212831
|
return;
|
|
212836
212832
|
for (const tsFile of tsFiles) {
|
|
212833
|
+
const relativePath = Path2.relative(rootDir, tsFile);
|
|
212834
|
+
const relativeDir = Path2.dirname(relativePath);
|
|
212837
212835
|
const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
|
|
212838
|
-
const
|
|
212836
|
+
const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
|
|
212837
|
+
const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
|
|
212839
212838
|
const dtsExists = await FS2.access(dtsPath).then(() => true).catch(() => false);
|
|
212840
212839
|
if (!dtsExists)
|
|
212841
212840
|
continue;
|
|
212842
212841
|
const content = await FS2.readFile(dtsPath, "utf-8");
|
|
212843
|
-
const
|
|
212842
|
+
const relativeToRoot = relativeDir === "." ? "./" : "../".repeat(relativeDir.split(Path2.sep).length);
|
|
212843
|
+
const references = ambientFiles.map((ambientFile) => `/// <reference path="${relativeToRoot}${ambientFile}" />`).join("\n");
|
|
212844
212844
|
const modifiedContent = `${references}
|
|
212845
212845
|
${content}`;
|
|
212846
212846
|
await FS2.writeFile(dtsPath, modifiedContent);
|
|
@@ -213700,6 +213700,8 @@ async function build2(cwd, save = false) {
|
|
|
213700
213700
|
outdir: distDir,
|
|
213701
213701
|
outbase: cwd,
|
|
213702
213702
|
// Preserve src/ and bin/ directory structure
|
|
213703
|
+
chunkNames: "src/_chunks/[name]-[hash]",
|
|
213704
|
+
// Put chunks in a subdirectory
|
|
213703
213705
|
format: "esm",
|
|
213704
213706
|
outExtension: { ".js": ".js" },
|
|
213705
213707
|
bundle: true,
|
|
@@ -213732,17 +213734,19 @@ async function build2(cwd, save = false) {
|
|
|
213732
213734
|
]
|
|
213733
213735
|
});
|
|
213734
213736
|
if (options.formats.cjs) {
|
|
213735
|
-
const
|
|
213736
|
-
const
|
|
213737
|
-
|
|
213738
|
-
|
|
213739
|
-
|
|
213740
|
-
|
|
213737
|
+
const chunksDir = Path3.join(distSrcDir, "_chunks");
|
|
213738
|
+
const chunksExist = await FS3.stat(chunksDir).then(() => true, () => false);
|
|
213739
|
+
if (chunksExist) {
|
|
213740
|
+
const chunkFiles = await FS3.readdir(chunksDir);
|
|
213741
|
+
const jsChunks = chunkFiles.filter((f) => f.endsWith(".js"));
|
|
213742
|
+
if (jsChunks.length > 0) {
|
|
213743
|
+
console.info(`
|
|
213741
213744
|
\u26A0\uFE0F Code splitting detected - CommonJS build will bundle dynamic imports inline`);
|
|
213742
|
-
|
|
213743
|
-
|
|
213744
|
-
|
|
213745
|
+
console.info(` ESM build: ${jsChunks.length} chunk file(s) created for lazy loading`);
|
|
213746
|
+
console.info(` CJS build: Dynamic imports bundled inline (no chunks)`);
|
|
213747
|
+
console.info(` To get code splitting benefits, use ESM imports or remove "main" field
|
|
213745
213748
|
`);
|
|
213749
|
+
}
|
|
213746
213750
|
}
|
|
213747
213751
|
}
|
|
213748
213752
|
if (binEntryPoints.length > 0) {
|
|
@@ -214081,8 +214085,8 @@ async function publish(cwd, save = true, extraArgs = []) {
|
|
|
214081
214085
|
cwd: distDir,
|
|
214082
214086
|
stdio: "inherit"
|
|
214083
214087
|
});
|
|
214084
|
-
const exitCode = await new Promise((
|
|
214085
|
-
proc.on("close",
|
|
214088
|
+
const exitCode = await new Promise((resolve2) => {
|
|
214089
|
+
proc.on("close", resolve2);
|
|
214086
214090
|
});
|
|
214087
214091
|
if (exitCode === 0) {
|
|
214088
214092
|
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,42 +110,35 @@ function dtsPlugin(options) {
|
|
|
118
110
|
} catch (error) {
|
|
119
111
|
return;
|
|
120
112
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
await FS2.mkdir(options.outDir, { recursive: true });
|
|
114
|
+
const fs = await import("fs");
|
|
115
|
+
const resolvedRootDir = fs.realpathSync(options.rootDir);
|
|
116
|
+
const resolvedOutDir = fs.realpathSync(options.outDir);
|
|
117
|
+
const tsFiles = entryFiles.filter((file) => file.endsWith(".ts") && !file.endsWith(".d.ts")).map((f) => fs.realpathSync(f)).filter((f) => f.startsWith(resolvedRootDir + Path2.sep));
|
|
137
118
|
if (tsFiles.length === 0) {
|
|
138
119
|
return;
|
|
139
120
|
}
|
|
121
|
+
const resolvedTsFiles = tsFiles;
|
|
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:
|
|
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
|
-
|
|
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(
|
|
156
|
-
const
|
|
134
|
+
const program = TS.createProgram(resolvedTsFiles, compilerOptions);
|
|
135
|
+
const writeFile4 = (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
|
136
|
+
if (!fileName.startsWith(resolvedOutDir + Path2.sep)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
TS.sys.writeFile(fileName, data, writeByteOrderMark);
|
|
140
|
+
};
|
|
141
|
+
const emitResult = program.emit(void 0, writeFile4);
|
|
157
142
|
if (emitResult.diagnostics.length > 0) {
|
|
158
143
|
const diagnostics = TS.formatDiagnosticsWithColorAndContext(emitResult.diagnostics, {
|
|
159
144
|
getCanonicalFileName: (path) => path,
|
|
@@ -180,17 +165,20 @@ ${diagnostics}`,
|
|
|
180
165
|
detail: void 0
|
|
181
166
|
});
|
|
182
167
|
}
|
|
183
|
-
await addTripleSlashReferences(
|
|
184
|
-
await addAmbientReferences(
|
|
168
|
+
await addTripleSlashReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
|
|
169
|
+
await addAmbientReferences(resolvedTsFiles, resolvedOutDir, resolvedRootDir);
|
|
185
170
|
});
|
|
186
171
|
}
|
|
187
172
|
};
|
|
188
173
|
}
|
|
189
|
-
async function addTripleSlashReferences(tsFiles, outDir) {
|
|
174
|
+
async function addTripleSlashReferences(tsFiles, outDir, rootDir) {
|
|
190
175
|
for (const tsFile of tsFiles) {
|
|
176
|
+
const relativePath = Path2.relative(rootDir, tsFile);
|
|
177
|
+
const relativeDir = Path2.dirname(relativePath);
|
|
191
178
|
const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
|
|
192
|
-
const
|
|
193
|
-
const
|
|
179
|
+
const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
|
|
180
|
+
const jsPath = Path2.join(outputSubDir, `${baseName}.js`);
|
|
181
|
+
const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
|
|
194
182
|
const [jsExists, dtsExists] = await Promise.all([
|
|
195
183
|
FS2.access(jsPath).then(() => true).catch(() => false),
|
|
196
184
|
FS2.access(dtsPath).then(() => true).catch(() => false)
|
|
@@ -227,13 +215,17 @@ async function addAmbientReferences(tsFiles, outDir, rootDir) {
|
|
|
227
215
|
if (ambientFiles.length === 0)
|
|
228
216
|
return;
|
|
229
217
|
for (const tsFile of tsFiles) {
|
|
218
|
+
const relativePath = Path2.relative(rootDir, tsFile);
|
|
219
|
+
const relativeDir = Path2.dirname(relativePath);
|
|
230
220
|
const baseName = Path2.basename(tsFile, Path2.extname(tsFile));
|
|
231
|
-
const
|
|
221
|
+
const outputSubDir = relativeDir === "." ? outDir : Path2.join(outDir, relativeDir);
|
|
222
|
+
const dtsPath = Path2.join(outputSubDir, `${baseName}.d.ts`);
|
|
232
223
|
const dtsExists = await FS2.access(dtsPath).then(() => true).catch(() => false);
|
|
233
224
|
if (!dtsExists)
|
|
234
225
|
continue;
|
|
235
226
|
const content = await FS2.readFile(dtsPath, "utf-8");
|
|
236
|
-
const
|
|
227
|
+
const relativeToRoot = relativeDir === "." ? "./" : "../".repeat(relativeDir.split(Path2.sep).length);
|
|
228
|
+
const references = ambientFiles.map((ambientFile) => `/// <reference path="${relativeToRoot}${ambientFile}" />`).join("\n");
|
|
237
229
|
const modifiedContent = `${references}
|
|
238
230
|
${content}`;
|
|
239
231
|
await FS2.writeFile(dtsPath, modifiedContent);
|
|
@@ -1093,6 +1085,8 @@ async function build2(cwd, save = false) {
|
|
|
1093
1085
|
outdir: distDir,
|
|
1094
1086
|
outbase: cwd,
|
|
1095
1087
|
// Preserve src/ and bin/ directory structure
|
|
1088
|
+
chunkNames: "src/_chunks/[name]-[hash]",
|
|
1089
|
+
// Put chunks in a subdirectory
|
|
1096
1090
|
format: "esm",
|
|
1097
1091
|
outExtension: { ".js": ".js" },
|
|
1098
1092
|
bundle: true,
|
|
@@ -1125,17 +1119,19 @@ async function build2(cwd, save = false) {
|
|
|
1125
1119
|
]
|
|
1126
1120
|
});
|
|
1127
1121
|
if (options.formats.cjs) {
|
|
1128
|
-
const
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1122
|
+
const chunksDir = Path3.join(distSrcDir, "_chunks");
|
|
1123
|
+
const chunksExist = await FS3.stat(chunksDir).then(() => true, () => false);
|
|
1124
|
+
if (chunksExist) {
|
|
1125
|
+
const chunkFiles = await FS3.readdir(chunksDir);
|
|
1126
|
+
const jsChunks = chunkFiles.filter((f) => f.endsWith(".js"));
|
|
1127
|
+
if (jsChunks.length > 0) {
|
|
1128
|
+
console.info(`
|
|
1134
1129
|
\u26A0\uFE0F Code splitting detected - CommonJS build will bundle dynamic imports inline`);
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1130
|
+
console.info(` ESM build: ${jsChunks.length} chunk file(s) created for lazy loading`);
|
|
1131
|
+
console.info(` CJS build: Dynamic imports bundled inline (no chunks)`);
|
|
1132
|
+
console.info(` To get code splitting benefits, use ESM imports or remove "main" field
|
|
1138
1133
|
`);
|
|
1134
|
+
}
|
|
1139
1135
|
}
|
|
1140
1136
|
}
|
|
1141
1137
|
if (binEntryPoints.length > 0) {
|
|
@@ -1474,8 +1470,8 @@ async function publish(cwd, save = true, extraArgs = []) {
|
|
|
1474
1470
|
cwd: distDir,
|
|
1475
1471
|
stdio: "inherit"
|
|
1476
1472
|
});
|
|
1477
|
-
const exitCode = await new Promise((
|
|
1478
|
-
proc.on("close",
|
|
1473
|
+
const exitCode = await new Promise((resolve2) => {
|
|
1474
|
+
proc.on("close", resolve2);
|
|
1479
1475
|
});
|
|
1480
1476
|
if (exitCode === 0) {
|
|
1481
1477
|
const distPkg2 = JSON.parse(await FS3.readFile(distPkgPath, "utf-8"));
|
|
@@ -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;
|