@d1g1tal/tsbuild 1.0.2 → 1.0.3

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.
@@ -3,7 +3,7 @@ import {
3
3
  Json,
4
4
  Paths,
5
5
  typeScriptExtensionExpression
6
- } from "./44KSX2XO.js";
6
+ } from "./VMWNQL2J.js";
7
7
 
8
8
  // src/plugins/decorator-metadata.ts
9
9
  import { dirname } from "node:path";
@@ -29,7 +29,7 @@ import {
29
29
  toEsTarget,
30
30
  toJsxRenderingMode,
31
31
  typeMatcher
32
- } from "./44KSX2XO.js";
32
+ } from "./VMWNQL2J.js";
33
33
 
34
34
  // src/errors.ts
35
35
  import { SyntaxKind } from "typescript";
@@ -448,7 +448,6 @@ import {
448
448
  getCombinedModifierFlags
449
449
  } from "typescript";
450
450
  import MagicString from "magic-string";
451
- var codeTransformationComparator = (a, b) => b.start - a.start;
452
451
  var DeclarationProcessor = class _DeclarationProcessor {
453
452
  constructor() {
454
453
  }
@@ -747,22 +746,17 @@ var DeclarationProcessor = class _DeclarationProcessor {
747
746
  * @returns The processed source code
748
747
  */
749
748
  static postProcess(sourceFile) {
750
- let code = sourceFile.getFullText();
751
- const transformations = [];
749
+ const magic = new MagicString(sourceFile.getFullText());
752
750
  function visitNode(node) {
753
751
  if (isEmptyStatement(node)) {
754
- transformations.push({ start: node.getStart(), end: node.getEnd() });
752
+ magic.remove(node.getStart(), node.getEnd());
755
753
  return;
756
754
  }
757
755
  if ((isImportDeclaration(node) || isExportDeclaration(node)) && node.moduleSpecifier && isStringLiteral(node.moduleSpecifier)) {
758
756
  const { text } = node.moduleSpecifier;
759
757
  if (text.startsWith(".") && text.endsWith(FileExtension.DTS)) {
760
758
  const replacement = text.endsWith(".d.tsx") ? text.slice(0, -6) + FileExtension.JS : text.slice(0, -5) + FileExtension.JS;
761
- transformations.push({
762
- start: node.moduleSpecifier.getStart() + 1,
763
- end: node.moduleSpecifier.getEnd() - 1,
764
- replacement
765
- });
759
+ magic.overwrite(node.moduleSpecifier.getStart() + 1, node.moduleSpecifier.getEnd() - 1, replacement);
766
760
  }
767
761
  }
768
762
  if (isModuleDeclaration(node) && node.body && isModuleBlock(node.body)) {
@@ -770,7 +764,7 @@ var DeclarationProcessor = class _DeclarationProcessor {
770
764
  if (isExportDeclaration(bodyStatement) && bodyStatement.exportClause && !isNamespaceExport(bodyStatement.exportClause)) {
771
765
  for (const { name, propertyName } of bodyStatement.exportClause.elements) {
772
766
  if (propertyName && isIdentifier(propertyName) && isIdentifier(name) && propertyName.getText() === name.getText()) {
773
- transformations.push({ start: propertyName.getStart(), end: name.getStart() });
767
+ magic.remove(propertyName.getStart(), name.getStart());
774
768
  }
775
769
  }
776
770
  }
@@ -779,10 +773,7 @@ var DeclarationProcessor = class _DeclarationProcessor {
779
773
  forEachChild(node, visitNode);
780
774
  }
781
775
  visitNode(sourceFile);
782
- for (const { start, end, replacement = "" } of transformations.sort(codeTransformationComparator)) {
783
- code = code.slice(0, start) + replacement + code.slice(end);
784
- }
785
- return code;
776
+ return magic.toString();
786
777
  }
787
778
  };
788
779
 
@@ -799,7 +790,6 @@ import {
799
790
  isFunctionDeclaration as isFunctionDeclaration2,
800
791
  isClassDeclaration as isClassDeclaration2,
801
792
  isVariableStatement as isVariableStatement2,
802
- isModuleBlock as isModuleBlock2,
803
793
  isModuleDeclaration as isModuleDeclaration2,
804
794
  isNamedExports as isNamedExports2,
805
795
  isIdentifier as isIdentifier2,
@@ -846,6 +836,8 @@ var DeclarationBundler = class {
846
836
  identifierCache = /* @__PURE__ */ new WeakMap();
847
837
  /** Module resolution cache for this bundler instance */
848
838
  moduleResolutionCache = /* @__PURE__ */ new Map();
839
+ /** Pre-computed set of directory prefixes from declaration file paths for O(1) directoryExists lookups */
840
+ declarationDirs = /* @__PURE__ */ new Set();
849
841
  // Create a proper module resolution host that supports both in-memory files and disk files
850
842
  moduleResolutionHost = {
851
843
  fileExists: (fileName) => {
@@ -868,13 +860,8 @@ var DeclarationBundler = class {
868
860
  return void 0;
869
861
  },
870
862
  directoryExists: (dirName) => {
871
- const normalizedDir = dirName.endsWith("/") ? dirName : dirName + "/";
872
- for (const filePath of this.declarationFiles.keys()) {
873
- if (filePath.startsWith(normalizedDir)) {
874
- return true;
875
- }
876
- }
877
- return this.options.resolve ? sys.directoryExists(dirName) : false;
863
+ const normalizedDir = dirName.endsWith("/") ? dirName.slice(0, -1) : dirName;
864
+ return this.declarationDirs.has(normalizedDir) || (this.options.resolve ? sys.directoryExists(dirName) : false);
878
865
  },
879
866
  getCurrentDirectory: () => this.options.currentDirectory,
880
867
  /* v8 ignore next */
@@ -888,6 +875,17 @@ var DeclarationBundler = class {
888
875
  for (const [filePath, cachedDecl] of dtsBundleOptions.declarationFiles) {
889
876
  this.declarationFiles.set(sys.resolvePath(filePath), cachedDecl);
890
877
  }
878
+ for (const filePath of this.declarationFiles.keys()) {
879
+ let dir = filePath.lastIndexOf("/") !== -1 ? filePath.slice(0, filePath.lastIndexOf("/")) : "";
880
+ while (dir.length > 0) {
881
+ if (this.declarationDirs.has(dir)) {
882
+ break;
883
+ }
884
+ this.declarationDirs.add(dir);
885
+ const nextSlash = dir.lastIndexOf("/");
886
+ dir = nextSlash !== -1 ? dir.slice(0, nextSlash) : "";
887
+ }
888
+ }
891
889
  this.options = dtsBundleOptions;
892
890
  }
893
891
  /**
@@ -1003,14 +1001,6 @@ var DeclarationBundler = class {
1003
1001
  if (resolvedPath?.includes(nodeModules) && !this.matchesPattern(specifier, this.options.noExternal)) {
1004
1002
  continue;
1005
1003
  }
1006
- if (resolvedPath && !this.declarationFiles.has(resolvedPath)) {
1007
- if (this.options.resolve && sys.fileExists(resolvedPath)) {
1008
- const rawContent = sys.readFile(resolvedPath, Encoding.utf8);
1009
- if (rawContent !== void 0) {
1010
- this.declarationFiles.set(resolvedPath, DeclarationProcessor.preProcess(createSourceFile(resolvedPath, rawContent, ScriptTarget.Latest, true)));
1011
- }
1012
- }
1013
- }
1014
1004
  if (resolvedPath && this.declarationFiles.has(resolvedPath)) {
1015
1005
  module.imports.add(resolvedPath);
1016
1006
  bundledSpecs.push(specifier);
@@ -1094,8 +1084,6 @@ var DeclarationBundler = class {
1094
1084
  values.add(name.text);
1095
1085
  }
1096
1086
  }
1097
- } else if (isModuleBlock2(statement)) {
1098
- collectNestedIdentifiers(statement.statements);
1099
1087
  } else if (isModuleDeclaration2(statement)) {
1100
1088
  if (statement.name && isIdentifier2(statement.name)) {
1101
1089
  values.add(statement.name.text);
@@ -1170,7 +1158,7 @@ var DeclarationBundler = class {
1170
1158
  if (isIdentifier2(node)) {
1171
1159
  const renamed = moduleRenames.get(node.text);
1172
1160
  if (renamed) {
1173
- magic.overwrite(node.pos, node.end, renamed);
1161
+ magic.overwrite(node.getStart(), node.end, renamed);
1174
1162
  }
1175
1163
  }
1176
1164
  forEachChild2(node, visit);
@@ -1851,6 +1839,7 @@ var _TypeScriptProject = class _TypeScriptProject {
1851
1839
  __publicField(this, "buildConfiguration");
1852
1840
  __publicField(this, "pendingChanges", []);
1853
1841
  __publicField(this, "buildDependencies", /* @__PURE__ */ new Set());
1842
+ __publicField(this, "dependencyPaths");
1854
1843
  this.directory = Paths.absolute(directory);
1855
1844
  this.configuration = _TypeScriptProject.resolveConfiguration(this.directory, options);
1856
1845
  const { buildCache, rootNames, projectReferences, configFileParsingDiagnostics, tsbuild: { entryPoints, ...tsbuildOptions }, compilerOptions: { target, outDir } } = this.configuration;
@@ -1869,11 +1858,11 @@ var _TypeScriptProject = class _TypeScriptProject {
1869
1858
  return Files.empty(this.buildConfiguration.outDir);
1870
1859
  }
1871
1860
  async build() {
1872
- Logger.header(`\u{1F680} tsbuild v${"1.0.2"}${this.configuration.compilerOptions.incremental ? " [incremental]" : ""}`);
1861
+ Logger.header(`\u{1F680} tsbuild v${"1.0.3"}${this.configuration.compilerOptions.incremental ? " [incremental]" : ""}`);
1873
1862
  try {
1874
1863
  const processes = [];
1875
1864
  const filesWereEmitted = await this.typeCheck();
1876
- if (filesWereEmitted && (!this.configuration.compilerOptions.noEmit || this.configuration.tsbuild.force)) {
1865
+ if ((filesWereEmitted || this.configuration.tsbuild.force) && !this.configuration.compilerOptions.noEmit) {
1877
1866
  if (this.configuration.clean) {
1878
1867
  await this.clean();
1879
1868
  }
@@ -1920,7 +1909,7 @@ var _TypeScriptProject = class _TypeScriptProject {
1920
1909
  }
1921
1910
  if (this.configuration.compilerOptions.emitDecoratorMetadata) {
1922
1911
  try {
1923
- const { swcDecoratorMetadataPlugin } = await import("./QAEHWWWE.js");
1912
+ const { swcDecoratorMetadataPlugin } = await import("./7ALTNLQM.js");
1924
1913
  plugins.push(swcDecoratorMetadataPlugin);
1925
1914
  } catch {
1926
1915
  throw new ConfigurationError("emitDecoratorMetadata is enabled but @swc/core is not installed. Install it with: pnpm add -D @swc/core");
@@ -2061,11 +2050,13 @@ var _TypeScriptProject = class _TypeScriptProject {
2061
2050
  const index = rootNames.indexOf(path);
2062
2051
  if (event === Watchr.FileEvent.unlink && index !== -1) {
2063
2052
  rootNames.splice(index, 1);
2053
+ } else if (event === Watchr.FileEvent.add && index === -1) {
2054
+ rootNames.push(path);
2064
2055
  }
2065
2056
  }
2066
2057
  }
2067
2058
  this.pendingChanges.length = 0;
2068
- this.builderProgram = createIncrementalProgram({ rootNames, options: this.configuration.compilerOptions, projectReferences: this.configuration.projectReferences });
2059
+ this.builderProgram = createIncrementalProgram({ rootNames, options: this.configuration.compilerOptions, projectReferences: this.configuration.projectReferences, configFileParsingDiagnostics: this.configuration.configFileParsingDiagnostics });
2069
2060
  await this.build();
2070
2061
  }
2071
2062
  /**
@@ -2108,8 +2099,7 @@ var _TypeScriptProject = class _TypeScriptProject {
2108
2099
  compilerOptions: {
2109
2100
  ...{ outDir: defaultOutDirectory, noEmit: false, sourceMap: false, incremental: true, tsBuildInfoFile: Paths.join(cacheDirectory, buildInfoFile), lib: [] },
2110
2101
  ...configResult.config.compilerOptions,
2111
- ...typeScriptOptions.compilerOptions,
2112
- ...compilerOptionOverrides
2102
+ ...typeScriptOptions.compilerOptions
2113
2103
  }
2114
2104
  };
2115
2105
  const { options, fileNames, errors } = parseJsonConfigFileContent(baseConfig, sys3, directory);
@@ -2149,12 +2139,14 @@ var _TypeScriptProject = class _TypeScriptProject {
2149
2139
  return expandedEntryPoints;
2150
2140
  }
2151
2141
  /**
2152
- * Gets the project dependency paths.
2142
+ * Gets the project dependency paths, cached after first call.
2153
2143
  * @returns A promise that resolves to an array of project dependency paths.
2154
2144
  */
2155
- async getProjectDependencyPaths() {
2156
- const { dependencies = {}, peerDependencies = {} } = Json.parse(await Files.read(Paths.absolute(this.directory, "package.json")));
2157
- return [.../* @__PURE__ */ new Set([...Object.keys(dependencies), ...Object.keys(peerDependencies)])];
2145
+ getProjectDependencyPaths() {
2146
+ return this.dependencyPaths ??= Files.read(Paths.absolute(this.directory, "package.json")).then((content) => {
2147
+ const { dependencies = {}, peerDependencies = {} } = Json.parse(content);
2148
+ return [.../* @__PURE__ */ new Set([...Object.keys(dependencies), ...Object.keys(peerDependencies)])];
2149
+ });
2158
2150
  }
2159
2151
  /**
2160
2152
  * Handles build errors by logging unexpected errors and setting appropriate exit codes.
package/dist/index.d.ts CHANGED
@@ -22,9 +22,9 @@ type RemoveIndex<T> = {
22
22
  };
23
23
  type PrettyModify<T, R extends Partial<Record<keyof T, unknown>>> = Prettify<Omit<T, keyof R> & R>;
24
24
  type Optional<T> = T | undefined | void;
25
- type OptionalReturn<T extends TypedFunction<T>> = Optional<ReturnType<T>>;
25
+ type OptionalReturn<T extends (...args: any[]) => any> = Optional<ReturnType<T>>;
26
26
  type Function<P = any, R = any> = (...args: P[]) => R;
27
- type TypedFunction<T extends (...args: Parameters<T>) => ReturnType<T>> = (...args: Parameters<T>) => ReturnType<T>;
27
+ type TypedFunction<T extends (...args: any[]) => any> = (...args: Parameters<T>) => ReturnType<T>;
28
28
  type InferredFunction<T = Function> = T extends (...args: infer P) => infer R ? (...args: P) => R : never;
29
29
  /**
30
30
  * Type representing a method function signature with typed this, arguments, and return type.
@@ -257,6 +257,7 @@ declare class TypeScriptProject implements Closable {
257
257
  private readonly buildConfiguration;
258
258
  private readonly pendingChanges;
259
259
  private readonly buildDependencies;
260
+ private dependencyPaths?;
260
261
  /**
261
262
  * Creates a TypeScript project and prepares it for building/bundling.
262
263
  * @param directory - Project root directory (defaults to current working directory)
@@ -317,7 +318,7 @@ declare class TypeScriptProject implements Closable {
317
318
  */
318
319
  private getEntryPoints;
319
320
  /**
320
- * Gets the project dependency paths.
321
+ * Gets the project dependency paths, cached after first call.
321
322
  * @returns A promise that resolves to an array of project dependency paths.
322
323
  */
323
324
  private getProjectDependencyPaths;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TypeScriptProject
3
- } from "./4GEJO7YZ.js";
4
- import "./44KSX2XO.js";
3
+ } from "./7SPSROV3.js";
4
+ import "./VMWNQL2J.js";
5
5
  export {
6
6
  TypeScriptProject
7
7
  };
package/dist/tsbuild.js CHANGED
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  BuildError,
4
4
  TypeScriptProject
5
- } from "./4GEJO7YZ.js";
6
- import "./44KSX2XO.js";
5
+ } from "./7SPSROV3.js";
6
+ import "./VMWNQL2J.js";
7
7
 
8
8
  // src/tsbuild.ts
9
9
  import { sys } from "typescript";
@@ -30,7 +30,7 @@ if (help) {
30
30
  process.exit(0);
31
31
  }
32
32
  if (version) {
33
- console.log("1.0.2");
33
+ console.log("1.0.3");
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.0.2",
3
+ "version": "1.0.3",
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",
File without changes