@nu-art/build-and-install 0.400.5 → 0.400.7

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 (104) hide show
  1. package/build-and-install-v3.d.ts +3 -0
  2. package/build-and-install-v3.js +27 -14
  3. package/build-and-install.js +0 -1
  4. package/core/consts.js +0 -1
  5. package/core/exceptions/PhaseAggregatedException.d.ts +5 -2
  6. package/core/exceptions/PhaseAggregatedException.js +18 -3
  7. package/core/exceptions/UnitPhaseException.d.ts +5 -0
  8. package/core/exceptions/UnitPhaseException.js +6 -0
  9. package/core/package/consts.js +0 -1
  10. package/core/params/params.d.ts +5 -5
  11. package/core/params/params.js +57 -29
  12. package/core/types/configs/firebasejson.js +0 -1
  13. package/core/types/configs/firebaserc.js +0 -1
  14. package/core/types/configs/index.js +0 -1
  15. package/core/types/configs/package-json.js +0 -1
  16. package/core/types/core.js +0 -1
  17. package/core/types/index.js +0 -1
  18. package/core/types/package/index.js +0 -1
  19. package/core/types/package/package.js +0 -1
  20. package/core/types/package/runtime-package.js +0 -1
  21. package/core/types/project-config.js +0 -1
  22. package/defaults/consts.js +0 -1
  23. package/old/PhaseRunnerDispatcher.js +0 -1
  24. package/old/runner-dispatchers.js +0 -1
  25. package/package.json +3 -3
  26. package/v3/PhaseManager.js +19 -5
  27. package/v3/RunningStatusHandler.d.ts +7 -5
  28. package/v3/RunningStatusHandler.js +21 -11
  29. package/v3/UnitsDependencyMapper/UnitsDependencyMapper.js +0 -1
  30. package/v3/UnitsMapper/UnitsMapper.js +0 -1
  31. package/v3/UnitsMapper/resolvers/UnitMapper_Base.js +0 -1
  32. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js +0 -1
  33. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.js +3 -2
  34. package/v3/UnitsMapper/resolvers/UnitMapper_Node.js +41 -35
  35. package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.js +0 -1
  36. package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.js +0 -1
  37. package/v3/UnitsMapper/resolvers/index.js +0 -1
  38. package/v3/UnitsMapper/types.js +0 -1
  39. package/v3/core/FilesCache.js +0 -1
  40. package/v3/core/Unit_HelpPrinter.d.ts +1 -1
  41. package/v3/core/Unit_HelpPrinter.js +0 -1
  42. package/v3/core/types.js +0 -1
  43. package/v3/phase/consts.d.ts +1 -0
  44. package/v3/phase/consts.js +4 -1
  45. package/v3/phase/index.js +0 -1
  46. package/v3/phase/types.js +0 -1
  47. package/v3/units/BaseUnit.js +0 -1
  48. package/v3/units/ProjectUnit.js +0 -1
  49. package/v3/units/Unit_NodeProject.js +0 -1
  50. package/v3/units/Unit_PackageJson.js +0 -1
  51. package/v3/units/Unit_TypescriptLib.d.ts +1 -0
  52. package/v3/units/Unit_TypescriptLib.js +76 -36
  53. package/v3/units/firebase/Unit_FirebaseFunctionsApp.d.ts +5 -2
  54. package/v3/units/firebase/Unit_FirebaseFunctionsApp.js +47 -29
  55. package/v3/units/firebase/Unit_FirebaseHostingApp.d.ts +3 -2
  56. package/v3/units/firebase/Unit_FirebaseHostingApp.js +24 -6
  57. package/v3/units/firebase/common.d.ts +3 -0
  58. package/v3/units/firebase/common.js +13 -0
  59. package/v3/units/index.js +0 -1
  60. package/build-and-install-v3.js.map +0 -1
  61. package/build-and-install.js.map +0 -1
  62. package/core/consts.js.map +0 -1
  63. package/core/exceptions/PhaseAggregatedException.js.map +0 -1
  64. package/core/package/consts.js.map +0 -1
  65. package/core/params/params.js.map +0 -1
  66. package/core/types/configs/firebasejson.js.map +0 -1
  67. package/core/types/configs/firebaserc.js.map +0 -1
  68. package/core/types/configs/index.js.map +0 -1
  69. package/core/types/configs/package-json.js.map +0 -1
  70. package/core/types/core.js.map +0 -1
  71. package/core/types/index.js.map +0 -1
  72. package/core/types/package/index.js.map +0 -1
  73. package/core/types/package/package.js.map +0 -1
  74. package/core/types/package/runtime-package.js.map +0 -1
  75. package/core/types/project-config.js.map +0 -1
  76. package/defaults/consts.js.map +0 -1
  77. package/old/PhaseRunnerDispatcher.js.map +0 -1
  78. package/old/runner-dispatchers.js.map +0 -1
  79. package/v3/PhaseManager.js.map +0 -1
  80. package/v3/RunningStatusHandler.js.map +0 -1
  81. package/v3/UnitsDependencyMapper/UnitsDependencyMapper.js.map +0 -1
  82. package/v3/UnitsMapper/UnitsMapper.js.map +0 -1
  83. package/v3/UnitsMapper/resolvers/UnitMapper_Base.js.map +0 -1
  84. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js.map +0 -1
  85. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.js.map +0 -1
  86. package/v3/UnitsMapper/resolvers/UnitMapper_Node.js.map +0 -1
  87. package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.js.map +0 -1
  88. package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.js.map +0 -1
  89. package/v3/UnitsMapper/resolvers/index.js.map +0 -1
  90. package/v3/UnitsMapper/types.js.map +0 -1
  91. package/v3/core/FilesCache.js.map +0 -1
  92. package/v3/core/Unit_HelpPrinter.js.map +0 -1
  93. package/v3/core/types.js.map +0 -1
  94. package/v3/phase/consts.js.map +0 -1
  95. package/v3/phase/index.js.map +0 -1
  96. package/v3/phase/types.js.map +0 -1
  97. package/v3/units/BaseUnit.js.map +0 -1
  98. package/v3/units/ProjectUnit.js.map +0 -1
  99. package/v3/units/Unit_NodeProject.js.map +0 -1
  100. package/v3/units/Unit_PackageJson.js.map +0 -1
  101. package/v3/units/Unit_TypescriptLib.js.map +0 -1
  102. package/v3/units/firebase/Unit_FirebaseFunctionsApp.js.map +0 -1
  103. package/v3/units/firebase/Unit_FirebaseHostingApp.js.map +0 -1
  104. package/v3/units/index.js.map +0 -1
@@ -57,4 +57,3 @@ export class UnitsMapper extends Logger {
57
57
  }
58
58
  }
59
59
  }
60
- //# sourceMappingURL=UnitsMapper.js.map
@@ -14,4 +14,3 @@ export class UnitMapper_Base extends Logger {
14
14
  this.baiConfig = config;
15
15
  }
16
16
  }
17
- //# sourceMappingURL=UnitMapper_Base.js.map
@@ -53,4 +53,3 @@ export class UnitMapper_FirebaseFunction_Class extends UnitMapper_Node {
53
53
  }
54
54
  }
55
55
  export const UnitMapper_FirebaseFunction = new UnitMapper_FirebaseFunction_Class();
56
- //# sourceMappingURL=UnitMapper_FirebaseFunction.js.map
@@ -23,8 +23,10 @@ export class UnitMapper_FirebaseHosting_Class extends UnitMapper_Node {
23
23
  const outputDir = context.packageJson.publishConfig?.directory;
24
24
  const env = this.runtimeParams[BaiParam_SetEnv.keyName];
25
25
  const envUnitConfig = context.packageJson.unitConfig.envs[env];
26
- if (!envUnitConfig)
26
+ if (!envUnitConfig) {
27
+ this.logWarning('Package Json config:', context.packageJson.unitConfig);
27
28
  throw new ImplementationMissingException(`Missing configuration for env: ${env}`);
29
+ }
28
30
  const envConfig = {
29
31
  config: envUnitConfig.config,
30
32
  projectId: envUnitConfig.projectId,
@@ -46,4 +48,3 @@ export class UnitMapper_FirebaseHosting_Class extends UnitMapper_Node {
46
48
  }
47
49
  }
48
50
  export const UnitMapper_FirebaseHosting = new UnitMapper_FirebaseHosting_Class();
49
- //# sourceMappingURL=UnitMapper_FirebaseHosting.js.map
@@ -19,41 +19,47 @@ export class UnitMapper_Node extends UnitMapper_Base {
19
19
  const pathToFile = `${path}/__package.json`;
20
20
  if (!await FileSystemUtils.file.exists(pathToFile))
21
21
  return;
22
- let packageJson = await FilesCache.load.json(pathToFile);
23
- if (!packageJson)
24
- return;
25
- if (!packageJson.unitConfig) {
26
- this.logWarning(`Found a package.json without unitConfig at: ${pathToFile}`);
27
- UnitMapper_Node.invalidPaths.push(path);
28
- return;
22
+ let packageJson;
23
+ try {
24
+ packageJson = await FilesCache.load.json(pathToFile);
25
+ if (!packageJson)
26
+ return;
27
+ if (!packageJson.unitConfig) {
28
+ this.logWarning(`Found a package.json without unitConfig at: ${pathToFile}`);
29
+ UnitMapper_Node.invalidPaths.push(path);
30
+ return;
31
+ }
32
+ if (tsValidateResult(packageJson.unitConfig.type, this.validator.type))
33
+ return; // not the expected type for this mapper
34
+ packageJson = deepClone(packageJson);
35
+ tsValidate(packageJson.unitConfig, this.validator);
36
+ const dependencies = packageJson.dependencies;
37
+ if (dependencies)
38
+ packageJson.dependencies = _keys(dependencies).reduce((acc, key) => {
39
+ acc[key] = dependencies[key] === '?' ? `{{${key}}}` : dependencies[key];
40
+ return acc;
41
+ }, {});
42
+ const devDependencies = packageJson.devDependencies;
43
+ if (devDependencies)
44
+ packageJson.devDependencies = _keys(devDependencies).reduce((acc, key) => {
45
+ acc[key] = devDependencies[key] === '?' ? `{{${key}}}` : devDependencies[key];
46
+ return acc;
47
+ }, {});
48
+ Object.freeze(packageJson);
49
+ const baseConfig = {
50
+ key: packageJson.name,
51
+ fullPath: path,
52
+ relativePath: path.replace(root, '.'),
53
+ label: packageJson.unitConfig.label ?? packageJson.name,
54
+ dependencies: { ...dependencies, ...packageJson.devDependencies },
55
+ };
56
+ const customESLintConfig = packageJson.unitConfig.customESLintConfig ?? false;
57
+ const customTSConfig = packageJson.unitConfig.customTSConfig ?? false;
58
+ return this.resolveNodeUnit({ path, root, packageJson, baseConfig, customESLintConfig, customTSConfig });
59
+ }
60
+ catch (e) {
61
+ this.logError(`Failed to load package.json at: ${pathToFile}`, e);
62
+ throw e;
29
63
  }
30
- if (tsValidateResult(packageJson.unitConfig.type, this.validator.type))
31
- return; // not the expected type for this mapper
32
- packageJson = deepClone(packageJson);
33
- tsValidate(packageJson.unitConfig, this.validator);
34
- const dependencies = packageJson.dependencies;
35
- if (dependencies)
36
- packageJson.dependencies = _keys(dependencies).reduce((acc, key) => {
37
- acc[key] = dependencies[key] === '?' ? `{{${key}}}` : dependencies[key];
38
- return acc;
39
- }, {});
40
- const devDependencies = packageJson.devDependencies;
41
- if (devDependencies)
42
- packageJson.devDependencies = _keys(devDependencies).reduce((acc, key) => {
43
- acc[key] = devDependencies[key] === '?' ? `{{${key}}}` : devDependencies[key];
44
- return acc;
45
- }, {});
46
- Object.freeze(packageJson);
47
- const baseConfig = {
48
- key: packageJson.name,
49
- fullPath: path,
50
- relativePath: path.replace(root, '.'),
51
- label: packageJson.unitConfig.label ?? packageJson.name,
52
- dependencies: { ...dependencies, ...packageJson.devDependencies },
53
- };
54
- const customESLintConfig = packageJson.unitConfig.customESLintConfig ?? false;
55
- const customTSConfig = packageJson.unitConfig.customTSConfig ?? false;
56
- return this.resolveNodeUnit({ path, root, packageJson, baseConfig, customESLintConfig, customTSConfig });
57
64
  }
58
65
  }
59
- //# sourceMappingURL=UnitMapper_Node.js.map
@@ -26,4 +26,3 @@ export class UnitMapper_NodeLib_Class extends UnitMapper_Node {
26
26
  }
27
27
  }
28
28
  export const UnitMapper_NodeLib = new UnitMapper_NodeLib_Class();
29
- //# sourceMappingURL=UnitMapper_NodeLib.js.map
@@ -20,4 +20,3 @@ export class UnitMapper_NodeProject_Class extends UnitMapper_Node {
20
20
  }
21
21
  }
22
22
  export const UnitMapper_NodeProject = new UnitMapper_NodeProject_Class();
23
- //# sourceMappingURL=UnitMapper_NodeProject.js.map
@@ -2,4 +2,3 @@ export * from './UnitMapper_NodeLib.js';
2
2
  export * from './UnitMapper_NodeProject.js';
3
3
  export * from './UnitMapper_FirebaseFunction.js';
4
4
  export * from './UnitMapper_FirebaseHosting.js';
5
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -31,4 +31,3 @@ export const FilesCache = {
31
31
  }
32
32
  }
33
33
  };
34
- //# sourceMappingURL=FilesCache.js.map
@@ -3,7 +3,7 @@ import { UnitPhaseImplementor } from './types.js';
3
3
  import { Phase } from '../phase/index.js';
4
4
  import { ProjectUnit } from '../units/index.js';
5
5
  export declare const BaiParam_Help: BaseCliParam<'help', boolean>;
6
- declare const AllBaiParams_Help: (BaseCliParam<"allUnits", boolean> | BaseCliParam<"dependencyTree", boolean> | BaseCliParam<"checkCyclicImports", boolean> | BaseCliParam<"continue", boolean> | BaseCliParam<"environment", string> | BaseCliParam<"setup", boolean> | BaseCliParam<"install", boolean> | BaseCliParam<"clean", boolean> | BaseCliParam<"purge", boolean> | BaseCliParam<"generate", boolean> | BaseCliParam<"generateDocs", boolean> | BaseCliParam<"noBuild", boolean> | BaseCliParam<"prepare", boolean> | BaseCliParam<"dryRun", boolean> | BaseCliParam<"lint", boolean> | BaseCliParam<"watch", boolean> | BaseCliParam<"watchBuildTree", boolean> | BaseCliParam<"test", boolean> | BaseCliParam<"testType", string[]> | BaseCliParam<"testFiles", string[]> | BaseCliParam<"testCases", string[]> | BaseCliParam<"testDebugPort", number> | BaseCliParam<"launch", boolean> | BaseCliParam<"debugBackend", boolean> | BaseCliParam<"deploy", string> | BaseCliParam<"debug", boolean> | BaseCliParam<"debugLifecycle", boolean> | BaseCliParam<"verbose", boolean> | BaseCliParam<"publish", "patch" | "minor" | "major"> | BaseCliParam<"usePackage", string[]> | BaseCliParam<"toESM", boolean> | BaseCliParam<"simulation", boolean> | BaseCliParam<"help", boolean>)[];
6
+ declare const AllBaiParams_Help: (BaseCliParam<"allUnits", boolean> | BaseCliParam<"dependencyTree", boolean> | BaseCliParam<"environment", string> | BaseCliParam<"install", boolean> | BaseCliParam<"clean", boolean> | BaseCliParam<"purge", boolean> | BaseCliParam<"generate", boolean> | BaseCliParam<"generateDocs", boolean> | BaseCliParam<"noBuild", boolean> | BaseCliParam<"prepare", boolean> | BaseCliParam<"dryRun", boolean> | BaseCliParam<"lint", boolean> | BaseCliParam<"watch", boolean> | BaseCliParam<"watchBuildTree", boolean> | BaseCliParam<"continue", boolean> | BaseCliParam<"test", boolean> | BaseCliParam<"testType", string[]> | BaseCliParam<"testFiles", string[]> | BaseCliParam<"testCases", string[]> | BaseCliParam<"testDebugPort", number> | BaseCliParam<"launch", boolean> | BaseCliParam<"debugBackend", boolean> | BaseCliParam<"deploy", boolean> | BaseCliParam<"debug", boolean> | BaseCliParam<"debugLifecycle", boolean> | BaseCliParam<"verbose", boolean> | BaseCliParam<"publish", "patch" | "minor" | "major"> | BaseCliParam<"usePackage", string[]> | BaseCliParam<"includePackage", string[]> | BaseCliParam<"toESM", boolean> | BaseCliParam<"simulation", boolean> | BaseCliParam<"checkCyclicImports", boolean> | BaseCliParam<"help", boolean>)[];
7
7
  export type Help_BaiParams = CliParams<typeof AllBaiParams_Help>;
8
8
  export type Phase_Help = typeof phase_Help;
9
9
  export declare const phaseKey_Help = "help";
@@ -45,4 +45,3 @@ class _Unit_HelpPrinter extends ProjectUnit {
45
45
  }
46
46
  }
47
47
  export const Unit_HelpPrinter = new _Unit_HelpPrinter();
48
- //# sourceMappingURL=Unit_HelpPrinter.js.map
package/v3/core/types.js CHANGED
@@ -3,4 +3,3 @@ export const WatchEvent_Update = 'update';
3
3
  export const WatchEvent_RemoveDir = 'remove_dir';
4
4
  export const WatchEvent_RemoveFile = 'remove_file';
5
5
  export const WatchEvent_Ready = 'ready';
6
- //# sourceMappingURL=types.js.map
@@ -8,6 +8,7 @@ export declare const phase_CheckCyclicImports: Phase<'checkCyclicImports'>;
8
8
  export type Phase_ToESM = typeof phase_ToESM;
9
9
  export declare const phaseKey_ToESM = "convertToESM";
10
10
  export declare const phase_ToESM: Phase<'convertToESM'>;
11
+ export declare const phases_Terminating: Phase<string>[][];
11
12
  export type Phase_Purge = typeof phase_Purge;
12
13
  export declare const phaseKey_Purge = "purge";
13
14
  export declare const phase_Purge: Phase<'purge'>;
@@ -21,6 +21,10 @@ export const phase_ToESM = {
21
21
  method: 'convertToESM',
22
22
  filter: (baiParams) => baiParams.toESM,
23
23
  };
24
+ export const phases_Terminating = [
25
+ [phase_PrintDependencyTree],
26
+ [phase_CheckCyclicImports],
27
+ ];
24
28
  export const phaseKey_Purge = 'purge';
25
29
  export const phase_Purge = {
26
30
  key: phaseKey_Purge,
@@ -125,4 +129,3 @@ export const phase_Deploy = {
125
129
  filter: (baiParams) => !!baiParams.deploy,
126
130
  };
127
131
  export const phases_Deploy = [[phase_Publish, phase_Deploy], [phase_PostPublish]];
128
- //# sourceMappingURL=consts.js.map
package/v3/phase/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './types.js';
2
2
  export * from './consts.js';
3
- //# sourceMappingURL=index.js.map
package/v3/phase/types.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -117,4 +117,3 @@ export class BaseUnit extends Logger {
117
117
  return this.logger.buffers[0];
118
118
  }
119
119
  }
120
- //# sourceMappingURL=BaseUnit.js.map
@@ -9,4 +9,3 @@ export class ProjectUnit extends BaseUnit {
9
9
  this.addToClassStack(ProjectUnit);
10
10
  }
11
11
  }
12
- //# sourceMappingURL=ProjectUnit.js.map
@@ -241,4 +241,3 @@ export class Unit_NodeProject extends Unit_PackageJson {
241
241
  async postPublish() {
242
242
  }
243
243
  }
244
- //# sourceMappingURL=Unit_NodeProject.js.map
@@ -48,4 +48,3 @@ export class Unit_PackageJson extends ProjectUnit {
48
48
  .execute();
49
49
  }
50
50
  }
51
- //# sourceMappingURL=Unit_PackageJson.js.map
@@ -11,6 +11,7 @@ export type Unit_TypescriptLib_Config = Unit_PackageJson_Config & {
11
11
  export declare class Unit_TypescriptLib<C extends Unit_TypescriptLib_Config = Unit_TypescriptLib_Config> extends Unit_PackageJson<C> implements UnitPhaseImplementor<[Phase_PreCompile, Phase_Compile, Phase_PrintDependencyTree, Phase_CheckCyclicImports, Phase_Lint, Phase_Test, Phase_Publish, Phase_ToESM]> {
12
12
  private TestTypeWorkspaceSetup;
13
13
  runTests(): Promise<void>;
14
+ protected dependencyUnits: Unit_TypescriptLib[];
14
15
  constructor(config: Unit_TypescriptLib<C>['config']);
15
16
  protected clearOutputDir(): Promise<void>;
16
17
  protected clearOutputDirImpl(): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import { copyFileSync, existsSync, promises as _fs, readdirSync, statSync } from 'fs';
3
- import { __stringify, arrayToMap, BadImplementationException, exists, ImplementationMissingException, LogLevel, NotImplementedYetException } from '@nu-art/ts-common';
3
+ import { __stringify, arrayToMap, BadImplementationException, ImplementationMissingException, LogLevel, NotImplementedYetException } from '@nu-art/ts-common';
4
4
  import { CONST_BaiConfig, CONST_FirebaseJSON, CONST_FirebaseRC, CONST_NodeModules, CONST_PackageJSON, CONST_PackageJSONTemplate, CONST_TS_CONFIG } from '../../core/consts.js';
5
5
  import { CommandoException } from '@nu-art/commando/shell/core/CliError';
6
6
  import { Commando_NVM } from '@nu-art/commando/shell/plugins/nvm';
@@ -126,6 +126,7 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
126
126
  });
127
127
  }
128
128
  }
129
+ dependencyUnits;
129
130
  constructor(config) {
130
131
  super(config);
131
132
  this.addToClassStack(Unit_TypescriptLib);
@@ -147,6 +148,8 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
147
148
  // @ts-ignore
148
149
  this.publish = undefined;
149
150
  }
151
+ const unitKeys = this.runtimeContext.unitsMapper.getTransitiveDependencies([this.config.key]);
152
+ this.dependencyUnits = this.runtimeContext.unitsResolver(unitKeys, Unit_TypescriptLib);
150
153
  }
151
154
  async compileImpl() {
152
155
  const pathToCompile = `${this.config.fullPath}/src/main`;
@@ -228,6 +231,8 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
228
231
  .execute();
229
232
  }
230
233
  async compile() {
234
+ if (!this.dependencyUnits)
235
+ await this.prepare();
231
236
  await this.clearOutputDirImpl();
232
237
  await this.compileImpl();
233
238
  await this.copyAssetsToOutput();
@@ -259,15 +264,18 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
259
264
  }
260
265
  async checkCyclicImports() {
261
266
  this.logDebug(`Checking Cyclic Imports - ${this.config.label}`);
267
+ const pathToMain = pathResolve(this.config.fullPath, './src/main');
268
+ const pathToTsConfig = pathResolve(pathToMain, './tsconfig.json');
262
269
  await this.allocateCommando(Commando_Basic)
263
270
  .cd(this.config.fullPath)
264
271
  // .setStdErrorValidator(stderr => {
265
272
  // return !stderr.includes('Finding files') && !stderr.includes('Image created');
266
273
  // })
267
- .append(`npx madge --no-spinner --image "./imports-${this.config.key}.svg" --circular ${this.config.output}`)
274
+ .append(`npx madge --no-spinner --ts-config ${pathToTsConfig} --image "./imports-${this.config.key}.svg" --extensions ts,tsx,mts,js,mjs --circular ${pathToMain} `)
268
275
  .append('echo $?')
269
276
  .execute();
270
277
  }
278
+ // npx madge --circular --ts-config ./tsconfig.json --extensions ts,tsx,mts,js,mjs ./src/main
271
279
  async lint() {
272
280
  // need to move the copy of the default eslint rules to here
273
281
  const pathToLint = pathResolve(this.config.fullPath, `src/main`);
@@ -383,55 +391,88 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
383
391
  const specificFiles = [CONST_PackageJSONTemplate];
384
392
  const fileExtensions = ['.ts', '.tsx', '.mts', '.js', '.jsx', '.mjs'];
385
393
  const units = arrayToMap(this.runtimeContext.childUnits, unit => unit.config.key);
386
- const toESM = async (pathTofile, importPath) => {
387
- importPath = importPath.replace(/\/+/g, '/');
388
- if (importPath.endsWith('.js'))
389
- return importPath;
394
+ const toESM = async (pathTofile, originImportPath) => {
395
+ originImportPath = originImportPath.replace(/\/+/g, '/');
396
+ if (originImportPath.endsWith('.js'))
397
+ return originImportPath;
398
+ if (originImportPath.endsWith('.json'))
399
+ return originImportPath;
390
400
  for (const extension of fileExtensions) {
391
- if (!importPath.endsWith(extension))
401
+ if (!originImportPath.endsWith(extension))
392
402
  continue;
393
- importPath = importPath.replace(extension, '');
403
+ originImportPath = originImportPath.replace(extension, '');
394
404
  break;
395
405
  }
396
- let initialPath;
397
- let relativePathToFile;
398
- let extension = '';
399
- if (importPath.startsWith('.') || importPath.startsWith('/')) {
400
- initialPath = path.dirname(pathTofile);
401
- relativePathToFile = importPath;
402
- extension = '.js';
403
- }
404
- else {
405
- const [part1, part2, ...relativePathParts] = importPath.split('/');
406
- const unit = units[part1] ?? units[`${part1}/${part2}`];
407
- if (unit) {
408
- initialPath = `${unit.config.fullPath}/src/main`;
409
- relativePathToFile = relativePathParts.join('/');
410
- }
406
+ // this can be ./path/to/folder => ./path/to/folder/index.js
407
+ // this can be ./path/to/file => ./path/to/file.js
408
+ if (originImportPath.startsWith('.') || originImportPath.startsWith('/')) {
409
+ const initialPath = path.dirname(pathTofile);
410
+ let relativePathToFile = originImportPath;
411
+ const fullPath = path.resolve(initialPath, relativePathToFile);
412
+ if (await FileSystemUtils.exists(fullPath) && await FileSystemUtils.folder.isFolder(fullPath))
413
+ relativePathToFile = `${relativePathToFile}/index`;
414
+ // either way we need to add a .js
415
+ relativePathToFile += '.js';
416
+ relativePathToFile = relativePathToFile.replace(/\/+/g, '/');
417
+ return relativePathToFile;
411
418
  }
412
- if (!exists(initialPath) || !exists(relativePathToFile))
419
+ const resolveImportPathFromUnit = async (packageName, relativePathToFile) => {
420
+ const unit = units[packageName];
421
+ if (!unit)
422
+ return;
423
+ let initialPath = `${unit.config.fullPath}/src/main`;
424
+ const fullPath = path.resolve(initialPath, relativePathToFile);
425
+ if (await FileSystemUtils.exists(fullPath) && await FileSystemUtils.folder.isFolder(fullPath))
426
+ relativePathToFile = `${relativePathToFile}/index`;
427
+ const importPath = `${packageName}/${relativePathToFile}`.replace(/\/+/g, '/');
428
+ if (importPath === `${packageName}/index`)
429
+ return `${packageName}`;
413
430
  return importPath;
414
- const fullPath = path.resolve(initialPath, relativePathToFile);
415
- if (await FileSystemUtils.exists(fullPath) && await FileSystemUtils.folder.isFolder(fullPath))
416
- relativePathToFile = `${relativePathToFile}/index`;
417
- // throw new BadImplementationException(`Expected file to exist: ${fullPath}`);
418
- relativePathToFile += extension;
419
- relativePathToFile = relativePathToFile.replace(/\/+/g, '/');
420
- return relativePathToFile;
431
+ };
432
+ // this can be {{libName}}/path/to/file => {{libName}}/path/to/file
433
+ let [libName1, ...rest1] = originImportPath.split('/');
434
+ let esmImportPath = await resolveImportPathFromUnit(libName1, rest1.join('/'));
435
+ if (esmImportPath)
436
+ return esmImportPath;
437
+ let [libOrg, libName2, ...rest2] = originImportPath.split('/');
438
+ esmImportPath = await resolveImportPathFromUnit(`${libOrg}/${libName2}`, rest2.join('/'));
439
+ if (esmImportPath)
440
+ return esmImportPath;
441
+ return originImportPath;
421
442
  };
422
443
  const importMatchers = [
423
444
  {
424
- regex: /from\s+["']([^"']+)["']/g,
445
+ regex: /from\s+"(\S+)?"/g,
425
446
  replacer: async (pathTofile, importPath) => `from "${await toESM(pathTofile, importPath)}"`
426
447
  },
427
448
  {
428
- regex: /require\(\s*["']([^"']+)["']\s*\)/g,
429
- replacer: async (pathTofile, importPath) => `await import("${await toESM(pathTofile, importPath)}")`
449
+ regex: /from\s+'(\S+)?'/g,
450
+ replacer: async (pathTofile, importPath) => `from '${await toESM(pathTofile, importPath)}'`
451
+ },
452
+ {
453
+ regex: /\srequire\((\S+)?\)/g,
454
+ replacer: async (pathTofile, importPath) => ` await import("${await toESM(pathTofile, importPath)}")`
430
455
  },
431
456
  {
432
- regex: /import\(\s*["']([^"']+)["']\s*\)/g,
457
+ regex: /\srequire\((\S+)?\)/g,
458
+ replacer: async (pathTofile, importPath) => ` await import('${await toESM(pathTofile, importPath)}')`
459
+ },
460
+ {
461
+ regex: /\srequire\(\s*"(\S+)?"\s*\)/g,
462
+ replacer: async (pathTofile, importPath) => ` await import("${await toESM(pathTofile, importPath)}")`
463
+ },
464
+ {
465
+ regex: /\srequire\(\s*'(\S+)?'\s*\)/g,
466
+ replacer: async (pathTofile, importPath) => ` await import('${await toESM(pathTofile, importPath)}')`
467
+ },
468
+ {
469
+ regex: /import\(\s*"(\S+)?"\s*\)/g,
433
470
  replacer: async (pathTofile, importPath) => `import("${await toESM(pathTofile, importPath)}")`
434
471
  },
472
+ {
473
+ regex: /import\(\s*'(\S+)?'\s*\)/g,
474
+ replacer: async (pathTofile, importPath) => `import('${await toESM(pathTofile, importPath)}')`
475
+ },
435
476
  ];
436
477
  const updateImports = async (pathToEntry) => {
437
478
  let content = await FileSystemUtils.file.read(pathToEntry);
@@ -499,4 +540,3 @@ export class Unit_TypescriptLib extends Unit_PackageJson {
499
540
  }
500
541
  ;
501
542
  }
502
- //# sourceMappingURL=Unit_TypescriptLib.js.map
@@ -1,7 +1,8 @@
1
- import { Unit_TypescriptLib, Unit_TypescriptLib_Config } from '../index.js';
2
1
  import { UnitPhaseImplementor } from '../../core/types.js';
3
2
  import { FirebasePackageConfig } from '../../../core/types/index.js';
3
+ import { StringMap } from '@nu-art/ts-common';
4
4
  import { Phase_Deploy, Phase_Launch } from '../../phase/index.js';
5
+ import { Unit_TypescriptLib, Unit_TypescriptLib_Config } from '../Unit_TypescriptLib.js';
5
6
  export declare const firebaseFunctionEmulator_ErrorStrings: string[];
6
7
  export declare const firebaseFunctionEmulator_WarningStrings: string[];
7
8
  type EnvConfig = {
@@ -23,6 +24,7 @@ export type Unit_FirebaseFunctionsApp_Config = Unit_TypescriptLib_Config & {
23
24
  sources?: string[];
24
25
  };
25
26
  export declare class Unit_FirebaseFunctionsApp<C extends Unit_FirebaseFunctionsApp_Config = Unit_FirebaseFunctionsApp_Config> extends Unit_TypescriptLib<C> implements UnitPhaseImplementor<[Phase_Launch, Phase_Deploy]> {
27
+ functions: StringMap;
26
28
  static staggerCount: number;
27
29
  static DefaultConfig_FirebaseFunction: {
28
30
  pathToFirebaseConfig: string;
@@ -48,11 +50,12 @@ export declare class Unit_FirebaseFunctionsApp<C extends Unit_FirebaseFunctionsA
48
50
  private getEnvConfig;
49
51
  private resolveFunctionsRC;
50
52
  private resolveProxyFile;
53
+ private pathToProxy;
51
54
  private resolveConfigDir;
52
55
  private resolveFunctionsJSON;
53
56
  private resolveFunctionsRuntimeConfig;
54
57
  private createAppVersionFile;
55
- protected deriveDistDependencies(): import("@nu-art/ts-common").StringMap;
58
+ protected deriveDistDependencies(): StringMap;
56
59
  private createDependenciesDir;
57
60
  private runProxy;
58
61
  private runEmulator;
@@ -1,11 +1,13 @@
1
- import { Unit_TypescriptLib } from '../index.js';
2
- import { CONST_FirebaseJSON, CONST_FirebaseRC, CONST_PackageJSON } from '../../../core/consts.js';
1
+ import { CONST_FirebaseJSON, CONST_FirebaseRC, CONST_NodeModules, CONST_PackageJSON } from '../../../core/consts.js';
3
2
  import { promises as _fs } from 'fs';
4
- import { __stringify, _logger_logPrefixes, deepClone, ImplementationMissingException, LogLevel, reduceObject, Second, sleep } from '@nu-art/ts-common';
3
+ import { __stringify, _keys, _logger_logPrefixes, deepClone, ImplementationMissingException, LogLevel, Second, sleep } from '@nu-art/ts-common';
5
4
  import { Const_FirebaseConfigKeys, Const_FirebaseDefaultsKeyToFile } from '../../../defaults/consts.js';
6
5
  import { Commando_NVM } from '@nu-art/commando/shell/plugins/nvm';
7
6
  import { resolve } from 'path';
8
7
  import { DEFAULT_OLD_TEMPLATE_PATTERN, FileSystemUtils } from '@nu-art/ts-common/utils/FileSystemUtils';
8
+ import { Unit_TypescriptLib } from '../Unit_TypescriptLib.js';
9
+ import { CommandoException } from '@nu-art/commando/shell/core/CliError';
10
+ import { deployLogFilter } from './common.js';
9
11
  export const firebaseFunctionEmulator_ErrorStrings = [
10
12
  'functions: Failed',
11
13
  ];
@@ -14,6 +16,7 @@ export const firebaseFunctionEmulator_WarningStrings = [
14
16
  ];
15
17
  // const CONST_VersionApp = 'version-app.json';
16
18
  export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
19
+ functions = {};
17
20
  static staggerCount = 0;
18
21
  static DefaultConfig_FirebaseFunction = {
19
22
  pathToFirebaseConfig: '.firebase_config',
@@ -45,11 +48,20 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
45
48
  const distDependencies = this.deriveDistDependencies();
46
49
  packageJson.main = 'index.js';
47
50
  packageJson.types = 'index.d.ts';
48
- if (packageJson.dependencies)
49
- packageJson.dependencies = reduceObject(packageJson.dependencies, packageJson.dependencies, (acc, key, value) => {
50
- acc[key] = distDependencies[key] ?? value;
51
- return acc;
52
- });
51
+ const dependencies = packageJson.dependencies ?? {};
52
+ // First, update existing dependencies (replace workspace:* with file: paths where applicable)
53
+ _keys(dependencies).reduce((dependencies, packageName) => {
54
+ if (distDependencies[packageName])
55
+ dependencies[packageName] = distDependencies[packageName];
56
+ return dependencies;
57
+ }, dependencies);
58
+ // Then, add ALL dependencyUnits to the dependencies (this includes transitive dependencies)
59
+ // This ensures the entire dependency tree is referenced in the main package.json
60
+ this.dependencyUnits.reduce((dependencies, unit) => {
61
+ dependencies[unit.config.key] = distDependencies[unit.config.key];
62
+ return dependencies;
63
+ }, dependencies);
64
+ packageJson.dependencies = dependencies;
53
65
  await FileSystemUtils.file.template.write(targetPath, __stringify(packageJson, true), this.deriveDistDependencies(), DEFAULT_OLD_TEMPLATE_PATTERN);
54
66
  }
55
67
  async prepare() {
@@ -59,6 +71,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
59
71
  return await FileSystemUtils.folder.delete(path);
60
72
  });
61
73
  await FileSystemUtils.folder.create(resolve(this.config.fullPath, this.config.pathToEmulatorData));
74
+ await FileSystemUtils.file.delete(this.pathToProxy());
62
75
  await this.resolveConfigs();
63
76
  }
64
77
  async resolveConfigs() {
@@ -89,8 +102,19 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
89
102
  .ls()
90
103
  .cat('package.json')
91
104
  .cat('index.js')
92
- .cd(this.config.fullPath);
93
- await this.executeAsyncCommando(commando, `firebase --debug deploy --only functions --force`);
105
+ .cd(this.config.fullPath)
106
+ .setLogLevelFilter(deployLogFilter)
107
+ // example: Function URL (hello(us-central1)): https://hello-kv65k7yylq-uc.a.run.app
108
+ .onLog(/.*Function URL.*?\((.*?)\(.*(https:\/\/.*?)$/, match => {
109
+ this.functions[match[1]] = match[2];
110
+ });
111
+ const debug = this.runtimeContext.runtimeParams.verbose ? ' --debug' : '';
112
+ await this.executeAsyncCommando(commando, `firebase${debug} deploy --only functions --force`, (stdout, stderr, exitCode) => {
113
+ if (exitCode === 0)
114
+ return;
115
+ throw new CommandoException(`Failed to deploy function with exit code ${exitCode}`, stdout, stderr, exitCode);
116
+ });
117
+ this.logInfo(`Functions: `, this.functions);
94
118
  }
95
119
  //######################### ResolveConfig Logic #########################
96
120
  getEnvConfig() {
@@ -118,7 +142,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
118
142
  }
119
143
  async resolveProxyFile() {
120
144
  const envConfig = this.getEnvConfig();
121
- const targetPath = `${this.config.fullPath}/src/main/proxy.ts`;
145
+ const targetPath = this.pathToProxy();
122
146
  const path = this.runtimeContext.baiConfig.files?.backend?.proxy;
123
147
  if (!path)
124
148
  return;
@@ -131,15 +155,13 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
131
155
  };
132
156
  await FileSystemUtils.file.template.copy(path, targetPath, params);
133
157
  }
158
+ pathToProxy() {
159
+ return resolve(this.config.fullPath, 'src/main/proxy.ts');
160
+ }
134
161
  async resolveConfigDir() {
135
162
  //Create the dir if it doesn't exist
136
163
  const pathToFirebaseConfigFolder = `${this.config.fullPath}/${this.config.pathToFirebaseConfig}`;
137
- try {
138
- await _fs.access(pathToFirebaseConfigFolder);
139
- }
140
- catch (e) {
141
- await _fs.mkdir(pathToFirebaseConfigFolder, { recursive: true });
142
- }
164
+ await FileSystemUtils.folder.create(pathToFirebaseConfigFolder);
143
165
  //Fill config dir with relevant files for each file that doesn't exist
144
166
  const defaultFiles = this.runtimeContext.baiConfig.files?.firebase;
145
167
  if (!defaultFiles) {
@@ -148,11 +170,10 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
148
170
  }
149
171
  await Promise.all(Const_FirebaseConfigKeys.map(async (firebaseConfigKey) => {
150
172
  const pathToConfigFile = `${pathToFirebaseConfigFolder}/${Const_FirebaseDefaultsKeyToFile[firebaseConfigKey]}`;
151
- const path = defaultFiles[firebaseConfigKey];
152
- if (!path)
173
+ if (!defaultFiles[firebaseConfigKey])
153
174
  return;
154
- const defaultFileContent = await _fs.readFile(path, { encoding: 'utf-8' });
155
- await _fs.writeFile(pathToConfigFile, defaultFileContent, { encoding: 'utf-8' });
175
+ const path = resolve(this.runtimeContext.parentUnit.config.fullPath, defaultFiles[firebaseConfigKey]);
176
+ await FileSystemUtils.file.copy(path, pathToConfigFile);
156
177
  }));
157
178
  }
158
179
  async resolveFunctionsJSON() {
@@ -205,6 +226,7 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
205
226
  functions: {
206
227
  source: this.config.output.replace(`${this.config.fullPath}/`, ''),
207
228
  ignore: this.config.ignore,
229
+ runtime: 'nodejs22',
208
230
  }
209
231
  };
210
232
  }
@@ -233,18 +255,14 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
233
255
  // await _fs.writeFile(targetPath, fileContent, {encoding: 'utf-8'});
234
256
  }
235
257
  deriveDistDependencies() {
236
- const unitKeys = this.runtimeContext.unitsMapper.getTransitiveDependencies([this.config.key]);
237
- const dependencyUnits = this.runtimeContext.unitsResolver(unitKeys, Unit_TypescriptLib);
238
- return dependencyUnits.reduce((dependencies, unit) => {
258
+ return this.dependencyUnits.reduce((dependencies, unit) => {
239
259
  dependencies[unit.config.key] = `file:.dependencies/${unit.config.key}`;
240
260
  return dependencies;
241
261
  }, super.deriveDistDependencies());
242
262
  }
243
263
  async createDependenciesDir() {
244
264
  //Gather units that are dependencies of this unit
245
- const unitKeys = this.runtimeContext.unitsMapper.getTransitiveDependencies([this.config.key]);
246
- const dependencyUnits = this.runtimeContext.unitsResolver(unitKeys, Unit_TypescriptLib);
247
- await Promise.all(dependencyUnits.map(async (unit) => {
265
+ await Promise.all(this.dependencyUnits.map(async (unit) => {
248
266
  //Copy dependency unit output into this units output/.dependency dir
249
267
  const dependencyOutputPath = `${unit.config.output}/`;
250
268
  const targetPath = `${this.config.output}/.dependencies/${unit.config.key}/`;
@@ -259,7 +277,8 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
259
277
  await this.resolveProxyFile();
260
278
  const commando = this.allocateCommando(Commando_NVM).applyNVM()
261
279
  .cd(this.config.fullPath);
262
- await this.executeAsyncCommando(commando, 'tsx src/main/proxy.ts');
280
+ const command = `${this.runtimeContext.parentUnit.config.fullPath}/${CONST_NodeModules}/.bin/tsx`;
281
+ await this.executeAsyncCommando(commando, `${command} src/main/proxy.ts`);
263
282
  this.logWarning('PROXY TERMINATED');
264
283
  }
265
284
  async runEmulator() {
@@ -278,4 +297,3 @@ export class Unit_FirebaseFunctionsApp extends Unit_TypescriptLib {
278
297
  this.logWarning('EMULATORS TERMINATED');
279
298
  }
280
299
  }
281
- //# sourceMappingURL=Unit_FirebaseFunctionsApp.js.map