depflow 2.0.2 → 3.0.0-dev.10

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 (78) hide show
  1. package/README.md +129 -58
  2. package/build/cli/DepFLowCLI.d.ts +1 -0
  3. package/build/cli/DepFLowCLI.js +66 -19
  4. package/build/cli/DepFLowCLI.js.map +1 -1
  5. package/build/cli/bin.js +13 -12
  6. package/build/cli/bin.js.map +1 -1
  7. package/build/config/Config.d.ts +3 -3
  8. package/build/config/Config.js +3 -3
  9. package/build/config/Config.js.map +1 -1
  10. package/build/config/ImportMap.d.ts +24 -11
  11. package/build/config/ImportMap.js +43 -29
  12. package/build/config/ImportMap.js.map +1 -1
  13. package/build/config/{Tsconfig.d.ts → TSConfig.d.ts} +14 -17
  14. package/build/config/{Tsconfig.js → TSConfig.js} +42 -37
  15. package/build/config/TSConfig.js.map +1 -0
  16. package/build/schema/Config/Builder.d.ts +431 -0
  17. package/build/schema/Config/Builder.js +48 -0
  18. package/build/schema/Config/Builder.js.map +1 -0
  19. package/build/schema/Config/Config.d.ts +582 -0
  20. package/build/schema/Config/Config.js +20 -0
  21. package/build/schema/Config/Config.js.map +1 -0
  22. package/build/schema/Config/Dependency.d.ts +748 -0
  23. package/build/schema/Config/Dependency.js +25 -0
  24. package/build/schema/Config/Dependency.js.map +1 -0
  25. package/build/schema/Config/Extractor.d.ts +133 -0
  26. package/build/schema/Config/Extractor.js +25 -0
  27. package/build/schema/Config/Extractor.js.map +1 -0
  28. package/build/schema/Config/Resolver.d.ts +70 -0
  29. package/build/schema/Config/Resolver.js +25 -0
  30. package/build/schema/Config/Resolver.js.map +1 -0
  31. package/build/schema/Config/Transform.d.ts +73 -0
  32. package/build/schema/Config/Transform.js +27 -0
  33. package/build/schema/Config/Transform.js.map +1 -0
  34. package/build/schema/ImportMap.d.ts +22 -0
  35. package/build/schema/ImportMap.js +12 -0
  36. package/build/schema/ImportMap.js.map +1 -0
  37. package/build/schema/TSConfig.d.ts +56 -0
  38. package/build/schema/TSConfig.js +19 -0
  39. package/build/schema/TSConfig.js.map +1 -0
  40. package/build/schema/schema.d.ts +29 -0
  41. package/build/schema/schema.js +31 -0
  42. package/build/schema/schema.js.map +1 -0
  43. package/build/support/Builder/Builder.d.ts +46 -0
  44. package/build/support/Builder/Builder.js +116 -0
  45. package/build/support/Builder/Builder.js.map +1 -0
  46. package/build/support/Dependency/Dependency.d.ts +38 -0
  47. package/build/support/Dependency/Dependency.js +14 -0
  48. package/build/support/Dependency/Dependency.js.map +1 -0
  49. package/build/support/Dependency/GitDependency.d.ts +20 -0
  50. package/build/support/Dependency/GitDependency.js +67 -0
  51. package/build/support/Dependency/GitDependency.js.map +1 -0
  52. package/build/support/Dependency/NpmDependency.d.ts +18 -0
  53. package/build/support/Dependency/NpmDependency.js +65 -0
  54. package/build/support/Dependency/NpmDependency.js.map +1 -0
  55. package/build/support/Git.js +1 -1
  56. package/build/support/Git.js.map +1 -1
  57. package/build/support/PathResolver/AliasCompiler.d.ts +13 -6
  58. package/build/support/PathResolver/AliasCompiler.js +35 -12
  59. package/build/support/PathResolver/AliasCompiler.js.map +1 -1
  60. package/build/support/PathResolver/PathResolver.d.ts +4 -4
  61. package/build/support/PathResolver/PathResolver.js +23 -17
  62. package/build/support/PathResolver/PathResolver.js.map +1 -1
  63. package/build/support/Task/Task.js +1 -1
  64. package/build/support/Task/Task.js.map +1 -1
  65. package/build/support/Utils.d.ts +9 -1
  66. package/build/support/Utils.js +30 -0
  67. package/build/support/Utils.js.map +1 -1
  68. package/package.json +6 -7
  69. package/build/config/Tsconfig.js.map +0 -1
  70. package/build/config/schemas.d.ts +0 -641
  71. package/build/config/schemas.js +0 -51
  72. package/build/config/schemas.js.map +0 -1
  73. package/build/support/Async.d.ts +0 -22
  74. package/build/support/Async.js +0 -62
  75. package/build/support/Async.js.map +0 -1
  76. package/build/support/Dependency.d.ts +0 -109
  77. package/build/support/Dependency.js +0 -274
  78. package/build/support/Dependency.js.map +0 -1
@@ -1,15 +1,13 @@
1
- import PATH from 'node:path';
2
1
  import { Logger } from '@netfeez/vterm';
3
2
  import { File, Path } from '@netfeez/common-node';
3
+ import schema from '../schema/schema.js';
4
4
  export class ImportMap {
5
5
  data;
6
- projectRoot;
7
- filename;
6
+ path;
8
7
  logger;
9
- constructor(data, projectRoot, filename, options = {}) {
8
+ constructor(data, path, options = {}) {
10
9
  this.data = data;
11
- this.projectRoot = projectRoot;
12
- this.filename = filename;
10
+ this.path = path;
13
11
  this.logger = options.logger || new Logger({ name: 'IMP-MAP' });
14
12
  }
15
13
  /**
@@ -21,15 +19,15 @@ export class ImportMap {
21
19
  updateImports(aliases, mode) {
22
20
  if (!this.data.imports)
23
21
  this.data.imports = {};
22
+ const projectRoot = Path.dirname(this.path);
24
23
  for (const aliasObj of aliases) {
25
24
  const key = aliasObj.isWildcard ? `${aliasObj.alias}/` : aliasObj.alias;
26
25
  let target = mode === 'cdn' && aliasObj.targets.cdn
27
26
  ? aliasObj.targets.cdn
28
27
  : aliasObj.targets.local;
29
28
  if (target === aliasObj.targets.local) {
30
- target = PATH.relative(this.projectRoot, target);
31
- if (!target.startsWith('./'))
32
- target = `./${target}`;
29
+ target = Path.diff(projectRoot, target);
30
+ target = target.startsWith('.') ? target : `./${target}`;
33
31
  target = Path.normalize(target);
34
32
  }
35
33
  if (aliasObj.isWildcard) {
@@ -39,44 +37,60 @@ export class ImportMap {
39
37
  this.data.imports[key] = target;
40
38
  }
41
39
  }
42
- async save(filename = this.filename) {
43
- await ImportMap.save(this.projectRoot, filename, this.data, { logger: this.logger });
40
+ /**
41
+ * Saves the provided import map data to a specified file path.
42
+ * It ensures that the directory for the file exists, converts the data to a JSON string with proper formatting, and writes it to the file system.
43
+ * The method also includes logging to inform users when the save operation is successful.
44
+ * @param path The path to the import map file to save.
45
+ * @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
46
+ */
47
+ async save(path = this.path) {
48
+ await ImportMap.save(path, this.data, { logger: this.logger });
49
+ if (path !== this.path)
50
+ this.path = path;
44
51
  }
45
- static async save(projectRoot, filename, data, options = {}) {
52
+ /**
53
+ * Saves the provided import map data to a specified file path.
54
+ * It ensures that the directory for the file exists, converts the data to a JSON string with proper formatting, and writes it to the file system.
55
+ * The method also includes logging to inform users when the save operation is successful.
56
+ * @param path The path to the import map file to save.
57
+ * @param data The import map data to be saved.
58
+ * @param options Additional options for saving, such as a logger for logging messages during the save process.
59
+ * @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
60
+ */
61
+ static async save(path, data, options = {}) {
46
62
  const logger = options.logger || new Logger({ name: 'IMP-MAP' });
47
- const importMapPath = PATH.resolve(projectRoot, filename);
48
- const folder = PATH.dirname(importMapPath);
49
- if (!await File.exists(folder))
50
- await File.mkdir(folder, { recursive: true });
63
+ const folder = Path.dirname(path);
64
+ await File.ensureDir(folder);
51
65
  const json = JSON.stringify(data, null, 4);
52
- await File.write(importMapPath, json);
53
- logger.log(`&C2Generated &C4${filename}`);
66
+ await File.write(path, json);
67
+ const filename = Path.fileName(path);
68
+ logger.log(`&C2Saved file &C4${filename}`);
54
69
  }
55
70
  /**
56
71
  * Factory method: Loads, validates (or creates default), and returns an instance of the ImportMap class.
57
72
  * It checks if the specified import map file exists, and if it does, it attempts to read and parse its content as JSON.
58
73
  * If the file does not exist or contains invalid JSON, it initializes the data with a default structure containing an empty "imports" object.
59
74
  * Finally, it returns a new instance of ImportMap with the loaded or default data, allowing for further manipulation and saving of the import map configuration.
60
- * @param projectRoot The root directory of the project where the import map file is located.
61
- * @param filename The name of the import map file to load (e.g., 'import-map.json').
75
+ * @param path The path to the import map file to load.
62
76
  * @param options Additional options for loading, such as a logger for logging messages during the load process.
63
77
  * @returns A promise that resolves to an instance of ImportMap initialized with the loaded or default data.
64
78
  */
65
- static async load(projectRoot, filename, options = {}) {
79
+ static async load(path, options = {}) {
66
80
  const logger = options.logger || new Logger({ name: 'IMP-MAP' });
67
- const importMapPath = PATH.resolve(projectRoot, filename);
68
- let data = { imports: {} };
69
- if (!await File.exists(importMapPath)) {
81
+ let data;
82
+ if (!await File.exists(path)) {
83
+ const filename = Path.fileName(path);
70
84
  logger.warn(`&C3${filename} not found. Creating defaults...`);
71
- const data = { imports: {} };
72
- await ImportMap.save(projectRoot, filename, data, { logger });
85
+ data = schema.ImportMap.processData({});
86
+ // await ImportMap.save(projectRoot, filename, data, { logger });
73
87
  }
74
88
  else {
75
- const content = await File.read(importMapPath, 'utf-8');
89
+ const content = await File.read(path, 'utf-8');
76
90
  const json = JSON.parse(content);
77
- data = json;
91
+ data = schema.ImportMap.processData(json);
78
92
  }
79
- return new ImportMap(data, projectRoot, filename, { logger });
93
+ return new ImportMap(data, path, { logger });
80
94
  }
81
95
  }
82
96
  export default ImportMap;
@@ -1 +1 @@
1
- {"version":3,"file":"ImportMap.js","sourceRoot":"","sources":["../../src/config/ImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,OAAO,SAAS;IAIJ;IACA;IACA;IALJ,MAAM,CAAS;IAEzB,YACc,IAAoB,EACpB,WAAmB,EACnB,QAAgB,EAC1B,UAA6B,EAAE;QAHrB,SAAI,GAAJ,IAAI,CAAgB;QACpB,gBAAW,GAAX,WAAW,CAAQ;QACnB,aAAQ,GAAR,QAAQ,CAAQ;QAG1B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IACpE,CAAC;IAED;;;;;OAKG;IACI,aAAa,CAAC,OAAsC,EAAE,IAAqB;QAC9E,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QA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,CAAC;YAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;CACJ;AAOD,eAAe,SAAS,CAAC"}
@@ -1,12 +1,11 @@
1
1
  import { Logger } from '@netfeez/vterm';
2
- import schemas from "./schemas.js";
3
2
  import AliasCompiler from '../support/PathResolver/AliasCompiler.js';
4
- export declare class Tsconfig {
5
- protected data: Tsconfig.Data;
6
- protected projectRoot: string;
7
- protected filename: string;
3
+ import schema from '../schema/schema.js';
4
+ export declare class TSConfig {
5
+ protected data: TSConfig.Data;
6
+ protected path: string;
8
7
  protected logger: Logger;
9
- constructor(data: Tsconfig.Data, projectRoot: string, filename: string, options?: Tsconfig.Options);
8
+ constructor(data: TSConfig.Data, path: string, options?: TSConfig.Options);
10
9
  /**
11
10
  * Updates the paths in the tsconfig data based on the provided compiled aliases.
12
11
  * It ensures that the compilerOptions and paths properties exist in the tsconfig data, and then iterates through the compiled aliases to construct the appropriate path mappings.
@@ -19,39 +18,37 @@ export declare class Tsconfig {
19
18
  * Saves the current tsconfig data to a file.
20
19
  * It constructs the path to the tsconfig file using the project root and filename, converts the data to a JSON string with proper formatting, and writes it to the file system using the File.write method.
21
20
  * The method also includes error handling to log any issues that occur during the save process, ensuring that users are informed of any problems when attempting to save the tsconfig configuration.
22
- * @param filename The name of the tsconfig file to save (default is the instance's filename property).
21
+ * @param path The path to the tsconfig file where the data should be saved.
23
22
  * @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
24
23
  */
25
- save(filename?: string): Promise<void>;
24
+ save(path?: string): Promise<void>;
26
25
  /**
27
26
  * Static method to save tsconfig data to a specified file. It takes the project root, filename, tsconfig data, and options (including a logger) as parameters.
28
27
  * The method constructs the full path to the tsconfig file, converts the data to a formatted JSON string, and writes it to the file system.
29
28
  * It also includes error handling to log any issues that arise during the save process, providing feedback on whether the operation was successful or if it encountered problems.
30
- * @param projectRoot The root directory of the project where the tsconfig file should be saved.
31
- * @param filename The name of the tsconfig file (default is 'tsconfig.json').
29
+ * @param path The path to the tsconfig file where the data should be saved.
32
30
  * @param data The tsconfig data to be saved, structured according to the defined schema.
33
31
  * @param options Additional options for saving, such as a logger for logging messages during the save process.
34
32
  * @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
35
33
  * @throws Will throw an error if there is an issue during the save process, which can be caught by the caller to handle it appropriately.
36
34
  */
37
- static save(projectRoot: string, filename: string | undefined, data: Tsconfig.Data, options?: Tsconfig.Options): Promise<void>;
35
+ static save(path: string, data: TSConfig.Data, options?: TSConfig.Options): Promise<void>;
38
36
  /**
39
37
  * Static method to load tsconfig data from a specified file.
40
38
  * It takes the project root, filename, and options (including a logger) as parameters.
41
39
  * The method checks if the tsconfig file exists, and if it does, it reads the content, parses it as JSON, and processes it using the defined schema to ensure it conforms to the expected structure.
42
40
  * If the file does not exist, it creates a default tsconfig data object using the schema. Finally, it returns an instance of the Tsconfig class initialized with the loaded or default data.
43
- * @param projectRoot The root directory of the project where the tsconfig file is located.
44
- * @param filename The name of the tsconfig file to load (default is 'tsconfig.json').
41
+ * @param path The path to the tsconfig file to load.
45
42
  * @param options Additional options for loading, such as a logger for logging messages during the load process.
46
43
  * @returns A promise that resolves to an instance of the Tsconfig class containing the loaded data, or rejects if there is an error during the load process.
47
44
  * @throws Will throw an error if there is an issue during the load process, which
48
45
  */
49
- static load(projectRoot: string, filename: string, options: Tsconfig.Options): Promise<Tsconfig>;
46
+ static load(path: string, options: TSConfig.Options): Promise<TSConfig>;
50
47
  }
51
- export declare namespace Tsconfig {
52
- type Data = schemas.basicTsconfig['infer'];
48
+ export declare namespace TSConfig {
49
+ type Data = schema.TSConfig.Root;
53
50
  interface Options {
54
51
  logger?: Logger;
55
52
  }
56
53
  }
57
- export default Tsconfig;
54
+ export default TSConfig;
@@ -1,16 +1,13 @@
1
- import PATH from 'node:path';
2
1
  import { Logger } from '@netfeez/vterm';
3
2
  import { File, Path } from '@netfeez/common-node';
4
- import schemas from "./schemas.js";
5
- export class Tsconfig {
3
+ import schema from '../schema/schema.js';
4
+ export class TSConfig {
6
5
  data;
7
- projectRoot;
8
- filename;
6
+ path;
9
7
  logger;
10
- constructor(data, projectRoot, filename, options = {}) {
8
+ constructor(data, path, options = {}) {
11
9
  this.data = data;
12
- this.projectRoot = projectRoot;
13
- this.filename = filename;
10
+ this.path = path;
14
11
  this.logger = options.logger || new Logger({ name: 'TS-CFG' });
15
12
  }
16
13
  /**
@@ -25,75 +22,83 @@ export class Tsconfig {
25
22
  this.data.compilerOptions = {};
26
23
  if (!this.data.compilerOptions.paths)
27
24
  this.data.compilerOptions.paths = {};
28
- for (const aliasObj of aliases) {
29
- const key = aliasObj.isWildcard ? `${aliasObj.alias}/*` : aliasObj.alias;
30
- let target = PATH.relative(this.projectRoot, aliasObj.targets.local);
25
+ const projectRoot = Path.dirname(this.path);
26
+ for (const alias of aliases) {
27
+ const key = alias.isWildcard ? `${alias.alias}/*` : alias.alias;
28
+ let target = Path.diff(projectRoot, alias.targets.local);
29
+ target = target.startsWith('.') ? target : `./${target}`;
31
30
  target = Path.normalize(target);
32
- if (aliasObj.isWildcard) {
31
+ let typeTarget;
32
+ if (alias.targets.type) {
33
+ typeTarget = Path.diff(projectRoot, alias.targets.type);
34
+ typeTarget = typeTarget.startsWith('.') ? typeTarget : `./${typeTarget}`;
35
+ typeTarget = Path.normalize(typeTarget);
36
+ }
37
+ if (alias.isWildcard) {
33
38
  const suffix = target.endsWith('/') ? '*' : '/*';
34
39
  target = `${target}${suffix}`;
40
+ if (typeTarget) {
41
+ typeTarget = `${typeTarget}${suffix}`;
42
+ }
35
43
  }
36
- this.data.compilerOptions.paths[key] = [target];
44
+ this.data.compilerOptions.paths[key] = typeTarget ? [typeTarget, target] : [target];
37
45
  }
38
46
  }
39
47
  /**
40
48
  * Saves the current tsconfig data to a file.
41
49
  * It constructs the path to the tsconfig file using the project root and filename, converts the data to a JSON string with proper formatting, and writes it to the file system using the File.write method.
42
50
  * The method also includes error handling to log any issues that occur during the save process, ensuring that users are informed of any problems when attempting to save the tsconfig configuration.
43
- * @param filename The name of the tsconfig file to save (default is the instance's filename property).
51
+ * @param path The path to the tsconfig file where the data should be saved.
44
52
  * @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
45
53
  */
46
- async save(filename = this.filename) {
47
- await Tsconfig.save(this.projectRoot, filename, this.data, { logger: this.logger });
54
+ async save(path = this.path) {
55
+ await TSConfig.save(path, this.data, { logger: this.logger });
56
+ if (path !== this.path)
57
+ this.path = path;
48
58
  }
49
59
  /**
50
60
  * Static method to save tsconfig data to a specified file. It takes the project root, filename, tsconfig data, and options (including a logger) as parameters.
51
61
  * The method constructs the full path to the tsconfig file, converts the data to a formatted JSON string, and writes it to the file system.
52
62
  * It also includes error handling to log any issues that arise during the save process, providing feedback on whether the operation was successful or if it encountered problems.
53
- * @param projectRoot The root directory of the project where the tsconfig file should be saved.
54
- * @param filename The name of the tsconfig file (default is 'tsconfig.json').
63
+ * @param path The path to the tsconfig file where the data should be saved.
55
64
  * @param data The tsconfig data to be saved, structured according to the defined schema.
56
65
  * @param options Additional options for saving, such as a logger for logging messages during the save process.
57
66
  * @returns A promise that resolves when the save operation is complete, or rejects if an error occurs during the process.
58
67
  * @throws Will throw an error if there is an issue during the save process, which can be caught by the caller to handle it appropriately.
59
68
  */
60
- static async save(projectRoot, filename = 'tsconfig.json', data, options = {}) {
69
+ static async save(path, data, options = {}) {
61
70
  const logger = options.logger || new Logger({ name: 'TS-CFG' });
62
- const tsconfigPath = PATH.resolve(projectRoot, filename);
63
- const folder = PATH.dirname(tsconfigPath);
64
- if (!await File.exists(folder))
65
- await File.mkdir(folder, { recursive: true });
66
71
  const json = JSON.stringify(data, null, 4);
67
- await File.write(tsconfigPath, json);
68
- logger.log(`&C2Updated &C4${filename}&C2 successfully.`);
72
+ await File.write(path, json);
73
+ const filename = Path.fileName(path);
74
+ logger.log(`&C2Saved file &C4${filename}&C2 successfully.`);
69
75
  }
70
76
  /**
71
77
  * Static method to load tsconfig data from a specified file.
72
78
  * It takes the project root, filename, and options (including a logger) as parameters.
73
79
  * The method checks if the tsconfig file exists, and if it does, it reads the content, parses it as JSON, and processes it using the defined schema to ensure it conforms to the expected structure.
74
80
  * If the file does not exist, it creates a default tsconfig data object using the schema. Finally, it returns an instance of the Tsconfig class initialized with the loaded or default data.
75
- * @param projectRoot The root directory of the project where the tsconfig file is located.
76
- * @param filename The name of the tsconfig file to load (default is 'tsconfig.json').
81
+ * @param path The path to the tsconfig file to load.
77
82
  * @param options Additional options for loading, such as a logger for logging messages during the load process.
78
83
  * @returns A promise that resolves to an instance of the Tsconfig class containing the loaded data, or rejects if there is an error during the load process.
79
84
  * @throws Will throw an error if there is an issue during the load process, which
80
85
  */
81
- static async load(projectRoot, filename, options) {
86
+ static async load(path, options) {
82
87
  const logger = options.logger || new Logger({ name: 'TS-CFG' });
83
- const tsconfigPath = PATH.resolve(projectRoot, filename);
84
88
  let data;
85
- if (!await File.exists(tsconfigPath)) {
89
+ if (!await File.exists(path)) {
90
+ const filename = Path.fileName(path);
86
91
  logger.warn(`&C3${filename} not found. Creating defaults...`);
87
- data = schemas.basicTsconfig.processData({});
88
- this.save(projectRoot, filename, data, { logger }).catch(err => logger.error(`Failed to create default tsconfig:`, err.message));
92
+ data = schema.TSConfig.processData({});
93
+ // this.save(projectRoot, filename, data, { logger }).catch(err => logger.error(`Failed to create default tsconfig:`, err.message));
89
94
  }
90
95
  else {
91
- const content = await File.read(tsconfigPath, 'utf-8');
96
+ const content = await File.read(path, 'utf-8');
92
97
  const json = JSON.parse(content);
93
- data = schemas.basicTsconfig.processData(json);
98
+ data = schema.TSConfig.processData(json);
94
99
  }
95
- return new Tsconfig(data, projectRoot, filename, { logger });
100
+ return new TSConfig(data, path, { logger });
96
101
  }
97
102
  }
98
- export default Tsconfig;
99
- //# sourceMappingURL=Tsconfig.js.map
103
+ export default TSConfig;
104
+ //# sourceMappingURL=TSConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TSConfig.js","sourceRoot":"","sources":["../../src/config/TSConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC,MAAM,OAAO,QAAQ;IAIH;IACA;IAJJ,MAAM,CAAS;IAEzB,YACc,IAAmB,EACnB,IAAY,EACtB,UAA4B,EAAE;QAFpB,SAAI,GAAJ,IAAI,CAAe;QACnB,SAAI,GAAJ,IAAI,CAAQ;QAEtB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,CAAC;IACrE;;;;;;OAMG;IACI,WAAW,CAAC,OAAsC;QACrD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe;YAAE,IAAI,CAAC,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC/D,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,GAAG,EAAE,CAAC;QAE3E,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE5C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;YAEhE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