resolve-tsconfig-CNjJwuKB.mjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { n as __toESM, t as require_binding } from "./binding-s-V_wTpj.mjs";
  2. import { a as bindingifySourcemap, n as normalizeBindingError } from "./error-w0u7biK-.mjs";
  3. //#region src/utils/minify.ts
  4. var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
  5. /**
  6. * Minify asynchronously.
  7. *
  8. * Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
  9. *
  10. * @category Utilities
  11. * @experimental
  12. */
  13. async function minify(filename, sourceText, options) {
  14. const inputMap = bindingifySourcemap(options?.inputMap);
  15. const result = await (0, import_binding.minify)(filename, sourceText, options);
  16. if (result.map && inputMap) result.map = {
  17. version: 3,
  18. ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
  19. };
  20. return result;
  21. }
  22. /**
  23. * Minify synchronously.
  24. *
  25. * @category Utilities
  26. * @experimental
  27. */
  28. function minifySync(filename, sourceText, options) {
  29. const inputMap = bindingifySourcemap(options?.inputMap);
  30. const result = (0, import_binding.minifySync)(filename, sourceText, options);
  31. if (result.map && inputMap) result.map = {
  32. version: 3,
  33. ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
  34. };
  35. return result;
  36. }
  37. //#endregion
  38. //#region src/utils/transform.ts
  39. const yarnPnp$1 = typeof process === "object" && !!process.versions?.pnp;
  40. /**
  41. * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
  42. *
  43. * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
  44. *
  45. * @param filename The name of the file being transformed. If this is a
  46. * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
  47. * @param sourceText The source code to transform.
  48. * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
  49. * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
  50. * Only used when `options.tsconfig` is `true`.
  51. *
  52. * @returns a promise that resolves to an object containing the transformed code,
  53. * source maps, and any errors that occurred during parsing or transformation.
  54. *
  55. * @category Utilities
  56. * @experimental
  57. */
  58. async function transform(filename, sourceText, options, cache) {
  59. const result = await (0, import_binding.enhancedTransform)(filename, sourceText, options, cache, yarnPnp$1);
  60. return {
  61. ...result,
  62. errors: result.errors.map(normalizeBindingError),
  63. warnings: result.warnings.map((w) => w.field0)
  64. };
  65. }
  66. /**
  67. * Transpile a JavaScript or TypeScript into a target ECMAScript version.
  68. *
  69. * @param filename The name of the file being transformed. If this is a
  70. * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
  71. * @param sourceText The source code to transform.
  72. * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
  73. * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
  74. * Only used when `options.tsconfig` is `true`.
  75. *
  76. * @returns an object containing the transformed code, source maps, and any errors
  77. * that occurred during parsing or transformation.
  78. *
  79. * @category Utilities
  80. * @experimental
  81. */
  82. function transformSync(filename, sourceText, options, cache) {
  83. const result = (0, import_binding.enhancedTransformSync)(filename, sourceText, options, cache, yarnPnp$1);
  84. return {
  85. ...result,
  86. errors: result.errors.map(normalizeBindingError),
  87. warnings: result.warnings.map((w) => w.field0)
  88. };
  89. }
  90. //#endregion
  91. //#region src/utils/resolve-tsconfig.ts
  92. const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
  93. /**
  94. * Cache for tsconfig resolution to avoid redundant file system operations.
  95. *
  96. * The cache stores resolved tsconfig configurations keyed by their file paths.
  97. * When transforming multiple files in the same project, tsconfig lookups are
  98. * deduplicated, improving performance.
  99. *
  100. * @category Utilities
  101. * @experimental
  102. */
  103. var TsconfigCache = class extends import_binding.TsconfigCache {
  104. constructor() {
  105. super(yarnPnp);
  106. }
  107. };
  108. /** @hidden This is only expected to be used by Vite */
  109. function resolveTsconfig(filename, cache) {
  110. return (0, import_binding.resolveTsconfig)(filename, cache, yarnPnp);
  111. }
  112. //#endregion
  113. export { minify as a, transformSync as i, resolveTsconfig as n, minifySync as o, transform as r, TsconfigCache as t };