@d1g1tal/tsbuild 1.1.0 → 1.1.2

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.
@@ -794,6 +794,8 @@ import {
794
794
  isModuleDeclaration as isModuleDeclaration2,
795
795
  isNamedExports as isNamedExports2,
796
796
  isIdentifier as isIdentifier2,
797
+ isNamespaceImport,
798
+ isQualifiedName,
797
799
  resolveModuleName,
798
800
  isExportAssignment,
799
801
  forEachChild as forEachChild2
@@ -911,17 +913,20 @@ var DeclarationBundler = class {
911
913
  const dtsPath = posix.normalize(Paths.join(outDir, Paths.relative(rootDir, sourceWithoutExt) + FileExtension.DTS));
912
914
  return this.declarationFiles.has(dtsPath) ? dtsPath : sourcePath;
913
915
  }
916
+ let bestMatch;
917
+ let bestRelativeLength = Infinity;
914
918
  for (const dtsPath of this.declarationFiles.keys()) {
915
919
  if (!dtsPath.endsWith(FileExtension.DTS)) {
916
920
  continue;
917
921
  }
918
922
  const withoutOutDir = dtsPath.startsWith(outDir + "/") ? dtsPath.slice(outDir.length + 1) : dtsPath;
919
923
  const relativeDtsPath = withoutOutDir.slice(0, -FileExtension.DTS.length);
920
- if (sourceWithoutExt === relativeDtsPath || sourceWithoutExt.endsWith("/" + relativeDtsPath)) {
921
- return dtsPath;
924
+ if ((sourceWithoutExt === relativeDtsPath || sourceWithoutExt.endsWith("/" + relativeDtsPath)) && relativeDtsPath.length < bestRelativeLength) {
925
+ bestRelativeLength = relativeDtsPath.length;
926
+ bestMatch = dtsPath;
922
927
  }
923
928
  }
924
- return sourcePath;
929
+ return bestMatch ?? sourcePath;
925
930
  }
926
931
  /**
927
932
  * Extract import statements from declaration file content using AST
@@ -1137,11 +1142,14 @@ var DeclarationBundler = class {
1137
1142
  moduleRenames.set(name, renamed);
1138
1143
  }
1139
1144
  }
1145
+ const bundledNamespaceAliases = /* @__PURE__ */ new Set();
1140
1146
  for (const statement of sourceFile.statements) {
1141
1147
  if (isImportDeclaration2(statement)) {
1142
1148
  const moduleSpecifier = statement.moduleSpecifier.text;
1143
1149
  if (this.isExternal(moduleSpecifier) || !bundledImportPaths.includes(moduleSpecifier)) {
1144
1150
  externalImports.push(code.substring(statement.pos, statement.end).trim());
1151
+ } else if (statement.importClause?.namedBindings && isNamespaceImport(statement.importClause.namedBindings)) {
1152
+ bundledNamespaceAliases.add(statement.importClause.namedBindings.name.text);
1145
1153
  }
1146
1154
  magic.remove(statement.pos, statement.end);
1147
1155
  } else if (isExportDeclaration2(statement)) {
@@ -1178,7 +1186,20 @@ var DeclarationBundler = class {
1178
1186
  }
1179
1187
  forEachChild2(node, visit);
1180
1188
  };
1181
- forEachChild2(sourceFile, visit);
1189
+ for (const statement of sourceFile.statements) {
1190
+ if (!isImportDeclaration2(statement) && !isExportDeclaration2(statement) && !isExportAssignment(statement)) {
1191
+ visit(statement);
1192
+ }
1193
+ }
1194
+ }
1195
+ if (bundledNamespaceAliases.size > 0) {
1196
+ const visitQualified = (node) => {
1197
+ if (isQualifiedName(node) && isIdentifier2(node.left) && bundledNamespaceAliases.has(node.left.text)) {
1198
+ magic.remove(node.left.getStart(), node.right.getStart());
1199
+ }
1200
+ forEachChild2(node, visitQualified);
1201
+ };
1202
+ forEachChild2(sourceFile, visitQualified);
1182
1203
  }
1183
1204
  const finalValueExports = [...new Set(valueExports.map(exportsMapper))];
1184
1205
  const valueExportsSet = new Set(finalValueExports);
@@ -1767,6 +1788,8 @@ var IncrementalBuildCache = class {
1767
1788
  cacheFilePath;
1768
1789
  /** Pre-loading promise started in constructor for async cache restoration */
1769
1790
  cacheLoaded;
1791
+ /** Set to true when invalidate() is called to prevent stale cache from being restored */
1792
+ invalidated = false;
1770
1793
  /**
1771
1794
  * Creates a new build cache instance and begins pre-loading the cache asynchronously.
1772
1795
  * @param projectRoot - Root directory of the project
@@ -1798,6 +1821,9 @@ var IncrementalBuildCache = class {
1798
1821
  * @param target - The map to populate with cached declarations
1799
1822
  */
1800
1823
  async restore(target) {
1824
+ if (this.invalidated) {
1825
+ return;
1826
+ }
1801
1827
  const cache = await this.cacheLoaded;
1802
1828
  if (cache === void 0) {
1803
1829
  return;
@@ -1816,6 +1842,7 @@ var IncrementalBuildCache = class {
1816
1842
  }
1817
1843
  /** Invalidates the build cache by removing the cache directory. */
1818
1844
  invalidate() {
1845
+ this.invalidated = true;
1819
1846
  try {
1820
1847
  rmSync(this.cacheDirectoryPath, defaultCleanOptions);
1821
1848
  } catch {
@@ -1973,7 +2000,7 @@ var _TypeScriptProject = class _TypeScriptProject {
1973
2000
  return Files.empty(this.buildConfiguration.outDir);
1974
2001
  }
1975
2002
  async build() {
1976
- Logger.header(`\u{1F680} tsbuild v${"1.1.0"}${this.configuration.compilerOptions.incremental ? " [incremental]" : ""}`);
2003
+ Logger.header(`\u{1F680} tsbuild v${"1.1.2"}${this.configuration.compilerOptions.incremental ? " [incremental]" : ""}`);
1977
2004
  try {
1978
2005
  const processes = [];
1979
2006
  const filesWereEmitted = await this.typeCheck();
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TypeScriptProject
3
- } from "./BLUMG6XT.js";
3
+ } from "./3F6EMFXF.js";
4
4
  import "./VMWNQL2J.js";
5
5
  export {
6
6
  TypeScriptProject
package/dist/tsbuild.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BuildError,
4
4
  TypeScriptProject
5
- } from "./BLUMG6XT.js";
5
+ } from "./3F6EMFXF.js";
6
6
  import "./VMWNQL2J.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.1.0");
33
+ console.log("1.1.2");
34
34
  process.exit(0);
35
35
  }
36
36
  var typeScriptOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d1g1tal/tsbuild",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "packageManager": "pnpm@10.29.3",
5
5
  "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.",
6
6
  "type": "module",