@d1g1tal/tsbuild 1.0.2 → 1.1.0

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";
@@ -78,7 +78,7 @@ var ConfigurationError = class extends BuildError {
78
78
  this.name = "ConfigurationError";
79
79
  }
80
80
  };
81
- var UnsupportedSyntaxError = class extends Error {
81
+ var UnsupportedSyntaxError = class extends BundleError {
82
82
  /**
83
83
  * Creates an instance of UnsupportedSyntaxError.
84
84
  * @param node The node with unsupported syntax
@@ -88,6 +88,7 @@ var UnsupportedSyntaxError = class extends Error {
88
88
  const syntaxKindName = SyntaxKind[node.kind] ?? `Unknown(${node.kind})`;
89
89
  const nodeText = node.getText ? node.getText().slice(0, 100) : "<no text>";
90
90
  super(`${message}: ${syntaxKindName} - "${nodeText}"`);
91
+ this.name = "UnsupportedSyntaxError";
91
92
  }
92
93
  };
93
94
  var castError = (exception) => {
@@ -448,7 +449,6 @@ import {
448
449
  getCombinedModifierFlags
449
450
  } from "typescript";
450
451
  import MagicString from "magic-string";
451
- var codeTransformationComparator = (a, b) => b.start - a.start;
452
452
  var DeclarationProcessor = class _DeclarationProcessor {
453
453
  constructor() {
454
454
  }
@@ -558,7 +558,7 @@ var DeclarationProcessor = class _DeclarationProcessor {
558
558
  let hasDeclare = false;
559
559
  for (const modifier of node.modifiers ?? []) {
560
560
  if (modifier.kind === SyntaxKind2.DefaultKeyword || modifier.kind === SyntaxKind2.ExportKeyword) {
561
- code.remove(modifier.getStart(), modifier.getEnd() + 1);
561
+ code.remove(modifier.getStart(), modifier.getEnd() + getTrailingWhitespaceLength(modifier.getEnd(), node.getEnd()));
562
562
  } else if (modifier.kind === SyntaxKind2.DeclareKeyword) {
563
563
  hasDeclare = true;
564
564
  }
@@ -747,22 +747,17 @@ var DeclarationProcessor = class _DeclarationProcessor {
747
747
  * @returns The processed source code
748
748
  */
749
749
  static postProcess(sourceFile) {
750
- let code = sourceFile.getFullText();
751
- const transformations = [];
750
+ const magic = new MagicString(sourceFile.getFullText());
752
751
  function visitNode(node) {
753
752
  if (isEmptyStatement(node)) {
754
- transformations.push({ start: node.getStart(), end: node.getEnd() });
753
+ magic.remove(node.getStart(), node.getEnd());
755
754
  return;
756
755
  }
757
756
  if ((isImportDeclaration(node) || isExportDeclaration(node)) && node.moduleSpecifier && isStringLiteral(node.moduleSpecifier)) {
758
757
  const { text } = node.moduleSpecifier;
759
758
  if (text.startsWith(".") && text.endsWith(FileExtension.DTS)) {
760
759
  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
- });
760
+ magic.overwrite(node.moduleSpecifier.getStart() + 1, node.moduleSpecifier.getEnd() - 1, replacement);
766
761
  }
767
762
  }
768
763
  if (isModuleDeclaration(node) && node.body && isModuleBlock(node.body)) {
@@ -770,7 +765,7 @@ var DeclarationProcessor = class _DeclarationProcessor {
770
765
  if (isExportDeclaration(bodyStatement) && bodyStatement.exportClause && !isNamespaceExport(bodyStatement.exportClause)) {
771
766
  for (const { name, propertyName } of bodyStatement.exportClause.elements) {
772
767
  if (propertyName && isIdentifier(propertyName) && isIdentifier(name) && propertyName.getText() === name.getText()) {
773
- transformations.push({ start: propertyName.getStart(), end: name.getStart() });
768
+ magic.remove(propertyName.getStart(), name.getStart());
774
769
  }
775
770
  }
776
771
  }
@@ -779,10 +774,7 @@ var DeclarationProcessor = class _DeclarationProcessor {
779
774
  forEachChild(node, visitNode);
780
775
  }
781
776
  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;
777
+ return magic.toString();
786
778
  }
787
779
  };
788
780
 
@@ -799,7 +791,6 @@ import {
799
791
  isFunctionDeclaration as isFunctionDeclaration2,
800
792
  isClassDeclaration as isClassDeclaration2,
801
793
  isVariableStatement as isVariableStatement2,
802
- isModuleBlock as isModuleBlock2,
803
794
  isModuleDeclaration as isModuleDeclaration2,
804
795
  isNamedExports as isNamedExports2,
805
796
  isIdentifier as isIdentifier2,
@@ -838,21 +829,25 @@ function mergeImports(imports) {
838
829
  return result;
839
830
  }
840
831
  var DeclarationBundler = class {
841
- /** d.ts Bundle Options (internally mutable for caching - stores pre-processed declarations) */
832
+ /** Project declaration files from in-memory FileManager */
842
833
  declarationFiles = /* @__PURE__ */ new Map();
834
+ /** External declaration files resolved from disk (node_modules) when resolve is enabled */
835
+ externalDeclarationFiles = /* @__PURE__ */ new Map();
843
836
  /** d.ts Bundle Options */
844
837
  options;
845
838
  /** WeakMap cache for identifier collection to avoid re-parsing same source files */
846
839
  identifierCache = /* @__PURE__ */ new WeakMap();
847
840
  /** Module resolution cache for this bundler instance */
848
841
  moduleResolutionCache = /* @__PURE__ */ new Map();
842
+ /** Pre-computed set of directory prefixes from declaration file paths for O(1) directoryExists lookups */
843
+ declarationDirs = /* @__PURE__ */ new Set();
849
844
  // Create a proper module resolution host that supports both in-memory files and disk files
850
845
  moduleResolutionHost = {
851
846
  fileExists: (fileName) => {
852
- return this.declarationFiles.has(fileName) || this.options.resolve && sys.fileExists(fileName);
847
+ return this.declarationFiles.has(fileName) || this.externalDeclarationFiles.has(fileName) || this.options.resolve && sys.fileExists(fileName);
853
848
  },
854
849
  readFile: (fileName) => {
855
- const cached = this.declarationFiles.get(fileName);
850
+ const cached = this.declarationFiles.get(fileName) ?? this.externalDeclarationFiles.get(fileName);
856
851
  if (cached) {
857
852
  return cached.code;
858
853
  }
@@ -862,19 +857,14 @@ var DeclarationBundler = class {
862
857
  const rawContent = sys.readFile(fileName, Encoding.utf8);
863
858
  if (rawContent !== void 0) {
864
859
  const preProcessOutput = DeclarationProcessor.preProcess(createSourceFile(fileName, rawContent, ScriptTarget.Latest, true));
865
- this.declarationFiles.set(fileName, preProcessOutput);
860
+ this.externalDeclarationFiles.set(fileName, preProcessOutput);
866
861
  return preProcessOutput.code;
867
862
  }
868
863
  return void 0;
869
864
  },
870
865
  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;
866
+ const normalizedDir = dirName.endsWith("/") ? dirName.slice(0, -1) : dirName;
867
+ return this.declarationDirs.has(normalizedDir) || (this.options.resolve ? sys.directoryExists(dirName) : false);
878
868
  },
879
869
  getCurrentDirectory: () => this.options.currentDirectory,
880
870
  /* v8 ignore next */
@@ -888,8 +878,27 @@ var DeclarationBundler = class {
888
878
  for (const [filePath, cachedDecl] of dtsBundleOptions.declarationFiles) {
889
879
  this.declarationFiles.set(sys.resolvePath(filePath), cachedDecl);
890
880
  }
881
+ for (const filePath of this.declarationFiles.keys()) {
882
+ let dir = filePath.lastIndexOf("/") !== -1 ? filePath.slice(0, filePath.lastIndexOf("/")) : "";
883
+ while (dir.length > 0) {
884
+ if (this.declarationDirs.has(dir)) {
885
+ break;
886
+ }
887
+ this.declarationDirs.add(dir);
888
+ const nextSlash = dir.lastIndexOf("/");
889
+ dir = nextSlash !== -1 ? dir.slice(0, nextSlash) : "";
890
+ }
891
+ }
891
892
  this.options = dtsBundleOptions;
892
893
  }
894
+ /**
895
+ * Clears external declaration files and module resolution cache to free memory.
896
+ * Called after all entry points have been bundled.
897
+ */
898
+ clearExternalFiles() {
899
+ this.externalDeclarationFiles.clear();
900
+ this.moduleResolutionCache.clear();
901
+ }
893
902
  /**
894
903
  * Convert a source file path to its corresponding declaration file path
895
904
  * @param sourcePath - Absolute path to a source file (.ts, .tsx)
@@ -986,7 +995,7 @@ var DeclarationBundler = class {
986
995
  return;
987
996
  }
988
997
  visited.add(path);
989
- const cached = this.declarationFiles.get(path);
998
+ const cached = this.declarationFiles.get(path) ?? this.externalDeclarationFiles.get(path);
990
999
  if (cached === void 0) {
991
1000
  return;
992
1001
  }
@@ -1003,15 +1012,7 @@ var DeclarationBundler = class {
1003
1012
  if (resolvedPath?.includes(nodeModules) && !this.matchesPattern(specifier, this.options.noExternal)) {
1004
1013
  continue;
1005
1014
  }
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
- if (resolvedPath && this.declarationFiles.has(resolvedPath)) {
1015
+ if (resolvedPath && (this.declarationFiles.has(resolvedPath) || this.externalDeclarationFiles.has(resolvedPath))) {
1015
1016
  module.imports.add(resolvedPath);
1016
1017
  bundledSpecs.push(specifier);
1017
1018
  visit(resolvedPath);
@@ -1034,7 +1035,11 @@ var DeclarationBundler = class {
1034
1035
  const visited = /* @__PURE__ */ new Set();
1035
1036
  const visiting = /* @__PURE__ */ new Set();
1036
1037
  const visit = (path) => {
1037
- if (visited.has(path) || visiting.has(path)) {
1038
+ if (visited.has(path)) {
1039
+ return;
1040
+ }
1041
+ if (visiting.has(path)) {
1042
+ Logger.warn(`Circular dependency detected: ${Paths.relative(this.options.currentDirectory, path)}`);
1038
1043
  return;
1039
1044
  }
1040
1045
  visiting.add(path);
@@ -1094,8 +1099,6 @@ var DeclarationBundler = class {
1094
1099
  values.add(name.text);
1095
1100
  }
1096
1101
  }
1097
- } else if (isModuleBlock2(statement)) {
1098
- collectNestedIdentifiers(statement.statements);
1099
1102
  } else if (isModuleDeclaration2(statement)) {
1100
1103
  if (statement.name && isIdentifier2(statement.name)) {
1101
1104
  values.add(statement.name.text);
@@ -1170,7 +1173,7 @@ var DeclarationBundler = class {
1170
1173
  if (isIdentifier2(node)) {
1171
1174
  const renamed = moduleRenames.get(node.text);
1172
1175
  if (renamed) {
1173
- magic.overwrite(node.pos, node.end, renamed);
1176
+ magic.overwrite(node.getStart(), node.end, renamed);
1174
1177
  }
1175
1178
  }
1176
1179
  forEachChild2(node, visit);
@@ -1215,9 +1218,15 @@ var DeclarationBundler = class {
1215
1218
  for (const [name, sourcesSet] of declarationSources) {
1216
1219
  if (sourcesSet.size > 1) {
1217
1220
  const sources = Array.from(sourcesSet);
1218
- sources.slice(1).forEach((modulePath, index) => {
1219
- renameMap.set(`${name}:${modulePath}`, `${name}$${index + 1}`);
1220
- });
1221
+ let suffix = 1;
1222
+ for (const modulePath of sources.slice(1)) {
1223
+ let candidate = `${name}$${suffix}`;
1224
+ while (declarationSources.has(candidate)) {
1225
+ candidate = `${name}$${++suffix}`;
1226
+ }
1227
+ renameMap.set(`${name}:${modulePath}`, candidate);
1228
+ suffix++;
1229
+ }
1221
1230
  }
1222
1231
  }
1223
1232
  for (const { path, typeReferences, fileReferences, sourceFile, code, identifiers } of sortedModules) {
@@ -1328,7 +1337,9 @@ async function bundleDeclarations(options) {
1328
1337
  await writeFile2(outPath, content, Encoding.utf8);
1329
1338
  return { path: Paths.relative(options.currentDirectory, outPath), size: content.length };
1330
1339
  });
1331
- return Promise.all(bundleTasks);
1340
+ const results = await Promise.all(bundleTasks);
1341
+ dtsBundler.clearExternalFiles();
1342
+ return results;
1332
1343
  }
1333
1344
 
1334
1345
  // src/plugins/output.ts
@@ -1827,6 +1838,97 @@ var IncrementalBuildCache = class {
1827
1838
  }
1828
1839
  };
1829
1840
 
1841
+ // src/entry-points.ts
1842
+ var importConditions = ["import", "default"];
1843
+ var outputToSourceExtension = /* @__PURE__ */ new Map([
1844
+ [".js", ".ts"],
1845
+ [".mjs", ".ts"],
1846
+ [".jsx", ".tsx"],
1847
+ [".d.ts", ".ts"],
1848
+ [".d.mts", ".ts"]
1849
+ ]);
1850
+ function outputToSourcePath(outputPath, outDir, sourceDir) {
1851
+ const normalizedOutput = outputPath.replace(/^\.\//, "");
1852
+ const normalizedOutDir = outDir.replace(/^\.\//, "").replace(/\/$/, "");
1853
+ if (!normalizedOutput.startsWith(normalizedOutDir + "/") && normalizedOutput !== normalizedOutDir) {
1854
+ return void 0;
1855
+ }
1856
+ const relativePortion = normalizedOutput.slice(normalizedOutDir.length + 1);
1857
+ for (const [outExt, srcExt] of outputToSourceExtension) {
1858
+ if (relativePortion.endsWith(outExt)) {
1859
+ const stem = relativePortion.slice(0, -outExt.length);
1860
+ return `./${sourceDir}/${stem}${srcExt}`;
1861
+ }
1862
+ }
1863
+ return void 0;
1864
+ }
1865
+ function resolveConditionalExport(exportValue) {
1866
+ if (typeof exportValue === "string") {
1867
+ return exportValue;
1868
+ }
1869
+ for (const condition of importConditions) {
1870
+ const value = exportValue[condition];
1871
+ if (typeof value === "string") {
1872
+ return value;
1873
+ }
1874
+ }
1875
+ return void 0;
1876
+ }
1877
+ function subpathToEntryName(subpath, packageName) {
1878
+ if (subpath === ".") {
1879
+ return packageName ?? "index";
1880
+ }
1881
+ const withoutPrefix = subpath.replace(/^\.\//, "");
1882
+ const lastSegment = withoutPrefix.lastIndexOf("/");
1883
+ return lastSegment === -1 ? withoutPrefix : withoutPrefix.slice(lastSegment + 1);
1884
+ }
1885
+ function inferEntryPoints(packageJson, outDir, sourceDir = "src") {
1886
+ const entryPoints = {};
1887
+ if (packageJson.exports !== void 0) {
1888
+ if (typeof packageJson.exports === "string") {
1889
+ const sourcePath = outputToSourcePath(packageJson.exports, outDir, sourceDir);
1890
+ if (sourcePath) {
1891
+ entryPoints[packageJson.name ?? "index"] = sourcePath;
1892
+ }
1893
+ } else {
1894
+ for (const [subpath, exportValue] of Object.entries(packageJson.exports)) {
1895
+ if (subpath.includes("*")) {
1896
+ continue;
1897
+ }
1898
+ const outputPath = resolveConditionalExport(exportValue);
1899
+ if (outputPath === void 0) {
1900
+ continue;
1901
+ }
1902
+ const sourcePath = outputToSourcePath(outputPath, outDir, sourceDir);
1903
+ if (sourcePath) {
1904
+ entryPoints[subpathToEntryName(subpath, packageJson.name)] = sourcePath;
1905
+ }
1906
+ }
1907
+ }
1908
+ }
1909
+ if (packageJson.bin !== void 0) {
1910
+ const binEntries = typeof packageJson.bin === "string" ? { [packageJson.name ?? "cli"]: packageJson.bin } : packageJson.bin;
1911
+ for (const [name, outputPath] of Object.entries(binEntries)) {
1912
+ if (entryPoints[name] === void 0) {
1913
+ const sourcePath = outputToSourcePath(outputPath, outDir, sourceDir);
1914
+ if (sourcePath) {
1915
+ entryPoints[name] = sourcePath;
1916
+ }
1917
+ }
1918
+ }
1919
+ }
1920
+ if (Object.keys(entryPoints).length === 0) {
1921
+ const legacyPath = packageJson.module ?? packageJson.main;
1922
+ if (legacyPath !== void 0) {
1923
+ const sourcePath = outputToSourcePath(legacyPath, outDir, sourceDir);
1924
+ if (sourcePath) {
1925
+ entryPoints["index"] = sourcePath;
1926
+ }
1927
+ }
1928
+ }
1929
+ return Object.keys(entryPoints).length > 0 ? entryPoints : void 0;
1930
+ }
1931
+
1830
1932
  // src/type-script-project.ts
1831
1933
  import { build as esbuild, formatMessages } from "esbuild";
1832
1934
  import { sys as sys3, createIncrementalProgram, formatDiagnostics, formatDiagnosticsWithColorAndContext, parseJsonConfigFileContent, readConfigFile, findConfigFile } from "typescript";
@@ -1851,6 +1953,8 @@ var _TypeScriptProject = class _TypeScriptProject {
1851
1953
  __publicField(this, "buildConfiguration");
1852
1954
  __publicField(this, "pendingChanges", []);
1853
1955
  __publicField(this, "buildDependencies", /* @__PURE__ */ new Set());
1956
+ __publicField(this, "dependencyPaths");
1957
+ __publicField(this, "packageJson");
1854
1958
  this.directory = Paths.absolute(directory);
1855
1959
  this.configuration = _TypeScriptProject.resolveConfiguration(this.directory, options);
1856
1960
  const { buildCache, rootNames, projectReferences, configFileParsingDiagnostics, tsbuild: { entryPoints, ...tsbuildOptions }, compilerOptions: { target, outDir } } = this.configuration;
@@ -1869,11 +1973,11 @@ var _TypeScriptProject = class _TypeScriptProject {
1869
1973
  return Files.empty(this.buildConfiguration.outDir);
1870
1974
  }
1871
1975
  async build() {
1872
- Logger.header(`\u{1F680} tsbuild v${"1.0.2"}${this.configuration.compilerOptions.incremental ? " [incremental]" : ""}`);
1976
+ Logger.header(`\u{1F680} tsbuild v${"1.1.0"}${this.configuration.compilerOptions.incremental ? " [incremental]" : ""}`);
1873
1977
  try {
1874
1978
  const processes = [];
1875
1979
  const filesWereEmitted = await this.typeCheck();
1876
- if (filesWereEmitted && (!this.configuration.compilerOptions.noEmit || this.configuration.tsbuild.force)) {
1980
+ if ((filesWereEmitted || this.configuration.tsbuild.force) && !this.configuration.compilerOptions.noEmit) {
1877
1981
  if (this.configuration.clean) {
1878
1982
  await this.clean();
1879
1983
  }
@@ -1920,7 +2024,7 @@ var _TypeScriptProject = class _TypeScriptProject {
1920
2024
  }
1921
2025
  if (this.configuration.compilerOptions.emitDecoratorMetadata) {
1922
2026
  try {
1923
- const { swcDecoratorMetadataPlugin } = await import("./QAEHWWWE.js");
2027
+ const { swcDecoratorMetadataPlugin } = await import("./7ALTNLQM.js");
1924
2028
  plugins.push(swcDecoratorMetadataPlugin);
1925
2029
  } catch {
1926
2030
  throw new ConfigurationError("emitDecoratorMetadata is enabled but @swc/core is not installed. Install it with: pnpm add -D @swc/core");
@@ -2061,11 +2165,13 @@ var _TypeScriptProject = class _TypeScriptProject {
2061
2165
  const index = rootNames.indexOf(path);
2062
2166
  if (event === Watchr.FileEvent.unlink && index !== -1) {
2063
2167
  rootNames.splice(index, 1);
2168
+ } else if (event === Watchr.FileEvent.add && index === -1) {
2169
+ rootNames.push(path);
2064
2170
  }
2065
2171
  }
2066
2172
  }
2067
2173
  this.pendingChanges.length = 0;
2068
- this.builderProgram = createIncrementalProgram({ rootNames, options: this.configuration.compilerOptions, projectReferences: this.configuration.projectReferences });
2174
+ this.builderProgram = createIncrementalProgram({ rootNames, options: this.configuration.compilerOptions, projectReferences: this.configuration.projectReferences, configFileParsingDiagnostics: this.configuration.configFileParsingDiagnostics });
2069
2175
  await this.build();
2070
2176
  }
2071
2177
  /**
@@ -2082,6 +2188,19 @@ var _TypeScriptProject = class _TypeScriptProject {
2082
2188
  const bundle = typeScriptOptions.tsbuild?.bundle ?? configResult.config.tsbuild?.bundle ?? true;
2083
2189
  const platform2 = configResult.config.compilerOptions?.lib?.some(domPredicate) ? Platform.BROWSER : Platform.NODE;
2084
2190
  const noExternal = typeScriptOptions.tsbuild?.noExternal ?? configResult.config.tsbuild?.noExternal ?? [];
2191
+ const hasExplicitEntryPoints = typeScriptOptions.tsbuild?.entryPoints !== void 0 || configResult.config.tsbuild?.entryPoints !== void 0;
2192
+ let inferredEntryPoints;
2193
+ if (!hasExplicitEntryPoints && bundle) {
2194
+ const packageJsonContent = sys3.readFile(Paths.join(directory, "package.json"));
2195
+ if (packageJsonContent) {
2196
+ try {
2197
+ const pkgJson = JSON.parse(packageJsonContent);
2198
+ const outDir = typeScriptOptions.compilerOptions?.outDir ?? configResult.config.compilerOptions?.outDir ?? defaultOutDirectory;
2199
+ inferredEntryPoints = inferEntryPoints(pkgJson, outDir);
2200
+ } catch {
2201
+ }
2202
+ }
2203
+ }
2085
2204
  const defaultTsbuildConfig = {
2086
2205
  splitting: bundle,
2087
2206
  minify: false,
@@ -2093,7 +2212,7 @@ var _TypeScriptProject = class _TypeScriptProject {
2093
2212
  platform: platform2,
2094
2213
  dts: { resolve: platform2 !== Platform.NODE, entryPoints: bundle ? void 0 : [] },
2095
2214
  watch: { enabled: false, recursive: true, ignoreInitial: true, persistent: true },
2096
- entryPoints: bundle ? { [defaultEntryPoint]: defaultEntryFile } : { src: defaultSourceDirectory }
2215
+ entryPoints: inferredEntryPoints ?? (bundle ? { [defaultEntryPoint]: defaultEntryFile } : { src: defaultSourceDirectory })
2097
2216
  };
2098
2217
  const baseConfig = {
2099
2218
  ...configResult.config,
@@ -2108,8 +2227,7 @@ var _TypeScriptProject = class _TypeScriptProject {
2108
2227
  compilerOptions: {
2109
2228
  ...{ outDir: defaultOutDirectory, noEmit: false, sourceMap: false, incremental: true, tsBuildInfoFile: Paths.join(cacheDirectory, buildInfoFile), lib: [] },
2110
2229
  ...configResult.config.compilerOptions,
2111
- ...typeScriptOptions.compilerOptions,
2112
- ...compilerOptionOverrides
2230
+ ...typeScriptOptions.compilerOptions
2113
2231
  }
2114
2232
  };
2115
2233
  const { options, fileNames, errors } = parseJsonConfigFileContent(baseConfig, sys3, directory);
@@ -2149,12 +2267,17 @@ var _TypeScriptProject = class _TypeScriptProject {
2149
2267
  return expandedEntryPoints;
2150
2268
  }
2151
2269
  /**
2152
- * Gets the project dependency paths.
2270
+ * Gets the project dependency paths, cached after first call.
2271
+ * Reads package.json and caches it for reuse.
2153
2272
  * @returns A promise that resolves to an array of project dependency paths.
2154
2273
  */
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)])];
2274
+ getProjectDependencyPaths() {
2275
+ return this.dependencyPaths ??= Files.read(Paths.absolute(this.directory, "package.json")).then((content) => {
2276
+ const packageJson = Json.parse(content);
2277
+ this.packageJson = packageJson;
2278
+ const { dependencies = {}, peerDependencies = {} } = packageJson;
2279
+ return [.../* @__PURE__ */ new Set([...Object.keys(dependencies), ...Object.keys(peerDependencies)])];
2280
+ });
2158
2281
  }
2159
2282
  /**
2160
2283
  * 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,8 @@ declare class TypeScriptProject implements Closable {
257
257
  private readonly buildConfiguration;
258
258
  private readonly pendingChanges;
259
259
  private readonly buildDependencies;
260
+ private dependencyPaths?;
261
+ private packageJson?;
260
262
  /**
261
263
  * Creates a TypeScript project and prepares it for building/bundling.
262
264
  * @param directory - Project root directory (defaults to current working directory)
@@ -317,7 +319,8 @@ declare class TypeScriptProject implements Closable {
317
319
  */
318
320
  private getEntryPoints;
319
321
  /**
320
- * Gets the project dependency paths.
322
+ * Gets the project dependency paths, cached after first call.
323
+ * Reads package.json and caches it for reuse.
321
324
  * @returns A promise that resolves to an array of project dependency paths.
322
325
  */
323
326
  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 "./BLUMG6XT.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 "./BLUMG6XT.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.1.0");
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.1.0",
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",
package/schema.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "additionalProperties": false,
17
17
  "properties": {
18
18
  "entryPoints": {
19
- "markdownDescription": "Files that each serve as an input to the bundling algorithm. Can be an array of paths or an object mapping output names to input paths.",
19
+ "markdownDescription": "Files that each serve as an input to the bundling algorithm. Can be an array of paths or an object mapping output names to input paths.\n\nWhen omitted, tsbuild auto-infers entry points from the `exports`, `bin`, `main`, or `module` fields in `package.json` by reverse-mapping output paths to source paths.",
20
20
  "oneOf": [
21
21
  {
22
22
  "type": "array",
File without changes