@memberjunction/installer 0.0.1 → 5.6.0
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/dist/InstallerEngine.d.ts +182 -0
- package/dist/InstallerEngine.d.ts.map +1 -0
- package/dist/InstallerEngine.js +571 -0
- package/dist/InstallerEngine.js.map +1 -0
- package/dist/adapters/FileSystemAdapter.d.ts +197 -0
- package/dist/adapters/FileSystemAdapter.d.ts.map +1 -0
- package/dist/adapters/FileSystemAdapter.js +355 -0
- package/dist/adapters/FileSystemAdapter.js.map +1 -0
- package/dist/adapters/GitHubReleaseProvider.d.ts +197 -0
- package/dist/adapters/GitHubReleaseProvider.d.ts.map +1 -0
- package/dist/adapters/GitHubReleaseProvider.js +348 -0
- package/dist/adapters/GitHubReleaseProvider.js.map +1 -0
- package/dist/adapters/ProcessRunner.d.ts +174 -0
- package/dist/adapters/ProcessRunner.d.ts.map +1 -0
- package/dist/adapters/ProcessRunner.js +264 -0
- package/dist/adapters/ProcessRunner.js.map +1 -0
- package/dist/adapters/SqlServerAdapter.d.ts +78 -0
- package/dist/adapters/SqlServerAdapter.d.ts.map +1 -0
- package/dist/adapters/SqlServerAdapter.js +120 -0
- package/dist/adapters/SqlServerAdapter.js.map +1 -0
- package/dist/errors/InstallerError.d.ts +92 -0
- package/dist/errors/InstallerError.d.ts.map +1 -0
- package/dist/errors/InstallerError.js +66 -0
- package/dist/errors/InstallerError.js.map +1 -0
- package/dist/events/InstallerEvents.d.ts +255 -0
- package/dist/events/InstallerEvents.d.ts.map +1 -0
- package/dist/events/InstallerEvents.js +96 -0
- package/dist/events/InstallerEvents.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/models/Diagnostics.d.ts +121 -0
- package/dist/models/Diagnostics.d.ts.map +1 -0
- package/dist/models/Diagnostics.js +75 -0
- package/dist/models/Diagnostics.js.map +1 -0
- package/dist/models/InstallConfig.d.ts +139 -0
- package/dist/models/InstallConfig.d.ts.map +1 -0
- package/dist/models/InstallConfig.js +207 -0
- package/dist/models/InstallConfig.js.map +1 -0
- package/dist/models/InstallPlan.d.ts +189 -0
- package/dist/models/InstallPlan.d.ts.map +1 -0
- package/dist/models/InstallPlan.js +117 -0
- package/dist/models/InstallPlan.js.map +1 -0
- package/dist/models/InstallState.d.ts +173 -0
- package/dist/models/InstallState.d.ts.map +1 -0
- package/dist/models/InstallState.js +203 -0
- package/dist/models/InstallState.js.map +1 -0
- package/dist/models/VersionInfo.d.ts +53 -0
- package/dist/models/VersionInfo.d.ts.map +1 -0
- package/dist/models/VersionInfo.js +2 -0
- package/dist/models/VersionInfo.js.map +1 -0
- package/dist/phases/CodeGenPhase.d.ts +364 -0
- package/dist/phases/CodeGenPhase.d.ts.map +1 -0
- package/dist/phases/CodeGenPhase.js +1086 -0
- package/dist/phases/CodeGenPhase.js.map +1 -0
- package/dist/phases/ConfigurePhase.d.ts +86 -0
- package/dist/phases/ConfigurePhase.d.ts.map +1 -0
- package/dist/phases/ConfigurePhase.js +439 -0
- package/dist/phases/ConfigurePhase.js.map +1 -0
- package/dist/phases/DatabaseProvisionPhase.d.ts +82 -0
- package/dist/phases/DatabaseProvisionPhase.d.ts.map +1 -0
- package/dist/phases/DatabaseProvisionPhase.js +284 -0
- package/dist/phases/DatabaseProvisionPhase.js.map +1 -0
- package/dist/phases/DependencyPhase.d.ts +88 -0
- package/dist/phases/DependencyPhase.d.ts.map +1 -0
- package/dist/phases/DependencyPhase.js +237 -0
- package/dist/phases/DependencyPhase.js.map +1 -0
- package/dist/phases/MigratePhase.d.ts +70 -0
- package/dist/phases/MigratePhase.d.ts.map +1 -0
- package/dist/phases/MigratePhase.js +96 -0
- package/dist/phases/MigratePhase.js.map +1 -0
- package/dist/phases/PlatformCompatPhase.d.ts +193 -0
- package/dist/phases/PlatformCompatPhase.d.ts.map +1 -0
- package/dist/phases/PlatformCompatPhase.js +587 -0
- package/dist/phases/PlatformCompatPhase.js.map +1 -0
- package/dist/phases/PreflightPhase.d.ts +119 -0
- package/dist/phases/PreflightPhase.d.ts.map +1 -0
- package/dist/phases/PreflightPhase.js +394 -0
- package/dist/phases/PreflightPhase.js.map +1 -0
- package/dist/phases/ScaffoldPhase.d.ts +99 -0
- package/dist/phases/ScaffoldPhase.d.ts.map +1 -0
- package/dist/phases/ScaffoldPhase.js +235 -0
- package/dist/phases/ScaffoldPhase.js.map +1 -0
- package/dist/phases/SmokeTestPhase.d.ts +111 -0
- package/dist/phases/SmokeTestPhase.d.ts.map +1 -0
- package/dist/phases/SmokeTestPhase.js +426 -0
- package/dist/phases/SmokeTestPhase.js.map +1 -0
- package/package.json +26 -7
- package/README.md +0 -45
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase G — Dependencies (Install + Build)
|
|
3
|
+
*
|
|
4
|
+
* Runs `npm install` at the repo root to install all workspace dependencies,
|
|
5
|
+
* then `npm run build` to compile all ~170 packages in the monorepo.
|
|
6
|
+
*
|
|
7
|
+
* Key behaviors:
|
|
8
|
+
* - **ERESOLVE retry**: If `npm install` fails with peer dependency conflicts,
|
|
9
|
+
* automatically retries with `--legacy-peer-deps`.
|
|
10
|
+
* - **Partial build tolerance**: Build failures in codegen-managed packages
|
|
11
|
+
* (entity forms, bootstrap) are treated as partial success since CodeGen
|
|
12
|
+
* will regenerate their source and rebuild in a later phase.
|
|
13
|
+
* - **Audit warnings**: npm vulnerability reports are logged as informational
|
|
14
|
+
* warnings — users are explicitly told NOT to run `npm audit fix --force`.
|
|
15
|
+
*
|
|
16
|
+
* @module phases/DependencyPhase
|
|
17
|
+
* @see CodeGenPhase — handles rebuilding codegen-managed packages after code generation.
|
|
18
|
+
* @see PlatformCompatPhase — patches scripts before this phase runs.
|
|
19
|
+
*/
|
|
20
|
+
import { InstallerError } from '../errors/InstallerError.js';
|
|
21
|
+
import { ProcessRunner } from '../adapters/ProcessRunner.js';
|
|
22
|
+
/**
|
|
23
|
+
* Packages that contain generated code managed by CodeGen.
|
|
24
|
+
*
|
|
25
|
+
* Build failures in **only** these packages are treated as partial success.
|
|
26
|
+
* CodeGen will regenerate their stale source code and rebuild them in the
|
|
27
|
+
* codegen phase. If any package outside this list fails, the build is a
|
|
28
|
+
* hard error.
|
|
29
|
+
*/
|
|
30
|
+
const CODEGEN_MANAGED_PACKAGES = [
|
|
31
|
+
'ng-core-entity-forms',
|
|
32
|
+
'server-bootstrap-lite',
|
|
33
|
+
'server-bootstrap',
|
|
34
|
+
'ng-bootstrap',
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Phase G — Installs npm dependencies and builds all workspace packages.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const deps = new DependencyPhase();
|
|
42
|
+
* const result = await deps.Run({ Dir: '/path/to/install', Emitter: emitter });
|
|
43
|
+
* if (result.BuildPartial) {
|
|
44
|
+
* console.log('Partial build — CodeGen will fix remaining packages');
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export class DependencyPhase {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.processRunner = new ProcessRunner();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Execute the dependency phase: `npm install` then `npm run build`.
|
|
54
|
+
*
|
|
55
|
+
* @param context - Dependency input with directory and emitter.
|
|
56
|
+
* @returns Install/build status and collected warnings.
|
|
57
|
+
* @throws {InstallerError} With code `NPM_INSTALL_FAILED` or `NPM_INSTALL_TIMEOUT` on install failure.
|
|
58
|
+
* @throws {InstallerError} With code `BUILD_FAILED` or `BUILD_TIMEOUT` on non-codegen build failure.
|
|
59
|
+
*/
|
|
60
|
+
async Run(context) {
|
|
61
|
+
const { Emitter: emitter } = context;
|
|
62
|
+
const warnings = [];
|
|
63
|
+
// Step 1: npm install
|
|
64
|
+
await this.runNpmInstall(context.Dir, emitter, warnings);
|
|
65
|
+
// Step 2: npm run build
|
|
66
|
+
const buildPartial = await this.runNpmBuild(context.Dir, emitter, warnings);
|
|
67
|
+
return {
|
|
68
|
+
InstallSuccess: true,
|
|
69
|
+
BuildSuccess: !buildPartial,
|
|
70
|
+
BuildPartial: buildPartial,
|
|
71
|
+
Warnings: warnings,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// npm install
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
async runNpmInstall(dir, emitter, warnings) {
|
|
78
|
+
emitter.Emit('step:progress', {
|
|
79
|
+
Type: 'step:progress',
|
|
80
|
+
Phase: 'dependencies',
|
|
81
|
+
Message: 'Running npm install (this may take several minutes)...',
|
|
82
|
+
});
|
|
83
|
+
let result = await this.runNpmInstallOnce(dir, emitter, []);
|
|
84
|
+
if (result.TimedOut) {
|
|
85
|
+
throw new InstallerError('dependencies', 'NPM_INSTALL_TIMEOUT', 'npm install timed out after 10 minutes.', 'Run "npm install" manually at the repo root. Check network connectivity.');
|
|
86
|
+
}
|
|
87
|
+
// If npm install failed due to peer dependency conflicts, retry with --legacy-peer-deps
|
|
88
|
+
if (result.ExitCode !== 0 && this.isEresolveError(result.Stderr)) {
|
|
89
|
+
emitter.Emit('warn', {
|
|
90
|
+
Type: 'warn',
|
|
91
|
+
Phase: 'dependencies',
|
|
92
|
+
Message: 'Peer dependency conflict detected. Retrying with --legacy-peer-deps...',
|
|
93
|
+
});
|
|
94
|
+
result = await this.runNpmInstallOnce(dir, emitter, ['--legacy-peer-deps']);
|
|
95
|
+
if (result.TimedOut) {
|
|
96
|
+
throw new InstallerError('dependencies', 'NPM_INSTALL_TIMEOUT', 'npm install --legacy-peer-deps timed out after 10 minutes.', 'Run "npm install --legacy-peer-deps" manually at the repo root.');
|
|
97
|
+
}
|
|
98
|
+
if (result.ExitCode === 0) {
|
|
99
|
+
warnings.push('npm install required --legacy-peer-deps due to peer dependency conflicts in the release. ' +
|
|
100
|
+
'This is safe but indicates a minor version skew in the release packages.');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (result.ExitCode !== 0) {
|
|
104
|
+
const lastLines = this.lastNLines(result.Stderr || result.Stdout, 50);
|
|
105
|
+
throw new InstallerError('dependencies', 'NPM_INSTALL_FAILED', `npm install failed (exit code ${result.ExitCode}):\n${lastLines}`, 'Run "npm install" manually at the repo root to see full error output.');
|
|
106
|
+
}
|
|
107
|
+
// Check for audit vulnerabilities (informational only)
|
|
108
|
+
if (result.Stderr.includes('vulnerabilit')) {
|
|
109
|
+
warnings.push('npm reports vulnerabilities in dependencies. This is common in large workspaces. ' +
|
|
110
|
+
'Do NOT run "npm audit fix --force" — it can break the workspace.');
|
|
111
|
+
emitter.Emit('warn', {
|
|
112
|
+
Type: 'warn',
|
|
113
|
+
Phase: 'dependencies',
|
|
114
|
+
Message: 'npm reports dependency vulnerabilities (informational). Do not run "npm audit fix --force".',
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
emitter.Emit('log', {
|
|
118
|
+
Type: 'log',
|
|
119
|
+
Level: 'info',
|
|
120
|
+
Message: 'npm install completed successfully.',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// npm run build
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
/**
|
|
127
|
+
* Runs npm run build. Returns true if the build was "partial" (only codegen-managed
|
|
128
|
+
* packages failed), false if it fully succeeded. Throws on hard failures.
|
|
129
|
+
*/
|
|
130
|
+
async runNpmBuild(dir, emitter, warnings) {
|
|
131
|
+
emitter.Emit('step:progress', {
|
|
132
|
+
Type: 'step:progress',
|
|
133
|
+
Phase: 'dependencies',
|
|
134
|
+
Message: 'Running npm run build (first-time builds can take 15-20 minutes for 170 packages)...',
|
|
135
|
+
});
|
|
136
|
+
const result = await this.processRunner.Run('npm', ['run', 'build'], {
|
|
137
|
+
Cwd: dir,
|
|
138
|
+
TimeoutMs: 1_800_000, // 30 minutes — first-time full workspace build of 170 packages can take 17+ min
|
|
139
|
+
OnStdout: (line) => {
|
|
140
|
+
emitter.Emit('step:progress', {
|
|
141
|
+
Type: 'step:progress',
|
|
142
|
+
Phase: 'dependencies',
|
|
143
|
+
Message: line.trim(),
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
OnStderr: (line) => {
|
|
147
|
+
emitter.Emit('log', {
|
|
148
|
+
Type: 'log',
|
|
149
|
+
Level: 'verbose',
|
|
150
|
+
Message: `[build:stderr] ${line.trim()}`,
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
if (result.TimedOut) {
|
|
155
|
+
throw new InstallerError('dependencies', 'BUILD_TIMEOUT', 'npm run build timed out after 30 minutes.', 'Run "npm run build" manually at the repo root to see full output. First-time builds of 170 packages can take 15-20 minutes.');
|
|
156
|
+
}
|
|
157
|
+
if (result.ExitCode === 0) {
|
|
158
|
+
emitter.Emit('log', {
|
|
159
|
+
Type: 'log',
|
|
160
|
+
Level: 'info',
|
|
161
|
+
Message: 'Build completed successfully.',
|
|
162
|
+
});
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
// Build failed — check if failures are only in codegen-managed packages.
|
|
166
|
+
// These packages contain generated code that may be stale in the release.
|
|
167
|
+
// CodeGen will regenerate them and rebuild in a later phase.
|
|
168
|
+
// Note: turbo outputs the "Failed:" summary to stdout, not stderr.
|
|
169
|
+
const combinedOutput = result.Stdout + '\n' + result.Stderr;
|
|
170
|
+
const failedPackages = this.extractFailedTurboPackages(combinedOutput);
|
|
171
|
+
const onlyCodegenFailures = failedPackages.length > 0
|
|
172
|
+
&& failedPackages.every(pkg => CODEGEN_MANAGED_PACKAGES.some(pattern => pkg.includes(pattern)));
|
|
173
|
+
if (onlyCodegenFailures) {
|
|
174
|
+
const failList = failedPackages.join(', ');
|
|
175
|
+
emitter.Emit('warn', {
|
|
176
|
+
Type: 'warn',
|
|
177
|
+
Phase: 'dependencies',
|
|
178
|
+
Message: `Build partially succeeded. Failed packages (${failList}) contain generated code that will be regenerated by CodeGen.`,
|
|
179
|
+
});
|
|
180
|
+
warnings.push(`Build partially succeeded. The following packages failed due to stale generated code and will be fixed by CodeGen: ${failList}`);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
// Non-codegen failures — hard error
|
|
184
|
+
const lastLines = this.lastNLines(result.Stderr || result.Stdout, 50);
|
|
185
|
+
throw new InstallerError('dependencies', 'BUILD_FAILED', `Build failed (exit code ${result.ExitCode}):\n${lastLines}`, 'Run "npm run build" manually at the repo root to see full error output.');
|
|
186
|
+
}
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// Turbo output parsing
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
/**
|
|
191
|
+
* Extract failed package names from turbo's stderr output.
|
|
192
|
+
* Turbo outputs lines like: "Failed: @memberjunction/ng-core-entity-forms#build"
|
|
193
|
+
*/
|
|
194
|
+
extractFailedTurboPackages(stderr) {
|
|
195
|
+
const packages = [];
|
|
196
|
+
const failedPattern = /Failed:\s+(@[^#\s]+)#build/g;
|
|
197
|
+
let match;
|
|
198
|
+
while ((match = failedPattern.exec(stderr)) !== null) {
|
|
199
|
+
packages.push(match[1]);
|
|
200
|
+
}
|
|
201
|
+
return [...new Set(packages)];
|
|
202
|
+
}
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Helpers
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
async runNpmInstallOnce(dir, emitter, extraArgs) {
|
|
207
|
+
const args = ['install', ...extraArgs];
|
|
208
|
+
return this.processRunner.Run('npm', args, {
|
|
209
|
+
Cwd: dir,
|
|
210
|
+
TimeoutMs: 600_000, // 10 minutes
|
|
211
|
+
OnStdout: (line) => {
|
|
212
|
+
emitter.Emit('step:progress', {
|
|
213
|
+
Type: 'step:progress',
|
|
214
|
+
Phase: 'dependencies',
|
|
215
|
+
Message: line.trim(),
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
OnStderr: (line) => {
|
|
219
|
+
if (line.includes('WARN') || line.includes('warn')) {
|
|
220
|
+
emitter.Emit('log', {
|
|
221
|
+
Type: 'log',
|
|
222
|
+
Level: 'verbose',
|
|
223
|
+
Message: `[npm] ${line.trim()}`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
isEresolveError(stderr) {
|
|
230
|
+
return stderr.includes('ERESOLVE') || stderr.includes('unable to resolve dependency tree');
|
|
231
|
+
}
|
|
232
|
+
lastNLines(text, n) {
|
|
233
|
+
const lines = text.split('\n');
|
|
234
|
+
return lines.slice(-n).join('\n');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=DependencyPhase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependencyPhase.js","sourceRoot":"","sources":["../../src/phases/DependencyPhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAsB,MAAM,8BAA8B,CAAC;AAEjF;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG;IAC/B,sBAAsB;IACtB,uBAAuB;IACvB,kBAAkB;IAClB,cAAc;CACf,CAAC;AAiCF;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,eAAe;IAA5B;QACU,kBAAa,GAAG,IAAI,aAAa,EAAE,CAAC;IA6P9C,CAAC;IA3PC;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,OAA0B;QAClC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QACrC,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,sBAAsB;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EA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CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase D — Database Migrations
|
|
3
|
+
*
|
|
4
|
+
* Runs database migrations via `npx mj migrate --verbose`, which invokes
|
|
5
|
+
* node-flyway under the hood to apply pending SQL migration scripts from
|
|
6
|
+
* the `migrations/` directory.
|
|
7
|
+
*
|
|
8
|
+
* The migration command reads database connection settings from the `.env`
|
|
9
|
+
* file generated by the configure phase. It applies all pending migrations
|
|
10
|
+
* in version order, creating the `__mj` schema tables, stored procedures,
|
|
11
|
+
* views, and seed data that MemberJunction requires.
|
|
12
|
+
*
|
|
13
|
+
* @module phases/MigratePhase
|
|
14
|
+
* @see ConfigurePhase — generates the `.env` file with database credentials.
|
|
15
|
+
* @see DatabaseProvisionPhase — creates the database and SQL logins used by migrations.
|
|
16
|
+
*/
|
|
17
|
+
import type { InstallerEventEmitter } from '../events/InstallerEvents.js';
|
|
18
|
+
import type { PartialInstallConfig } from '../models/InstallConfig.js';
|
|
19
|
+
/**
|
|
20
|
+
* Input context for the migrate phase.
|
|
21
|
+
*
|
|
22
|
+
* @see MigratePhase.Run
|
|
23
|
+
*/
|
|
24
|
+
export interface MigrateContext {
|
|
25
|
+
/** Absolute path to the repo root (where `npx mj migrate` is executed). */
|
|
26
|
+
Dir: string;
|
|
27
|
+
/** Current install config (used for diagnostic context, not directly by migrations). */
|
|
28
|
+
Config: PartialInstallConfig;
|
|
29
|
+
/** Event emitter for progress and log events. */
|
|
30
|
+
Emitter: InstallerEventEmitter;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of the migrate phase.
|
|
34
|
+
*
|
|
35
|
+
* @see MigratePhase.Run
|
|
36
|
+
*/
|
|
37
|
+
export interface MigrateResult {
|
|
38
|
+
/** Whether all migrations completed successfully. */
|
|
39
|
+
Success: boolean;
|
|
40
|
+
/** Raw stdout output from the `npx mj migrate` command. */
|
|
41
|
+
Output: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Phase D — Runs database migrations via `npx mj migrate`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const migrate = new MigratePhase();
|
|
49
|
+
* const result = await migrate.Run({
|
|
50
|
+
* Dir: '/path/to/install',
|
|
51
|
+
* Config: { DatabaseHost: 'localhost' },
|
|
52
|
+
* Emitter: emitter,
|
|
53
|
+
* });
|
|
54
|
+
* console.log(result.Success ? 'Migrations applied' : 'Migration failed');
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class MigratePhase {
|
|
58
|
+
private processRunner;
|
|
59
|
+
/**
|
|
60
|
+
* Execute database migrations.
|
|
61
|
+
*
|
|
62
|
+
* @param context - Migrate input with directory, config, and emitter.
|
|
63
|
+
* @returns Migration result with success status and raw output.
|
|
64
|
+
* @throws {InstallerError} With code `MIGRATE_TIMEOUT` if migrations exceed 5 minutes.
|
|
65
|
+
* @throws {InstallerError} With code `MIGRATE_FAILED` if the migration command exits non-zero.
|
|
66
|
+
*/
|
|
67
|
+
Run(context: MigrateContext): Promise<MigrateResult>;
|
|
68
|
+
private lastNLines;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=MigratePhase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigratePhase.d.ts","sourceRoot":"","sources":["../../src/phases/MigratePhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAIvE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,wFAAwF;IACxF,MAAM,EAAE,oBAAoB,CAAC;IAC7B,iDAAiD;IACjD,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAAuB;IAE5C;;;;;;;OAOG;IACG,GAAG,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA+D1D,OAAO,CAAC,UAAU;CAInB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase D — Database Migrations
|
|
3
|
+
*
|
|
4
|
+
* Runs database migrations via `npx mj migrate --verbose`, which invokes
|
|
5
|
+
* node-flyway under the hood to apply pending SQL migration scripts from
|
|
6
|
+
* the `migrations/` directory.
|
|
7
|
+
*
|
|
8
|
+
* The migration command reads database connection settings from the `.env`
|
|
9
|
+
* file generated by the configure phase. It applies all pending migrations
|
|
10
|
+
* in version order, creating the `__mj` schema tables, stored procedures,
|
|
11
|
+
* views, and seed data that MemberJunction requires.
|
|
12
|
+
*
|
|
13
|
+
* @module phases/MigratePhase
|
|
14
|
+
* @see ConfigurePhase — generates the `.env` file with database credentials.
|
|
15
|
+
* @see DatabaseProvisionPhase — creates the database and SQL logins used by migrations.
|
|
16
|
+
*/
|
|
17
|
+
import { InstallerError } from '../errors/InstallerError.js';
|
|
18
|
+
import { ProcessRunner } from '../adapters/ProcessRunner.js';
|
|
19
|
+
/**
|
|
20
|
+
* Phase D — Runs database migrations via `npx mj migrate`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const migrate = new MigratePhase();
|
|
25
|
+
* const result = await migrate.Run({
|
|
26
|
+
* Dir: '/path/to/install',
|
|
27
|
+
* Config: { DatabaseHost: 'localhost' },
|
|
28
|
+
* Emitter: emitter,
|
|
29
|
+
* });
|
|
30
|
+
* console.log(result.Success ? 'Migrations applied' : 'Migration failed');
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class MigratePhase {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.processRunner = new ProcessRunner();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Execute database migrations.
|
|
39
|
+
*
|
|
40
|
+
* @param context - Migrate input with directory, config, and emitter.
|
|
41
|
+
* @returns Migration result with success status and raw output.
|
|
42
|
+
* @throws {InstallerError} With code `MIGRATE_TIMEOUT` if migrations exceed 5 minutes.
|
|
43
|
+
* @throws {InstallerError} With code `MIGRATE_FAILED` if the migration command exits non-zero.
|
|
44
|
+
*/
|
|
45
|
+
async Run(context) {
|
|
46
|
+
const { Emitter: emitter } = context;
|
|
47
|
+
emitter.Emit('step:progress', {
|
|
48
|
+
Type: 'step:progress',
|
|
49
|
+
Phase: 'migrate',
|
|
50
|
+
Message: 'Running database migrations...',
|
|
51
|
+
});
|
|
52
|
+
// Use npx mj migrate to run Flyway-based migrations
|
|
53
|
+
// Always pass --verbose so we get detailed Flyway output for diagnostics
|
|
54
|
+
const result = await this.processRunner.Run('npx', ['mj', 'migrate', '--verbose'], {
|
|
55
|
+
Cwd: context.Dir,
|
|
56
|
+
TimeoutMs: 300_000, // 5 minutes
|
|
57
|
+
OnStdout: (line) => {
|
|
58
|
+
emitter.Emit('step:progress', {
|
|
59
|
+
Type: 'step:progress',
|
|
60
|
+
Phase: 'migrate',
|
|
61
|
+
Message: line.trim(),
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
OnStderr: (line) => {
|
|
65
|
+
emitter.Emit('log', {
|
|
66
|
+
Type: 'log',
|
|
67
|
+
Level: 'verbose',
|
|
68
|
+
Message: `[migrate:stderr] ${line.trim()}`,
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (result.TimedOut) {
|
|
73
|
+
throw new InstallerError('migrate', 'MIGRATE_TIMEOUT', 'Database migration timed out after 5 minutes.', 'Run "mj migrate" manually to see detailed output. Check database connectivity.');
|
|
74
|
+
}
|
|
75
|
+
if (result.ExitCode !== 0) {
|
|
76
|
+
// Combine stdout and stderr for full diagnostic output — Flyway errors go to stderr
|
|
77
|
+
const combined = [result.Stdout, result.Stderr].filter(Boolean).join('\n');
|
|
78
|
+
const lastLines = this.lastNLines(combined, 80);
|
|
79
|
+
throw new InstallerError('migrate', 'MIGRATE_FAILED', `Database migration failed (exit code ${result.ExitCode}):\n${lastLines}`, 'Check the migration output above. Common issues: database connectivity, incorrect credentials, or SQL syntax errors.');
|
|
80
|
+
}
|
|
81
|
+
emitter.Emit('log', {
|
|
82
|
+
Type: 'log',
|
|
83
|
+
Level: 'info',
|
|
84
|
+
Message: 'Database migrations completed successfully.',
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
Success: true,
|
|
88
|
+
Output: result.Stdout,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
lastNLines(text, n) {
|
|
92
|
+
const lines = text.split('\n');
|
|
93
|
+
return lines.slice(-n).join('\n');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=MigratePhase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigratePhase.js","sourceRoot":"","sources":["../../src/phases/MigratePhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AA4B7D;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAY;IAAzB;QACU,kBAAa,GAAG,IAAI,aAAa,EAAE,CAAC;IA6E9C,CAAC;IA3EC;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,OAAuB;QAC/B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAErC,OAAO,CAAC,IAAI,CAAC,eAA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MAAM,IAAI,cAAc,CACtB,SAAS,EACT,gBAAgB,EAChB,wCAAwC,MAAM,CAAC,QAAQ,OAAO,SAAS,EAAE,EACzE,sHAAsH,CACvH,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE;YAClB,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,6CAA6C;SACvD,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;IAEO,UAAU,CAAC,IAAY,EAAE,CAAS;QACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase F — Platform Compatibility
|
|
3
|
+
*
|
|
4
|
+
* Detects and fixes cross-platform issues in npm scripts that would
|
|
5
|
+
* prevent the MemberJunction workspace from building or running on Windows.
|
|
6
|
+
*
|
|
7
|
+
* **F1: Cross-platform script patching** (Windows only):
|
|
8
|
+
* - **Unix env vars** (`FOO=bar command`) — prefixed with `cross-env`.
|
|
9
|
+
* - **Bash conditionals** (`if [ -d dir ]; then ...`) — rewritten to
|
|
10
|
+
* `node -e` equivalents that work in `cmd.exe`.
|
|
11
|
+
* - **Single-quoted globs** (`'src/**'`) — replaced with double quotes
|
|
12
|
+
* (single quotes are literal in `cmd.exe`, breaking glob expansion).
|
|
13
|
+
*
|
|
14
|
+
* On non-Windows platforms, these issues are only warned about (not patched).
|
|
15
|
+
*
|
|
16
|
+
* **F2: Heap size advisory** (Node >= 24):
|
|
17
|
+
* - Informs users that `--max-old-space-size` flags may no longer be needed
|
|
18
|
+
* since Node 24+ has improved memory management.
|
|
19
|
+
*
|
|
20
|
+
* **F3: TypeScript build hygiene** (all platforms):
|
|
21
|
+
* - Ensures `tsconfig.json` files exclude test directories (`__tests__`,
|
|
22
|
+
* `*.test.ts`, `*.spec.ts`) so that test-only compilation errors don't
|
|
23
|
+
* block production builds. This fixes a known issue where release packages
|
|
24
|
+
* ship test files referencing features from a newer version.
|
|
25
|
+
*
|
|
26
|
+
* **F4: Stale entity file cleanup** (all platforms):
|
|
27
|
+
* - Removes old-name entity files from `MJCoreEntities/src/custom/` that
|
|
28
|
+
* were superseded by MJ-prefixed versions during the 5.x entity rename.
|
|
29
|
+
* The published packages may ship both old and new files (e.g.,
|
|
30
|
+
* `UserViewEntity.ts` alongside `MJUserViewEntityExtended.ts`). The old
|
|
31
|
+
* files cause build errors (private property type conflicts) and runtime
|
|
32
|
+
* issues (duplicate `@RegisterClass` registrations).
|
|
33
|
+
*
|
|
34
|
+
* @module phases/PlatformCompatPhase
|
|
35
|
+
* @see PreflightPhase — provides the detected OS used for conditional patching.
|
|
36
|
+
*/
|
|
37
|
+
import type { InstallerEventEmitter } from '../events/InstallerEvents.js';
|
|
38
|
+
/**
|
|
39
|
+
* Input context for the platform compatibility phase.
|
|
40
|
+
*
|
|
41
|
+
* @see PlatformCompatPhase.Run
|
|
42
|
+
*/
|
|
43
|
+
export interface PlatformCompatContext {
|
|
44
|
+
/** Absolute path to the repo root. */
|
|
45
|
+
Dir: string;
|
|
46
|
+
/** Detected operating system from the preflight phase. */
|
|
47
|
+
DetectedOS: 'windows' | 'macos' | 'linux' | 'other';
|
|
48
|
+
/** Event emitter for progress, warn, and log events. */
|
|
49
|
+
Emitter: InstallerEventEmitter;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Result of the platform compatibility phase.
|
|
53
|
+
*
|
|
54
|
+
* @see PlatformCompatPhase.Run
|
|
55
|
+
*/
|
|
56
|
+
export interface PlatformCompatResult {
|
|
57
|
+
/** Absolute paths of `package.json` files that had scripts patched. */
|
|
58
|
+
ScriptsPatched: string[];
|
|
59
|
+
/** Whether `cross-env` was added as a dependency to any package. */
|
|
60
|
+
CrossEnvNeeded: boolean;
|
|
61
|
+
/** Number of `tsconfig.json` files patched to exclude test files from compilation. */
|
|
62
|
+
TsconfigsPatched: number;
|
|
63
|
+
/** Number of stale pre-MJ-prefix entity files removed from MJCoreEntities. */
|
|
64
|
+
StaleFilesRemoved: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Phase F — Detects and patches cross-platform incompatibilities in npm scripts.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const platform = new PlatformCompatPhase();
|
|
72
|
+
* const result = await platform.Run({
|
|
73
|
+
* Dir: '/path/to/install',
|
|
74
|
+
* DetectedOS: 'windows',
|
|
75
|
+
* Emitter: emitter,
|
|
76
|
+
* });
|
|
77
|
+
* console.log(`Patched ${result.ScriptsPatched.length} file(s)`);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare class PlatformCompatPhase {
|
|
81
|
+
private fileSystem;
|
|
82
|
+
/**
|
|
83
|
+
* Execute the platform compatibility phase.
|
|
84
|
+
*
|
|
85
|
+
* Scans all `package.json` files in the workspace for platform-specific
|
|
86
|
+
* script issues and patches them on Windows. Also emits a heap size
|
|
87
|
+
* advisory for Node >= 24.
|
|
88
|
+
*
|
|
89
|
+
* @param context - Platform compat input with directory, detected OS, and emitter.
|
|
90
|
+
* @returns List of patched files and whether cross-env was added.
|
|
91
|
+
*/
|
|
92
|
+
Run(context: PlatformCompatContext): Promise<PlatformCompatResult>;
|
|
93
|
+
private checkAndPatchPackageJson;
|
|
94
|
+
private hasUnixEnvSyntax;
|
|
95
|
+
private hasBashConditionalSyntax;
|
|
96
|
+
private hasSingleQuotedGlobs;
|
|
97
|
+
/**
|
|
98
|
+
* Replaces single-quoted file path/glob arguments with double-quoted equivalents.
|
|
99
|
+
* e.g. cpy 'src/lib/styles/**' → cpy "src/lib/styles/**"
|
|
100
|
+
*
|
|
101
|
+
* Only replaces single-quoted args containing `/` or `*` (file paths and globs).
|
|
102
|
+
* As a safety net, `node -e "..."` and `node -p "..."` embedded code blocks are
|
|
103
|
+
* preserved verbatim — single quotes inside those are JS string delimiters that
|
|
104
|
+
* must not be converted to double quotes.
|
|
105
|
+
*/
|
|
106
|
+
private replaceSingleQuotes;
|
|
107
|
+
/**
|
|
108
|
+
* Regex matching `node -e "..."` or `node -p "..."` inline code blocks.
|
|
109
|
+
* Captures the entire block so we can exclude it from single-quote replacement.
|
|
110
|
+
*/
|
|
111
|
+
private static readonly NODE_EVAL_PATTERN;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the script with all `node -e "..."` / `node -p "..."` blocks removed,
|
|
114
|
+
* so callers can test the remaining text for patterns without false positives
|
|
115
|
+
* from embedded JS code.
|
|
116
|
+
*/
|
|
117
|
+
private stripEmbeddedNodeCode;
|
|
118
|
+
/**
|
|
119
|
+
* Applies `transform` to every part of `script` that is NOT inside a
|
|
120
|
+
* `node -e "..."` or `node -p "..."` block, preserving those blocks verbatim.
|
|
121
|
+
*/
|
|
122
|
+
private withEmbeddedNodeCodePreserved;
|
|
123
|
+
/**
|
|
124
|
+
* Rewrites bash conditional scripts to cross-platform Node.js equivalents.
|
|
125
|
+
*
|
|
126
|
+
* Strategy: replace the entire script with a single `node -e` that performs
|
|
127
|
+
* the condition check and branch logic inline, then chains the actual commands
|
|
128
|
+
* with && / ||. This avoids nested quoting issues.
|
|
129
|
+
*
|
|
130
|
+
* Returns null if the script can't be auto-rewritten.
|
|
131
|
+
*/
|
|
132
|
+
private rewriteBashConditional;
|
|
133
|
+
/**
|
|
134
|
+
* Rewrites bash-only commands within a command chain to cross-platform equivalents.
|
|
135
|
+
* Replaces: `touch FILE`, `rm FILE`
|
|
136
|
+
* Leaves other commands (npm, mj, tsc, echo, etc.) unchanged.
|
|
137
|
+
* Handles `&&` chains and `||` fallbacks.
|
|
138
|
+
*/
|
|
139
|
+
private rewriteBashCommands;
|
|
140
|
+
/**
|
|
141
|
+
* Standard test-file exclusion patterns added to tsconfig `exclude` arrays.
|
|
142
|
+
* These ensure that `tsc` doesn't compile test files during production builds.
|
|
143
|
+
* Vitest handles its own compilation via its config, so tests still run fine.
|
|
144
|
+
*/
|
|
145
|
+
private static readonly TEST_EXCLUDE_PATTERNS;
|
|
146
|
+
/**
|
|
147
|
+
* Scans all `tsconfig.json` files under `packages/` and adds test-file
|
|
148
|
+
* exclusion patterns where missing. This prevents test files that reference
|
|
149
|
+
* newer or unreleased APIs from breaking the production build.
|
|
150
|
+
*
|
|
151
|
+
* @returns Number of tsconfig files that were patched.
|
|
152
|
+
*/
|
|
153
|
+
private ensureTsconfigTestExclusions;
|
|
154
|
+
/**
|
|
155
|
+
* Patches a single tsconfig.json to exclude test files if not already excluded.
|
|
156
|
+
* Only patches files that include `src/**` patterns (package tsconfigs).
|
|
157
|
+
*
|
|
158
|
+
* @returns `true` if the file was modified.
|
|
159
|
+
*/
|
|
160
|
+
private patchTsconfigIfNeeded;
|
|
161
|
+
/**
|
|
162
|
+
* Removes stale entity files from `packages/MJCoreEntities/src/custom/` that
|
|
163
|
+
* were superseded by MJ-prefixed versions during the 5.x entity rename.
|
|
164
|
+
*
|
|
165
|
+
* The published npm packages may ship both old-name and new-name files (e.g.,
|
|
166
|
+
* `UserViewEntity.ts` alongside `MJUserViewEntityExtended.ts`). The old files
|
|
167
|
+
* are unreferenced by `index.ts` but still compiled by `tsc`, causing build
|
|
168
|
+
* errors (TS2322: private property type conflicts) and potential runtime issues
|
|
169
|
+
* (duplicate `@RegisterClass` registrations for the same entity).
|
|
170
|
+
*
|
|
171
|
+
* Detection strategy: reads `index.ts` to identify active custom exports,
|
|
172
|
+
* then deletes any `.ts` files in `custom/` that contain `@RegisterClass`
|
|
173
|
+
* but are not referenced by any `index.ts` export line.
|
|
174
|
+
*
|
|
175
|
+
* @returns Number of stale files removed.
|
|
176
|
+
*/
|
|
177
|
+
private removeStaleEntityFiles;
|
|
178
|
+
/**
|
|
179
|
+
* Extracts the set of active custom file paths from `index.ts` export lines.
|
|
180
|
+
*
|
|
181
|
+
* Parses lines like `export * from './custom/MJUserViewEntityExtended'`
|
|
182
|
+
* and resolves them to absolute paths with `.ts` extensions.
|
|
183
|
+
*/
|
|
184
|
+
private extractActiveCustomFiles;
|
|
185
|
+
/**
|
|
186
|
+
* Recursively finds `.ts` files in a directory that:
|
|
187
|
+
* 1. Are NOT in the `activeFiles` set (not exported by `index.ts`)
|
|
188
|
+
* 2. Contain `@RegisterClass` (indicating entity registration, not utilities)
|
|
189
|
+
*/
|
|
190
|
+
private findStaleEntityFiles;
|
|
191
|
+
private checkHeapAdvisory;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=PlatformCompatPhase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformCompatPhase.d.ts","sourceRoot":"","sources":["../../src/phases/PlatformCompatPhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAgC1E;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,0DAA0D;IAC1D,UAAU,EAAE,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IACpD,wDAAwD;IACxD,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,uEAAuE;IACvE,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,oEAAoE;IACpE,cAAc,EAAE,OAAO,CAAC;IACxB,sFAAsF;IACtF,gBAAgB,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAkBD;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAmB;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