powerlines 0.23.9 → 0.24.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.
Files changed (273) hide show
  1. package/dist/{api-5H3zEedD.d.ts → api-C32Buv5_.d.ts} +1 -1
  2. package/dist/{api-B77aqxGC.d.cts → api-wzd5AREv.d.cts} +1 -1
  3. package/dist/api.cjs +2 -2
  4. package/dist/api.d.cts +4 -2
  5. package/dist/api.d.ts +4 -2
  6. package/dist/api.js +1 -1
  7. package/dist/astro.cjs +4 -4
  8. package/dist/astro.d.cts +3 -1
  9. package/dist/astro.d.ts +3 -1
  10. package/dist/astro.js +3 -3
  11. package/dist/babel-types.d.ts +292 -0
  12. package/dist/chunk-2TWFBWKA.cjs +133 -0
  13. package/dist/{chunk-UYJXRMS3.js → chunk-7V3LWCLB.js} +1 -1
  14. package/dist/chunk-EXQM3KGH.js +130 -0
  15. package/dist/{chunk-6ZKM7WOB.cjs → chunk-FGH3MZTQ.cjs} +535 -659
  16. package/dist/{chunk-ITL6JGKX.cjs → chunk-FPB2O7FD.cjs} +2 -2
  17. package/dist/{chunk-KOBCKTHY.js → chunk-H74SWU2C.js} +1 -1
  18. package/dist/{chunk-2QLM4MYP.cjs → chunk-HTGCHSLH.cjs} +2 -2
  19. package/dist/{chunk-G5K3I7JU.cjs → chunk-TIBYAWZZ.cjs} +2 -2
  20. package/dist/{chunk-S47BU5QR.js → chunk-ZEE73BCY.js} +1 -1
  21. package/dist/{chunk-FDEGM4CR.js → chunk-ZT2J55YE.js} +538 -659
  22. package/dist/config.d.cts +3 -1
  23. package/dist/config.d.ts +3 -1
  24. package/dist/esbuild.cjs +6 -6
  25. package/dist/esbuild.d.cts +3 -1
  26. package/dist/esbuild.d.ts +3 -1
  27. package/dist/esbuild.js +3 -3
  28. package/dist/farm.cjs +3 -3
  29. package/dist/farm.d.cts +3 -1
  30. package/dist/farm.d.ts +3 -1
  31. package/dist/farm.js +2 -2
  32. package/dist/index.cjs +11 -23
  33. package/dist/index.d.cts +6 -135
  34. package/dist/index.d.ts +6 -135
  35. package/dist/index.js +2 -2
  36. package/dist/lib/{api-Cm51oVbC.d.cts → api-BRMITKt-.d.cts} +1 -1
  37. package/dist/lib/{api-mja4jirh.d.ts → api-CDUN9en8.d.ts} +1 -1
  38. package/dist/lib/build/esbuild.d.cts +3 -1
  39. package/dist/lib/build/esbuild.d.ts +3 -1
  40. package/dist/lib/build/index.d.cts +5 -3
  41. package/dist/lib/build/index.d.ts +5 -3
  42. package/dist/lib/build/rolldown.d.cts +3 -1
  43. package/dist/lib/build/rolldown.d.ts +3 -1
  44. package/dist/lib/build/rollup.d.cts +3 -1
  45. package/dist/lib/build/rollup.d.ts +3 -1
  46. package/dist/lib/build/rspack.d.cts +3 -1
  47. package/dist/lib/build/rspack.d.ts +3 -1
  48. package/dist/lib/build/tsup.d.cts +3 -1
  49. package/dist/lib/build/tsup.d.ts +3 -1
  50. package/dist/lib/build/unbuild.d.cts +5 -3
  51. package/dist/lib/build/unbuild.d.ts +5 -3
  52. package/dist/lib/build/vite.d.cts +3 -1
  53. package/dist/lib/build/vite.d.ts +3 -1
  54. package/dist/lib/build/webpack.d.cts +3 -1
  55. package/dist/lib/build/webpack.d.ts +3 -1
  56. package/dist/lib/{chunk-52VDUP5J.js → chunk-6I5PL7H2.js} +5 -17
  57. package/dist/lib/{chunk-UPVFKXB7.cjs → chunk-6PPZCPME.cjs} +1 -2
  58. package/dist/lib/{chunk-OI7EHXNE.js → chunk-7CVPZOH4.js} +3 -3
  59. package/dist/lib/{chunk-7XHBIYIN.cjs → chunk-7VJ42H2I.cjs} +0 -16
  60. package/dist/lib/{chunk-SEWUUTNA.js → chunk-A2NFSQ5K.js} +1 -1
  61. package/dist/lib/{chunk-B3DJ4CXY.cjs → chunk-AA6RBP44.cjs} +10 -10
  62. package/dist/lib/{chunk-BGGENJH4.js → chunk-CGRHZJY5.js} +42 -83
  63. package/dist/lib/{chunk-AHONHQGB.js → chunk-DFW5FGEO.js} +1 -1
  64. package/dist/lib/{chunk-VL63QEPF.cjs → chunk-DUZJ7ZF2.cjs} +2 -2
  65. package/dist/lib/{chunk-EFYMNU53.cjs → chunk-EV357RFB.cjs} +5 -17
  66. package/dist/lib/{chunk-YH5GOJS3.js → chunk-FQLZZYYO.js} +1 -16
  67. package/dist/lib/{chunk-54XNJQTH.js → chunk-HAXL7QE7.js} +3 -3
  68. package/dist/lib/chunk-K3NBD5LL.cjs +75 -0
  69. package/dist/lib/{chunk-63MH3ERQ.js → chunk-KFWMKDJQ.js} +395 -591
  70. package/dist/lib/{chunk-3KR6TYGW.cjs → chunk-MS3CD2U6.cjs} +52 -94
  71. package/dist/lib/{chunk-LQEGZT5U.cjs → chunk-RNHKEPFD.cjs} +397 -594
  72. package/dist/lib/{chunk-4EIXDLFP.cjs → chunk-SAS5EPBD.cjs} +7 -5
  73. package/dist/lib/{chunk-EUDKQWSB.js → chunk-VHLINWXG.js} +1 -2
  74. package/dist/lib/{chunk-SMZ672RP.cjs → chunk-VMLQATMA.cjs} +6 -6
  75. package/dist/lib/{chunk-IBPA3VN5.cjs → chunk-WUYK74EH.cjs} +3 -3
  76. package/dist/lib/chunk-XBM7FHNK.js +68 -0
  77. package/dist/lib/{chunk-RD5AUWXN.js → chunk-YQ3ODCHV.js} +7 -5
  78. package/dist/lib/{config-BnJpgcGr.d.cts → config-D8KrE7SZ.d.cts} +109 -35
  79. package/dist/lib/{config-7Q2dBjJE.d.ts → config-DBIFdRoq.d.ts} +109 -35
  80. package/dist/lib/config-file.cjs +3 -3
  81. package/dist/lib/config-file.d.cts +3 -1
  82. package/dist/lib/config-file.d.ts +3 -1
  83. package/dist/lib/config-file.js +1 -1
  84. package/dist/lib/contexts/api-context.cjs +7 -6
  85. package/dist/lib/contexts/api-context.d.cts +5 -3
  86. package/dist/lib/contexts/api-context.d.ts +5 -3
  87. package/dist/lib/contexts/api-context.js +6 -5
  88. package/dist/lib/contexts/context.cjs +5 -4
  89. package/dist/lib/contexts/context.d.cts +47 -4
  90. package/dist/lib/contexts/context.d.ts +47 -4
  91. package/dist/lib/contexts/context.js +4 -3
  92. package/dist/lib/contexts/environment-context.cjs +6 -5
  93. package/dist/lib/contexts/environment-context.d.cts +5 -3
  94. package/dist/lib/contexts/environment-context.d.ts +5 -3
  95. package/dist/lib/contexts/environment-context.js +5 -4
  96. package/dist/lib/contexts/index.cjs +9 -8
  97. package/dist/lib/contexts/index.d.cts +5 -3
  98. package/dist/lib/contexts/index.d.ts +5 -3
  99. package/dist/lib/contexts/index.js +6 -5
  100. package/dist/lib/contexts/plugin-context.d.cts +5 -3
  101. package/dist/lib/contexts/plugin-context.d.ts +5 -3
  102. package/dist/lib/entry.d.cts +3 -1
  103. package/dist/lib/entry.d.ts +3 -1
  104. package/dist/lib/index.cjs +49 -59
  105. package/dist/lib/index.d.cts +68 -49
  106. package/dist/lib/index.d.ts +68 -49
  107. package/dist/lib/index.js +14 -16
  108. package/dist/lib/{internal-BEygquYh.d.ts → internal-1qCyw7bA.d.ts} +2 -2
  109. package/dist/lib/{internal-BeR8fOB1.d.cts → internal-CaGANOWK.d.cts} +2 -2
  110. package/dist/lib/logger.d.cts +3 -1
  111. package/dist/lib/logger.d.ts +3 -1
  112. package/dist/lib/typescript/compiler-host.cjs +7 -7
  113. package/dist/lib/typescript/compiler-host.d.cts +3 -1
  114. package/dist/lib/typescript/compiler-host.d.ts +3 -1
  115. package/dist/lib/typescript/compiler-host.js +6 -6
  116. package/dist/lib/typescript/import-transformer.cjs +1 -1
  117. package/dist/lib/typescript/import-transformer.d.cts +3 -1
  118. package/dist/lib/typescript/import-transformer.d.ts +3 -1
  119. package/dist/lib/typescript/import-transformer.js +1 -1
  120. package/dist/lib/typescript/index.cjs +8 -8
  121. package/dist/lib/typescript/index.d.cts +3 -2
  122. package/dist/lib/typescript/index.d.ts +3 -2
  123. package/dist/lib/typescript/index.js +2 -2
  124. package/dist/lib/typescript/program.cjs +6 -6
  125. package/dist/lib/typescript/program.d.cts +3 -1
  126. package/dist/lib/typescript/program.d.ts +3 -1
  127. package/dist/lib/typescript/program.js +1 -1
  128. package/dist/lib/typescript/ts-morph.cjs +2 -2
  129. package/dist/lib/typescript/ts-morph.d.cts +5 -3
  130. package/dist/lib/typescript/ts-morph.d.ts +5 -3
  131. package/dist/lib/typescript/ts-morph.js +1 -1
  132. package/dist/lib/unplugin/factory.cjs +8 -8
  133. package/dist/lib/unplugin/factory.d.cts +5 -3
  134. package/dist/lib/unplugin/factory.d.ts +5 -3
  135. package/dist/lib/unplugin/factory.js +7 -7
  136. package/dist/lib/unplugin/helpers.d.cts +3 -1
  137. package/dist/lib/unplugin/helpers.d.ts +3 -1
  138. package/dist/lib/unplugin/index.cjs +13 -13
  139. package/dist/lib/unplugin/index.d.cts +6 -4
  140. package/dist/lib/unplugin/index.d.ts +6 -4
  141. package/dist/lib/unplugin/index.js +9 -9
  142. package/dist/lib/unplugin/plugin.cjs +2 -3
  143. package/dist/lib/unplugin/plugin.d.cts +6 -4
  144. package/dist/lib/unplugin/plugin.d.ts +6 -4
  145. package/dist/lib/unplugin/plugin.js +1 -2
  146. package/dist/lib/{unplugin-CbbNDduM.d.ts → unplugin-CEeJqADD.d.ts} +2 -2
  147. package/dist/lib/{unplugin-ppAOzR__.d.cts → unplugin-bUSyjd0S.d.cts} +2 -2
  148. package/dist/lib/utilities/bundle.cjs +2 -3
  149. package/dist/lib/utilities/bundle.d.cts +3 -1
  150. package/dist/lib/utilities/bundle.d.ts +3 -1
  151. package/dist/lib/utilities/bundle.js +1 -2
  152. package/dist/lib/utilities/cache.d.cts +3 -1
  153. package/dist/lib/utilities/cache.d.ts +3 -1
  154. package/dist/lib/utilities/file-header.d.cts +3 -1
  155. package/dist/lib/utilities/file-header.d.ts +3 -1
  156. package/dist/lib/utilities/index.cjs +21 -30
  157. package/dist/lib/utilities/index.d.cts +4 -3
  158. package/dist/lib/utilities/index.d.ts +4 -3
  159. package/dist/lib/utilities/index.js +5 -6
  160. package/dist/lib/utilities/meta.cjs +7 -11
  161. package/dist/lib/utilities/meta.d.cts +4 -3
  162. package/dist/lib/utilities/meta.d.ts +4 -3
  163. package/dist/lib/utilities/meta.js +1 -1
  164. package/dist/lib/utilities/resolve.cjs +3 -4
  165. package/dist/lib/utilities/resolve.d.cts +3 -1
  166. package/dist/lib/utilities/resolve.d.ts +3 -1
  167. package/dist/lib/utilities/resolve.js +2 -3
  168. package/dist/lib/utilities/source-file.d.cts +3 -1
  169. package/dist/lib/utilities/source-file.d.ts +3 -1
  170. package/dist/lib/utilities/source-map.d.cts +3 -1
  171. package/dist/lib/utilities/source-map.d.ts +3 -1
  172. package/dist/lib/utilities/worker.d.cts +3 -1
  173. package/dist/lib/utilities/worker.d.ts +3 -1
  174. package/dist/lib/utilities/write-file.d.cts +3 -1
  175. package/dist/lib/utilities/write-file.d.ts +3 -1
  176. package/dist/next.cjs +4 -4
  177. package/dist/next.js +3 -3
  178. package/dist/nuxt.cjs +6 -6
  179. package/dist/nuxt.js +4 -4
  180. package/dist/plugin-utils/{context-Cg11S-CE.d.ts → context-BITGF5LZ.d.cts} +118 -39
  181. package/dist/plugin-utils/{context-Cg11S-CE.d.cts → context-BITGF5LZ.d.ts} +118 -39
  182. package/dist/plugin-utils/context-helpers.d.cts +4 -1
  183. package/dist/plugin-utils/context-helpers.d.ts +4 -1
  184. package/dist/plugin-utils/enforce.d.cts +4 -1
  185. package/dist/plugin-utils/enforce.d.ts +4 -1
  186. package/dist/plugin-utils/extend.d.cts +4 -1
  187. package/dist/plugin-utils/extend.d.ts +4 -1
  188. package/dist/plugin-utils/get-config-path.d.cts +4 -1
  189. package/dist/plugin-utils/get-config-path.d.ts +4 -1
  190. package/dist/plugin-utils/helpers.d.cts +4 -1
  191. package/dist/plugin-utils/helpers.d.ts +4 -1
  192. package/dist/plugin-utils/index.d.cts +4 -1
  193. package/dist/plugin-utils/index.d.ts +4 -1
  194. package/dist/plugin-utils/merge.d.cts +4 -1
  195. package/dist/plugin-utils/merge.d.ts +4 -1
  196. package/dist/plugin-utils/paths.d.cts +4 -1
  197. package/dist/plugin-utils/paths.d.ts +4 -1
  198. package/dist/{resolved-B3BSdXCt.d.ts → resolved-BABoCnXm.d.ts} +43 -1
  199. package/dist/{resolved-DGrpILrS.d.cts → resolved-CSqGKlA5.d.cts} +43 -1
  200. package/dist/rolldown.cjs +3 -3
  201. package/dist/rolldown.d.cts +3 -1
  202. package/dist/rolldown.d.ts +3 -1
  203. package/dist/rolldown.js +2 -2
  204. package/dist/rollup.cjs +3 -3
  205. package/dist/rollup.d.cts +3 -1
  206. package/dist/rollup.d.ts +3 -1
  207. package/dist/rollup.js +2 -2
  208. package/dist/rspack.cjs +3 -3
  209. package/dist/rspack.d.cts +3 -1
  210. package/dist/rspack.d.ts +3 -1
  211. package/dist/rspack.js +2 -2
  212. package/dist/tsup.cjs +4 -4
  213. package/dist/tsup.js +3 -3
  214. package/dist/types/api.d.cts +4 -2
  215. package/dist/types/api.d.ts +4 -2
  216. package/dist/types/babel.d.cts +3 -1
  217. package/dist/types/babel.d.ts +3 -1
  218. package/dist/types/commands.d.cts +3 -1
  219. package/dist/types/commands.d.ts +3 -1
  220. package/dist/types/config.d.cts +3 -1
  221. package/dist/types/config.d.ts +3 -1
  222. package/dist/types/context.d.cts +3 -1
  223. package/dist/types/context.d.ts +3 -1
  224. package/dist/types/fs.d.cts +68 -36
  225. package/dist/types/fs.d.ts +68 -36
  226. package/dist/types/hooks.d.cts +3 -1
  227. package/dist/types/hooks.d.ts +3 -1
  228. package/dist/types/index.d.cts +5 -3
  229. package/dist/types/index.d.ts +5 -3
  230. package/dist/types/internal.d.cts +4 -2
  231. package/dist/types/internal.d.ts +4 -2
  232. package/dist/types/plugin.d.cts +3 -1
  233. package/dist/types/plugin.d.ts +3 -1
  234. package/dist/types/resolved.d.cts +3 -1
  235. package/dist/types/resolved.d.ts +3 -1
  236. package/dist/types/unplugin.d.cts +4 -2
  237. package/dist/types/unplugin.d.ts +4 -2
  238. package/dist/unloader.cjs +3 -3
  239. package/dist/unloader.d.cts +3 -1
  240. package/dist/unloader.d.ts +3 -1
  241. package/dist/unloader.js +2 -2
  242. package/dist/unplugin.cjs +12 -28
  243. package/dist/unplugin.d.cts +104 -31
  244. package/dist/unplugin.d.ts +104 -31
  245. package/dist/unplugin.js +10 -23
  246. package/dist/vite.cjs +6 -6
  247. package/dist/vite.d.cts +3 -1
  248. package/dist/vite.d.ts +3 -1
  249. package/dist/vite.js +3 -3
  250. package/dist/webpack.cjs +6 -6
  251. package/dist/webpack.d.cts +3 -1
  252. package/dist/webpack.d.ts +3 -1
  253. package/dist/webpack.js +3 -3
  254. package/package.json +16 -14
  255. package/schemas/fs.capnp +35 -38
  256. package/dist/chunk-FJWXCUGQ.cjs +0 -234
  257. package/dist/chunk-RKMUBSYG.js +0 -230
  258. package/dist/lib/chunk-7JAGT5GC.cjs +0 -74
  259. package/dist/lib/chunk-G7S5PIAC.js +0 -89
  260. package/dist/lib/chunk-MZJWK36Q.cjs +0 -37
  261. package/dist/lib/chunk-NWAD7K4D.js +0 -35
  262. package/dist/lib/chunk-PVCAB6BZ.js +0 -67
  263. package/dist/lib/chunk-ZBDVQVUK.cjs +0 -91
  264. package/dist/lib/unplugin/resolve-id.cjs +0 -11
  265. package/dist/lib/unplugin/resolve-id.d.cts +0 -57
  266. package/dist/lib/unplugin/resolve-id.d.ts +0 -57
  267. package/dist/lib/unplugin/resolve-id.js +0 -2
  268. package/dist/lib/utilities/resolve-path.cjs +0 -11
  269. package/dist/lib/utilities/resolve-path.d.cts +0 -40
  270. package/dist/lib/utilities/resolve-path.d.ts +0 -40
  271. package/dist/lib/utilities/resolve-path.js +0 -2
  272. /package/dist/lib/{chunk-HMO3LAYL.js → chunk-I2DQRMX3.js} +0 -0
  273. /package/dist/lib/{chunk-EJ25PQEL.cjs → chunk-YK4PYVLM.cjs} +0 -0
@@ -12,7 +12,7 @@ import { createDirectory } from '@stryke/fs/helpers';
12
12
  import { install } from '@stryke/fs/install';
13
13
  import { listFiles, listFilesSync } from '@stryke/fs/list-files';
14
14
  import { isPackageExists, isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns';
15
- import { resolvePackage } from '@stryke/fs/resolve';
15
+ import { getResolutionCombinations, resolve, resolveSync, resolvePackage } from '@stryke/fs/resolve';
16
16
  import { appendPath } from '@stryke/path/append';
17
17
  import { joinPaths as joinPaths$1 } from '@stryke/path/join-paths';
18
18
  import { replacePath, replaceExtension } from '@stryke/path/replace';
@@ -24,17 +24,17 @@ import { isSet } from '@stryke/type-checks/is-set';
24
24
  import { isSetObject } from '@stryke/type-checks/is-set-object';
25
25
  import { isSetString } from '@stryke/type-checks/is-set-string';
26
26
  import chalk5 from 'chalk';
27
- import defu6, { defu } from 'defu';
28
27
  import Handlebars from 'handlebars';
29
28
  import { declare } from '@babel/helper-plugin-utils';
30
29
  import * as t from '@babel/types';
31
- import ts2, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
30
+ import ts2, { flattenDiagnosticMessageText } from 'typescript';
31
+ import defu6, { defu } from 'defu';
32
32
  import { getPackageName, hasPackageVersion, getPackageVersion } from '@stryke/string-format/package';
33
33
  import { getObjectDiff } from '@donedeal0/superdiff';
34
34
  import { readJsonFile, readJsonFileSync } from '@stryke/fs/json';
35
35
  import { loadTsConfig } from '@stryke/fs/tsconfig';
36
36
  import { StormJSON } from '@stryke/json/storm-json';
37
- import { findFileDotExtensionSafe, findFilePath, relativePath, findFileName } from '@stryke/path/file-path-fns';
37
+ import { findFilePath, relativePath, findFileName, findFileDotExtensionSafe } from '@stryke/path/file-path-fns';
38
38
  import { titleCase } from '@stryke/string-format/title-case';
39
39
  import { writeFile as writeFile$1 } from '@stryke/fs/write-file';
40
40
  import { resolveConfig, format } from 'prettier';
@@ -51,6 +51,7 @@ import { joinPaths } from '@stryke/path/join';
51
51
  import { isNull } from '@stryke/type-checks/is-null';
52
52
  import { isString } from '@stryke/type-checks/is-string';
53
53
  import { uuid } from '@stryke/unique-id/uuid';
54
+ import { tsconfigPathsToRegExp, match } from 'bundle-require';
54
55
  import { createJiti } from 'jiti';
55
56
  import { isUndefined } from '@stryke/type-checks/is-undefined';
56
57
  import { parseTypeDefinition } from '@stryke/convert/parse-type-definition';
@@ -58,8 +59,10 @@ import { isFile } from '@stryke/fs/is-file';
58
59
  import * as $ from '@stryke/capnp';
59
60
  import { bufferToString } from '@stryke/convert/buffer-to-string';
60
61
  import { readFileBuffer, readFileBufferSync, writeFileBuffer } from '@stryke/fs/buffer';
62
+ import { toAbsolutePath } from '@stryke/path/correct-path';
61
63
  import { prettyBytes } from '@stryke/string-format/pretty-bytes';
62
64
  import { isBuffer } from '@stryke/type-checks/is-buffer';
65
+ import { create } from 'flat-cache';
63
66
  import { Blob } from 'node:buffer';
64
67
  import _fs from 'node:fs';
65
68
  import { getLogFn, getLogLevel } from '@storm-software/config-tools/logger';
@@ -68,6 +71,7 @@ import { noop } from '@stryke/helpers/noop';
68
71
  import { isParentPath } from '@stryke/path/is-parent-path';
69
72
  import { Volume } from 'memfs';
70
73
  import { Union } from 'unionfs';
74
+ import { InMemoryFileSystemHost, Project } from 'ts-morph';
71
75
  import '@stryke/fs/remove-file';
72
76
  import { kebabCase } from '@stryke/string-format/kebab-case';
73
77
  import { isObject } from '@stryke/type-checks/is-object';
@@ -77,7 +81,7 @@ function resolveModulePath(nodePath, state) {
77
81
  return;
78
82
  }
79
83
  const sourcePath = nodePath.node.value;
80
- const resolvedPath = state.context?.fs.resolve(sourcePath);
84
+ const resolvedPath = state.context?.fs.resolveSync(sourcePath);
81
85
  if (resolvedPath) {
82
86
  nodePath.replaceWith(t.stringLiteral(
83
87
  // Remove the file extension if it exists
@@ -181,33 +185,31 @@ function formatTypes(code) {
181
185
  ).replaceAll("#private;", "").replace(/__Ω/g, "");
182
186
  }
183
187
  __name(formatTypes, "formatTypes");
184
- async function emitTypes(context, tsconfig, files) {
185
- context.log(LogLevelLabel.TRACE, "Creating the TypeScript compiler host");
186
- const program = createProgram(files, tsconfig.options, createCompilerHost(tsconfig.options));
187
- context.log(LogLevelLabel.TRACE, `Running the TypeScript compiler for ${context.builtins.length} built-in runtime files.`);
188
+ async function emitTypes(context, files) {
189
+ context.log(LogLevelLabel.TRACE, `Running the TypeScript compiler for ${files.length} generated runtime files.`);
190
+ context.program.addSourceFilesAtPaths(files);
191
+ const result = context.program.emitToMemory({
192
+ emitOnlyDtsFiles: true
193
+ });
188
194
  let builtinModules = "";
189
- const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
190
- const sourceFile = sourceFiles?.[0];
191
- if (sourceFile?.fileName && !fileName.endsWith(".map")) {
192
- if (context.builtins.some((file) => file === sourceFile.fileName || context.fs.metadata[file]?.id && context.fs.metadata[file]?.id === sourceFile.fileName)) {
195
+ for (const file of result.getFiles()) {
196
+ if (!file.filePath.endsWith(".map")) {
197
+ if (context.builtins.some((builtin) => builtin === file.filePath || context.fs.metadata[builtin]?.id && context.fs.metadata[builtin]?.id === file.filePath)) {
198
+ const module = await context.fs.resolve(file.filePath);
193
199
  builtinModules += `
194
- declare module "${context.fs.resolve(sourceFile.fileName)}" {
195
- ${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
196
- }
197
- `;
200
+ declare module "${module}" {
201
+ ${file.text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
202
+ }
203
+ `;
198
204
  }
199
205
  }
200
- }, void 0, true);
201
- const diagnostics = getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
206
+ }
202
207
  const diagnosticMessages = [];
203
- diagnostics.forEach((diagnostic) => {
204
- if (diagnostic.file) {
205
- const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
206
- const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
207
- diagnosticMessages.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
208
+ result.getDiagnostics().forEach((diagnostic) => {
209
+ if (diagnostic.getSourceFile()?.getBaseName()) {
210
+ diagnosticMessages.push(`${diagnostic.getSourceFile()?.getBaseName()} (${(diagnostic.getLineNumber() ?? 0) + 1}): ${flattenDiagnosticMessageText(diagnostic.getMessageText().toString(), "\n")}`);
208
211
  } else {
209
- const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
210
- diagnosticMessages.push(message);
212
+ diagnosticMessages.push(flattenDiagnosticMessageText(diagnostic.getMessageText().toString(), "\n"));
211
213
  }
212
214
  });
213
215
  const diagnosticMessage = diagnosticMessages.join("\n");
@@ -522,6 +524,7 @@ async function initializeTsconfig(context) {
522
524
  const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
523
525
  context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
524
526
  context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
527
+ context.log(LogLevelLabel.TRACE, "Writing updated TypeScript configuration (tsconfig.json) file to disk.");
525
528
  await context.fs.writeFile(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson), {
526
529
  mode: "fs"
527
530
  });
@@ -637,23 +640,23 @@ async function loadWorkspaceConfig(workspaceRoot, cwd) {
637
640
  }));
638
641
  }
639
642
  __name(loadWorkspaceConfig, "loadWorkspaceConfig");
640
- async function loadUserConfigFile(projectRoot, workspaceRoot, jiti, command, mode, configFile, framework = "powerlines") {
643
+ async function loadUserConfigFile(projectRoot, workspaceRoot, jiti, command, mode = "production", configFile, framework = "powerlines") {
641
644
  let resolvedUserConfig = {};
642
- const resolvedUserConfigFile = configFile && existsSync(configFile) ? configFile : configFile && existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), configFile)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), configFile) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.ts`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.ts`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.js`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.js`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mts`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mts`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mjs`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mjs`) : void 0;
645
+ let resolvedUserConfigFile;
646
+ if (configFile) {
647
+ resolvedUserConfigFile = existsSync(replacePath(configFile, projectRoot)) ? replacePath(configFile, projectRoot) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), replacePath(configFile, projectRoot))) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), replacePath(configFile, projectRoot)) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), configFile)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), configFile) : void 0;
648
+ }
649
+ if (!resolvedUserConfigFile) {
650
+ resolvedUserConfigFile = existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.ts`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.ts`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.js`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.js`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mts`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mts`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mjs`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.${mode}.config.mjs`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.ts`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.ts`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.js`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.js`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mts`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mts`) : existsSync(joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mjs`)) ? joinPaths$1(appendPath(projectRoot, workspaceRoot), `${framework}.config.mjs`) : void 0;
651
+ }
643
652
  if (resolvedUserConfigFile) {
644
- let resolvedPath;
645
- try {
646
- resolvedPath = jiti.esmResolve(resolvedUserConfigFile);
647
- } catch {
648
- resolvedPath = resolvedUserConfigFile;
649
- }
650
- const resolved = await jiti.import(resolvedPath);
653
+ const resolved = await jiti.import(jiti.esmResolve(resolvedUserConfigFile));
651
654
  if (resolved) {
652
655
  let config = {};
653
656
  if (isFunction(resolved)) {
654
657
  config = await Promise.resolve(resolved({
655
658
  command,
656
- mode: mode || "production",
659
+ mode,
657
660
  isSsrBuild: false,
658
661
  isPreview: false
659
662
  }));
@@ -684,6 +687,7 @@ async function loadUserConfigFile(projectRoot, workspaceRoot, jiti, command, mod
684
687
  __name(loadUserConfigFile, "loadUserConfigFile");
685
688
  function resolveOptions(options) {
686
689
  return defu6(options, {
690
+ debug: options.logLevel === "trace",
687
691
  interopDefault: true,
688
692
  fsCache: options.mode !== "development" ? joinPaths$1(options.cacheDir, "jiti") : false,
689
693
  moduleCache: options.mode !== "development"
@@ -762,8 +766,6 @@ function replacePathTokens(context, path) {
762
766
  return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{distPath}", context.config.output.distPath).replaceAll("{artifactsPath}", replacePath(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", replacePath(context.entryPath, context.workspaceConfig.workspaceRoot));
763
767
  }
764
768
  __name(replacePathTokens, "replacePathTokens");
765
-
766
- // src/lib/entry.ts
767
769
  function resolveEntryInputFile(context, typeDefinition) {
768
770
  return replacePath(typeDefinition.file, joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.projectRoot));
769
771
  }
@@ -924,187 +926,6 @@ var FileMetadata = class _FileMetadata extends $.Struct {
924
926
  return "FileMetadata_" + super.toString();
925
927
  }
926
928
  };
927
- var ChunkData = class extends $.Struct {
928
- static {
929
- __name(this, "ChunkData");
930
- }
931
- static _capnp = {
932
- displayName: "ChunkData",
933
- id: "84076f13b057f83a",
934
- size: new $.ObjectSize(8, 4)
935
- };
936
- /**
937
- * An additional name for the file.
938
- *
939
- */
940
- get id() {
941
- return $.utils.getText(0, this);
942
- }
943
- set id(value) {
944
- $.utils.setText(0, value, this);
945
- }
946
- /**
947
- * Files that are implicitly loaded after one of the specified files.
948
- *
949
- */
950
- get name() {
951
- return $.utils.getText(1, this);
952
- }
953
- set name(value) {
954
- $.utils.setText(1, value, this);
955
- }
956
- _adoptImplicitlyLoadedAfterOneOf(value) {
957
- $.utils.adopt(value, $.utils.getPointer(2, this));
958
- }
959
- _disownImplicitlyLoadedAfterOneOf() {
960
- return $.utils.disown(this.implicitlyLoadedAfterOneOf);
961
- }
962
- /**
963
- * The importer of the file.
964
- *
965
- */
966
- get implicitlyLoadedAfterOneOf() {
967
- return $.utils.getList(2, $.TextList, this);
968
- }
969
- _hasImplicitlyLoadedAfterOneOf() {
970
- return !$.utils.isNull($.utils.getPointer(2, this));
971
- }
972
- _initImplicitlyLoadedAfterOneOf(length) {
973
- return $.utils.initList(2, $.TextList, length, this);
974
- }
975
- set implicitlyLoadedAfterOneOf(value) {
976
- $.utils.copyFrom(value, $.utils.getPointer(2, this));
977
- }
978
- /**
979
- * The signature preservation mode for the file.
980
- *
981
- */
982
- get importer() {
983
- return $.utils.getText(3, this);
984
- }
985
- set importer(value) {
986
- $.utils.setText(3, value, this);
987
- }
988
- get preserveSignature() {
989
- return $.utils.getUint16(0, this);
990
- }
991
- set preserveSignature(value) {
992
- $.utils.setUint16(0, value, this);
993
- }
994
- toString() {
995
- return "ChunkData_" + super.toString();
996
- }
997
- };
998
- var PrebuiltData = class extends $.Struct {
999
- static {
1000
- __name(this, "PrebuiltData");
1001
- }
1002
- static _capnp = {
1003
- displayName: "PrebuiltData",
1004
- id: "c5b1a6ca696328ee",
1005
- size: new $.ObjectSize(0, 4)
1006
- };
1007
- /**
1008
- * An additional name for the file.
1009
- *
1010
- */
1011
- get id() {
1012
- return $.utils.getText(0, this);
1013
- }
1014
- set id(value) {
1015
- $.utils.setText(0, value, this);
1016
- }
1017
- /**
1018
- * The file exports.
1019
- *
1020
- */
1021
- get name() {
1022
- return $.utils.getText(1, this);
1023
- }
1024
- set name(value) {
1025
- $.utils.setText(1, value, this);
1026
- }
1027
- _adoptExports(value) {
1028
- $.utils.adopt(value, $.utils.getPointer(2, this));
1029
- }
1030
- _disownExports() {
1031
- return $.utils.disown(this.exports);
1032
- }
1033
- /**
1034
- * The source map for the file.
1035
- *
1036
- */
1037
- get exports() {
1038
- return $.utils.getList(2, $.TextList, this);
1039
- }
1040
- _hasExports() {
1041
- return !$.utils.isNull($.utils.getPointer(2, this));
1042
- }
1043
- _initExports(length) {
1044
- return $.utils.initList(2, $.TextList, length, this);
1045
- }
1046
- set exports(value) {
1047
- $.utils.copyFrom(value, $.utils.getPointer(2, this));
1048
- }
1049
- get map() {
1050
- return $.utils.getText(3, this);
1051
- }
1052
- set map(value) {
1053
- $.utils.setText(3, value, this);
1054
- }
1055
- toString() {
1056
- return "PrebuiltData_" + super.toString();
1057
- }
1058
- };
1059
- var AssetData = class extends $.Struct {
1060
- static {
1061
- __name(this, "AssetData");
1062
- }
1063
- static _capnp = {
1064
- displayName: "AssetData",
1065
- id: "da660c6c1fa4c830",
1066
- size: new $.ObjectSize(8, 3)
1067
- };
1068
- /**
1069
- * An additional name for the file.
1070
- *
1071
- */
1072
- get id() {
1073
- return $.utils.getText(0, this);
1074
- }
1075
- set id(value) {
1076
- $.utils.setText(0, value, this);
1077
- }
1078
- /**
1079
- * Indicates whether the file needs a code reference.
1080
- *
1081
- */
1082
- get name() {
1083
- return $.utils.getText(1, this);
1084
- }
1085
- set name(value) {
1086
- $.utils.setText(1, value, this);
1087
- }
1088
- /**
1089
- * The original file name before any transformations.
1090
- *
1091
- */
1092
- get needsCodeReference() {
1093
- return $.utils.getBit(0, this);
1094
- }
1095
- set needsCodeReference(value) {
1096
- $.utils.setBit(0, value, this);
1097
- }
1098
- get originalFileName() {
1099
- return $.utils.getText(2, this);
1100
- }
1101
- set originalFileName(value) {
1102
- $.utils.setText(2, value, this);
1103
- }
1104
- toString() {
1105
- return "AssetData_" + super.toString();
1106
- }
1107
- };
1108
929
  var FileId = class extends $.Struct {
1109
930
  static {
1110
931
  __name(this, "FileId");
@@ -1170,14 +991,11 @@ var FileSystem = class _FileSystem extends $.Struct {
1170
991
  static _capnp = {
1171
992
  displayName: "FileSystem",
1172
993
  id: "ae0c23d43e56abcf",
1173
- size: new $.ObjectSize(0, 6)
994
+ size: new $.ObjectSize(0, 3)
1174
995
  };
1175
996
  static _Ids;
1176
997
  static _Files;
1177
998
  static _Metadata;
1178
- static _Assets;
1179
- static _Chunks;
1180
- static _Prebuilt;
1181
999
  _adoptIds(value) {
1182
1000
  $.utils.adopt(value, $.utils.getPointer(0, this));
1183
1001
  }
@@ -1232,60 +1050,6 @@ var FileSystem = class _FileSystem extends $.Struct {
1232
1050
  set metadata(value) {
1233
1051
  $.utils.copyFrom(value, $.utils.getPointer(2, this));
1234
1052
  }
1235
- _adoptAssets(value) {
1236
- $.utils.adopt(value, $.utils.getPointer(3, this));
1237
- }
1238
- _disownAssets() {
1239
- return $.utils.disown(this.assets);
1240
- }
1241
- get assets() {
1242
- return $.utils.getList(3, _FileSystem._Assets, this);
1243
- }
1244
- _hasAssets() {
1245
- return !$.utils.isNull($.utils.getPointer(3, this));
1246
- }
1247
- _initAssets(length) {
1248
- return $.utils.initList(3, _FileSystem._Assets, length, this);
1249
- }
1250
- set assets(value) {
1251
- $.utils.copyFrom(value, $.utils.getPointer(3, this));
1252
- }
1253
- _adoptChunks(value) {
1254
- $.utils.adopt(value, $.utils.getPointer(4, this));
1255
- }
1256
- _disownChunks() {
1257
- return $.utils.disown(this.chunks);
1258
- }
1259
- get chunks() {
1260
- return $.utils.getList(4, _FileSystem._Chunks, this);
1261
- }
1262
- _hasChunks() {
1263
- return !$.utils.isNull($.utils.getPointer(4, this));
1264
- }
1265
- _initChunks(length) {
1266
- return $.utils.initList(4, _FileSystem._Chunks, length, this);
1267
- }
1268
- set chunks(value) {
1269
- $.utils.copyFrom(value, $.utils.getPointer(4, this));
1270
- }
1271
- _adoptPrebuilt(value) {
1272
- $.utils.adopt(value, $.utils.getPointer(5, this));
1273
- }
1274
- _disownPrebuilt() {
1275
- return $.utils.disown(this.prebuilt);
1276
- }
1277
- get prebuilt() {
1278
- return $.utils.getList(5, _FileSystem._Prebuilt, this);
1279
- }
1280
- _hasPrebuilt() {
1281
- return !$.utils.isNull($.utils.getPointer(5, this));
1282
- }
1283
- _initPrebuilt(length) {
1284
- return $.utils.initList(5, _FileSystem._Prebuilt, length, this);
1285
- }
1286
- set prebuilt(value) {
1287
- $.utils.copyFrom(value, $.utils.getPointer(5, this));
1288
- }
1289
1053
  toString() {
1290
1054
  return "FileSystem_" + super.toString();
1291
1055
  }
@@ -1294,9 +1058,6 @@ FileMetadata._Properties = $.CompositeList(FileMetadata_KeyValuePair);
1294
1058
  FileSystem._Ids = $.CompositeList(FileId);
1295
1059
  FileSystem._Files = $.CompositeList(FileData);
1296
1060
  FileSystem._Metadata = $.CompositeList(FileMetadata);
1297
- FileSystem._Assets = $.CompositeList(AssetData);
1298
- FileSystem._Chunks = $.CompositeList(ChunkData);
1299
- FileSystem._Prebuilt = $.CompositeList(PrebuiltData);
1300
1061
  var createLog = /* @__PURE__ */ __name((name, options = {}) => {
1301
1062
  const logLevel = options.logLevel === null ? LogLevelLabel.SILENT : options.logLevel || LogLevelLabel.INFO;
1302
1063
  if (logLevel === LogLevelLabel.SILENT) {
@@ -1340,13 +1101,9 @@ function isBufferEncoding(options) {
1340
1101
  }
1341
1102
  __name(isBufferEncoding, "isBufferEncoding");
1342
1103
  function isPowerlinesWriteFileOptions(options) {
1343
- return !isBufferEncoding(options) && isSetObject(options) && ("skipFormat" in options || "mode" in options && (options.mode === "fs" || options.mode === "virtual"));
1104
+ return !isBufferEncoding(options) && isSetObject(options) && "mode" in options && (options.mode === "fs" || options.mode === "virtual");
1344
1105
  }
1345
1106
  __name(isPowerlinesWriteFileOptions, "isPowerlinesWriteFileOptions");
1346
- function isNodeWriteFileOptions(options) {
1347
- return !isUndefined(options) && (isBufferEncoding(options) || !isPowerlinesWriteFileOptions(options));
1348
- }
1349
- __name(isNodeWriteFileOptions, "isNodeWriteFileOptions");
1350
1107
  function isVirtualFileData(obj) {
1351
1108
  return !!(isSetObject(obj) && "code" in obj && obj.code);
1352
1109
  }
@@ -1483,6 +1240,18 @@ function patchFS(originalFS, vfs) {
1483
1240
  };
1484
1241
  }
1485
1242
  __name(patchFS, "patchFS");
1243
+ function isValidId(id, prefix = "powerlines") {
1244
+ return id.replace(/^\\0/, "").startsWith(`${prefix.replace(/:$/, "")}`);
1245
+ }
1246
+ __name(isValidId, "isValidId");
1247
+ function normalizeId(id, prefix = "powerlines") {
1248
+ return `${prefix.replace(/:$/, "")}:${toFilePath(id).replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), "").replace(/^\\0/, "").replace(findFileDotExtensionSafe(toFilePath(id)), "")}`;
1249
+ }
1250
+ __name(normalizeId, "normalizeId");
1251
+ function normalizePath(path, builtinsPath, prefix = "powerlines") {
1252
+ return isValidId(toFilePath(path), prefix) ? normalizeId(toFilePath(path), prefix).replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), builtinsPath) : toFilePath(path);
1253
+ }
1254
+ __name(normalizePath, "normalizePath");
1486
1255
  var UnifiedFS = class _UnifiedFS extends Union {
1487
1256
  static {
1488
1257
  __name(this, "UnifiedFS");
@@ -1659,9 +1428,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
1659
1428
  */
1660
1429
  #paths;
1661
1430
  /**
1662
- * A map of virtual file paths to their underlying file content.
1431
+ * A cache for module resolution results.
1663
1432
  */
1664
- #cachedResolver = /* @__PURE__ */ new Map();
1433
+ #resolverCache;
1665
1434
  /**
1666
1435
  * The unified volume that combines the virtual file system with the real file system.
1667
1436
  *
@@ -1696,189 +1465,35 @@ var VirtualFileSystem = class _VirtualFileSystem {
1696
1465
  * @returns `true` if the path exists, otherwise `false`.
1697
1466
  */
1698
1467
  #existsSync(path) {
1699
- const formattedPath = this.formatPath(path);
1700
- return this.#unifiedFS.virtual.existsSync(formattedPath) || this.#unifiedFS.physical.existsSync(formattedPath) || this.#unifiedFS.resolveFS(path).existsSync(formattedPath);
1701
- }
1702
- /**
1703
- * Builds a regular expression from a string pattern for path matching.
1704
- *
1705
- * @param strPattern - The string pattern to convert.
1706
- * @returns A regular expression for matching paths.
1707
- */
1708
- #buildRegex(strPattern) {
1709
- const token = "::GLOBSTAR::";
1710
- return new RegExp(`^${this.formatPath(strPattern).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
1711
- }
1712
- /**
1713
- * Formats a file id by removing the file extension and prepending the runtime prefix.
1714
- *
1715
- * @param id - The file ID to format.
1716
- * @returns The formatted file ID.
1717
- */
1718
- #formatId(id) {
1719
- const formattedId = toFilePath(id);
1720
- return `${this.#context.config.output.builtinPrefix}:${formattedId.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "").replace(findFileDotExtensionSafe(formattedId), "")}`;
1721
- }
1722
- /**
1723
- * Resolves an id parameter to a corresponding virtual file path in the virtual file system (VFS).
1724
- *
1725
- * @param id - The id to resolve.
1726
- * @returns The resolved file id if it exists, otherwise undefined.
1727
- */
1728
- #resolveId(id) {
1729
- if (this.#ids[this.#formatId(id)]) {
1730
- return this.#ids[this.#formatId(id)] || false;
1731
- }
1732
- return false;
1733
- }
1734
- /**
1735
- * Resolves a path parameter to a corresponding virtual file path in the virtual file system (VFS).
1736
- *
1737
- * @param path - The path to resolve.
1738
- * @param options - Optional parameters for resolving the path.
1739
- * @returns The resolved file path if it exists, otherwise undefined.
1740
- */
1741
- #resolvePath(path, options = {}) {
1742
- if (isAbsolutePath(path)) {
1743
- if (this.#existsSync(path)) {
1744
- return path;
1745
- }
1746
- const result = this.#checkVariants(path);
1747
- if (result) {
1748
- return result;
1749
- }
1750
- }
1751
- for (const parentPath of this.#resolveParentPaths(path, options.paths)) {
1752
- const request = joinPaths$1(parentPath, path);
1753
- if (this.#existsSync(request)) {
1754
- return request;
1755
- }
1756
- const result = this.#checkVariants(request);
1757
- if (result) {
1758
- return result;
1759
- }
1760
- }
1761
- return false;
1468
+ return this.#unifiedFS.virtual.existsSync(this.#normalizePath(path)) || this.#unifiedFS.physical.existsSync(this.#normalizePath(path)) || this.#unifiedFS.resolveFS(path).existsSync(this.#normalizePath(path));
1762
1469
  }
1763
1470
  /**
1764
- * Resolves parent paths for a given request.
1471
+ * Normalizes a given module id by resolving it against the built-ins path.
1765
1472
  *
1766
- * @param request - The request path to resolve parent paths for.
1767
- * @param parents - An optional array of parent paths to consider.
1768
- * @returns An array of resolved parent paths.
1769
- */
1770
- #resolveParentPaths(request, parents = []) {
1771
- let paths = [
1772
- this.#context.workspaceConfig.workspaceRoot,
1773
- joinPaths$1(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
1774
- ];
1775
- if (this.#context.tsconfig.options.paths) {
1776
- paths = this.#context.tsconfig.options.paths ? Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => request.startsWith(tsconfigPath.replaceAll("*", ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().reduce((ret, path) => {
1777
- if (path && !ret.includes(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, path))) {
1778
- ret.push(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, path));
1779
- }
1780
- return ret;
1781
- }, paths) : paths;
1782
- }
1783
- return paths.reduce((ret, path) => {
1784
- if (!ret.includes(path)) {
1785
- ret.push(path);
1786
- }
1787
- return ret;
1788
- }, parents.filter(Boolean).map((p) => this.formatPath(p)));
1789
- }
1790
- /**
1791
- * Clears the resolver cache for a given path.
1792
- *
1793
- * @param path - The path to clear the resolver cache for.
1473
+ * @param id - The module id to normalize.
1474
+ * @returns The normalized module id.
1794
1475
  */
1795
- #clearResolverCache(path) {
1796
- this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
1476
+ #normalizeId(id) {
1477
+ return normalizeId(id, this.#context.config.output.builtinPrefix);
1797
1478
  }
1798
1479
  /**
1799
- * Check if the file exists with different variants (index, extensions).
1480
+ * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
1800
1481
  *
1801
- * @param request - The request path to check.
1802
- * @param parentPath - An optional parent path to prepend to the request.
1803
- * @returns The file path if it exists, otherwise false.
1804
- */
1805
- #checkVariants(request, parentPath) {
1806
- const path = parentPath ? joinPaths$1(parentPath, request) : request;
1807
- let file = this.#checkExtensions(path);
1808
- if (file) {
1809
- return file;
1810
- }
1811
- file = this.#checkIndex(path);
1812
- if (file) {
1813
- return file;
1814
- }
1815
- return false;
1816
- }
1817
- /**
1818
- * Check if the index file exists in the given request path.
1819
- *
1820
- * @param request - The request path to check.
1821
- * @returns The index file path if it exists, otherwise false.
1482
+ * @param path - The path to normalize.
1483
+ * @returns The normalized path.
1822
1484
  */
1823
- #checkIndex(request) {
1824
- let file = joinPaths$1(request, "index");
1825
- if (this.#existsSync(file)) {
1826
- return file;
1827
- }
1828
- file = this.#checkExtensions(file);
1829
- if (file) {
1830
- return file;
1831
- }
1832
- return false;
1485
+ #normalizePath(path) {
1486
+ return normalizePath(path, this.#context.builtinsPath, this.#context.config.output.builtinPrefix);
1833
1487
  }
1834
1488
  /**
1835
- * Check if the file exists with different extensions.
1489
+ * Builds a regular expression from a string pattern for path matching.
1836
1490
  *
1837
- * @param request - The request path to check.
1838
- * @returns The file path if it exists with any of the checked extensions, otherwise false.
1491
+ * @param path - The string pattern to convert.
1492
+ * @returns A regular expression for matching paths.
1839
1493
  */
1840
- #checkExtensions(request) {
1841
- let file = `${request}.ts`;
1842
- if (this.#existsSync(file)) {
1843
- return file;
1844
- }
1845
- file = `${request}.mts`;
1846
- if (this.#existsSync(file)) {
1847
- return file;
1848
- }
1849
- file = `${request}.cts`;
1850
- if (this.#existsSync(file)) {
1851
- return file;
1852
- }
1853
- file = `${request}.tsx`;
1854
- if (this.#existsSync(file)) {
1855
- return file;
1856
- }
1857
- file = `${request}.js`;
1858
- if (this.#existsSync(file)) {
1859
- return file;
1860
- }
1861
- file = `${request}.mjs`;
1862
- if (this.#existsSync(file)) {
1863
- return file;
1864
- }
1865
- file = `${request}.cjs`;
1866
- if (this.#existsSync(file)) {
1867
- return file;
1868
- }
1869
- file = `${request}.jsx`;
1870
- if (this.#existsSync(file)) {
1871
- return file;
1872
- }
1873
- file = `${request}.json`;
1874
- if (this.#existsSync(file)) {
1875
- return file;
1876
- }
1877
- file = `${request}.d.ts`;
1878
- if (this.#existsSync(file)) {
1879
- return file;
1880
- }
1881
- return false;
1494
+ #buildRegex(path) {
1495
+ const token = "::GLOBSTAR::";
1496
+ return new RegExp(`^${this.#normalizePath(path).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
1882
1497
  }
1883
1498
  /**
1884
1499
  * Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
@@ -1887,8 +1502,8 @@ var VirtualFileSystem = class _VirtualFileSystem {
1887
1502
  * @returns A promise that resolves to a new virtual file system instance.
1888
1503
  */
1889
1504
  static async create(context) {
1890
- if (!context.config.skipCache && existsSync(joinPaths$1(context.cachePath, "fs.bin"))) {
1891
- const buffer = await readFileBuffer(joinPaths$1(context.cachePath, "fs.bin"));
1505
+ if (!context.config.skipCache && existsSync(joinPaths$1(context.dataPath, "fs.bin"))) {
1506
+ const buffer = await readFileBuffer(joinPaths$1(context.dataPath, "fs.bin"));
1892
1507
  const message2 = new $.Message(buffer, false);
1893
1508
  return new _VirtualFileSystem(context, message2.getRoot(FileSystem));
1894
1509
  }
@@ -1902,8 +1517,8 @@ var VirtualFileSystem = class _VirtualFileSystem {
1902
1517
  * @returns A new virtual file system instance.
1903
1518
  */
1904
1519
  static createSync(context) {
1905
- if (!context.config.skipCache && existsSync(joinPaths$1(context.cachePath, "fs.bin"))) {
1906
- const buffer = readFileBufferSync(joinPaths$1(context.cachePath, "fs.bin"));
1520
+ if (!context.config.skipCache && existsSync(joinPaths$1(context.dataPath, "fs.bin"))) {
1521
+ const buffer = readFileBufferSync(joinPaths$1(context.dataPath, "fs.bin"));
1907
1522
  const message2 = new $.Message(buffer, false);
1908
1523
  return new _VirtualFileSystem(context, message2.getRoot(FileSystem));
1909
1524
  }
@@ -1914,19 +1529,43 @@ var VirtualFileSystem = class _VirtualFileSystem {
1914
1529
  * A map of file ids to their metadata.
1915
1530
  */
1916
1531
  get metadata() {
1917
- return this.#metadata;
1532
+ return new Proxy(this.#metadata, {
1533
+ get: /* @__PURE__ */ __name((target, prop) => {
1534
+ return target[this.#normalizeId(prop)];
1535
+ }, "get")
1536
+ });
1918
1537
  }
1919
1538
  /**
1920
- * A map of module ids to their file paths.
1539
+ * A map of file paths to their module ids.
1921
1540
  */
1922
1541
  get ids() {
1923
- return this.#ids;
1542
+ return new Proxy(this.#paths, {
1543
+ get: /* @__PURE__ */ __name((target, prop) => {
1544
+ return target[this.#normalizePath(prop)];
1545
+ }, "get")
1546
+ });
1924
1547
  }
1925
1548
  /**
1926
- * A map of virtual file paths to their IDs.
1549
+ * A map of module ids to their file paths.
1927
1550
  */
1928
1551
  get paths() {
1929
- return this.#paths;
1552
+ return new Proxy(this.#paths, {
1553
+ get: /* @__PURE__ */ __name((target, prop) => {
1554
+ return target[this.#normalizeId(prop)];
1555
+ }, "get")
1556
+ });
1557
+ }
1558
+ get resolverCache() {
1559
+ if (!this.#resolverCache) {
1560
+ this.#resolverCache = create({
1561
+ cacheId: "module-resolution",
1562
+ cacheDir: this.#context.cachePath,
1563
+ ttl: 60 * 60 * 1e3,
1564
+ lruSize: 5e3,
1565
+ persistInterval: 100
1566
+ });
1567
+ }
1568
+ return this.#resolverCache;
1930
1569
  }
1931
1570
  /**
1932
1571
  * Creates a new instance of the {@link VirtualFileSystem}.
@@ -1971,17 +1610,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
1971
1610
  * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
1972
1611
  *
1973
1612
  * @param pathOrId - The path or id to check.
1974
- * @param options - Optional parameters for resolving the path.
1975
1613
  * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
1976
1614
  */
1977
- isVirtual(pathOrId, options = {}) {
1615
+ isVirtual(pathOrId, importer, options = {}) {
1978
1616
  if (!pathOrId) {
1979
1617
  return false;
1980
1618
  }
1981
- const resolvedPath = this.resolve(pathOrId, {
1982
- ...options,
1983
- pathType: "file"
1984
- });
1619
+ const resolvedPath = this.resolveSync(pathOrId, importer, options);
1985
1620
  if (!resolvedPath) {
1986
1621
  return false;
1987
1622
  }
@@ -1991,17 +1626,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
1991
1626
  * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
1992
1627
  *
1993
1628
  * @param pathOrId - The path or id to check.
1994
- * @param options - Optional parameters for resolving the path.
1995
1629
  * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
1996
1630
  */
1997
- isPhysical(pathOrId, options = {}) {
1631
+ isPhysical(pathOrId, importer, options = {}) {
1998
1632
  if (!pathOrId) {
1999
1633
  return false;
2000
1634
  }
2001
- const resolvedPath = this.resolve(pathOrId, {
2002
- ...options,
2003
- pathType: "file"
2004
- });
1635
+ const resolvedPath = this.resolveSync(pathOrId, importer, options);
2005
1636
  if (!resolvedPath) {
2006
1637
  return false;
2007
1638
  }
@@ -2023,16 +1654,17 @@ var VirtualFileSystem = class _VirtualFileSystem {
2023
1654
  * @param path - The path to create the directory at.
2024
1655
  */
2025
1656
  unlinkSync(path, options) {
2026
- const formattedPath = toFilePath(path);
2027
- if (!this.isFile(formattedPath)) {
1657
+ if (!this.isFile(this.#normalizePath(path))) {
2028
1658
  return;
2029
1659
  }
2030
- this.#log(LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
2031
- this.#unifiedFS.resolveFS(path, options).unlinkSync(formattedPath);
2032
- if (this.paths[formattedPath] && this.metadata[this.paths[formattedPath]]) {
2033
- delete this.metadata[this.paths[formattedPath]];
1660
+ this.#log(LogLevelLabel.TRACE, `Synchronously removing file: ${this.#normalizePath(path)}`);
1661
+ this.#unifiedFS.resolveFS(path, options).unlinkSync(this.#normalizePath(path));
1662
+ if (this.#ids[this.#normalizePath(path)] && this.#metadata[this.#ids[this.#normalizePath(path)]]) {
1663
+ delete this.#metadata[this.#ids[this.#normalizePath(path)]];
1664
+ delete this.#ids[this.#normalizePath(path)];
1665
+ delete this.#paths[this.#normalizeId(path)];
1666
+ this.#resolverCache.delete(this.#normalizePath(path));
2034
1667
  }
2035
- this.#clearResolverCache(formattedPath);
2036
1668
  }
2037
1669
  /**
2038
1670
  * Removes a file in the virtual file system (VFS).
@@ -2040,19 +1672,17 @@ var VirtualFileSystem = class _VirtualFileSystem {
2040
1672
  * @param path - The path to create the directory at.
2041
1673
  */
2042
1674
  async unlink(path, options) {
2043
- const formattedPath = toFilePath(path);
2044
- if (!this.isFile(formattedPath)) {
1675
+ if (!this.isFile(this.#normalizePath(path))) {
2045
1676
  return;
2046
1677
  }
2047
- this.#log(LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
1678
+ this.#log(LogLevelLabel.TRACE, `Removing file: ${this.#normalizePath(path)}`);
2048
1679
  if (isFunction(this.#unifiedFS.resolveFS(path, options).promises.unlink)) {
2049
- await this.#unifiedFS.resolveFS(path, options).promises.unlink(formattedPath);
2050
- if (this.paths[formattedPath] && this.metadata[this.paths[formattedPath]]) {
2051
- delete this.metadata[this.paths[formattedPath]];
1680
+ await this.#unifiedFS.resolveFS(path, options).promises.unlink(this.#normalizePath(path));
1681
+ if (this.#ids[this.#normalizePath(path)] && this.#metadata[this.#ids[this.#normalizePath(path)]]) {
1682
+ delete this.#metadata[this.#ids[this.#normalizePath(path)]];
2052
1683
  }
2053
- this.#clearResolverCache(formattedPath);
2054
1684
  } else {
2055
- this.unlinkSync(formattedPath, options);
1685
+ this.unlinkSync(this.#normalizePath(path), options);
2056
1686
  }
2057
1687
  }
2058
1688
  /**
@@ -2062,15 +1692,13 @@ var VirtualFileSystem = class _VirtualFileSystem {
2062
1692
  * @param options - Options for creating the directory.
2063
1693
  */
2064
1694
  rmdirSync(path, options = {}) {
2065
- const formattedPath = toFilePath(path);
2066
- if (!this.isDirectory(formattedPath)) {
1695
+ if (!this.isDirectory(this.#normalizePath(path))) {
2067
1696
  return;
2068
1697
  }
2069
- this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
2070
- this.#unifiedFS.resolveFS(path, options).rmdirSync(formattedPath, defu6(options, {
1698
+ this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${this.#normalizePath(path)}`);
1699
+ this.#unifiedFS.resolveFS(path, options).rmdirSync(this.#normalizePath(path), defu6(options, {
2071
1700
  recursive: true
2072
1701
  }));
2073
- this.#clearResolverCache(formattedPath);
2074
1702
  }
2075
1703
  /**
2076
1704
  * Removes a directory in the virtual file system (VFS).
@@ -2080,19 +1708,17 @@ var VirtualFileSystem = class _VirtualFileSystem {
2080
1708
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
2081
1709
  */
2082
1710
  async rmdir(path, options = {}) {
2083
- const formattedPath = toFilePath(path);
2084
- if (!this.isDirectory(formattedPath)) {
1711
+ if (!this.isDirectory(this.#normalizePath(path))) {
2085
1712
  return;
2086
1713
  }
2087
- this.#log(LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
1714
+ this.#log(LogLevelLabel.TRACE, `Removing directory: ${this.#normalizePath(path)}`);
2088
1715
  if (isFunction(this.#unifiedFS.resolveFS(path, options).promises.rm)) {
2089
- await this.#unifiedFS.resolveFS(path, options).promises.rm(formattedPath, defu6(options, {
1716
+ await this.#unifiedFS.resolveFS(path, options).promises.rm(this.#normalizePath(path), defu6(options, {
2090
1717
  force: true,
2091
1718
  recursive: true
2092
1719
  }));
2093
- this.#clearResolverCache(formattedPath);
2094
1720
  } else {
2095
- this.rmdirSync(formattedPath, defu6(options ?? {}, {
1721
+ this.rmdirSync(this.#normalizePath(path), defu6(options ?? {}, {
2096
1722
  force: true,
2097
1723
  recursive: true
2098
1724
  }));
@@ -2106,11 +1732,11 @@ var VirtualFileSystem = class _VirtualFileSystem {
2106
1732
  * @returns A promise that resolves when the file is removed.
2107
1733
  */
2108
1734
  async rm(path, options = {}) {
2109
- this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
2110
- if (this.isDirectory(path)) {
2111
- return this.rmdir(path, options);
1735
+ this.#log(LogLevelLabel.TRACE, `Removing: ${this.#normalizePath(path)}`);
1736
+ if (this.isDirectory(this.#normalizePath(path))) {
1737
+ return this.rmdir(this.#normalizePath(path), options);
2112
1738
  }
2113
- return this.unlink(path, options);
1739
+ return this.unlink(this.#normalizePath(path), options);
2114
1740
  }
2115
1741
  /**
2116
1742
  * Synchronously removes a file or directory in the virtual file system (VFS).
@@ -2119,11 +1745,11 @@ var VirtualFileSystem = class _VirtualFileSystem {
2119
1745
  * @param options - Options for removing the file or directory.
2120
1746
  */
2121
1747
  rmSync(path, options = {}) {
2122
- this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
2123
- if (this.isDirectory(path)) {
2124
- return this.rmdirSync(path, options);
1748
+ this.#log(LogLevelLabel.TRACE, `Removing: ${this.#normalizePath(path)}`);
1749
+ if (this.isDirectory(this.#normalizePath(path))) {
1750
+ return this.rmdirSync(this.#normalizePath(path), options);
2125
1751
  }
2126
- return this.unlinkSync(path, options);
1752
+ return this.unlinkSync(this.#normalizePath(path), options);
2127
1753
  }
2128
1754
  /**
2129
1755
  * Creates a directory in the virtual file system (VFS).
@@ -2133,9 +1759,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
2133
1759
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
2134
1760
  */
2135
1761
  mkdirSync(path, options = {}) {
2136
- const filePath = toFilePath(path);
2137
- this.#clearResolverCache(filePath);
2138
- return this.#unifiedFS.resolveFS(filePath, options).mkdirSync(filePath, defu6(options ?? {}, {
1762
+ return this.#unifiedFS.resolveFS(this.#normalizePath(path), options).mkdirSync(this.#normalizePath(path), defu6(omit(options, [
1763
+ "mode"
1764
+ ]), {
2139
1765
  recursive: true
2140
1766
  }));
2141
1767
  }
@@ -2148,17 +1774,19 @@ var VirtualFileSystem = class _VirtualFileSystem {
2148
1774
  */
2149
1775
  async mkdir(path, options = {}) {
2150
1776
  let result;
2151
- const filePath = toFilePath(path);
2152
- if (isFunction(this.#unifiedFS.resolveFS(filePath, options).promises.mkdir)) {
2153
- result = await this.#unifiedFS.resolveFS(filePath, options).promises.mkdir(filePath, defu6(options ?? {}, {
1777
+ if (isFunction(this.#unifiedFS.resolveFS(this.#normalizePath(path), options).promises.mkdir)) {
1778
+ result = await this.#unifiedFS.resolveFS(this.#normalizePath(path), options).promises.mkdir(this.#normalizePath(path), defu6(omit(options, [
1779
+ "mode"
1780
+ ]), {
2154
1781
  recursive: true
2155
1782
  }));
2156
1783
  } else {
2157
- result = this.#unifiedFS.resolveFS(filePath, options).mkdirSync(filePath, defu6(options ?? {}, {
1784
+ result = this.#unifiedFS.resolveFS(this.#normalizePath(path), options).mkdirSync(this.#normalizePath(path), defu6(omit(options, [
1785
+ "mode"
1786
+ ]), {
2158
1787
  recursive: true
2159
1788
  }));
2160
1789
  }
2161
- this.#clearResolverCache(filePath);
2162
1790
  return result;
2163
1791
  }
2164
1792
  /**
@@ -2170,17 +1798,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
2170
1798
  async glob(patterns) {
2171
1799
  const results = [];
2172
1800
  for (const pattern of toArray(patterns)) {
2173
- const normalized = this.formatPath(pattern);
1801
+ const normalized = this.#normalizePath(pattern);
2174
1802
  if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
2175
- const resolved = this.resolve(normalized, {
2176
- pathType: "file"
2177
- });
1803
+ const resolved = this.resolveSync(normalized);
2178
1804
  if (resolved && !results.includes(resolved)) {
2179
1805
  results.push(resolved);
2180
1806
  }
2181
1807
  continue;
2182
1808
  }
2183
- const absPattern = isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, normalized));
1809
+ const absPattern = isAbsolutePath(normalized) ? normalized : this.#normalizePath(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, normalized));
2184
1810
  const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
2185
1811
  const baseDir = firstGlobIdx === -1 ? findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
2186
1812
  const stack = [
@@ -2195,7 +1821,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2195
1821
  continue;
2196
1822
  }
2197
1823
  for (const entry of entries) {
2198
- const full = this.formatPath(joinPaths$1(dir, entry));
1824
+ const full = this.#normalizePath(joinPaths$1(dir, entry));
2199
1825
  let stats;
2200
1826
  try {
2201
1827
  stats = this.#unifiedFS.lstatSync(full);
@@ -2207,9 +1833,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2207
1833
  stack.push(full);
2208
1834
  } else if (stats.isFile()) {
2209
1835
  if (this.#buildRegex(absPattern).test(full)) {
2210
- const resolved = this.resolve(full, {
2211
- pathType: "file"
2212
- });
1836
+ const resolved = this.resolveSync(full);
2213
1837
  if (resolved && !results.includes(resolved)) {
2214
1838
  results.push(resolved);
2215
1839
  }
@@ -2229,17 +1853,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
2229
1853
  globSync(patterns) {
2230
1854
  const results = [];
2231
1855
  for (const pattern of toArray(patterns)) {
2232
- const normalized = this.formatPath(pattern);
1856
+ const normalized = this.#normalizePath(pattern);
2233
1857
  if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
2234
- const resolved = this.resolve(normalized, {
2235
- pathType: "file"
2236
- });
1858
+ const resolved = this.resolveSync(normalized);
2237
1859
  if (resolved && !results.includes(resolved)) {
2238
1860
  results.push(resolved);
2239
1861
  }
2240
1862
  continue;
2241
1863
  }
2242
- const absPattern = isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, normalized));
1864
+ const absPattern = isAbsolutePath(normalized) ? normalized : this.#normalizePath(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, normalized));
2243
1865
  const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
2244
1866
  const baseDir = firstGlobIdx === -1 ? findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
2245
1867
  const stack = [
@@ -2254,7 +1876,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2254
1876
  continue;
2255
1877
  }
2256
1878
  for (const entry of entries) {
2257
- const full = this.formatPath(joinPaths$1(dir, entry));
1879
+ const full = this.#normalizePath(joinPaths$1(dir, entry));
2258
1880
  let stats;
2259
1881
  try {
2260
1882
  stats = this.#unifiedFS.lstatSync(full);
@@ -2266,9 +1888,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2266
1888
  stack.push(full);
2267
1889
  } else if (stats.isFile()) {
2268
1890
  if (this.#buildRegex(absPattern).test(full)) {
2269
- const resolved = this.resolve(full, {
2270
- pathType: "file"
2271
- });
1891
+ const resolved = this.resolveSync(full);
2272
1892
  if (resolved && !results.includes(resolved)) {
2273
1893
  results.push(resolved);
2274
1894
  }
@@ -2338,21 +1958,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
2338
1958
  * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
2339
1959
  */
2340
1960
  async readFile(pathOrId, options = "utf8") {
2341
- if (!pathOrId) {
2342
- return void 0;
2343
- }
2344
- const filePath = this.resolve(toFilePath(pathOrId), {
2345
- pathType: "file"
2346
- });
2347
- if (filePath) {
1961
+ const filePath = await this.resolve(pathOrId);
1962
+ if (filePath && this.isFile(filePath)) {
2348
1963
  let result;
2349
1964
  if (isFunction(this.#unifiedFS.resolveFS(filePath).promises.readFile)) {
2350
1965
  result = (await this.#unifiedFS.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
2351
1966
  } else {
2352
1967
  result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
2353
1968
  }
2354
- const content = isBuffer(result) ? bufferToString(result) : result;
2355
- return content;
1969
+ return isBuffer(result) ? bufferToString(result) : result;
2356
1970
  }
2357
1971
  return void 0;
2358
1972
  }
@@ -2363,16 +1977,10 @@ var VirtualFileSystem = class _VirtualFileSystem {
2363
1977
  * @returns The contents of the file as a string, or undefined if the file does not exist.
2364
1978
  */
2365
1979
  readFileSync(pathOrId, options = "utf8") {
2366
- if (!pathOrId) {
2367
- return void 0;
2368
- }
2369
- const filePath = this.resolve(toFilePath(pathOrId), {
2370
- pathType: "file"
2371
- });
2372
- if (filePath) {
1980
+ const filePath = this.resolveSync(pathOrId);
1981
+ if (filePath && this.isFile(filePath)) {
2373
1982
  const result = this.#unifiedFS.resolveFS(filePath).readFileSync(filePath, options);
2374
- const content = isBuffer(result) ? bufferToString(result) : result;
2375
- return content;
1983
+ return isBuffer(result) ? bufferToString(result) : result;
2376
1984
  }
2377
1985
  return void 0;
2378
1986
  }
@@ -2385,34 +1993,40 @@ var VirtualFileSystem = class _VirtualFileSystem {
2385
1993
  * @returns A promise that resolves when the file is written.
2386
1994
  */
2387
1995
  async writeFile(path, data = "", options = "utf8") {
2388
- const formattedPath = this.formatPath(path);
2389
- if (!this.isDirectory(findFilePath(formattedPath))) {
2390
- await this.mkdir(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
1996
+ if (!this.isDirectory(findFilePath(this.#normalizePath(path)))) {
1997
+ await this.mkdir(findFilePath(this.#normalizePath(path)), isPowerlinesWriteFileOptions(options) ? options : void 0);
2391
1998
  }
2392
- let code = isVirtualFileData(data) ? data.code : data;
1999
+ const metadata = isVirtualFileData(data) ? data : {};
2000
+ metadata.id = this.#normalizeId(path);
2001
+ let code = isVirtualFileData(data) ? metadata.code : data;
2393
2002
  if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString(code)) {
2394
- const resolvedConfig = await resolveConfig(formattedPath);
2003
+ const resolvedConfig = await resolveConfig(this.#normalizePath(path));
2395
2004
  if (resolvedConfig) {
2396
2005
  code = await format(code, {
2397
- absolutePath: formattedPath,
2006
+ absolutePath: this.#normalizePath(path),
2398
2007
  ...resolvedConfig
2399
2008
  });
2400
2009
  }
2401
2010
  }
2402
- const outputMode = this.#unifiedFS.resolveMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
2403
- this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
2404
- this.metadata[formattedPath] = {
2011
+ const outputMode = this.#unifiedFS.resolveMode(this.#normalizePath(path), isPowerlinesWriteFileOptions(options) ? options : void 0);
2012
+ this.#log(LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
2013
+ this.#metadata[metadata.id] = {
2405
2014
  mode: outputMode,
2406
2015
  variant: "normal",
2407
2016
  timestamp: Date.now(),
2408
- ...isVirtualFileData(data) ? data : {}
2017
+ ...metadata
2409
2018
  };
2410
- this.#clearResolverCache(formattedPath);
2411
- const ifs = this.#unifiedFS.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
2019
+ this.#paths[metadata.id] = this.#normalizePath(path);
2020
+ this.#ids[this.#normalizePath(path)] = metadata.id;
2021
+ const ifs = this.#unifiedFS.resolveFS(this.#normalizePath(path), isPowerlinesWriteFileOptions(options) ? options : void 0);
2412
2022
  if (isFunction(ifs.promises.writeFile)) {
2413
- return ifs.promises.writeFile(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
2023
+ return ifs.promises.writeFile(this.#normalizePath(path), code, isSetObject(options) ? omit(options, [
2024
+ "mode"
2025
+ ]) : "utf8");
2414
2026
  }
2415
- return ifs.writeFileSync(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
2027
+ return ifs.writeFileSync(this.#normalizePath(path), code, isSetObject(options) ? omit(options, [
2028
+ "mode"
2029
+ ]) : "utf8");
2416
2030
  }
2417
2031
  /**
2418
2032
  * Synchronously writes a file to the virtual file system (VFS).
@@ -2422,21 +2036,23 @@ var VirtualFileSystem = class _VirtualFileSystem {
2422
2036
  * @param options - Optional parameters for writing the file.
2423
2037
  */
2424
2038
  writeFileSync(path, data = "", options = "utf8") {
2425
- const formattedPath = this.formatPath(path);
2426
- if (!this.isDirectory(findFilePath(formattedPath))) {
2427
- this.mkdirSync(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
2428
- }
2429
- const code = isVirtualFileData(data) ? data.code : data;
2430
- const outputMode = this.#unifiedFS.resolveMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
2431
- this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
2432
- this.metadata[formattedPath] = {
2039
+ if (!this.isDirectory(findFilePath(this.#normalizePath(path)))) {
2040
+ this.mkdirSync(findFilePath(this.#normalizePath(path)), isPowerlinesWriteFileOptions(options) ? options : void 0);
2041
+ }
2042
+ const metadata = isVirtualFileData(data) ? data : {};
2043
+ metadata.id = this.#normalizeId(path);
2044
+ const code = isVirtualFileData(data) ? metadata.code : data;
2045
+ const outputMode = this.#unifiedFS.resolveMode(this.#normalizePath(path), isPowerlinesWriteFileOptions(options) ? options : void 0);
2046
+ this.#log(LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
2047
+ this.#metadata[metadata.id] = {
2433
2048
  mode: outputMode,
2434
2049
  variant: "normal",
2435
2050
  timestamp: Date.now(),
2436
- ...isVirtualFileData(data) ? data : {}
2051
+ ...metadata
2437
2052
  };
2438
- this.#clearResolverCache(formattedPath);
2439
- const writeStream = this.#unifiedFS.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
2053
+ this.#paths[metadata.id] = this.#normalizePath(path);
2054
+ this.#ids[this.#normalizePath(path)] = metadata.id;
2055
+ const writeStream = this.#unifiedFS.resolveFS(this.#normalizePath(path), isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(this.#normalizePath(path));
2440
2056
  try {
2441
2057
  writeStream.write(code);
2442
2058
  } finally {
@@ -2450,7 +2066,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2450
2066
  * @returns `true` if the file exists, otherwise `false`.
2451
2067
  */
2452
2068
  existsSync(pathOrId) {
2453
- return this.resolve(pathOrId) !== false;
2069
+ return !!this.resolveSync(pathOrId);
2454
2070
  }
2455
2071
  /**
2456
2072
  * Retrieves the metadata of a file in the virtual file system (VFS).
@@ -2459,7 +2075,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2459
2075
  * @returns The metadata of the file, or undefined if the file does not exist.
2460
2076
  */
2461
2077
  getMetadata(pathOrId) {
2462
- const resolved = this.resolve(pathOrId);
2078
+ const resolved = this.resolveSync(pathOrId);
2463
2079
  if (resolved && this.metadata[resolved]) {
2464
2080
  return this.metadata[resolved];
2465
2081
  }
@@ -2475,7 +2091,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2475
2091
  * @returns `true` if the file exists, otherwise `false`.
2476
2092
  */
2477
2093
  isFile(pathOrId) {
2478
- const resolved = this.resolve(pathOrId);
2094
+ const resolved = this.resolveSync(pathOrId);
2479
2095
  return !!(resolved && (this.#unifiedFS.virtual.existsSync(resolved) && this.#unifiedFS.virtual.lstatSync(resolved).isFile() || this.#unifiedFS.physical.existsSync(resolved) && this.#unifiedFS.physical.lstatSync(resolved).isFile() || this.#unifiedFS.resolveFS(resolved).existsSync(resolved) && this.#unifiedFS.resolveFS(resolved).lstatSync(resolved).isFile()));
2480
2096
  }
2481
2097
  /**
@@ -2485,7 +2101,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2485
2101
  * @returns `true` if the directory exists, otherwise `false`.
2486
2102
  */
2487
2103
  isDirectory(pathOrId) {
2488
- const resolved = this.resolve(pathOrId);
2104
+ const resolved = this.resolveSync(pathOrId);
2489
2105
  return !!(resolved && (this.#unifiedFS.virtual.existsSync(resolved) && this.#unifiedFS.virtual.lstatSync(resolved).isDirectory() || this.#unifiedFS.physical.existsSync(resolved) && this.#unifiedFS.physical.lstatSync(resolved).isDirectory() || this.#unifiedFS.resolveFS(resolved).existsSync(resolved) && this.#unifiedFS.resolveFS(resolved).lstatSync(resolved).isDirectory()));
2490
2106
  }
2491
2107
  /**
@@ -2495,7 +2111,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2495
2111
  * @returns A promise that resolves to the file's status information, or false if the file does not exist.
2496
2112
  */
2497
2113
  async stat(pathOrId, options) {
2498
- return this.#unifiedFS.resolveFS(pathOrId).promises.stat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
2114
+ return this.#unifiedFS.resolveFS(pathOrId).promises.stat(await this.resolve(pathOrId) || pathOrId, options);
2499
2115
  }
2500
2116
  /**
2501
2117
  * Synchronously retrieves the status of a file in the virtual file system (VFS).
@@ -2504,7 +2120,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2504
2120
  * @returns The file's status information, or false if the file does not exist.
2505
2121
  */
2506
2122
  statSync(pathOrId) {
2507
- return this.#unifiedFS.resolveFS(pathOrId).statSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId));
2123
+ return this.#unifiedFS.resolveFS(pathOrId).statSync(this.resolveSync(pathOrId) || pathOrId);
2508
2124
  }
2509
2125
  /**
2510
2126
  * Retrieves the status of a symbolic link in the virtual file system (VFS).
@@ -2513,7 +2129,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2513
2129
  * @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
2514
2130
  */
2515
2131
  async lstat(pathOrId, options) {
2516
- return this.#unifiedFS.resolveFS(pathOrId).promises.lstat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
2132
+ return this.#unifiedFS.resolveFS(pathOrId).promises.lstat(await this.resolve(pathOrId) || pathOrId, options);
2517
2133
  }
2518
2134
  /**
2519
2135
  * Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
@@ -2522,7 +2138,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2522
2138
  * @returns The symbolic link's status information, or false if the link does not exist.
2523
2139
  */
2524
2140
  lstatSync(pathOrId, options) {
2525
- return this.#unifiedFS.resolveFS(pathOrId).lstatSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
2141
+ return this.#unifiedFS.resolveFS(pathOrId).lstatSync(this.resolveSync(pathOrId) || pathOrId, options);
2526
2142
  }
2527
2143
  /**
2528
2144
  * Resolves a path or ID to its real path in the virtual file system (VFS).
@@ -2531,52 +2147,113 @@ var VirtualFileSystem = class _VirtualFileSystem {
2531
2147
  * @returns The resolved real path if it exists, otherwise undefined.
2532
2148
  */
2533
2149
  realpathSync(pathOrId) {
2534
- const filePath = this.resolve(toFilePath(pathOrId));
2150
+ const filePath = this.resolveSync(pathOrId);
2535
2151
  if (!filePath) {
2536
- throw new Error(`File not found: ${toFilePath(pathOrId)}`);
2152
+ throw new Error(`File not found: ${pathOrId}`);
2537
2153
  }
2538
2154
  return filePath;
2539
2155
  }
2540
2156
  /**
2541
- * Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
2157
+ * A helper function to resolve modules in the virtual file system (VFS).
2542
2158
  *
2543
- * @param pathOrId - The path or ID to resolve.
2544
- * @param options - Optional parameters for resolving the path, such as whether to include the file extension.
2545
- * @returns The resolved file path if it exists, otherwise undefined.
2546
- */
2547
- resolve(pathOrId, options = {}) {
2548
- const formattedPathOrId = toFilePath(pathOrId);
2549
- const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash(options.paths)}` : ""}${options.pathType ? `-${options.pathType}` : ""}`;
2550
- if (this.#cachedResolver.has(resolverKey)) {
2551
- return this.#cachedResolver.get(resolverKey);
2552
- }
2553
- let result = this.#resolveId(formattedPathOrId);
2554
- if (!result) {
2555
- result = this.#resolvePath(formattedPathOrId, options);
2159
+ * @remarks
2160
+ * This function can be used to resolve modules relative to the project root directory.
2161
+ *
2162
+ * @example
2163
+ * ```ts
2164
+ * const resolved = await context.resolvePath("some-module", "/path/to/importer");
2165
+ * ```
2166
+ *
2167
+ * @param id - The module to resolve.
2168
+ * @param importer - An optional path to the importer module.
2169
+ * @param options - Additional resolution options.
2170
+ * @returns A promise that resolves to the resolved module path.
2171
+ */
2172
+ async resolve(id, importer, options = {}) {
2173
+ let result = this.resolverCache.get(this.#normalizeId(id));
2174
+ if (result) {
2175
+ return result;
2556
2176
  }
2177
+ result = this.paths[this.#normalizeId(id)];
2557
2178
  if (!result) {
2558
- result = false;
2179
+ const paths = options.paths ?? [];
2180
+ if (importer && !paths.includes(importer)) {
2181
+ paths.push(importer);
2182
+ }
2183
+ paths.push(this.#context.workspaceConfig.workspaceRoot);
2184
+ paths.push(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot));
2185
+ paths.push(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, this.#context.config.sourceRoot));
2186
+ paths.push(...Object.keys(this.#context.tsconfig.options.paths ?? {}).filter((tsconfigPath) => id.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
2187
+ for (const combination of getResolutionCombinations(id, {
2188
+ paths
2189
+ })) {
2190
+ if (this.#existsSync(combination)) {
2191
+ result = combination;
2192
+ }
2193
+ }
2194
+ try {
2195
+ result = await resolve(id, {
2196
+ paths
2197
+ });
2198
+ } catch {
2199
+ }
2559
2200
  }
2560
- if (result && options.withExtension === false) {
2561
- return result.replace(/\.[m|c]?[t|j]sx?$/, "");
2201
+ if (result) {
2202
+ result = toAbsolutePath(appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
2203
+ this.resolverCache.set(this.#normalizeId(id), result);
2562
2204
  }
2563
- this.#cachedResolver.set(resolverKey, result);
2564
2205
  return result;
2565
2206
  }
2566
2207
  /**
2567
- * Converts a relative path to an absolute path based on the workspace and project root.
2208
+ * A synchronous helper function to resolve modules using the Jiti resolver
2209
+ *
2210
+ * @remarks
2211
+ * This function can be used to resolve modules relative to the project root directory.
2568
2212
  *
2569
- * @param path - The relative path to convert.
2570
- * @returns The absolute path.
2571
- */
2572
- formatPath(path) {
2573
- const formattedPath = toFilePath(path);
2574
- if (isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
2575
- return formattedPath;
2576
- } else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
2577
- return joinPaths$1(this.#context.workspaceConfig.workspaceRoot, formattedPath);
2213
+ * @example
2214
+ * ```ts
2215
+ * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
2216
+ * ```
2217
+ *
2218
+ * @param id - The module to resolve.
2219
+ * @param importer - An optional path to the importer module.
2220
+ * @param options - Additional resolution options.
2221
+ * @returns The resolved module path.
2222
+ */
2223
+ resolveSync(id, importer, options = {}) {
2224
+ let result = this.resolverCache.get(this.#normalizeId(id));
2225
+ if (result) {
2226
+ return result;
2227
+ }
2228
+ result = this.paths[this.#normalizeId(id)];
2229
+ if (!result) {
2230
+ const paths = options.paths ?? [];
2231
+ if (importer && !paths.includes(importer)) {
2232
+ paths.push(importer);
2233
+ }
2234
+ paths.push(this.#context.workspaceConfig.workspaceRoot);
2235
+ paths.push(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot));
2236
+ paths.push(joinPaths$1(this.#context.workspaceConfig.workspaceRoot, this.#context.config.sourceRoot));
2237
+ paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => id.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
2238
+ for (const combination of getResolutionCombinations(id, {
2239
+ paths
2240
+ })) {
2241
+ if (this.#existsSync(combination)) {
2242
+ result = combination;
2243
+ }
2244
+ }
2245
+ try {
2246
+ result = resolveSync(id, {
2247
+ paths
2248
+ });
2249
+ } catch {
2250
+ }
2578
2251
  }
2579
- return formattedPath;
2252
+ if (result) {
2253
+ result = toAbsolutePath(appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
2254
+ this.resolverCache.set(this.#normalizeId(id), result);
2255
+ }
2256
+ return result;
2580
2257
  }
2581
2258
  /**
2582
2259
  * Disposes of the virtual file system (VFS) by saving its state to disk.
@@ -2585,7 +2262,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2585
2262
  if (!this.#isDisposed) {
2586
2263
  this.#isDisposed = true;
2587
2264
  this.#log(LogLevelLabel.DEBUG, "Disposing virtual file system...");
2588
- await this.unlink(joinPaths$1(this.#context.cachePath, "fs.bin"));
2265
+ await this.unlink(joinPaths$1(this.#context.dataPath, "fs.bin"));
2589
2266
  const message = new $.Message();
2590
2267
  const fs2 = message.initRoot(FileSystem);
2591
2268
  const virtualFS = this.#unifiedFS.toJSON();
@@ -2594,7 +2271,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
2594
2271
  virtualFiles.forEach(([path, code], index) => {
2595
2272
  const fd = files.get(index);
2596
2273
  fd.path = path;
2597
- fd.code = code;
2274
+ fd.code = code || "";
2598
2275
  });
2599
2276
  const ids = fs2._initIds(Object.keys(this.ids).length);
2600
2277
  Object.entries(this.ids).forEach(([id, path], index) => {
@@ -2618,7 +2295,9 @@ var VirtualFileSystem = class _VirtualFileSystem {
2618
2295
  });
2619
2296
  }
2620
2297
  });
2621
- await writeFileBuffer(joinPaths$1(this.#context.cachePath, "fs.bin"), message.toArrayBuffer());
2298
+ await writeFileBuffer(joinPaths$1(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
2299
+ this.#resolverCache.save(true);
2300
+ this.#log(LogLevelLabel.DEBUG, "Virtual file system disposed.");
2622
2301
  }
2623
2302
  }
2624
2303
  /**
@@ -2646,6 +2325,105 @@ var VirtualFileSystem = class _VirtualFileSystem {
2646
2325
  return this.dispose();
2647
2326
  }
2648
2327
  };
2328
+ var VirtualFileSystemHost = class VirtualFileSystemHost2 extends InMemoryFileSystemHost {
2329
+ static {
2330
+ __name(this, "VirtualFileSystemHost");
2331
+ }
2332
+ #fs;
2333
+ constructor(fs2) {
2334
+ super();
2335
+ this.#fs = fs2;
2336
+ }
2337
+ deleteSync(path) {
2338
+ this.#fs.rmSync(path);
2339
+ }
2340
+ readDirSync(dirPath) {
2341
+ return this.#fs.readdirSync(dirPath).reduce((ret, entry) => {
2342
+ const fullPath = this.#fs.resolveSync(joinPaths(dirPath, entry));
2343
+ if (fullPath) {
2344
+ ret.push({
2345
+ name: entry,
2346
+ isDirectory: this.#fs.isDirectory(fullPath),
2347
+ isFile: this.#fs.isFile(fullPath),
2348
+ isSymlink: false
2349
+ });
2350
+ }
2351
+ return ret;
2352
+ }, []);
2353
+ }
2354
+ async readFile(filePath) {
2355
+ if (!this.#fs.existsSync(filePath)) {
2356
+ throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
2357
+ }
2358
+ return await this.#fs.readFile(filePath);
2359
+ }
2360
+ readFileSync(filePath) {
2361
+ if (!this.#fs.existsSync(filePath)) {
2362
+ throw new Error(`File not found: '${filePath}'. Please check the path and try again.`);
2363
+ }
2364
+ return this.#fs.readFileSync(filePath);
2365
+ }
2366
+ async writeFile(filePath, fileText) {
2367
+ return this.#fs.writeFile(filePath, fileText);
2368
+ }
2369
+ writeFileSync(filePath, fileText) {
2370
+ this.#fs.writeFileSync(filePath, fileText);
2371
+ }
2372
+ async mkdir(dirPath) {
2373
+ await this.#fs.mkdir(dirPath);
2374
+ }
2375
+ mkdirSync(dirPath) {
2376
+ this.#fs.mkdirSync(dirPath);
2377
+ }
2378
+ async move(srcPath, destPath) {
2379
+ await this.#fs.move(srcPath, destPath);
2380
+ }
2381
+ moveSync(srcPath, destPath) {
2382
+ this.#fs.moveSync(srcPath, destPath);
2383
+ }
2384
+ async copy(srcPath, destPath) {
2385
+ await this.#fs.copy(srcPath, destPath);
2386
+ }
2387
+ copySync(srcPath, destPath) {
2388
+ this.#fs.copySync(srcPath, destPath);
2389
+ }
2390
+ async fileExists(filePath) {
2391
+ return this.#fs.isFile(filePath);
2392
+ }
2393
+ fileExistsSync(filePath) {
2394
+ return this.#fs.isFile(filePath);
2395
+ }
2396
+ async directoryExists(dirPath) {
2397
+ return this.#fs.isDirectory(dirPath);
2398
+ }
2399
+ directoryExistsSync(dirPath) {
2400
+ return this.#fs.isDirectory(dirPath);
2401
+ }
2402
+ realpathSync(path) {
2403
+ return this.#fs.resolveSync(path) || path;
2404
+ }
2405
+ getCurrentDirectory() {
2406
+ return "/";
2407
+ }
2408
+ async glob(patterns) {
2409
+ return this.#fs.glob(patterns);
2410
+ }
2411
+ globSync(patterns) {
2412
+ return this.#fs.globSync(patterns);
2413
+ }
2414
+ };
2415
+ function createProgram(context, override) {
2416
+ const project = new Project({
2417
+ compilerOptions: {
2418
+ ...context.tsconfig.options
2419
+ },
2420
+ tsConfigFilePath: context.tsconfig.tsconfigFilePath,
2421
+ fileSystem: new VirtualFileSystemHost(context.fs),
2422
+ ...override
2423
+ });
2424
+ return project;
2425
+ }
2426
+ __name(createProgram, "createProgram");
2649
2427
  var PROJECT_ROOT_HASH_LENGTH = 45;
2650
2428
  var CACHE_HASH_LENGTH = 62;
2651
2429
  function getPrefixedProjectRootHash(name, projectRootHash) {
@@ -2682,6 +2460,8 @@ var PowerlinesContext = class _PowerlinesContext {
2682
2460
  #envPaths;
2683
2461
  #fs;
2684
2462
  #tsconfig;
2463
+ #program;
2464
+ #resolvePatterns = [];
2685
2465
  #getConfigProps(config = {}) {
2686
2466
  return {
2687
2467
  variant: config.build?.variant,
@@ -2773,7 +2553,7 @@ var PowerlinesContext = class _PowerlinesContext {
2773
2553
  */
2774
2554
  get tsconfig() {
2775
2555
  if (!this.#tsconfig) {
2776
- this.#tsconfig = {
2556
+ this.tsconfig = {
2777
2557
  tsconfigFilePath: this.config.tsconfig
2778
2558
  };
2779
2559
  }
@@ -2784,6 +2564,7 @@ var PowerlinesContext = class _PowerlinesContext {
2784
2564
  */
2785
2565
  set tsconfig(value) {
2786
2566
  this.#tsconfig = value;
2567
+ this.#resolvePatterns = tsconfigPathsToRegExp(value?.options?.paths ?? {});
2787
2568
  }
2788
2569
  /**
2789
2570
  * The virtual file system interface for the project
@@ -2908,6 +2689,106 @@ var PowerlinesContext = class _PowerlinesContext {
2908
2689
  return Object.values(this.fs.metadata).filter((meta) => meta && meta.type === "builtin").map((meta) => meta?.id).filter(Boolean);
2909
2690
  }
2910
2691
  /**
2692
+ * The {@link Project} instance used for type reflection and module manipulation
2693
+ *
2694
+ * @see https://ts-morph.com/
2695
+ *
2696
+ * @remarks
2697
+ * This instance is created lazily on first access.
2698
+ */
2699
+ get program() {
2700
+ if (!this.#program) {
2701
+ this.#program = createProgram(this, {
2702
+ skipAddingFilesFromTsConfig: true
2703
+ });
2704
+ }
2705
+ return this.#program;
2706
+ }
2707
+ /**
2708
+ * A helper function to resolve modules in the Virtual File System
2709
+ *
2710
+ * @remarks
2711
+ * This function can be used to resolve modules relative to the project root directory.
2712
+ *
2713
+ * @example
2714
+ * ```ts
2715
+ * const resolved = await context.resolve("some-module", "/path/to/importer");
2716
+ * ```
2717
+ *
2718
+ * @param id - The module to resolve.
2719
+ * @param importer - An optional path to the importer module.
2720
+ * @param options - Additional resolution options.
2721
+ * @returns A promise that resolves to the resolved module path.
2722
+ */
2723
+ async resolveId(id, importer, options = {}) {
2724
+ if (this.fs.isVirtual(id)) {
2725
+ const result = await this.fs.resolve(id, importer, options);
2726
+ if (!result) {
2727
+ return void 0;
2728
+ }
2729
+ return {
2730
+ id: `\0${result}`,
2731
+ external: this.config.projectType !== "application"
2732
+ };
2733
+ }
2734
+ if (this.config.build.skipNodeModulesBundle) {
2735
+ if (match(id, this.#resolvePatterns) || match(id, this.config.build.noExternal)) {
2736
+ return void 0;
2737
+ }
2738
+ if (match(id, this.config.build.external) || id.startsWith("node:")) {
2739
+ return {
2740
+ id,
2741
+ external: true
2742
+ };
2743
+ }
2744
+ if (!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(id)) {
2745
+ return {
2746
+ id,
2747
+ external: true
2748
+ };
2749
+ }
2750
+ } else {
2751
+ if (match(id, this.config.build.noExternal)) {
2752
+ return void 0;
2753
+ }
2754
+ if (match(id, this.config.build.external) || id.startsWith("node:")) {
2755
+ return {
2756
+ id,
2757
+ external: true
2758
+ };
2759
+ }
2760
+ }
2761
+ return void 0;
2762
+ }
2763
+ /**
2764
+ * A helper function to load modules from the Virtual File System
2765
+ *
2766
+ * @remarks
2767
+ * This function can be used to load modules relative to the project root directory.
2768
+ *
2769
+ * @example
2770
+ * ```ts
2771
+ * const module = await context.load("some-module", "/path/to/importer");
2772
+ * ```
2773
+ *
2774
+ * @param id - The module to load.
2775
+ * @returns A promise that resolves to the loaded module.
2776
+ */
2777
+ async load(id) {
2778
+ const resolvedId = await this.fs.resolve(id);
2779
+ if (!resolvedId) {
2780
+ return void 0;
2781
+ }
2782
+ const code = await this.fs.readFile(resolvedId);
2783
+ if (!code) {
2784
+ return void 0;
2785
+ }
2786
+ return {
2787
+ code,
2788
+ map: null
2789
+ };
2790
+ }
2791
+ /**
2911
2792
  * Get the builtin virtual files that exist in the Powerlines virtual file system
2912
2793
  */
2913
2794
  async getBuiltins() {
@@ -3130,6 +3011,7 @@ var PowerlinesContext = class _PowerlinesContext {
3130
3011
  projectRoot: cacheKey.projectRoot,
3131
3012
  cacheDir: this.cachePath,
3132
3013
  mode: cacheKey.mode,
3014
+ logLevel: config.logLevel || this.config?.logLevel || this.workspaceConfig.logLevel || "info",
3133
3015
  skipCache: cacheKey.skipCache
3134
3016
  });
3135
3017
  const userConfig = await loadUserConfigFile(cacheKey.projectRoot, this.workspaceConfig.workspaceRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile, cacheKey.framework);
@@ -3243,6 +3125,24 @@ var PowerlinesContext = class _PowerlinesContext {
3243
3125
  ret.push(plugin);
3244
3126
  return ret;
3245
3127
  }, []);
3128
+ if (this.config.tsconfig) {
3129
+ this.config.tsconfig = replacePathTokens(this, this.config.tsconfig);
3130
+ }
3131
+ if (this.config.output.dts) {
3132
+ this.config.output.dts = replacePathTokens(this, this.config.output.dts);
3133
+ }
3134
+ if (this.config.build.polyfill) {
3135
+ this.config.build.polyfill = this.config.build.polyfill.map((polyfill) => replacePathTokens(this, polyfill));
3136
+ }
3137
+ if (this.config.output.assets) {
3138
+ this.config.output.assets = this.config.output.assets.map((asset) => ({
3139
+ ...asset,
3140
+ glob: replacePathTokens(this, asset.glob),
3141
+ ignore: asset.ignore ? asset.ignore.map((ignore) => replacePathTokens(this, ignore)) : void 0,
3142
+ input: replacePathTokens(this, asset.input),
3143
+ output: replacePathTokens(this, asset.output)
3144
+ }));
3145
+ }
3246
3146
  this.#fs ??= await VirtualFileSystem.create(this);
3247
3147
  }
3248
3148
  mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
@@ -3663,13 +3563,9 @@ ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.outpu
3663
3563
  await resolveTsconfig(context);
3664
3564
  await installDependencies(context);
3665
3565
  await this.callPostHook(context, "configResolved");
3666
- if (context.config.build.polyfill) {
3667
- context.config.build.polyfill = context.config.build.polyfill.map((polyfill) => replacePathTokens(context, polyfill));
3668
- }
3669
3566
  context.log(LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
3670
3567
 
3671
3568
  ${formatLogMessage(context.config)}`);
3672
- context.fs[__VFS_PATCH__]();
3673
3569
  await writeMetaFile(context);
3674
3570
  context.persistedMeta = context.meta;
3675
3571
  if (!existsSync(context.cachePath)) {
@@ -3719,35 +3615,19 @@ ${formatLogMessage(context.config)}`);
3719
3615
  if (!typescriptPath) {
3720
3616
  throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
3721
3617
  }
3722
- const files = builtinFilePaths.reduce((ret, fileName) => {
3723
- const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
3724
- if (!ret.includes(formatted)) {
3725
- ret.push(formatted);
3726
- }
3727
- return ret;
3728
- }, [
3729
- joinPaths$1(typescriptPath, "lib", "lib.esnext.full.d.ts")
3730
- ]);
3731
- context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
3732
- const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu6({
3733
- compilerOptions: {
3734
- strict: false,
3735
- noEmit: false,
3736
- declaration: true,
3737
- declarationMap: false,
3738
- emitDeclarationOnly: true,
3739
- skipLibCheck: true
3618
+ const files = builtinFilePaths.reduce(
3619
+ (ret, fileName) => {
3620
+ const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
3621
+ if (!ret.includes(formatted)) {
3622
+ ret.push(formatted);
3623
+ }
3624
+ return ret;
3740
3625
  },
3741
- exclude: [
3742
- "node_modules",
3743
- "dist"
3744
- ],
3745
- include: files
3746
- }, context.config.tsconfigRaw ?? {}));
3747
- resolvedTsconfig.options.configFilePath = joinPaths$1(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
3748
- resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
3749
- resolvedTsconfig.options.suppressOutputPathCheck = true;
3750
- let generatedTypes = await emitTypes(context, resolvedTsconfig, files);
3626
+ []
3627
+ // [joinPaths(typescriptPath, "lib", "lib.esnext.full.d.ts")]
3628
+ );
3629
+ context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
3630
+ let generatedTypes = await emitTypes(context, files);
3751
3631
  context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file in ${context.config.output.dts}.`);
3752
3632
  const directives = [];
3753
3633
  let result = await this.callPreHook(context, "generateTypes", generatedTypes);
@@ -3801,7 +3681,6 @@ ${formatTypes(generatedTypes)}
3801
3681
  }
3802
3682
  await this.callPostHook(context, "prepare");
3803
3683
  await writeMetaFile(context);
3804
- context.fs[__VFS_REVERT__]();
3805
3684
  });
3806
3685
  this.context.log(LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
3807
3686
  }
@@ -4240,4 +4119,4 @@ Note: Please ensure the plugin package's default export is a class that extends
4240
4119
  }
4241
4120
  };
4242
4121
 
4243
- export { AssetData, ChunkData, FileData, FileId, FileMetadata, FileMetadata_KeyValuePair, FileSystem, FileType, PowerlinesAPI, PrebuiltData, PreserveSignatureType, _capnpFileId, createLog, extendLog };
4122
+ export { FileData, FileId, FileMetadata, FileMetadata_KeyValuePair, FileSystem, FileType, PowerlinesAPI, PreserveSignatureType, _capnpFileId, createLog, extendLog };