resolve-tsconfig-CcfxWrib.mjs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { n as __toESM, t as require_binding } from "./binding-CXquf8ay.mjs";
  2. import { a as bindingifySourcemap, n as normalizeBindingError } from "./error-BuvQYXuZ.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. function normalizeBindingWarning(warning) {
  41. if (warning.type === "JsError") return warning.field0;
  42. return {
  43. code: warning.field0.kind,
  44. message: warning.field0.message,
  45. id: warning.field0.id,
  46. exporter: warning.field0.exporter,
  47. loc: warning.field0.loc,
  48. pos: warning.field0.pos
  49. };
  50. }
  51. /**
  52. * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
  53. *
  54. * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
  55. *
  56. * @param filename The name of the file being transformed. If this is a
  57. * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
  58. * @param sourceText The source code to transform.
  59. * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
  60. * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
  61. * Only used when `options.tsconfig` is `true`.
  62. *
  63. * @returns a promise that resolves to an object containing the transformed code,
  64. * source maps, and any errors that occurred during parsing or transformation.
  65. *
  66. * @category Utilities
  67. * @experimental
  68. */
  69. async function transform(filename, sourceText, options, cache) {
  70. const result = await (0, import_binding.enhancedTransform)(filename, sourceText, options, cache, yarnPnp$1);
  71. return {
  72. ...result,
  73. errors: result.errors.map(normalizeBindingError),
  74. warnings: result.warnings.map(normalizeBindingWarning)
  75. };
  76. }
  77. /**
  78. * Transpile a JavaScript or TypeScript into a target ECMAScript version.
  79. *
  80. * @param filename The name of the file being transformed. If this is a
  81. * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
  82. * @param sourceText The source code to transform.
  83. * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
  84. * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
  85. * Only used when `options.tsconfig` is `true`.
  86. *
  87. * @returns an object containing the transformed code, source maps, and any errors
  88. * that occurred during parsing or transformation.
  89. *
  90. * @category Utilities
  91. * @experimental
  92. */
  93. function transformSync(filename, sourceText, options, cache) {
  94. const result = (0, import_binding.enhancedTransformSync)(filename, sourceText, options, cache, yarnPnp$1);
  95. return {
  96. ...result,
  97. errors: result.errors.map(normalizeBindingError),
  98. warnings: result.warnings.map(normalizeBindingWarning)
  99. };
  100. }
  101. //#endregion
  102. //#region src/utils/resolve-tsconfig.ts
  103. const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
  104. /**
  105. * Cache for tsconfig resolution to avoid redundant file system operations.
  106. *
  107. * The cache stores resolved tsconfig configurations keyed by their file paths.
  108. * When transforming multiple files in the same project, tsconfig lookups are
  109. * deduplicated, improving performance.
  110. *
  111. * @category Utilities
  112. * @experimental
  113. */
  114. var TsconfigCache = class extends import_binding.TsconfigCache {
  115. constructor() {
  116. super(yarnPnp);
  117. }
  118. };
  119. /** @hidden This is only expected to be used by Vite */
  120. function resolveTsconfig(filename, cache) {
  121. return (0, import_binding.resolveTsconfig)(filename, cache, yarnPnp);
  122. }
  123. //#endregion
  124. export { minify as a, transformSync as i, resolveTsconfig as n, minifySync as o, transform as r, TsconfigCache as t };