depflow 2.0.0-dev.1 → 2.0.0-dev.3

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 (94) hide show
  1. package/build/{bin → cli}/DepFLowCLI.d.ts +4 -2
  2. package/build/{bin → cli}/DepFLowCLI.js +60 -36
  3. package/build/cli/DepFLowCLI.js.map +1 -0
  4. package/build/{bin → cli}/bin.js +15 -4
  5. package/build/cli/bin.js.map +1 -0
  6. package/build/config/Config.d.ts +28 -0
  7. package/build/config/Config.js +46 -0
  8. package/build/config/Config.js.map +1 -0
  9. package/build/config/ImportMap.d.ts +38 -0
  10. package/build/config/ImportMap.js +83 -0
  11. package/build/config/ImportMap.js.map +1 -0
  12. package/build/config/Tsconfig.d.ts +57 -0
  13. package/build/config/Tsconfig.js +99 -0
  14. package/build/config/Tsconfig.js.map +1 -0
  15. package/build/config/schemas.d.ts +592 -0
  16. package/build/config/schemas.js +51 -0
  17. package/build/config/schemas.js.map +1 -0
  18. package/build/support/Dependency.d.ts +127 -0
  19. package/build/support/Dependency.js +307 -0
  20. package/build/support/Dependency.js.map +1 -0
  21. package/build/support/File.d.ts +80 -0
  22. package/build/support/File.js +123 -0
  23. package/build/support/File.js.map +1 -0
  24. package/build/support/Git.js.map +1 -0
  25. package/build/support/PathFixer.d.ts +36 -0
  26. package/build/support/PathFixer.js +161 -0
  27. package/build/support/PathFixer.js.map +1 -0
  28. package/build/support/PathResolver/AliasCompiler.d.ts +25 -0
  29. package/build/support/PathResolver/AliasCompiler.js +39 -0
  30. package/build/support/PathResolver/AliasCompiler.js.map +1 -0
  31. package/build/support/PathResolver/PathResolver.d.ts +45 -0
  32. package/build/support/PathResolver/PathResolver.js +99 -0
  33. package/build/support/PathResolver/PathResolver.js.map +1 -0
  34. package/build/support/PathResolver/PathRewriter.d.ts +18 -0
  35. package/build/support/PathResolver/PathRewriter.js +47 -0
  36. package/build/support/PathResolver/PathRewriter.js.map +1 -0
  37. package/build/support/PathResolver/Utils.d.ts +36 -0
  38. package/build/support/PathResolver/Utils.js +45 -0
  39. package/build/support/PathResolver/Utils.js.map +1 -0
  40. package/build/support/PathResolver.d.ts +100 -0
  41. package/build/support/PathResolver.js +280 -0
  42. package/build/support/PathResolver.js.map +1 -0
  43. package/build/support/Resolver/AliasCompiler.d.ts +18 -0
  44. package/build/support/Resolver/AliasCompiler.js +32 -0
  45. package/build/support/Resolver/AliasCompiler.js.map +1 -0
  46. package/build/support/Resolver/PathResolver.d.ts +25 -0
  47. package/build/support/Resolver/PathResolver.js +79 -0
  48. package/build/support/Resolver/PathResolver.js.map +1 -0
  49. package/build/support/Resolver/PathRewriter.d.ts +10 -0
  50. package/build/support/Resolver/PathRewriter.js +39 -0
  51. package/build/support/Resolver/PathRewriter.js.map +1 -0
  52. package/build/support/Resolver/Utils.d.ts +36 -0
  53. package/build/support/Resolver/Utils.js +45 -0
  54. package/build/support/Resolver/Utils.js.map +1 -0
  55. package/build/support/Utils.d.ts +30 -0
  56. package/build/support/Utils.js +95 -0
  57. package/build/support/Utils.js.map +1 -0
  58. package/build/support/Validator.d.ts +22 -0
  59. package/build/support/Validator.js +28 -0
  60. package/build/support/Validator.js.map +1 -0
  61. package/package.json +4 -3
  62. package/build/Config.d.ts +0 -15
  63. package/build/Config.js +0 -21
  64. package/build/Config.js.map +0 -1
  65. package/build/Dependency.d.ts +0 -86
  66. package/build/Dependency.js +0 -264
  67. package/build/Dependency.js.map +0 -1
  68. package/build/File.d.ts +0 -9
  69. package/build/File.js +0 -41
  70. package/build/File.js.map +0 -1
  71. package/build/Git.js.map +0 -1
  72. package/build/PathFixer.d.ts +0 -35
  73. package/build/PathFixer.js +0 -143
  74. package/build/PathFixer.js.map +0 -1
  75. package/build/Tsconfig.d.ts +0 -13
  76. package/build/Tsconfig.js +0 -16
  77. package/build/Tsconfig.js.map +0 -1
  78. package/build/Utils.d.ts +0 -16
  79. package/build/Utils.js +0 -40
  80. package/build/Utils.js.map +0 -1
  81. package/build/Validator.d.ts +0 -9
  82. package/build/Validator.js +0 -15
  83. package/build/Validator.js.map +0 -1
  84. package/build/bin/DepFLowCLI.js.map +0 -1
  85. package/build/bin/bin.d.ts +0 -2
  86. package/build/bin/bin.js.map +0 -1
  87. package/build/bin.js +0 -26
  88. package/build/bin.js.map +0 -1
  89. package/build/schemas.d.ts +0 -296
  90. package/build/schemas.js +0 -29
  91. package/build/schemas.js.map +0 -1
  92. /package/build/{bin.d.ts → cli/bin.d.ts} +0 -0
  93. /package/build/{Git.d.ts → support/Git.d.ts} +0 -0
  94. /package/build/{Git.js → support/Git.js} +0 -0
@@ -0,0 +1,36 @@
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;
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,100 @@
1
+ import { Logger } from 'vortez';
2
+ import schemas from '../config/schemas.js';
3
+ export declare class PathResolver {
4
+ readonly config: schemas.config['infer'];
5
+ readonly options: PathResolver.Options;
6
+ readonly projectRoot: string;
7
+ static readonly WILDCARD_SUFFIX_REGEX: RegExp;
8
+ static readonly IMPORT_REGEX: RegExp;
9
+ static readonly PROJECT_ROOT: string;
10
+ static readonly EXTENSIONS: string[];
11
+ absoluteOutDir: string;
12
+ protected vCompiledAliases: PathResolver.ResolvedAlias[] | null;
13
+ protected logger: Logger;
14
+ constructor(config: schemas.config['infer'], options?: PathResolver.Options, projectRoot?: string);
15
+ /** compile the aliases from the config into a flat array for easy lookup during replacement. */
16
+ get aliases(): PathResolver.ResolvedAlias[];
17
+ /**
18
+ * Main method to run the path resolver. It scans all relevant files in the output directory,
19
+ * applies path replacements based on the configured aliases, and updates the files in place. It also logs the process and results.
20
+ * @param mode The mode of resolution, either 'local' or 'cdn', which determines whether to use the local or CDN target for the alias replacement.
21
+ */
22
+ rewritePaths(mode: PathResolver.Mode): Promise<void>;
23
+ /**
24
+ * Processes a single file, replacing import paths based on the configured aliases. It reads the file content, applies the replacements, and writes back if any changes were made.
25
+ * It returns a boolean indicating whether the file was modified.
26
+ * @param file The path to the file being processed.
27
+ * @param mode The mode of resolution, either 'local' or 'cdn', which determines whether to use the local or CDN target for the alias replacement.
28
+ */
29
+ protected processFile(file: string, mode: PathResolver.Mode): Promise<boolean>;
30
+ /**
31
+ * Core logic for replacing a matched import path. It checks if the modulePath matches any configured alias (considering wildcards), and if so, constructs the new path accordingly. For remote targets, it returns the full URL. For local targets, it calculates the relative path from the current file to the target and normalizes it.
32
+ * This method is designed to be called for each match found in the file content, allowing for multiple replacements per file if necessary.
33
+ * @param file The current file being processed, used to calculate relative paths for local targets.
34
+ * @param match The full matched string from the regex, used to reconstruct the import statement.
35
+ * @param prefix The part of the import statement before the module path (e.g., "from '").
36
+ * @param modulePath The actual module path that was matched and needs to be checked against aliases.
37
+ * @param suffix The part of the import statement after the module path (e.g., "'").
38
+ * @param mode The mode of resolution, either 'local' or 'cdn', which determines whether to use the local or CDN target for the alias replacement.
39
+ */
40
+ protected replaceLogic(file: string, match: string, prefix: string, modulePath: string, suffix: string, mode: 'local' | 'cdn'): string;
41
+ /**
42
+ * Synchronizes the configured path aliases with the tsconfig.json file.
43
+ * It reads the existing tsconfig, updates the compilerOptions.paths section based on the configured aliases, and writes back the changes.
44
+ * It handles both wildcard and exact aliases, ensuring that directory mappings are correctly represented with a trailing "/*". It also logs the process and any issues encountered, such as missing tsconfig or write errors.
45
+ * This method is intended to be called after the path resolver has processed the files, ensuring that the tsconfig paths are in sync with the actual file structure and alias configuration.
46
+ */
47
+ syncTsConfig(): Promise<void>;
48
+ /**
49
+ * Generates an import map file based on the configured path aliases. It constructs an import map object with an "imports" section, where each alias is mapped to its corresponding target path. For remote targets, it uses the full URL, while for local targets, it calculates the relative path from the project root and normalizes it.
50
+ * The generated import map is then written to the specified location in the project, and any necessary directories are created if they do not exist.
51
+ * It also logs the process and any issues encountered, such as missing import map configuration or write errors.
52
+ * This method is useful for projects that utilize import maps for module resolution, ensuring that the import map is always up to date with the configured aliases and can be used effectively during development and deployment.
53
+ */
54
+ syncImportMap(mode: PathResolver.Mode): Promise<void>;
55
+ /**
56
+ * Watches the output directory for changes to files with specified extensions and automatically re-runs the path resolver on those files when changes are detected.
57
+ * It uses fs.watch to monitor the directory recursively, and implements a debounce mechanism to prevent multiple rapid triggers for the same file.
58
+ * When a change is detected, it processes the affected file and logs the update.
59
+ * This method allows for real-time updates to the resolved paths during development, ensuring that any changes to the output files are immediately reflected in the path resolution without needing to manually re-run the resolver.
60
+ */
61
+ watch(mode: PathResolver.Mode): Promise<void>;
62
+ /**
63
+ * Recursively retrieves all files with specified extensions from a given directory.
64
+ * It uses fs.readdir with the "withFileTypes" option to efficiently determine if an entry is a file or a directory.
65
+ * For directories, it calls itself recursively to gather files from subdirectories. For files, it checks if their extensions match the provided list and includes them in the result.
66
+ * This method returns a flat array of file paths that can be processed by the path resolver.
67
+ * @param dir The directory to scan for files.
68
+ * @param extensions An array of file extensions to filter the results (e.g., ['.js', '.ts']).
69
+ * @returns A promise that resolves to an array of file paths matching the specified extensions.
70
+ */
71
+ static getAllFiles(dir: string, extensions: string[]): Promise<string[]>;
72
+ /**
73
+ * Determines if a given alias string is a wildcard alias by checking if it ends with "/*" or just "/". This is used to identify aliases that represent directory mappings, allowing for more flexible path resolution where any subpath under the alias can be matched and replaced accordingly.
74
+ * @param alias The alias string to check (e.g., "components/*" or "utils/").
75
+ * @returns A boolean indicating whether the alias is a wildcard alias.
76
+ */
77
+ static isWildcard(alias: string): boolean;
78
+ /**
79
+ * Removes the wildcard suffix (either "/*" or "/") from a given alias string, returning the base alias without the wildcard. 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.
80
+ * @param alias The alias string from which to remove the wildcard suffix (e.g., "components/*" or "utils/").
81
+ * @returns The alias string with the wildcard suffix removed (e.g., "components" or "utils").
82
+ */
83
+ static removeWildcardSuffix(alias: string): string;
84
+ }
85
+ export declare namespace PathResolver {
86
+ type Mode = 'local' | 'cdn';
87
+ interface Options {
88
+ logger?: Logger;
89
+ }
90
+ interface Target {
91
+ local: string;
92
+ cdn?: string;
93
+ }
94
+ interface ResolvedAlias {
95
+ alias: string;
96
+ targets: Target;
97
+ isWildcard: boolean;
98
+ }
99
+ }
100
+ export default PathResolver;
@@ -0,0 +1,280 @@
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 'path';
7
+ import syncFs, { promises as fs } from 'fs';
8
+ import { Logger, Utilities } from 'vortez';
9
+ import File from './File.js';
10
+ export class PathResolver {
11
+ config;
12
+ options;
13
+ projectRoot;
14
+ static WILDCARD_SUFFIX_REGEX = /\/\*?$/;
15
+ static IMPORT_REGEX = /(from\s+['"])([^'"]+)(['"])/g;
16
+ static PROJECT_ROOT = process.cwd();
17
+ static EXTENSIONS = ['.js', '.d.ts', '.mjs', '.cjs'];
18
+ absoluteOutDir;
19
+ vCompiledAliases = null;
20
+ logger;
21
+ constructor(config, options = {}, projectRoot = PathResolver.PROJECT_ROOT) {
22
+ this.config = config;
23
+ this.options = options;
24
+ this.projectRoot = projectRoot;
25
+ this.logger = options.logger || new Logger({ prefix: 'PathResolver' });
26
+ const outDir = config.outDir || '.';
27
+ const fullPath = path.isAbsolute(outDir) ? outDir : path.join(projectRoot, outDir);
28
+ this.absoluteOutDir = path.resolve(fullPath);
29
+ }
30
+ /** compile the aliases from the config into a flat array for easy lookup during replacement. */
31
+ get aliases() {
32
+ if (this.vCompiledAliases)
33
+ return this.vCompiledAliases;
34
+ const result = [];
35
+ const allDeps = [
36
+ ...(this.config.dependencies || []),
37
+ ...(this.config.npmDependencies || [])
38
+ ];
39
+ for (const dep of allDeps) {
40
+ if (typeof dep !== 'object' || !dep.resolver)
41
+ continue;
42
+ for (const entry of dep.resolver) {
43
+ const isWildcard = PathResolver.isWildcard(entry.alias);
44
+ const alias = PathResolver.removeWildcardSuffix(entry.alias);
45
+ const rawLocal = typeof entry.target !== 'string'
46
+ ? entry.target.local
47
+ : entry.target;
48
+ const cleanLocal = PathResolver.removeWildcardSuffix(rawLocal);
49
+ const localTarget = !path.isAbsolute(cleanLocal)
50
+ ? path.resolve(this.projectRoot, cleanLocal)
51
+ : cleanLocal;
52
+ let cdnTarget = typeof entry.target === 'object' && entry.target.cdn
53
+ ? PathResolver.removeWildcardSuffix(entry.target.cdn)
54
+ : undefined;
55
+ result.push({
56
+ alias,
57
+ isWildcard,
58
+ targets: { local: localTarget, cdn: cdnTarget }
59
+ });
60
+ }
61
+ }
62
+ this.vCompiledAliases = result;
63
+ return result;
64
+ }
65
+ /**
66
+ * Main method to run the path resolver. It scans all relevant files in the output directory,
67
+ * applies path replacements based on the configured aliases, and updates the files in place. It also logs the process and results.
68
+ * @param mode The mode of resolution, either 'local' or 'cdn', which determines whether to use the local or CDN target for the alias replacement.
69
+ */
70
+ async rewritePaths(mode) {
71
+ this.logger.log(`&C2Starting path resolver in &C3${mode} &C2mode...`);
72
+ if (!await File.exists(this.absoluteOutDir)) {
73
+ return void this.logger.warn(`The output directory &C4${this.absoluteOutDir}&R does not exist.`);
74
+ }
75
+ const files = await PathResolver.getAllFiles(this.absoluteOutDir, PathResolver.EXTENSIONS);
76
+ this.logger.log(`&C2Found &C3${files.length} &C2files in &C4${this.absoluteOutDir}.`);
77
+ let rewrittenCount = 0;
78
+ for (const file of files) {
79
+ const result = await this.processFile(file, mode);
80
+ if (result)
81
+ rewrittenCount++;
82
+ }
83
+ this.logger.log(`&C2Path aliases resolved in &C3${rewrittenCount} &C2files.`);
84
+ }
85
+ /**
86
+ * Processes a single file, replacing import paths based on the configured aliases. It reads the file content, applies the replacements, and writes back if any changes were made.
87
+ * It returns a boolean indicating whether the file was modified.
88
+ * @param file The path to the file being processed.
89
+ * @param mode The mode of resolution, either 'local' or 'cdn', which determines whether to use the local or CDN target for the alias replacement.
90
+ */
91
+ async processFile(file, mode) {
92
+ const content = await fs.readFile(file, 'utf8');
93
+ const newContent = content.replace(PathResolver.IMPORT_REGEX, (match, prefix, modulePath, suffix) => {
94
+ return this.replaceLogic(file, match, prefix, modulePath, suffix, mode);
95
+ });
96
+ if (content === newContent)
97
+ return false;
98
+ await fs.writeFile(file, newContent, 'utf8');
99
+ return true;
100
+ }
101
+ /**
102
+ * Core logic for replacing a matched import path. It checks if the modulePath matches any configured alias (considering wildcards), and if so, constructs the new path accordingly. For remote targets, it returns the full URL. For local targets, it calculates the relative path from the current file to the target and normalizes it.
103
+ * This method is designed to be called for each match found in the file content, allowing for multiple replacements per file if necessary.
104
+ * @param file The current file being processed, used to calculate relative paths for local targets.
105
+ * @param match The full matched string from the regex, used to reconstruct the import statement.
106
+ * @param prefix The part of the import statement before the module path (e.g., "from '").
107
+ * @param modulePath The actual module path that was matched and needs to be checked against aliases.
108
+ * @param suffix The part of the import statement after the module path (e.g., "'").
109
+ * @param mode The mode of resolution, either 'local' or 'cdn', which determines whether to use the local or CDN target for the alias replacement.
110
+ */
111
+ replaceLogic(file, match, prefix, modulePath, suffix, mode) {
112
+ const aliasCfg = this.aliases.find(c => c.isWildcard ? modulePath.startsWith(`${c.alias}/`) : modulePath === c.alias);
113
+ if (!aliasCfg)
114
+ return match;
115
+ const isCDN = mode === 'cdn' && aliasCfg.targets.cdn;
116
+ let baseTarget = isCDN ? aliasCfg.targets.cdn : aliasCfg.targets.local;
117
+ let resolvedPath;
118
+ if (aliasCfg.isWildcard) {
119
+ const subPath = modulePath.substring(aliasCfg.alias.length + 1);
120
+ if (isCDN) {
121
+ const cleanBase = baseTarget.endsWith('/') ? baseTarget.slice(0, -1) : baseTarget;
122
+ resolvedPath = `${cleanBase}/${subPath}`;
123
+ }
124
+ else {
125
+ resolvedPath = path.join(baseTarget, subPath);
126
+ }
127
+ }
128
+ else {
129
+ resolvedPath = baseTarget;
130
+ }
131
+ if (isCDN)
132
+ return `${prefix}${resolvedPath}${suffix}`;
133
+ const currentFileDir = path.dirname(file);
134
+ let relativeTarget = path.relative(currentFileDir, resolvedPath);
135
+ if (!relativeTarget.startsWith('.')) {
136
+ relativeTarget = `./${relativeTarget}`;
137
+ }
138
+ return `${prefix}${Utilities.Path.normalize(relativeTarget)}${suffix}`;
139
+ }
140
+ /**
141
+ * Synchronizes the configured path aliases with the tsconfig.json file.
142
+ * It reads the existing tsconfig, updates the compilerOptions.paths section based on the configured aliases, and writes back the changes.
143
+ * It handles both wildcard and exact aliases, ensuring that directory mappings are correctly represented with a trailing "/*". It also logs the process and any issues encountered, such as missing tsconfig or write errors.
144
+ * This method is intended to be called after the path resolver has processed the files, ensuring that the tsconfig paths are in sync with the actual file structure and alias configuration.
145
+ */
146
+ async syncTsConfig() {
147
+ if (!this.config.tsconfig)
148
+ return void this.logger.warn(`&C3Warning: No tsconfig specified in config.`);
149
+ const tsconfigName = this.config.tsconfig;
150
+ const tsconfigPath = path.resolve(this.projectRoot, tsconfigName);
151
+ if (!await File.exists(tsconfigPath))
152
+ return void this.logger.warn(`&C3Warning: ${tsconfigName} not found.`);
153
+ try {
154
+ const tsConfigContent = JSON.parse(await File.read(tsconfigPath));
155
+ if (!tsConfigContent.compilerOptions)
156
+ tsConfigContent.compilerOptions = {};
157
+ if (!tsConfigContent.compilerOptions.paths)
158
+ tsConfigContent.compilerOptions.paths = {};
159
+ for (const aliasObj of this.aliases) {
160
+ const key = aliasObj.isWildcard ? `${aliasObj.alias}/*` : aliasObj.alias;
161
+ let localTarget = path.relative(this.projectRoot, aliasObj.targets.local);
162
+ localTarget = Utilities.Path.normalize(localTarget);
163
+ console.log(aliasObj);
164
+ if (aliasObj.isWildcard) {
165
+ localTarget = `${localTarget.endsWith('/') ? localTarget : localTarget + '/'}*`;
166
+ }
167
+ tsConfigContent.compilerOptions.paths[key] = [localTarget];
168
+ }
169
+ const json = JSON.stringify(tsConfigContent, null, 4);
170
+ await File.write(tsconfigPath, json);
171
+ this.logger.log(`&C2Updated paths in &C4${tsconfigName}`);
172
+ }
173
+ catch (error) {
174
+ this.logger.error(`Failed to sync tsconfig:`, error.message);
175
+ }
176
+ }
177
+ /**
178
+ * Generates an import map file based on the configured path aliases. It constructs an import map object with an "imports" section, where each alias is mapped to its corresponding target path. For remote targets, it uses the full URL, while for local targets, it calculates the relative path from the project root and normalizes it.
179
+ * The generated import map is then written to the specified location in the project, and any necessary directories are created if they do not exist.
180
+ * It also logs the process and any issues encountered, such as missing import map configuration or write errors.
181
+ * This method is useful for projects that utilize import maps for module resolution, ensuring that the import map is always up to date with the configured aliases and can be used effectively during development and deployment.
182
+ */
183
+ async syncImportMap(mode) {
184
+ if (!this.config.importmap)
185
+ return void this.logger.warn(`&C3Warning: No importmap specified in config.`);
186
+ const importMapName = this.config.importmap;
187
+ const importMapPath = path.resolve(this.projectRoot, importMapName);
188
+ const importMap = { imports: {} };
189
+ for (const aliasObj of this.aliases) {
190
+ const isDirectory = aliasObj.isWildcard || aliasObj.alias.endsWith('/');
191
+ const key = isDirectory && !aliasObj.alias.endsWith('/')
192
+ ? `${aliasObj.alias}/`
193
+ : aliasObj.alias;
194
+ let val = (mode === 'cdn' && aliasObj.targets.cdn)
195
+ ? aliasObj.targets.cdn
196
+ : aliasObj.targets.local;
197
+ if (val === aliasObj.targets.local) {
198
+ val = path.relative(this.projectRoot, val);
199
+ if (!val.startsWith('.'))
200
+ val = `./${val}`;
201
+ val = Utilities.Path.normalize(val);
202
+ }
203
+ if (key.endsWith('/') && !val.endsWith('/')) {
204
+ val += '/';
205
+ }
206
+ importMap.imports[key] = val;
207
+ }
208
+ const folder = Utilities.Path.dirname(importMapPath);
209
+ if (!await File.exists(folder))
210
+ await File.mkdir(folder, { recursive: true });
211
+ await File.write(importMapPath, JSON.stringify(importMap, null, 4));
212
+ this.logger.log(`&C2Generated &C4${importMapName}`);
213
+ }
214
+ /**
215
+ * Watches the output directory for changes to files with specified extensions and automatically re-runs the path resolver on those files when changes are detected.
216
+ * It uses fs.watch to monitor the directory recursively, and implements a debounce mechanism to prevent multiple rapid triggers for the same file.
217
+ * When a change is detected, it processes the affected file and logs the update.
218
+ * This method allows for real-time updates to the resolved paths during development, ensuring that any changes to the output files are immediately reflected in the path resolution without needing to manually re-run the resolver.
219
+ */
220
+ async watch(mode) {
221
+ await this.rewritePaths(mode);
222
+ this.logger.log(`&C2Watching for changes in &C4${this.absoluteOutDir}...`);
223
+ const queue = new Map();
224
+ syncFs.watch(this.absoluteOutDir, { recursive: true }, (eventType, filename) => {
225
+ if (!filename || !PathResolver.EXTENSIONS.some(ext => filename.endsWith(ext)))
226
+ return;
227
+ const fullPath = path.join(this.absoluteOutDir, filename);
228
+ if (queue.has(fullPath))
229
+ clearTimeout(queue.get(fullPath));
230
+ queue.set(fullPath, setTimeout(async () => {
231
+ try {
232
+ const result = await this.processFile(fullPath, mode);
233
+ if (result)
234
+ this.logger.log(`&C2File &C4${filename}&C2 updated.`);
235
+ }
236
+ catch (e) { }
237
+ queue.delete(fullPath);
238
+ }, 300));
239
+ });
240
+ }
241
+ /**
242
+ * Recursively retrieves all files with specified extensions from a given directory.
243
+ * It uses fs.readdir with the "withFileTypes" option to efficiently determine if an entry is a file or a directory.
244
+ * For directories, it calls itself recursively to gather files from subdirectories. For files, it checks if their extensions match the provided list and includes them in the result.
245
+ * This method returns a flat array of file paths that can be processed by the path resolver.
246
+ * @param dir The directory to scan for files.
247
+ * @param extensions An array of file extensions to filter the results (e.g., ['.js', '.ts']).
248
+ * @returns A promise that resolves to an array of file paths matching the specified extensions.
249
+ */
250
+ static async getAllFiles(dir, extensions) {
251
+ const result = [];
252
+ const entries = await fs.readdir(dir, { withFileTypes: true });
253
+ for (const entry of entries) {
254
+ const fullPath = path.join(dir, entry.name);
255
+ if (entry.isDirectory())
256
+ result.push(...(await PathResolver.getAllFiles(fullPath, extensions)));
257
+ else if (extensions.some(ext => fullPath.endsWith(ext)))
258
+ result.push(fullPath);
259
+ }
260
+ return result;
261
+ }
262
+ /**
263
+ * Determines if a given alias string is a wildcard alias by checking if it ends with "/*" or just "/". This is used to identify aliases that represent directory mappings, allowing for more flexible path resolution where any subpath under the alias can be matched and replaced accordingly.
264
+ * @param alias The alias string to check (e.g., "components/*" or "utils/").
265
+ * @returns A boolean indicating whether the alias is a wildcard alias.
266
+ */
267
+ static isWildcard(alias) {
268
+ return PathResolver.WILDCARD_SUFFIX_REGEX.test(alias);
269
+ }
270
+ /**
271
+ * Removes the wildcard suffix (either "/*" or "/") from a given alias string, returning the base alias without the wildcard. 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.
272
+ * @param alias The alias string from which to remove the wildcard suffix (e.g., "components/*" or "utils/").
273
+ * @returns The alias string with the wildcard suffix removed (e.g., "components" or "utils").
274
+ */
275
+ static removeWildcardSuffix(alias) {
276
+ return alias.replace(PathResolver.WILDCARD_SUFFIX_REGEX, '');
277
+ }
278
+ }
279
+ export default PathResolver;
280
+ //# sourceMappingURL=PathResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathResolver.js","sourceRoot":"","sources":["../../src/support/PathResolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,EAAE,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,OAAO,YAAY;IAWD;IACA;IACA;IAZb,MAAM,CAAU,qBAAqB,GAAG,QAAQ,CAAC;IACjD,MAAM,CAAU,YAAY,GAAG,8BAA8B,CAAC;IAC9D,MAAM,CAAU,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC7C,MAAM,CAAU,UAAU,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAE9D,cAAc,CAAS;IACpB,gBAAgB,GAAwC,IAAI,CAAC;IAC7D,MAAM,CAAS;IAEzB,YACoB,MAA+B,EAC/B,UAAgC,EAAE,EAClC,cAAsB,YAAY,CAAC,YAAY;QAF/C,WAAM,GAAN,MAAM,CAAyB;QAC/B,YAAO,GAAP,OAAO,CAA2B;QAClC,gBAAW,GAAX,WAAW,CAAoC;QAE/D,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,MAAM,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as from '../../config/schemas.js';
2
+ export declare class AliasCompiler {
3
+ private projectRoot;
4
+ constructor(projectRoot: string);
5
+ compile(config: schemas.config['infer']): AliasCompiler.CompiledAlias[];
6
+ }
7
+ export declare namespace AliasCompiler {
8
+ interface Target {
9
+ local: string;
10
+ cdn?: string;
11
+ }
12
+ interface CompiledAlias {
13
+ alias: string;
14
+ targets: Target;
15
+ isWildcard: boolean;
16
+ }
17
+ }
18
+ export default AliasCompiler;
@@ -0,0 +1,32 @@
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
+ compile(config) {
9
+ const result = [];
10
+ const allDeps = [...(config.dependencies || []), ...(config.npmDependencies || [])];
11
+ for (const dep of allDeps) {
12
+ if (typeof dep !== 'object' || !dep.resolver)
13
+ continue;
14
+ for (const entry of dep.resolver) {
15
+ const isWildcard = Utils.isWildcard(entry.alias);
16
+ const alias = Utils.removeWildcardSuffix(entry.alias);
17
+ const rawLocal = typeof entry.target === 'string' ? entry.target : entry.target.local;
18
+ const localTarget = path.isAbsolute(rawLocal)
19
+ ? Utils.removeWildcardSuffix(rawLocal)
20
+ : path.resolve(this.projectRoot, Utils.removeWildcardSuffix(rawLocal));
21
+ let cdnTarget;
22
+ if (typeof entry.target === 'object' && entry.target.cdn) {
23
+ cdnTarget = Utils.removeWildcardSuffix(entry.target.cdn);
24
+ }
25
+ result.push({ alias, isWildcard, targets: { local: localTarget, cdn: cdnTarget } });
26
+ }
27
+ }
28
+ return result;
29
+ }
30
+ }
31
+ export default AliasCompiler;
32
+ //# sourceMappingURL=AliasCompiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AliasCompiler.js","sourceRoot":"","sources":["../../../src/support/Resolver/AliasCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/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AAC,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"}
@@ -0,0 +1,25 @@
1
+ import { Logger } from "vortez";
2
+ import schemas from '../../config/schemas.js';
3
+ import PathRewriter from './PathRewriter.js';
4
+ import AliasCompiler from './AliasCompiler.js';
5
+ export declare class PathResolver {
6
+ readonly config: schemas.config['infer'];
7
+ readonly options: PathResolver.Options;
8
+ static readonly PROJECT_ROOT: string;
9
+ static readonly EXTENSIONS: string[];
10
+ protected readonly logger: Logger;
11
+ protected readonly rewriter: PathRewriter;
12
+ protected readonly absoluteOutDir: string;
13
+ readonly aliases: AliasCompiler.CompiledAlias[];
14
+ constructor(config: schemas.config['infer'], options?: PathResolver.Options);
15
+ rewritePaths(mode: PathResolver.Mode): Promise<void>;
16
+ protected processFile(file: string, mode: PathResolver.Mode): Promise<boolean>;
17
+ watch(mode: PathResolver.Mode): Promise<void>;
18
+ }
19
+ export declare namespace PathResolver {
20
+ type Mode = 'local' | 'cdn';
21
+ interface Options {
22
+ logger?: Logger;
23
+ }
24
+ }
25
+ export default PathResolver;