vite-plugin-dts 4.3.0 → 4.5.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.
package/dist/index.cjs CHANGED
@@ -29,6 +29,9 @@ const windowsSlashRE = /\\+/g;
29
29
  function slash(p) {
30
30
  return p.replace(windowsSlashRE, "/");
31
31
  }
32
+ function resolveConfigDir(path, configDir) {
33
+ return path.replace("${configDir}", configDir);
34
+ }
32
35
  function normalizePath(id) {
33
36
  return node_path.posix.normalize(slash(id));
34
37
  }
@@ -195,7 +198,7 @@ function tryGetPkgPath(beginPath) {
195
198
  }
196
199
  const parentDir = normalizePath(node_path.dirname(beginPath));
197
200
  if (!parentDir || parentDir === beginPath) {
198
- pkgPathCache.set(beginPath, void 0);
201
+ pkgPathCache.set(beginPath, undefined);
199
202
  return;
200
203
  }
201
204
  return tryGetPkgPath(parentDir);
@@ -211,16 +214,13 @@ function toCapitalCase(value) {
211
214
  function findTypesPath(...pkgs) {
212
215
  let path;
213
216
  for (const pkg of pkgs) {
214
- if (typeof pkg !== "object")
215
- continue;
217
+ if (typeof pkg !== "object") continue;
216
218
  path = pkg.types || pkg.typings || pkg.exports?.types || pkg.exports?.["."]?.types || pkg.exports?.["./"]?.types;
217
- if (path)
218
- return path;
219
+ if (path) return path;
219
220
  }
220
221
  }
221
222
  function setModuleResolution(options) {
222
- if (options.moduleResolution)
223
- return;
223
+ if (options.moduleResolution) return;
224
224
  const module = typeof options.module === "number" ? options.module : options.target ?? ts__default.ScriptTarget.ES5 >= 2 ? ts__default.ModuleKind.ES2015 : ts__default.ModuleKind.CommonJS;
225
225
  let moduleResolution;
226
226
  switch (module) {
@@ -273,9 +273,41 @@ function parseTsAliases(basePath, paths) {
273
273
  }
274
274
  return result;
275
275
  }
276
+ const rootAsteriskImportRE = /^(?!\.{1,2}\/)([^*]+)$/;
277
+ function isAliasGlobal(alias) {
278
+ return alias.find.toString() === rootAsteriskImportRE.toString();
279
+ }
280
+ function importResolves(path) {
281
+ const files = [
282
+ // js
283
+ ".js",
284
+ ".jsx",
285
+ ".mjs",
286
+ ".cjs",
287
+ // ts
288
+ ".ts",
289
+ ".tsx",
290
+ ".mts",
291
+ ".cts",
292
+ ".d.ts",
293
+ // json
294
+ ".json",
295
+ // vue
296
+ ".vue",
297
+ ".vue.d.ts",
298
+ // svelte
299
+ ".svelte"
300
+ ];
301
+ for (const ext of files) {
302
+ if (node_fs.existsSync(path + ext)) {
303
+ return true;
304
+ }
305
+ }
306
+ return false;
307
+ }
276
308
  function tryGetPackageInfo(name) {
277
309
  if (process.versions.pnp) {
278
- const targetRequire = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
310
+ const targetRequire = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
279
311
  try {
280
312
  return localPkg.getPackageInfoSync(
281
313
  targetRequire.resolve(`${name}/package.json`, { paths: [process.cwd()] })
@@ -385,8 +417,7 @@ function JsonResolver() {
385
417
  },
386
418
  transform({ id, root, program }) {
387
419
  const sourceFile = program.getSourceFile(id);
388
- if (!sourceFile)
389
- return [];
420
+ if (!sourceFile) return [];
390
421
  return [
391
422
  {
392
423
  path: node_path.relative(root, `${id}.d.ts`),
@@ -403,8 +434,7 @@ export default _default;
403
434
  const svelteRE = /\.svelte$/;
404
435
  let lowerVersion;
405
436
  function querySvelteVersion() {
406
- if (typeof lowerVersion === "boolean")
407
- return;
437
+ if (typeof lowerVersion === "boolean") return;
408
438
  try {
409
439
  const version = tryGetPackageInfo("svelte")?.version;
410
440
  lowerVersion = version ? compareVersions.compare(version, "4.0.0", "<") : false;
@@ -440,19 +470,17 @@ function VueResolver() {
440
470
  },
441
471
  transform({ id, code, program }) {
442
472
  const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
443
- if (!sourceFile)
444
- return [];
473
+ if (!sourceFile) return [];
445
474
  const outputs = [];
446
475
  program.emit(
447
476
  sourceFile,
448
477
  (path, content) => {
449
478
  outputs.push({ path, content });
450
479
  },
451
- void 0,
480
+ undefined,
452
481
  true
453
482
  );
454
- if (!program.getCompilerOptions().declarationMap)
455
- return outputs;
483
+ if (!program.getCompilerOptions().declarationMap) return outputs;
456
484
  const [beforeScript] = code.split(/\s*<script.*>/);
457
485
  const beforeLines = beforeScript.split("\n").length;
458
486
  for (const output of outputs) {
@@ -501,12 +529,9 @@ function walkSourceFile(sourceFile, callback) {
501
529
  sourceFile.forEachChild((child) => walkNode(child, sourceFile, callback));
502
530
  }
503
531
  function isAliasMatch(alias, importer) {
504
- if (isRegExp(alias.find))
505
- return alias.find.test(importer);
506
- if (importer.length < alias.find.length)
507
- return false;
508
- if (importer === alias.find)
509
- return true;
532
+ if (isRegExp(alias.find)) return alias.find.test(importer);
533
+ if (importer.length < alias.find.length) return false;
534
+ if (importer === alias.find) return true;
510
535
  return importer.indexOf(alias.find) === 0 && (alias.find.endsWith("/") || importer.substring(alias.find.length)[0] === "/");
511
536
  }
512
537
  function transformAlias(importer, dir, aliases, aliasesExclude) {
@@ -519,8 +544,11 @@ function transformAlias(importer, dir, aliases, aliasesExclude) {
519
544
  matchedAlias.find,
520
545
  replacement + (endsWithSlash ? "/" : "")
521
546
  );
522
- const normalizedPath = normalizePath(node_path.relative(dir, node_path.resolve(dir, truthPath)));
523
- return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
547
+ const absolutePath = node_path.resolve(dir, truthPath);
548
+ const normalizedPath = normalizePath(node_path.relative(dir, absolutePath));
549
+ const resultPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
550
+ if (!isAliasGlobal(matchedAlias)) return resultPath;
551
+ if (importResolves(absolutePath)) return resultPath;
524
552
  }
525
553
  }
526
554
  return importer;
@@ -713,7 +741,7 @@ const fixedCompilerOptions = {
713
741
  checkJs: false,
714
742
  skipLibCheck: true,
715
743
  preserveSymlinks: false,
716
- noEmitOnError: void 0,
744
+ noEmitOnError: undefined,
717
745
  target: ts__default.ScriptTarget.ESNext
718
746
  };
719
747
  const noop = () => {
@@ -769,6 +797,7 @@ function dtsPlugin(options = {}) {
769
797
  ]);
770
798
  const rootFiles = /* @__PURE__ */ new Set();
771
799
  const outputFiles = /* @__PURE__ */ new Map();
800
+ const transformedFiles = /* @__PURE__ */ new Set();
772
801
  const setOutputFile = (path, content) => {
773
802
  outputFiles.set(path, content);
774
803
  };
@@ -842,8 +871,7 @@ ${logPrefix} ${kolorist.yellow(
842
871
  bundleDebug("parse vite config");
843
872
  },
844
873
  options(options2) {
845
- if (entries)
846
- return;
874
+ if (entries) return;
847
875
  const input = typeof options2.input === "string" ? [options2.input] : options2.input;
848
876
  if (Array.isArray(input)) {
849
877
  entries = input.reduce(
@@ -863,13 +891,12 @@ ${logPrefix} ${kolorist.yellow(
863
891
  bundleDebug("parse options");
864
892
  },
865
893
  async buildStart() {
866
- if (program)
867
- return;
894
+ if (program) return;
868
895
  bundleDebug("begin buildStart");
869
896
  timeRecord = 0;
870
897
  const startTime = Date.now();
871
898
  configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts__default.findConfigFile(root, ts__default.sys.fileExists);
872
- const content = configPath ? languageCore.createParsedCommandLine(ts__default, ts__default.sys, configPath) : void 0;
899
+ const content = configPath ? languageCore.createParsedCommandLine(ts__default, ts__default.sys, configPath) : undefined;
873
900
  compilerOptions = {
874
901
  ...content?.options || {},
875
902
  ...options.compilerOptions || {},
@@ -882,26 +909,41 @@ ${logPrefix} ${kolorist.yellow(
882
909
  setModuleResolution(compilerOptions);
883
910
  }
884
911
  if (!outDirs) {
885
- outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
912
+ outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [
913
+ ensureAbsolute(
914
+ content?.raw.compilerOptions?.outDir ? resolveConfigDir(content.raw.compilerOptions.outDir, root) : "dist",
915
+ root
916
+ )
917
+ ];
886
918
  }
887
919
  const {
888
920
  // Here we are using the default value to set the `baseUrl` to the current directory if no value exists. This is
889
921
  // the same behavior as the TS Compiler. See TS source:
890
922
  // https://github.com/microsoft/TypeScript/blob/3386e943215613c40f68ba0b108cda1ddb7faee1/src/compiler/utilities.ts#L6493-L6501
891
- baseUrl = compilerOptions.paths ? process.cwd() : void 0,
923
+ baseUrl = compilerOptions.paths ? process.cwd() : undefined,
892
924
  paths
893
925
  } = compilerOptions;
894
926
  if (pathsToAliases && baseUrl && paths) {
895
927
  aliases.push(
896
- ...parseTsAliases(ensureAbsolute(baseUrl, configPath ? node_path.dirname(configPath) : root), paths)
928
+ ...parseTsAliases(
929
+ ensureAbsolute(
930
+ resolveConfigDir(baseUrl, root),
931
+ configPath ? node_path.dirname(configPath) : root
932
+ ),
933
+ paths
934
+ )
897
935
  );
898
936
  }
899
937
  const computeGlobs = (rootGlobs, tsGlobs, defaultGlob) => {
900
938
  if (rootGlobs?.length) {
901
- return ensureArray(rootGlobs).map((glob) => normalizeGlob(ensureAbsolute(glob, root)));
939
+ return ensureArray(rootGlobs).map(
940
+ (glob) => normalizeGlob(ensureAbsolute(resolveConfigDir(glob, root), root))
941
+ );
902
942
  }
903
943
  return ensureArray(tsGlobs?.length ? tsGlobs : defaultGlob).map(
904
- (glob) => normalizeGlob(ensureAbsolute(glob, configPath ? node_path.dirname(configPath) : root))
944
+ (glob) => normalizeGlob(
945
+ ensureAbsolute(resolveConfigDir(glob, root), configPath ? node_path.dirname(configPath) : root)
946
+ )
905
947
  );
906
948
  };
907
949
  include = computeGlobs(
@@ -928,7 +970,7 @@ ${logPrefix} ${kolorist.yellow(
928
970
  const maybeEmitted = (sourceFile) => {
929
971
  return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
930
972
  };
931
- publicRoot = compilerOptions.rootDir ? ensureAbsolute(compilerOptions.rootDir, root) : compilerOptions.composite && compilerOptions.configFilePath ? node_path.dirname(compilerOptions.configFilePath) : queryPublicPath(
973
+ publicRoot = compilerOptions.rootDir ? ensureAbsolute(resolveConfigDir(compilerOptions.rootDir, root), root) : compilerOptions.composite && compilerOptions.configFilePath ? node_path.dirname(compilerOptions.configFilePath) : queryPublicPath(
932
974
  program.getSourceFiles().filter(maybeEmitted).map((sourceFile) => sourceFile.fileName)
933
975
  );
934
976
  publicRoot = normalizePath(publicRoot);
@@ -954,14 +996,14 @@ ${logPrefix} ${kolorist.yellow(
954
996
  },
955
997
  async transform(code, id) {
956
998
  let resolver;
957
- id = normalizePath(id);
958
- if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id)) {
999
+ id = normalizePath(id).split("?")[0];
1000
+ if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id) || transformedFiles.has(id)) {
959
1001
  return;
960
1002
  }
961
1003
  const startTime = Date.now();
962
1004
  const outDir = outDirs[0];
963
- id = id.split("?")[0];
964
1005
  rootFiles.delete(id);
1006
+ transformedFiles.add(id);
965
1007
  if (resolver) {
966
1008
  const result = await resolver.transform({
967
1009
  id,
@@ -988,7 +1030,7 @@ ${logPrefix} ${kolorist.yellow(
988
1030
  text
989
1031
  );
990
1032
  },
991
- void 0,
1033
+ undefined,
992
1034
  true
993
1035
  );
994
1036
  }
@@ -1016,8 +1058,8 @@ ${logPrefix} ${kolorist.yellow(
1016
1058
  }
1017
1059
  },
1018
1060
  async writeBundle() {
1019
- if (!host || !program || bundled)
1020
- return;
1061
+ transformedFiles.clear();
1062
+ if (!host || !program || bundled) return;
1021
1063
  bundled = true;
1022
1064
  bundleDebug("begin writeBundle");
1023
1065
  logger.info(kolorist.green(`
@@ -1029,8 +1071,7 @@ ${logPrefix} Start generate declaration files...`));
1029
1071
  const writeOutput = async (path, content, outDir2, record = true) => {
1030
1072
  if (typeof beforeWriteFile === "function") {
1031
1073
  const result = await unwrapPromise(beforeWriteFile(path, content));
1032
- if (result === false)
1033
- return;
1074
+ if (result === false) return;
1034
1075
  if (result) {
1035
1076
  path = result.filePath || path;
1036
1077
  content = result.content ?? content;
@@ -1050,8 +1091,7 @@ ${logPrefix} Start generate declaration files...`));
1050
1091
  };
1051
1092
  const sourceFiles = program.getSourceFiles();
1052
1093
  for (const sourceFile of sourceFiles) {
1053
- if (!filter(sourceFile.fileName))
1054
- continue;
1094
+ if (!filter(sourceFile.fileName)) continue;
1055
1095
  if (copyDtsFiles && dtsRE.test(sourceFile.fileName)) {
1056
1096
  setOutputFile(normalizePath(sourceFile.fileName), sourceFile.getFullText());
1057
1097
  }
@@ -1064,7 +1104,7 @@ ${logPrefix} Start generate declaration files...`));
1064
1104
  text
1065
1105
  );
1066
1106
  },
1067
- void 0,
1107
+ undefined,
1068
1108
  true
1069
1109
  );
1070
1110
  rootFiles.delete(sourceFile.fileName);
@@ -1171,8 +1211,7 @@ ${logPrefix} ${kolorist.yellow(
1171
1211
  }
1172
1212
  for (const name of entryNames) {
1173
1213
  const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles) : typesPath;
1174
- if (node_fs.existsSync(entryDtsPath))
1175
- continue;
1214
+ if (node_fs.existsSync(entryDtsPath)) continue;
1176
1215
  const sourceEntry = normalizePath(
1177
1216
  cleanPath(resolve(outDir, node_path.relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
1178
1217
  );
package/dist/index.mjs CHANGED
@@ -25,6 +25,9 @@ const windowsSlashRE = /\\+/g;
25
25
  function slash(p) {
26
26
  return p.replace(windowsSlashRE, "/");
27
27
  }
28
+ function resolveConfigDir(path, configDir) {
29
+ return path.replace("${configDir}", configDir);
30
+ }
28
31
  function normalizePath(id) {
29
32
  return posix.normalize(slash(id));
30
33
  }
@@ -191,7 +194,7 @@ function tryGetPkgPath(beginPath) {
191
194
  }
192
195
  const parentDir = normalizePath(dirname(beginPath));
193
196
  if (!parentDir || parentDir === beginPath) {
194
- pkgPathCache.set(beginPath, void 0);
197
+ pkgPathCache.set(beginPath, undefined);
195
198
  return;
196
199
  }
197
200
  return tryGetPkgPath(parentDir);
@@ -207,16 +210,13 @@ function toCapitalCase(value) {
207
210
  function findTypesPath(...pkgs) {
208
211
  let path;
209
212
  for (const pkg of pkgs) {
210
- if (typeof pkg !== "object")
211
- continue;
213
+ if (typeof pkg !== "object") continue;
212
214
  path = pkg.types || pkg.typings || pkg.exports?.types || pkg.exports?.["."]?.types || pkg.exports?.["./"]?.types;
213
- if (path)
214
- return path;
215
+ if (path) return path;
215
216
  }
216
217
  }
217
218
  function setModuleResolution(options) {
218
- if (options.moduleResolution)
219
- return;
219
+ if (options.moduleResolution) return;
220
220
  const module = typeof options.module === "number" ? options.module : options.target ?? ts.ScriptTarget.ES5 >= 2 ? ts.ModuleKind.ES2015 : ts.ModuleKind.CommonJS;
221
221
  let moduleResolution;
222
222
  switch (module) {
@@ -269,6 +269,38 @@ function parseTsAliases(basePath, paths) {
269
269
  }
270
270
  return result;
271
271
  }
272
+ const rootAsteriskImportRE = /^(?!\.{1,2}\/)([^*]+)$/;
273
+ function isAliasGlobal(alias) {
274
+ return alias.find.toString() === rootAsteriskImportRE.toString();
275
+ }
276
+ function importResolves(path) {
277
+ const files = [
278
+ // js
279
+ ".js",
280
+ ".jsx",
281
+ ".mjs",
282
+ ".cjs",
283
+ // ts
284
+ ".ts",
285
+ ".tsx",
286
+ ".mts",
287
+ ".cts",
288
+ ".d.ts",
289
+ // json
290
+ ".json",
291
+ // vue
292
+ ".vue",
293
+ ".vue.d.ts",
294
+ // svelte
295
+ ".svelte"
296
+ ];
297
+ for (const ext of files) {
298
+ if (existsSync(path + ext)) {
299
+ return true;
300
+ }
301
+ }
302
+ return false;
303
+ }
272
304
  function tryGetPackageInfo(name) {
273
305
  if (process.versions.pnp) {
274
306
  const targetRequire = createRequire(import.meta.url);
@@ -381,8 +413,7 @@ function JsonResolver() {
381
413
  },
382
414
  transform({ id, root, program }) {
383
415
  const sourceFile = program.getSourceFile(id);
384
- if (!sourceFile)
385
- return [];
416
+ if (!sourceFile) return [];
386
417
  return [
387
418
  {
388
419
  path: relative(root, `${id}.d.ts`),
@@ -399,8 +430,7 @@ export default _default;
399
430
  const svelteRE = /\.svelte$/;
400
431
  let lowerVersion;
401
432
  function querySvelteVersion() {
402
- if (typeof lowerVersion === "boolean")
403
- return;
433
+ if (typeof lowerVersion === "boolean") return;
404
434
  try {
405
435
  const version = tryGetPackageInfo("svelte")?.version;
406
436
  lowerVersion = version ? compare(version, "4.0.0", "<") : false;
@@ -436,19 +466,17 @@ function VueResolver() {
436
466
  },
437
467
  transform({ id, code, program }) {
438
468
  const sourceFile = program.getSourceFile(id) || program.getSourceFile(id + ".ts") || program.getSourceFile(id + ".js") || program.getSourceFile(id + ".tsx") || program.getSourceFile(id + ".jsx");
439
- if (!sourceFile)
440
- return [];
469
+ if (!sourceFile) return [];
441
470
  const outputs = [];
442
471
  program.emit(
443
472
  sourceFile,
444
473
  (path, content) => {
445
474
  outputs.push({ path, content });
446
475
  },
447
- void 0,
476
+ undefined,
448
477
  true
449
478
  );
450
- if (!program.getCompilerOptions().declarationMap)
451
- return outputs;
479
+ if (!program.getCompilerOptions().declarationMap) return outputs;
452
480
  const [beforeScript] = code.split(/\s*<script.*>/);
453
481
  const beforeLines = beforeScript.split("\n").length;
454
482
  for (const output of outputs) {
@@ -497,12 +525,9 @@ function walkSourceFile(sourceFile, callback) {
497
525
  sourceFile.forEachChild((child) => walkNode(child, sourceFile, callback));
498
526
  }
499
527
  function isAliasMatch(alias, importer) {
500
- if (isRegExp(alias.find))
501
- return alias.find.test(importer);
502
- if (importer.length < alias.find.length)
503
- return false;
504
- if (importer === alias.find)
505
- return true;
528
+ if (isRegExp(alias.find)) return alias.find.test(importer);
529
+ if (importer.length < alias.find.length) return false;
530
+ if (importer === alias.find) return true;
506
531
  return importer.indexOf(alias.find) === 0 && (alias.find.endsWith("/") || importer.substring(alias.find.length)[0] === "/");
507
532
  }
508
533
  function transformAlias(importer, dir, aliases, aliasesExclude) {
@@ -515,8 +540,11 @@ function transformAlias(importer, dir, aliases, aliasesExclude) {
515
540
  matchedAlias.find,
516
541
  replacement + (endsWithSlash ? "/" : "")
517
542
  );
518
- const normalizedPath = normalizePath(relative(dir, resolve$1(dir, truthPath)));
519
- return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
543
+ const absolutePath = resolve$1(dir, truthPath);
544
+ const normalizedPath = normalizePath(relative(dir, absolutePath));
545
+ const resultPath = normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
546
+ if (!isAliasGlobal(matchedAlias)) return resultPath;
547
+ if (importResolves(absolutePath)) return resultPath;
520
548
  }
521
549
  }
522
550
  return importer;
@@ -709,7 +737,7 @@ const fixedCompilerOptions = {
709
737
  checkJs: false,
710
738
  skipLibCheck: true,
711
739
  preserveSymlinks: false,
712
- noEmitOnError: void 0,
740
+ noEmitOnError: undefined,
713
741
  target: ts.ScriptTarget.ESNext
714
742
  };
715
743
  const noop = () => {
@@ -765,6 +793,7 @@ function dtsPlugin(options = {}) {
765
793
  ]);
766
794
  const rootFiles = /* @__PURE__ */ new Set();
767
795
  const outputFiles = /* @__PURE__ */ new Map();
796
+ const transformedFiles = /* @__PURE__ */ new Set();
768
797
  const setOutputFile = (path, content) => {
769
798
  outputFiles.set(path, content);
770
799
  };
@@ -838,8 +867,7 @@ ${logPrefix} ${yellow(
838
867
  bundleDebug("parse vite config");
839
868
  },
840
869
  options(options2) {
841
- if (entries)
842
- return;
870
+ if (entries) return;
843
871
  const input = typeof options2.input === "string" ? [options2.input] : options2.input;
844
872
  if (Array.isArray(input)) {
845
873
  entries = input.reduce(
@@ -859,13 +887,12 @@ ${logPrefix} ${yellow(
859
887
  bundleDebug("parse options");
860
888
  },
861
889
  async buildStart() {
862
- if (program)
863
- return;
890
+ if (program) return;
864
891
  bundleDebug("begin buildStart");
865
892
  timeRecord = 0;
866
893
  const startTime = Date.now();
867
894
  configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts.findConfigFile(root, ts.sys.fileExists);
868
- const content = configPath ? createParsedCommandLine(ts, ts.sys, configPath) : void 0;
895
+ const content = configPath ? createParsedCommandLine(ts, ts.sys, configPath) : undefined;
869
896
  compilerOptions = {
870
897
  ...content?.options || {},
871
898
  ...options.compilerOptions || {},
@@ -878,26 +905,41 @@ ${logPrefix} ${yellow(
878
905
  setModuleResolution(compilerOptions);
879
906
  }
880
907
  if (!outDirs) {
881
- outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [ensureAbsolute(content?.raw.compilerOptions?.outDir || "dist", root)];
908
+ outDirs = options.outDir ? ensureArray(options.outDir).map((d) => ensureAbsolute(d, root)) : [
909
+ ensureAbsolute(
910
+ content?.raw.compilerOptions?.outDir ? resolveConfigDir(content.raw.compilerOptions.outDir, root) : "dist",
911
+ root
912
+ )
913
+ ];
882
914
  }
883
915
  const {
884
916
  // Here we are using the default value to set the `baseUrl` to the current directory if no value exists. This is
885
917
  // the same behavior as the TS Compiler. See TS source:
886
918
  // https://github.com/microsoft/TypeScript/blob/3386e943215613c40f68ba0b108cda1ddb7faee1/src/compiler/utilities.ts#L6493-L6501
887
- baseUrl = compilerOptions.paths ? process.cwd() : void 0,
919
+ baseUrl = compilerOptions.paths ? process.cwd() : undefined,
888
920
  paths
889
921
  } = compilerOptions;
890
922
  if (pathsToAliases && baseUrl && paths) {
891
923
  aliases.push(
892
- ...parseTsAliases(ensureAbsolute(baseUrl, configPath ? dirname(configPath) : root), paths)
924
+ ...parseTsAliases(
925
+ ensureAbsolute(
926
+ resolveConfigDir(baseUrl, root),
927
+ configPath ? dirname(configPath) : root
928
+ ),
929
+ paths
930
+ )
893
931
  );
894
932
  }
895
933
  const computeGlobs = (rootGlobs, tsGlobs, defaultGlob) => {
896
934
  if (rootGlobs?.length) {
897
- return ensureArray(rootGlobs).map((glob) => normalizeGlob(ensureAbsolute(glob, root)));
935
+ return ensureArray(rootGlobs).map(
936
+ (glob) => normalizeGlob(ensureAbsolute(resolveConfigDir(glob, root), root))
937
+ );
898
938
  }
899
939
  return ensureArray(tsGlobs?.length ? tsGlobs : defaultGlob).map(
900
- (glob) => normalizeGlob(ensureAbsolute(glob, configPath ? dirname(configPath) : root))
940
+ (glob) => normalizeGlob(
941
+ ensureAbsolute(resolveConfigDir(glob, root), configPath ? dirname(configPath) : root)
942
+ )
901
943
  );
902
944
  };
903
945
  include = computeGlobs(
@@ -924,7 +966,7 @@ ${logPrefix} ${yellow(
924
966
  const maybeEmitted = (sourceFile) => {
925
967
  return !(compilerOptions.noEmitForJsFiles && jsRE.test(sourceFile.fileName)) && !sourceFile.isDeclarationFile && !program.isSourceFileFromExternalLibrary(sourceFile);
926
968
  };
927
- publicRoot = compilerOptions.rootDir ? ensureAbsolute(compilerOptions.rootDir, root) : compilerOptions.composite && compilerOptions.configFilePath ? dirname(compilerOptions.configFilePath) : queryPublicPath(
969
+ publicRoot = compilerOptions.rootDir ? ensureAbsolute(resolveConfigDir(compilerOptions.rootDir, root), root) : compilerOptions.composite && compilerOptions.configFilePath ? dirname(compilerOptions.configFilePath) : queryPublicPath(
928
970
  program.getSourceFiles().filter(maybeEmitted).map((sourceFile) => sourceFile.fileName)
929
971
  );
930
972
  publicRoot = normalizePath(publicRoot);
@@ -950,14 +992,14 @@ ${logPrefix} ${yellow(
950
992
  },
951
993
  async transform(code, id) {
952
994
  let resolver;
953
- id = normalizePath(id);
954
- if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id)) {
995
+ id = normalizePath(id).split("?")[0];
996
+ if (!host || !program || !filter(id) || !(resolver = resolvers.find((r) => r.supports(id))) && !tjsRE.test(id) || transformedFiles.has(id)) {
955
997
  return;
956
998
  }
957
999
  const startTime = Date.now();
958
1000
  const outDir = outDirs[0];
959
- id = id.split("?")[0];
960
1001
  rootFiles.delete(id);
1002
+ transformedFiles.add(id);
961
1003
  if (resolver) {
962
1004
  const result = await resolver.transform({
963
1005
  id,
@@ -984,7 +1026,7 @@ ${logPrefix} ${yellow(
984
1026
  text
985
1027
  );
986
1028
  },
987
- void 0,
1029
+ undefined,
988
1030
  true
989
1031
  );
990
1032
  }
@@ -1012,8 +1054,8 @@ ${logPrefix} ${yellow(
1012
1054
  }
1013
1055
  },
1014
1056
  async writeBundle() {
1015
- if (!host || !program || bundled)
1016
- return;
1057
+ transformedFiles.clear();
1058
+ if (!host || !program || bundled) return;
1017
1059
  bundled = true;
1018
1060
  bundleDebug("begin writeBundle");
1019
1061
  logger.info(green(`
@@ -1025,8 +1067,7 @@ ${logPrefix} Start generate declaration files...`));
1025
1067
  const writeOutput = async (path, content, outDir2, record = true) => {
1026
1068
  if (typeof beforeWriteFile === "function") {
1027
1069
  const result = await unwrapPromise(beforeWriteFile(path, content));
1028
- if (result === false)
1029
- return;
1070
+ if (result === false) return;
1030
1071
  if (result) {
1031
1072
  path = result.filePath || path;
1032
1073
  content = result.content ?? content;
@@ -1046,8 +1087,7 @@ ${logPrefix} Start generate declaration files...`));
1046
1087
  };
1047
1088
  const sourceFiles = program.getSourceFiles();
1048
1089
  for (const sourceFile of sourceFiles) {
1049
- if (!filter(sourceFile.fileName))
1050
- continue;
1090
+ if (!filter(sourceFile.fileName)) continue;
1051
1091
  if (copyDtsFiles && dtsRE.test(sourceFile.fileName)) {
1052
1092
  setOutputFile(normalizePath(sourceFile.fileName), sourceFile.getFullText());
1053
1093
  }
@@ -1060,7 +1100,7 @@ ${logPrefix} Start generate declaration files...`));
1060
1100
  text
1061
1101
  );
1062
1102
  },
1063
- void 0,
1103
+ undefined,
1064
1104
  true
1065
1105
  );
1066
1106
  rootFiles.delete(sourceFile.fileName);
@@ -1167,8 +1207,7 @@ ${logPrefix} ${yellow(
1167
1207
  }
1168
1208
  for (const name of entryNames) {
1169
1209
  const entryDtsPath = multiple ? cleanPath(resolve(outDir, tsToDts(name)), emittedFiles) : typesPath;
1170
- if (existsSync(entryDtsPath))
1171
- continue;
1210
+ if (existsSync(entryDtsPath)) continue;
1172
1211
  const sourceEntry = normalizePath(
1173
1212
  cleanPath(resolve(outDir, relative(entryRoot, tsToDts(entries[name]))), emittedFiles)
1174
1213
  );