@open-mercato/cli 0.10.1-develop.7753.1.61290f530d → 0.10.1-develop.7758.1.fb3a60392f
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/agentic/guides/module-facts.json +162 -162
- package/dist/agentic/guides/module-facts.v2.json +162 -162
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/lib/__integration__/TC-INT-007.spec.js +17 -0
- package/dist/lib/__integration__/TC-INT-007.spec.js.map +2 -2
- package/dist/lib/module-install.js +46 -8
- package/dist/lib/module-install.js.map +2 -2
- package/dist/lib/modules-config.js +100 -27
- package/dist/lib/modules-config.js.map +2 -2
- package/dist/lib/resolver.js +21 -1
- package/dist/lib/resolver.js.map +2 -2
- package/dist/mercato.js +19 -12
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/lib/__integration__/TC-INT-007.spec.ts +22 -0
- package/src/lib/__tests__/module-install.test.ts +220 -14
- package/src/lib/__tests__/modules-config.test.ts +273 -1
- package/src/lib/__tests__/resolver.enterprise.test.ts +60 -0
- package/src/lib/module-install.ts +54 -10
- package/src/lib/modules-config.ts +145 -36
- package/src/lib/resolver.ts +23 -1
- package/src/mercato.ts +19 -8
|
@@ -144,6 +144,66 @@ describe('resolver enterprise module toggle', () => {
|
|
|
144
144
|
expect(modules).toEqual([{ id: 'customers', from: '@open-mercato/core' }])
|
|
145
145
|
})
|
|
146
146
|
|
|
147
|
+
it('keeps one registration per module id and warns about duplicates', () => {
|
|
148
|
+
process.env.OM_ENABLE_ENTERPRISE_MODULES = 'true'
|
|
149
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'resolver-duplicate-'))
|
|
150
|
+
fs.mkdirSync(path.join(tempDir, 'src'), { recursive: true })
|
|
151
|
+
fs.writeFileSync(
|
|
152
|
+
path.join(tempDir, 'src', 'modules.ts'),
|
|
153
|
+
`
|
|
154
|
+
import { parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'
|
|
155
|
+
|
|
156
|
+
export const enabledModules = [
|
|
157
|
+
{ id: 'customers', from: '@open-mercato/core' },
|
|
158
|
+
{ id: 'record_locks', from: '@open-mercato/enterprise' },
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
if (parseBooleanWithDefault(process.env.OM_ENABLE_ENTERPRISE_MODULES, false)) {
|
|
162
|
+
enabledModules.push({ id: 'record_locks', from: '@open-mercato/enterprise' })
|
|
163
|
+
}
|
|
164
|
+
`,
|
|
165
|
+
'utf8',
|
|
166
|
+
)
|
|
167
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
const modules = createResolver(tempDir).loadEnabledModules()
|
|
171
|
+
expect(modules.filter((entry) => entry.id === 'record_locks')).toHaveLength(1)
|
|
172
|
+
expect(modules.map((entry) => entry.id)).toEqual(['customers', 'record_locks'])
|
|
173
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('Module "record_locks" is registered more than once'))
|
|
174
|
+
} finally {
|
|
175
|
+
warn.mockRestore()
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('carries the full dev bootstrap mark from a dropped duplicate onto the kept registration', () => {
|
|
180
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'resolver-duplicate-bootstrap-'))
|
|
181
|
+
fs.mkdirSync(path.join(tempDir, 'src'), { recursive: true })
|
|
182
|
+
fs.writeFileSync(
|
|
183
|
+
path.join(tempDir, 'src', 'modules.ts'),
|
|
184
|
+
`
|
|
185
|
+
export const enabledModules = [
|
|
186
|
+
{ id: 'events', from: '@open-mercato/events' },
|
|
187
|
+
{ id: 'events', from: '@open-mercato/events', overrides: { cli: { start: null } } },
|
|
188
|
+
{ id: 'queue', from: '@open-mercato/core', overrides: { workers: { 'queue:process': null } } },
|
|
189
|
+
{ id: 'queue', from: '@open-mercato/core' },
|
|
190
|
+
]
|
|
191
|
+
`,
|
|
192
|
+
'utf8',
|
|
193
|
+
)
|
|
194
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
expect(createResolver(tempDir).loadEnabledModules()).toEqual([
|
|
198
|
+
{ id: 'events', from: '@open-mercato/events', devSupervisorRequiresFullBootstrap: true },
|
|
199
|
+
{ id: 'queue', from: '@open-mercato/core', devSupervisorRequiresFullBootstrap: true },
|
|
200
|
+
])
|
|
201
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('Module "events" is registered more than once'))
|
|
202
|
+
} finally {
|
|
203
|
+
warn.mockRestore()
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
|
|
147
207
|
it('parses modules.ts statically without executing runtime side effects', () => {
|
|
148
208
|
delete (globalThis as Record<string, unknown>).__resolver_evaluated__
|
|
149
209
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'resolver-enterprise-'))
|
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
validateEjectBoundaries,
|
|
9
9
|
type ValidatedOfficialModulePackage,
|
|
10
10
|
} from './module-package'
|
|
11
|
-
import { ensureModuleRegistration } from './modules-config'
|
|
11
|
+
import { assertModuleNotGatedOff, ensureModuleRegistration } from './modules-config'
|
|
12
12
|
import type { PackageResolver } from './resolver'
|
|
13
13
|
import { resolveSpawnCommand } from './spawn'
|
|
14
14
|
|
|
15
|
-
type ModuleCommandResult = {
|
|
15
|
+
export type ModuleCommandResult = {
|
|
16
16
|
moduleId: string
|
|
17
17
|
packageName: string
|
|
18
18
|
from: string
|
|
@@ -87,6 +87,42 @@ function runCommand(
|
|
|
87
87
|
})
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
function readFileIfExists(filePath: string): string | null {
|
|
91
|
+
return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isDeclaredAppDependency(appDir: string, packageName: string): boolean {
|
|
95
|
+
const packageJsonContent = readFileIfExists(path.join(appDir, 'package.json'))
|
|
96
|
+
if (!packageJsonContent) {
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let packageJson: Record<string, unknown>
|
|
101
|
+
try {
|
|
102
|
+
packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>
|
|
103
|
+
} catch (error) {
|
|
104
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
105
|
+
throw new Error(`App package.json at ${path.join(appDir, 'package.json')} is not valid JSON. ${message}`)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'].some((field) => {
|
|
109
|
+
const dependencies = packageJson[field]
|
|
110
|
+
return typeof dependencies === 'object' && dependencies !== null && packageName in dependencies
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isGatedOffError(error: unknown): boolean {
|
|
115
|
+
return error instanceof Error && (error as { code?: unknown }).code === 'MODULE_GATED_OFF'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function withLeftoverPackageHint(error: unknown, resolver: PackageResolver, packageName: string): Error {
|
|
119
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
120
|
+
const removeArgs = [...resolveInstallTarget(resolver).args.slice(0, -1), 'remove', packageName]
|
|
121
|
+
return new Error(
|
|
122
|
+
`${message} The package "${packageName}" stayed in package.json. To remove it, run: yarn ${removeArgs.join(' ')}`,
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
90
126
|
async function installPackageSpec(
|
|
91
127
|
resolver: PackageResolver,
|
|
92
128
|
packageSpec: string,
|
|
@@ -221,6 +257,7 @@ async function registerResolvedOfficialModule(
|
|
|
221
257
|
packageName: string,
|
|
222
258
|
eject: boolean,
|
|
223
259
|
): Promise<ModuleCommandResult> {
|
|
260
|
+
assertModuleNotGatedOff(resolver.getModulesConfigPath(), modulePackage.metadata.moduleId)
|
|
224
261
|
const from = prepareRegistrationSource(modulePackage, resolver, packageName, eject)
|
|
225
262
|
|
|
226
263
|
const registration = ensureModuleRegistration(
|
|
@@ -231,14 +268,10 @@ async function registerResolvedOfficialModule(
|
|
|
231
268
|
},
|
|
232
269
|
)
|
|
233
270
|
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
`Module "${modulePackage.metadata.moduleId}" from "${from}" is already enabled in modules.ts.`,
|
|
237
|
-
)
|
|
271
|
+
if (registration.changed) {
|
|
272
|
+
await runGeneratorsWithRegistrationNotice(resolver, modulePackage.metadata.moduleId)
|
|
238
273
|
}
|
|
239
274
|
|
|
240
|
-
await runGeneratorsWithRegistrationNotice(resolver, modulePackage.metadata.moduleId)
|
|
241
|
-
|
|
242
275
|
return {
|
|
243
276
|
moduleId: modulePackage.metadata.moduleId,
|
|
244
277
|
packageName,
|
|
@@ -258,10 +291,21 @@ export async function addOfficialModule(
|
|
|
258
291
|
const packageName = parsePackageNameFromSpec(safePackageSpec)
|
|
259
292
|
assertPackageName(packageName)
|
|
260
293
|
|
|
294
|
+
const wasDeclaredBefore = isDeclaredAppDependency(resolver.getAppDir(), packageName)
|
|
295
|
+
const modulesConfigBefore = readFileIfExists(resolver.getModulesConfigPath())
|
|
296
|
+
|
|
261
297
|
await installPackageSpec(resolver, safePackageSpec)
|
|
262
298
|
|
|
263
|
-
|
|
264
|
-
|
|
299
|
+
try {
|
|
300
|
+
const modulePackage = resolveInstalledOfficialModulePackage(resolver, packageName, moduleId)
|
|
301
|
+
return await registerResolvedOfficialModule(resolver, modulePackage, packageName, eject)
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const moduleWasRegistered = readFileIfExists(resolver.getModulesConfigPath()) !== modulesConfigBefore
|
|
304
|
+
if (wasDeclaredBefore || moduleWasRegistered || isGatedOffError(error)) {
|
|
305
|
+
throw error
|
|
306
|
+
}
|
|
307
|
+
throw withLeftoverPackageHint(error, resolver, packageName)
|
|
308
|
+
}
|
|
265
309
|
}
|
|
266
310
|
|
|
267
311
|
export async function enableOfficialModule(
|
|
@@ -10,8 +10,12 @@ export type ModuleEntry = {
|
|
|
10
10
|
type ModuleOccurrence = {
|
|
11
11
|
entry: ModuleEntry
|
|
12
12
|
node: ts.ObjectLiteralExpression
|
|
13
|
+
active: boolean
|
|
14
|
+
envFlags: string[] | null
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
type EnvFlagScope = Map<string, string[] | null>
|
|
18
|
+
|
|
15
19
|
type ModuleConfigShape = {
|
|
16
20
|
arrayNode: ts.ArrayLiteralExpression
|
|
17
21
|
occurrences: ModuleOccurrence[]
|
|
@@ -41,20 +45,15 @@ function parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): Mo
|
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
&& target.expression.text === 'process'
|
|
54
|
-
&& target.name.text === 'env'
|
|
55
|
-
) {
|
|
56
|
-
return { matched: true, value: env[node.name.text] }
|
|
57
|
-
}
|
|
48
|
+
function readProcessEnvName(node: ts.Expression): string | null {
|
|
49
|
+
if (
|
|
50
|
+
ts.isPropertyAccessExpression(node)
|
|
51
|
+
&& ts.isPropertyAccessExpression(node.expression)
|
|
52
|
+
&& ts.isIdentifier(node.expression.expression)
|
|
53
|
+
&& node.expression.expression.text === 'process'
|
|
54
|
+
&& node.expression.name.text === 'env'
|
|
55
|
+
) {
|
|
56
|
+
return node.name.text
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
if (
|
|
@@ -65,10 +64,10 @@ function parseProcessEnvAccess(
|
|
|
65
64
|
&& node.expression.name.text === 'env'
|
|
66
65
|
&& ts.isStringLiteralLike(node.argumentExpression)
|
|
67
66
|
) {
|
|
68
|
-
return
|
|
67
|
+
return node.argumentExpression.text
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
return
|
|
70
|
+
return null
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
function evaluateStaticExpressionWithScope(
|
|
@@ -96,9 +95,9 @@ function evaluateStaticExpressionWithScope(
|
|
|
96
95
|
if (node.kind === ts.SyntaxKind.FalseKeyword) return false
|
|
97
96
|
if (node.kind === ts.SyntaxKind.NullKeyword) return null
|
|
98
97
|
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
return
|
|
98
|
+
const envName = readProcessEnvName(node)
|
|
99
|
+
if (envName) {
|
|
100
|
+
return env[envName]
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
if (ts.isPropertyAccessExpression(node)) {
|
|
@@ -202,28 +201,84 @@ function evaluateStaticCondition(
|
|
|
202
201
|
return Boolean(evaluateStaticExpressionWithScope(node, env, scope))
|
|
203
202
|
}
|
|
204
203
|
|
|
204
|
+
function mergeEnvFlags(left: string[] | null, right: string[] | null): string[] | null {
|
|
205
|
+
if (left === null || right === null) return null
|
|
206
|
+
return Array.from(new Set([...left, ...right]))
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function collectEnablingEnvFlags(node: ts.Expression, envFlagScope: EnvFlagScope): string[] | null {
|
|
210
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
211
|
+
return collectEnablingEnvFlags(node.expression, envFlagScope)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const envName = readProcessEnvName(node)
|
|
215
|
+
if (envName) return [envName]
|
|
216
|
+
|
|
217
|
+
if (ts.isIdentifier(node)) {
|
|
218
|
+
return envFlagScope.get(node.text) ?? null
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
222
|
+
return mergeEnvFlags(
|
|
223
|
+
collectEnablingEnvFlags(node.left, envFlagScope),
|
|
224
|
+
collectEnablingEnvFlags(node.right, envFlagScope),
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (
|
|
229
|
+
ts.isCallExpression(node)
|
|
230
|
+
&& ts.isIdentifier(node.expression)
|
|
231
|
+
&& node.expression.text === 'parseBooleanWithDefault'
|
|
232
|
+
&& node.arguments[0]
|
|
233
|
+
) {
|
|
234
|
+
const envArgument = readProcessEnvName(node.arguments[0])
|
|
235
|
+
return envArgument ? [envArgument] : null
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return null
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
type BranchContext = {
|
|
242
|
+
active: boolean
|
|
243
|
+
envFlags: string[] | null
|
|
244
|
+
}
|
|
245
|
+
|
|
205
246
|
function collectPushEntriesFromStatement(
|
|
206
247
|
statement: ts.Statement,
|
|
207
248
|
env: NodeJS.ProcessEnv,
|
|
208
249
|
targetVariableName: string,
|
|
209
250
|
scope: Map<string, unknown>,
|
|
251
|
+
envFlagScope: EnvFlagScope,
|
|
252
|
+
branch: BranchContext = { active: true, envFlags: [] },
|
|
210
253
|
): ModuleOccurrence[] {
|
|
211
254
|
if (ts.isBlock(statement)) {
|
|
212
255
|
return statement.statements.flatMap((child) =>
|
|
213
|
-
collectPushEntriesFromStatement(child, env, targetVariableName, scope),
|
|
256
|
+
collectPushEntriesFromStatement(child, env, targetVariableName, scope, envFlagScope, branch),
|
|
214
257
|
)
|
|
215
258
|
}
|
|
216
259
|
|
|
217
260
|
if (ts.isIfStatement(statement)) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
261
|
+
const conditionMet = evaluateStaticCondition(statement.expression, env, scope)
|
|
262
|
+
const envFlags = mergeEnvFlags(branch.envFlags, collectEnablingEnvFlags(statement.expression, envFlagScope))
|
|
263
|
+
const thenEntries = collectPushEntriesFromStatement(
|
|
264
|
+
statement.thenStatement,
|
|
265
|
+
env,
|
|
266
|
+
targetVariableName,
|
|
267
|
+
scope,
|
|
268
|
+
envFlagScope,
|
|
269
|
+
{ active: branch.active && conditionMet, envFlags },
|
|
270
|
+
)
|
|
271
|
+
const elseEntries = statement.elseStatement
|
|
272
|
+
? collectPushEntriesFromStatement(
|
|
273
|
+
statement.elseStatement,
|
|
274
|
+
env,
|
|
275
|
+
targetVariableName,
|
|
276
|
+
scope,
|
|
277
|
+
envFlagScope,
|
|
278
|
+
{ active: branch.active && !conditionMet, envFlags: null },
|
|
279
|
+
)
|
|
280
|
+
: []
|
|
281
|
+
return [...thenEntries, ...elseEntries]
|
|
227
282
|
}
|
|
228
283
|
|
|
229
284
|
if (!ts.isExpressionStatement(statement)) return []
|
|
@@ -243,10 +298,14 @@ function collectPushEntriesFromStatement(
|
|
|
243
298
|
return expression.arguments.flatMap((argument) => {
|
|
244
299
|
if (!ts.isObjectLiteralExpression(argument)) return []
|
|
245
300
|
const entry = parseModuleEntryFromObjectLiteral(argument)
|
|
246
|
-
return entry ? [{ entry, node: argument }] : []
|
|
301
|
+
return entry ? [{ entry, node: argument, active: branch.active, envFlags: branch.envFlags }] : []
|
|
247
302
|
})
|
|
248
303
|
}
|
|
249
304
|
|
|
305
|
+
function activeEntries(occurrences: ModuleOccurrence[]): ModuleEntry[] {
|
|
306
|
+
return occurrences.filter((occurrence) => occurrence.active).map((occurrence) => occurrence.entry)
|
|
307
|
+
}
|
|
308
|
+
|
|
250
309
|
function parseModuleConfigShape(
|
|
251
310
|
source: string,
|
|
252
311
|
env: NodeJS.ProcessEnv = process.env,
|
|
@@ -255,6 +314,7 @@ function parseModuleConfigShape(
|
|
|
255
314
|
const variableName = 'enabledModules'
|
|
256
315
|
const occurrences: ModuleOccurrence[] = []
|
|
257
316
|
const scope = new Map<string, unknown>()
|
|
317
|
+
const envFlagScope: EnvFlagScope = new Map()
|
|
258
318
|
let arrayNode: ts.ArrayLiteralExpression | null = null
|
|
259
319
|
let foundDeclaration = false
|
|
260
320
|
|
|
@@ -270,9 +330,9 @@ function parseModuleConfigShape(
|
|
|
270
330
|
occurrences.push(...declaration.initializer.elements.flatMap((element) => {
|
|
271
331
|
if (!ts.isObjectLiteralExpression(element)) return []
|
|
272
332
|
const entry = parseModuleEntryFromObjectLiteral(element)
|
|
273
|
-
return entry ? [{ entry, node: element }] : []
|
|
333
|
+
return entry ? [{ entry, node: element, active: true, envFlags: [] }] : []
|
|
274
334
|
}))
|
|
275
|
-
scope.set(variableName, occurrences
|
|
335
|
+
scope.set(variableName, activeEntries(occurrences))
|
|
276
336
|
foundDeclaration = true
|
|
277
337
|
continue
|
|
278
338
|
}
|
|
@@ -283,16 +343,17 @@ function parseModuleConfigShape(
|
|
|
283
343
|
declaration.name.text,
|
|
284
344
|
evaluateStaticExpressionWithScope(declaration.initializer, env, scope),
|
|
285
345
|
)
|
|
346
|
+
envFlagScope.set(declaration.name.text, collectEnablingEnvFlags(declaration.initializer, envFlagScope))
|
|
286
347
|
}
|
|
287
348
|
continue
|
|
288
349
|
}
|
|
289
350
|
|
|
290
351
|
if (!foundDeclaration) continue
|
|
291
352
|
|
|
292
|
-
const pushedOccurrences = collectPushEntriesFromStatement(statement, env, variableName, scope)
|
|
353
|
+
const pushedOccurrences = collectPushEntriesFromStatement(statement, env, variableName, scope, envFlagScope)
|
|
293
354
|
if (pushedOccurrences.length > 0) {
|
|
294
355
|
occurrences.push(...pushedOccurrences)
|
|
295
|
-
scope.set(variableName, occurrences
|
|
356
|
+
scope.set(variableName, activeEntries(occurrences))
|
|
296
357
|
}
|
|
297
358
|
}
|
|
298
359
|
|
|
@@ -394,6 +455,49 @@ function upsertModuleSource(objectLiteral: string, from: string): string {
|
|
|
394
455
|
return objectLiteral.replace(/\}\s*$/, `, from: '${escapeSingleQuotedString(from)}' }`)
|
|
395
456
|
}
|
|
396
457
|
|
|
458
|
+
export class ModuleGatedOffError extends Error {
|
|
459
|
+
readonly code = 'MODULE_GATED_OFF'
|
|
460
|
+
|
|
461
|
+
constructor(
|
|
462
|
+
message: string,
|
|
463
|
+
readonly moduleId: string,
|
|
464
|
+
readonly envFlags: string[],
|
|
465
|
+
) {
|
|
466
|
+
super(message)
|
|
467
|
+
this.name = 'ModuleGatedOffError'
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function resolveFlagsToSet(occurrences: ModuleOccurrence[], env: NodeJS.ProcessEnv): string[] {
|
|
472
|
+
if (occurrences.some((occurrence) => occurrence.envFlags === null)) return []
|
|
473
|
+
const envFlags = Array.from(new Set(occurrences.flatMap((occurrence) => occurrence.envFlags ?? [])))
|
|
474
|
+
return envFlags.filter((flag) => !parseBooleanWithDefault(env[flag], false))
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function buildModuleGatedOffError(
|
|
478
|
+
moduleId: string,
|
|
479
|
+
modulesPath: string,
|
|
480
|
+
occurrences: ModuleOccurrence[],
|
|
481
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
482
|
+
): ModuleGatedOffError {
|
|
483
|
+
const flagsToSet = resolveFlagsToSet(occurrences, env)
|
|
484
|
+
const prefix = `Module "${moduleId}" is already registered in ${modulesPath} behind a condition that is currently off, so no second entry was added.`
|
|
485
|
+
const message = flagsToSet.length === 0
|
|
486
|
+
? `${prefix} Make that condition true to enable it.`
|
|
487
|
+
: `${prefix} Enable it by setting ${flagsToSet.map((flag) => `${flag}=true`).join(' and ')} in your environment (.env), then run \`yarn generate\`.`
|
|
488
|
+
return new ModuleGatedOffError(message, moduleId, flagsToSet)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export function assertModuleNotGatedOff(modulesPath: string, moduleId: string): void {
|
|
492
|
+
if (!fs.existsSync(modulesPath)) return
|
|
493
|
+
|
|
494
|
+
const config = parseModuleConfigShape(fs.readFileSync(modulesPath, 'utf8'))
|
|
495
|
+
const matches = config.occurrences.filter((occurrence) => occurrence.entry.id === moduleId)
|
|
496
|
+
if (matches.length > 0 && matches.every((occurrence) => !occurrence.active)) {
|
|
497
|
+
throw buildModuleGatedOffError(moduleId, modulesPath, matches)
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
397
501
|
export function ensureModuleRegistration(
|
|
398
502
|
modulesPath: string,
|
|
399
503
|
entry: ModuleEntry,
|
|
@@ -406,7 +510,12 @@ export function ensureModuleRegistration(
|
|
|
406
510
|
const sourceFile = ts.createSourceFile('modules.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
|
|
407
511
|
const config = parseModuleConfigShape(source)
|
|
408
512
|
const normalized = normalizeModuleEntry(entry)
|
|
409
|
-
const
|
|
513
|
+
const allMatches = config.occurrences.filter((occurrence) => occurrence.entry.id === normalized.id)
|
|
514
|
+
const matches = allMatches.filter((occurrence) => occurrence.active)
|
|
515
|
+
|
|
516
|
+
if (matches.length === 0 && allMatches.length > 0) {
|
|
517
|
+
throw buildModuleGatedOffError(normalized.id, modulesPath, allMatches)
|
|
518
|
+
}
|
|
410
519
|
|
|
411
520
|
if (matches.length > 1) {
|
|
412
521
|
throw new Error(
|
|
@@ -442,7 +551,7 @@ export function setModuleRegistrationSource(
|
|
|
442
551
|
|
|
443
552
|
const source = fs.readFileSync(modulesPath, 'utf8')
|
|
444
553
|
const config = parseModuleConfigShape(source)
|
|
445
|
-
const matches = config.occurrences.filter((occurrence) => occurrence.entry.id === moduleId)
|
|
554
|
+
const matches = config.occurrences.filter((occurrence) => occurrence.active && occurrence.entry.id === moduleId)
|
|
446
555
|
|
|
447
556
|
if (matches.length === 0) {
|
|
448
557
|
throw new Error(
|
package/src/lib/resolver.ts
CHANGED
|
@@ -331,7 +331,29 @@ function parseModulesFromSource(source: string, env: NodeJS.ProcessEnv = process
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
return modules
|
|
334
|
+
return dedupeModulesById(modules)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const reportedDuplicateModuleIds = new Set<string>()
|
|
338
|
+
|
|
339
|
+
function dedupeModulesById(modules: ModuleEntry[]): ModuleEntry[] {
|
|
340
|
+
const seen = new Map<string, ModuleEntry>()
|
|
341
|
+
for (const entry of modules) {
|
|
342
|
+
const existing = seen.get(entry.id)
|
|
343
|
+
if (!existing) {
|
|
344
|
+
seen.set(entry.id, entry)
|
|
345
|
+
continue
|
|
346
|
+
}
|
|
347
|
+
if (entry.devSupervisorRequiresFullBootstrap && !existing.devSupervisorRequiresFullBootstrap) {
|
|
348
|
+
seen.set(entry.id, { ...existing, devSupervisorRequiresFullBootstrap: true })
|
|
349
|
+
}
|
|
350
|
+
if (reportedDuplicateModuleIds.has(entry.id)) continue
|
|
351
|
+
reportedDuplicateModuleIds.add(entry.id)
|
|
352
|
+
console.warn(
|
|
353
|
+
`[resolver] Module "${entry.id}" is registered more than once in src/modules.ts (from "${existing.from ?? '@open-mercato/core'}" and "${entry.from ?? '@open-mercato/core'}"). Keeping the first registration; remove the duplicate entry.`,
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
return Array.from(seen.values())
|
|
335
357
|
}
|
|
336
358
|
|
|
337
359
|
export function readEnabledModulesFromConfig(cfgPath: string): ModuleEntry[] {
|
package/src/mercato.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
type GenerateWatcherMode,
|
|
40
40
|
} from './lib/in-process-generate-watcher-mode'
|
|
41
41
|
import { parseModuleInstallArgs } from './lib/module-install-args'
|
|
42
|
+
import type { ModuleCommandResult } from './lib/module-install'
|
|
42
43
|
import { resolveNextBuildIdCandidate } from './lib/next-build-id'
|
|
43
44
|
import { acquireServerStartLock } from './lib/server-start-lock'
|
|
44
45
|
import { assertSingleInstanceStrategies } from './lib/single-instance-strategy-guard'
|
|
@@ -678,6 +679,22 @@ function ensureNextBuildIdInConfiguredDistDir(appDir: string): void {
|
|
|
678
679
|
)
|
|
679
680
|
}
|
|
680
681
|
|
|
682
|
+
function printModuleCommandResult(result: ModuleCommandResult, alreadyEnabledNote?: string): void {
|
|
683
|
+
if (!result.registrationChanged) {
|
|
684
|
+
console.log(`\nℹ️ Module "${result.moduleId}" from "${result.from}" is already enabled in modules.ts. Nothing to change.`)
|
|
685
|
+
if (alreadyEnabledNote) {
|
|
686
|
+
console.log(alreadyEnabledNote)
|
|
687
|
+
}
|
|
688
|
+
console.log('')
|
|
689
|
+
return
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
console.log(`\n✅ Module "${result.moduleId}" enabled from ${result.from}.\n`)
|
|
693
|
+
console.log('Next steps:')
|
|
694
|
+
console.log(' 1. Review generated files if needed: .mercato/generated/')
|
|
695
|
+
console.log(' 2. Start dev: yarn dev')
|
|
696
|
+
}
|
|
697
|
+
|
|
681
698
|
async function handleDirectEjectCommand(args: string[]): Promise<number> {
|
|
682
699
|
const { createResolver } = await import('./lib/resolver')
|
|
683
700
|
const { listEjectableModules, ejectModule } = await import('./lib/eject')
|
|
@@ -1469,10 +1486,7 @@ export async function run(argv = process.argv) {
|
|
|
1469
1486
|
}
|
|
1470
1487
|
|
|
1471
1488
|
const result = await addOfficialModule(createResolver(), packageSpec, eject, moduleId ?? undefined, allowThirdParty)
|
|
1472
|
-
|
|
1473
|
-
console.log('Next steps:')
|
|
1474
|
-
console.log(' 1. Review generated files if needed: .mercato/generated/')
|
|
1475
|
-
console.log(' 2. Start dev: yarn dev')
|
|
1489
|
+
printModuleCommandResult(result, 'If yarn add changed the package version, run "yarn mercato generate" to refresh generated files.')
|
|
1476
1490
|
return 0
|
|
1477
1491
|
}
|
|
1478
1492
|
|
|
@@ -1487,10 +1501,7 @@ export async function run(argv = process.argv) {
|
|
|
1487
1501
|
const { enableOfficialModule } = await import('./lib/module-install')
|
|
1488
1502
|
const { moduleId, eject, allowThirdParty } = parseModuleInstallArgs(commandArgs)
|
|
1489
1503
|
const result = await enableOfficialModule(createResolver(), packageName, moduleId ?? undefined, eject, allowThirdParty)
|
|
1490
|
-
|
|
1491
|
-
console.log('Next steps:')
|
|
1492
|
-
console.log(' 1. Review generated files if needed: .mercato/generated/')
|
|
1493
|
-
console.log(' 2. Start dev: yarn dev')
|
|
1504
|
+
printModuleCommandResult(result)
|
|
1494
1505
|
return 0
|
|
1495
1506
|
}
|
|
1496
1507
|
|