depflow 3.0.0-dev.1 → 3.0.0-dev.11

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 (165) hide show
  1. package/README.md +108 -43
  2. package/dist/builder/Builder.d.ts +279 -0
  3. package/dist/builder/Builder.js +391 -0
  4. package/dist/builder/Builder.js.map +1 -0
  5. package/dist/cli/CLI.d.ts +157 -0
  6. package/dist/cli/CLI.js +214 -0
  7. package/dist/cli/CLI.js.map +1 -0
  8. package/dist/cli/DepFLowCLI.d.ts +93 -0
  9. package/dist/cli/DepFLowCLI.js +413 -0
  10. package/dist/cli/DepFLowCLI.js.map +1 -0
  11. package/dist/cli/Flags.d.ts +106 -0
  12. package/dist/cli/Flags.js +125 -0
  13. package/dist/cli/Flags.js.map +1 -0
  14. package/dist/cli/bin.js +68 -0
  15. package/dist/cli/bin.js.map +1 -0
  16. package/dist/config/Config.d.ts +690 -0
  17. package/dist/config/Config.js +45 -0
  18. package/dist/config/Config.js.map +1 -0
  19. package/dist/config/ImportMap.d.ts +60 -0
  20. package/dist/config/ImportMap.js +66 -0
  21. package/dist/config/ImportMap.js.map +1 -0
  22. package/dist/config/JsonSchema.d.ts +12 -0
  23. package/dist/config/JsonSchema.js +26 -0
  24. package/dist/config/JsonSchema.js.map +1 -0
  25. package/dist/config/Settings.d.ts +201 -0
  26. package/dist/config/Settings.js +191 -0
  27. package/dist/config/Settings.js.map +1 -0
  28. package/dist/config/TSConfig.d.ts +73 -0
  29. package/dist/config/TSConfig.js +73 -0
  30. package/dist/config/TSConfig.js.map +1 -0
  31. package/dist/config/codecs/JsonCodec.d.ts +30 -0
  32. package/dist/config/codecs/JsonCodec.js +31 -0
  33. package/dist/config/codecs/JsonCodec.js.map +1 -0
  34. package/dist/config/codecs/YamlCodec.d.ts +62 -0
  35. package/dist/config/codecs/YamlCodec.js +89 -0
  36. package/dist/config/codecs/YamlCodec.js.map +1 -0
  37. package/dist/dependency/DepUtils.d.ts +50 -0
  38. package/dist/dependency/DepUtils.js +71 -0
  39. package/dist/dependency/DepUtils.js.map +1 -0
  40. package/dist/dependency/Dependency.d.ts +81 -0
  41. package/dist/dependency/Dependency.js +71 -0
  42. package/dist/dependency/Dependency.js.map +1 -0
  43. package/dist/dependency/Git.d.ts +75 -0
  44. package/dist/dependency/Git.js +97 -0
  45. package/dist/dependency/Git.js.map +1 -0
  46. package/dist/dependency/GitDependency.d.ts +30 -0
  47. package/dist/dependency/GitDependency.js +79 -0
  48. package/dist/dependency/GitDependency.js.map +1 -0
  49. package/dist/dependency/NpmDependency.d.ts +27 -0
  50. package/dist/dependency/NpmDependency.js +91 -0
  51. package/dist/dependency/NpmDependency.js.map +1 -0
  52. package/dist/resolve/AliasCompiler.d.ts +45 -0
  53. package/dist/resolve/AliasCompiler.js +84 -0
  54. package/dist/resolve/AliasCompiler.js.map +1 -0
  55. package/{build/support/PathResolver → dist/resolve}/PathResolver.d.ts +26 -9
  56. package/dist/resolve/PathResolver.js +133 -0
  57. package/dist/resolve/PathResolver.js.map +1 -0
  58. package/dist/resolve/PathRewriter.d.ts +24 -0
  59. package/{build/support/PathResolver → dist/resolve}/PathRewriter.js +21 -11
  60. package/dist/resolve/PathRewriter.js.map +1 -0
  61. package/dist/schema/Config/Builder.d.ts +496 -0
  62. package/dist/schema/Config/Builder.js +78 -0
  63. package/dist/schema/Config/Builder.js.map +1 -0
  64. package/dist/schema/Config/Config.d.ts +673 -0
  65. package/dist/schema/Config/Config.js +62 -0
  66. package/dist/schema/Config/Config.js.map +1 -0
  67. package/dist/schema/Config/Dependency.d.ts +878 -0
  68. package/dist/schema/Config/Dependency.js +80 -0
  69. package/dist/schema/Config/Dependency.js.map +1 -0
  70. package/dist/schema/Config/Extractor.d.ts +157 -0
  71. package/dist/schema/Config/Extractor.js +43 -0
  72. package/dist/schema/Config/Extractor.js.map +1 -0
  73. package/dist/schema/Config/Resolver.d.ts +87 -0
  74. package/dist/schema/Config/Resolver.js +43 -0
  75. package/dist/schema/Config/Resolver.js.map +1 -0
  76. package/dist/schema/Config/Transform.d.ts +90 -0
  77. package/dist/schema/Config/Transform.js +51 -0
  78. package/dist/schema/Config/Transform.js.map +1 -0
  79. package/dist/schema/Defaults.d.ts +20 -0
  80. package/dist/schema/Defaults.js +24 -0
  81. package/dist/schema/Defaults.js.map +1 -0
  82. package/dist/schema/ImportMap.d.ts +30 -0
  83. package/dist/schema/ImportMap.js +28 -0
  84. package/dist/schema/ImportMap.js.map +1 -0
  85. package/dist/schema/TSConfig.d.ts +70 -0
  86. package/dist/schema/TSConfig.js +39 -0
  87. package/dist/schema/TSConfig.js.map +1 -0
  88. package/dist/schema/schema.d.ts +38 -0
  89. package/dist/schema/schema.js +40 -0
  90. package/dist/schema/schema.js.map +1 -0
  91. package/dist/task/Command.d.ts +287 -0
  92. package/dist/task/Command.js +404 -0
  93. package/dist/task/Command.js.map +1 -0
  94. package/dist/task/Group.d.ts +15 -0
  95. package/dist/task/Group.js +29 -0
  96. package/dist/task/Group.js.map +1 -0
  97. package/dist/task/OutputPolicy.d.ts +262 -0
  98. package/dist/task/OutputPolicy.js +364 -0
  99. package/dist/task/OutputPolicy.js.map +1 -0
  100. package/dist/task/Task.d.ts +210 -0
  101. package/dist/task/Task.js +312 -0
  102. package/dist/task/Task.js.map +1 -0
  103. package/package.json +16 -14
  104. package/.gitignore +0 -7
  105. package/build/cli/DepFLowCLI.d.ts +0 -15
  106. package/build/cli/DepFLowCLI.js +0 -223
  107. package/build/cli/DepFLowCLI.js.map +0 -1
  108. package/build/cli/bin.js +0 -41
  109. package/build/cli/bin.js.map +0 -1
  110. package/build/config/Config.d.ts +0 -28
  111. package/build/config/Config.js +0 -46
  112. package/build/config/Config.js.map +0 -1
  113. package/build/config/ImportMap.d.ts +0 -37
  114. package/build/config/ImportMap.js +0 -82
  115. package/build/config/ImportMap.js.map +0 -1
  116. package/build/config/Tsconfig.d.ts +0 -57
  117. package/build/config/Tsconfig.js +0 -100
  118. package/build/config/Tsconfig.js.map +0 -1
  119. package/build/config/schemas.d.ts +0 -1194
  120. package/build/config/schemas.js +0 -66
  121. package/build/config/schemas.js.map +0 -1
  122. package/build/support/Async.d.ts +0 -22
  123. package/build/support/Async.js +0 -62
  124. package/build/support/Async.js.map +0 -1
  125. package/build/support/Builder/Builder.d.ts +0 -36
  126. package/build/support/Builder/Builder.js +0 -89
  127. package/build/support/Builder/Builder.js.map +0 -1
  128. package/build/support/Dependency/Dependency.d.ts +0 -38
  129. package/build/support/Dependency/Dependency.js +0 -14
  130. package/build/support/Dependency/Dependency.js.map +0 -1
  131. package/build/support/Dependency/GitDependency.d.ts +0 -20
  132. package/build/support/Dependency/GitDependency.js +0 -67
  133. package/build/support/Dependency/GitDependency.js.map +0 -1
  134. package/build/support/Dependency/NpmDependency.d.ts +0 -18
  135. package/build/support/Dependency/NpmDependency.js +0 -65
  136. package/build/support/Dependency/NpmDependency.js.map +0 -1
  137. package/build/support/Dependency/Resolver.d.ts +0 -7
  138. package/build/support/Dependency/Resolver.js +0 -4
  139. package/build/support/Dependency/Resolver.js.map +0 -1
  140. package/build/support/Git.d.ts +0 -53
  141. package/build/support/Git.js +0 -86
  142. package/build/support/Git.js.map +0 -1
  143. package/build/support/PathResolver/AliasCompiler.d.ts +0 -25
  144. package/build/support/PathResolver/AliasCompiler.js +0 -39
  145. package/build/support/PathResolver/AliasCompiler.js.map +0 -1
  146. package/build/support/PathResolver/PathResolver.js +0 -104
  147. package/build/support/PathResolver/PathResolver.js.map +0 -1
  148. package/build/support/PathResolver/PathRewriter.d.ts +0 -18
  149. package/build/support/PathResolver/PathRewriter.js.map +0 -1
  150. package/build/support/PathResolver/Utils.d.ts +0 -36
  151. package/build/support/PathResolver/Utils.js +0 -45
  152. package/build/support/PathResolver/Utils.js.map +0 -1
  153. package/build/support/Task/Command.d.ts +0 -49
  154. package/build/support/Task/Command.js +0 -100
  155. package/build/support/Task/Command.js.map +0 -1
  156. package/build/support/Task/Task.d.ts +0 -84
  157. package/build/support/Task/Task.js +0 -145
  158. package/build/support/Task/Task.js.map +0 -1
  159. package/build/support/Utils.d.ts +0 -40
  160. package/build/support/Utils.js +0 -138
  161. package/build/support/Utils.js.map +0 -1
  162. package/build/support/Validator.d.ts +0 -22
  163. package/build/support/Validator.js +0 -28
  164. package/build/support/Validator.js.map +0 -1
  165. /package/{build → dist}/cli/bin.d.ts +0 -0
@@ -1,86 +0,0 @@
1
- import Task from "./Task/Task.js";
2
- import Async from "./Async.js";
3
- export class Git {
4
- path;
5
- repo;
6
- logger;
7
- cwd;
8
- constructor(path, repo, options) {
9
- this.path = path;
10
- this.repo = repo;
11
- const { logger, cwd } = options;
12
- this.logger = logger || null;
13
- this.cwd = cwd || process.cwd();
14
- }
15
- /**
16
- * Clones a Git repository from the specified URL to the target path, optionally checking out a specific tag after cloning.
17
- * The method constructs the necessary commands to perform the clone operation and optionally check out a specified tag, then initiates a Task to execute these commands sequentially.
18
- * It listens for 'line' events to log standard output and 'error' events to log any errors that occur during command execution, including the step at which the error occurred.
19
- * Once all commands have been executed,
20
- * it listens for the 'finish' event to determine the overall success of the operation, logging a summary of the results and resolving or rejecting the promise accordingly based on whether any steps failed.
21
- * @param repo The URL of the Git repository to clone.
22
- * @param path The file system path where the repository should be cloned to.
23
- * @param options An object containing optional parameters for the clone operation, including:
24
- * - tag: An optional Git tag to check out after cloning the repository.
25
- * - logger: An optional Logger instance for real-time logging of command output and errors.
26
- * - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
27
- */
28
- static async clone(repo, path, options) {
29
- const { tag, logger, cwd = process.cwd() } = options;
30
- const commands = [
31
- `git clone ${repo} ${path}`,
32
- `cd ${path}`,
33
- ];
34
- if (tag)
35
- commands.push(`git checkout ${tag}`);
36
- await this.runTask(commands, { cwd, logger });
37
- }
38
- /**
39
- * Performs a 'git pull' operation on the specified repository path, optionally checking out a specific tag after pulling the latest changes.
40
- * The method constructs the necessary commands to navigate to the repository path, execute the pull operation, and optionally check out a specified tag.
41
- * It then initiates a Task to execute these commands sequentially, providing real-time logging and error handling through the provided Logger instance.
42
- * The method listens for 'line' events to log standard output and 'error' events to log any errors that occur during command execution, including the step at which the error occurred.
43
- * Once all commands have been executed, it listens for the 'finish' event to determine the overall success of the operation, logging a summary of the results and resolving or rejecting the promise accordingly based on whether any steps failed.
44
- * @param path The file system path to the local Git repository where the pull operation should be performed.
45
- * @param options An object containing optional parameters for the pull operation, including:
46
- * - tag: An optional Git tag to check out after pulling the latest changes.
47
- * - logger: An optional Logger instance for real-time logging of command output and errors.
48
- * - cwd: An optional current working directory to execute the commands from, defaulting to the process's current working directory if not provided.
49
- */
50
- static async pull(path, options) {
51
- const { tag, logger, cwd = process.cwd() } = options;
52
- const commands = [
53
- `cd ${path}`,
54
- `git pull`
55
- ];
56
- if (tag)
57
- commands.push(`git checkout ${tag}`);
58
- await this.runTask(commands, { cwd, logger });
59
- }
60
- /**
61
- * Executes a series of Git commands as a Task, providing real-time logging and error handling through the provided Logger instance.
62
- * The method constructs the necessary commands based on the provided repository URL, target path, and optional tag, then initiates a Task to execute these commands sequentially.
63
- * It listens for 'line' events to log standard output and 'error' events to log any errors that occur during command execution, including the step at which the error occurred.
64
- * Once all commands have been executed, it listens for the 'finish' event to determine the overall success of the operation, logging a summary of the results and resolving or rejecting the promise accordingly based on whether any steps failed.
65
- */
66
- static async runTask(commands, options) {
67
- const { cwd = process.cwd(), logger } = options;
68
- return Async.awaitEvent((done, fail) => {
69
- const task = new Task(cwd, commands);
70
- if (logger) {
71
- task.on('line', logger.info.bind(logger));
72
- task.on('error', (msg, step) => { logger.error(`&C6[Step ${step}]&C7: &C1${msg}`); });
73
- }
74
- task.once('finish', (summary) => {
75
- if (summary.fails === 0)
76
- done(summary);
77
- else
78
- fail(new Error(`Git clone failed with ${summary.fails} failed steps.\nErrors:\n${summary.errors.join('\n')}`));
79
- });
80
- task.start().catch(fail);
81
- return () => { task.stop(); };
82
- });
83
- }
84
- }
85
- export default Git;
86
- //# sourceMappingURL=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K,CAAC,IAAI,CAAC,CAAC;YACzB,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAUD,eAAe,GAAG,CAAC"}
@@ -1,25 +0,0 @@
1
- import Schemas from '../../config/schemas.js';
2
- export declare class AliasCompiler {
3
- private projectRoot;
4
- constructor(projectRoot: string);
5
- /**
6
- * Compiles alias configurations from the provided config object into a structured format for path resolution.
7
- * It processes both regular and wildcard aliases, resolving local paths to absolute paths based on the project root.
8
- * The resulting compiled aliases include information about the alias name, whether it's a wildcard, and its target paths for local and CDN usage.
9
- * @param config The configuration object containing dependencies with resolver entries to compile into aliases.
10
- * @returns An array of compiled alias objects ready for use in path resolution.
11
- */
12
- compile(config: Schemas.Config['infer']): AliasCompiler.CompiledAlias[];
13
- }
14
- export declare namespace AliasCompiler {
15
- interface Target {
16
- local: string;
17
- cdn?: string;
18
- }
19
- interface CompiledAlias {
20
- alias: string;
21
- targets: Target;
22
- isWildcard: boolean;
23
- }
24
- }
25
- export default AliasCompiler;
@@ -1,39 +0,0 @@
1
- import path from 'node:path';
2
- import Utils from './Utils.js';
3
- export class AliasCompiler {
4
- projectRoot;
5
- constructor(projectRoot) {
6
- this.projectRoot = projectRoot;
7
- }
8
- /**
9
- * Compiles alias configurations from the provided config object into a structured format for path resolution.
10
- * It processes both regular and wildcard aliases, resolving local paths to absolute paths based on the project root.
11
- * The resulting compiled aliases include information about the alias name, whether it's a wildcard, and its target paths for local and CDN usage.
12
- * @param config The configuration object containing dependencies with resolver entries to compile into aliases.
13
- * @returns An array of compiled alias objects ready for use in path resolution.
14
- */
15
- compile(config) {
16
- const result = [];
17
- const allDeps = [...(config.dependencies || []), ...(config.npmDependencies || [])];
18
- for (const dep of allDeps) {
19
- if (typeof dep !== 'object' || !dep.resolver)
20
- continue;
21
- for (const entry of dep.resolver) {
22
- const isWildcard = Utils.isWildcard(entry.alias);
23
- const alias = Utils.removeWildcardSuffix(entry.alias);
24
- const rawLocal = typeof entry.target === 'string' ? entry.target : entry.target.local;
25
- const localTarget = path.isAbsolute(rawLocal)
26
- ? Utils.removeWildcardSuffix(rawLocal)
27
- : path.resolve(this.projectRoot, Utils.removeWildcardSuffix(rawLocal));
28
- let cdnTarget;
29
- if (typeof entry.target === 'object' && entry.target.cdn) {
30
- cdnTarget = Utils.removeWildcardSuffix(entry.target.cdn);
31
- }
32
- result.push({ alias, isWildcard, targets: { local: localTarget, cdn: cdnTarget } });
33
- }
34
- }
35
- return result;
36
- }
37
- }
38
- export default AliasCompiler;
39
- //# sourceMappingURL=AliasCompiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AliasCompiler.js","sourceRoot":"","sources":["../../../src/support/PathResolver/AliasCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,OAAO,aAAa;IACF;IAApB,YAAoB,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;IAAG,CAAC;IAC3C;;;;;;OAMG;IACI,OAAO,CAAC,MAA+B;QAC1C,MAAM,MAAM,GAAkC,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC;QAEpF,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ;gBAAE,SAAS;YAEvD,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;gBAC/B,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACjD,MAAM,KAAK,GAAG,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAEtD,MAAM,QAAQ,GAAG,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;gBACtF,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;oBACzC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAC;oBACtC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAE3E,IAAI,SAA6B,CAAC;gBAClC,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;oBACvD,SAAS,GAAG,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC7D,CAAC;gBAED,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;YACxF,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAYD,eAAe,aAAa,CAAC"}
@@ -1,104 +0,0 @@
1
- /**
2
- * @author NetFeez <netfeez.dev@gmail.com>
3
- * @description Utility for path resolution with Local/CDN support and dual path fixing.
4
- * @license Apache-2.0
5
- */
6
- import PATH from "node:path";
7
- import FS, { promises as FSP } from 'node:fs';
8
- import { File } from '@netfeez/common-node';
9
- import { Logger } from "@netfeez/vterm";
10
- import Utils from '../Utils.js';
11
- import PathRewriter from './PathRewriter.js';
12
- import AliasCompiler from './AliasCompiler.js';
13
- export class PathResolver {
14
- config;
15
- options;
16
- static PROJECT_ROOT = process.cwd();
17
- static EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
18
- logger;
19
- rewriter;
20
- absoluteOutDir;
21
- aliases;
22
- constructor(config, options = {}) {
23
- this.config = config;
24
- this.options = options;
25
- this.logger = options.logger || new Logger({ name: 'PATH-RW' });
26
- const outDir = config.outDir || '.';
27
- this.absoluteOutDir = !PATH.isAbsolute(outDir)
28
- ? PATH.resolve(PathResolver.PROJECT_ROOT, outDir)
29
- : outDir;
30
- this.aliases = new AliasCompiler(PathResolver.PROJECT_ROOT).compile(config);
31
- this.rewriter = new PathRewriter(this.aliases, PathResolver.PROJECT_ROOT);
32
- }
33
- /**
34
- * Resolves and rewrites paths in built files based on the provided mode (local or CDN).
35
- * It processes all files in the output directory, rewriting import paths according to the configured aliases.
36
- * @param mode The resolution mode ('local' or 'cdn') to determine which target paths to use.
37
- */
38
- async rewritePaths(mode) {
39
- this.logger.log(`&C2Starting path resolver in &C3${mode} &C2mode...`);
40
- if (!await File.exists(this.absoluteOutDir))
41
- return void this.logger.warn(`Directory &C4${this.absoluteOutDir}&R not found.`);
42
- // const files = await File.getAllFiles(this.absoluteOutDir, PathResolver.EXTENSIONS);
43
- const files = [];
44
- files.push(...await File.find('**/*.js'));
45
- files.push(...await File.find('**/*.ts'));
46
- files.push(...await File.find('**/*.jsx'));
47
- files.push(...await File.find('**/*.tsx'));
48
- let rewrittenCount = 0;
49
- for (const file of files) {
50
- if (await this.processFile(file, mode))
51
- rewrittenCount++;
52
- }
53
- this.logger.log(`&C2Path aliases resolved in &C3${rewrittenCount} &C2files.`);
54
- }
55
- /**
56
- * Processes a single file, rewriting import paths based on the configured aliases and the specified mode (local or CDN).
57
- * It reads the file content, applies the path rewriting logic, and writes the updated content back to the file system if any changes were made.
58
- * @param file The path of the file to process.
59
- * @param mode The resolution mode ('local' or 'cdn') to determine which target paths to use for rewriting.
60
- * @returns A boolean indicating whether the file was modified (true if rewritten, false if no changes were made).
61
- */
62
- async processFile(file, mode) {
63
- try {
64
- const content = await FSP.readFile(file, 'utf8');
65
- const newContent = this.rewriter.rewrite(content, file, mode);
66
- if (content === newContent)
67
- return false;
68
- await FSP.writeFile(file, newContent, 'utf8');
69
- return true;
70
- }
71
- catch (error) {
72
- this.logger.error(`Failed to process file &C4${file}:`, error.message);
73
- return false;
74
- }
75
- }
76
- /**
77
- * Watches the output directory for changes and automatically rewrites paths in modified files based on the configured aliases and specified mode (local or CDN).
78
- * It sets up a file system watcher that listens for changes in the output directory, and when a relevant file is modified, it triggers the path rewriting process for that file.
79
- * The method includes debouncing to prevent excessive processing during rapid file changes, ensuring efficient handling of updates while maintaining responsiveness.
80
- * @param mode The resolution mode ('local' or 'cdn') to determine which target paths to use for rewriting when changes are detected.
81
- * @returns A promise that resolves when the watcher is set up and running, allowing the application to continue monitoring for changes indefinitely until manually stopped.
82
- * @throws Will throw an error if there is an issue setting up the file system watcher or processing files, which can be caught by the caller to handle it appropriately.
83
- */
84
- async watch(mode) {
85
- await this.rewritePaths(mode);
86
- this.logger.log(`&C2Watching for changes in &C4${this.absoluteOutDir}...`);
87
- const debouncedProcessor = Utils.debounce(async (fullPath, filename) => {
88
- if (await this.processFile(fullPath, mode)) {
89
- this.logger.log(`&C2File &C4${filename}&C2 updated.`);
90
- }
91
- }, 300);
92
- FS.watch(this.absoluteOutDir, { recursive: true }, (eventType, filename) => {
93
- if (!filename)
94
- return;
95
- const isTargetExtension = PathResolver.EXTENSIONS.some(ext => filename.endsWith(ext));
96
- if (!isTargetExtension)
97
- return;
98
- const fullPath = PATH.join(this.absoluteOutDir, filename);
99
- debouncedProcessor(fullPath, filename);
100
- });
101
- }
102
- }
103
- export default PathResolver;
104
- //# sourceMappingURL=PathResolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PathResolver.js","sourceRoot":"","sources":["../../../src/support/PathResolver/PathResolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,EAAE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,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;YAC1D,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC;;AAQL,eAAe,YAAY,CAAC"}
@@ -1,18 +0,0 @@
1
- import AliasCompiler from "./AliasCompiler.js";
2
- export declare class PathRewriter {
3
- private readonly aliases;
4
- private readonly projectRoot;
5
- static readonly IMPORT_REGEX: RegExp;
6
- constructor(aliases: AliasCompiler.CompiledAlias[], projectRoot: string);
7
- /**
8
- * Rewrites import paths in the given content based on the configured aliases.
9
- * It detects import statements and replaces alias paths with their resolved targets.
10
- * @param content The file content to rewrite.
11
- * @param filePath The path of the file being processed (used for relative path calculations).
12
- * @param mode The resolution mode ('local' or 'cdn') to determine which target to use.
13
- * @returns The rewritten content with resolved import paths.
14
- */
15
- rewrite(content: string, filePath: string, mode: 'local' | 'cdn'): string;
16
- }
17
- export declare namespace PathRewriter { }
18
- export default PathRewriter;
@@ -1 +0,0 @@
1
- {"version":3,"file":"PathRewriter.js","sourceRoot":"","sources":["../../../src/support/PathResolver/PathRewriter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAI5C,MAAM,OAAO,YAAY;IAGA;IACA;IAHd,MAAM,CAAU,YAAY,GAAG,8BAA8B,CAAC;IACrE,YACqB,OAAsC,EACtC,WAAmB;QADnB,YAAO,GAAP,OAAO,CAA+B;QACtC,gBAAW,GAAX,WAAW,CAAQ;IACrC,CAAC;IACJ;;;;;;;OAOG;IACI,OAAO,CAAC,OAAe,EAAE,QAAgB,EAAE,IAAqB;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;YACpF,MAAM,QAAQ,GA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AK,cAAc,EAAE,CAAC;YAE5E,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,MAAM,EAAE,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC;;AAGL,eAAe,YAAY,CAAC"}
@@ -1,36 +0,0 @@
1
- export declare class Utils {
2
- static readonly WILDCARD_SUFFIX_REGEX: RegExp;
3
- /**
4
- * Checks if a given alias string ends with a wildcard suffix (either "/*" or "/"), indicating that it is a wildcard alias.
5
- * This method is used to determine whether an alias should be treated as a wildcard mapping, which allows for matching multiple paths under the same base alias.
6
- * @param alias The alias string to check (e.g., "components/*" or "utils/").
7
- * @returns True if the alias ends with a wildcard suffix, false otherwise.
8
- */
9
- static isWildcard(alias: string): boolean;
10
- /**
11
- * Removes the wildcard suffix (either "/*" or "/") from a given alias string, returning the base alias without the wildcard.
12
- * This is useful for normalizing aliases when processing them, allowing the resolver to work with a consistent format regardless of whether the original alias was defined as a wildcard or not.
13
- * @param pathStr The alias string from which to remove the wildcard suffix (e.g., "components/*" or "utils/").
14
- * @returns The alias string with the wildcard suffix removed (e.g., "components" or "utils").
15
- */
16
- static removeWildcardSuffix(pathStr: string): string;
17
- /**
18
- * Ensures that a given alias string has a wildcard suffix (i.e., ends with "/*"). If the input string already ends with "/*" or "/", it will be normalized to end with "/*".
19
- * If it does not end with either, "/*" will be appended to the end of the string.
20
- * This method is useful for standardizing alias definitions when they are intended to be wildcard mappings.
21
- * @param pathStr The alias string to ensure has a wildcard suffix (e.g., "components", "utils/", or "services/*").
22
- * @returns The alias string guaranteed to end with "/*" (e.g., "components/*", "utils/*", or "services/*").
23
- */
24
- static ensureTsWildcard(pathStr: string): string;
25
- /**
26
- * Ensures that a given alias string has a trailing slash (i.e., ends with "/"). If the input string already ends with "/*" or "/", it will be normalized to end with "/".
27
- * If it does not end with either, "/" will be appended to the end of the string.
28
- * This method is useful for standardizing alias definitions when they are intended to be directory mappings without the wildcard.
29
- * @param pathStr The alias string to ensure has a trailing slash (e.g., "components", "utils/", or "services/*").
30
- * @returns The alias string guaranteed to end with "/" (e.g., "components/", "utils/", or "services/").
31
- */
32
- static ensureTrailingSlash(pathStr: string): string;
33
- }
34
- export declare namespace Utils {
35
- }
36
- export default Utils;
@@ -1,45 +0,0 @@
1
- export class Utils {
2
- static WILDCARD_SUFFIX_REGEX = /\/\*?$/;
3
- /**
4
- * Checks if a given alias string ends with a wildcard suffix (either "/*" or "/"), indicating that it is a wildcard alias.
5
- * This method is used to determine whether an alias should be treated as a wildcard mapping, which allows for matching multiple paths under the same base alias.
6
- * @param alias The alias string to check (e.g., "components/*" or "utils/").
7
- * @returns True if the alias ends with a wildcard suffix, false otherwise.
8
- */
9
- static isWildcard(alias) {
10
- return this.WILDCARD_SUFFIX_REGEX.test(alias);
11
- }
12
- /**
13
- * Removes the wildcard suffix (either "/*" or "/") from a given alias string, returning the base alias without the wildcard.
14
- * This is useful for normalizing aliases when processing them, allowing the resolver to work with a consistent format regardless of whether the original alias was defined as a wildcard or not.
15
- * @param pathStr The alias string from which to remove the wildcard suffix (e.g., "components/*" or "utils/").
16
- * @returns The alias string with the wildcard suffix removed (e.g., "components" or "utils").
17
- */
18
- static removeWildcardSuffix(pathStr) {
19
- return pathStr.replace(this.WILDCARD_SUFFIX_REGEX, '');
20
- }
21
- /**
22
- * Ensures that a given alias string has a wildcard suffix (i.e., ends with "/*"). If the input string already ends with "/*" or "/", it will be normalized to end with "/*".
23
- * If it does not end with either, "/*" will be appended to the end of the string.
24
- * This method is useful for standardizing alias definitions when they are intended to be wildcard mappings.
25
- * @param pathStr The alias string to ensure has a wildcard suffix (e.g., "components", "utils/", or "services/*").
26
- * @returns The alias string guaranteed to end with "/*" (e.g., "components/*", "utils/*", or "services/*").
27
- */
28
- static ensureTsWildcard(pathStr) {
29
- const clean = this.removeWildcardSuffix(pathStr);
30
- return `${clean}/*`;
31
- }
32
- /**
33
- * Ensures that a given alias string has a trailing slash (i.e., ends with "/"). If the input string already ends with "/*" or "/", it will be normalized to end with "/".
34
- * If it does not end with either, "/" will be appended to the end of the string.
35
- * This method is useful for standardizing alias definitions when they are intended to be directory mappings without the wildcard.
36
- * @param pathStr The alias string to ensure has a trailing slash (e.g., "components", "utils/", or "services/*").
37
- * @returns The alias string guaranteed to end with "/" (e.g., "components/", "utils/", or "services/").
38
- */
39
- static ensureTrailingSlash(pathStr) {
40
- const clean = this.removeWildcardSuffix(pathStr);
41
- return `${clean}/`;
42
- }
43
- }
44
- export default Utils;
45
- //# sourceMappingURL=Utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/support/PathResolver/Utils.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IACP,MAAM,CAAU,qBAAqB,GAAG,QAAQ,CAAC;IACxD;;;;;OAKG;IACI,MAAM,CAAC,UAAU,CAAC,KAAa;QAClC,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,oBAAoB,CAAC,OAAe;QAC9C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,gBAAgB,CAAC,OAAe;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,GAAG,KAAK,IAAI,CAAC;IACxB,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,mBAAmB,CAAC,OAAe;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,GAAG,KAAK,GAAG,CAAC;IACvB,CAAC;;AAKL,eAAe,KAAK,CAAC"}
@@ -1,49 +0,0 @@
1
- import { ChildProcessWithoutNullStreams } from "node:child_process";
2
- import { Events } from "@netfeez/common";
3
- export declare class Command extends Events<Command.EventMap> {
4
- protected shell: ChildProcessWithoutNullStreams;
5
- protected command: string;
6
- protected activeListeners: {
7
- stdout: Command.StdOut;
8
- stderr: Command.StdErr;
9
- } | null;
10
- constructor(shell: ChildProcessWithoutNullStreams, command: string);
11
- /**
12
- * Executes a command using the provided shell instance, returning a promise that resolves with the command's output, execution time, and success status.
13
- * This method sets up listeners for the shell's stdout and stderr streams to capture the command's output and errors in real-time.
14
- * It also handles the command's completion by listening for a specific marker in the output, allowing it to determine when the command has finished executing and to capture its exit status.
15
- * The method ensures that all listeners are properly cleaned up after execution to prevent memory leaks and unintended side effects on subsequent commands executed with the same shell instance.
16
- */
17
- exec(): void;
18
- /**
19
- * Cleans up the listeners attached to the shell's stdout and stderr streams after command execution, ensuring that no residual listeners remain that could interfere with subsequent commands or cause memory leaks.
20
- * This method is called after a command finishes executing, regardless of whether it succeeded or failed, to ensure that the TaskManager can safely execute new commands without unintended side effects from previous listeners.
21
- * It checks if there are active listeners and, if so, removes them from the shell's stdout and stderr streams before resetting the activeListeners reference to null.
22
- * By centralizing the cleanup logic in this method, it promotes better resource management and helps maintain the stability and reliability of the command execution process within the TaskManager.
23
- */
24
- protected cleanup(): void;
25
- /**
26
- * Creates a new shell instance using the appropriate shell executable based on the operating system, returning a promise that resolves with the created shell process.
27
- * This method abstracts the logic for determining which shell to use (e.g., cmd.exe for Windows and bash for Unix-like systems) and handles the creation of the shell process with the necessary stdio configuration.
28
- * By returning a promise, it allows callers to easily integrate shell creation into asynchronous workflows, ensuring that they can await the availability of the shell before attempting to execute commands.
29
- * If the shell process fails to start, the promise will be rejected with an appropriate error message, allowing callers to handle such scenarios gracefully.
30
- */
31
- static createShell(): Promise<Command.ShellComponents>;
32
- }
33
- export declare namespace Command {
34
- type Emitter = Events.Emitter<EventMap>;
35
- type StdOut = (output: Buffer) => void;
36
- type StdErr = (error: Buffer) => void;
37
- type Abort = (reason?: any) => void;
38
- type Shell = ChildProcessWithoutNullStreams;
39
- type EventMap = {
40
- log: [message: string];
41
- err: [message: string];
42
- end: [code: number, message: string];
43
- };
44
- interface ShellComponents {
45
- shell: Shell;
46
- abort: Abort;
47
- }
48
- }
49
- export default Command;
@@ -1,100 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { Events } from "@netfeez/common";
3
- export class Command extends Events {
4
- shell;
5
- command;
6
- activeListeners = null;
7
- constructor(shell, command) {
8
- super();
9
- this.shell = shell;
10
- this.command = command;
11
- }
12
- /**
13
- * Executes a command using the provided shell instance, returning a promise that resolves with the command's output, execution time, and success status.
14
- * This method sets up listeners for the shell's stdout and stderr streams to capture the command's output and errors in real-time.
15
- * It also handles the command's completion by listening for a specific marker in the output, allowing it to determine when the command has finished executing and to capture its exit status.
16
- * The method ensures that all listeners are properly cleaned up after execution to prevent memory leaks and unintended side effects on subsequent commands executed with the same shell instance.
17
- */
18
- exec() {
19
- const marker = `__DEF_FLOW_END_${Date.now()}__`;
20
- const statusKey = `__EXIT_STATUS_${Date.now()}__`;
21
- let accumulator = '';
22
- const isWin = process.platform === 'win32';
23
- const getStatusCmd = isWin
24
- ? `echo ${statusKey}=%errorlevel%`
25
- : `echo ${statusKey}=$?`;
26
- const stdoutListener = (data) => {
27
- const chunk = data.toString();
28
- accumulator += chunk;
29
- if (!chunk.includes(marker) && !chunk.includes(statusKey)) {
30
- this.emit('log', chunk.trim());
31
- }
32
- if (accumulator.includes(marker)) {
33
- const statusMatch = accumulator.match(new RegExp(`${statusKey}=(\\d+)`));
34
- const statusCode = statusMatch ? parseInt(statusMatch[1]) : 0;
35
- this.cleanup();
36
- const msg = accumulator.replace(getStatusCmd, '').replace(marker, '').trim();
37
- this.emit('end', statusCode, msg);
38
- }
39
- };
40
- const stderrListener = (data) => {
41
- const msg = data.toString().trim();
42
- if (msg)
43
- this.emit('err', msg);
44
- };
45
- this.activeListeners = { stdout: stdoutListener, stderr: stderrListener };
46
- this.shell.stdout.on('data', stdoutListener);
47
- this.shell.stderr.on('data', stderrListener);
48
- this.shell.once('error', (error) => {
49
- this.cleanup();
50
- const errorMsg = error instanceof Error ? error.message : String(error);
51
- this.emit('err', `Fatal Shell Error: ${errorMsg}`);
52
- this.emit('end', -1, errorMsg);
53
- });
54
- this.shell.stdin.write(`${this.command}\n`);
55
- this.shell.stdin.write(`${getStatusCmd}\n`);
56
- this.shell.stdin.write(`echo ${marker}\n`);
57
- }
58
- /**
59
- * Cleans up the listeners attached to the shell's stdout and stderr streams after command execution, ensuring that no residual listeners remain that could interfere with subsequent commands or cause memory leaks.
60
- * This method is called after a command finishes executing, regardless of whether it succeeded or failed, to ensure that the TaskManager can safely execute new commands without unintended side effects from previous listeners.
61
- * It checks if there are active listeners and, if so, removes them from the shell's stdout and stderr streams before resetting the activeListeners reference to null.
62
- * By centralizing the cleanup logic in this method, it promotes better resource management and helps maintain the stability and reliability of the command execution process within the TaskManager.
63
- */
64
- cleanup() {
65
- if (!this.activeListeners)
66
- return;
67
- this.shell.stdout.off('data', this.activeListeners.stdout);
68
- this.shell.stderr.off('data', this.activeListeners.stderr);
69
- this.activeListeners = null;
70
- }
71
- /**
72
- * Creates a new shell instance using the appropriate shell executable based on the operating system, returning a promise that resolves with the created shell process.
73
- * This method abstracts the logic for determining which shell to use (e.g., cmd.exe for Windows and bash for Unix-like systems) and handles the creation of the shell process with the necessary stdio configuration.
74
- * By returning a promise, it allows callers to easily integrate shell creation into asynchronous workflows, ensuring that they can await the availability of the shell before attempting to execute commands.
75
- * If the shell process fails to start, the promise will be rejected with an appropriate error message, allowing callers to handle such scenarios gracefully.
76
- */
77
- static async createShell() {
78
- const ac = new AbortController();
79
- const shellExecutable = process.platform === 'win32' ? 'cmd.exe' : 'bash';
80
- const shell = spawn(shellExecutable, { shell: false, detached: true, stdio: ['pipe', 'pipe', 'pipe'], signal: ac.signal });
81
- shell.unref();
82
- ac.signal.addEventListener('abort', () => {
83
- if (shell.stderr)
84
- shell.stderr.destroy();
85
- if (shell.stdout)
86
- shell.stdout.destroy();
87
- if (shell.stdin)
88
- shell.stdin.destroy();
89
- if (process.platform !== 'win32' && shell.pid) {
90
- try {
91
- process.kill(-shell.pid, 'SIGKILL');
92
- }
93
- catch (e) { }
94
- }
95
- });
96
- return { shell, abort: (reason) => ac.abort(reason) };
97
- }
98
- }
99
- export default Command;
100
- //# sourceMappingURL=Command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/support/Task/Command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,OAAO,OAAQ,SAAQ,MAAwB;IACvC,KAAK,CAAiC;IACtC,OAAO,CAAS;IAChB,eAAe,GAA8D,IAAI,CAAC;IAE5F,YAAmB,KAAqC,EAAE,OAAe;QAAI,KAAK,EAAE,CAAC;QACjF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IACD;;;;;MAKE;IACK,IAAI;QACP,MAAM,MAAM,GAAG,kBAAkB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;QAChD,MAAM,SAAS,GAAG,iBAAiB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;QAClD,IAAI,WAAW,GAAG,EAAE,CAAC;QAErB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;QAC3C,MAAM,YAAY,GAAG,KAAK;YACtB,CAAC,CAAC,QAAQ,SAAS,eAAe;YAClC,CAAC,CAAC,QAAQ,SAAS,KAAK,CAAC;QAE7B,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;YACpC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9B,WAAW,IAAI,KAAK,CAAC;YAErB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAA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