@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.
- package/build-and-install-v3.d.ts +3 -0
- package/build-and-install-v3.js +27 -14
- package/build-and-install.js +0 -1
- package/core/consts.js +0 -1
- package/core/exceptions/PhaseAggregatedException.d.ts +5 -2
- package/core/exceptions/PhaseAggregatedException.js +18 -3
- package/core/exceptions/UnitPhaseException.d.ts +5 -0
- package/core/exceptions/UnitPhaseException.js +6 -0
- package/core/package/consts.js +0 -1
- package/core/params/params.d.ts +5 -5
- package/core/params/params.js +57 -29
- package/core/types/configs/firebasejson.js +0 -1
- package/core/types/configs/firebaserc.js +0 -1
- package/core/types/configs/index.js +0 -1
- package/core/types/configs/package-json.js +0 -1
- package/core/types/core.js +0 -1
- package/core/types/index.js +0 -1
- package/core/types/package/index.js +0 -1
- package/core/types/package/package.js +0 -1
- package/core/types/package/runtime-package.js +0 -1
- package/core/types/project-config.js +0 -1
- package/defaults/consts.js +0 -1
- package/old/PhaseRunnerDispatcher.js +0 -1
- package/old/runner-dispatchers.js +0 -1
- package/package.json +3 -3
- package/v3/PhaseManager.js +19 -5
- package/v3/RunningStatusHandler.d.ts +7 -5
- package/v3/RunningStatusHandler.js +21 -11
- package/v3/UnitsDependencyMapper/UnitsDependencyMapper.js +0 -1
- package/v3/UnitsMapper/UnitsMapper.js +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_Base.js +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.js +3 -2
- package/v3/UnitsMapper/resolvers/UnitMapper_Node.js +41 -35
- package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.js +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.js +0 -1
- package/v3/UnitsMapper/resolvers/index.js +0 -1
- package/v3/UnitsMapper/types.js +0 -1
- package/v3/core/FilesCache.js +0 -1
- package/v3/core/Unit_HelpPrinter.d.ts +1 -1
- package/v3/core/Unit_HelpPrinter.js +0 -1
- package/v3/core/types.js +0 -1
- package/v3/phase/consts.d.ts +1 -0
- package/v3/phase/consts.js +4 -1
- package/v3/phase/index.js +0 -1
- package/v3/phase/types.js +0 -1
- package/v3/units/BaseUnit.js +0 -1
- package/v3/units/ProjectUnit.js +0 -1
- package/v3/units/Unit_NodeProject.js +0 -1
- package/v3/units/Unit_PackageJson.js +0 -1
- package/v3/units/Unit_TypescriptLib.d.ts +1 -0
- package/v3/units/Unit_TypescriptLib.js +76 -36
- package/v3/units/firebase/Unit_FirebaseFunctionsApp.d.ts +5 -2
- package/v3/units/firebase/Unit_FirebaseFunctionsApp.js +47 -29
- package/v3/units/firebase/Unit_FirebaseHostingApp.d.ts +3 -2
- package/v3/units/firebase/Unit_FirebaseHostingApp.js +24 -6
- package/v3/units/firebase/common.d.ts +3 -0
- package/v3/units/firebase/common.js +13 -0
- package/v3/units/index.js +0 -1
- package/build-and-install-v3.js.map +0 -1
- package/build-and-install.js.map +0 -1
- package/core/consts.js.map +0 -1
- package/core/exceptions/PhaseAggregatedException.js.map +0 -1
- package/core/package/consts.js.map +0 -1
- package/core/params/params.js.map +0 -1
- package/core/types/configs/firebasejson.js.map +0 -1
- package/core/types/configs/firebaserc.js.map +0 -1
- package/core/types/configs/index.js.map +0 -1
- package/core/types/configs/package-json.js.map +0 -1
- package/core/types/core.js.map +0 -1
- package/core/types/index.js.map +0 -1
- package/core/types/package/index.js.map +0 -1
- package/core/types/package/package.js.map +0 -1
- package/core/types/package/runtime-package.js.map +0 -1
- package/core/types/project-config.js.map +0 -1
- package/defaults/consts.js.map +0 -1
- package/old/PhaseRunnerDispatcher.js.map +0 -1
- package/old/runner-dispatchers.js.map +0 -1
- package/v3/PhaseManager.js.map +0 -1
- package/v3/RunningStatusHandler.js.map +0 -1
- package/v3/UnitsDependencyMapper/UnitsDependencyMapper.js.map +0 -1
- package/v3/UnitsMapper/UnitsMapper.js.map +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_Base.js.map +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js.map +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.js.map +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_Node.js.map +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.js.map +0 -1
- package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.js.map +0 -1
- package/v3/UnitsMapper/resolvers/index.js.map +0 -1
- package/v3/UnitsMapper/types.js.map +0 -1
- package/v3/core/FilesCache.js.map +0 -1
- package/v3/core/Unit_HelpPrinter.js.map +0 -1
- package/v3/core/types.js.map +0 -1
- package/v3/phase/consts.js.map +0 -1
- package/v3/phase/index.js.map +0 -1
- package/v3/phase/types.js.map +0 -1
- package/v3/units/BaseUnit.js.map +0 -1
- package/v3/units/ProjectUnit.js.map +0 -1
- package/v3/units/Unit_NodeProject.js.map +0 -1
- package/v3/units/Unit_PackageJson.js.map +0 -1
- package/v3/units/Unit_TypescriptLib.js.map +0 -1
- package/v3/units/firebase/Unit_FirebaseFunctionsApp.js.map +0 -1
- package/v3/units/firebase/Unit_FirebaseHostingApp.js.map +0 -1
- package/v3/units/index.js.map +0 -1
|
@@ -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
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
package/v3/UnitsMapper/types.js
CHANGED
package/v3/core/FilesCache.js
CHANGED
|
@@ -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<"
|
|
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";
|
package/v3/core/types.js
CHANGED
package/v3/phase/consts.d.ts
CHANGED
|
@@ -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'>;
|
package/v3/phase/consts.js
CHANGED
|
@@ -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
package/v3/phase/types.js
CHANGED
package/v3/units/BaseUnit.js
CHANGED
package/v3/units/ProjectUnit.js
CHANGED
|
@@ -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,
|
|
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 ${
|
|
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,
|
|
387
|
-
|
|
388
|
-
if (
|
|
389
|
-
return
|
|
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 (!
|
|
401
|
+
if (!originImportPath.endsWith(extension))
|
|
392
402
|
continue;
|
|
393
|
-
|
|
403
|
+
originImportPath = originImportPath.replace(extension, '');
|
|
394
404
|
break;
|
|
395
405
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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+
|
|
445
|
+
regex: /from\s+"(\S+)?"/g,
|
|
425
446
|
replacer: async (pathTofile, importPath) => `from "${await toESM(pathTofile, importPath)}"`
|
|
426
447
|
},
|
|
427
448
|
{
|
|
428
|
-
regex: /
|
|
429
|
-
replacer: async (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:
|
|
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():
|
|
58
|
+
protected deriveDistDependencies(): StringMap;
|
|
56
59
|
private createDependenciesDir;
|
|
57
60
|
private runProxy;
|
|
58
61
|
private runEmulator;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
152
|
-
if (!path)
|
|
173
|
+
if (!defaultFiles[firebaseConfigKey])
|
|
153
174
|
return;
|
|
154
|
-
const
|
|
155
|
-
await
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|