@powerlines/nx 0.11.268 → 0.11.270

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 (202) hide show
  1. package/README.md +29 -31
  2. package/dist/src/base/base-executor.d.mts +1 -1
  3. package/dist/src/base/base-executor.d.ts +1 -1
  4. package/dist/src/base/base-executor.js +78 -3
  5. package/dist/src/base/base-executor.mjs +75 -3
  6. package/dist/src/base/base-executor.mjs.map +1 -0
  7. package/dist/src/base/base-executor.schema.d.mts +117 -2
  8. package/dist/src/base/base-executor.schema.d.mts.map +1 -0
  9. package/dist/src/base/base-executor.schema.d.ts +117 -2
  10. package/dist/src/base/base-executor.schema.d.ts.map +1 -0
  11. package/dist/src/base/base-executor.untyped.d.mts +1 -1
  12. package/dist/src/base/base-executor.untyped.d.ts +1 -1
  13. package/dist/src/base/base-executor.untyped.js +135 -2
  14. package/dist/src/base/base-executor.untyped.mjs +135 -2
  15. package/dist/src/base/base-executor.untyped.mjs.map +1 -0
  16. package/dist/src/base/index.d.mts +1 -3
  17. package/dist/src/base/index.d.ts +1 -1
  18. package/dist/src/base/index.js +4 -5
  19. package/dist/src/base/index.mjs +2 -4
  20. package/dist/src/base-executor-Bj63x9OE.d.ts +28 -0
  21. package/dist/src/base-executor-Bj63x9OE.d.ts.map +1 -0
  22. package/dist/src/base-executor-D6POztG2.d.mts +28 -0
  23. package/dist/src/base-executor-D6POztG2.d.mts.map +1 -0
  24. package/dist/src/base-executor.untyped-D4R6pki2.d.ts +7 -0
  25. package/dist/src/base-executor.untyped-D4R6pki2.d.ts.map +1 -0
  26. package/dist/src/base-executor.untyped-hmlG6oyC.d.mts +7 -0
  27. package/dist/src/base-executor.untyped-hmlG6oyC.d.mts.map +1 -0
  28. package/dist/src/chunk-BE-pF4vm.js +34 -0
  29. package/dist/src/{constants-BvODbBl8.d.ts → constants-CbG11Mby.d.ts} +1 -1
  30. package/dist/src/constants-CbG11Mby.d.ts.map +1 -0
  31. package/dist/src/{constants-ByputsG8.d.mts → constants-VDvVnoLC.d.mts} +1 -1
  32. package/dist/src/constants-VDvVnoLC.d.mts.map +1 -0
  33. package/dist/src/executors/build/executor.d.mts +2 -16
  34. package/dist/src/executors/build/executor.d.mts.map +1 -1
  35. package/dist/src/executors/build/executor.d.ts +2 -16
  36. package/dist/src/executors/build/executor.d.ts.map +1 -1
  37. package/dist/src/executors/build/executor.js +6 -7
  38. package/dist/src/executors/build/executor.mjs +4 -6
  39. package/dist/src/executors/build/executor.mjs.map +1 -1
  40. package/dist/src/executors/build/untyped.d.mts +2 -2
  41. package/dist/src/executors/build/untyped.d.mts.map +1 -1
  42. package/dist/src/executors/build/untyped.d.ts +2 -2
  43. package/dist/src/executors/build/untyped.d.ts.map +1 -1
  44. package/dist/src/executors/build/untyped.js +3 -4
  45. package/dist/src/executors/build/untyped.mjs +1 -2
  46. package/dist/src/executors/build/untyped.mjs.map +1 -1
  47. package/dist/src/executors/clean/executor.d.mts +2 -13
  48. package/dist/src/executors/clean/executor.d.mts.map +1 -1
  49. package/dist/src/executors/clean/executor.d.ts +2 -13
  50. package/dist/src/executors/clean/executor.d.ts.map +1 -1
  51. package/dist/src/executors/clean/executor.js +4 -6
  52. package/dist/src/executors/clean/executor.mjs +2 -4
  53. package/dist/src/executors/clean/executor.mjs.map +1 -1
  54. package/dist/src/executors/clean/untyped.d.mts +2 -2
  55. package/dist/src/executors/clean/untyped.d.mts.map +1 -1
  56. package/dist/src/executors/clean/untyped.d.ts +2 -2
  57. package/dist/src/executors/clean/untyped.d.ts.map +1 -1
  58. package/dist/src/executors/clean/untyped.js +3 -3
  59. package/dist/src/executors/clean/untyped.mjs +1 -1
  60. package/dist/src/executors/docs/executor.d.mts +2 -15
  61. package/dist/src/executors/docs/executor.d.mts.map +1 -1
  62. package/dist/src/executors/docs/executor.d.ts +2 -15
  63. package/dist/src/executors/docs/executor.d.ts.map +1 -1
  64. package/dist/src/executors/docs/executor.js +4 -6
  65. package/dist/src/executors/docs/executor.mjs +2 -4
  66. package/dist/src/executors/docs/executor.mjs.map +1 -1
  67. package/dist/src/executors/docs/untyped.d.mts +2 -2
  68. package/dist/src/executors/docs/untyped.d.mts.map +1 -1
  69. package/dist/src/executors/docs/untyped.d.ts +2 -2
  70. package/dist/src/executors/docs/untyped.d.ts.map +1 -1
  71. package/dist/src/executors/docs/untyped.js +3 -4
  72. package/dist/src/executors/docs/untyped.mjs +1 -2
  73. package/dist/src/executors/docs/untyped.mjs.map +1 -1
  74. package/dist/src/executors/lint/executor.d.mts +2 -15
  75. package/dist/src/executors/lint/executor.d.mts.map +1 -1
  76. package/dist/src/executors/lint/executor.d.ts +2 -15
  77. package/dist/src/executors/lint/executor.d.ts.map +1 -1
  78. package/dist/src/executors/lint/executor.js +4 -6
  79. package/dist/src/executors/lint/executor.mjs +2 -4
  80. package/dist/src/executors/lint/executor.mjs.map +1 -1
  81. package/dist/src/executors/lint/untyped.d.mts +2 -2
  82. package/dist/src/executors/lint/untyped.d.mts.map +1 -1
  83. package/dist/src/executors/lint/untyped.d.ts +2 -2
  84. package/dist/src/executors/lint/untyped.d.ts.map +1 -1
  85. package/dist/src/executors/lint/untyped.js +3 -4
  86. package/dist/src/executors/lint/untyped.mjs +1 -2
  87. package/dist/src/executors/lint/untyped.mjs.map +1 -1
  88. package/dist/src/executors/prepare/executor.d.mts +2 -15
  89. package/dist/src/executors/prepare/executor.d.mts.map +1 -1
  90. package/dist/src/executors/prepare/executor.d.ts +2 -15
  91. package/dist/src/executors/prepare/executor.d.ts.map +1 -1
  92. package/dist/src/executors/prepare/executor.js +6 -7
  93. package/dist/src/executors/prepare/executor.mjs +4 -6
  94. package/dist/src/executors/prepare/executor.mjs.map +1 -1
  95. package/dist/src/executors/prepare/untyped.d.mts +2 -2
  96. package/dist/src/executors/prepare/untyped.d.mts.map +1 -1
  97. package/dist/src/executors/prepare/untyped.d.ts +2 -2
  98. package/dist/src/executors/prepare/untyped.d.ts.map +1 -1
  99. package/dist/src/executors/prepare/untyped.js +26 -3
  100. package/dist/src/executors/prepare/untyped.mjs +26 -3
  101. package/dist/src/executors/prepare/untyped.mjs.map +1 -0
  102. package/dist/src/generators/sync/generator.d.mts.map +1 -1
  103. package/dist/src/generators/sync/generator.d.ts.map +1 -1
  104. package/dist/src/generators/sync/generator.js +5 -6
  105. package/dist/src/generators/sync/generator.mjs +1 -2
  106. package/dist/src/generators/sync/generator.mjs.map +1 -1
  107. package/dist/src/generators/sync/untyped.d.mts +2 -2
  108. package/dist/src/generators/sync/untyped.d.mts.map +1 -1
  109. package/dist/src/generators/sync/untyped.d.ts +2 -2
  110. package/dist/src/generators/sync/untyped.d.ts.map +1 -1
  111. package/dist/src/generators/sync/untyped.js +1 -1
  112. package/dist/src/helpers/constants.d.mts +1 -1
  113. package/dist/src/helpers/constants.d.ts +1 -1
  114. package/dist/src/helpers/constants.js +34 -2
  115. package/dist/src/helpers/constants.mjs +33 -2
  116. package/dist/src/helpers/constants.mjs.map +1 -0
  117. package/dist/src/helpers/index.d.mts +2 -3
  118. package/dist/src/helpers/index.d.ts +2 -2
  119. package/dist/src/helpers/index.js +7 -8
  120. package/dist/src/helpers/index.mjs +2 -4
  121. package/dist/src/helpers/plugin-utilities.d.mts +1 -1
  122. package/dist/src/helpers/plugin-utilities.d.ts +1 -1
  123. package/dist/src/helpers/plugin-utilities.js +274 -5
  124. package/dist/src/helpers/plugin-utilities.mjs +270 -3
  125. package/dist/src/helpers/plugin-utilities.mjs.map +1 -0
  126. package/dist/src/index.d.mts +4 -7
  127. package/dist/src/index.d.ts +4 -4
  128. package/dist/src/index.js +11 -12
  129. package/dist/src/index.mjs +5 -7
  130. package/dist/src/plugin/index.d.mts +1 -1
  131. package/dist/src/plugin/index.d.mts.map +1 -1
  132. package/dist/src/plugin/index.d.ts +1 -1
  133. package/dist/src/plugin/index.d.ts.map +1 -1
  134. package/dist/src/plugin/index.js +3 -3
  135. package/dist/src/plugin/index.mjs +1 -2
  136. package/dist/src/plugin/index.mjs.map +1 -1
  137. package/dist/src/{plugin-DIj3oU64.d.mts → plugin-B_ZGdX7U.d.mts} +1 -1
  138. package/dist/src/plugin-B_ZGdX7U.d.mts.map +1 -0
  139. package/dist/src/{plugin-DN475itb.d.ts → plugin-DpyutMl2.d.ts} +1 -1
  140. package/dist/src/plugin-DpyutMl2.d.ts.map +1 -0
  141. package/dist/src/{plugin-utilities-Bz3Muyag.d.mts → plugin-utilities-Cg-Ccp4C.d.mts} +2 -3
  142. package/dist/src/plugin-utilities-Cg-Ccp4C.d.mts.map +1 -0
  143. package/dist/src/{plugin-utilities-CeMy-9YQ.d.ts → plugin-utilities-CmfuC3TZ.d.ts} +2 -3
  144. package/dist/src/plugin-utilities-CmfuC3TZ.d.ts.map +1 -0
  145. package/dist/src/types/index.d.mts +1 -1
  146. package/dist/src/types/index.d.ts +1 -1
  147. package/dist/src/types/plugin.d.mts +1 -1
  148. package/dist/src/types/plugin.d.ts +1 -1
  149. package/package.json +4 -4
  150. package/dist/src/base-B7jekb-W.js +0 -0
  151. package/dist/src/base-BRSa-clf.mjs +0 -1
  152. package/dist/src/base-executor-BY0qdmfF.js +0 -4881
  153. package/dist/src/base-executor-CC8rBACl.mjs +0 -4863
  154. package/dist/src/base-executor-CC8rBACl.mjs.map +0 -1
  155. package/dist/src/base-executor-CWToCKgJ.d.ts +0 -2195
  156. package/dist/src/base-executor-CWToCKgJ.d.ts.map +0 -1
  157. package/dist/src/base-executor-Cc27ehGx.js +0 -4881
  158. package/dist/src/base-executor-PhChSWwR.mjs +0 -4863
  159. package/dist/src/base-executor-PhChSWwR.mjs.map +0 -1
  160. package/dist/src/base-executor-xsZuLKpp.d.mts +0 -2197
  161. package/dist/src/base-executor-xsZuLKpp.d.mts.map +0 -1
  162. package/dist/src/base-executor.schema-BaaDD_VU.d.ts +0 -130
  163. package/dist/src/base-executor.schema-BaaDD_VU.d.ts.map +0 -1
  164. package/dist/src/base-executor.schema-CYPLsYvI.d.mts +0 -130
  165. package/dist/src/base-executor.schema-CYPLsYvI.d.mts.map +0 -1
  166. package/dist/src/base-executor.untyped-B24q82iI.d.ts +0 -7
  167. package/dist/src/base-executor.untyped-B24q82iI.d.ts.map +0 -1
  168. package/dist/src/base-executor.untyped-C1pQETnQ.mjs +0 -136
  169. package/dist/src/base-executor.untyped-C1pQETnQ.mjs.map +0 -1
  170. package/dist/src/base-executor.untyped-Cz1Zw_02.js +0 -141
  171. package/dist/src/base-executor.untyped-DBccuF6E.d.ts +0 -7
  172. package/dist/src/base-executor.untyped-DBccuF6E.d.ts.map +0 -1
  173. package/dist/src/base-executor.untyped-imww7Gm9.d.mts +0 -7
  174. package/dist/src/base-executor.untyped-imww7Gm9.d.mts.map +0 -1
  175. package/dist/src/config-CGQhS8tm.js +0 -239
  176. package/dist/src/config-LoR-NIJg.mjs +0 -147
  177. package/dist/src/config-LoR-NIJg.mjs.map +0 -1
  178. package/dist/src/constants-BvODbBl8.d.ts.map +0 -1
  179. package/dist/src/constants-ByputsG8.d.mts.map +0 -1
  180. package/dist/src/constants-CKuImMYn.js +0 -39
  181. package/dist/src/constants-DzvoYj5w.mjs +0 -34
  182. package/dist/src/constants-DzvoYj5w.mjs.map +0 -1
  183. package/dist/src/helpers-B78f0Oey.js +0 -0
  184. package/dist/src/helpers-j01T2doK.mjs +0 -1
  185. package/dist/src/index-7rWKHdox.d.mts +0 -1
  186. package/dist/src/index-CB5PSF-Q.d.ts +0 -1
  187. package/dist/src/index-CDDzqahH.d.ts +0 -1
  188. package/dist/src/index-CsuikFeJ.d.mts +0 -1
  189. package/dist/src/index-LhFpnU-f.d.mts +0 -1
  190. package/dist/src/index-g0mugXoV.d.ts +0 -1
  191. package/dist/src/plugin-BnaFlFmT.js +0 -0
  192. package/dist/src/plugin-DIj3oU64.d.mts.map +0 -1
  193. package/dist/src/plugin-DN475itb.d.ts.map +0 -1
  194. package/dist/src/plugin-DRjpXVSI.mjs +0 -1
  195. package/dist/src/plugin-utilities-ByTgFCEW.js +0 -287
  196. package/dist/src/plugin-utilities-Bz3Muyag.d.mts.map +0 -1
  197. package/dist/src/plugin-utilities-CeMy-9YQ.d.ts.map +0 -1
  198. package/dist/src/plugin-utilities-DamtoOxO.mjs +0 -270
  199. package/dist/src/plugin-utilities-DamtoOxO.mjs.map +0 -1
  200. package/dist/src/untyped-BzuygGwJ.mjs +0 -27
  201. package/dist/src/untyped-BzuygGwJ.mjs.map +0 -1
  202. package/dist/src/untyped-CB-jtwm-.js +0 -32
@@ -1,4863 +0,0 @@
1
- import { a as DEFAULT_ENVIRONMENT, c as PLUGIN_HOOKS_FIELDS, i as ROOT_HASH_LENGTH, l as PLUGIN_NON_HOOK_FIELDS, n as loadWorkspaceConfig, o as GLOBAL_ENVIRONMENT, r as CACHE_HASH_LENGTH, s as BUILDER_VARIANTS, t as loadUserConfigFile, u as UNPLUGIN_BUILDER_VARIANTS } from "./config-LoR-NIJg.mjs";
2
- import { getLogFn, getLogLevel, writeError } from "@storm-software/config-tools/logger";
3
- import { withRunExecutor } from "@storm-software/workspace-tools/base/base-executor";
4
- import { isError } from "@stryke/type-checks/is-error";
5
- import defu$1, { createDefu, defu } from "defu";
6
- import { relativeToWorkspaceRoot } from "@stryke/fs/get-workspace-root";
7
- import { formatLogMessage } from "@storm-software/config-tools/logger/console";
8
- import { toArray } from "@stryke/convert/to-array";
9
- import { createDirectory, createDirectorySync } from "@stryke/fs/helpers";
10
- import { install } from "@stryke/fs/install";
11
- import { listFiles, listFilesSync } from "@stryke/fs/list-files";
12
- import { doesPackageMatch, getPackageListing, isPackageExists, isPackageListed } from "@stryke/fs/package-fns";
13
- import { getResolutionCombinations, resolve, resolvePackage, resolveSync } from "@stryke/fs/resolve";
14
- import { omit } from "@stryke/helpers/omit";
15
- import { appendPath } from "@stryke/path/append";
16
- import { joinPaths } from "@stryke/path/join-paths";
17
- import { replaceExtension, replacePath } from "@stryke/path/replace";
18
- import { isFunction } from "@stryke/type-checks/is-function";
19
- import { isNumber } from "@stryke/type-checks/is-number";
20
- import { isObject } from "@stryke/type-checks/is-object";
21
- import { isPromiseLike } from "@stryke/type-checks/is-promise";
22
- import { isSet } from "@stryke/type-checks/is-set";
23
- import { isSetObject } from "@stryke/type-checks/is-set-object";
24
- import { isSetString } from "@stryke/type-checks/is-set-string";
25
- import { isString } from "@stryke/type-checks/is-string";
26
- import chalk from "chalk";
27
- import Handlebars from "handlebars";
28
- import { findFileDotExtensionSafe, findFileExtensionSafe, findFileName, findFilePath, hasFileExtension, relativePath } from "@stryke/path/file-path-fns";
29
- import { isParentPath } from "@stryke/path/is-parent-path";
30
- import { prettyBytes } from "@stryke/string-format/pretty-bytes";
31
- import { DiagnosticCategory, InMemoryFileSystemHost, Project } from "ts-morph";
32
- import { getUnique, getUniqueBy } from "@stryke/helpers/get-unique";
33
- import { isRegExp } from "@stryke/type-checks/is-regexp";
34
- import { isUndefined } from "@stryke/type-checks/is-undefined";
35
- import { joinPaths as joinPaths$1 } from "@stryke/path/join";
36
- import { format, resolveConfig } from "prettier";
37
- import { unlinkSync } from "node:fs";
38
- import { getPackageName, getPackageVersion, hasPackageVersion } from "@stryke/string-format/package";
39
- import { exists, existsSync } from "@stryke/fs/exists";
40
- import { readJsonFile, readJsonFileSync } from "@stryke/fs/json";
41
- import "@stryke/fs/remove-file";
42
- import { kebabCase } from "@stryke/string-format/kebab-case";
43
- import { getObjectDiff } from "@donedeal0/superdiff";
44
- import { StormJSON } from "@stryke/json/storm-json";
45
- import { titleCase } from "@stryke/string-format/title-case";
46
- import ts from "typescript";
47
- import { LogLevelLabel } from "@storm-software/config-tools/types";
48
- import { getEnvPaths } from "@stryke/env/get-env-paths";
49
- import { murmurhash } from "@stryke/hash";
50
- import { hashDirectory } from "@stryke/hash/node";
51
- import { fetchRequest } from "@stryke/http/fetch";
52
- import { isNull } from "@stryke/type-checks/is-null";
53
- import { uuid } from "@stryke/unique-id/uuid";
54
- import { match, tsconfigPathsToRegExp } from "bundle-require";
55
- import { resolveCompatibilityDates } from "compatx";
56
- import { create } from "flat-cache";
57
- import { parse } from "oxc-parser";
58
- import { Agent, Response, interceptors, setGlobalDispatcher } from "undici";
59
- import { createJiti } from "jiti";
60
- import * as $ from "@stryke/capnp";
61
- import { readFileBuffer, readFileBufferSync, writeFileBuffer } from "@stryke/fs/buffer";
62
- import { correctPath, stripStars } from "@stryke/path/correct-path";
63
- import { globToRegex } from "@stryke/path/glob-to-regex";
64
- import { isAbsolutePath } from "@stryke/path/is-type";
65
- import { slash } from "@stryke/path/slash";
66
- import { Blob as Blob$1 } from "node:buffer";
67
- import { fileURLToPath } from "node:url";
68
- import { ResolverFactory } from "oxc-resolver";
69
- import { isDirectory, isFile } from "@stryke/fs/is-file";
70
- import { readFile, readFileSync } from "@stryke/fs/read-file";
71
- import { writeFile, writeFileSync } from "@stryke/fs/write-file";
72
- import { unlink } from "node:fs/promises";
73
- import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
74
- import { getColor } from "@storm-software/config-tools/utilities/colors";
75
- import { noop } from "@stryke/helpers/noop";
76
- import "magic-string";
77
- import Diff from "diff-match-patch";
78
- import { resolve as resolve$1 } from "node:path";
79
- import "unplugin";
80
-
81
- //#region ../powerlines/package.json
82
- var version = "0.41.4";
83
-
84
- //#endregion
85
- //#region ../powerlines/src/typescript/ts-morph.ts
86
- var VirtualFileSystemHost = class extends InMemoryFileSystemHost {
87
- #context;
88
- constructor(context) {
89
- super();
90
- this.#context = context;
91
- }
92
- deleteSync(path) {
93
- this.#context.fs.removeSync(path);
94
- }
95
- readDirSync(dirPath) {
96
- if (!this.#context.fs.isDirectorySync(dirPath)) return [];
97
- return this.#context.fs.listSync(dirPath).reduce((ret, entry) => {
98
- const fullPath = this.#context.fs.resolveSync(entry);
99
- if (fullPath) ret.push({
100
- name: entry,
101
- isDirectory: this.#context.fs.isDirectorySync(fullPath),
102
- isFile: this.#context.fs.isFileSync(fullPath),
103
- isSymlink: false
104
- });
105
- return ret;
106
- }, []);
107
- }
108
- async readFile(filePath) {
109
- if (!this.#context.fs.isFileSync(filePath)) return "";
110
- return await this.#context.fs.read(filePath);
111
- }
112
- readFileSync(filePath) {
113
- if (!this.#context.fs.isFileSync(filePath)) return "";
114
- return this.#context.fs.readSync(filePath);
115
- }
116
- async writeFile(filePath, fileText) {
117
- return this.#context.fs.write(filePath, fileText);
118
- }
119
- writeFileSync(filePath, fileText) {
120
- this.#context.fs.writeSync(filePath, fileText);
121
- }
122
- async mkdir(dirPath) {
123
- await this.#context.fs.mkdir(dirPath);
124
- }
125
- mkdirSync(dirPath) {
126
- this.#context.fs.mkdirSync(dirPath);
127
- }
128
- async move(srcPath, destPath) {
129
- await this.#context.fs.move(srcPath, destPath);
130
- }
131
- moveSync(srcPath, destPath) {
132
- this.#context.fs.moveSync(srcPath, destPath);
133
- }
134
- async copy(srcPath, destPath) {
135
- await this.#context.fs.copy(srcPath, destPath);
136
- }
137
- copySync(srcPath, destPath) {
138
- this.#context.fs.copySync(srcPath, destPath);
139
- }
140
- async fileExists(filePath) {
141
- return this.#context.fs.isFile(filePath);
142
- }
143
- fileExistsSync(filePath) {
144
- return this.#context.fs.isFileSync(filePath);
145
- }
146
- async directoryExists(dirPath) {
147
- return this.#context.fs.isDirectory(dirPath);
148
- }
149
- directoryExistsSync(dirPath) {
150
- return this.#context.fs.isDirectorySync(dirPath);
151
- }
152
- realpathSync(path) {
153
- return this.#context.fs.resolveSync(path) || path;
154
- }
155
- getCurrentDirectory() {
156
- return this.#context.workspaceConfig.workspaceRoot;
157
- }
158
- async glob(patterns) {
159
- return this.#context.fs.glob(patterns);
160
- }
161
- globSync(patterns) {
162
- return this.#context.fs.globSync(patterns);
163
- }
164
- };
165
- /**
166
- * Create a ts-morph {@link Project} instance used for type reflection and module manipulation during processing
167
- *
168
- * @param context - The Powerlines context
169
- * @returns A ts-morph {@link Project} instance
170
- */
171
- function createProgram(context, override) {
172
- context.debug(`Creating ts-morph Project instance with configuration from: ${context.tsconfig.tsconfigFilePath}.`);
173
- return new Project(defu$1(override ?? {}, {
174
- skipAddingFilesFromTsConfig: false,
175
- tsConfigFilePath: context.tsconfig.tsconfigFilePath,
176
- fileSystem: new VirtualFileSystemHost(context),
177
- compilerOptions: defu$1(context.tsconfig.options ?? {}, { lib: ["lib.esnext.full.d.ts"] })
178
- }));
179
- }
180
-
181
- //#endregion
182
- //#region ../powerlines/src/_internal/helpers/generate-types.ts
183
- const getModuleCommentBlockRegex = (moduleId) => /* @__PURE__ */ new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${moduleId}(?s:.)*?\\*\\/\\s+`);
184
- /**
185
- * Formats the generated TypeScript types source code.
186
- *
187
- * @param code - The generated TypeScript code.
188
- * @returns The formatted TypeScript code.
189
- */
190
- function formatTypes(code) {
191
- return code.replace(/import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g, "").replaceAll("#private;", "").replace(/__Ω/g, "");
192
- }
193
- /**
194
- * Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
195
- *
196
- * @param context - The context containing options and environment paths.
197
- * @param files - The list of files to generate types for.
198
- * @returns A promise that resolves to the generated TypeScript declaration types.
199
- */
200
- async function emitBuiltinTypes(context, files) {
201
- if (files.length === 0) {
202
- context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
203
- return "";
204
- }
205
- context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
206
- const program = createProgram(context, {
207
- skipAddingFilesFromTsConfig: true,
208
- compilerOptions: {
209
- declaration: true,
210
- declarationMap: false,
211
- emitDeclarationOnly: true,
212
- sourceMap: false,
213
- outDir: replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot),
214
- composite: false,
215
- incremental: false,
216
- tsBuildInfoFile: void 0
217
- }
218
- });
219
- program.addSourceFilesAtPaths(files);
220
- const result = program.emitToMemory({ emitOnlyDtsFiles: true });
221
- const diagnostics = result.getDiagnostics();
222
- if (diagnostics && diagnostics.length > 0) if (diagnostics.some((d) => d.getCategory() === DiagnosticCategory.Error)) throw new Error(`The Typescript emit process failed while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === DiagnosticCategory.Error).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
223
- else if (diagnostics.some((d) => d.getCategory() === DiagnosticCategory.Warning)) context.warn(`The Typescript emit process completed with warnings while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === DiagnosticCategory.Warning).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
224
- else context.debug(`The Typescript emit process completed with diagnostic messages while generating built-in types: \n ${diagnostics.map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
225
- const emittedFiles = result.getFiles();
226
- context.debug(`The TypeScript compiler emitted ${emittedFiles.length} files for built-in types.`);
227
- let builtinModules = "";
228
- for (const emittedFile of emittedFiles) {
229
- context.trace(`Processing emitted type declaration file: ${emittedFile.filePath}`);
230
- const filePath = appendPath(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
231
- if (!filePath.endsWith(".map") && findFileName(filePath) !== "tsconfig.tsbuildinfo" && isParentPath(filePath, context.builtinsPath)) {
232
- const moduleId = `${context.config.framework}:${replaceExtension(replacePath(filePath, context.builtinsPath), "", { fullExtension: true })}`;
233
- const moduleComment = emittedFile.text.match(getModuleCommentBlockRegex(moduleId))?.find((comment) => isSetString(comment?.trim()));
234
- builtinModules += `${moduleComment ? `\n${moduleComment.trim()}` : ""}
235
- declare module "${moduleId}" {
236
- ${emittedFile.text.replace(moduleComment ?? "", "").trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
237
- }
238
- `;
239
- }
240
- }
241
- builtinModules = formatTypes(builtinModules);
242
- context.debug(`A TypeScript declaration file (size: ${prettyBytes(new Blob(toArray(builtinModules)).size)}) emitted for the built-in modules types.`);
243
- return builtinModules;
244
- }
245
-
246
- //#endregion
247
- //#region ../core/src/plugin-utils/helpers.ts
248
- /**
249
- * Type guard to check if an object is a {@link Plugin}
250
- *
251
- * @param value - The object to check
252
- * @returns True if the object is a {@link Plugin}, false otherwise
253
- */
254
- function isPlugin(value) {
255
- return isSetObject(value) && "name" in value && isSetString(value.name) && (isUndefined(value.api) || "api" in value && isSetObject(value.api)) && (isUndefined(value.applyToEnvironment) || "applyToEnvironment" in value && isFunction(value.applyToEnvironment)) && (isUndefined(value.dedupe) || "dedupe" in value && isFunction(value.dedupe)) && PLUGIN_HOOKS_FIELDS.every((hook) => isUndefined(value[hook]) || hook in value && (isPluginHookFunction(value[hook]) || hook === "config" && isSetObject(value[hook]))) && BUILDER_VARIANTS.every((variant) => isUndefined(value[variant]) || variant in value && isSetObject(value[variant]));
256
- }
257
- /**
258
- * Type guard to check if an object is a {@link PluginConfigObject}
259
- *
260
- * @param value - The object to check
261
- * @returns True if the object is a {@link PluginConfigObject}, false otherwise
262
- */
263
- function isPluginConfigObject(value) {
264
- return isSetObject(value) && "plugin" in value && ((isSetString(value.plugin) || isFunction(value.plugin)) && "options" in value && isSetObject(value.options) || isPlugin(value.plugin));
265
- }
266
- /**
267
- * Type guard to check if an object is a {@link PluginConfigTuple}
268
- *
269
- * @param value - The object to check
270
- * @returns True if the object is a {@link PluginConfigTuple}, false otherwise
271
- */
272
- function isPluginConfigTuple(value) {
273
- return Array.isArray(value) && (value.length === 1 || value.length === 2) && ((isSetString(value[0]) || isFunction(value[0])) && value.length > 1 && isSetObject(value[1]) || isPlugin(value[0]));
274
- }
275
- /**
276
- * Type guard to check if an object is a {@link PluginConfig}
277
- *
278
- * @param value - The object to check
279
- * @returns True if the object is a {@link PluginConfig}, false otherwise
280
- */
281
- function isPluginConfig(value) {
282
- return isSetString(value) || isFunction(value) || isPlugin(value) || isPluginConfigObject(value) || isPluginConfigTuple(value) || Array.isArray(value) && value.every((item) => isPluginConfig(item));
283
- }
284
- /**
285
- * Type guard to check if an value is a {@link PluginHook} function
286
- *
287
- * @param value - The value to check
288
- * @returns True if the value is a {@link PluginHook} function, false otherwise
289
- */
290
- function isPluginHookObject(value) {
291
- return isSetObject(value) && "handler" in value && isFunction(value.handler);
292
- }
293
- /**
294
- * Type guard to check if an value is a {@link PluginHook} function
295
- *
296
- * @param value - The value to check
297
- * @returns True if the value is a {@link PluginHook} function, false otherwise
298
- */
299
- function isPluginHookFunction(value) {
300
- return isFunction(value) || isPluginHookObject(value);
301
- }
302
- /**
303
- * Type guard to check if an object is a {@link PluginHook}
304
- *
305
- * @param value - The object to check
306
- * @returns True if the object is a {@link PluginHook}, false otherwise
307
- */
308
- function isPluginHook(value) {
309
- return isPluginHookFunction(value) || isPluginHookObject(value);
310
- }
311
- /**
312
- * Extract the hook handler function from a plugin hook
313
- *
314
- * @param pluginHook - The plugin hook to extract the handler function from
315
- * @returns The hook handler function
316
- */
317
- function getHookHandler(pluginHook) {
318
- return isFunction(pluginHook) ? pluginHook : pluginHook.handler;
319
- }
320
- /**
321
- * Check if a hook is external.
322
- *
323
- * @param keys - The name of the hook to check.
324
- * @returns True if the hook is external, false otherwise.
325
- */
326
- function isUnpluginHookKey(keys) {
327
- return UNPLUGIN_BUILDER_VARIANTS.some((variant) => keys.startsWith(`${variant}:`));
328
- }
329
- /**
330
- * Check if a hook is internal.
331
- *
332
- * @param keys - The name of the hook to check.
333
- * @returns True if the hook is external, false otherwise.
334
- */
335
- function isPluginHookField(keys) {
336
- return !isUnpluginHookKey(keys) && PLUGIN_HOOKS_FIELDS.includes(keys);
337
- }
338
- /**
339
- * Check if a hook is external.
340
- *
341
- * @param field - The name of the hook to check.
342
- * @returns True if the hook is external, false otherwise.
343
- */
344
- function isUnpluginHookField(field) {
345
- return !isPluginHookField(field) && UNPLUGIN_BUILDER_VARIANTS.includes(field);
346
- }
347
- /**
348
- * Check if a plugin should be deduplicated.
349
- *
350
- * @param plugin - The plugin to check
351
- * @param plugins - The list of plugins to check against
352
- * @returns True if the plugin should be deduplicated, false otherwise
353
- */
354
- function checkDedupe(plugin, plugins) {
355
- return plugin.dedupe === false || plugins.some((p) => p.dedupe !== false && (isFunction(p.dedupe) && p.dedupe(plugin) || p.name === plugin.name));
356
- }
357
- /**
358
- * Add a plugin hook to the hooks list.
359
- *
360
- * @param context - The plugin context
361
- * @param plugin - The plugin to add the hook from
362
- * @param pluginHook - The plugin hook to add
363
- * @param hooksList - The list of hooks to add to
364
- */
365
- function addPluginHook(context, plugin, pluginHook, hooksList) {
366
- if (!checkDedupe(plugin, hooksList.map((hook) => hook.plugin).filter(Boolean))) {
367
- const handler = ((...args) => getHookHandler(pluginHook).apply(context, args));
368
- if (!handler) return;
369
- hooksList.push({
370
- plugin,
371
- handler
372
- });
373
- }
374
- }
375
- /**
376
- * Check the provided {@link PluginConfig}, and return a stringified version of the invalid configuration. If an array is provided, check each item in the array.
377
- *
378
- * @param config - The plugin configuration to check
379
- * @returns Null if the configuration is valid, otherwise an array of stringified invalid configurations
380
- */
381
- function findInvalidPluginConfig(config) {
382
- if (isPluginConfig(config)) return null;
383
- if (Array.isArray(config)) {
384
- const invalidItems = [];
385
- config.forEach((item) => {
386
- const invalid = findInvalidPluginConfig(item);
387
- if (invalid) invalidItems.push(...invalid.map((i) => JSON.stringify(i, null, 2)));
388
- });
389
- return invalidItems.length > 0 ? invalidItems : null;
390
- }
391
- return [JSON.stringify(config, null, 2)];
392
- }
393
-
394
- //#endregion
395
- //#region ../core/src/plugin-utils/merge.ts
396
- const mergePlugin = createDefu((obj, key, value) => {
397
- if (isPluginHook(obj[key]) && isPluginHook(value)) {
398
- obj[key] = {
399
- ...obj[key],
400
- ...value,
401
- handler: async (...params) => {
402
- const [resultA, resultB] = await Promise.all([getHookHandler(obj[key])(...params), getHookHandler(value)(...params)]);
403
- return resultB && resultA ? defu$1(resultA, resultB) : resultA || resultB;
404
- }
405
- };
406
- return true;
407
- }
408
- return false;
409
- });
410
- /**
411
- * Merges two configuration objects together, with special handling for string values.
412
- * If the value from the second object is a non-empty string, it will overwrite the value from the first object.
413
- *
414
- * @example
415
- * ```ts
416
- * const configA = { name: "Default", version: "1.0.0" };
417
- * const configB = { name: "Custom", description: "A custom config" };
418
- * const mergedConfig = mergeConfig(configA, configB);
419
- * // Result: { name: "Custom", version: "1.0.0", description: "A custom config" }
420
- * ```
421
- *
422
- * @param objA - The first configuration object.
423
- * @param objB - The second configuration object.
424
- * @returns The merged configuration object.
425
- */
426
- const mergeConfig = createDefu((obj, key, value) => {
427
- if (isString(obj[key]) && isString(value)) {
428
- if (isSetString(value)) obj[key] = value;
429
- return true;
430
- }
431
- return false;
432
- });
433
-
434
- //#endregion
435
- //#region ../core/src/lib/utilities/format.ts
436
- /**
437
- * Formats code using Prettier based on the file path.
438
- *
439
- * @param context - The Powerlines context.
440
- * @param path - The file path to use for resolving Prettier configuration.
441
- * @param data - The code string to format.
442
- * @param force - Whether to force formatting even for output/build paths.
443
- * @returns A promise that resolves to the formatted code string.
444
- */
445
- async function format$1(context, path, data, force = false) {
446
- if (!force && (isParentPath(path, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) || isParentPath(path, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot)))) return data;
447
- let code = data;
448
- const resolvedConfig = await resolveConfig(path);
449
- if (resolvedConfig) code = await format(data, {
450
- absolutePath: path,
451
- ...resolvedConfig
452
- });
453
- return code;
454
- }
455
- /**
456
- * Formats all files in a folder using Prettier based on their file paths.
457
- *
458
- * @param context - The Powerlines context.
459
- * @param path - The folder path containing files to format.
460
- * @returns A promise that resolves when all files have been formatted.
461
- */
462
- async function formatFolder(context, path) {
463
- if (!isParentPath(path, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) && !isParentPath(path, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot))) await Promise.allSettled((await listFiles(path)).map(async (file) => {
464
- if (!isParentPath(file, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) && !isParentPath(file, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot))) {
465
- const data = await context.fs.read(file);
466
- if (data) {
467
- const formatted = await format$1(context, file, data);
468
- return context.fs.write(file, formatted);
469
- }
470
- }
471
- }));
472
- }
473
-
474
- //#endregion
475
- //#region ../core/src/plugin-utils/paths.ts
476
- /**
477
- * Replaces tokens in the given path string with their corresponding values from the context.
478
- *
479
- * @remarks
480
- * The following tokens are supported:
481
- * - `{workspaceRoot}` - The root directory of the workspace.
482
- * - `{root}` - The root directory of the project (same as `{projectRoot}`).
483
- * - `{projectRoot}` - The root directory of the project (same as `{root}`).
484
- * - `{sourceRoot}` - The source root directory of the project (usually `./src`).
485
- * - `{powerlinesPath}` - The directory where Powerlines is installed.
486
- * - `{cachePath}` - The environment's directory for cached files.
487
- * - `{dataPath}` - The environment's directory for data files.
488
- * - `{logPath}` - The environment's directory for log files.
489
- * - `{tempPath}` - The environment's directory for temporary files.
490
- * - `{configPath}` - The environment's directory for configuration files.
491
- * - `{outputPath}` - The configured output directory for the project.
492
- * - `{buildPath}` - The configured distribution directory for the project.
493
- * - `{artifactsPath}` - The configured directory for build artifacts.
494
- * - `{builtinPath}` - The configured directory for generated built-in plugins.
495
- * - `{entryPath}` - The configured directory for generated entry files.
496
- *
497
- * @param context - The context containing the values for the path tokens.
498
- * @param path - The path string with tokens to replace.
499
- * @returns The path string with tokens replaced by their corresponding values from the context.
500
- */
501
- function replacePathTokens(context, path) {
502
- if (!path) return path;
503
- return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.root).replaceAll("{projectRoot}", context.config.root).replaceAll("{sourceRoot}", joinPaths$1(context.config.root, "src")).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("{buildPath}", context.config.output.buildPath).replaceAll("{artifactsPath}", replacePath(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", replacePath(context.entryPath, context.workspaceConfig.workspaceRoot));
504
- }
505
-
506
- //#endregion
507
- //#region ../powerlines/src/_internal/helpers/hooks.ts
508
- const mergeResultObjects = createDefu((obj, key, value) => {
509
- if (isString(obj[key]) && isString(value)) {
510
- obj[key] = `${obj[key] || ""}\n${value || ""}`.trim();
511
- return true;
512
- }
513
- return false;
514
- });
515
- /**
516
- * Merges the current hook result with the previous results based on their types.
517
- *
518
- * @param currentResult - The current hook result to merge with the previous results.
519
- * @param previousResults - The previous hook results to merge with the current result.
520
- * @returns The merged result.
521
- */
522
- function mergeResults(currentResult, previousResults) {
523
- if (isString(currentResult)) previousResults = [`${isString(previousResults[0]) ? previousResults[0] || "" : ""}\n${currentResult || ""}`.trim()];
524
- else if (isObject(currentResult)) previousResults = [mergeResultObjects(currentResult, previousResults[0] ?? {})];
525
- return previousResults;
526
- }
527
- /**
528
- * Merges multiple hook results together, with special handling for string values and object values.
529
- *
530
- * @param currentResult - The current hook result to merge with the previous results.
531
- * @param previousResults - The previous hook results to merge with the current result.
532
- * @returns The merged result.
533
- */
534
- function mergeConfigs(currentResult, previousResults) {
535
- if (isString(currentResult)) previousResults = [`${isString(previousResults[0]) ? previousResults[0] || "" : ""}\n${currentResult || ""}`.trim()];
536
- else if (isObject(currentResult)) previousResults = [mergeConfig(currentResult, previousResults[0] ?? {})];
537
- return previousResults;
538
- }
539
- /**
540
- * Calls a hook with the given context, options, and arguments.
541
- *
542
- * @param context - The context to use when calling the hook.
543
- * @param key - The hook to call.
544
- * @param options - Options for calling the hook.
545
- * @param args - Arguments to pass to the hook.
546
- * @returns The return value of the hook.
547
- */
548
- async function callHook(context, key, options, ...args) {
549
- const hooks = context.selectHooks(key, options);
550
- if (hooks.length > 0) {
551
- context.debug(` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
552
- const invokeHook = async (hook, hookArgs) => {
553
- return Reflect.apply(hook.handler, hook.context, hookArgs);
554
- };
555
- let results = [];
556
- if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
557
- if (!isFunction(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
558
- return invokeHook(hook, [...args]);
559
- }));
560
- else for (const hook of hooks) {
561
- if (!isFunction(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
562
- if (options?.result === "first" || options?.asNextParam === false) {
563
- results.push(await Promise.resolve(invokeHook(hook, [...args])));
564
- if (options?.result === "first" && isSet(results[results.length - 1])) break;
565
- } else {
566
- const sequenceArgs = [...args];
567
- if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = isFunction(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
568
- const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
569
- if (result) if (options.result === "last") results = [result];
570
- else if (options.result === "merge" && options.merge) results = options.merge(result, results);
571
- else results = mergeResults(result, results);
572
- }
573
- }
574
- const definedResults = results.filter((result) => isSet(result));
575
- if (definedResults.length > 0) {
576
- let mergedResult = void 0;
577
- for (const result of definedResults) mergedResult = defu(result, mergedResult ?? {});
578
- return mergedResult;
579
- }
580
- }
581
- }
582
-
583
- //#endregion
584
- //#region ../powerlines/src/_internal/helpers/install.ts
585
- /**
586
- * Installs a package if it is not already installed.
587
- *
588
- * @param context - The resolved options
589
- * @param packageName - The name of the package to install
590
- * @param dev - Whether to install the package as a dev dependency
591
- */
592
- async function installPackage(context, packageName, dev = false) {
593
- if (!await isPackageListed(getPackageName(packageName), { cwd: context.config.root })) if (context.config.autoInstall) {
594
- context.warn(`The package "${packageName}" is not installed. It will be installed automatically.`);
595
- const result = await install(packageName, {
596
- cwd: context.config.root,
597
- dev
598
- });
599
- if (isNumber(result.exitCode) && result.exitCode > 0) {
600
- context.error(result.stderr);
601
- throw new Error(`An error occurred while installing the package "${packageName}"`);
602
- }
603
- } else context.warn(`The package "${packageName}" is not installed. Since the "autoInstall" option is set to false, it will not be installed automatically.`);
604
- else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
605
- if (!await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.root)) {
606
- const packageListing = await getPackageListing(getPackageName(packageName), { cwd: context.config.root });
607
- if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.warn(`The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
608
- }
609
- }
610
- }
611
-
612
- //#endregion
613
- //#region ../powerlines/src/_internal/helpers/install-dependencies.ts
614
- /**
615
- * Install missing project dependencies.
616
- *
617
- * @param context - The build context.
618
- */
619
- async function installDependencies(context) {
620
- context.debug(`Checking and installing missing project dependencies.`);
621
- context.dependencies ??= {};
622
- context.devDependencies ??= {};
623
- if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
624
- context.debug(`No dependencies or devDependencies to install. Skipping installation step.`);
625
- return;
626
- }
627
- context.debug(`The following packages are required: \nDependencies: \n${Object.entries(context.dependencies).map(([name, version$1]) => `- ${name}@${String(version$1)}`).join(" \n")}\n\nDevDependencies: \n${Object.entries(context.devDependencies).map(([name, version$1]) => `- ${name}@${String(version$1)}`).join(" \n")}`);
628
- await Promise.all([Promise.all(Object.entries(context.dependencies).map(async ([name, version$1]) => installPackage(context, `${getPackageName(name)}@${String(version$1)}`, false))), Promise.all(Object.entries(context.devDependencies).map(async ([name, version$1]) => installPackage(context, `${getPackageName(name)}@${String(version$1)}`, true)))]);
629
- }
630
-
631
- //#endregion
632
- //#region ../powerlines/src/_internal/helpers/meta.ts
633
- /**
634
- * Generates a prefixed project root hash object.
635
- *
636
- * @remarks
637
- * This function returns a string where the project root hash is prefixed with the project name plus a hyphen. If the total length of this string combination exceeds 45 characters, it will truncate the hash.
638
- *
639
- * @param name - The name of the project.
640
- * @param rootHash - The hash of the project root.
641
- * @returns An object containing the name and project root hash.
642
- */
643
- function getPrefixedRootHash(name, rootHash) {
644
- const combined = `${kebabCase(name)}_${rootHash}`;
645
- return combined.length > ROOT_HASH_LENGTH ? combined.slice(0, ROOT_HASH_LENGTH) : combined;
646
- }
647
- /**
648
- * Writes the meta file for the context.
649
- *
650
- * @param context - The context to write the meta file for.
651
- * @returns A promise that resolves when the meta file has been written.
652
- */
653
- async function writeMetaFile(context) {
654
- const metaFilePath = joinPaths(context.dataPath, "meta.json");
655
- context.debug(`Writing runtime metadata to ${metaFilePath}`);
656
- await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
657
- }
658
-
659
- //#endregion
660
- //#region ../powerlines/src/typescript/tsconfig.ts
661
- /**
662
- * Get the path to the tsconfig.json file.
663
- *
664
- * @param workspaceRoot - The root directory of the workspace.
665
- * @param projectRoot - The root directory of the project.
666
- * @param tsconfig - The path to the tsconfig.json file.
667
- * @returns The absolute path to the tsconfig.json file.
668
- * @throws If the tsconfig.json file does not exist.
669
- */
670
- function getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig) {
671
- let tsconfigFilePath;
672
- if (tsconfig) tsconfigFilePath = tryTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
673
- else {
674
- tsconfigFilePath = tryTsconfigFilePath(workspaceRoot, projectRoot, "tsconfig.app.json");
675
- if (!tsconfigFilePath) {
676
- tsconfigFilePath = tryTsconfigFilePath(workspaceRoot, projectRoot, "tsconfig.lib.json");
677
- if (!tsconfigFilePath) tsconfigFilePath = tryTsconfigFilePath(workspaceRoot, projectRoot, "tsconfig.json");
678
- }
679
- }
680
- if (!tsconfigFilePath) throw new Error(`Cannot find the \`tsconfig.json\` configuration file for the project at ${projectRoot}.`);
681
- return tsconfigFilePath;
682
- }
683
- /**
684
- * Get the path to the tsconfig.json file.
685
- *
686
- * @param workspaceRoot - The root directory of the workspace.
687
- * @param projectRoot - The root directory of the project.
688
- * @param tsconfig - The path to the tsconfig.json file.
689
- * @returns The absolute path to the tsconfig.json file.
690
- * @throws If the tsconfig.json file does not exist.
691
- */
692
- function tryTsconfigFilePath(workspaceRoot, projectRoot, tsconfig) {
693
- let tsconfigFilePath = tsconfig;
694
- if (!existsSync(tsconfigFilePath)) {
695
- tsconfigFilePath = appendPath(tsconfig, projectRoot);
696
- if (!existsSync(tsconfigFilePath)) {
697
- tsconfigFilePath = appendPath(tsconfig, appendPath(projectRoot, workspaceRoot));
698
- if (!existsSync(tsconfigFilePath)) return;
699
- }
700
- }
701
- return tsconfigFilePath;
702
- }
703
- /**
704
- * Check if the TypeScript configuration type matches any of the provided types.
705
- *
706
- * @param tsconfigType - The type from the TypeScript configuration.
707
- * @param types - An array of type names to check against.
708
- * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.
709
- */
710
- function findMatch(tsconfigType, types, extensions = [
711
- ".ts",
712
- ".tsx",
713
- ".d.ts"
714
- ]) {
715
- return types.find((type) => tsconfigType?.toString().toLowerCase() === type?.toString().toLowerCase() || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}` || `./${tsconfigType?.toString().toLowerCase()}` === type?.toString().toLowerCase() || extensions.some((ext) => `${tsconfigType?.toString().toLowerCase()}${ext}` === type?.toString().toLowerCase() || `${tsconfigType?.toString().toLowerCase()}${ext}` === `./${type?.toString().toLowerCase()}` || `${type?.toString().toLowerCase()}${ext}` === `./${tsconfigType?.toString().toLowerCase()}` || tsconfigType?.toString().toLowerCase() === `${type?.toString().toLowerCase()}${ext}` || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}${ext}` || type?.toString().toLowerCase() === `./${tsconfigType?.toString().toLowerCase()}${ext}`));
716
- }
717
- /**
718
- * Check if the TypeScript configuration type matches any of the provided types.
719
- *
720
- * @param tsconfigType - The type from the TypeScript configuration.
721
- * @param types - An array of type names to check against.
722
- * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.
723
- */
724
- function findIncludeMatch(tsconfigType, types) {
725
- return findMatch(tsconfigType, types, [
726
- ".ts",
727
- ".tsx",
728
- ".d.ts",
729
- ".js",
730
- ".jsx",
731
- ".mjs",
732
- ".cjs",
733
- ".mts",
734
- ".cts",
735
- "/*.ts",
736
- "/*.tsx",
737
- "/*.d.ts",
738
- "/*.js",
739
- "/*.jsx",
740
- "/*.mjs",
741
- "/*.cjs",
742
- "/*.mts",
743
- "/*.cts",
744
- "/**/*.ts",
745
- "/**/*.tsx",
746
- "/**/*.d.ts",
747
- "/**/*.js",
748
- "/**/*.jsx",
749
- "/**/*.mjs",
750
- "/**/*.cjs",
751
- "/**/*.mts",
752
- "/**/*.cts"
753
- ]);
754
- }
755
- /**
756
- * Check if the TypeScript configuration type matches any of the provided types.
757
- *
758
- * @param tsconfigType - The type from the TypeScript configuration.
759
- * @param types - An array of type names to check against.
760
- * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.
761
- */
762
- function isIncludeMatchFound(tsconfigType, types) {
763
- return findIncludeMatch(tsconfigType, types) !== void 0;
764
- }
765
- /**
766
- * Get the parsed TypeScript configuration.
767
- *
768
- * @param workspaceRoot - The root directory of the workspace.
769
- * @param projectRoot - The root directory of the project.
770
- * @param tsconfig - The path to the tsconfig.json file.
771
- * @param tsconfigRaw - The raw tsconfig.json content.
772
- * @param originalTsconfigJson - The original tsconfig.json content.
773
- * @param host - The TypeScript parse config host.
774
- * @returns The resolved TypeScript configuration.
775
- */
776
- function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, originalTsconfigJson, host = ts.sys) {
777
- const tsconfigFilePath = getTsconfigFilePath(workspaceRoot, projectRoot, tsconfig);
778
- const tsconfigJson = readJsonFileSync(tsconfigFilePath);
779
- if (!tsconfigJson) throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
780
- const parsedCommandLine = ts.parseJsonConfigFileContent(defu$1(tsconfigRaw ?? {}, tsconfigJson), host, appendPath(projectRoot, workspaceRoot));
781
- if (parsedCommandLine.errors.length > 0) {
782
- const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
783
- ${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
784
- `;
785
- throw new Error(errorMessage);
786
- }
787
- return {
788
- ...parsedCommandLine,
789
- originalTsconfigJson: originalTsconfigJson ?? tsconfigJson,
790
- tsconfigJson,
791
- tsconfigFilePath
792
- };
793
- }
794
-
795
- //#endregion
796
- //#region ../powerlines/src/_internal/helpers/resolve-tsconfig.ts
797
- function getTsconfigDtsPath(context) {
798
- return joinPaths(relativePath(joinPaths(context.workspaceConfig.workspaceRoot, context.config.root), findFilePath(context.dtsPath)), findFileName(context.dtsPath));
799
- }
800
- async function resolveTsconfigChanges(context) {
801
- const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig, context.config.tsconfigRaw);
802
- const tsconfigJson = await readJsonFile(getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig));
803
- tsconfigJson.compilerOptions ??= {};
804
- if (context.config.output.dts !== false) {
805
- const dtsRelativePath = getTsconfigDtsPath(context);
806
- if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [context.dtsPath, dtsRelativePath]))) {
807
- tsconfigJson.include ??= [];
808
- tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
809
- }
810
- }
811
- if (!tsconfig.options.lib?.some((lib) => [
812
- "lib.esnext.d.ts",
813
- "lib.es2021.d.ts",
814
- "lib.es2022.d.ts",
815
- "lib.es2023.d.ts"
816
- ].includes(lib.toLowerCase()))) {
817
- tsconfigJson.compilerOptions.lib ??= [];
818
- tsconfigJson.compilerOptions.lib.push("esnext");
819
- }
820
- if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
821
- if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
822
- if (context.config.platform === "node") {
823
- if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
824
- tsconfigJson.compilerOptions.types ??= [];
825
- tsconfigJson.compilerOptions.types.push("node");
826
- }
827
- }
828
- return tsconfigJson;
829
- }
830
- async function initializeTsconfig(context) {
831
- context.debug("Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
832
- if (!isPackageExists("typescript")) throw new Error("The TypeScript package is not installed. Please install the package using the command: \"npm install typescript --save-dev\"");
833
- const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
834
- context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
835
- context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
836
- context.debug("Writing updated TypeScript configuration (tsconfig.json) file to disk.");
837
- await context.fs.write(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson));
838
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
839
- }
840
- async function resolveTsconfig(context) {
841
- const updateTsconfigJson = await readJsonFile(context.tsconfig.tsconfigFilePath);
842
- if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
843
- const result = getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
844
- ignoreArrayOrder: true,
845
- showOnly: {
846
- statuses: [
847
- "added",
848
- "deleted",
849
- "updated"
850
- ],
851
- granularity: "deep"
852
- }
853
- });
854
- const changes = [];
855
- const getChanges = (difference, property) => {
856
- if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") if (difference.diff) for (const diff of difference.diff) getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
857
- else changes.push({
858
- field: property ? `${property}.${difference.property}` : difference.property,
859
- status: difference.status,
860
- previous: difference.status === "added" ? "---" : StormJSON.stringify(difference.previousValue),
861
- current: difference.status === "deleted" ? "---" : StormJSON.stringify(difference.currentValue)
862
- });
863
- };
864
- for (const diff of result.diff) getChanges(diff);
865
- if (changes.length > 0) context.warn(`Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
866
-
867
- ${changes.map((change, i) => `${chalk.bold.whiteBright(`${i + 1}. ${titleCase(change.status)} the ${change.field} field: `)}
868
- ${chalk.red(` - Previous: ${change.previous} `)}
869
- ${chalk.green(` - Updated: ${change.current} `)}
870
- `).join("\n")}
871
- `);
872
- await context.fs.write(context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
873
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
874
- if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
875
- }
876
-
877
- //#endregion
878
- //#region ../powerlines/src/_internal/helpers/environment.ts
879
- function createEnvironment(name, userConfig) {
880
- return defu$1(userConfig.environments?.[name] ?? {}, {
881
- name,
882
- title: userConfig.title || titleCase(userConfig.name),
883
- ssr: false,
884
- mainFields: userConfig?.platform === "browser" ? [
885
- "browser",
886
- "module",
887
- "jsnext:main",
888
- "jsnext"
889
- ] : [
890
- "module",
891
- "jsnext:main",
892
- "jsnext"
893
- ],
894
- extensions: [
895
- ".mjs",
896
- ".js",
897
- ".mts",
898
- ".ts",
899
- ".jsx",
900
- ".tsx",
901
- ".json"
902
- ],
903
- consumer: userConfig?.platform === "browser" ? "client" : "server",
904
- preview: userConfig?.platform === "browser" ? {
905
- port: 5173,
906
- open: true,
907
- strictPort: false,
908
- host: "localhost",
909
- allowedHosts: ["."],
910
- cors: true,
911
- headers: {}
912
- } : void 0
913
- }, userConfig);
914
- }
915
- function createDefaultEnvironment(userConfig) {
916
- return createEnvironment(DEFAULT_ENVIRONMENT, userConfig);
917
- }
918
-
919
- //#endregion
920
- //#region ../powerlines/src/_internal/helpers/resolver.ts
921
- /**
922
- * Create a Jiti resolver for the given workspace and project root.
923
- *
924
- * @param options - The options for creating the resolver.
925
- * @returns A Jiti instance configured for the specified workspace and project root.
926
- */
927
- function resolveOptions(options) {
928
- return defu$1(options, {
929
- interopDefault: true,
930
- fsCache: options.mode !== "development" ? joinPaths(options.cacheDir, "jiti") : false,
931
- moduleCache: options.mode !== "development"
932
- });
933
- }
934
- /**
935
- * Create a Jiti resolver for the given workspace and project root.
936
- *
937
- * @param options - The options for creating the resolver.
938
- * @returns A Jiti instance configured for the specified workspace and project root.
939
- */
940
- function createResolver(options) {
941
- const baseResolver = createJiti(joinPaths(options.workspaceRoot, options.root), resolveOptions(options));
942
- baseResolver.plugin = createJiti(joinPaths(options.workspaceRoot, options.root), resolveOptions(options));
943
- return baseResolver;
944
- }
945
-
946
- //#endregion
947
- //#region ../powerlines/schemas/fs.ts
948
- var FileMetadata_KeyValuePair = class extends $.Struct {
949
- static _capnp = {
950
- displayName: "KeyValuePair",
951
- id: "eabb26cf58b2a14c",
952
- size: new $.ObjectSize(0, 2)
953
- };
954
- get key() {
955
- return $.utils.getText(0, this);
956
- }
957
- set key(value) {
958
- $.utils.setText(0, value, this);
959
- }
960
- get value() {
961
- return $.utils.getText(1, this);
962
- }
963
- set value(value) {
964
- $.utils.setText(1, value, this);
965
- }
966
- toString() {
967
- return "FileMetadata_KeyValuePair_" + super.toString();
968
- }
969
- };
970
- /**
971
- * The identifier for the file data.
972
- *
973
- */
974
- var FileMetadata = class FileMetadata extends $.Struct {
975
- static KeyValuePair = FileMetadata_KeyValuePair;
976
- static _capnp = {
977
- displayName: "FileMetadata",
978
- id: "8e2cab5d7e28c7b3",
979
- size: new $.ObjectSize(8, 3),
980
- defaultType: "normal"
981
- };
982
- static _Properties;
983
- /**
984
- * The type of the file.
985
- *
986
- */
987
- get id() {
988
- return $.utils.getText(0, this);
989
- }
990
- set id(value) {
991
- $.utils.setText(0, value, this);
992
- }
993
- /**
994
- * The timestamp representing the file's creation date.
995
- *
996
- */
997
- get type() {
998
- return $.utils.getText(1, this, FileMetadata._capnp.defaultType);
999
- }
1000
- set type(value) {
1001
- $.utils.setText(1, value, this);
1002
- }
1003
- /**
1004
- * Additional metadata associated with the file.
1005
- *
1006
- */
1007
- get timestamp() {
1008
- return $.utils.getUint32(0, this);
1009
- }
1010
- set timestamp(value) {
1011
- $.utils.setUint32(0, value, this);
1012
- }
1013
- _adoptProperties(value) {
1014
- $.utils.adopt(value, $.utils.getPointer(2, this));
1015
- }
1016
- _disownProperties() {
1017
- return $.utils.disown(this.properties);
1018
- }
1019
- get properties() {
1020
- return $.utils.getList(2, FileMetadata._Properties, this);
1021
- }
1022
- _hasProperties() {
1023
- return !$.utils.isNull($.utils.getPointer(2, this));
1024
- }
1025
- _initProperties(length) {
1026
- return $.utils.initList(2, FileMetadata._Properties, length, this);
1027
- }
1028
- set properties(value) {
1029
- $.utils.copyFrom(value, $.utils.getPointer(2, this));
1030
- }
1031
- toString() {
1032
- return "FileMetadata_" + super.toString();
1033
- }
1034
- };
1035
- /**
1036
- * An identifier for the file.
1037
- *
1038
- */
1039
- var FileId = class extends $.Struct {
1040
- static _capnp = {
1041
- displayName: "FileId",
1042
- id: "990d6a471072f997",
1043
- size: new $.ObjectSize(0, 2)
1044
- };
1045
- /**
1046
- * A virtual (or actual) path to the file in the file system.
1047
- *
1048
- */
1049
- get id() {
1050
- return $.utils.getText(0, this);
1051
- }
1052
- set id(value) {
1053
- $.utils.setText(0, value, this);
1054
- }
1055
- get path() {
1056
- return $.utils.getText(1, this);
1057
- }
1058
- set path(value) {
1059
- $.utils.setText(1, value, this);
1060
- }
1061
- toString() {
1062
- return "FileId_" + super.toString();
1063
- }
1064
- };
1065
- /**
1066
- * An identifier for the file.
1067
- *
1068
- */
1069
- var FileStorage = class extends $.Struct {
1070
- static _capnp = {
1071
- displayName: "FileStorage",
1072
- id: "9dca66ac858c9ebe",
1073
- size: new $.ObjectSize(0, 2)
1074
- };
1075
- /**
1076
- * A virtual (or actual) path to the file in the file system.
1077
- *
1078
- */
1079
- get path() {
1080
- return $.utils.getText(0, this);
1081
- }
1082
- set path(value) {
1083
- $.utils.setText(0, value, this);
1084
- }
1085
- get code() {
1086
- return $.utils.getText(1, this);
1087
- }
1088
- set code(value) {
1089
- $.utils.setText(1, value, this);
1090
- }
1091
- toString() {
1092
- return "FileStorage_" + super.toString();
1093
- }
1094
- };
1095
- var FileSystem = class FileSystem extends $.Struct {
1096
- static _capnp = {
1097
- displayName: "FileSystem",
1098
- id: "ae0c23d43e56abcf",
1099
- size: new $.ObjectSize(0, 3)
1100
- };
1101
- static _Ids;
1102
- static _Storage;
1103
- static _Metadata;
1104
- _adoptIds(value) {
1105
- $.utils.adopt(value, $.utils.getPointer(0, this));
1106
- }
1107
- _disownIds() {
1108
- return $.utils.disown(this.ids);
1109
- }
1110
- get ids() {
1111
- return $.utils.getList(0, FileSystem._Ids, this);
1112
- }
1113
- _hasIds() {
1114
- return !$.utils.isNull($.utils.getPointer(0, this));
1115
- }
1116
- _initIds(length) {
1117
- return $.utils.initList(0, FileSystem._Ids, length, this);
1118
- }
1119
- set ids(value) {
1120
- $.utils.copyFrom(value, $.utils.getPointer(0, this));
1121
- }
1122
- _adoptStorage(value) {
1123
- $.utils.adopt(value, $.utils.getPointer(1, this));
1124
- }
1125
- _disownStorage() {
1126
- return $.utils.disown(this.storage);
1127
- }
1128
- get storage() {
1129
- return $.utils.getList(1, FileSystem._Storage, this);
1130
- }
1131
- _hasStorage() {
1132
- return !$.utils.isNull($.utils.getPointer(1, this));
1133
- }
1134
- _initStorage(length) {
1135
- return $.utils.initList(1, FileSystem._Storage, length, this);
1136
- }
1137
- set storage(value) {
1138
- $.utils.copyFrom(value, $.utils.getPointer(1, this));
1139
- }
1140
- _adoptMetadata(value) {
1141
- $.utils.adopt(value, $.utils.getPointer(2, this));
1142
- }
1143
- _disownMetadata() {
1144
- return $.utils.disown(this.metadata);
1145
- }
1146
- get metadata() {
1147
- return $.utils.getList(2, FileSystem._Metadata, this);
1148
- }
1149
- _hasMetadata() {
1150
- return !$.utils.isNull($.utils.getPointer(2, this));
1151
- }
1152
- _initMetadata(length) {
1153
- return $.utils.initList(2, FileSystem._Metadata, length, this);
1154
- }
1155
- set metadata(value) {
1156
- $.utils.copyFrom(value, $.utils.getPointer(2, this));
1157
- }
1158
- toString() {
1159
- return "FileSystem_" + super.toString();
1160
- }
1161
- };
1162
- FileMetadata._Properties = $.CompositeList(FileMetadata_KeyValuePair);
1163
- FileSystem._Ids = $.CompositeList(FileId);
1164
- FileSystem._Storage = $.CompositeList(FileStorage);
1165
- FileSystem._Metadata = $.CompositeList(FileMetadata);
1166
-
1167
- //#endregion
1168
- //#region ../core/src/lib/entry.ts
1169
- function resolveEntryOutput(context, typeDefinition) {
1170
- return replaceExtension(replacePath(replacePath(replacePath(replacePath(replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.root, "src")), joinPaths(context.workspaceConfig.workspaceRoot, context.config.root)), joinPaths(context.config.root, "src")), context.config.root), "src"));
1171
- }
1172
- function resolveInput(context, typeDefinition, input, output) {
1173
- return {
1174
- ...typeDefinition,
1175
- input: isSetString(input) ? { file: String(input) } : typeDefinition,
1176
- output: output || resolveEntryOutput(context, typeDefinition)
1177
- };
1178
- }
1179
- /**
1180
- * Resolves multiple type definitions into their corresponding resolved entry type definitions.
1181
- *
1182
- * @param context - The current context
1183
- * @param typeDefinitions - The type definitions to resolve.
1184
- * @returns A promise that resolves to an array of resolved entry type definitions.
1185
- */
1186
- function resolveInputsSync(context, typeDefinitions) {
1187
- return (isObject(typeDefinitions) && !isTypeDefinition(typeDefinitions) ? Object.values(typeDefinitions).flat() : toArray(typeDefinitions)).map((entry) => {
1188
- if (isResolvedEntryTypeDefinition(entry)) return {
1189
- ...entry,
1190
- output: entry.output ? replacePathTokens(context, entry.output) : void 0,
1191
- file: replacePathTokens(context, entry.file)
1192
- };
1193
- let typeDefinition;
1194
- if (isString(entry)) typeDefinition = parseTypeDefinition(replacePathTokens(context, entry));
1195
- else {
1196
- typeDefinition = entry;
1197
- typeDefinition.file = replacePathTokens(context, typeDefinition.file);
1198
- }
1199
- const filePath = isAbsolutePath(typeDefinition.file) ? typeDefinition.file : appendPath(typeDefinition.file, context.config.root);
1200
- if (context.fs.isFileSync(filePath)) return resolveInput(context, {
1201
- file: appendPath(filePath, context.workspaceConfig.workspaceRoot),
1202
- name: typeDefinition.name
1203
- });
1204
- return context.fs.globSync(appendPath(filePath, context.workspaceConfig.workspaceRoot)).map((file) => resolveInput(context, {
1205
- file,
1206
- name: typeDefinition.name
1207
- }));
1208
- }).flat().filter(Boolean);
1209
- }
1210
- /**
1211
- * Checks if the provided entry is a type definition.
1212
- *
1213
- * @param entry - The entry to check.
1214
- * @returns True if the entry is a type definition, false otherwise.
1215
- */
1216
- function isTypeDefinition(entry) {
1217
- return !isString(entry) && entry.file !== void 0;
1218
- }
1219
- /**
1220
- * Checks if the provided entry is a resolved entry type definition.
1221
- *
1222
- * @param entry - The entry to check.
1223
- * @returns True if the entry is a resolved entry type definition, false otherwise.
1224
- */
1225
- function isResolvedEntryTypeDefinition(entry) {
1226
- return isTypeDefinition(entry) && entry.output !== void 0;
1227
- }
1228
- /**
1229
- * Get unique inputs from the provided list.
1230
- *
1231
- * @param inputs - The entry points to process.
1232
- * @returns An array of unique inputs (by file path or content hash).
1233
- */
1234
- function getUniqueInputs(inputs = []) {
1235
- return isObject(inputs) ? inputs : getUniqueBy(toArray(inputs), (item) => isSetString(item) ? item : murmurhash(item ?? {}, { maxLength: 24 }));
1236
- }
1237
-
1238
- //#endregion
1239
- //#region ../core/src/lib/logger.ts
1240
- /**
1241
- * Create a logging function with a specific name and options.
1242
- *
1243
- * @param name - The name of the logging function.
1244
- * @param options - The options to configure the logging function.
1245
- * @returns A logging function.
1246
- */
1247
- const createLog = (name, options = {}) => {
1248
- const logLevel = options.logLevel === null ? LogLevelLabel.SILENT : options.logLevel || LogLevelLabel.INFO;
1249
- if (logLevel === LogLevelLabel.SILENT) return noop;
1250
- if (options.customLogger) return options.customLogger;
1251
- return (type, ...args) => getLogFn(getLogLevel(type), {
1252
- ...options,
1253
- logLevel
1254
- })(`${chalk.bold.hex(getColor("brand", options))(`${name ? kebabCase(name) : ""}${options.name ? `${name ? chalk.gray(" > ") : ""}${kebabCase(options.name)}` : ""}${chalk.gray(" > ")}`)}${args.join(" ")} `.trim());
1255
- };
1256
- const BADGE_COLORS = [
1257
- "#00A0DD",
1258
- "#6FCE4E",
1259
- "#FBBF24",
1260
- "#F43F5E",
1261
- "#3B82F6",
1262
- "#A855F7",
1263
- "#469592",
1264
- "#288EDF",
1265
- "#D8B4FE",
1266
- "#10B981",
1267
- "#EF4444",
1268
- "#F0EC56",
1269
- "#F472B6",
1270
- "#22D3EE",
1271
- "#EAB308",
1272
- "#84CC16",
1273
- "#F87171",
1274
- "#0EA5E9",
1275
- "#D946EF",
1276
- "#FACC15",
1277
- "#34D399",
1278
- "#8B5CF6"
1279
- ];
1280
- const extendLog = (logFn, name) => {
1281
- return (type, ...args) => logFn(type, ` ${chalk.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase(name)} `)} ${args.join(" ")} `);
1282
- };
1283
-
1284
- //#endregion
1285
- //#region ../core/src/lib/utilities/file-header.ts
1286
- /**
1287
- * Generates a file header comment with a warning about automatic overwriting.
1288
- *
1289
- * @param overwrite - Whether the file will be automatically overwritten. If `false`, the warning will indicate that the file will not be overwritten. If `true` or omitted, the warning will indicate that the file will be overwritten.
1290
- * @param framework - The name of the framework to include in the warning message. Defaults to "powerlines".
1291
- * @returns A string containing the file header warning message.
1292
- */
1293
- function getFileHeaderWarningText(overwrite = true, framework = "powerlines") {
1294
- return overwrite !== false ? `Do not edit this file manually - it will be overwritten automatically. Automatic overwrites can be disabled by using the \`output.overwrite\` option.` : `This file was generated on ${(/* @__PURE__ */ new Date()).toLocaleString()} - it will not be overwritten by ${titleCase(framework)} while the \`output.overwrite\` option is set to \`true\`.`;
1295
- }
1296
- /**
1297
- * Generates a file header warning message based on the provided context.
1298
- *
1299
- * @param context - The Powerlines context.
1300
- * @returns A string containing the file header warning message.
1301
- */
1302
- function getFileHeaderWarning(context) {
1303
- return getFileHeaderWarningText(context.config.output?.overwrite, context.config.framework);
1304
- }
1305
- /**
1306
- * Generates a file header comment for a generated source file, including a warning about automatic overwriting.
1307
- *
1308
- * @param context - The Powerlines context.
1309
- * @param comment - The comment syntax to use for the header (e.g., `//` for JavaScript/TypeScript, `#` for Python). Defaults to `//`.
1310
- * @returns A string containing the file header comment.
1311
- */
1312
- function getFileHeader(context, comment = "//") {
1313
- return `
1314
- ${comment} Generated by ${titleCase(context.config.framework) || "Powerlines"}
1315
- ${comment} ${getFileHeaderWarning(context)}
1316
- `;
1317
- }
1318
- /**
1319
- * Generates a file header comment for a generated TypeScript source file, including a warning about automatic overwriting.
1320
- *
1321
- * @param context - The Powerlines context.
1322
- * @param options - Additional options for generating the file header, such as a directive to include and whether to add a Prettier ignore comment.
1323
- * @returns A string containing the file header comment for a TypeScript file.
1324
- */
1325
- function getTypescriptFileHeader(context, options = {}) {
1326
- const { directive = null, prettierIgnore = false } = options;
1327
- return `/* eslint-disable */
1328
- // biome-ignore lint: disable
1329
- ${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `\n\n${directive}\n` : "\n"}
1330
- ${getFileHeader(context)}
1331
-
1332
- `;
1333
- }
1334
-
1335
- //#endregion
1336
- //#region ../core/src/lib/utilities/source-map.ts
1337
- const dmp = new Diff();
1338
-
1339
- //#endregion
1340
- //#region ../powerlines/src/storage/base.ts
1341
- /**
1342
- * Abstract base class for storage adapters, providing a template for storage operations.
1343
- */
1344
- var BaseStorageAdapter = class {
1345
- /**
1346
- * Indicates whether the storage adapter has been disposed.
1347
- */
1348
- #isDisposed = false;
1349
- /**
1350
- * Configuration options for the storage adapter.
1351
- */
1352
- options;
1353
- /**
1354
- * The storage preset for the adapter.
1355
- *
1356
- * @remarks
1357
- * This can be used as an alternate way to identify the type of storage being used.
1358
- */
1359
- preset = null;
1360
- /**
1361
- * Constructor for the BaseStorageAdapter.
1362
- *
1363
- * @param context - The Powerlines context.
1364
- * @param options - Configuration options for the storage adapter.
1365
- */
1366
- constructor(context, options = { base: "/" }) {
1367
- this.context = context;
1368
- this.options = options;
1369
- this.options.base = resolve$1(options.base);
1370
- this.options.isReadOnly = !!options.isReadOnly;
1371
- }
1372
- /**
1373
- * Asynchronously checks if a key exists in the storage.
1374
- *
1375
- * @param key - The key to check for existence.
1376
- * @returns A promise that resolves to `true` if the key exists, otherwise `false`.
1377
- */
1378
- async exists(key) {
1379
- return this.existsSync(key);
1380
- }
1381
- /**
1382
- * Asynchronously retrieves the value associated with a given key.
1383
- *
1384
- * @param key - The key whose value is to be retrieved.
1385
- * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.
1386
- */
1387
- async get(key) {
1388
- return this.getSync(key);
1389
- }
1390
- /**
1391
- * Asynchronously sets the value for a given key.
1392
- *
1393
- * @param key - The key to set the value for.
1394
- * @param value - The value to set.
1395
- */
1396
- async set(key, value) {
1397
- if (!this.isReadOnly && (!this.existsSync(key) || this.overwrite)) this.setSync(key, value);
1398
- }
1399
- /**
1400
- * Synchronously creates a directory at the specified path.
1401
- *
1402
- * @param _ - The path of the directory to create.
1403
- */
1404
- mkdirSync(_) {}
1405
- /**
1406
- * Creates a directory at the specified path.
1407
- *
1408
- * @param dirPath - The path of the directory to create.
1409
- */
1410
- async mkdir(dirPath) {
1411
- return Promise.resolve(this.mkdirSync(dirPath));
1412
- }
1413
- /**
1414
- * Asynchronously removes a key from the storage.
1415
- *
1416
- * @param key - The key to remove.
1417
- */
1418
- async remove(key) {
1419
- if (!this.isReadOnly && this.overwrite) this.removeSync(key);
1420
- }
1421
- /**
1422
- * Synchronously removes all entries from the storage that match the provided base path.
1423
- *
1424
- * @param base - The base path to clear keys from.
1425
- */
1426
- clearSync(base) {
1427
- if (!this.isReadOnly && this.overwrite) {
1428
- const keys = this.listSync(base || this.options.base);
1429
- if (!keys.length) return;
1430
- keys.map((key) => this.removeSync(base && !key.startsWith(base) ? joinPaths$1(base, key) : key));
1431
- }
1432
- }
1433
- /**
1434
- * Asynchronously removes all entries from the storage that match the provided base path.
1435
- *
1436
- * @param base - The base path to clear keys from.
1437
- * @returns A promise that resolves when the operation is complete.
1438
- */
1439
- async clear(base) {
1440
- if (!this.isReadOnly && this.overwrite) {
1441
- const keys = await this.list(base || this.options.base);
1442
- if (!keys.length) return;
1443
- await Promise.all(keys.map(async (key) => this.remove(base && !key.startsWith(base) ? joinPaths$1(base, key) : key)));
1444
- }
1445
- }
1446
- /**
1447
- * Asynchronously lists all keys under a given base path.
1448
- *
1449
- * @param base - The base path to list keys from.
1450
- * @returns A promise that resolves to an array of keys under the specified base path.
1451
- */
1452
- async list(base) {
1453
- return this.listSync(base);
1454
- }
1455
- /**
1456
- * Synchronously checks if the given key is a directory.
1457
- *
1458
- * @param _ - The key to check.
1459
- * @returns `true` if the key is a directory, otherwise `false`.
1460
- */
1461
- isDirectorySync(_) {
1462
- return false;
1463
- }
1464
- /**
1465
- * Checks if the given key is a directory.
1466
- *
1467
- * @param key - The key to check.
1468
- * @returns A promise that resolves to `true` if the key is a directory, otherwise `false`.
1469
- */
1470
- async isDirectory(key) {
1471
- return Promise.resolve(this.isDirectorySync(key));
1472
- }
1473
- /**
1474
- * Synchronously checks if the given key is a file.
1475
- *
1476
- * @param key - The key to check.
1477
- * @returns `true` if the key is a file, otherwise `false`.
1478
- */
1479
- isFileSync(key) {
1480
- return this.existsSync(key) && !this.isDirectorySync(key);
1481
- }
1482
- /**
1483
- * Checks if the given key is a file.
1484
- *
1485
- * @param key - The key to check.
1486
- * @returns A promise that resolves to `true` if the key is a file, otherwise `false`.
1487
- */
1488
- async isFile(key) {
1489
- return Promise.resolve(this.isFileSync(key));
1490
- }
1491
- /**
1492
- * Disposes of the storage adapter, releasing any held resources.
1493
- *
1494
- * @returns A promise that resolves when the disposal is complete.
1495
- */
1496
- dispose() {
1497
- return Promise.resolve();
1498
- }
1499
- /**
1500
- * Async dispose method to clean up resources.
1501
- *
1502
- * @returns A promise that resolves when disposal is complete.
1503
- */
1504
- async [Symbol.asyncDispose]() {
1505
- return this._dispose();
1506
- }
1507
- /**
1508
- * Determines if the storage adapter is read-only based on the provided options.
1509
- *
1510
- * @returns `true` if the storage adapter is read-only, otherwise `false`.
1511
- */
1512
- get isReadOnly() {
1513
- return !!this.options.isReadOnly;
1514
- }
1515
- /**
1516
- * Determines if the storage adapter should overwrite existing keys based on the provided options and context configuration.
1517
- *
1518
- * @returns `true` if the storage adapter should overwrite existing keys, otherwise `false`.
1519
- */
1520
- get overwrite() {
1521
- return !this.isReadOnly && this.context.config.output.overwrite !== false;
1522
- }
1523
- /**
1524
- * Resolves a given key to its full path within the storage adapter.
1525
- *
1526
- * @param key - The key to resolve.
1527
- * @returns The resolved full path for the key.
1528
- */
1529
- resolve(key) {
1530
- if (!key) return this.options.base;
1531
- if (/\.\.:|\.\.$/.test(key)) throw new Error(`[${this.name}]: Invalid key: ${JSON.stringify(key)} provided to storage adapter.`);
1532
- return appendPath(correctPath(key).replace(/:/g, "/"), this.options.base);
1533
- }
1534
- /**
1535
- * Disposes of the storage adapter, releasing any held resources.
1536
- *
1537
- * @returns A promise that resolves when the disposal is complete.
1538
- */
1539
- async _dispose() {
1540
- if (!this.#isDisposed) {
1541
- await Promise.resolve(this.dispose());
1542
- this.#isDisposed = true;
1543
- }
1544
- }
1545
- };
1546
-
1547
- //#endregion
1548
- //#region ../powerlines/src/storage/helpers.ts
1549
- /**
1550
- * Checks if an error is a file system error.
1551
- *
1552
- * @param err - The error to check.
1553
- * @returns `true` if the error is a file system error, otherwise `false`.
1554
- */
1555
- function isFileError(err) {
1556
- return isError(err) && "code" in err && err.code;
1557
- }
1558
- /**
1559
- * Ignores file not found errors.
1560
- *
1561
- * @param err - The error to check.
1562
- * @returns `null` if the error is a file not found error, otherwise returns the error.
1563
- */
1564
- function ignoreNotfound(err) {
1565
- return isFileError(err) && (err.code === "ENOENT" || err.code === "EISDIR" ? null : err);
1566
- }
1567
-
1568
- //#endregion
1569
- //#region ../powerlines/src/storage/file-system.ts
1570
- /**
1571
- * File system storage adapter implementation.
1572
- */
1573
- var FileSystemStorageAdapter = class extends BaseStorageAdapter {
1574
- /**
1575
- * A name identifying the storage adapter type.
1576
- */
1577
- name = "file-system";
1578
- /**
1579
- * The storage preset for the adapter.
1580
- *
1581
- * @remarks
1582
- * This can be used as an alternate way to identify the type of storage being used.
1583
- */
1584
- preset = "fs";
1585
- /**
1586
- * Constructor for the FileSystemStorageAdapter.
1587
- *
1588
- * @param context - The Powerlines context.
1589
- * @param options - Configuration options for the storage adapter.
1590
- */
1591
- constructor(context, options) {
1592
- super(context, options);
1593
- }
1594
- /**
1595
- * Synchronously checks if a key exists in the storage.
1596
- *
1597
- * @param key - The key to check for existence.
1598
- * @returns Returns `true` if the key exists, otherwise `false`.
1599
- */
1600
- existsSync(key) {
1601
- return existsSync(this.resolve(key));
1602
- }
1603
- /**
1604
- * Asynchronously checks if a key exists in the storage.
1605
- *
1606
- * @param key - The key to check for existence.
1607
- * @returns A promise that resolves to `true` if the key exists, otherwise `false`.
1608
- */
1609
- async exists(key) {
1610
- return exists(this.resolve(key));
1611
- }
1612
- /**
1613
- * Synchronously retrieves the value associated with a given key.
1614
- *
1615
- * @param key - The key whose value is to be retrieved.
1616
- * @returns The value associated with the key, or `null` if the key does not exist.
1617
- */
1618
- getSync(key) {
1619
- return readFileSync(this.resolve(key));
1620
- }
1621
- /**
1622
- * Asynchronously retrieves the value associated with a given key.
1623
- *
1624
- * @param key - The key whose value is to be retrieved.
1625
- * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.
1626
- */
1627
- async get(key) {
1628
- return readFile(this.resolve(key));
1629
- }
1630
- /**
1631
- * Synchronously sets the value for a given key.
1632
- *
1633
- * @param key - The key to set the value for.
1634
- * @param value - The value to set.
1635
- */
1636
- setSync(key, value) {
1637
- if (!this.isReadOnly) if (this.existsSync(this.resolve(key)) && !this.overwrite) {
1638
- const existingValue = this.getSync(this.resolve(key));
1639
- if (isSetString(existingValue) && existingValue.includes(getFileHeaderWarningText(true, this.context.config.framework))) return writeFileSync(this.resolve(key), existingValue.replace(getFileHeaderWarningText(true, this.context.config.framework), getFileHeaderWarningText(false, this.context.config.framework)));
1640
- } else return writeFileSync(this.resolve(key), value);
1641
- }
1642
- /**
1643
- * Asynchronously sets the value for a given key.
1644
- *
1645
- * @param key - The key to set the value for.
1646
- * @param value - The value to set.
1647
- */
1648
- async set(key, value) {
1649
- if (!this.isReadOnly) if (this.existsSync(this.resolve(key)) && !this.overwrite) {
1650
- const existingValue = await this.get(this.resolve(key));
1651
- if (isSetString(existingValue) && existingValue.includes(getFileHeaderWarningText(true, this.context.config.framework))) return writeFile(this.resolve(key), existingValue.replace(getFileHeaderWarningText(true, this.context.config.framework), getFileHeaderWarningText(false, this.context.config.framework)));
1652
- } else return writeFile(this.resolve(key), value);
1653
- }
1654
- /**
1655
- * Synchronously removes a key from the storage.
1656
- *
1657
- * @param key - The key to remove.
1658
- */
1659
- removeSync(key) {
1660
- if (!this.isReadOnly && this.overwrite) try {
1661
- return unlinkSync(this.resolve(key));
1662
- } catch (err) {
1663
- return ignoreNotfound(err);
1664
- }
1665
- }
1666
- /**
1667
- * Asynchronously removes a key from the storage.
1668
- *
1669
- * @param key - The key to remove.
1670
- */
1671
- async remove(key) {
1672
- if (!this.isReadOnly && this.overwrite) return unlink(this.resolve(key)).catch(ignoreNotfound);
1673
- }
1674
- /**
1675
- * Synchronously creates a directory at the specified path.
1676
- *
1677
- * @param dirPath - The path of the directory to create.
1678
- */
1679
- mkdirSync(dirPath) {
1680
- createDirectorySync(this.resolve(dirPath));
1681
- }
1682
- /**
1683
- * Creates a directory at the specified path.
1684
- *
1685
- * @param dirPath - The path of the directory to create.
1686
- */
1687
- async mkdir(dirPath) {
1688
- await createDirectory(this.resolve(dirPath));
1689
- }
1690
- /**
1691
- * Lists all keys under a given base path synchronously.
1692
- *
1693
- * @param base - The base path to list keys from.
1694
- * @returns An array of keys under the specified base path.
1695
- */
1696
- listSync(base) {
1697
- try {
1698
- return listFilesSync(this.resolve(base), { ignore: this.options.ignore });
1699
- } catch (err) {
1700
- return ignoreNotfound(err) ?? [];
1701
- }
1702
- }
1703
- /**
1704
- * Asynchronously lists all keys under a given base path.
1705
- *
1706
- * @param base - The base path to list keys from.
1707
- * @returns A promise that resolves to an array of keys under the specified base path.
1708
- */
1709
- async list(base) {
1710
- return listFiles(this.resolve(base), { ignore: this.options.ignore }).catch(ignoreNotfound).then((r) => r || []);
1711
- }
1712
- /**
1713
- * Synchronously checks if the given key is a directory.
1714
- *
1715
- * @param key - The key to check.
1716
- * @returns `true` if the key is a directory, otherwise `false`.
1717
- */
1718
- isDirectorySync(key) {
1719
- return isDirectory(this.resolve(key));
1720
- }
1721
- /**
1722
- * Synchronously checks if the given key is a file.
1723
- *
1724
- * @param key - The key to check.
1725
- * @returns `true` if the key is a file, otherwise `false`.
1726
- */
1727
- isFileSync(key) {
1728
- return isFile(this.resolve(key));
1729
- }
1730
- };
1731
-
1732
- //#endregion
1733
- //#region ../powerlines/src/storage/virtual.ts
1734
- /**
1735
- * Virtual/in-memory storage adapter implementation.
1736
- */
1737
- var VirtualStorageAdapter = class extends BaseStorageAdapter {
1738
- /**
1739
- * A name identifying the storage adapter type.
1740
- */
1741
- name = "virtual";
1742
- /**
1743
- * The storage preset for the adapter.
1744
- *
1745
- * @remarks
1746
- * This can be used as an alternate way to identify the type of storage being used.
1747
- */
1748
- preset = "virtual";
1749
- /**
1750
- * In-memory data storage.
1751
- */
1752
- data = /* @__PURE__ */ new Map();
1753
- /**
1754
- * Constructor for the VirtualStorageAdapter.
1755
- *
1756
- * @param context - The Powerlines context.
1757
- * @param options - Configuration options for the storage adapter.
1758
- */
1759
- constructor(context, options) {
1760
- super(context, options);
1761
- }
1762
- /**
1763
- * Synchronously checks if a key exists in the storage.
1764
- *
1765
- * @param key - The key to check for existence.
1766
- * @returns Returns `true` if the key exists, otherwise `false`.
1767
- */
1768
- existsSync(key) {
1769
- return this.data.has(this.resolve(key));
1770
- }
1771
- /**
1772
- * Synchronously retrieves the value associated with a given key.
1773
- *
1774
- * @param key - The key whose value is to be retrieved.
1775
- * @returns The value associated with the key, or `null` if the key does not exist.
1776
- */
1777
- getSync(key) {
1778
- return this.data.get(this.resolve(key)) ?? null;
1779
- }
1780
- /**
1781
- * Synchronously sets the value for a given key.
1782
- *
1783
- * @param key - The key to set the value for.
1784
- * @param value - The value to set.
1785
- */
1786
- setSync(key, value) {
1787
- if (!this.isReadOnly && (!this.existsSync(key) || this.overwrite)) this.data.set(this.resolve(key), value);
1788
- }
1789
- /**
1790
- * Synchronously removes a key from the storage.
1791
- *
1792
- * @param key - The key to remove.
1793
- */
1794
- removeSync(key) {
1795
- if (!this.isReadOnly && this.overwrite) this.data.delete(this.resolve(key));
1796
- }
1797
- /**
1798
- * Lists all keys under a given base path synchronously.
1799
- *
1800
- * @param base - The base path to list keys from.
1801
- * @returns An array of keys under the specified base path.
1802
- */
1803
- listSync(base) {
1804
- return [...this.data.keys().filter((key) => !base ? true : isParentPath(key, this.resolve(base)))];
1805
- }
1806
- /**
1807
- * Disposes of the storage adapter, releasing any held resources.
1808
- *
1809
- * @returns A promise that resolves when the disposal is complete.
1810
- */
1811
- async dispose() {
1812
- return this.clear();
1813
- }
1814
- /**
1815
- * Determines if the storage adapter should overwrite existing keys based on the provided options and context configuration.
1816
- *
1817
- * @returns `true` if the storage adapter should overwrite existing keys, otherwise `false`.
1818
- */
1819
- get overwrite() {
1820
- return !this.isReadOnly;
1821
- }
1822
- };
1823
-
1824
- //#endregion
1825
- //#region ../powerlines/src/_internal/helpers/constants.ts
1826
- const DEFAULT_EXTENSIONS = [
1827
- "js",
1828
- "ts",
1829
- "cjs",
1830
- "cts",
1831
- "mjs",
1832
- "mts",
1833
- "tsx",
1834
- "jsx",
1835
- "json",
1836
- "json5",
1837
- "jsonc",
1838
- "md",
1839
- "mdx"
1840
- ];
1841
-
1842
- //#endregion
1843
- //#region ../powerlines/src/_internal/vfs.ts
1844
- function toFilePath(path) {
1845
- return correctPath(slash(path?.toString() || ".").replace(/^file:\/\//, ""));
1846
- }
1847
- /**
1848
- * Checks if a given file id is valid based on the specified prefix.
1849
- *
1850
- * @param id - The file ID to check.
1851
- * @param prefix - The prefix to use for built-in files. Default is "powerlines".
1852
- * @returns `true` if the file ID is valid, otherwise `false`.
1853
- */
1854
- function isValidId(id, prefix = "powerlines") {
1855
- return id.replace(/^\\0/, "").startsWith(`${prefix.replace(/:$/, "")}`);
1856
- }
1857
- /**
1858
- * Formats a file id by removing the file extension and prepended runtime prefix.
1859
- *
1860
- * @param id - The file ID to format.
1861
- * @param prefix - The prefix to use for built-in files. Default is "powerlines".
1862
- * @returns The formatted file ID.
1863
- */
1864
- function normalizeId(id, prefix = "powerlines") {
1865
- return replaceExtension(toFilePath(id)).replace(/^\\0/, "").replace(/^powerlines:/, "").replace(/* @__PURE__ */ new RegExp(`^${prefix.replace(/:$/, "")}:`), "");
1866
- }
1867
- /**
1868
- * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
1869
- *
1870
- * @param path - The path to normalize.
1871
- * @param builtinsPath - The path to built-in files.
1872
- * @param prefix - The prefix to use for built-in files. Default is "powerlines".
1873
- * @returns The normalized path.
1874
- */
1875
- function normalizePath(path, builtinsPath, prefix = "powerlines") {
1876
- return isAbsolutePath(path) ? path : isValidId(toFilePath(path), prefix) ? normalizeId(toFilePath(path), prefix).replace(/* @__PURE__ */ new RegExp(`^${prefix.replace(/:$/, "")}:`), builtinsPath) : toFilePath(path);
1877
- }
1878
- /**
1879
- * Normalizes glob patterns by resolving them against the workspace root.
1880
- *
1881
- * @param workspaceRoot - The root directory of the workspace.
1882
- * @param patterns - The glob patterns to normalize.
1883
- * @returns An array of normalized glob patterns.
1884
- */
1885
- function normalizeGlobPatterns(workspaceRoot, patterns) {
1886
- return getUnique(toArray(patterns).map((pattern) => {
1887
- if (isSetObject(pattern) && (isSetString(pattern.input) || isSetString(pattern.glob))) return joinPaths$1(pattern.input || workspaceRoot, pattern.glob || "**/*");
1888
- else if (!isSetString(pattern)) return;
1889
- return pattern;
1890
- }).filter(isSetString));
1891
- }
1892
- /**
1893
- * Represents a virtual file system (VFS) that stores files and their associated metadata in virtual memory.
1894
- *
1895
- * @remarks
1896
- * This class provides methods to manage virtual files, check their existence, retrieve their content, and manipulate the virtual file system. It allows for efficient file management and retrieval without relying on the actual file system.
1897
- */
1898
- var VirtualFileSystem = class VirtualFileSystem {
1899
- /**
1900
- * A map of virtual file IDs to their associated metadata.
1901
- */
1902
- #metadata;
1903
- /**
1904
- * A map of underlying file paths to their virtual file IDs.
1905
- */
1906
- #ids;
1907
- /**
1908
- * A map of virtual file IDs to their underlying file paths.
1909
- */
1910
- #paths;
1911
- /**
1912
- * The unified volume that combines the virtual file system with the real file system.
1913
- *
1914
- * @remarks
1915
- * This volume allows for seamless access to both virtual and real files.
1916
- */
1917
- #storage;
1918
- /**
1919
- * The resolver factory used during module resolution within the virtual file system.
1920
- *
1921
- * @see https://github.com/oxc-project/oxc-resolver
1922
- */
1923
- #resolver;
1924
- /**
1925
- * A cache for module resolution results.
1926
- */
1927
- #resolverCache;
1928
- /**
1929
- * Indicator specifying if the virtual file system (VFS) is disposed
1930
- */
1931
- #isDisposed = false;
1932
- /**
1933
- * The context of the virtual file system.
1934
- */
1935
- #context;
1936
- /**
1937
- * The file system's logging function.
1938
- */
1939
- #log;
1940
- /**
1941
- * Normalizes a given module id by resolving it against the built-ins path.
1942
- *
1943
- * @param id - The module id to normalize.
1944
- * @returns The normalized module id.
1945
- */
1946
- #normalizeId(id) {
1947
- let normalized = id;
1948
- if (isParentPath(normalized, this.#context.builtinsPath)) normalized = replacePath(normalized, this.#context.builtinsPath);
1949
- return normalizeId(normalized, this.#context.config.framework);
1950
- }
1951
- /**
1952
- * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
1953
- *
1954
- * @param path - The path to normalize.
1955
- * @returns The normalized path.
1956
- */
1957
- #normalizePath(path) {
1958
- return normalizePath(path.includes("{") || path.includes("}") ? replacePathTokens(this.#context, path) : path, this.#context.builtinsPath, this.#context.config.framework);
1959
- }
1960
- /**
1961
- * Gets the storage adapter and relative key for a given key.
1962
- *
1963
- * @remarks
1964
- * The `key` can be either a path or a storage adapter name.
1965
- *
1966
- * @param key - The key to get the storage adapter for.
1967
- * @returns The storage adapter and relative key for the given key.
1968
- */
1969
- #getStorage(key, preset) {
1970
- const path = this.resolveSync(this.#normalizePath(key)) || key;
1971
- for (const base of Object.keys(this.#storage).filter(Boolean).sort().reverse()) if ((path === base || isParentPath(path, base)) && (!preset || this.#storage[base]?.preset?.toLowerCase() === preset.toLowerCase())) return {
1972
- base,
1973
- relativeKey: replacePath(path, base),
1974
- adapter: this.#storage[base]
1975
- };
1976
- if (!preset || this.#storage[""]?.preset?.toLowerCase() === preset.toLowerCase()) return {
1977
- base: "",
1978
- relativeKey: path,
1979
- adapter: this.#storage[""]
1980
- };
1981
- this.#storage[path] = preset === "virtual" ? new VirtualStorageAdapter(this.#context, { base: path }) : new FileSystemStorageAdapter(this.#context, { base: path });
1982
- return {
1983
- base: path,
1984
- relativeKey: "",
1985
- adapter: this.#storage[path]
1986
- };
1987
- }
1988
- /**
1989
- * Gets all storage adapters that match a given base key.
1990
- *
1991
- * @param base - The base key to match storage adapters against.
1992
- * @param includeParent - Whether to include parent storage adapters.
1993
- * @returns An array of storage adapters that match the given base key.
1994
- */
1995
- #getStorages(base = "", includeParent = false) {
1996
- const baseKey = this.resolveSync(base) || base;
1997
- return Object.keys(this.#storage).sort().reverse().filter((key) => isParentPath(key, baseKey) || includeParent && isParentPath(baseKey, key) || baseKey.includes("*") && (isParentPath(stripStars(baseKey), key) || globToRegex(replaceExtension(baseKey)).test(key))).map((key) => ({
1998
- relativeBase: baseKey.length > key.length ? baseKey.slice(key.length) : void 0,
1999
- base: key,
2000
- adapter: this.#storage[key]
2001
- }));
2002
- }
2003
- /**
2004
- * A helper function to resolve modules in the virtual file system (VFS).
2005
- *
2006
- * @remarks
2007
- * This function can be used to resolve modules relative to the project root directory.
2008
- *
2009
- * @example
2010
- * ```ts
2011
- * const resolved = await context.resolvePath("some-module", "/path/to/importer");
2012
- * ```
2013
- *
2014
- * @param id - The module to resolve.
2015
- * @param importer - An optional path to the importer module.
2016
- * @param options - Additional resolution options.
2017
- * @returns A promise that resolves to the resolved module path.
2018
- */
2019
- #innerResolve = async (id, importer, options = {}) => {
2020
- let path = id;
2021
- if (path.includes("{") || path.includes("}")) path = replacePathTokens(this.#context, path);
2022
- if (options.skipAlias !== true) path = this.resolveAlias(path);
2023
- if (isAbsolutePath(path) && (!options.isFile || !await this.isDirectory(path))) return path;
2024
- const resolverCacheKey = murmurhash({
2025
- path: this.#normalizeId(path),
2026
- importer,
2027
- options
2028
- });
2029
- let result;
2030
- if (!this.#context.config.skipCache) {
2031
- result = this.resolverCache.get(resolverCacheKey);
2032
- if (result) return result;
2033
- }
2034
- result = this.paths[this.#normalizeId(path)];
2035
- if (!result) {
2036
- const paths = options.paths ?? [];
2037
- if (importer && !paths.includes(importer)) paths.push(importer);
2038
- if (!importer) {
2039
- paths.push(this.#context.workspaceConfig.workspaceRoot);
2040
- paths.push(appendPath(this.#context.config.root, this.#context.workspaceConfig.workspaceRoot));
2041
- paths.push(appendPath(joinPaths$1(this.#context.config.root, "src"), this.#context.workspaceConfig.workspaceRoot));
2042
- }
2043
- paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
2044
- for (const combination of getResolutionCombinations(path, { paths })) {
2045
- const { relativeKey, adapter } = this.#getStorage(combination);
2046
- if (await adapter.exists(relativeKey)) {
2047
- result = combination;
2048
- break;
2049
- }
2050
- }
2051
- if (!result) {
2052
- try {
2053
- result = await resolve(path, {
2054
- ...options,
2055
- paths
2056
- });
2057
- } catch {}
2058
- if (!result) {
2059
- let index = 0;
2060
- do {
2061
- const resolveResult = await this.resolver.async((paths.length > index ? paths[index] : void 0) || this.#context.config.root, path);
2062
- if (resolveResult.path) result = resolveResult.path;
2063
- index++;
2064
- } while (!result && index < paths.length);
2065
- }
2066
- }
2067
- }
2068
- if (result && !this.#context.config.skipCache) this.resolverCache.set(resolverCacheKey, result);
2069
- return result;
2070
- };
2071
- /**
2072
- * A synchronous helper function to resolve modules using the Jiti resolver
2073
- *
2074
- * @remarks
2075
- * This function can be used to resolve modules relative to the project root directory.
2076
- *
2077
- * @example
2078
- * ```ts
2079
- * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
2080
- * ```
2081
- *
2082
- * @param id - The module to resolve.
2083
- * @param importer - An optional path to the importer module.
2084
- * @param options - Additional resolution options.
2085
- * @returns The resolved module path.
2086
- */
2087
- #innerResolveSync = (id, importer, options = {}) => {
2088
- let path = id;
2089
- if (path.includes("{") || path.includes("}")) path = replacePathTokens(this.#context, path);
2090
- if (options.skipAlias !== true) path = this.resolveAlias(path);
2091
- if (isAbsolutePath(path) && (!options.isFile || !this.isDirectorySync(path))) return path;
2092
- let result;
2093
- if (!this.#context.config.skipCache) {
2094
- result = this.resolverCache.get(this.#normalizeId(path));
2095
- if (result) return result;
2096
- }
2097
- result = this.paths[this.#normalizeId(path)];
2098
- if (!result) {
2099
- const paths = options.paths ?? [];
2100
- if (importer && !paths.includes(importer)) paths.push(importer);
2101
- if (!importer) {
2102
- paths.push(this.#context.workspaceConfig.workspaceRoot);
2103
- paths.push(appendPath(this.#context.config.root, this.#context.workspaceConfig.workspaceRoot));
2104
- paths.push(appendPath(joinPaths$1(this.#context.config.root, "src"), this.#context.workspaceConfig.workspaceRoot));
2105
- }
2106
- paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
2107
- for (const combination of getResolutionCombinations(path, { paths })) {
2108
- const { relativeKey, adapter } = this.#getStorage(combination);
2109
- if (adapter.existsSync(relativeKey)) {
2110
- result = combination;
2111
- break;
2112
- }
2113
- }
2114
- if (!result) {
2115
- try {
2116
- result = resolveSync(path, {
2117
- ...options,
2118
- paths
2119
- });
2120
- } catch {}
2121
- if (!result) {
2122
- let index = 0;
2123
- do {
2124
- const resolveResult = this.resolver.sync((paths.length > index ? paths[index] : void 0) || this.#context.config.root, path);
2125
- if (resolveResult.path) result = resolveResult.path;
2126
- index++;
2127
- } while (!result && index < paths.length);
2128
- }
2129
- }
2130
- }
2131
- if (result && !this.#context.config.skipCache) this.resolverCache.set(this.#normalizeId(path), result);
2132
- return result;
2133
- };
2134
- /**
2135
- * Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
2136
- *
2137
- * @param context - The context of the virtual file system, typically containing options and logging functions.
2138
- * @returns A promise that resolves to a new virtual file system instance.
2139
- */
2140
- static async create(context) {
2141
- context.debug("Starting virtual file system (VFS) initialization processes...");
2142
- let result;
2143
- if (!context.config.skipCache && existsSync(joinPaths$1(context.dataPath, "fs.bin"))) {
2144
- const buffer = await readFileBuffer(joinPaths$1(context.dataPath, "fs.bin"));
2145
- const fs = new $.Message(buffer, false).getRoot(FileSystem);
2146
- result = new VirtualFileSystem(context, fs);
2147
- if (fs._hasStorage() && fs.storage.length > 0) await Promise.all(fs.storage.values().map(async (file) => {
2148
- if (file.path && file.code) {
2149
- let id;
2150
- if (fs._hasIds()) id = fs.ids.find((fileId) => fileId.path === file.path);
2151
- let metadata;
2152
- if (fs._hasMetadata()) metadata = fs.metadata.find((meta) => meta.id === result.#normalizeId(id?.id ?? file.path));
2153
- await result.write(file.path, file.code, { meta: {
2154
- id: result.#normalizeId(id?.id ?? metadata?.id ?? file.path),
2155
- type: metadata?.type || "normal",
2156
- properties: metadata?._hasProperties() ? metadata?.properties.values().reduce((ret, kvp) => {
2157
- ret[kvp.key] = kvp.value;
2158
- return ret;
2159
- }, {}) : void 0,
2160
- timestamp: metadata?.timestamp
2161
- } });
2162
- }
2163
- }));
2164
- } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
2165
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
2166
- return result;
2167
- }
2168
- /**
2169
- * Synchronously creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
2170
- *
2171
- * @param context - The context of the virtual file system, typically containing options and logging functions.
2172
- * @returns A new virtual file system instance.
2173
- */
2174
- static createSync(context) {
2175
- context.debug("Starting virtual file system (VFS) initialization processes...");
2176
- let result;
2177
- if (!context.config.skipCache && existsSync(joinPaths$1(context.dataPath, "fs.bin"))) {
2178
- const buffer = readFileBufferSync(joinPaths$1(context.dataPath, "fs.bin"));
2179
- const fs = new $.Message(buffer, false).getRoot(FileSystem);
2180
- result = new VirtualFileSystem(context, fs);
2181
- if (fs._hasStorage() && fs.storage.length > 0) fs.storage.values().forEach((file) => {
2182
- if (file.path && file.code) {
2183
- let id;
2184
- if (fs._hasIds()) id = fs.ids.find((fileId) => fileId.path === file.path);
2185
- let metadata;
2186
- if (fs._hasMetadata()) metadata = fs.metadata.find((meta) => meta.id === result.#normalizeId(id?.id ?? file.path));
2187
- result.writeSync(file.path, file.code, { meta: {
2188
- id: result.#normalizeId(id?.id ?? metadata?.id ?? file.path),
2189
- type: metadata?.type,
2190
- properties: metadata?._hasProperties() ? metadata?.properties.values().reduce((ret, kvp) => {
2191
- ret[kvp.key] = kvp.value;
2192
- return ret;
2193
- }, {}) : void 0,
2194
- timestamp: metadata?.timestamp
2195
- } });
2196
- }
2197
- });
2198
- } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
2199
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
2200
- return result;
2201
- }
2202
- /**
2203
- * A map of file ids to their metadata.
2204
- */
2205
- get metadata() {
2206
- return new Proxy(this.#metadata, {
2207
- get: (target, prop) => {
2208
- return target[this.#normalizeId(prop)];
2209
- },
2210
- set: (target, prop, value) => {
2211
- target[this.#normalizeId(prop)] = value;
2212
- return true;
2213
- },
2214
- deleteProperty: (target, prop) => {
2215
- delete target[this.#normalizeId(prop)];
2216
- return true;
2217
- },
2218
- has: (target, prop) => {
2219
- return this.#normalizeId(prop) in target;
2220
- },
2221
- ownKeys: (target) => {
2222
- return getUnique(Reflect.ownKeys(target).map((key) => this.#normalizeId(key)));
2223
- }
2224
- });
2225
- }
2226
- /**
2227
- * A map of file paths to their module ids.
2228
- */
2229
- get ids() {
2230
- return new Proxy(this.#ids, {
2231
- get: (target, prop) => {
2232
- return target[this.#normalizePath(prop)];
2233
- },
2234
- set: (target, prop, value) => {
2235
- target[this.#normalizePath(prop)] = value;
2236
- return true;
2237
- },
2238
- deleteProperty: (target, prop) => {
2239
- delete target[this.#normalizePath(prop)];
2240
- return true;
2241
- },
2242
- has: (target, prop) => {
2243
- return this.#normalizePath(prop) in target;
2244
- },
2245
- ownKeys: (target) => {
2246
- return getUnique(Reflect.ownKeys(target).map((key) => this.#normalizePath(key)));
2247
- }
2248
- });
2249
- }
2250
- /**
2251
- * A map of module ids to their file paths.
2252
- */
2253
- get paths() {
2254
- return new Proxy(this.#paths, {
2255
- get: (target, prop) => {
2256
- return target[this.#normalizeId(prop)];
2257
- },
2258
- set: (target, prop, value) => {
2259
- target[this.#normalizeId(prop)] = value;
2260
- return true;
2261
- },
2262
- deleteProperty: (target, prop) => {
2263
- delete target[this.#normalizeId(prop)];
2264
- return true;
2265
- },
2266
- has: (target, prop) => {
2267
- return this.#normalizeId(prop) in target;
2268
- },
2269
- ownKeys: (target) => {
2270
- return getUnique(Reflect.ownKeys(target).map((key) => this.#normalizeId(key)));
2271
- }
2272
- });
2273
- }
2274
- /**
2275
- * Gets the resolver cache.
2276
- */
2277
- get resolverCache() {
2278
- if (!this.#resolverCache) this.#resolverCache = create({
2279
- cacheId: "module-resolution",
2280
- cacheDir: this.#context.cachePath,
2281
- ttl: 3600 * 1e3,
2282
- lruSize: 5e3,
2283
- persistInterval: 100
2284
- });
2285
- return this.#resolverCache;
2286
- }
2287
- /**
2288
- * The resolver factory used during module resolution within the virtual file system.
2289
- *
2290
- * @remarks
2291
- * This resolver is configured with the workspace root, project root, TypeScript configuration, alias mappings, and other resolution options specified in the context. It is lazily initialized on first access to optimize performance.
2292
- *
2293
- * @see https://github.com/oxc-project/oxc-resolver
2294
- */
2295
- get resolver() {
2296
- if (!this.#resolver) this.#resolver = new ResolverFactory({
2297
- roots: [this.#context.workspaceConfig.workspaceRoot, appendPath(this.#context.config.root, this.#context.workspaceConfig.workspaceRoot)],
2298
- tsconfig: {
2299
- configFile: this.#context.tsconfig.tsconfigFilePath,
2300
- references: this.#context.tsconfig.projectReferences && this.#context.tsconfig.projectReferences.length > 0 ? "auto" : void 0
2301
- },
2302
- alias: Object.fromEntries(Object.entries(this.#context.alias).map(([key, value]) => [key, [value]])),
2303
- extensions: this.#context.config.resolve.extensions,
2304
- mainFields: this.#context.config.resolve.mainFields,
2305
- conditionNames: this.#context.config.resolve.conditions,
2306
- symlinks: this.#context.config.resolve.preserveSymlinks,
2307
- allowPackageExportsInDirectoryResolve: true
2308
- });
2309
- return this.#resolver;
2310
- }
2311
- /**
2312
- * Creates a new instance of the {@link VirtualFileSystem}.
2313
- *
2314
- * @param context - The context of the virtual file system, typically containing options and logging functions.
2315
- * @param fs - A buffer containing the serialized virtual file system data.
2316
- */
2317
- constructor(context, fs) {
2318
- this.#context = context;
2319
- this.#storage = { "": new FileSystemStorageAdapter(context) };
2320
- if (isSetObject(this.#context.config.output.storage)) this.#storage = {
2321
- ...this.#storage,
2322
- ...this.#context.config.output.storage
2323
- };
2324
- this.#storage.virtual ??= new VirtualStorageAdapter(context, { base: "/_virtual" });
2325
- this.#storage[this.#context.config.output.outputPath] ??= new FileSystemStorageAdapter(context, { base: this.#context.config.output.outputPath });
2326
- this.#storage[this.#context.config.output.buildPath] ??= new FileSystemStorageAdapter(context, { base: this.#context.config.output.buildPath });
2327
- if (this.#context.config.output.storage !== "fs") {
2328
- this.#storage[this.#context.artifactsPath] ??= new VirtualStorageAdapter(context, { base: this.#context.artifactsPath });
2329
- this.#storage[this.#context.builtinsPath] ??= new VirtualStorageAdapter(context, { base: this.#context.builtinsPath });
2330
- this.#storage[this.#context.entryPath] ??= new VirtualStorageAdapter(context, { base: this.#context.entryPath });
2331
- }
2332
- this.#metadata = {};
2333
- if (fs._hasMetadata()) this.#metadata = fs.metadata.values().reduce((ret, metadata) => {
2334
- ret[metadata.id] = {
2335
- id: metadata.id,
2336
- type: metadata.type,
2337
- timestamp: metadata.timestamp ?? Date.now(),
2338
- properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret$1, item) => {
2339
- ret$1[item.key] = item.value;
2340
- return ret$1;
2341
- }, {}) : {}
2342
- };
2343
- return ret;
2344
- }, {});
2345
- this.#ids = {};
2346
- this.#paths = {};
2347
- if (fs._hasIds()) {
2348
- this.#ids = fs.ids.values().reduce((ret, identifier) => {
2349
- ret[identifier.path] ??= identifier.id;
2350
- return ret;
2351
- }, {});
2352
- this.#paths = fs.ids.values().reduce((ret, identifier) => {
2353
- ret[identifier.id] ??= identifier.path;
2354
- return ret;
2355
- }, {});
2356
- }
2357
- this.#log = extendLog(this.#context.log, "file-system");
2358
- }
2359
- /**
2360
- * Asynchronously checks if a file exists in the virtual file system (VFS).
2361
- *
2362
- * @param path - The path to the file.
2363
- * @returns A promise that resolves to `true` if the file exists, otherwise `false`.
2364
- */
2365
- async exists(path) {
2366
- const { relativeKey, adapter } = this.#getStorage(path);
2367
- return adapter.exists(relativeKey);
2368
- }
2369
- /**
2370
- * Synchronously checks if a file exists in the virtual file system (VFS).
2371
- *
2372
- * @param path - The path to the file.
2373
- * @returns `true` if the file exists, otherwise `false`.
2374
- */
2375
- existsSync(path) {
2376
- const { relativeKey, adapter } = this.#getStorage(path);
2377
- return adapter.existsSync(relativeKey);
2378
- }
2379
- /**
2380
- * Checks if a file is virtual in the virtual file system (VFS).
2381
- *
2382
- * @param path - The path to the file.
2383
- * @returns `true` if the file is virtual, otherwise `false`.
2384
- */
2385
- isVirtual(path) {
2386
- const resolved = this.resolveSync(path);
2387
- if (!resolved) return false;
2388
- return this.#getStorage(resolved)?.adapter?.preset === "virtual";
2389
- }
2390
- /**
2391
- * Checks if a path is a directory in the virtual file system (VFS).
2392
- *
2393
- * @param path - The path to check.
2394
- * @returns `true` if the path is a directory, otherwise `false`.
2395
- */
2396
- isDirectorySync(path) {
2397
- const resolved = this.resolveSync(path);
2398
- if (!resolved) return false;
2399
- return !!(this.existsSync(resolved) && this.#getStorage(resolved)?.adapter?.isDirectorySync(resolved));
2400
- }
2401
- /**
2402
- * Checks if a path is a directory in the virtual file system (VFS).
2403
- *
2404
- * @param path - The path to check.
2405
- * @returns `true` if the path is a directory, otherwise `false`.
2406
- */
2407
- async isDirectory(path) {
2408
- const resolved = await this.resolve(path);
2409
- if (!resolved) return false;
2410
- return !!(await this.exists(resolved) && await this.#getStorage(resolved)?.adapter?.isDirectory(resolved));
2411
- }
2412
- /**
2413
- * Checks if a path is a file in the virtual file system (VFS).
2414
- *
2415
- * @param path - The path to check.
2416
- * @returns `true` if the path is a file, otherwise `false`.
2417
- */
2418
- isFileSync(path) {
2419
- const resolved = this.resolveSync(path);
2420
- if (!resolved) return false;
2421
- return this.#getStorage(resolved)?.adapter?.isFileSync(resolved) ?? false;
2422
- }
2423
- /**
2424
- * Checks if a path is a file in the virtual file system (VFS).
2425
- *
2426
- * @param path - The path to check.
2427
- * @returns `true` if the path is a file, otherwise `false`.
2428
- */
2429
- async isFile(path) {
2430
- const resolved = await this.resolve(path);
2431
- if (!resolved) return false;
2432
- return await this.#getStorage(resolved)?.adapter?.isFile(resolved) ?? false;
2433
- }
2434
- /**
2435
- * Lists files in a given path.
2436
- *
2437
- * @param path - The path to list files from.
2438
- * @returns An array of file names in the specified path.
2439
- */
2440
- listSync(path) {
2441
- let resolvedPath = path;
2442
- if (resolvedPath.includes("*")) {
2443
- this.#log(LogLevelLabel.WARN, `Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
2444
- resolvedPath = stripStars(resolvedPath);
2445
- }
2446
- return getUnique(this.#getStorages(resolvedPath, true).map((storage) => storage.adapter.listSync(storage.relativeBase ? storage.base ? appendPath(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)).flat().filter(Boolean));
2447
- }
2448
- /**
2449
- * Lists files in a given path.
2450
- *
2451
- * @param path - The path to list files from.
2452
- * @returns An array of file names in the specified path.
2453
- */
2454
- async list(path) {
2455
- let resolvedPath = path;
2456
- if (resolvedPath.includes("*")) {
2457
- this.#log(LogLevelLabel.WARN, `Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
2458
- resolvedPath = stripStars(resolvedPath);
2459
- }
2460
- return getUnique((await Promise.all(this.#getStorages(resolvedPath, true).map(async (storage) => storage.adapter.list(storage.relativeBase ? storage.base ? appendPath(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)))).flat().filter(Boolean));
2461
- }
2462
- /**
2463
- * Removes a file in the virtual file system (VFS).
2464
- *
2465
- * @param path - The path to create the directory at.
2466
- */
2467
- async remove(path) {
2468
- const normalizedPath = this.#normalizePath(path);
2469
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
2470
- const { relativeKey, adapter } = this.#getStorage(normalizedPath);
2471
- if (hasFileExtension(normalizedPath)) await adapter.remove(relativeKey);
2472
- else await adapter.clear(relativeKey);
2473
- const id = this.#ids[normalizedPath];
2474
- if (id && this.#metadata[id]) {
2475
- delete this.#metadata[id];
2476
- delete this.#ids[normalizedPath];
2477
- delete this.#paths[id];
2478
- }
2479
- }
2480
- /**
2481
- * Removes a file in the virtual file system (VFS).
2482
- *
2483
- * @param path - The path to create the directory at.
2484
- */
2485
- removeSync(path) {
2486
- const normalizedPath = this.#normalizePath(path);
2487
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
2488
- const { relativeKey, adapter } = this.#getStorage(normalizedPath);
2489
- if (hasFileExtension(normalizedPath)) adapter.removeSync(relativeKey);
2490
- else adapter.clearSync(relativeKey);
2491
- const id = this.#ids[normalizedPath];
2492
- if (id && this.#metadata[id]) {
2493
- delete this.#metadata[id];
2494
- delete this.#ids[normalizedPath];
2495
- delete this.#paths[id];
2496
- }
2497
- }
2498
- /**
2499
- * Glob files in the virtual file system (VFS) based on the provided pattern(s).
2500
- *
2501
- * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
2502
- * @returns An array of file paths matching the provided pattern(s)
2503
- */
2504
- async glob(patterns) {
2505
- const results = [];
2506
- for (const pattern of normalizeGlobPatterns(this.#context.workspaceConfig.workspaceRoot, patterns)) {
2507
- const normalized = this.#normalizePath(pattern);
2508
- if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("*")) if (this.isDirectorySync(normalized)) results.push(...await this.list(normalized));
2509
- else {
2510
- const resolved = await this.resolve(normalized);
2511
- if (resolved && !results.includes(resolved)) results.push(resolved);
2512
- }
2513
- else {
2514
- const absPattern = isAbsolutePath(normalized) ? normalized : this.#normalizePath(appendPath(normalized, this.#context.workspaceConfig.workspaceRoot));
2515
- await Promise.all((await this.list(stripStars(absPattern))).map(async (file) => {
2516
- if (globToRegex(absPattern).test(file)) {
2517
- const resolved = await this.resolve(file);
2518
- if (resolved && !results.includes(resolved)) results.push(resolved);
2519
- }
2520
- }));
2521
- }
2522
- }
2523
- return results;
2524
- }
2525
- /**
2526
- * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
2527
- *
2528
- * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
2529
- * @returns An array of file paths matching the provided pattern(s)
2530
- */
2531
- globSync(patterns) {
2532
- const results = [];
2533
- for (const pattern of normalizeGlobPatterns(this.#context.workspaceConfig.workspaceRoot, patterns)) {
2534
- const normalized = this.#normalizePath(pattern);
2535
- if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("*")) if (this.isDirectorySync(normalized)) results.push(...this.listSync(normalized));
2536
- else {
2537
- const resolved = this.resolveSync(normalized);
2538
- if (resolved && !results.includes(resolved)) results.push(resolved);
2539
- }
2540
- else {
2541
- const absPattern = isAbsolutePath(normalized) ? normalized : this.#normalizePath(appendPath(normalized, this.#context.workspaceConfig.workspaceRoot));
2542
- const files = this.listSync(stripStars(absPattern));
2543
- for (const file of files) if (globToRegex(absPattern).test(file)) {
2544
- const resolved = this.resolveSync(file);
2545
- if (resolved && !results.includes(resolved)) results.push(resolved);
2546
- }
2547
- }
2548
- }
2549
- return results;
2550
- }
2551
- /**
2552
- * Copies a file from one path to another in the virtual file system (VFS).
2553
- *
2554
- * @param srcPath - The source path to copy
2555
- * @param destPath - The destination path to copy to
2556
- */
2557
- async copy(srcPath, destPath) {
2558
- const src = srcPath instanceof URL ? fileURLToPath(srcPath) : srcPath;
2559
- const dest = destPath instanceof URL ? fileURLToPath(destPath) : destPath;
2560
- if (!isSetString(src) && (!isSetObject(src) || !isSetString(src.input)) || !isSetString(dest)) return;
2561
- const sourceStr = isString(src) ? src : src.input ? src.input : this.#context.workspaceConfig.workspaceRoot;
2562
- const source = await this.resolve(sourceStr);
2563
- if (!source) return;
2564
- if (this.isDirectorySync(source) || isSetString(src) && src.includes("*") || isSetObject(src) && isSetString(src.glob)) await Promise.all((await this.glob(src)).map(async (file) => {
2565
- return this.copy(file, appendPath(replacePath(file, sourceStr), dest));
2566
- }));
2567
- else {
2568
- const content = await this.read(source);
2569
- if (content !== void 0) await this.write(this.#normalizePath(dest), content, { skipFormat: true });
2570
- }
2571
- }
2572
- /**
2573
- * Synchronously copies a file from one path to another in the virtual file system (VFS).
2574
- *
2575
- * @param srcPath - The source path to copy
2576
- * @param destPath - The destination path to copy to
2577
- */
2578
- copySync(srcPath, destPath) {
2579
- const src = srcPath instanceof URL ? fileURLToPath(srcPath) : srcPath;
2580
- const dest = destPath instanceof URL ? fileURLToPath(destPath) : destPath;
2581
- if (!isSetString(src) && (!isSetObject(src) || !isSetString(src.input)) || !isSetString(dest)) return;
2582
- const sourceStr = isString(src) ? src : src.input ? src.input : this.#context.workspaceConfig.workspaceRoot;
2583
- const source = this.resolveSync(sourceStr);
2584
- if (!source) return;
2585
- if (this.isDirectorySync(source) || isSetString(src) && src.includes("*") || isSetObject(src) && isSetString(src.glob)) this.globSync(src).map((file) => {
2586
- return this.copySync(file, appendPath(findFilePath(replacePath(file, sourceStr)), dest));
2587
- });
2588
- else {
2589
- const content = this.readSync(source);
2590
- if (content !== void 0) this.writeSync(this.#normalizePath(hasFileExtension(dest) ? dest : appendPath(findFileName(source), dest)), content, { skipFormat: true });
2591
- }
2592
- }
2593
- /**
2594
- * Moves a file (or files) from one path to another in the virtual file system (VFS).
2595
- *
2596
- * @param srcPath - The source path to move
2597
- * @param destPath - The destination path to move to
2598
- */
2599
- async move(srcPath, destPath) {
2600
- if (hasFileExtension(srcPath)) {
2601
- await this.copy(srcPath, destPath);
2602
- await this.remove(srcPath);
2603
- } else await Promise.all((await this.list(srcPath)).map(async (file) => {
2604
- await this.copy(file, destPath);
2605
- await this.remove(file);
2606
- }));
2607
- }
2608
- /**
2609
- * Synchronously moves a file (or files) from one path to another in the virtual file system (VFS).
2610
- *
2611
- * @param srcPath - The source path to move
2612
- * @param destPath - The destination path to move to
2613
- */
2614
- moveSync(srcPath, destPath) {
2615
- if (hasFileExtension(srcPath)) {
2616
- this.copySync(srcPath, destPath);
2617
- this.removeSync(srcPath);
2618
- } else this.listSync(srcPath).forEach((file) => {
2619
- this.copySync(file, destPath);
2620
- this.removeSync(file);
2621
- });
2622
- }
2623
- /**
2624
- * Asynchronously reads a file from the virtual file system (VFS).
2625
- *
2626
- * @param path - The path or ID of the file to read.
2627
- * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
2628
- */
2629
- async read(path) {
2630
- const filePath = await this.resolve(path, void 0, { isFile: true });
2631
- if (!filePath || !this.existsSync(filePath)) return;
2632
- const { adapter } = this.#getStorage(filePath);
2633
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
2634
- return await adapter.get(filePath) ?? void 0;
2635
- }
2636
- /**
2637
- * Synchronously reads a file from the virtual file system (VFS).
2638
- *
2639
- * @param path - The path or ID of the file to read.
2640
- * @returns The contents of the file as a string, or undefined if the file does not exist.
2641
- */
2642
- readSync(path) {
2643
- const filePath = this.resolveSync(path, void 0, { isFile: true });
2644
- if (!filePath || !this.existsSync(filePath)) return;
2645
- const { adapter } = this.#getStorage(filePath);
2646
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
2647
- return adapter.getSync(filePath) ?? void 0;
2648
- }
2649
- /**
2650
- * Writes a file to the virtual file system (VFS).
2651
- *
2652
- * @param path - The path to the file.
2653
- * @param data - The contents of the file.
2654
- * @param options - Optional parameters for writing the file.
2655
- * @returns A promise that resolves when the file is written.
2656
- */
2657
- async write(path, data = "", options = {}) {
2658
- const meta = options.meta ?? {};
2659
- const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
2660
- const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
2661
- this.#log(LogLevelLabel.TRACE, `Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(data)).size)})`);
2662
- let code = data;
2663
- try {
2664
- if (!options.skipFormat) code = await format$1(this.#context, resolvedPath, data);
2665
- } catch (err) {
2666
- if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log(LogLevelLabel.WARN, `Failed to format file ${resolvedPath} before writing: ${err.message}`);
2667
- code = data;
2668
- }
2669
- this.#log(LogLevelLabel.TRACE, `Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(code)).size)})`);
2670
- const id = this.#normalizeId(meta.id || resolvedPath);
2671
- this.metadata[id] = {
2672
- type: "normal",
2673
- timestamp: Date.now(),
2674
- ...this.metadata[id] ?? {},
2675
- ...meta
2676
- };
2677
- this.paths[id] = resolvedPath;
2678
- this.ids[resolvedPath] = id;
2679
- return adapter.set(relativeKey, code);
2680
- }
2681
- /**
2682
- * Synchronously writes a file to the virtual file system (VFS).
2683
- *
2684
- * @param path - The file to write.
2685
- * @param data - The contents of the file.
2686
- * @param options - Optional parameters for writing the file.
2687
- */
2688
- writeSync(path, data = "", options = {}) {
2689
- const meta = options.meta ?? {};
2690
- const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
2691
- const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
2692
- this.#log(LogLevelLabel.TRACE, `Writing ${resolvedPath} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(data)).size)})`);
2693
- const id = this.#normalizeId(meta.id || resolvedPath);
2694
- this.metadata[id] = {
2695
- type: "normal",
2696
- timestamp: Date.now(),
2697
- ...this.metadata[id] ?? {},
2698
- ...meta
2699
- };
2700
- this.paths[id] = resolvedPath;
2701
- this.ids[resolvedPath] = id;
2702
- return adapter.setSync(relativeKey, data);
2703
- }
2704
- /**
2705
- * Synchronously creates a directory at the specified path.
2706
- *
2707
- * @param dirPath - The path of the directory to create.
2708
- */
2709
- mkdirSync(dirPath) {
2710
- return this.#getStorage(dirPath)?.adapter?.mkdirSync(dirPath);
2711
- }
2712
- /**
2713
- * Creates a directory at the specified path.
2714
- *
2715
- * @param path - The path of the directory to create.
2716
- */
2717
- async mkdir(path) {
2718
- return this.#getStorage(path)?.adapter?.mkdir(path);
2719
- }
2720
- /**
2721
- * Retrieves the metadata of a file in the virtual file system (VFS).
2722
- *
2723
- * @param pathOrId - The path or ID of the file to retrieve metadata for.
2724
- * @returns The metadata of the file, or undefined if the file does not exist.
2725
- */
2726
- getMetadata(pathOrId) {
2727
- const resolved = this.resolveSync(pathOrId);
2728
- if (resolved && this.metadata[resolved]) return this.metadata[resolved];
2729
- }
2730
- /**
2731
- * Resolves a given module ID using the configured aliases.
2732
- *
2733
- * @remarks
2734
- * This function can be used to map module IDs to different paths based on the alias configuration.
2735
- *
2736
- * @param id - The module ID to resolve.
2737
- * @returns The resolved module ID - after applying any configured aliases (this will be the same as the input ID if no aliases match).
2738
- */
2739
- resolveAlias(id) {
2740
- let path = id;
2741
- if (this.#context.config.resolve.alias) {
2742
- if (Array.isArray(this.#context.config.resolve.alias) && this.#context.config.resolve.alias.length > 0) {
2743
- const found = this.#context.config.resolve.alias.filter((alias) => isSetString(alias.find) && (alias.find === path || path.startsWith(`${alias.find}/`)) || isRegExp(alias.find) && alias.find.test(path));
2744
- if (found.length > 0) {
2745
- const alias = found.reduce((ret, current) => {
2746
- return (isSetString(ret.find) ? ret.find.length : isRegExp(ret.find) ? ret.find.source.length : 0) > (isSetString(current.find) ? current.find.length : isRegExp(current.find) ? current.find.source.length : 0) ? ret : current;
2747
- });
2748
- if (isSetString(alias.find)) path = path.replace(/* @__PURE__ */ new RegExp(`^${alias.find}`), alias.replacement);
2749
- else if (isRegExp(alias.find)) path = path.replace(alias.find, alias.replacement);
2750
- }
2751
- } else if (isSetObject(this.#context.config.resolve.alias)) {
2752
- const found = Object.keys(this.#context.config.resolve.alias).filter((key) => key === path || path.startsWith(`${key}/`));
2753
- if (found.length > 0) {
2754
- const alias = found.reduce((ret, current) => {
2755
- return ret.length > current.length ? ret : current;
2756
- });
2757
- path = path.replace(/* @__PURE__ */ new RegExp(`^${alias}`), this.#context.config.resolve.alias[alias]);
2758
- }
2759
- }
2760
- }
2761
- return path;
2762
- }
2763
- /**
2764
- * A helper function to resolve modules in the virtual file system (VFS).
2765
- *
2766
- * @remarks
2767
- * This function can be used to resolve modules relative to the project root directory.
2768
- *
2769
- * @example
2770
- * ```ts
2771
- * const resolved = await context.resolvePath("some-module", "/path/to/importer");
2772
- * ```
2773
- *
2774
- * @param id - The module to resolve.
2775
- * @param importer - An optional path to the importer module.
2776
- * @param options - Additional resolution options.
2777
- * @returns A promise that resolves to the resolved module path.
2778
- */
2779
- async resolve(id, importer, options = {}) {
2780
- const origResult = await this.#innerResolve(id, importer, options);
2781
- if (origResult && options.isFile && await this.isDirectory(origResult)) {
2782
- const indexResult = await this.resolve(joinPaths$1(origResult, "index"), importer, options);
2783
- if (indexResult) return indexResult;
2784
- if (!hasFileExtension(origResult)) for (const ext of DEFAULT_EXTENSIONS) {
2785
- const extResult = await this.resolve(`${origResult}.${ext}`, importer, options);
2786
- if (extResult) return extResult;
2787
- }
2788
- return;
2789
- }
2790
- return origResult;
2791
- }
2792
- /**
2793
- * A synchronous helper function to resolve modules using the Jiti resolver
2794
- *
2795
- * @remarks
2796
- * This function can be used to resolve modules relative to the project root directory.
2797
- *
2798
- * @example
2799
- * ```ts
2800
- * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
2801
- * ```
2802
- *
2803
- * @param id - The module to resolve.
2804
- * @param importer - An optional path to the importer module.
2805
- * @param options - Additional resolution options.
2806
- * @returns The resolved module path.
2807
- */
2808
- resolveSync(id, importer, options = {}) {
2809
- const origResult = this.#innerResolveSync(id, importer, options);
2810
- if (origResult && options.isFile && this.isDirectorySync(origResult)) {
2811
- const indexResult = this.resolveSync(joinPaths$1(origResult, "index"), importer, options);
2812
- if (indexResult) return indexResult;
2813
- if (!hasFileExtension(origResult)) for (const ext of DEFAULT_EXTENSIONS) {
2814
- const extResult = this.resolveSync(`${origResult}.${ext}`, importer, options);
2815
- if (extResult) return extResult;
2816
- }
2817
- return;
2818
- }
2819
- return origResult;
2820
- }
2821
- /**
2822
- * Disposes of the virtual file system (VFS) by saving its state to disk.
2823
- */
2824
- async dispose() {
2825
- if (!this.#isDisposed) {
2826
- this.#isDisposed = true;
2827
- this.#log(LogLevelLabel.DEBUG, "Disposing virtual file system...");
2828
- await this.remove(joinPaths$1(this.#context.dataPath, "fs.bin"));
2829
- const message = new $.Message();
2830
- const fs = message.initRoot(FileSystem);
2831
- const storage = fs._initStorage(Object.keys(this.#paths).length);
2832
- await Promise.all(Object.values(this.#paths).map(async (path, index) => {
2833
- const code = await this.read(path);
2834
- const fd = storage.get(index);
2835
- fd.path = path;
2836
- fd.code = code || "";
2837
- }));
2838
- const ids = fs._initIds(Object.keys(this.#ids).length);
2839
- Object.entries(this.#ids).filter(([, id]) => id).forEach(([path, id], index) => {
2840
- const fileId = ids.get(index);
2841
- fileId.id = id;
2842
- fileId.path = path;
2843
- });
2844
- const metadata = fs._initMetadata(Object.keys(this.#metadata).length);
2845
- Object.entries(this.#metadata).filter(([, value]) => value).forEach(([id, value], index) => {
2846
- const fileMetadata = metadata.get(index);
2847
- fileMetadata.id = id;
2848
- fileMetadata.type = value.type;
2849
- fileMetadata.timestamp = value.timestamp ?? Date.now();
2850
- if (value.properties) {
2851
- const props = fileMetadata._initProperties(Object.keys(value.properties).length);
2852
- Object.entries(value.properties).filter(([, val]) => isSetString(val)).forEach(([key, val], index$1) => {
2853
- const prop = props.get(index$1);
2854
- prop.key = key;
2855
- prop.value = val;
2856
- });
2857
- }
2858
- });
2859
- await writeFileBuffer(joinPaths$1(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
2860
- if (!this.#context.config.skipCache) this.#resolverCache.save(true);
2861
- await Promise.all(this.#getStorages().map(async (storage$1) => storage$1.adapter.dispose()));
2862
- this.#log(LogLevelLabel.TRACE, "Virtual file system has been disposed.");
2863
- }
2864
- }
2865
- async [Symbol.asyncDispose]() {
2866
- return this.dispose();
2867
- }
2868
- };
2869
-
2870
- //#endregion
2871
- //#region ../powerlines/src/context/context.ts
2872
- const configCache = /* @__PURE__ */ new WeakMap();
2873
- const envPathCache = /* @__PURE__ */ new WeakMap();
2874
- setGlobalDispatcher(new Agent({ keepAliveTimeout: 1e4 }).compose(interceptors.retry({
2875
- maxRetries: 3,
2876
- minTimeout: 1e3,
2877
- maxTimeout: 1e4,
2878
- timeoutFactor: 2,
2879
- retryAfter: true
2880
- })));
2881
- var PowerlinesContext = class PowerlinesContext {
2882
- /**
2883
- * Internal references storage
2884
- *
2885
- * @danger
2886
- * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
2887
- *
2888
- * @internal
2889
- */
2890
- #internal = {};
2891
- #workspaceConfig;
2892
- #checksum = null;
2893
- #buildId = uuid();
2894
- #releaseId = uuid();
2895
- #timestamp = Date.now();
2896
- #fs;
2897
- #tsconfig;
2898
- #parserCache;
2899
- #requestCache;
2900
- #getConfigProps(config = {}) {
2901
- return mergeConfig({
2902
- root: config.root,
2903
- name: config.name,
2904
- title: config.title,
2905
- organization: config.organization,
2906
- compatibilityDate: resolveCompatibilityDates(config.compatibilityDate, "latest"),
2907
- description: config.description,
2908
- configFile: config.configFile,
2909
- projectType: config.projectType,
2910
- customLogger: config.customLogger,
2911
- logLevel: config.logLevel,
2912
- tsconfig: config.tsconfig,
2913
- tsconfigRaw: config.tsconfigRaw,
2914
- skipCache: config.skipCache,
2915
- autoInstall: config.autoInstall,
2916
- input: config.input,
2917
- output: config.output,
2918
- plugins: config.plugins,
2919
- mode: config.mode,
2920
- resolve: config.resolve,
2921
- framework: config.framework,
2922
- ...config
2923
- }, { output: config.framework ? {
2924
- artifactsPath: `.${config.framework ?? "powerlines"}`,
2925
- dts: joinPaths$1(config.root ?? this.config.root, `${config.framework ?? "powerlines"}.d.ts`)
2926
- } : {} });
2927
- }
2928
- /**
2929
- * Create a new Storm context from the workspace root and user config.
2930
- *
2931
- * @param workspaceRoot - The root directory of the workspace.
2932
- * @param config - The user configuration options.
2933
- * @returns A promise that resolves to the new context.
2934
- */
2935
- static async from(workspaceRoot, config) {
2936
- const context = new PowerlinesContext(await loadWorkspaceConfig(workspaceRoot, config.root));
2937
- await context.withUserConfig(config);
2938
- const powerlinesPath = await resolvePackage("powerlines");
2939
- if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
2940
- context.powerlinesPath = powerlinesPath;
2941
- return context;
2942
- }
2943
- /**
2944
- * An object containing the dependencies that should be installed for the project
2945
- */
2946
- dependencies = {};
2947
- /**
2948
- * An object containing the development dependencies that should be installed for the project
2949
- */
2950
- devDependencies = {};
2951
- /**
2952
- * The persisted meta information about the current build
2953
- */
2954
- persistedMeta = void 0;
2955
- /**
2956
- * The path to the Powerlines package
2957
- */
2958
- powerlinesPath;
2959
- /**
2960
- * The parsed `package.json` file for the project
2961
- */
2962
- packageJson;
2963
- /**
2964
- * The parsed `project.json` file for the project
2965
- */
2966
- projectJson = void 0;
2967
- /**
2968
- * The module resolver for the project
2969
- */
2970
- resolver;
2971
- /**
2972
- * The resolved configuration options
2973
- */
2974
- resolvePatterns = [];
2975
- /**
2976
- * Internal context fields and methods
2977
- *
2978
- * @danger
2979
- * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
2980
- *
2981
- * @internal
2982
- */
2983
- get $$internal() {
2984
- return this.#internal;
2985
- }
2986
- /**
2987
- * Internal context fields and methods
2988
- *
2989
- * @danger
2990
- * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
2991
- *
2992
- * @internal
2993
- */
2994
- set $$internal(value) {
2995
- this.#internal = value;
2996
- }
2997
- /**
2998
- * The resolved entry type definitions for the project
2999
- */
3000
- get entry() {
3001
- const entry = this.resolvedEntry;
3002
- return resolveInputsSync(this, entry && entry.length > 0 ? entry : Array.isArray(this.config.input) || isSetObject(this.config.input) && !isTypeDefinition(this.config.input) ? this.config.input : toArray(this.config.input).flat());
3003
- }
3004
- /**
3005
- * The TypeScript configuration parsed from the tsconfig file
3006
- */
3007
- get tsconfig() {
3008
- if (!this.#tsconfig) this.tsconfig = { tsconfigFilePath: this.config.tsconfig };
3009
- return this.#tsconfig;
3010
- }
3011
- /**
3012
- * Sets the TypeScript configuration parsed from the tsconfig file
3013
- */
3014
- set tsconfig(value) {
3015
- this.#tsconfig = value;
3016
- this.resolvePatterns = tsconfigPathsToRegExp(value?.options?.paths ?? {});
3017
- }
3018
- /**
3019
- * The virtual file system interface for the project
3020
- */
3021
- get fs() {
3022
- if (!this.#fs) this.#fs = VirtualFileSystem.createSync(this);
3023
- return this.#fs;
3024
- }
3025
- /**
3026
- * Get the checksum of the project's current state
3027
- */
3028
- get checksum() {
3029
- return this.#checksum;
3030
- }
3031
- /**
3032
- * The meta information about the current build
3033
- */
3034
- get meta() {
3035
- return {
3036
- buildId: this.#buildId,
3037
- releaseId: this.#releaseId,
3038
- checksum: this.#checksum,
3039
- timestamp: this.#timestamp,
3040
- rootHash: murmurhash({
3041
- workspaceRoot: this.workspaceConfig?.workspaceRoot,
3042
- root: this.config?.root
3043
- }, { maxLength: ROOT_HASH_LENGTH }),
3044
- configHash: murmurhash(this.config, { maxLength: CACHE_HASH_LENGTH })
3045
- };
3046
- }
3047
- /**
3048
- * The resolved configuration options
3049
- */
3050
- get config() {
3051
- return this.resolvedConfig ?? {};
3052
- }
3053
- /**
3054
- * The logger function
3055
- */
3056
- get log() {
3057
- if (!this.logFn) this.logFn = this.createLog();
3058
- return this.logFn;
3059
- }
3060
- /**
3061
- * The workspace configuration
3062
- */
3063
- get workspaceConfig() {
3064
- return this.#workspaceConfig;
3065
- }
3066
- /**
3067
- * The environment paths for the project
3068
- */
3069
- get envPaths() {
3070
- if (envPathCache.has({
3071
- workspaceRoot: this.workspaceConfig.workspaceRoot,
3072
- framework: this.config?.framework || "powerlines"
3073
- })) return envPathCache.get({
3074
- workspaceRoot: this.workspaceConfig.workspaceRoot,
3075
- framework: this.config?.framework || "powerlines"
3076
- });
3077
- const envPaths = getEnvPaths({
3078
- orgId: "storm-software",
3079
- appId: this.config?.framework || "powerlines",
3080
- workspaceRoot: this.workspaceConfig.workspaceRoot
3081
- });
3082
- envPathCache.set({
3083
- workspaceRoot: this.workspaceConfig.workspaceRoot,
3084
- framework: this.config?.framework || "powerlines"
3085
- }, envPaths);
3086
- return envPaths;
3087
- }
3088
- /**
3089
- * Get the path to the artifacts directory for the project
3090
- */
3091
- get artifactsPath() {
3092
- return joinPaths$1(this.workspaceConfig.workspaceRoot, this.config.root, this.config.output.artifactsPath);
3093
- }
3094
- /**
3095
- * Get the path to the builtin modules used by the project
3096
- */
3097
- get builtinsPath() {
3098
- return joinPaths$1(this.artifactsPath, "builtins");
3099
- }
3100
- /**
3101
- * Get the path to the entry directory for the project
3102
- */
3103
- get entryPath() {
3104
- return joinPaths$1(this.artifactsPath, "entry");
3105
- }
3106
- /**
3107
- * Get the path to the infrastructure modules used by the project
3108
- */
3109
- get infrastructurePath() {
3110
- return joinPaths$1(this.artifactsPath, "infrastructure");
3111
- }
3112
- /**
3113
- * Get the path to the data directory for the project
3114
- */
3115
- get dataPath() {
3116
- return joinPaths$1(this.envPaths.data, "projects", getPrefixedRootHash(this.config.name, this.meta.rootHash));
3117
- }
3118
- /**
3119
- * Get the path to the cache directory for the project
3120
- */
3121
- get cachePath() {
3122
- return joinPaths$1(this.envPaths.cache, "projects", murmurhash({
3123
- checksum: this.#checksum,
3124
- config: this.meta.configHash
3125
- }, { maxLength: CACHE_HASH_LENGTH }));
3126
- }
3127
- /**
3128
- * Get the path to the generated declaration file for the project
3129
- */
3130
- get dtsPath() {
3131
- return this.config.output.dts ? appendPath(this.config.output.dts, this.workspaceConfig.workspaceRoot) : joinPaths$1(this.workspaceConfig.workspaceRoot, this.config.root, "powerlines.d.ts");
3132
- }
3133
- /**
3134
- * Get the project root relative to the workspace root
3135
- */
3136
- get relativeToWorkspaceRoot() {
3137
- return relativeToWorkspaceRoot(this.config.root);
3138
- }
3139
- /**
3140
- * The builtin module id that exist in the Powerlines virtual file system
3141
- */
3142
- get builtins() {
3143
- return Object.values(this.fs.metadata).filter((meta) => meta && meta.type === "builtin").map((meta) => meta?.id).filter(Boolean);
3144
- }
3145
- /**
3146
- * The alias mappings for the project used during module resolution
3147
- *
3148
- * @remarks
3149
- * This includes both the built-in module aliases as well as any custom aliases defined in the build configuration.
3150
- */
3151
- get alias() {
3152
- return this.builtins.reduce((ret, id) => {
3153
- const moduleId = `${this.config?.framework || "powerlines"}:${id.replace(/^.*?:/, "")}`;
3154
- if (!ret[moduleId]) {
3155
- const path = this.fs.paths[id];
3156
- if (path) ret[moduleId] = path;
3157
- }
3158
- return ret;
3159
- }, this.config.resolve.alias ? Array.isArray(this.config.resolve.alias) ? this.config.resolve.alias.reduce((ret, alias) => {
3160
- if (!ret[alias.find.toString()]) ret[alias.find.toString()] = alias.replacement;
3161
- return ret;
3162
- }, {}) : this.config.resolve.alias : {});
3163
- }
3164
- /**
3165
- * Gets the parser cache.
3166
- */
3167
- get parserCache() {
3168
- if (!this.#parserCache) this.#parserCache = create({
3169
- cacheId: "parser",
3170
- cacheDir: this.cachePath,
3171
- ttl: 7200 * 1e3,
3172
- lruSize: 5e3,
3173
- persistInterval: 250
3174
- });
3175
- return this.#parserCache;
3176
- }
3177
- /**
3178
- * Gets the request cache.
3179
- */
3180
- get requestCache() {
3181
- if (!this.#requestCache) this.#requestCache = create({
3182
- cacheId: "http",
3183
- cacheDir: this.cachePath,
3184
- ttl: 360 * 60 * 1e3,
3185
- lruSize: 5e3,
3186
- persistInterval: 250
3187
- });
3188
- return this.#requestCache;
3189
- }
3190
- /**
3191
- * The entry points that exist in the Powerlines virtual file system
3192
- */
3193
- get resolvedEntry() {
3194
- return Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "entry").map(([path, meta]) => {
3195
- const typeDefinition = { file: path };
3196
- if (meta.properties) {
3197
- if (isSetString(meta.properties.file)) typeDefinition.file = meta.properties.file;
3198
- if (isSetString(meta.properties.name)) typeDefinition.name = meta.properties.name;
3199
- if (isSetString(meta.properties["input.file"]) || isSetString(meta.properties["input.name"])) {
3200
- typeDefinition.input ??= {};
3201
- if (isSetString(meta.properties["input.file"])) typeDefinition.input.file = meta.properties["input.file"];
3202
- if (isSetString(meta.properties["input.name"])) typeDefinition.input.name = meta.properties["input.name"];
3203
- }
3204
- if (isSetString(meta.properties.output)) typeDefinition.output = meta.properties.output;
3205
- }
3206
- return typeDefinition;
3207
- }).filter(Boolean);
3208
- }
3209
- /**
3210
- * A function to perform HTTP fetch requests
3211
- *
3212
- * @remarks
3213
- * This function uses a caching layer to avoid duplicate requests during the Powerlines process.
3214
- *
3215
- * @example
3216
- * ```ts
3217
- * const response = await context.fetch("https://api.example.com/data");
3218
- * const data = await response.json();
3219
- * ```
3220
- *
3221
- * @see https://github.com/nodejs/undici
3222
- *
3223
- * @param input - The URL to fetch.
3224
- * @param options - The fetch request options.
3225
- * @returns A promise that resolves to a response returned by the fetch.
3226
- */
3227
- async fetch(input, options = {}) {
3228
- const cacheKey = murmurhash({
3229
- input: input.toString(),
3230
- options: JSON.stringify(options)
3231
- });
3232
- if (!this.config.skipCache && !options.skipCache) {
3233
- const cached = this.requestCache.get(cacheKey);
3234
- if (cached) return new Response(cached.body, {
3235
- status: cached.status,
3236
- statusText: cached.statusText,
3237
- headers: cached.headers
3238
- });
3239
- }
3240
- const response = await fetchRequest(input, {
3241
- timeout: 12e3,
3242
- ...options
3243
- });
3244
- const result = {
3245
- body: await response.text(),
3246
- status: response.status,
3247
- statusText: response.statusText,
3248
- headers: Object.fromEntries(response.headers.entries())
3249
- };
3250
- if (!this.config.skipCache && !options.skipCache) try {
3251
- this.requestCache.set(cacheKey, result);
3252
- } catch {}
3253
- return new Response(result.body, {
3254
- status: result.status,
3255
- statusText: result.statusText,
3256
- headers: result.headers
3257
- });
3258
- }
3259
- /**
3260
- * Parse code using [Oxc-Parser](https://github.com/oxc/oxc) into an (ESTree-compatible)[https://github.com/estree/estree] AST object.
3261
- *
3262
- * @remarks
3263
- * This function can be used to parse TypeScript code into an AST for further analysis or transformation.
3264
- *
3265
- * @example
3266
- * ```ts
3267
- * const ast = context.parse("const x: number = 42;");
3268
- * ```
3269
- *
3270
- * @see https://rollupjs.org/plugin-development/#this-parse
3271
- * @see https://github.com/oxc/oxc
3272
- *
3273
- * @param code - The source code to parse.
3274
- * @param options - The options to pass to the parser.
3275
- * @returns An (ESTree-compatible)[https://github.com/estree/estree] AST object.
3276
- */
3277
- async parse(code, options = {}) {
3278
- const cacheKey = murmurhash({
3279
- code,
3280
- options
3281
- });
3282
- let result;
3283
- if (!this.config.skipCache) {
3284
- result = this.parserCache.get(cacheKey);
3285
- if (result) return result;
3286
- }
3287
- result = await parse(`source.${options.lang || "ts"}`, code, {
3288
- ...options,
3289
- sourceType: "module",
3290
- showSemanticErrors: this.config.mode === "development"
3291
- });
3292
- if (!this.config.skipCache) this.parserCache.set(cacheKey, result);
3293
- return result;
3294
- }
3295
- /**
3296
- * A helper function to resolve modules in the Virtual File System
3297
- *
3298
- * @remarks
3299
- * This function can be used to resolve modules relative to the project root directory.
3300
- *
3301
- * @example
3302
- * ```ts
3303
- * const resolved = await context.resolve("some-module", "/path/to/importer");
3304
- * ```
3305
- *
3306
- * @param id - The module to resolve.
3307
- * @param importer - An optional path to the importer module.
3308
- * @param options - Additional resolution options.
3309
- * @returns A promise that resolves to the resolved module path.
3310
- */
3311
- async resolve(id, importer, options = {}) {
3312
- let moduleId = id;
3313
- if (this.config.resolve.alias) {
3314
- if (Array.isArray(this.config.resolve.alias)) {
3315
- const alias = this.config.resolve.alias.find((a) => match(moduleId, [a.find]));
3316
- if (alias) moduleId = alias.replacement;
3317
- } else if (isSetObject(this.config.resolve.alias) && this.config.resolve.alias[id]) moduleId = this.config.resolve.alias[id];
3318
- }
3319
- if (this.fs.isVirtual(moduleId) || importer && this.fs.isVirtual(importer)) {
3320
- let resolvedImporter = importer;
3321
- if (importer && this.fs.isVirtual(importer)) resolvedImporter = await this.fs.resolve(importer, void 0, {
3322
- conditions: this.config.resolve.conditions,
3323
- extensions: this.config.resolve.extensions,
3324
- ...options
3325
- });
3326
- const result = await this.fs.resolve(moduleId, resolvedImporter, {
3327
- conditions: this.config.resolve.conditions,
3328
- extensions: this.config.resolve.extensions,
3329
- ...options
3330
- });
3331
- if (!result) return;
3332
- const external = !match(moduleId, this.config.resolve.noExternal) && (match(moduleId, this.config.resolve.external) || moduleId.startsWith("node:") || this.fs.isVirtual(moduleId) && this.config.projectType !== "application" || this.config.resolve.skipNodeModulesBundle && !/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(moduleId));
3333
- return {
3334
- id: result,
3335
- external,
3336
- virtual: !external
3337
- };
3338
- }
3339
- if (this.config.resolve.skipNodeModulesBundle) {
3340
- if (match(moduleId, this.resolvePatterns) || match(moduleId, this.config.resolve.noExternal)) return;
3341
- if (match(moduleId, this.config.resolve.external) || moduleId.startsWith("node:")) return {
3342
- id: moduleId,
3343
- external: true,
3344
- virtual: false
3345
- };
3346
- if (!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(moduleId)) return {
3347
- id: moduleId,
3348
- external: true,
3349
- virtual: false
3350
- };
3351
- } else {
3352
- if (match(moduleId, this.config.resolve.noExternal)) return;
3353
- if (match(moduleId, this.config.resolve.external) || moduleId.startsWith("node:")) return {
3354
- id: moduleId,
3355
- external: true,
3356
- virtual: false
3357
- };
3358
- }
3359
- }
3360
- /**
3361
- * A helper function to load modules from the Virtual File System
3362
- *
3363
- * @remarks
3364
- * This function can be used to load modules relative to the project root directory.
3365
- *
3366
- * @example
3367
- * ```ts
3368
- * const module = await context.load("some-module", "/path/to/importer");
3369
- * ```
3370
- *
3371
- * @param id - The module to load.
3372
- * @returns A promise that resolves to the loaded module.
3373
- */
3374
- async load(id) {
3375
- const resolvedId = await this.fs.resolve(id);
3376
- if (!resolvedId) return;
3377
- const code = await this.fs.read(resolvedId);
3378
- if (!code) return;
3379
- return {
3380
- code,
3381
- map: null
3382
- };
3383
- }
3384
- /**
3385
- * Get the builtin virtual files that exist in the Powerlines virtual file system
3386
- */
3387
- async getBuiltins() {
3388
- return Promise.all(Object.entries(this.fs.metadata).filter(([, meta]) => meta && meta.type === "builtin").map(async ([id, meta]) => {
3389
- const code = await this.fs.read(id);
3390
- const path = this.fs.paths[id];
3391
- return {
3392
- ...meta,
3393
- path,
3394
- code
3395
- };
3396
- }));
3397
- }
3398
- /**
3399
- * Resolves a file and writes it to the VFS if it does not already exist
3400
- *
3401
- * @param code - The source code of the file
3402
- * @param path - The path to write the file to
3403
- * @param options - Additional options for writing the file
3404
- */
3405
- async emit(code, path, options = {}) {
3406
- const filePath = options.extension ? findFileExtensionSafe(path) ? options.extension.startsWith(".") ? path.replace(findFileDotExtensionSafe(path), options.extension) : path.replace(findFileExtensionSafe(path), options.extension) : options.extension.startsWith(".") ? `${path}${options.extension}` : `${path}.${options.extension}` : findFileExtensionSafe(path) ? path : `${path}.ts`;
3407
- if (isFunction(this.emitFile) && options.emitWithBundler) return this.emitFile({
3408
- needsCodeReference: options.needsCodeReference,
3409
- originalFileName: options.originalFileName,
3410
- fileName: filePath,
3411
- source: code,
3412
- type: "asset"
3413
- });
3414
- return this.fs.write(filePath, code, options);
3415
- }
3416
- /**
3417
- * Synchronously resolves a file and writes it to the VFS if it does not already exist
3418
- *
3419
- * @param code - The source code of the file
3420
- * @param path - The path to write the file to
3421
- * @param options - Additional options for writing the file
3422
- */
3423
- emitSync(code, path, options = {}) {
3424
- const filePath = options.extension ? findFileExtensionSafe(path) ? options.extension.startsWith(".") ? path.replace(findFileDotExtensionSafe(path), options.extension) : path.replace(findFileExtensionSafe(path), options.extension) : options.extension.startsWith(".") ? `${path}${options.extension}` : `${path}.${options.extension}` : findFileExtensionSafe(path) ? path : `${path}.ts`;
3425
- if (isFunction(this.emitFile) && options.emitWithBundler) return this.emitFile({
3426
- needsCodeReference: options.needsCodeReference,
3427
- originalFileName: options.originalFileName,
3428
- fileName: filePath,
3429
- source: code,
3430
- type: "asset"
3431
- });
3432
- return this.fs.writeSync(filePath, code, options);
3433
- }
3434
- /**
3435
- * Resolves a entry virtual file and writes it to the VFS if it does not already exist
3436
- *
3437
- * @param code - The source code of the entry file
3438
- * @param path - A path to write the entry file to
3439
- * @param options - Optional write file options
3440
- */
3441
- async emitEntry(code, path, options = {}) {
3442
- return this.emit(code, appendPath(path, this.entryPath), defu$1({ meta: {
3443
- type: "entry",
3444
- properties: {
3445
- file: appendPath(path, this.entryPath),
3446
- name: options?.name,
3447
- output: options?.output,
3448
- "input.file": options?.input?.file,
3449
- "input.name": options?.input?.name
3450
- }
3451
- } }, omit(options, ["name"])));
3452
- }
3453
- /**
3454
- * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
3455
- *
3456
- * @param code - The source code of the entry file
3457
- * @param path - A path to write the entry file to
3458
- * @param options - Optional write file options
3459
- */
3460
- emitEntrySync(code, path, options = {}) {
3461
- return this.emitSync(code, appendPath(path, this.entryPath), defu$1({ meta: {
3462
- type: "entry",
3463
- properties: {
3464
- file: appendPath(path, this.entryPath),
3465
- name: options?.name,
3466
- output: options?.output,
3467
- "input.file": options?.input?.file,
3468
- "input.name": options?.input?.name
3469
- }
3470
- } }, omit(options, ["name"])));
3471
- }
3472
- /**
3473
- * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
3474
- *
3475
- * @param code - The source code of the builtin file
3476
- * @param id - The unique identifier of the builtin file
3477
- * @param options - Optional write file options
3478
- */
3479
- async emitBuiltin(code, id, options = {}) {
3480
- if (!this.builtinsPath) throw new Error(`The builtins path is not set. Cannot emit builtin file with id "${id}".`);
3481
- if (!isSetString(id)) throw new Error(`The builtin id must be a non-empty string. Received: ${String(id)}`);
3482
- return this.emit(code, appendPath(id, this.builtinsPath), defu$1(options, { meta: {
3483
- type: "builtin",
3484
- id
3485
- } }));
3486
- }
3487
- /**
3488
- * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
3489
- *
3490
- * @param code - The source code of the builtin file
3491
- * @param id - The unique identifier of the builtin file
3492
- * @param options - Optional write file options
3493
- */
3494
- emitBuiltinSync(code, id, options = {}) {
3495
- if (!this.builtinsPath) throw new Error(`The builtins path is not set. Cannot emit builtin file with id "${id}".`);
3496
- if (!isSetString(id)) throw new Error(`The builtin id must be a non-empty string. Received: ${String(id)}`);
3497
- return this.emitSync(code, appendPath(id, this.builtinsPath), defu$1(options, { meta: {
3498
- type: "builtin",
3499
- id
3500
- } }));
3501
- }
3502
- /**
3503
- * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
3504
- *
3505
- * @param code - The source code of the builtin file
3506
- * @param id - The unique identifier of the builtin file
3507
- * @param options - Optional write file options
3508
- */
3509
- async emitInfrastructure(code, id, options = {}) {
3510
- if (!this.infrastructurePath) throw new Error(`The infrastructure path is not set. Cannot emit infrastructure file with id "${id}".`);
3511
- if (!isSetString(id)) throw new Error(`The infrastructure id must be a non-empty string. Received: ${String(id)}`);
3512
- return this.emit(code, appendPath(id, this.infrastructurePath), defu$1(options, { meta: {
3513
- type: "infrastructure",
3514
- id
3515
- } }));
3516
- }
3517
- /**
3518
- * Synchronously resolves an infrastructure virtual file and writes it to the VFS if it does not already exist
3519
- *
3520
- * @param code - The source code of the infrastructure file
3521
- * @param id - The unique identifier of the infrastructure file
3522
- * @param options - Optional write file options
3523
- */
3524
- emitInfrastructureSync(code, id, options = {}) {
3525
- if (!this.infrastructurePath) throw new Error(`The infrastructure path is not set. Cannot emit infrastructure file with id "${id}".`);
3526
- if (!isSetString(id)) throw new Error(`The infrastructure id must be a non-empty string. Received: ${String(id)}`);
3527
- return this.emitSync(code, appendPath(id, this.infrastructurePath), defu$1(options, { meta: {
3528
- type: "infrastructure",
3529
- id
3530
- } }));
3531
- }
3532
- /**
3533
- * Update the context using a new user configuration options
3534
- *
3535
- * @param userConfig - The new user configuration options.
3536
- */
3537
- async withUserConfig(userConfig, options = { isHighPriority: true }) {
3538
- this.mergeUserConfig(userConfig);
3539
- await this.init(this.config.userConfig, options);
3540
- }
3541
- /**
3542
- * Update the context using a new inline configuration options
3543
- *
3544
- * @param inlineConfig - The new inline configuration options.
3545
- */
3546
- async withInlineConfig(inlineConfig, options = { isHighPriority: true }) {
3547
- this.config.inlineConfig = inlineConfig;
3548
- if (inlineConfig.command === "new") {
3549
- const workspacePackageJsonPath = joinPaths$1(this.workspaceConfig.workspaceRoot, "package.json");
3550
- if (!existsSync(workspacePackageJsonPath)) throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
3551
- this.packageJson = await readJsonFile(workspacePackageJsonPath);
3552
- this.workspaceConfig.repository ??= isSetString(this.packageJson?.repository) ? this.packageJson.repository : this.packageJson?.repository?.url;
3553
- }
3554
- await this.init(this.config.inlineConfig, options);
3555
- }
3556
- /**
3557
- * A logging function for fatal messages
3558
- *
3559
- * @param message - The message to log.
3560
- */
3561
- fatal(message) {
3562
- this.log(LogLevelLabel.FATAL, isString(message) ? message : StormJSON.stringify(message));
3563
- }
3564
- /**
3565
- * A logging function for error messages
3566
- *
3567
- * @param message - The message to log.
3568
- */
3569
- error(message) {
3570
- this.log(LogLevelLabel.ERROR, isString(message) ? message : StormJSON.stringify(message));
3571
- }
3572
- /**
3573
- * A logging function for warning messages
3574
- *
3575
- * @param message - The message to log.
3576
- */
3577
- warn(message) {
3578
- this.log(LogLevelLabel.WARN, isString(message) ? message : StormJSON.stringify(message));
3579
- }
3580
- /**
3581
- * A logging function for informational messages
3582
- *
3583
- * @param message - The message to log.
3584
- */
3585
- info(message) {
3586
- this.log(LogLevelLabel.INFO, isString(message) ? message : StormJSON.stringify(message));
3587
- }
3588
- /**
3589
- * A logging function for debug messages
3590
- *
3591
- * @param message - The message to log.
3592
- */
3593
- debug(message) {
3594
- this.log(LogLevelLabel.DEBUG, isString(message) ? message : StormJSON.stringify(message));
3595
- }
3596
- /**
3597
- * A logging function for trace messages
3598
- *
3599
- * @param message - The message to log.
3600
- */
3601
- trace(message) {
3602
- this.log(LogLevelLabel.TRACE, isString(message) ? message : StormJSON.stringify(message));
3603
- }
3604
- /**
3605
- * Create a new logger instance
3606
- *
3607
- * @param name - The name to use for the logger instance
3608
- * @returns A logger function
3609
- */
3610
- createLog(name = null) {
3611
- return createLog(name, {
3612
- ...this.config,
3613
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel
3614
- });
3615
- }
3616
- /**
3617
- * Extend the current logger instance with a new name
3618
- *
3619
- * @param name - The name to use for the extended logger instance
3620
- * @returns A logger function
3621
- */
3622
- extendLog(name) {
3623
- return extendLog(this.log, name);
3624
- }
3625
- /**
3626
- * Generates a checksum representing the current context state
3627
- *
3628
- * @param root - The root directory of the project to generate the checksum for
3629
- * @returns A promise that resolves to a string representing the checksum
3630
- */
3631
- async generateChecksum(root = this.config.root) {
3632
- this.#checksum = await hashDirectory(root, { ignore: [
3633
- "node_modules",
3634
- ".git",
3635
- ".nx",
3636
- ".cache",
3637
- "tmp",
3638
- "dist"
3639
- ] });
3640
- return this.#checksum;
3641
- }
3642
- /**
3643
- * Creates a new StormContext instance.
3644
- *
3645
- * @param workspaceConfig - The workspace configuration.
3646
- */
3647
- constructor(workspaceConfig) {
3648
- this.#workspaceConfig = workspaceConfig;
3649
- envPathCache.set({
3650
- workspaceRoot: workspaceConfig.workspaceRoot,
3651
- framework: "powerlines"
3652
- }, getEnvPaths({
3653
- orgId: (isSetObject(workspaceConfig.organization) ? workspaceConfig.organization.name : workspaceConfig.organization) || "storm-software",
3654
- appId: "powerlines",
3655
- workspaceRoot: workspaceConfig.workspaceRoot
3656
- }));
3657
- }
3658
- /**
3659
- * The resolved configuration for this context
3660
- */
3661
- resolvedConfig = {};
3662
- /**
3663
- * A logger function specific to this context
3664
- */
3665
- logFn;
3666
- /**
3667
- * Initialize the context with the provided configuration options
3668
- *
3669
- * @param config - The partial user configuration to use for initialization.
3670
- */
3671
- async init(config = {}, options = { isHighPriority: true }) {
3672
- const cacheKey = {
3673
- root: config.root ?? this.config.root ?? this.config.userConfig?.root ?? this.config.inlineConfig?.root,
3674
- mode: (config.mode ?? this.config.mode) || this.workspaceConfig.mode,
3675
- skipCache: config.skipCache ?? this.config.skipCache ?? false,
3676
- configFile: config.configFile ?? this.config.configFile,
3677
- framework: config.framework ?? this.config.framework ?? "powerlines",
3678
- command: this.config.inlineConfig?.command,
3679
- alias: this.config.resolve?.alias ?? config.resolve?.alias
3680
- };
3681
- if (configCache.has(cacheKey)) {
3682
- const result = configCache.get(cacheKey);
3683
- this.projectJson = result.projectJson;
3684
- this.packageJson = result.packageJson;
3685
- this.#checksum = result.checksum;
3686
- this.resolver = result.resolver;
3687
- this.mergeUserConfig(result.userConfig.config, this.config.userConfig);
3688
- } else {
3689
- const projectJsonPath = joinPaths$1(cacheKey.root, "project.json");
3690
- if (existsSync(projectJsonPath)) this.projectJson = await readJsonFile(projectJsonPath);
3691
- const packageJsonPath = joinPaths$1(cacheKey.root, "package.json");
3692
- if (existsSync(packageJsonPath)) this.packageJson = await readJsonFile(packageJsonPath);
3693
- this.#checksum = await this.generateChecksum(cacheKey.root);
3694
- this.resolver = createResolver({
3695
- workspaceRoot: this.workspaceConfig.workspaceRoot,
3696
- root: cacheKey.root,
3697
- cacheDir: this.cachePath,
3698
- mode: cacheKey.mode,
3699
- logLevel: config.logLevel || this.config.logLevel || this.workspaceConfig.logLevel || "info",
3700
- skipCache: cacheKey.skipCache,
3701
- alias: this.config.resolve?.alias ? Array.isArray(this.config.resolve.alias) ? this.config.resolve.alias.reduce((ret, alias) => {
3702
- ret[alias.find.toString()] = alias.replacement;
3703
- return ret;
3704
- }, {}) : this.config.resolve.alias : {}
3705
- });
3706
- const userConfig = await loadUserConfigFile(cacheKey.root, this.workspaceConfig.workspaceRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile, cacheKey.framework);
3707
- this.mergeUserConfig(userConfig.config);
3708
- configCache.set(cacheKey, {
3709
- projectJson: this.projectJson,
3710
- packageJson: this.packageJson,
3711
- checksum: this.#checksum,
3712
- resolver: this.resolver,
3713
- userConfig
3714
- });
3715
- }
3716
- config.tsconfig ??= getTsconfigFilePath(this.workspaceConfig.workspaceRoot, cacheKey.root, config.tsconfig);
3717
- if (isSetObject(config)) this.resolvedConfig = mergeConfig({
3718
- inlineConfig: this.config.inlineConfig,
3719
- userConfig: this.config.userConfig
3720
- }, options.isHighPriority ? this.#getConfigProps(config) : {}, {
3721
- ...this.#getConfigProps(this.config.inlineConfig),
3722
- command: this.config.inlineConfig?.command
3723
- }, this.#getConfigProps(this.config.userConfig), {
3724
- mode: this.workspaceConfig?.mode,
3725
- logLevel: this.workspaceConfig?.logLevel,
3726
- skipCache: this.workspaceConfig?.skipCache
3727
- }, {
3728
- name: this.projectJson?.name || this.packageJson?.name,
3729
- version: this.packageJson?.version,
3730
- description: this.packageJson?.description,
3731
- output: mergeConfig(config.output ?? {}, {
3732
- outputPath: cacheKey.root ? joinPaths$1(this.workspaceConfig?.directories?.build || "dist", cacheKey.root) : this.workspaceConfig?.directories?.build || "dist",
3733
- artifactsPath: `.${config.framework ?? "powerlines"}`,
3734
- dts: joinPaths$1(cacheKey.root, `${config.framework ?? "powerlines"}.d.ts`),
3735
- assets: [
3736
- { glob: "LICENSE" },
3737
- {
3738
- input: cacheKey.root,
3739
- glob: "*.md"
3740
- },
3741
- {
3742
- input: cacheKey.root,
3743
- glob: "package.json"
3744
- }
3745
- ]
3746
- })
3747
- }, options.isHighPriority ? {} : this.#getConfigProps(config), {
3748
- inlineConfig: {},
3749
- userConfig: {},
3750
- framework: "powerlines",
3751
- mode: "production",
3752
- projectType: "application",
3753
- platform: "neutral",
3754
- logLevel: "info",
3755
- preview: false,
3756
- environments: {},
3757
- resolve: {}
3758
- });
3759
- this.config.input = getUniqueInputs(this.config.input);
3760
- if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) this.config.name = this.config.name.split("/").filter(Boolean)[1];
3761
- this.config.title ??= titleCase(this.config.name);
3762
- this.config.organization ??= (isSetObject(this.workspaceConfig.organization) ? this.workspaceConfig.organization.name : this.workspaceConfig.organization) || (isSetObject(this.packageJson?.author) ? this.packageJson?.author?.name : this.packageJson?.author) || this.config.name;
3763
- if (this.config.userConfig.resolve?.external) this.config.userConfig.resolve.external = getUnique(this.config.userConfig.resolve.external);
3764
- if (this.config.userConfig.resolve?.noExternal) this.config.userConfig.resolve.noExternal = getUnique(this.config.userConfig.resolve.noExternal);
3765
- if (this.config.resolve.external) this.config.resolve.external = getUnique(this.config.resolve.external);
3766
- if (this.config.resolve.noExternal) this.config.resolve.noExternal = getUnique(this.config.resolve.noExternal);
3767
- this.config.output.format = getUnique(toArray(this.config.output?.format ?? (this.config.projectType === "library" ? ["cjs", "esm"] : ["esm"])));
3768
- if (this.config.root && this.config.root !== "." && this.config.root !== "./" && this.config.root !== this.workspaceConfig.workspaceRoot) {
3769
- this.config.output.outputPath ??= joinPaths$1("dist", this.config.root);
3770
- this.config.output.buildPath ??= joinPaths$1(this.config.root, "dist");
3771
- } else {
3772
- this.config.output.outputPath ??= "dist";
3773
- this.config.output.buildPath ??= "dist";
3774
- }
3775
- this.config.output.assets = getUniqueBy(this.config.output.assets.map((asset) => {
3776
- return {
3777
- glob: isSetObject(asset) ? asset.glob : asset,
3778
- input: isString(asset) || !asset.input || asset.input === "." || asset.input === "/" || asset.input === "./" ? this.workspaceConfig.workspaceRoot : isParentPath(asset.input, this.workspaceConfig.workspaceRoot) || asset.input === this.workspaceConfig.workspaceRoot ? asset.input : appendPath(asset.input, this.workspaceConfig.workspaceRoot),
3779
- output: isSetObject(asset) && asset.output ? isParentPath(asset.output, this.workspaceConfig.workspaceRoot) ? asset.output : appendPath(joinPaths$1(this.config.output.outputPath, replacePath(replacePath(asset.output, replacePath(this.config.output.outputPath, this.workspaceConfig.workspaceRoot)), this.config.output.outputPath)), this.workspaceConfig.workspaceRoot) : appendPath(this.config.output.outputPath, this.workspaceConfig.workspaceRoot),
3780
- ignore: isSetObject(asset) && asset.ignore ? toArray(asset.ignore) : void 0
3781
- };
3782
- }), (a) => `${a.input}-${a.glob}-${a.output}`);
3783
- this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
3784
- if (isPlugin(plugin) && checkDedupe(plugin, ret.filter((p) => isPlugin(p)))) return ret;
3785
- ret.push(plugin);
3786
- return ret;
3787
- }, []);
3788
- if (this.config.tsconfig) this.config.tsconfig = replacePathTokens(this, this.config.tsconfig);
3789
- if (this.config.output.dts) if (isSetString(this.config.output.dts)) this.config.output.dts = replacePathTokens(this, this.config.output.dts);
3790
- else this.config.output.dts = joinPaths$1(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`);
3791
- if (this.config.output.assets) this.config.output.assets = this.config.output.assets.map((asset) => ({
3792
- ...asset,
3793
- glob: replacePathTokens(this, asset.glob),
3794
- ignore: asset.ignore ? asset.ignore.map((ignore) => replacePathTokens(this, ignore)) : void 0,
3795
- input: replacePathTokens(this, asset.input),
3796
- output: replacePathTokens(this, asset.output)
3797
- }));
3798
- if (isSetString(config.output?.storage) && config.output.storage === "virtual" || isSetObject(config.output?.storage) && Object.values(config.output.storage).every((adapter) => adapter.preset === "virtual")) this.config.output.overwrite = true;
3799
- this.#fs ??= await VirtualFileSystem.create(this);
3800
- }
3801
- mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
3802
- this.config.userConfig = mergeConfig({ input: isSetObject(from.input) && !isRegExp(from.input) && !Array.isArray(from.input) && from.input.file ? from.input.file : isSetObject(into?.input) && !isRegExp(into.input) && !Array.isArray(into.input) && into.input.file ? into.input.file : Array.isArray(from.input) && from.input.length > 0 ? from.input : Array.isArray(into?.input) && into.input.length > 0 ? into.input : [] }, omit(from ?? {}, ["input"]), omit(into ?? {}, ["input"]));
3803
- if (this.config.userConfig.output?.format) this.config.userConfig.output.format = getUnique(toArray(this.config.userConfig.output?.format));
3804
- this.config.userConfig.plugins = (this.config.userConfig.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
3805
- if (isPlugin(plugin) && checkDedupe(plugin, ret.filter((p) => isPlugin(p)))) return ret;
3806
- ret.push(plugin);
3807
- return ret;
3808
- }, []);
3809
- }
3810
- };
3811
-
3812
- //#endregion
3813
- //#region ../core/src/lib/unplugin/helpers.ts
3814
- /**
3815
- * Checks if a value is a valid UnpluginBuilderVariant.
3816
- *
3817
- * @param str - The value to check.
3818
- * @returns True if the value is a UnpluginBuilderVariant, false otherwise.
3819
- */
3820
- function isUnpluginBuilderVariant(str) {
3821
- return isSetString(str) && UNPLUGIN_BUILDER_VARIANTS.includes(str);
3822
- }
3823
-
3824
- //#endregion
3825
- //#region ../powerlines/src/context/plugin-context.ts
3826
- /**
3827
- * Create a Proxy-based PluginContext
3828
- *
3829
- * @param plugin - The plugin instance
3830
- * @param environment - The environment context
3831
- * @returns The proxied plugin context
3832
- */
3833
- function createPluginContext(plugin, environment) {
3834
- const normalizeMessage = (message) => {
3835
- return isString(message) ? message : message.message;
3836
- };
3837
- const log = environment.extendLog(plugin.name.replaceAll(":", " - "));
3838
- const callHookFn = async (hook, options, ...args) => {
3839
- return environment.$$internal.api.callHook(hook, {
3840
- sequential: true,
3841
- result: "merge",
3842
- ...options,
3843
- environment
3844
- }, ...args);
3845
- };
3846
- const meta = {};
3847
- return new Proxy({}, {
3848
- get(_, prop) {
3849
- if (prop === "$$internal") return {
3850
- ...environment.$$internal,
3851
- environment,
3852
- callHook: callHookFn,
3853
- meta
3854
- };
3855
- if (prop === "log" || prop === "logger") return log;
3856
- if (prop === "fatal") return (message) => {
3857
- log(LogLevelLabel.FATAL, normalizeMessage(message));
3858
- };
3859
- if (prop === "error") return (message) => {
3860
- log(LogLevelLabel.ERROR, normalizeMessage(message));
3861
- };
3862
- if (prop === "warn") return (message) => {
3863
- log(LogLevelLabel.WARN, normalizeMessage(message));
3864
- };
3865
- if (prop === "info") return (message) => {
3866
- log(LogLevelLabel.INFO, normalizeMessage(message));
3867
- };
3868
- if (prop === "debug") return (message) => {
3869
- log(LogLevelLabel.DEBUG, normalizeMessage(message));
3870
- };
3871
- if (prop === "trace") return (message) => {
3872
- log(LogLevelLabel.TRACE, normalizeMessage(message));
3873
- };
3874
- return environment[prop];
3875
- },
3876
- set(_, prop, value) {
3877
- if ([
3878
- "$$internal",
3879
- "environment",
3880
- "config",
3881
- "log",
3882
- "logger",
3883
- "error",
3884
- "warn",
3885
- "plugins",
3886
- "hooks",
3887
- "addPlugin",
3888
- "selectHooks"
3889
- ].includes(prop)) {
3890
- log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
3891
- return false;
3892
- }
3893
- environment[prop] = value;
3894
- return true;
3895
- }
3896
- });
3897
- }
3898
-
3899
- //#endregion
3900
- //#region ../powerlines/src/context/environment-context.ts
3901
- var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends PowerlinesContext {
3902
- /**
3903
- * The hooks registered by plugins in this environment
3904
- */
3905
- #hooks = {};
3906
- /**
3907
- * Create a new Storm context from the workspace root and user config.
3908
- *
3909
- * @param workspaceConfig - The root directory of the workspace.
3910
- * @param config - The user configuration options.
3911
- * @returns A promise that resolves to the new context.
3912
- */
3913
- static async fromConfig(workspaceConfig, config) {
3914
- const context = new PowerlinesEnvironmentContext(config, workspaceConfig);
3915
- await context.init();
3916
- const powerlinesPath = await resolvePackage("powerlines");
3917
- if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
3918
- context.powerlinesPath = powerlinesPath;
3919
- return context;
3920
- }
3921
- /**
3922
- * The resolved environment configuration
3923
- */
3924
- environment;
3925
- /**
3926
- * The list of plugins applied to this environment
3927
- */
3928
- plugins = [];
3929
- /**
3930
- * The resolved configuration options
3931
- */
3932
- get config() {
3933
- return super.config;
3934
- }
3935
- get hooks() {
3936
- return this.#hooks;
3937
- }
3938
- async addPlugin(plugin) {
3939
- let resolvedPlugin = plugin;
3940
- if (isFunction(plugin.applyToEnvironment)) {
3941
- const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
3942
- if (!result || isObject(result) && Object.keys(result).length === 0) return;
3943
- if (isPluginConfig(result)) return this.$$internal.addPlugin(result);
3944
- resolvedPlugin = isPlugin(result) ? result : plugin;
3945
- }
3946
- const context = createPluginContext(resolvedPlugin, this);
3947
- this.plugins.push({
3948
- plugin: resolvedPlugin,
3949
- context
3950
- });
3951
- this.#hooks = Object.keys(resolvedPlugin).filter((key) => !PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
3952
- const hook = key;
3953
- if (isPluginHookField(hook)) {
3954
- const pluginHook = resolvedPlugin[hook];
3955
- if (!isPluginHook(pluginHook)) return ret;
3956
- ret[hook] ??= {
3957
- preEnforced: [],
3958
- preOrdered: [],
3959
- normal: [],
3960
- postEnforced: [],
3961
- postOrdered: []
3962
- };
3963
- if (resolvedPlugin.enforce) {
3964
- const hookListOrder$1 = `${resolvedPlugin.enforce}Enforced`;
3965
- ret[hook][hookListOrder$1] ??= [];
3966
- const bucket = ret[hook][hookListOrder$1];
3967
- addPluginHook(context, resolvedPlugin, pluginHook, bucket);
3968
- return ret;
3969
- }
3970
- if (isFunction(pluginHook) || !pluginHook.order) {
3971
- ret[hook].normal ??= [];
3972
- const bucket = ret[hook].normal;
3973
- addPluginHook(context, resolvedPlugin, pluginHook, bucket);
3974
- return ret;
3975
- }
3976
- const hookListOrder = `${pluginHook.order}Ordered`;
3977
- ret[hook][hookListOrder] ??= [];
3978
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][hookListOrder]);
3979
- return ret;
3980
- } else if (isUnpluginHookField(hook)) {
3981
- const unpluginPlugin = resolvedPlugin[hook];
3982
- if (!isSetObject(unpluginPlugin)) return ret;
3983
- for (const field of Object.keys(unpluginPlugin)) {
3984
- const variantField = field;
3985
- const pluginHook = unpluginPlugin[variantField];
3986
- if (!isPluginHook(pluginHook)) continue;
3987
- ret[hook] ??= {};
3988
- ret[hook][variantField] ??= {
3989
- preEnforced: [],
3990
- preOrdered: [],
3991
- normal: [],
3992
- postEnforced: [],
3993
- postOrdered: []
3994
- };
3995
- if (resolvedPlugin.enforce) {
3996
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField][`${resolvedPlugin.enforce}Enforced`]);
3997
- return ret;
3998
- }
3999
- if (isFunction(pluginHook) || !pluginHook.order) {
4000
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField].normal);
4001
- return ret;
4002
- }
4003
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField][`${pluginHook.order}Ordered`]);
4004
- }
4005
- } else this.warn(`Unknown plugin hook field: ${String(hook)}`);
4006
- return ret;
4007
- }, this.hooks);
4008
- }
4009
- /**
4010
- * Retrieves the hook handlers for a specific hook name
4011
- */
4012
- selectHooks(key, options) {
4013
- const result = [];
4014
- if (isUnpluginHookKey(key)) {
4015
- const variant = String(key).split(":")[0];
4016
- if (isUnpluginBuilderVariant(variant)) {
4017
- const hooks = this.hooks[variant];
4018
- if (hooks) {
4019
- const field = String(key).split(":")[1];
4020
- if (field && hooks[field]) {
4021
- const fieldHooks = hooks[field];
4022
- if (options?.order) {
4023
- const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
4024
- const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
4025
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
4026
- return {
4027
- handler: hook.handler,
4028
- plugin: hook.plugin,
4029
- context: plugin.context
4030
- };
4031
- });
4032
- if (options?.order === "pre") {
4033
- result.push(...mapHooksToResult(fieldHooks.preOrdered ?? []));
4034
- result.push(...mapHooksToResult(fieldHooks.preEnforced ?? []));
4035
- } else if (options?.order === "post") {
4036
- result.push(...mapHooksToResult(fieldHooks.postOrdered ?? []));
4037
- result.push(...mapHooksToResult(fieldHooks.postEnforced ?? []));
4038
- } else result.push(...mapHooksToResult(fieldHooks.normal ?? []));
4039
- } else {
4040
- result.push(...this.selectHooks(key, { order: "pre" }));
4041
- result.push(...this.selectHooks(key, { order: "normal" }));
4042
- result.push(...this.selectHooks(key, { order: "post" }));
4043
- }
4044
- }
4045
- }
4046
- }
4047
- } else if (isPluginHookField(key)) {
4048
- if (this.hooks[key]) {
4049
- const fieldHooks = this.hooks[key];
4050
- if (options?.order) {
4051
- const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
4052
- const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
4053
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
4054
- return {
4055
- handler: hook.handler,
4056
- plugin: hook.plugin,
4057
- context: plugin.context
4058
- };
4059
- });
4060
- if (options?.order === "pre") {
4061
- result.push(...mapHooksToResult(fieldHooks.preOrdered ?? []));
4062
- result.push(...mapHooksToResult(fieldHooks.preEnforced ?? []));
4063
- } else if (options?.order === "post") {
4064
- result.push(...mapHooksToResult(fieldHooks.postOrdered ?? []));
4065
- result.push(...mapHooksToResult(fieldHooks.postEnforced ?? []));
4066
- } else result.push(...mapHooksToResult(fieldHooks.normal ?? []));
4067
- } else {
4068
- result.push(...this.selectHooks(key, { order: "pre" }));
4069
- result.push(...this.selectHooks(key, { order: "normal" }));
4070
- result.push(...this.selectHooks(key, { order: "post" }));
4071
- }
4072
- }
4073
- } else throw new Error(`Unknown plugin hook key: ${String(key)}`);
4074
- return result;
4075
- }
4076
- constructor(config, workspaceConfig) {
4077
- super(workspaceConfig);
4078
- this.resolvedConfig = config;
4079
- }
4080
- };
4081
-
4082
- //#endregion
4083
- //#region ../powerlines/src/context/api-context.ts
4084
- var PowerlinesAPIContext = class PowerlinesAPIContext extends PowerlinesContext {
4085
- #environments = {};
4086
- #plugins = [];
4087
- #log;
4088
- /**
4089
- * Create a new Storm context from the workspace root and user config.
4090
- *
4091
- * @param workspaceRoot - The root directory of the workspace.
4092
- * @param config - The user configuration options.
4093
- * @returns A promise that resolves to the new context.
4094
- */
4095
- static async from(workspaceRoot, config) {
4096
- const context = new PowerlinesAPIContext(await loadWorkspaceConfig(workspaceRoot, config.root));
4097
- await context.withUserConfig(config);
4098
- const powerlinesPath = await resolvePackage("powerlines");
4099
- if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
4100
- context.powerlinesPath = powerlinesPath;
4101
- return context;
4102
- }
4103
- /**
4104
- * Internal context fields and methods
4105
- *
4106
- * @danger
4107
- * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
4108
- *
4109
- * @internal
4110
- */
4111
- get $$internal() {
4112
- return super.$$internal;
4113
- }
4114
- /**
4115
- * Internal context fields and methods
4116
- *
4117
- * @danger
4118
- * This field is for internal use only and should not be accessed or modified directly. It is unstable and can be changed at anytime.
4119
- *
4120
- * @internal
4121
- */
4122
- set $$internal(value) {
4123
- super.$$internal = value;
4124
- for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
4125
- }
4126
- /**
4127
- * A record of all environments by name
4128
- */
4129
- get environments() {
4130
- return this.#environments;
4131
- }
4132
- get log() {
4133
- if (!this.#log) this.#log = this.createLog();
4134
- return this.#log;
4135
- }
4136
- get plugins() {
4137
- return this.#plugins;
4138
- }
4139
- constructor(workspaceConfig) {
4140
- super(workspaceConfig);
4141
- }
4142
- /**
4143
- * Initialize the context with the provided configuration options
4144
- *
4145
- * @param config - The partial user configuration to use for initialization.
4146
- */
4147
- async init(config = {}) {
4148
- await super.init(config);
4149
- await Promise.all(toArray(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => createEnvironment(name, this.config.userConfig)) : createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
4150
- this.#environments[env.name] = await this.in(env);
4151
- }));
4152
- }
4153
- /**
4154
- * A function to copy the context and update the fields for a specific environment
4155
- *
4156
- * @param environment - The environment configuration to use.
4157
- * @returns A new context instance with the updated environment.
4158
- */
4159
- async in(environment) {
4160
- let context;
4161
- if (this.environments[environment.name]) context = this.environments[environment.name];
4162
- else context = await PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
4163
- if (isSetObject(this.config.inlineConfig)) await context.withInlineConfig(this.config.inlineConfig);
4164
- context.environment = environment;
4165
- context.plugins = [];
4166
- for (const plugin of this.plugins) await context.addPlugin(plugin);
4167
- return context;
4168
- }
4169
- /**
4170
- * Update the context using a new user configuration options
4171
- *
4172
- * @param userConfig - The new user configuration options.
4173
- */
4174
- async withUserConfig(userConfig, options = { isHighPriority: true }) {
4175
- await super.withUserConfig(userConfig, options);
4176
- await Promise.all(Object.keys(this.#environments).map(async (name) => {
4177
- await this.#environments[name].withUserConfig(userConfig, options);
4178
- }));
4179
- }
4180
- /**
4181
- * Update the context using a new inline configuration options
4182
- *
4183
- * @param inlineConfig - The new inline configuration options.
4184
- */
4185
- async withInlineConfig(inlineConfig, options = { isHighPriority: true }) {
4186
- await super.withInlineConfig(inlineConfig, options);
4187
- await Promise.all(Object.keys(this.#environments).map(async (name) => {
4188
- await this.#environments[name].withInlineConfig(inlineConfig, options);
4189
- }));
4190
- }
4191
- /**
4192
- * Add a plugin to the API context and all environments
4193
- *
4194
- * @param plugin - The plugin to add.
4195
- */
4196
- async addPlugin(plugin) {
4197
- this.plugins.push(plugin);
4198
- await Promise.all(Object.keys(this.environments).map(async (name) => {
4199
- await this.environments[name].addPlugin(plugin);
4200
- }));
4201
- }
4202
- /**
4203
- * Get an environment by name, or the default environment if no name is provided
4204
- *
4205
- * @param name - The name of the environment to retrieve.
4206
- * @returns The requested environment context.
4207
- */
4208
- async getEnvironment(name) {
4209
- let environment;
4210
- if (name) environment = this.environments[name];
4211
- if (Object.keys(this.environments).length === 1) {
4212
- environment = this.environments[Object.keys(this.environments)[0]];
4213
- this.debug(`Applying the only configured environment: ${chalk.bold.cyanBright(environment?.environment.name)}`);
4214
- }
4215
- if (!environment) {
4216
- if (name) throw new Error(`Environment "${name}" not found.`);
4217
- environment = await this.in(createDefaultEnvironment(this.config.userConfig));
4218
- this.warn(`No environment specified, and no default environment found. Using a temporary default environment: ${chalk.bold.cyanBright(environment?.environment.name)}`);
4219
- }
4220
- return environment;
4221
- }
4222
- /**
4223
- * A safe version of `getEnvironment` that returns `undefined` if the environment is not found
4224
- *
4225
- * @param name - The name of the environment to retrieve.
4226
- * @returns The requested environment context or `undefined` if not found.
4227
- */
4228
- async getEnvironmentSafe(name) {
4229
- try {
4230
- return await this.getEnvironment(name);
4231
- } catch {
4232
- return;
4233
- }
4234
- }
4235
- /**
4236
- * A function to merge all configured environments into a single context.
4237
- *
4238
- * @remarks
4239
- * If only one environment is configured, that environment will be returned directly.
4240
- *
4241
- * @returns A promise that resolves to a merged/global environment context.
4242
- */
4243
- async toEnvironment() {
4244
- let environment;
4245
- if (Object.keys(this.environments).length > 1) {
4246
- environment = await this.in(createEnvironment(GLOBAL_ENVIRONMENT, this.config.userConfig));
4247
- this.debug(`Combined all ${Object.keys(this.environments).length} environments into a single global context.`);
4248
- } else environment = await this.getEnvironment();
4249
- return environment;
4250
- }
4251
- };
4252
-
4253
- //#endregion
4254
- //#region ../powerlines/src/api.ts
4255
- /**
4256
- * The Powerlines API class
4257
- *
4258
- * @remarks
4259
- * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
4260
- *
4261
- * @public
4262
- */
4263
- var PowerlinesAPI = class PowerlinesAPI {
4264
- /**
4265
- * The Powerlines context
4266
- */
4267
- #context;
4268
- /**
4269
- * The Powerlines context
4270
- */
4271
- get context() {
4272
- return this.#context;
4273
- }
4274
- /**
4275
- * Create a new Powerlines API instance
4276
- *
4277
- * @param context - The Powerlines context
4278
- */
4279
- constructor(context) {
4280
- this.#context = context;
4281
- }
4282
- /**
4283
- * Initialize a Powerlines API instance
4284
- *
4285
- * @param workspaceRoot - The directory of the underlying workspace the Powerlines project exists in
4286
- * @param config - An object containing the configuration required to run Powerlines tasks.
4287
- * @returns A new instance of the Powerlines API
4288
- */
4289
- static async from(workspaceRoot, config) {
4290
- const api = new PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
4291
- api.#context.$$internal = {
4292
- api,
4293
- addPlugin: api.#addPlugin.bind(api)
4294
- };
4295
- api.context.info(`🔌 The Powerlines Engine v${version} has started`);
4296
- for (const plugin of api.context.config.plugins ?? []) await api.#addPlugin(plugin);
4297
- if (api.context.plugins.length === 0) api.context.warn("No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
4298
- const pluginConfig = await api.callHook("config", {
4299
- environment: await api.context.getEnvironment(),
4300
- sequential: true,
4301
- result: "merge",
4302
- merge: mergeConfigs
4303
- });
4304
- await api.context.withUserConfig(pluginConfig, { isHighPriority: false });
4305
- return api;
4306
- }
4307
- /**
4308
- * Prepare the Powerlines API
4309
- *
4310
- * @remarks
4311
- * This method will prepare the Powerlines API for use, initializing any necessary resources.
4312
- *
4313
- * @param inlineConfig - The inline configuration for the prepare command
4314
- */
4315
- async prepare(inlineConfig = { command: "prepare" }) {
4316
- this.context.info(" 🏗️ Preparing the Powerlines project");
4317
- this.context.debug(" Aggregating configuration options for the Powerlines project");
4318
- await this.context.withInlineConfig(inlineConfig);
4319
- await this.#executeEnvironments(async (context) => {
4320
- context.debug(`Initializing the processing options for the Powerlines project.`);
4321
- await this.callHook("configResolved", {
4322
- environment: context,
4323
- order: "pre"
4324
- });
4325
- await initializeTsconfig(context);
4326
- await this.callHook("configResolved", {
4327
- environment: context,
4328
- order: "normal"
4329
- });
4330
- if (context.entry.length > 0) context.debug(`The configuration provided ${isObject(context.config.input) ? Object.keys(context.config.input).length : toArray(context.config.input).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `: \n${context.entry.map((entry) => `- ${entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}`);
4331
- else context.warn(`No entry files were found for the ${context.config.title} project. Please ensure this is correct. Powerlines plugins generally require at least one entry point to function properly.`);
4332
- await resolveTsconfig(context);
4333
- await installDependencies(context);
4334
- await this.callHook("configResolved", {
4335
- environment: context,
4336
- order: "post"
4337
- });
4338
- context.trace(`Powerlines configuration has been resolved: \n\n${formatLogMessage({
4339
- ...context.config,
4340
- userConfig: isSetObject(context.config.userConfig) ? omit(context.config.userConfig, ["plugins"]) : void 0,
4341
- inlineConfig: isSetObject(context.config.inlineConfig) ? omit(context.config.inlineConfig, ["plugins"]) : void 0,
4342
- plugins: context.plugins.map((plugin) => plugin.plugin.name)
4343
- })}`);
4344
- if (!context.fs.existsSync(context.cachePath)) await createDirectory(context.cachePath);
4345
- if (!context.fs.existsSync(context.dataPath)) await createDirectory(context.dataPath);
4346
- await this.callHook("prepare", {
4347
- environment: context,
4348
- order: "pre"
4349
- });
4350
- await this.callHook("prepare", {
4351
- environment: context,
4352
- order: "normal"
4353
- });
4354
- await this.callHook("prepare", {
4355
- environment: context,
4356
- order: "post"
4357
- });
4358
- if (context.config.output.dts !== false) {
4359
- context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
4360
- if (context.fs.existsSync(context.dtsPath)) await context.fs.remove(context.dtsPath);
4361
- if (!await resolvePackage("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
4362
- context.debug("Running TypeScript compiler for built-in runtime module files.");
4363
- let types = await emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
4364
- const formatted = replacePath(builtin.path, context.workspaceConfig.workspaceRoot);
4365
- if (!ret.includes(formatted)) ret.push(formatted);
4366
- return ret;
4367
- }, []));
4368
- context.debug(`Generating TypeScript declaration file ${context.dtsPath}.`);
4369
- const directives = [];
4370
- const asNextParam = (previousResult) => isObject(previousResult) ? previousResult.code : previousResult;
4371
- let result = await this.callHook("types", {
4372
- environment: context,
4373
- sequential: true,
4374
- order: "pre",
4375
- result: "merge",
4376
- asNextParam
4377
- }, types);
4378
- if (result) {
4379
- if (isSetObject(result)) {
4380
- types = result.code;
4381
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
4382
- } else if (isSetString(result)) types = result;
4383
- }
4384
- result = await this.callHook("types", {
4385
- environment: context,
4386
- sequential: true,
4387
- order: "normal",
4388
- result: "merge",
4389
- asNextParam
4390
- }, types);
4391
- if (result) {
4392
- if (isSetObject(result)) {
4393
- types = result.code;
4394
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
4395
- } else if (isSetString(result)) types = result;
4396
- }
4397
- result = await this.callHook("types", {
4398
- environment: context,
4399
- sequential: true,
4400
- order: "post",
4401
- result: "merge",
4402
- asNextParam
4403
- }, types);
4404
- if (result) {
4405
- if (isSetObject(result)) {
4406
- types = result.code;
4407
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
4408
- } else if (isSetString(result)) types = result;
4409
- }
4410
- if (isSetString(types?.trim()) || directives.length > 0) await context.fs.write(context.dtsPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
4411
-
4412
- ` : ""}${getTypescriptFileHeader(context, {
4413
- directive: null,
4414
- prettierIgnore: false
4415
- })}
4416
-
4417
- ${formatTypes(types)}
4418
- `);
4419
- else {
4420
- const dtsRelativePath = getTsconfigDtsPath(context);
4421
- if (context.tsconfig.tsconfigJson.include && isIncludeMatchFound(dtsRelativePath, context.tsconfig.tsconfigJson.include)) {
4422
- const normalizedDtsRelativePath = dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath;
4423
- context.tsconfig.tsconfigJson.include = context.tsconfig.tsconfigJson.include.filter((includeValue) => includeValue?.toString() !== normalizedDtsRelativePath);
4424
- await context.fs.write(context.tsconfig.tsconfigFilePath, JSON.stringify(context.tsconfig.tsconfigJson, null, 2));
4425
- }
4426
- }
4427
- }
4428
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
4429
- if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
4430
- this.context.debug("Formatting files generated during the prepare step.");
4431
- await Promise.all([formatFolder(context, context.builtinsPath), formatFolder(context, context.entryPath)]);
4432
- await writeMetaFile(context);
4433
- context.persistedMeta = context.meta;
4434
- });
4435
- this.context.debug("✔ Powerlines preparation has completed successfully");
4436
- }
4437
- /**
4438
- * Create a new Powerlines project
4439
- *
4440
- * @remarks
4441
- * This method will create a new Powerlines project in the current directory.
4442
- *
4443
- * @param inlineConfig - The inline configuration for the new command
4444
- * @returns A promise that resolves when the project has been created
4445
- */
4446
- async new(inlineConfig) {
4447
- this.context.info(" 🆕 Creating a new Powerlines project");
4448
- await this.prepare(inlineConfig);
4449
- await this.#executeEnvironments(async (context) => {
4450
- context.debug("Initializing the processing options for the Powerlines project.");
4451
- await this.callHook("new", {
4452
- environment: context,
4453
- order: "pre"
4454
- });
4455
- const files = await listFiles(joinPaths(context.powerlinesPath, "files/common/**/*.hbs"));
4456
- for (const file of files) {
4457
- context.trace(`Adding template file to project: ${file}`);
4458
- const template = Handlebars.compile(file);
4459
- await context.fs.write(joinPaths(context.config.root, file.replace(".hbs", "")), template(context));
4460
- }
4461
- await this.callHook("new", {
4462
- environment: context,
4463
- order: "normal"
4464
- });
4465
- if (context.config.projectType === "application") {
4466
- const files$1 = await listFiles(joinPaths(context.powerlinesPath, "files/application/**/*.hbs"));
4467
- for (const file of files$1) {
4468
- context.trace(`Adding application template file: ${file}`);
4469
- const template = Handlebars.compile(file);
4470
- await context.fs.write(joinPaths(context.config.root, file.replace(".hbs", "")), template(context));
4471
- }
4472
- } else {
4473
- const files$1 = await listFiles(joinPaths(context.powerlinesPath, "files/library/**/*.hbs"));
4474
- for (const file of files$1) {
4475
- context.trace(`Adding library template file: ${file}`);
4476
- const template = Handlebars.compile(file);
4477
- await context.fs.write(joinPaths(context.config.root, file.replace(".hbs", "")), template(context));
4478
- }
4479
- }
4480
- await this.callHook("new", {
4481
- environment: context,
4482
- order: "post"
4483
- });
4484
- });
4485
- this.context.debug("✔ Powerlines new command completed successfully");
4486
- }
4487
- /**
4488
- * Clean any previously prepared artifacts
4489
- *
4490
- * @remarks
4491
- * This method will remove the previous Powerlines artifacts from the project.
4492
- *
4493
- * @param inlineConfig - The inline configuration for the clean command
4494
- * @returns A promise that resolves when the clean command has completed
4495
- */
4496
- async clean(inlineConfig = { command: "clean" }) {
4497
- this.context.info(" 🧹 Cleaning the previous Powerlines artifacts");
4498
- await this.prepare(inlineConfig);
4499
- await this.#executeEnvironments(async (context) => {
4500
- context.debug("Cleaning the project's dist and artifacts directories.");
4501
- await context.fs.remove(joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.buildPath));
4502
- await context.fs.remove(joinPaths(context.workspaceConfig.workspaceRoot, context.config.root, context.config.output.artifactsPath));
4503
- await this.callHook("clean", {
4504
- environment: context,
4505
- sequential: false
4506
- });
4507
- });
4508
- this.context.debug("✔ Powerlines cleaning completed successfully");
4509
- }
4510
- /**
4511
- * Lint the project
4512
- *
4513
- * @param inlineConfig - The inline configuration for the lint command
4514
- * @returns A promise that resolves when the lint command has completed
4515
- */
4516
- async lint(inlineConfig = { command: "lint" }) {
4517
- this.context.info(" 📝 Linting the Powerlines project");
4518
- await this.prepare(inlineConfig);
4519
- await this.#executeEnvironments(async (context) => {
4520
- await this.callHook("lint", {
4521
- environment: context,
4522
- sequential: false
4523
- });
4524
- });
4525
- this.context.debug("✔ Powerlines linting completed successfully");
4526
- }
4527
- /**
4528
- * Build the project
4529
- *
4530
- * @remarks
4531
- * This method will build the Powerlines project, generating the necessary artifacts.
4532
- *
4533
- * @param inlineConfig - The inline configuration for the build command
4534
- * @returns A promise that resolves when the build command has completed
4535
- */
4536
- async build(inlineConfig = { command: "build" }) {
4537
- this.context.info(" 📦 Building the Powerlines project");
4538
- await this.context.generateChecksum();
4539
- if (this.context.meta.checksum !== this.context.persistedMeta?.checksum || this.context.config.skipCache) {
4540
- this.context.info("The project has been modified since the last time `prepare` was ran. Re-preparing the project.");
4541
- await this.prepare(inlineConfig);
4542
- }
4543
- if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
4544
- else await this.#executeEnvironments(async (context) => {
4545
- await this.#handleBuild(context);
4546
- });
4547
- this.context.debug("✔ Powerlines build completed successfully");
4548
- }
4549
- /**
4550
- * Prepare the documentation for the project
4551
- *
4552
- * @param inlineConfig - The inline configuration for the docs command
4553
- * @returns A promise that resolves when the documentation generation has completed
4554
- */
4555
- async docs(inlineConfig = { command: "docs" }) {
4556
- this.context.info(" 📓 Generating documentation for the Powerlines project");
4557
- await this.prepare(inlineConfig);
4558
- await this.#executeEnvironments(async (context) => {
4559
- context.debug("Writing documentation for the Powerlines project artifacts.");
4560
- await this.prepare(inlineConfig);
4561
- await this.#executeEnvironments(async (context$1) => {
4562
- await this.callHook("docs", { environment: context$1 });
4563
- });
4564
- });
4565
- this.context.debug("✔ Powerlines documentation generation completed successfully");
4566
- }
4567
- /**
4568
- * Deploy the project source code
4569
- *
4570
- * @remarks
4571
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
4572
- *
4573
- * @param inlineConfig - The inline configuration for the deploy command
4574
- */
4575
- async deploy(inlineConfig = { command: "deploy" }) {
4576
- this.context.info(" 🚀 Deploying the Powerlines project");
4577
- await this.prepare(inlineConfig);
4578
- await this.#executeEnvironments(async (context) => {
4579
- await this.callHook("deploy", { environment: context });
4580
- });
4581
- this.context.debug("✔ Powerlines deploy completed successfully");
4582
- }
4583
- /**
4584
- * Finalization process
4585
- *
4586
- * @remarks
4587
- * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
4588
- *
4589
- * @returns A promise that resolves when the finalization process has completed
4590
- */
4591
- async finalize() {
4592
- this.context.info(" 🏁 Powerlines finalization processes started");
4593
- await this.#executeEnvironments(async (context) => {
4594
- await this.callHook("finalize", { environment: context });
4595
- await context.fs.dispose();
4596
- });
4597
- this.context.debug("✔ Powerlines finalization completed successfully");
4598
- }
4599
- /**
4600
- * Invokes the configured plugin hooks
4601
- *
4602
- * @remarks
4603
- * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
4604
- *
4605
- * @param hook - The hook to call
4606
- * @param options - The options to provide to the hook
4607
- * @param args - The arguments to pass to the hook
4608
- * @returns The result of the hook call
4609
- */
4610
- async callHook(hook, options, ...args) {
4611
- return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
4612
- sequential: true,
4613
- ...options
4614
- }, ...args);
4615
- }
4616
- /**
4617
- * Dispose of the Powerlines API instance
4618
- *
4619
- * @remarks
4620
- * This method will finalize the Powerlines API instance, cleaning up any resources used.
4621
- */
4622
- async [Symbol.asyncDispose]() {
4623
- await this.finalize();
4624
- }
4625
- async #handleBuild(context) {
4626
- await this.callHook("build", {
4627
- environment: context,
4628
- order: "pre"
4629
- });
4630
- context.debug("Formatting the generated entry files before the build process starts.");
4631
- await formatFolder(context, context.entryPath);
4632
- await this.callHook("build", {
4633
- environment: context,
4634
- order: "normal"
4635
- });
4636
- if (context.config.output.buildPath !== context.config.output.outputPath) {
4637
- const sourcePath = appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot);
4638
- const destinationPath = joinPaths(appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
4639
- if (context.fs.existsSync(sourcePath) && sourcePath !== destinationPath) {
4640
- context.debug(`Copying build output files from project's build directory (${context.config.output.buildPath}) to the workspace's output directory (${context.config.output.outputPath}).`);
4641
- await context.fs.copy(sourcePath, destinationPath);
4642
- }
4643
- }
4644
- await Promise.all(context.config.output.assets.map(async (asset) => {
4645
- context.trace(`Copying asset(s): ${chalk.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : joinPaths(replacePath(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk.greenBright(joinPaths(replacePath(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.yellowBright(i)).join(", ")})` : ""}`);
4646
- await context.fs.copy(asset, asset.output);
4647
- }));
4648
- await this.callHook("build", {
4649
- environment: context,
4650
- order: "post"
4651
- });
4652
- }
4653
- /**
4654
- * Get the configured environments
4655
- *
4656
- * @returns The configured environments
4657
- */
4658
- async #getEnvironments() {
4659
- if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
4660
- this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
4661
- return [await this.context.getEnvironment()];
4662
- }
4663
- this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
4664
- return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
4665
- if (!await this.context.getEnvironmentSafe(name)) {
4666
- const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
4667
- if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
4668
- }
4669
- return this.context.environments[name];
4670
- }))).filter((context) => isSet(context));
4671
- }
4672
- /**
4673
- * Execute a handler function for each environment
4674
- *
4675
- * @param handle - The handler function to execute for each environment
4676
- */
4677
- async #executeEnvironments(handle) {
4678
- await Promise.all((await this.#getEnvironments()).map(async (context) => {
4679
- return Promise.resolve(handle(context));
4680
- }));
4681
- }
4682
- /**
4683
- * Add a Powerlines plugin used in the build process
4684
- *
4685
- * @param config - The import path of the plugin to add
4686
- */
4687
- async #addPlugin(config) {
4688
- if (config) {
4689
- const result = await this.#initPlugin(config);
4690
- if (!result) return;
4691
- for (const plugin of result) {
4692
- this.context.debug(`Successfully initialized the ${chalk.bold.cyanBright(plugin.name)} plugin`);
4693
- await this.context.addPlugin(plugin);
4694
- }
4695
- }
4696
- }
4697
- /**
4698
- * Initialize a Powerlines plugin
4699
- *
4700
- * @param config - The configuration for the plugin
4701
- * @returns The initialized plugin instance, or null if the plugin was a duplicate
4702
- * @throws Will throw an error if the plugin cannot be found or is invalid
4703
- */
4704
- async #initPlugin(config) {
4705
- let awaited = config;
4706
- if (isPromiseLike(config)) awaited = await Promise.resolve(config);
4707
- if (!isPluginConfig(awaited)) {
4708
- const invalid = findInvalidPluginConfig(awaited);
4709
- throw new Error(`Invalid ${invalid && invalid.length > 1 ? "plugins" : "plugin"} specified in the configuration - ${invalid && invalid.length > 0 ? JSON.stringify(awaited) : invalid?.join("\n\n")} \n\nPlease ensure the value is one of the following: \n - an instance of \`Plugin\` \n - a plugin name \n - an object with the \`plugin\` and \`options\` properties \n - a tuple array with the plugin and options \n - a factory function that returns a plugin or array of plugins \n - an array of plugins or plugin configurations`);
4710
- }
4711
- let plugins;
4712
- if (isPlugin(awaited)) plugins = [awaited];
4713
- else if (isFunction(awaited)) plugins = toArray(await Promise.resolve(awaited()));
4714
- else if (isString(awaited)) {
4715
- const resolved = await this.#resolvePlugin(awaited);
4716
- if (isFunction(resolved)) plugins = toArray(await Promise.resolve(resolved()));
4717
- else plugins = toArray(resolved);
4718
- } else if (Array.isArray(awaited) && awaited.every(isPlugin)) plugins = awaited;
4719
- else if (Array.isArray(awaited) && awaited.every(isPluginConfig)) {
4720
- plugins = [];
4721
- for (const pluginConfig of awaited) {
4722
- const initialized = await this.#initPlugin(pluginConfig);
4723
- if (initialized) plugins.push(...initialized);
4724
- }
4725
- } else if (isPluginConfigTuple(awaited) || isPluginConfigObject(awaited)) {
4726
- let pluginConfig;
4727
- let pluginOptions;
4728
- if (isPluginConfigTuple(awaited)) {
4729
- pluginConfig = awaited[0];
4730
- pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
4731
- } else {
4732
- pluginConfig = awaited.plugin;
4733
- pluginOptions = awaited.options;
4734
- }
4735
- if (isSetString(pluginConfig)) {
4736
- const resolved = await this.#resolvePlugin(pluginConfig);
4737
- if (isFunction(resolved)) plugins = toArray(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
4738
- else plugins = toArray(resolved);
4739
- } else if (isFunction(pluginConfig)) plugins = toArray(await Promise.resolve(pluginConfig(pluginOptions)));
4740
- else if (Array.isArray(pluginConfig) && pluginConfig.every(isPlugin)) plugins = pluginConfig;
4741
- else if (isPlugin(pluginConfig)) plugins = toArray(pluginConfig);
4742
- }
4743
- if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
4744
- if (plugins.length > 0 && !plugins.every(isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
4745
- const result = [];
4746
- for (const plugin of plugins) if (checkDedupe(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
4747
- else {
4748
- result.push(plugin);
4749
- this.context.trace(`Initializing the ${chalk.bold.cyanBright(plugin.name)} plugin...`);
4750
- }
4751
- return result;
4752
- }
4753
- async #resolvePlugin(pluginPath) {
4754
- if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
4755
- const splits = pluginPath.split("/").filter(Boolean);
4756
- pluginPath = `${splits[0]}/${splits[1]}`;
4757
- }
4758
- const isInstalled = isPackageExists(pluginPath, { paths: [this.context.workspaceConfig.workspaceRoot, this.context.config.root] });
4759
- if (!isInstalled && this.context.config.autoInstall) {
4760
- this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
4761
- const result = await install(pluginPath, { cwd: this.context.config.root });
4762
- if (isNumber(result.exitCode) && result.exitCode > 0) {
4763
- this.#context.error(result.stderr);
4764
- throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
4765
- }
4766
- }
4767
- try {
4768
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths(pluginPath, "plugin")));
4769
- const result = module.plugin ?? module.default;
4770
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
4771
- return result;
4772
- } catch (error) {
4773
- try {
4774
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
4775
- const result = module.plugin ?? module.default;
4776
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
4777
- return result;
4778
- } catch {
4779
- if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
4780
- else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
4781
- ${isError(error) ? error.message : String(error)}
4782
-
4783
- Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
4784
- }
4785
- }
4786
- }
4787
- };
4788
-
4789
- //#endregion
4790
- //#region ../powerlines/src/index.ts
4791
- var src_default = PowerlinesAPI;
4792
-
4793
- //#endregion
4794
- //#region src/base/base-executor.ts
4795
- /**
4796
- * A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.
4797
- *
4798
- * @remarks
4799
- * This function is designed to simplify the creation of Powerlines executors by providing a consistent interface and error handling.
4800
- *
4801
- * @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
4802
- * @param executorFn - The function that will be executed when the command is run.
4803
- * @returns A Promise that resolves to the result of the executor function.
4804
- */
4805
- function withExecutor(command, executorFn) {
4806
- return withRunExecutor(`Powerlines ${command} command executor`, async (options, context, workspaceConfig) => {
4807
- if (!context.projectName) throw new Error("The executor requires `projectName` on the context object.");
4808
- if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) throw new Error("The executor requires `projectsConfigurations` on the context object.");
4809
- const projectConfig = context.projectsConfigurations.projects[context.projectName];
4810
- const api = await src_default.from(workspaceConfig.workspaceRoot, defu$1({
4811
- input: options.input,
4812
- output: {
4813
- outputPath: options.outputPath ?? projectConfig.targets?.build?.options?.outputPath,
4814
- format: options.format,
4815
- sourceMap: options.sourceMap
4816
- },
4817
- resolve: {
4818
- external: options.external,
4819
- noExternal: options.noExternal,
4820
- skipNodeModulesBundle: options.skipNodeModulesBundle
4821
- },
4822
- root: projectConfig.root,
4823
- projectType: projectConfig.projectType,
4824
- sourceRoot: projectConfig.sourceRoot,
4825
- tsconfig: options.tsconfig,
4826
- platform: options.platform,
4827
- define: options.define,
4828
- logLevel: options.logLevel,
4829
- mode: options.mode
4830
- }, options));
4831
- try {
4832
- return await Promise.resolve(executorFn(defu$1({
4833
- projectName: context.projectName,
4834
- options,
4835
- workspaceConfig,
4836
- inlineConfig: {
4837
- command,
4838
- configFile: options.configFile
4839
- },
4840
- command
4841
- }, context), api));
4842
- } catch (error) {
4843
- writeError(`An error occurred while executing the Powerlines ${command} command executor: ${isError(error) ? `${error.message}
4844
-
4845
- ${error.stack}` : "Unknown error"}`);
4846
- return { success: false };
4847
- } finally {
4848
- await api.finalize();
4849
- }
4850
- }, {
4851
- skipReadingConfig: false,
4852
- hooks: { applyDefaultOptions: (options) => {
4853
- if (options.mode !== "development" && options.mode !== "test") options.mode = "production";
4854
- options.outputPath ??= "dist/{projectRoot}";
4855
- options.configFile ??= "{projectRoot}/powerlines.config.ts";
4856
- return options;
4857
- } }
4858
- });
4859
- }
4860
-
4861
- //#endregion
4862
- export { withExecutor as t };
4863
- //# sourceMappingURL=base-executor-CC8rBACl.mjs.map