@d1g1tal/tsbuild 1.8.0 → 1.8.1

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
@@ -1,3 +1,13 @@
1
+ ## [1.8.1](https://github.com/D1g1talEntr0py/tsbuild/compare/v1.8.0...v1.8.1) (2026-04-09)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **iife:** ensure module exports are added to 'globalThis' (23933af3534c86b20ee364aae67e955d3cf374a6)
6
+ - change esbuild format from iife to esm to capture exports
7
+ - add wrapAsIife function to manually wrap esm content and assign exports
8
+ - execute esbuild per entry point to inline all dynamic chunks
9
+ - update tests to verify global export assignments and correct build options
10
+
1
11
  ## [1.8.0](https://github.com/D1g1talEntr0py/tsbuild/compare/v1.7.5...v1.8.0) (2026-04-09)
2
12
 
3
13
  ### Features
@@ -1570,6 +1570,27 @@ function extractEntryNames(entryPoints) {
1570
1570
  }
1571
1571
  return Object.keys(entryPoints);
1572
1572
  }
1573
+ var exportBlockStart = "\nexport {";
1574
+ var exportBlockEnd = "\n};";
1575
+ function wrapAsIife(text, globalName) {
1576
+ const start = text.lastIndexOf(exportBlockStart);
1577
+ if (start === -1) {
1578
+ return text;
1579
+ }
1580
+ const end = text.indexOf(exportBlockEnd, start) + exportBlockEnd.length;
1581
+ const block = text.slice(start + 1, end);
1582
+ const names = [...block.matchAll(/^\s+(\w+)/gm)].map((m) => m[1]);
1583
+ if (names.length === 0) {
1584
+ return text;
1585
+ }
1586
+ const assignment = globalName ? `globalThis.${globalName} = { ${names.join(", ")} };` : `Object.assign(globalThis, { ${names.join(", ")} });`;
1587
+ const body = text.slice(0, start);
1588
+ const after = text.slice(end);
1589
+ return `(() => {
1590
+ ${body}
1591
+ ${assignment}
1592
+ })();${after}`;
1593
+ }
1573
1594
  async function buildIife(outputFiles, entryPointNames, outdir, globalName, sourcemap) {
1574
1595
  const fileContents = /* @__PURE__ */ new Map();
1575
1596
  for (const file of outputFiles) {
@@ -1577,43 +1598,45 @@ async function buildIife(outputFiles, entryPointNames, outdir, globalName, sourc
1577
1598
  fileContents.set(file.path, textDecoder2.decode(file.contents));
1578
1599
  }
1579
1600
  }
1580
- const entryPoints = {};
1601
+ const validEntries = [];
1581
1602
  for (const name of entryPointNames) {
1582
1603
  const absPath = join(outdir, name + jsExtension);
1583
1604
  if (fileContents.has(absPath)) {
1584
- entryPoints[name] = absPath;
1605
+ validEntries.push({ name, absPath });
1585
1606
  }
1586
1607
  }
1587
- if (Object.keys(entryPoints).length === 0) {
1608
+ if (validEntries.length === 0) {
1588
1609
  return [];
1589
1610
  }
1590
1611
  const hasSourceMap = sourcemap !== void 0 && sourcemap !== false;
1591
1612
  const iifeOutdir = join(outdir, "iife");
1592
- const { outputFiles: iifeFiles } = await esbuild({
1593
- entryPoints,
1594
- bundle: true,
1595
- format: "iife",
1596
- globalName,
1597
- splitting: false,
1598
- outdir: iifeOutdir,
1599
- sourcemap: hasSourceMap ? "external" : false,
1600
- write: false,
1601
- logLevel: "warning",
1602
- footer: globalName ? { js: `globalThis.${globalName} = ${globalName};` } : void 0,
1603
- plugins: [virtualLoaderPlugin(fileContents)]
1604
- });
1605
- const entryOutputs = /* @__PURE__ */ new Set();
1606
- for (const name of entryPointNames) {
1607
- entryOutputs.add(join(iifeOutdir, name + jsExtension));
1608
- }
1613
+ const loaderPlugin = virtualLoaderPlugin(fileContents);
1609
1614
  await mkdir3(iifeOutdir, { recursive: true });
1615
+ const results = await Promise.all(validEntries.map(
1616
+ ({ name, absPath }) => esbuild({
1617
+ entryPoints: { [name]: absPath },
1618
+ bundle: true,
1619
+ format: "esm",
1620
+ splitting: false,
1621
+ outdir: iifeOutdir,
1622
+ sourcemap: hasSourceMap ? "external" : false,
1623
+ write: false,
1624
+ logLevel: "warning",
1625
+ plugins: [loaderPlugin]
1626
+ })
1627
+ ));
1610
1628
  const written = [];
1611
1629
  const writes = [];
1612
- for (const file of iifeFiles) {
1613
- const basePath = file.path.endsWith(".map") ? file.path.slice(0, -4) : file.path;
1614
- if (entryOutputs.has(basePath)) {
1615
- writes.push(writeFile3(file.path, file.contents));
1616
- written.push({ path: relative(process.cwd(), file.path), size: file.contents.byteLength });
1630
+ for (const { outputFiles: iifeFiles } of results) {
1631
+ for (const file of iifeFiles) {
1632
+ if (file.path.endsWith(jsExtension)) {
1633
+ const text = wrapAsIife(textDecoder2.decode(file.contents), globalName);
1634
+ writes.push(writeFile3(file.path, text));
1635
+ written.push({ path: relative(process.cwd(), file.path), size: Buffer.byteLength(text) });
1636
+ } else {
1637
+ writes.push(writeFile3(file.path, file.contents));
1638
+ written.push({ path: relative(process.cwd(), file.path), size: file.contents.byteLength });
1639
+ }
1617
1640
  }
1618
1641
  }
1619
1642
  await Promise.all(writes);
@@ -2321,7 +2344,7 @@ var _TypeScriptProject = class _TypeScriptProject {
2321
2344
  return Files.empty(this.buildConfiguration.outDir);
2322
2345
  }
2323
2346
  async build() {
2324
- Logger.header(`${tsLogo} tsbuild v${"1.8.0"}${this.configuration.compilerOptions.incremental && this.configuration.buildCache?.isValid() ? " [incremental]" : ""}`);
2347
+ Logger.header(`${tsLogo} tsbuild v${"1.8.1"}${this.configuration.compilerOptions.incremental && this.configuration.buildCache?.isValid() ? " [incremental]" : ""}`);
2325
2348
  try {
2326
2349
  const processes = [];
2327
2350
  const filesWereEmitted = await this.typeCheck();
package/dist/tsbuild.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BuildError,
4
4
  TypeScriptProject
5
- } from "./YKY7BYLQ.js";
5
+ } from "./GWNROQXR.js";
6
6
  import "./JKGYA2AW.js";
7
7
 
8
8
  // src/tsbuild.ts
@@ -30,7 +30,7 @@ if (help) {
30
30
  process.exit(0);
31
31
  }
32
32
  if (version) {
33
- console.log("1.8.0");
33
+ console.log("1.8.1");
34
34
  process.exit(0);
35
35
  }
36
36
  var typeScriptOptions = {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TypeScriptProject
3
- } from "./YKY7BYLQ.js";
3
+ } from "./GWNROQXR.js";
4
4
  import "./JKGYA2AW.js";
5
5
  export {
6
6
  TypeScriptProject
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d1g1tal/tsbuild",
3
3
  "author": "D1g1talEntr0py",
4
- "version": "1.8.0",
4
+ "version": "1.8.1",
5
5
  "license": "MIT",
6
6
  "description": "A fast, ESM-only TypeScript build tool combining the TypeScript API for type checking and declaration generation, esbuild for bundling, and SWC for decorator metadata.",
7
7
  "homepage": "https://github.com/D1g1talEntr0py/tsbuild#readme",