@powerlines/nx 0.10.45 → 0.10.47

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 (30) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{chunk-2JXCBCM2.js → chunk-23GFPMA6.js} +2 -2
  3. package/dist/{chunk-RV4A57IL.js → chunk-2ZHIKYNK.js} +2 -2
  4. package/dist/{chunk-ZL37TY72.js → chunk-3IX4CIEZ.js} +2 -2
  5. package/dist/{chunk-HMVFFEMQ.mjs → chunk-BRGJUSQE.mjs} +1 -1
  6. package/dist/{chunk-TCMZZXZF.mjs → chunk-JLOTTRGF.mjs} +310 -126
  7. package/dist/{chunk-7KYZYROW.mjs → chunk-KAGXZMPG.mjs} +1 -1
  8. package/dist/{chunk-6G6UOPGV.mjs → chunk-RVCS4GUB.mjs} +1 -1
  9. package/dist/{chunk-Z4DURF7V.js → chunk-SMUQRWNQ.js} +311 -127
  10. package/dist/{chunk-SFMHLFAI.mjs → chunk-SW7WPPQ5.mjs} +1 -1
  11. package/dist/{chunk-4GOHIU5C.js → chunk-UC4XWZN3.js} +2 -2
  12. package/dist/{chunk-OXP4T7OM.mjs → chunk-WOB6ZDJH.mjs} +1 -1
  13. package/dist/{chunk-DTWYF2BM.js → chunk-ZUHOITET.js} +2 -2
  14. package/dist/executors.js +11 -11
  15. package/dist/executors.mjs +6 -6
  16. package/dist/index.js +11 -11
  17. package/dist/index.mjs +6 -6
  18. package/dist/src/base/base-executor.js +2 -2
  19. package/dist/src/base/base-executor.mjs +1 -1
  20. package/dist/src/executors/build/executor.js +4 -4
  21. package/dist/src/executors/build/executor.mjs +2 -2
  22. package/dist/src/executors/clean/executor.js +4 -4
  23. package/dist/src/executors/clean/executor.mjs +2 -2
  24. package/dist/src/executors/docs/executor.js +4 -4
  25. package/dist/src/executors/docs/executor.mjs +2 -2
  26. package/dist/src/executors/lint/executor.js +4 -4
  27. package/dist/src/executors/lint/executor.mjs +2 -2
  28. package/dist/src/executors/prepare/executor.js +4 -4
  29. package/dist/src/executors/prepare/executor.mjs +2 -2
  30. package/package.json +8 -8
@@ -19,6 +19,7 @@ import { joinPaths as joinPaths$1 } from '@stryke/path/join-paths';
19
19
  import { replacePath, replaceExtension } from '@stryke/path/replace';
20
20
  import { isFunction } from '@stryke/type-checks/is-function';
21
21
  import { isNumber } from '@stryke/type-checks/is-number';
22
+ import { isObject } from '@stryke/type-checks/is-object';
22
23
  import { isPromiseLike } from '@stryke/type-checks/is-promise';
23
24
  import { isSet } from '@stryke/type-checks/is-set';
24
25
  import { isSetObject } from '@stryke/type-checks/is-set-object';
@@ -37,38 +38,40 @@ import { StormJSON } from '@stryke/json/storm-json';
37
38
  import { hasFileExtension, findFilePath, findFileName, relativePath, findFileDotExtensionSafe } from '@stryke/path/file-path-fns';
38
39
  import { titleCase } from '@stryke/string-format/title-case';
39
40
  import { existsSync, exists } from '@stryke/fs/exists';
40
- import { writeFileSync, writeFile as writeFile$1 } from '@stryke/fs/write-file';
41
- import { resolveConfig, format } from 'prettier';
42
41
  import { getEnvPaths } from '@stryke/env/get-env-paths';
43
42
  import { relativeToWorkspaceRoot } from '@stryke/fs/get-workspace-root';
44
43
  import { hashDirectory } from '@stryke/hash/hash-files';
45
44
  import { murmurhash } from '@stryke/hash/murmurhash';
46
45
  import { getUnique, getUniqueBy } from '@stryke/helpers/get-unique';
47
46
  import { omit } from '@stryke/helpers/omit';
47
+ import { fetchRequest } from '@stryke/http/fetch';
48
48
  import { isAbsolutePath, isAbsolute } from '@stryke/path/is-type';
49
49
  import { isNull } from '@stryke/type-checks/is-null';
50
50
  import { isString } from '@stryke/type-checks/is-string';
51
51
  import { uuid } from '@stryke/unique-id/uuid';
52
52
  import { tsconfigPathsToRegExp, match } from 'bundle-require';
53
+ import { create } from 'flat-cache';
54
+ import { parse } from 'oxc-parser';
55
+ import { Response } from 'undici';
53
56
  import { createJiti } from 'jiti';
54
57
  import { isUndefined } from '@stryke/type-checks/is-undefined';
55
58
  import { parseTypeDefinition } from '@stryke/convert/parse-type-definition';
56
59
  import { isFile } from '@stryke/fs/is-file';
57
60
  import * as $ from '@stryke/capnp';
58
61
  import { readFileBuffer, readFileBufferSync, writeFileBuffer } from '@stryke/fs/buffer';
59
- import { correctPath, toAbsolutePath } from '@stryke/path/correct-path';
60
62
  import { isParentPath } from '@stryke/path/is-parent-path';
61
63
  import { prettyBytes } from '@stryke/string-format/pretty-bytes';
62
- import { create } from 'flat-cache';
63
64
  import { Blob } from 'node:buffer';
65
+ import { resolveConfig, format } from 'prettier';
64
66
  import { getColor } from '@storm-software/config-tools/utilities/colors';
65
67
  import { noop } from '@stryke/helpers/noop';
68
+ import { correctPath } from '@stryke/path/correct-path';
66
69
  import { slash } from '@stryke/path/slash';
67
70
  import { readFileSync, readFile } from '@stryke/fs/read-file';
71
+ import { writeFileSync, writeFile } from '@stryke/fs/write-file';
68
72
  import { unlinkSync } from 'node:fs';
69
73
  import { unlink } from 'node:fs/promises';
70
74
  import { resolve } from 'node:path';
71
- import { isObject } from '@stryke/type-checks/is-object';
72
75
 
73
76
  function resolveModulePath(nodePath, state) {
74
77
  if (!t.isStringLiteral(nodePath.node)) {
@@ -330,7 +333,9 @@ async function callHook(context, hook, options, ...args) {
330
333
  if (!isFunction(handler)) {
331
334
  throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
332
335
  }
333
- return Promise.resolve(handler.apply(null, ...args));
336
+ return Promise.resolve(handler.apply(null, [
337
+ ...args
338
+ ]));
334
339
  }));
335
340
  } else {
336
341
  for (const handler of handlers) {
@@ -338,7 +343,9 @@ async function callHook(context, hook, options, ...args) {
338
343
  throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
339
344
  }
340
345
  if (options?.result === "first" || options?.asNextParam === false) {
341
- results.push(await Promise.resolve(handler.apply(null, ...args)));
346
+ results.push(await Promise.resolve(handler.apply(null, [
347
+ ...args
348
+ ])));
342
349
  if (options?.result === "first" && isSet(results[results.length - 1])) {
343
350
  break;
344
351
  }
@@ -350,12 +357,22 @@ async function callHook(context, hook, options, ...args) {
350
357
  sequenceArgs[0] = isFunction(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
351
358
  }
352
359
  const result = await Promise.resolve(
353
- // eslint-disable-next-line ts/no-unsafe-call
354
- handler.apply(null, ...sequenceArgs)
360
+ // eslint-disable-next-line ts/no-unsafe-call, no-useless-call
361
+ handler.apply(null, [
362
+ ...sequenceArgs
363
+ ])
355
364
  );
356
- results = [
357
- result
358
- ];
365
+ if (result) {
366
+ if (options?.result === "last") {
367
+ results = [
368
+ result
369
+ ];
370
+ } else {
371
+ results = [
372
+ defu(result, results[0] ?? {})
373
+ ];
374
+ }
375
+ }
359
376
  }
360
377
  }
361
378
  }
@@ -521,33 +538,20 @@ ${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && err
521
538
  };
522
539
  }
523
540
  __name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");
524
- async function writeFile(log, filepath, content, skipFormat = false) {
525
- try {
526
- if (skipFormat) {
527
- await writeFile$1(filepath, content);
528
- } else {
529
- const config = await resolveConfig(filepath);
530
- const formatted = await format(content, {
531
- ...config ?? {},
532
- filepath
533
- });
534
- await writeFile$1(filepath, formatted || "");
535
- }
536
- } catch (error) {
537
- log(LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk
538
- ${error?.message ? error.message : ""}`);
539
- }
540
- }
541
- __name(writeFile, "writeFile");
542
541
 
543
542
  // ../powerlines/src/internal/helpers/resolve-tsconfig.ts
543
+ function getTsconfigDtsPath(context) {
544
+ const dtsRelativePath = joinPaths$1(relativePath(joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.projectRoot), findFilePath(context.dtsPath)), findFileName(context.dtsPath));
545
+ return dtsRelativePath;
546
+ }
547
+ __name(getTsconfigDtsPath, "getTsconfigDtsPath");
544
548
  async function resolveTsconfigChanges(context) {
545
549
  const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
546
550
  const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
547
551
  const tsconfigJson = await readJsonFile(tsconfigFilePath);
548
552
  tsconfigJson.compilerOptions ??= {};
549
553
  if (context.config.output.dts !== false) {
550
- const dtsRelativePath = joinPaths$1(relativePath(joinPaths$1(context.workspaceConfig.workspaceRoot, context.config.projectRoot), findFilePath(context.dtsPath)), findFileName(context.dtsPath));
554
+ const dtsRelativePath = getTsconfigDtsPath(context);
551
555
  if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
552
556
  context.dtsPath,
553
557
  dtsRelativePath
@@ -589,7 +593,7 @@ async function initializeTsconfig(context) {
589
593
  context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
590
594
  context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
591
595
  context.log(LogLevelLabel.TRACE, "Writing updated TypeScript configuration (tsconfig.json) file to disk.");
592
- await writeFile(context.log, tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson));
596
+ await context.fs.write(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson));
593
597
  context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
594
598
  }
595
599
  __name(initializeTsconfig, "initializeTsconfig");
@@ -638,13 +642,11 @@ async function resolveTsconfig(context) {
638
642
  `).join("\n")}
639
643
  `);
640
644
  }
641
- await writeFile(context.log, context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
645
+ await context.fs.write(context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
642
646
  context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
643
647
  if (!context.tsconfig) {
644
648
  throw new Error("Failed to parse the TypeScript configuration file.");
645
649
  }
646
- context.tsconfig.tsconfigJson.compilerOptions ??= {};
647
- context.tsconfig.tsconfigJson.compilerOptions.strict = false;
648
650
  }
649
651
  __name(resolveTsconfig, "resolveTsconfig");
650
652
  var DEFAULT_ENVIRONMENT = "default";
@@ -784,7 +786,7 @@ function replacePathTokens(context, path) {
784
786
  if (!path) {
785
787
  return path;
786
788
  }
787
- return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{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));
789
+ return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{sourceRoot}", context.config.sourceRoot).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));
788
790
  }
789
791
  __name(replacePathTokens, "replacePathTokens");
790
792
  function resolveEntryInputFile(context, typeDefinition) {
@@ -1353,7 +1355,7 @@ var FileSystemStorageAdapter = class extends BaseStorageAdapter {
1353
1355
  */
1354
1356
  async set(key, value) {
1355
1357
  if (!this.options.isReadOnly) {
1356
- return writeFile$1(this.resolve(key), value);
1358
+ return writeFile(this.resolve(key), value);
1357
1359
  }
1358
1360
  }
1359
1361
  /**
@@ -1536,7 +1538,11 @@ var VirtualFileSystem = class _VirtualFileSystem {
1536
1538
  * @returns The normalized module id.
1537
1539
  */
1538
1540
  #normalizeId(id) {
1539
- return normalizeId(id, this.#context.config.output.builtinPrefix);
1541
+ let normalized = id;
1542
+ if (isParentPath(normalized, this.#context.builtinsPath)) {
1543
+ normalized = replacePath(normalized, this.#context.builtinsPath);
1544
+ }
1545
+ return normalizeId(normalized, this.#context.config.output.builtinPrefix);
1540
1546
  }
1541
1547
  /**
1542
1548
  * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
@@ -1545,7 +1551,7 @@ var VirtualFileSystem = class _VirtualFileSystem {
1545
1551
  * @returns The normalized path.
1546
1552
  */
1547
1553
  #normalizePath(path) {
1548
- return normalizePath(path, this.#context.builtinsPath, this.#context.config.output.builtinPrefix);
1554
+ return normalizePath(path.includes("{") || path.includes("}") ? replacePathTokens(this.#context, path) : path, this.#context.builtinsPath, this.#context.config.output.builtinPrefix);
1549
1555
  }
1550
1556
  /**
1551
1557
  * Builds a regular expression from a string pattern for path matching.
@@ -2050,15 +2056,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
2050
2056
  }
2051
2057
  }
2052
2058
  const { relativeKey, adapter } = this.#getStorage(path);
2053
- this.#log(LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
2054
- const id = options?.meta?.id || this.#normalizeId(path);
2059
+ this.#log(LogLevelLabel.TRACE, `Writing ${this.#normalizePath(relativeKey)} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
2060
+ const id = options?.meta?.id || this.#normalizeId(relativeKey);
2055
2061
  this.#metadata[id] = {
2056
2062
  variant: "normal",
2057
2063
  timestamp: Date.now(),
2058
2064
  ...options.meta ?? {}
2059
2065
  };
2060
- this.#paths[id] = this.#normalizePath(path);
2061
- this.#ids[this.#normalizePath(path)] = id;
2066
+ this.#paths[id] = this.#normalizePath(relativeKey);
2067
+ this.#ids[this.#normalizePath(relativeKey)] = id;
2062
2068
  return adapter.set(relativeKey, code);
2063
2069
  }
2064
2070
  /**
@@ -2070,15 +2076,15 @@ var VirtualFileSystem = class _VirtualFileSystem {
2070
2076
  */
2071
2077
  writeSync(path, data = "", options = {}) {
2072
2078
  const { relativeKey, adapter } = this.#getStorage(path);
2073
- this.#log(LogLevelLabel.TRACE, `Writing ${this.#normalizePath(path)} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob(toArray(data)).size)})`);
2074
- const id = options?.meta?.id || this.#normalizeId(path);
2079
+ this.#log(LogLevelLabel.TRACE, `Writing ${this.#normalizePath(relativeKey)} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob(toArray(data)).size)})`);
2080
+ const id = options?.meta?.id || this.#normalizeId(relativeKey);
2075
2081
  this.#metadata[id] = {
2076
2082
  variant: "normal",
2077
2083
  timestamp: Date.now(),
2078
2084
  ...options.meta ?? {}
2079
2085
  };
2080
- this.#paths[id] = this.#normalizePath(path);
2081
- this.#ids[this.#normalizePath(path)] = id;
2086
+ this.#paths[id] = this.#normalizePath(relativeKey);
2087
+ this.#ids[this.#normalizePath(relativeKey)] = id;
2082
2088
  return adapter.setSync(relativeKey, data);
2083
2089
  }
2084
2090
  /**
@@ -2111,17 +2117,26 @@ var VirtualFileSystem = class _VirtualFileSystem {
2111
2117
  * @returns A promise that resolves to the resolved module path.
2112
2118
  */
2113
2119
  async resolve(id, importer, options = {}) {
2114
- if (isAbsolutePath(id)) {
2115
- return id;
2120
+ let path = id;
2121
+ if (path.includes("{") || path.includes("}")) {
2122
+ path = replacePathTokens(this.#context, path);
2123
+ }
2124
+ if (isAbsolutePath(path)) {
2125
+ return path;
2116
2126
  }
2127
+ const resolverCacheKey = murmurhash({
2128
+ path: this.#normalizeId(path),
2129
+ importer,
2130
+ options
2131
+ });
2117
2132
  let result;
2118
2133
  if (!this.#context.config.skipCache) {
2119
- result = this.resolverCache.get(this.#normalizeId(id));
2134
+ result = this.resolverCache.get(resolverCacheKey);
2120
2135
  if (result) {
2121
2136
  return result;
2122
2137
  }
2123
2138
  }
2124
- result = this.paths[this.#normalizeId(id)];
2139
+ result = this.paths[this.#normalizeId(path)];
2125
2140
  if (!result) {
2126
2141
  const paths = options.paths ?? [];
2127
2142
  if (importer && !paths.includes(importer)) {
@@ -2130,8 +2145,8 @@ var VirtualFileSystem = class _VirtualFileSystem {
2130
2145
  paths.push(this.#context.workspaceConfig.workspaceRoot);
2131
2146
  paths.push(appendPath(this.#context.config.projectRoot, this.#context.workspaceConfig.workspaceRoot));
2132
2147
  paths.push(appendPath(this.#context.config.sourceRoot, this.#context.workspaceConfig.workspaceRoot));
2133
- paths.push(...Object.keys(this.#context.tsconfig.options.paths ?? {}).filter((tsconfigPath) => id.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
2134
- for (const combination of getResolutionCombinations(id, {
2148
+ 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)));
2149
+ for (const combination of getResolutionCombinations(path, {
2135
2150
  paths
2136
2151
  })) {
2137
2152
  const { relativeKey, adapter } = this.#getStorage(combination);
@@ -2140,18 +2155,18 @@ var VirtualFileSystem = class _VirtualFileSystem {
2140
2155
  break;
2141
2156
  }
2142
2157
  }
2143
- try {
2144
- result = await resolve$1(id, {
2145
- paths
2146
- });
2147
- } catch {
2158
+ if (!result) {
2159
+ try {
2160
+ result = await resolve$1(path, {
2161
+ ...options,
2162
+ paths
2163
+ });
2164
+ } catch {
2165
+ }
2148
2166
  }
2149
2167
  }
2150
- if (result) {
2151
- result = toAbsolutePath(appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
2152
- if (!this.#context.config.skipCache) {
2153
- this.resolverCache.set(this.#normalizeId(id), result);
2154
- }
2168
+ if (result && !this.#context.config.skipCache) {
2169
+ this.resolverCache.set(resolverCacheKey, result);
2155
2170
  }
2156
2171
  return result;
2157
2172
  }
@@ -2172,17 +2187,21 @@ var VirtualFileSystem = class _VirtualFileSystem {
2172
2187
  * @returns The resolved module path.
2173
2188
  */
2174
2189
  resolveSync(id, importer, options = {}) {
2175
- if (isAbsolutePath(id)) {
2176
- return id;
2190
+ let path = id;
2191
+ if (path.includes("{") || path.includes("}")) {
2192
+ path = replacePathTokens(this.#context, path);
2193
+ }
2194
+ if (isAbsolutePath(path)) {
2195
+ return path;
2177
2196
  }
2178
2197
  let result;
2179
2198
  if (!this.#context.config.skipCache) {
2180
- result = this.resolverCache.get(this.#normalizeId(id));
2199
+ result = this.resolverCache.get(this.#normalizeId(path));
2181
2200
  if (result) {
2182
2201
  return result;
2183
2202
  }
2184
2203
  }
2185
- result = this.paths[this.#normalizeId(id)];
2204
+ result = this.paths[this.#normalizeId(path)];
2186
2205
  if (!result) {
2187
2206
  const paths = options.paths ?? [];
2188
2207
  if (importer && !paths.includes(importer)) {
@@ -2191,8 +2210,8 @@ var VirtualFileSystem = class _VirtualFileSystem {
2191
2210
  paths.push(this.#context.workspaceConfig.workspaceRoot);
2192
2211
  paths.push(appendPath(this.#context.config.projectRoot, this.#context.workspaceConfig.workspaceRoot));
2193
2212
  paths.push(appendPath(this.#context.config.sourceRoot, this.#context.workspaceConfig.workspaceRoot));
2194
- paths.push(...Object.keys(this.#context.tsconfig.options.paths ?? {}).filter((tsconfigPath) => id.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => appendPath(tsconfigPath, this.#context.workspaceConfig.workspaceRoot)));
2195
- for (const combination of getResolutionCombinations(id, {
2213
+ 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)));
2214
+ for (const combination of getResolutionCombinations(path, {
2196
2215
  paths
2197
2216
  })) {
2198
2217
  const { relativeKey, adapter } = this.#getStorage(combination);
@@ -2201,18 +2220,18 @@ var VirtualFileSystem = class _VirtualFileSystem {
2201
2220
  break;
2202
2221
  }
2203
2222
  }
2204
- try {
2205
- result = resolveSync(id, {
2206
- paths
2207
- });
2208
- } catch {
2223
+ if (!result) {
2224
+ try {
2225
+ result = resolveSync(path, {
2226
+ ...options,
2227
+ paths
2228
+ });
2229
+ } catch {
2230
+ }
2209
2231
  }
2210
2232
  }
2211
- if (result) {
2212
- result = toAbsolutePath(appendPath(result, this.#context.config.projectRoot), this.#context.workspaceConfig.workspaceRoot);
2213
- if (!this.#context.config.skipCache) {
2214
- this.resolverCache.set(this.#normalizeId(id), result);
2215
- }
2233
+ if (result && !this.#context.config.skipCache) {
2234
+ this.resolverCache.set(this.#normalizeId(path), result);
2216
2235
  }
2217
2236
  return result;
2218
2237
  }
@@ -2312,7 +2331,8 @@ var PowerlinesContext = class _PowerlinesContext {
2312
2331
  #fs;
2313
2332
  #tsconfig;
2314
2333
  #program;
2315
- #resolvePatterns = [];
2334
+ #parserCache;
2335
+ #requestCache;
2316
2336
  #getConfigProps(config = {}) {
2317
2337
  return {
2318
2338
  variant: config.build?.variant,
@@ -2336,7 +2356,8 @@ var PowerlinesContext = class _PowerlinesContext {
2336
2356
  lint: config.lint,
2337
2357
  transform: config.transform,
2338
2358
  build: config.build,
2339
- framework: config.framework
2359
+ framework: config.framework,
2360
+ ...config
2340
2361
  };
2341
2362
  }
2342
2363
  /**
@@ -2384,6 +2405,10 @@ var PowerlinesContext = class _PowerlinesContext {
2384
2405
  */
2385
2406
  resolver;
2386
2407
  /**
2408
+ * The resolved configuration options
2409
+ */
2410
+ resolvePatterns = [];
2411
+ /**
2387
2412
  * Internal context fields and methods
2388
2413
  *
2389
2414
  * @internal
@@ -2415,7 +2440,7 @@ var PowerlinesContext = class _PowerlinesContext {
2415
2440
  */
2416
2441
  set tsconfig(value) {
2417
2442
  this.#tsconfig = value;
2418
- this.#resolvePatterns = tsconfigPathsToRegExp(value?.options?.paths ?? {});
2443
+ this.resolvePatterns = tsconfigPathsToRegExp(value?.options?.paths ?? {});
2419
2444
  }
2420
2445
  /**
2421
2446
  * The virtual file system interface for the project
@@ -2556,6 +2581,123 @@ var PowerlinesContext = class _PowerlinesContext {
2556
2581
  return this.#program;
2557
2582
  }
2558
2583
  /**
2584
+ * Gets the parser cache.
2585
+ */
2586
+ get parserCache() {
2587
+ if (!this.#parserCache) {
2588
+ this.#parserCache = create({
2589
+ cacheId: "parser",
2590
+ cacheDir: this.cachePath,
2591
+ ttl: 2 * 60 * 60 * 1e3,
2592
+ lruSize: 5e3,
2593
+ persistInterval: 250
2594
+ });
2595
+ }
2596
+ return this.#parserCache;
2597
+ }
2598
+ /**
2599
+ * Gets the request cache.
2600
+ */
2601
+ get requestCache() {
2602
+ if (!this.#requestCache) {
2603
+ this.#requestCache = create({
2604
+ cacheId: "http",
2605
+ cacheDir: this.cachePath,
2606
+ ttl: 5 * 60 * 1e3,
2607
+ lruSize: 5e3,
2608
+ persistInterval: 250
2609
+ });
2610
+ }
2611
+ return this.#requestCache;
2612
+ }
2613
+ /**
2614
+ * A function to perform HTTP fetch requests
2615
+ *
2616
+ * @remarks
2617
+ * This function uses a caching layer to avoid duplicate requests during the Powerlines process.
2618
+ *
2619
+ * @example
2620
+ * ```ts
2621
+ * const response = await context.fetch("https://api.example.com/data");
2622
+ * const data = await response.json();
2623
+ * ```
2624
+ *
2625
+ * @see https://github.com/nodejs/undici
2626
+ *
2627
+ * @param input - The URL to fetch.
2628
+ * @param options - The fetch request options.
2629
+ * @returns A promise that resolves to a response returned by the fetch.
2630
+ */
2631
+ async fetch(input, options = {}) {
2632
+ const cacheKey = murmurhash({
2633
+ input: input.toString(),
2634
+ options: JSON.stringify(options)
2635
+ });
2636
+ if (!this.config.skipCache && !options.skipCache) {
2637
+ const cached = this.requestCache.get(cacheKey);
2638
+ if (cached) {
2639
+ return new Response(cached.body, {
2640
+ status: cached.status,
2641
+ statusText: cached.statusText,
2642
+ headers: cached.headers
2643
+ });
2644
+ }
2645
+ }
2646
+ const result = await fetchRequest(input, options);
2647
+ if (!this.config.skipCache && !options.skipCache) {
2648
+ try {
2649
+ this.requestCache.set(cacheKey, {
2650
+ body: await result.text(),
2651
+ status: result.status,
2652
+ statusText: result.statusText,
2653
+ headers: Object.fromEntries(result.headers.entries())
2654
+ });
2655
+ } catch {
2656
+ }
2657
+ }
2658
+ return result;
2659
+ }
2660
+ /**
2661
+ * Parse code using [Oxc-Parser](https://github.com/oxc/oxc) into an (ESTree-compatible)[https://github.com/estree/estree] AST object.
2662
+ *
2663
+ * @remarks
2664
+ * This function can be used to parse TypeScript code into an AST for further analysis or transformation.
2665
+ *
2666
+ * @example
2667
+ * ```ts
2668
+ * const ast = context.parse("const x: number = 42;");
2669
+ * ```
2670
+ *
2671
+ * @see https://rollupjs.org/plugin-development/#this-parse
2672
+ * @see https://github.com/oxc/oxc
2673
+ *
2674
+ * @param code - The source code to parse.
2675
+ * @param options - The options to pass to the parser.
2676
+ * @returns An (ESTree-compatible)[https://github.com/estree/estree] AST object.
2677
+ */
2678
+ async parse(code, options = {}) {
2679
+ const cacheKey = murmurhash({
2680
+ code,
2681
+ options
2682
+ });
2683
+ let result;
2684
+ if (!this.config.skipCache) {
2685
+ result = this.parserCache.get(cacheKey);
2686
+ if (result) {
2687
+ return result;
2688
+ }
2689
+ }
2690
+ result = await parse(`source.${options.lang || "ts"}`, code, {
2691
+ ...options,
2692
+ sourceType: "module",
2693
+ showSemanticErrors: this.config.mode === "development"
2694
+ });
2695
+ if (!this.config.skipCache) {
2696
+ this.parserCache.set(cacheKey, result);
2697
+ }
2698
+ return result;
2699
+ }
2700
+ /**
2559
2701
  * A helper function to resolve modules in the Virtual File System
2560
2702
  *
2561
2703
  * @remarks
@@ -2571,9 +2713,26 @@ var PowerlinesContext = class _PowerlinesContext {
2571
2713
  * @param options - Additional resolution options.
2572
2714
  * @returns A promise that resolves to the resolved module path.
2573
2715
  */
2574
- async resolveId(id, importer, options = {}) {
2575
- if (this.fs.isVirtual(id)) {
2576
- const result = await this.fs.resolve(id, importer, options);
2716
+ async resolve(id, importer, options = {}) {
2717
+ let moduleId = id;
2718
+ if (this.config.build.alias) {
2719
+ if (Array.isArray(this.config.build.alias)) {
2720
+ const alias = this.config.build.alias.find((a) => match(moduleId, [
2721
+ a.find
2722
+ ]));
2723
+ if (alias) {
2724
+ moduleId = alias.replacement;
2725
+ }
2726
+ } else if (isSetObject(this.config.build.alias) && this.config.build.alias[id]) {
2727
+ moduleId = this.config.build.alias[id];
2728
+ }
2729
+ }
2730
+ if (this.fs.isVirtual(moduleId)) {
2731
+ const result = await this.fs.resolve(moduleId, importer, {
2732
+ conditions: this.config.build.conditions,
2733
+ extensions: this.config.build.extensions,
2734
+ ...options
2735
+ });
2577
2736
  if (!result) {
2578
2737
  return void 0;
2579
2738
  }
@@ -2583,28 +2742,28 @@ var PowerlinesContext = class _PowerlinesContext {
2583
2742
  };
2584
2743
  }
2585
2744
  if (this.config.build.skipNodeModulesBundle) {
2586
- if (match(id, this.#resolvePatterns) || match(id, this.config.build.noExternal)) {
2745
+ if (match(moduleId, this.resolvePatterns) || match(moduleId, this.config.build.noExternal)) {
2587
2746
  return void 0;
2588
2747
  }
2589
- if (match(id, this.config.build.external) || id.startsWith("node:")) {
2748
+ if (match(moduleId, this.config.build.external) || moduleId.startsWith("node:")) {
2590
2749
  return {
2591
- id,
2750
+ id: moduleId,
2592
2751
  external: true
2593
2752
  };
2594
2753
  }
2595
- if (!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(id)) {
2754
+ if (!/^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/.test(moduleId)) {
2596
2755
  return {
2597
- id,
2756
+ id: moduleId,
2598
2757
  external: true
2599
2758
  };
2600
2759
  }
2601
2760
  } else {
2602
- if (match(id, this.config.build.noExternal)) {
2761
+ if (match(moduleId, this.config.build.noExternal)) {
2603
2762
  return void 0;
2604
2763
  }
2605
- if (match(id, this.config.build.external) || id.startsWith("node:")) {
2764
+ if (match(moduleId, this.config.build.external) || moduleId.startsWith("node:")) {
2606
2765
  return {
2607
- id,
2766
+ id: moduleId,
2608
2767
  external: true
2609
2768
  };
2610
2769
  }
@@ -2777,6 +2936,26 @@ var PowerlinesContext = class _PowerlinesContext {
2777
2936
  return extendLog(this.log, name);
2778
2937
  }
2779
2938
  /**
2939
+ * Generates a checksum representing the current context state
2940
+ *
2941
+ * @param root - The root directory of the project to generate the checksum for
2942
+ * @returns A promise that resolves to a string representing the checksum
2943
+ */
2944
+ async generateChecksum(root = this.config.projectRoot) {
2945
+ this.#checksum = await hashDirectory(root, {
2946
+ ignore: [
2947
+ "node_modules",
2948
+ ".git",
2949
+ ".nx",
2950
+ ".cache",
2951
+ ".storm",
2952
+ "tmp",
2953
+ "dist"
2954
+ ]
2955
+ });
2956
+ return this.#checksum;
2957
+ }
2958
+ /**
2780
2959
  * Creates a new StormContext instance.
2781
2960
  *
2782
2961
  * @param workspaceConfig - The workspace configuration.
@@ -2798,26 +2977,6 @@ var PowerlinesContext = class _PowerlinesContext {
2798
2977
  */
2799
2978
  logFn;
2800
2979
  /**
2801
- * Generates a checksum representing the current context state
2802
- *
2803
- * @param root - The root directory of the project to generate the checksum for
2804
- * @returns A promise that resolves to a string representing the checksum
2805
- */
2806
- async generateChecksum(root = this.config.projectRoot) {
2807
- this.#checksum = await hashDirectory(root, {
2808
- ignore: [
2809
- "node_modules",
2810
- ".git",
2811
- ".nx",
2812
- ".cache",
2813
- ".storm",
2814
- "tmp",
2815
- "dist"
2816
- ]
2817
- });
2818
- return this.#checksum;
2819
- }
2820
- /**
2821
2980
  * Initialize the context with the provided configuration options
2822
2981
  *
2823
2982
  * @param config - The partial user configuration to use for initialization.
@@ -3030,9 +3189,11 @@ function createPluginContext(plugin, environment) {
3030
3189
  }, "normalizeMessage");
3031
3190
  const log = environment.extendLog(plugin.name);
3032
3191
  const callHookFn = /* @__PURE__ */ __name(async (hook, options, ...args) => {
3033
- return callHook(environment, hook, {
3192
+ return environment.$$internal.api.callHook(hook, {
3034
3193
  sequential: true,
3035
- ...options
3194
+ result: "merge",
3195
+ ...options,
3196
+ environment
3036
3197
  }, ...args);
3037
3198
  }, "callHookFn");
3038
3199
  return new Proxy({}, {
@@ -3415,7 +3576,11 @@ var PowerlinesAPI = class _PowerlinesAPI {
3415
3576
  this.#context = context;
3416
3577
  }
3417
3578
  /**
3418
- * Initialize the Powerlines API
3579
+ * Initialize a Powerlines API instance
3580
+ *
3581
+ * @param workspaceRoot - The directory of the underlying workspace the Powerlines project exists in
3582
+ * @param config - An object containing the configuration required to run Powerlines tasks.
3583
+ * @returns A new instance of the Powerlines API
3419
3584
  */
3420
3585
  static async from(workspaceRoot, config) {
3421
3586
  const api = new _PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
@@ -3543,9 +3708,13 @@ ${formatLogMessage(context.config)}`);
3543
3708
  let generatedTypes = await emitTypes(context, files);
3544
3709
  context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file ${context.dtsPath}.`);
3545
3710
  const directives = [];
3711
+ const asNextParam = /* @__PURE__ */ __name((previousResult) => isObject(previousResult) ? previousResult.code : previousResult, "asNextParam");
3546
3712
  let result = await this.callHook("generateTypes", {
3547
3713
  environment: context,
3548
- order: "pre"
3714
+ sequential: true,
3715
+ order: "pre",
3716
+ result: "merge",
3717
+ asNextParam
3549
3718
  }, generatedTypes);
3550
3719
  if (result) {
3551
3720
  if (isSetObject(result)) {
@@ -3559,7 +3728,10 @@ ${formatLogMessage(context.config)}`);
3559
3728
  }
3560
3729
  result = await this.callHook("generateTypes", {
3561
3730
  environment: context,
3562
- order: "normal"
3731
+ sequential: true,
3732
+ order: "normal",
3733
+ result: "merge",
3734
+ asNextParam
3563
3735
  }, generatedTypes);
3564
3736
  if (result) {
3565
3737
  if (isSetObject(result)) {
@@ -3573,7 +3745,10 @@ ${formatLogMessage(context.config)}`);
3573
3745
  }
3574
3746
  result = await this.callHook("generateTypes", {
3575
3747
  environment: context,
3576
- order: "post"
3748
+ sequential: true,
3749
+ order: "post",
3750
+ result: "merge",
3751
+ asNextParam
3577
3752
  }, generatedTypes);
3578
3753
  if (result) {
3579
3754
  if (isSetObject(result)) {
@@ -3585,15 +3760,24 @@ ${formatLogMessage(context.config)}`);
3585
3760
  generatedTypes = result;
3586
3761
  }
3587
3762
  }
3588
- await context.fs.write(context.dtsPath, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
3763
+ if (generatedTypes?.trim() || directives.length > 0) {
3764
+ await context.fs.write(context.dtsPath, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
3589
3765
 
3590
3766
  ` : ""}${getFileHeader(context, {
3591
- directive: null,
3592
- prettierIgnore: false
3593
- })}
3767
+ directive: null,
3768
+ prettierIgnore: false
3769
+ })}
3594
3770
 
3595
3771
  ${formatTypes(generatedTypes)}
3596
3772
  `);
3773
+ } else {
3774
+ const dtsRelativePath = getTsconfigDtsPath(context);
3775
+ if (context.tsconfig.tsconfigJson.include && isIncludeMatchFound(dtsRelativePath, context.tsconfig.tsconfigJson.include)) {
3776
+ const normalizedDtsRelativePath = dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath;
3777
+ context.tsconfig.tsconfigJson.include = context.tsconfig.tsconfigJson.include.filter((includeValue) => includeValue?.toString() !== normalizedDtsRelativePath);
3778
+ await context.fs.write(context.tsconfig.tsconfigFilePath, JSON.stringify(context.tsconfig.tsconfigJson, null, 2));
3779
+ }
3780
+ }
3597
3781
  }
3598
3782
  context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
3599
3783
  if (!context.tsconfig) {
@@ -3630,7 +3814,7 @@ ${formatTypes(generatedTypes)}
3630
3814
  for (const file of files) {
3631
3815
  context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
3632
3816
  const template = Handlebars.compile(file);
3633
- await writeFile(context.log, joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
3817
+ await context.fs.write(joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
3634
3818
  }
3635
3819
  await this.callHook("new", {
3636
3820
  environment: context,
@@ -3641,14 +3825,14 @@ ${formatTypes(generatedTypes)}
3641
3825
  for (const file of files2) {
3642
3826
  context.log(LogLevelLabel.TRACE, `Adding application template file: ${file}`);
3643
3827
  const template = Handlebars.compile(file);
3644
- await writeFile(context.log, joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
3828
+ await context.fs.write(joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
3645
3829
  }
3646
3830
  } else {
3647
3831
  const files2 = await listFiles(joinPaths$1(context.powerlinesPath, "files/library/**/*.hbs"));
3648
3832
  for (const file of files2) {
3649
3833
  context.log(LogLevelLabel.TRACE, `Adding library template file: ${file}`);
3650
3834
  const template = Handlebars.compile(file);
3651
- await writeFile(context.log, joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
3835
+ await context.fs.write(joinPaths$1(context.config.projectRoot, file.replace(".hbs", "")), template(context));
3652
3836
  }
3653
3837
  }
3654
3838
  await this.callHook("new", {