@friggframework/devtools 2.0.0--canary.731.ffe61d3.0 → 2.0.0--canary.656.6eb85ab.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.
Files changed (102) hide show
  1. package/frigg-cli/README.md +31 -115
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
  3. package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -33
  4. package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
  5. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  6. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
  7. package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
  8. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
  9. package/frigg-cli/build-command/index.js +0 -6
  10. package/frigg-cli/deploy-command/index.js +0 -6
  11. package/frigg-cli/generate-command/index.js +0 -1
  12. package/frigg-cli/generate-iam-command.js +0 -1
  13. package/frigg-cli/index.js +5 -22
  14. package/frigg-cli/index.test.js +158 -0
  15. package/frigg-cli/init-command/backend-first-handler.js +551 -395
  16. package/frigg-cli/init-command/index.js +35 -82
  17. package/frigg-cli/install-command/commit-changes.js +8 -40
  18. package/frigg-cli/install-command/environment-variables.js +0 -15
  19. package/frigg-cli/install-command/index.js +21 -96
  20. package/frigg-cli/install-command/install-package.js +4 -77
  21. package/frigg-cli/install-command/integration-file.js +11 -20
  22. package/frigg-cli/install-command/template.js +75 -102
  23. package/frigg-cli/install-command/validate-package.js +4 -36
  24. package/frigg-cli/package.json +1 -1
  25. package/frigg-cli/start-command/index.js +0 -4
  26. package/frigg-cli/start-command/start-command.test.js +0 -3
  27. package/frigg-cli/test/init-command.test.js +2 -9
  28. package/infrastructure/README.md +5 -32
  29. package/infrastructure/__tests__/postgres-config.test.js +836 -245
  30. package/infrastructure/__tests__/scoped-environment.test.js +0 -3
  31. package/infrastructure/__tests__/ssm-preload-node-options.test.js +0 -3
  32. package/infrastructure/__tests__/template-generation.test.js +8 -39
  33. package/infrastructure/create-frigg-infrastructure.js +1 -4
  34. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +98 -80
  35. package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -8
  36. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +6 -52
  37. package/infrastructure/domains/database/aurora-builder.js +2 -13
  38. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  39. package/infrastructure/domains/database/migration-builder.js +2 -21
  40. package/infrastructure/domains/database/migration-builder.test.js +6 -61
  41. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
  42. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
  43. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
  44. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
  45. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
  46. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
  47. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
  48. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
  49. package/infrastructure/domains/integration/integration-builder.js +0 -2
  50. package/infrastructure/domains/integration/integration-builder.test.js +6 -22
  51. package/infrastructure/domains/networking/vpc-builder.js +8 -18
  52. package/infrastructure/domains/networking/vpc-builder.test.js +12 -26
  53. package/infrastructure/domains/security/iam-generator.js +5 -112
  54. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  55. package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
  56. package/infrastructure/domains/shared/environment-builder.js +5 -31
  57. package/infrastructure/domains/shared/environment-builder.test.js +7 -93
  58. package/infrastructure/domains/shared/utilities/base-definition-factory.js +3 -39
  59. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +5 -85
  60. package/infrastructure/domains/shared/utilities/nested-node-modules.js +5 -6
  61. package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +26 -20
  62. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +12 -92
  63. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +6 -158
  64. package/infrastructure/infrastructure-composer.js +1 -12
  65. package/infrastructure/infrastructure-composer.test.js +794 -339
  66. package/infrastructure/integration.test.js +381 -0
  67. package/infrastructure/scripts/build-prisma-layer.js +50 -136
  68. package/infrastructure/scripts/build-prisma-layer.test.js +7 -128
  69. package/infrastructure/scripts/build-time-discovery.test.js +3 -18
  70. package/package.json +10 -12
  71. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  72. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
  73. package/frigg-cli/init-command/deployment-modes.js +0 -7
  74. package/frigg-cli/init-command/safe-path.js +0 -58
  75. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  76. package/frigg-cli/install-command/app-definition.js +0 -174
  77. package/frigg-cli/install-command/resolve-module.js +0 -69
  78. package/frigg-cli/templates/backend/README.md +0 -267
  79. package/frigg-cli/templates/backend/env.example +0 -20
  80. package/frigg-cli/templates/backend/gitignore +0 -10
  81. package/frigg-cli/templates/backend/index.js +0 -114
  82. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  83. package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
  84. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
  85. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -443
  86. package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -262
  87. package/frigg-cli/validate-command/checks/config.js +0 -504
  88. package/frigg-cli/validate-command/checks/integrations.js +0 -274
  89. package/frigg-cli/validate-command/format-report.js +0 -58
  90. package/frigg-cli/validate-command/index.js +0 -107
  91. package/frigg-cli/validate-command/load-app-definition.js +0 -105
  92. package/frigg-cli/validate-command/schema-issues.js +0 -154
  93. package/frigg-cli/validate-command/validate-app-definition.js +0 -60
  94. package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +0 -39
  95. package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -284
  96. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -151
  97. package/infrastructure/app-definition-schema-contract.test.js +0 -634
  98. package/infrastructure/create-frigg-infrastructure.test.js +0 -51
  99. package/infrastructure/domains/database/migration-engines.js +0 -93
  100. package/infrastructure/domains/database/migration-engines.test.js +0 -142
  101. package/infrastructure/domains/shared/lambda-architectures.js +0 -113
  102. package/infrastructure/domains/shared/lambda-architectures.test.js +0 -164
@@ -10,22 +10,6 @@ const {
10
10
  } = require('./environment-builder');
11
11
 
12
12
  describe('Environment Builder', () => {
13
- // Keep stage-default / empty-definition assertions deterministic even when
14
- // a developer shell has OTEL_EXPORTER_OTLP_ENDPOINT set (zero-code path).
15
- const originalOtelEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
16
-
17
- beforeEach(() => {
18
- delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
19
- });
20
-
21
- afterEach(() => {
22
- if (originalOtelEndpoint === undefined) {
23
- delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
24
- } else {
25
- process.env.OTEL_EXPORTER_OTLP_ENDPOINT = originalOtelEndpoint;
26
- }
27
- });
28
-
29
13
  describe('getAppEnvironmentVars()', () => {
30
14
  it('should extract environment variables with value true', () => {
31
15
  const appDefinition = {
@@ -161,44 +145,6 @@ describe('Environment Builder', () => {
161
145
  getAppEnvironmentVars({}).OTEL_EXPORTER_OTLP_ENDPOINT
162
146
  ).toBeUndefined();
163
147
  });
164
-
165
- it('zero-code: emits OTLP passthroughs when Definition omits exporter and the deploy env has the endpoint', () => {
166
- process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
167
- 'https://watchtower.example/api/v1/watchtower/otel';
168
-
169
- const result = getAppEnvironmentVars({});
170
-
171
- expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBe(
172
- "${env:OTEL_EXPORTER_OTLP_ENDPOINT, ''}"
173
- );
174
- expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBe(
175
- "${env:OTEL_EXPORTER_OTLP_HEADERS, ''}"
176
- );
177
- });
178
-
179
- it('zero-code: whitespace-only OTEL_EXPORTER_OTLP_ENDPOINT does not emit passthroughs', () => {
180
- process.env.OTEL_EXPORTER_OTLP_ENDPOINT = ' ';
181
-
182
- const result = getAppEnvironmentVars({});
183
-
184
- expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
185
- expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBeUndefined();
186
- });
187
-
188
- it.each(['none', 'console'])(
189
- 'explicit exporter type "%s" wins over a set deploy-shell endpoint',
190
- (type) => {
191
- process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
192
- 'https://watchtower.example/api/v1/watchtower/otel';
193
-
194
- const result = getAppEnvironmentVars({
195
- telemetry: { exporter: { type } },
196
- });
197
-
198
- expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
199
- expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBeUndefined();
200
- }
201
- );
202
148
  });
203
149
 
204
150
  describe('logging env (ADR-048)', () => {
@@ -271,12 +217,7 @@ describe('Environment Builder', () => {
271
217
  }
272
218
  };
273
219
 
274
- beforeEach(() =>
275
- setEnv({
276
- FRIGG_SKIP_AWS_DISCOVERY: 'true',
277
- FRIGG_LOG_LEVEL: undefined,
278
- })
279
- );
220
+ beforeEach(() => setEnv({ FRIGG_SKIP_AWS_DISCOVERY: 'true', FRIGG_LOG_LEVEL: undefined }));
280
221
 
281
222
  afterEach(() => {
282
223
  for (const [key, value] of Object.entries(saved)) {
@@ -295,39 +236,29 @@ describe('Environment Builder', () => {
295
236
  setEnv({ FRIGG_LOG_LEVEL: 'error' });
296
237
 
297
238
  expect(
298
- getAppEnvironmentVars({ logging: { level: 'debug' } })
299
- .FRIGG_LOG_LEVEL
239
+ getAppEnvironmentVars({ logging: { level: 'debug' } }).FRIGG_LOG_LEVEL
300
240
  ).toBe('error');
301
241
  });
302
242
 
303
243
  it('emits logging.level INFO, so the local DEBUG default does not replace it', () => {
304
244
  expect(
305
- getAppEnvironmentVars({ logging: { level: 'info' } })
306
- .FRIGG_LOG_LEVEL
245
+ getAppEnvironmentVars({ logging: { level: 'info' } }).FRIGG_LOG_LEVEL
307
246
  ).toBe('INFO');
308
247
  });
309
248
 
310
249
  it('ignores an empty shell value', () => {
311
250
  setEnv({ FRIGG_LOG_LEVEL: ' ' });
312
251
 
313
- expect(getAppEnvironmentVars({})).not.toHaveProperty(
314
- 'FRIGG_LOG_LEVEL'
315
- );
252
+ expect(getAppEnvironmentVars({})).not.toHaveProperty('FRIGG_LOG_LEVEL');
316
253
  expect(
317
- getAppEnvironmentVars({ logging: { level: 'warn' } })
318
- .FRIGG_LOG_LEVEL
254
+ getAppEnvironmentVars({ logging: { level: 'warn' } }).FRIGG_LOG_LEVEL
319
255
  ).toBe('WARN');
320
256
  });
321
257
 
322
258
  it('does not read the shell value outside frigg start', () => {
323
- setEnv({
324
- FRIGG_SKIP_AWS_DISCOVERY: undefined,
325
- FRIGG_LOG_LEVEL: 'error',
326
- });
259
+ setEnv({ FRIGG_SKIP_AWS_DISCOVERY: undefined, FRIGG_LOG_LEVEL: 'error' });
327
260
 
328
- expect(getAppEnvironmentVars({})).not.toHaveProperty(
329
- 'FRIGG_LOG_LEVEL'
330
- );
261
+ expect(getAppEnvironmentVars({})).not.toHaveProperty('FRIGG_LOG_LEVEL');
331
262
  expect(
332
263
  getAppEnvironmentVars({ logging: { level: 'info' } })
333
264
  ).not.toHaveProperty('FRIGG_LOG_LEVEL');
@@ -535,23 +466,6 @@ describe('Environment Builder', () => {
535
466
 
536
467
  expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
537
468
  });
538
-
539
- it('zero-code: omitted exporter + SSM-offloaded endpoint still passes through headers', () => {
540
- delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
541
- const appDefinition = {
542
- ssm: { enable: true },
543
- environment: {
544
- OTEL_EXPORTER_OTLP_ENDPOINT: 'ssm',
545
- },
546
- };
547
-
548
- const result = getAppEnvironmentVars(appDefinition);
549
-
550
- expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
551
- expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBe(
552
- "${env:OTEL_EXPORTER_OTLP_HEADERS, ''}"
553
- );
554
- });
555
469
  });
556
470
 
557
471
  describe('buildEnvironment()', () => {
@@ -10,10 +10,6 @@
10
10
  const { buildEnvironment } = require('../environment-builder');
11
11
  const { nestedNodeModulesExcludes } = require('./nested-node-modules');
12
12
  const { buildLoggingProviderConfig } = require('./logging-config');
13
- const {
14
- resolveLambdaArchitecture,
15
- bundledPrismaEngineExcludes,
16
- } = require('../lambda-architectures');
17
13
 
18
14
  /**
19
15
  * Create base serverless definition with core functions and resources
@@ -39,8 +35,6 @@ function createBaseDefinition(
39
35
  ) {
40
36
  const region = process.env.AWS_REGION || 'us-east-1';
41
37
  const loggingConfig = buildLoggingProviderConfig(AppDefinition.logging);
42
- const architecture = resolveLambdaArchitecture(AppDefinition);
43
- const bundledEngineExcludes = bundledPrismaEngineExcludes(AppDefinition, usePrismaLayer);
44
38
 
45
39
  // Package config for handlers that skip esbuild (need node_modules dependencies)
46
40
  // Include backend src/ and index.js since handlers load the app definition
@@ -60,7 +54,6 @@ function createBaseDefinition(
60
54
  'node_modules/prisma/**',
61
55
  'node_modules/@friggframework/core/generated/**',
62
56
  ] : []),
63
- ...bundledEngineExcludes,
64
57
 
65
58
  // Exclude AWS SDK (provided by Lambda runtime)
66
59
  'node_modules/aws-sdk/**',
@@ -134,7 +127,6 @@ function createBaseDefinition(
134
127
  'node_modules/prisma/**',
135
128
  'node_modules/@friggframework/core/generated/**',
136
129
  ] : []),
137
- ...bundledEngineExcludes,
138
130
 
139
131
  // Exclude nested node_modules from symlinked frigg packages (for npm link development)
140
132
  'node_modules/@friggframework/core/node_modules/**',
@@ -186,7 +178,6 @@ function createBaseDefinition(
186
178
  name: AppDefinition.provider || 'aws',
187
179
  ...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
188
180
  runtime: 'nodejs22.x', // Node.js 22.x (latest Lambda runtime with AWS SDK v3)
189
- ...(architecture.explicit && { architecture: architecture.name }),
190
181
  timeout: 29, // Set to 29s to give buffer before API Gateway's 30s timeout
191
182
  region,
192
183
  stage: '${opt:stage}',
@@ -295,11 +286,6 @@ function createBaseDefinition(
295
286
  ...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
296
287
  skipEsbuild: true, // Handlers in node_modules don't need bundling
297
288
  package: skipEsbuildPackageConfig,
298
- // Every path prefix the core integration router
299
- // (createIntegrationRouter) registers must be routed here;
300
- // HTTP API has no implicit catch-all, so an unlisted prefix
301
- // 404s at the gateway before Express sees it. Guarded by
302
- // __tests__/management-api-gateway-routes.test.js.
303
289
  events: [
304
290
  { httpApi: { path: '/api/integrations', method: 'ANY' } },
305
291
  {
@@ -309,20 +295,6 @@ function createBaseDefinition(
309
295
  },
310
296
  },
311
297
  { httpApi: { path: '/api/authorize', method: 'ANY' } },
312
- { httpApi: { path: '/api/entity', method: 'ANY' } },
313
- {
314
- httpApi: {
315
- path: '/api/entity/{proxy+}',
316
- method: 'ANY',
317
- },
318
- },
319
- { httpApi: { path: '/api/entities', method: 'ANY' } },
320
- {
321
- httpApi: {
322
- path: '/api/entities/{proxy+}',
323
- method: 'ANY',
324
- },
325
- },
326
298
  ],
327
299
  },
328
300
  user: {
@@ -350,11 +322,8 @@ function createBaseDefinition(
350
322
  prisma: {
351
323
  path: 'layers/prisma',
352
324
  name: '${self:service}-prisma-${sls:stage}',
353
- description: 'Prisma runtime client only (NO CLI) with the query engine for the deployed Lambda architecture (~10-15MB). CLI packaged separately in dbMigrate function.',
325
+ description: 'Prisma runtime client only (NO CLI) with rhel-openssl-3.0.x binaries (~10-15MB). CLI packaged separately in dbMigrate function.',
354
326
  compatibleRuntimes: ['nodejs20.x', 'nodejs22.x'],
355
- ...(architecture.explicit && {
356
- compatibleArchitectures: [architecture.name],
357
- }),
358
327
  retain: false,
359
328
  },
360
329
  } : {},
@@ -414,18 +383,12 @@ function createBaseDefinition(
414
383
  },
415
384
  },
416
385
  },
417
- // The functions above use `httpApi` events, so osls creates
418
- // an HTTP API (API Gateway v2, logical ID HttpApi) with only
419
- // the `$default` stage. HTTP APIs publish `5xx`, not the REST
420
- // API metric `5XXError`, and the ApiId dimension identifies
421
- // this API (a Stage dimension would have to be `$default`).
422
- // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
423
386
  ApiGatewayAlarm5xx: {
424
387
  Type: 'AWS::CloudWatch::Alarm',
425
388
  Properties: {
426
389
  AlarmDescription: 'API Gateway 5xx Errors',
427
390
  Namespace: 'AWS/ApiGateway',
428
- MetricName: '5xx',
391
+ MetricName: '5XXError',
429
392
  Statistic: 'Sum',
430
393
  Threshold: 0,
431
394
  ComparisonOperator: 'GreaterThanThreshold',
@@ -434,6 +397,7 @@ function createBaseDefinition(
434
397
  AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
435
398
  Dimensions: [
436
399
  { Name: 'ApiId', Value: { Ref: 'HttpApi' } },
400
+ { Name: 'Stage', Value: '${self:provider.stage}' },
437
401
  ],
438
402
  },
439
403
  },
@@ -5,7 +5,6 @@
5
5
  */
6
6
 
7
7
  const { createBaseDefinition } = require('./base-definition-factory');
8
- const { itBundlesOnlyTheTargetPrismaEngine } = require('../../../__tests__/helpers/bundled-prisma-engine-excludes');
9
8
 
10
9
  describe('Base Definition Factory', () => {
11
10
  beforeEach(() => {
@@ -95,19 +94,7 @@ describe('Base Definition Factory', () => {
95
94
 
96
95
  expect(result.functions.auth.handler).toBe('node_modules/@friggframework/core/handlers/routers/auth.handler');
97
96
  expect(result.functions.auth.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
98
- expect(
99
- result.functions.auth.events.map(
100
- (e) => `${e.httpApi.method} ${e.httpApi.path}`
101
- )
102
- ).toEqual([
103
- 'ANY /api/integrations',
104
- 'ANY /api/integrations/{proxy+}',
105
- 'ANY /api/authorize',
106
- 'ANY /api/entity',
107
- 'ANY /api/entity/{proxy+}',
108
- 'ANY /api/entities',
109
- 'ANY /api/entities/{proxy+}',
110
- ]);
97
+ expect(result.functions.auth.events).toHaveLength(3);
111
98
  });
112
99
 
113
100
  it('should NOT include legacy dbMigrate function', () => {
@@ -134,27 +121,6 @@ describe('Base Definition Factory', () => {
134
121
  expect(result.resources.Resources.ApiGatewayAlarm5xx).toBeDefined();
135
122
  });
136
123
 
137
- it('alarms on the HTTP API 5xx metric of the API osls creates', () => {
138
- // The Frigg functions use `httpApi` events, so osls creates an
139
- // API Gateway v2 HTTP API (logical ID HttpApi) with only the
140
- // `$default` stage. HTTP APIs publish `5xx` (REST APIs publish
141
- // `5XXError`) with the ApiId dimension; a Stage dimension set to
142
- // the deploy stage name would never match `$default`.
143
- const result = createBaseDefinition({}, {}, {});
144
- const usesHttpApi = Object.values(result.functions).some((fn) =>
145
- (fn.events || []).some((event) => event.httpApi)
146
- );
147
- expect(usesHttpApi).toBe(true);
148
-
149
- const alarm = result.resources.Resources.ApiGatewayAlarm5xx;
150
- expect(alarm.Properties).toMatchObject({
151
- Namespace: 'AWS/ApiGateway',
152
- MetricName: '5xx',
153
- Dimensions: [{ Name: 'ApiId', Value: { Ref: 'HttpApi' } }],
154
- AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
155
- });
156
- });
157
-
158
124
  it('should include base IAM permissions', () => {
159
125
  const result = createBaseDefinition({}, {}, {});
160
126
 
@@ -324,65 +290,19 @@ describe('Base Definition Factory', () => {
324
290
  });
325
291
 
326
292
 
327
- describe('Lambda architecture (architecture)', () => {
328
- const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
329
-
330
- it('adds no architecture fields when the key is unset, so existing templates do not change', () => {
331
- const result = build({ name: 'test-app' });
332
-
333
- expect(result.provider.architecture).toBeUndefined();
334
- expect(result.layers.prisma.compatibleArchitectures).toBeUndefined();
335
- });
336
-
337
- it.each(['x86_64', 'arm64'])(
338
- 'sets provider.architecture and the layer compatibleArchitectures to %s when set',
339
- (architecture) => {
340
- const result = build({ name: 'test-app', architecture });
341
-
342
- expect(result.provider.architecture).toBe(architecture);
343
- expect(result.layers.prisma.compatibleArchitectures).toEqual([architecture]);
344
- }
345
- );
346
-
347
- it('describes the layer without naming an engine, since the engine follows the architecture', () => {
348
- const result = build({ name: 'test-app' });
349
-
350
- expect(result.layers.prisma.description).not.toContain('rhel');
351
- });
352
-
353
- it('rejects an architecture the registry does not know', () => {
354
- expect(() => build({ name: 'test-app', architecture: 'aarch64' })).toThrow(
355
- /aarch64/
356
- );
357
- });
358
- });
359
-
360
- describe('Lambda architecture with usePrismaLambdaLayer=false', () => {
361
- const functionsOf = (usePrismaLayer, architecture) => {
362
- const result = createBaseDefinition(
363
- { name: 'test-app', ...(architecture && { architecture }) },
364
- {},
365
- {},
366
- usePrismaLayer
367
- );
368
- return Object.values(result.functions);
369
- };
370
- itBundlesOnlyTheTargetPrismaEngine(functionsOf);
371
- });
372
-
373
293
  describe('nested node_modules (lambda.keepNestedNodeModules)', () => {
374
294
  const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
375
295
 
376
- it('excludes every nested node_modules from the core function packages when the app opts out', () => {
377
- const result = build({ name: 'test-app', lambda: { keepNestedNodeModules: false } });
296
+ it('excludes every nested node_modules from the core function packages by default', () => {
297
+ const result = build({ name: 'test-app' });
378
298
 
379
299
  for (const fn of ['auth', 'user', 'health']) {
380
300
  expect(result.functions[fn].package.exclude).toContain('node_modules/**/node_modules/**');
381
301
  }
382
302
  });
383
303
 
384
- it('keeps nested node_modules by default, still excluding nested Frigg, AWS SDK and Prisma copies', () => {
385
- const result = build({ name: 'test-app' });
304
+ it('keeps nested node_modules when the app opts in, still excluding nested Frigg, AWS SDK and Prisma copies', () => {
305
+ const result = build({ name: 'test-app', lambda: { keepNestedNodeModules: true } });
386
306
 
387
307
  for (const fn of ['auth', 'user', 'health']) {
388
308
  const { exclude } = result.functions[fn].package;
@@ -6,11 +6,10 @@
6
6
  * npm nests a package only when the root copy cannot satisfy the dependant's
7
7
  * range. Excluding every nested node_modules from a Lambda package therefore
8
8
  * rewires module resolution to whatever is hoisted, and drops a package
9
- * outright when the root copy is dev-only. Function packages ship the tree the
10
- * way npm resolved it unless an app opts out with
11
- * `lambda.keepNestedNodeModules: false`. Nested copies of Frigg packages, the
12
- * AWS SDK and Prisma stay excluded because the app's single core, the Lambda
13
- * runtime and the Prisma layer provide them.
9
+ * outright when the root copy is dev-only. Apps opt in to shipping the tree
10
+ * the way npm resolved it with `lambda.keepNestedNodeModules: true`. Nested
11
+ * copies of Frigg packages, the AWS SDK and Prisma stay excluded because the
12
+ * app's single core, the Lambda runtime and the Prisma layer provide them.
14
13
  */
15
14
 
16
15
  const ALL_NESTED_NODE_MODULES = 'node_modules/**/node_modules/**';
@@ -20,7 +19,7 @@ const ALL_NESTED_NODE_MODULES = 'node_modules/**/node_modules/**';
20
19
  * @returns {boolean}
21
20
  */
22
21
  function keepsNestedNodeModules(appDefinition = {}) {
23
- return appDefinition.lambda?.keepNestedNodeModules !== false;
22
+ return appDefinition.lambda?.keepNestedNodeModules === true;
24
23
  }
25
24
 
26
25
  /**
@@ -8,13 +8,20 @@ const {
8
8
  nestedNodeModulesExcludes,
9
9
  } = require('./nested-node-modules');
10
10
 
11
- const OPT_OUT = { lambda: { keepNestedNodeModules: false } };
12
-
13
11
  describe('nestedNodeModulesExcludes', () => {
14
- it('keeps nested node_modules by default, except Frigg, AWS SDK and Prisma copies', () => {
15
- const excludes = nestedNodeModulesExcludes({}, true);
12
+ it('excludes every nested node_modules by default', () => {
13
+ expect(nestedNodeModulesExcludes({}, true)).toEqual([
14
+ 'node_modules/**/node_modules/**',
15
+ ]);
16
+ expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**');
17
+ });
16
18
 
17
- expect(excludes).not.toContain(ALL_NESTED_NODE_MODULES);
19
+ it('keeps nested node_modules when the app opts in, except Frigg, AWS SDK and Prisma copies', () => {
20
+ const appDefinition = { lambda: { keepNestedNodeModules: true } };
21
+
22
+ const excludes = nestedNodeModulesExcludes(appDefinition, true);
23
+
24
+ expect(excludes).not.toContain('node_modules/**/node_modules/**');
18
25
  expect(excludes).toEqual([
19
26
  'node_modules/**/node_modules/@friggframework/**',
20
27
  'node_modules/**/node_modules/aws-sdk/**',
@@ -25,31 +32,30 @@ describe('nestedNodeModulesExcludes', () => {
25
32
  });
26
33
 
27
34
  it('keeps nested Prisma copies when the app bundles Prisma instead of using the layer', () => {
28
- expect(nestedNodeModulesExcludes({}, false)).toEqual([
35
+ const appDefinition = { lambda: { keepNestedNodeModules: true } };
36
+
37
+ const excludes = nestedNodeModulesExcludes(appDefinition, false);
38
+
39
+ expect(excludes).toEqual([
29
40
  'node_modules/**/node_modules/@friggframework/**',
30
41
  'node_modules/**/node_modules/aws-sdk/**',
31
42
  'node_modules/**/node_modules/@aws-sdk/**',
32
43
  ]);
33
44
  });
34
-
35
- it('excludes every nested node_modules when the app opts out', () => {
36
- expect(nestedNodeModulesExcludes(OPT_OUT, true)).toEqual([
37
- 'node_modules/**/node_modules/**',
38
- ]);
39
- expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**');
40
- });
41
45
  });
42
46
 
43
47
  describe('keepsNestedNodeModules', () => {
44
- it('is only disabled by the boolean false', () => {
45
- expect(keepsNestedNodeModules(OPT_OUT)).toBe(false);
48
+ it('is only enabled by the boolean true', () => {
49
+ expect(
50
+ keepsNestedNodeModules({ lambda: { keepNestedNodeModules: true } })
51
+ ).toBe(true);
46
52
  expect(
47
53
  keepsNestedNodeModules({
48
- lambda: { keepNestedNodeModules: true },
54
+ lambda: { keepNestedNodeModules: 'true' },
49
55
  })
50
- ).toBe(true);
51
- expect(keepsNestedNodeModules({ lambda: {} })).toBe(true);
52
- expect(keepsNestedNodeModules({})).toBe(true);
53
- expect(keepsNestedNodeModules()).toBe(true);
56
+ ).toBe(false);
57
+ expect(keepsNestedNodeModules({ lambda: {} })).toBe(false);
58
+ expect(keepsNestedNodeModules({})).toBe(false);
59
+ expect(keepsNestedNodeModules()).toBe(false);
54
60
  });
55
61
  });
@@ -9,11 +9,7 @@
9
9
 
10
10
  const path = require('path');
11
11
  const fs = require('fs');
12
- const {
13
- buildPrismaLayer,
14
- layerBuildInputs,
15
- } = require('../../../scripts/build-prisma-layer');
16
- const { resolveLambdaArchitecture } = require('../lambda-architectures');
12
+ const { buildPrismaLayer } = require('../../../scripts/build-prisma-layer');
17
13
 
18
14
  /**
19
15
  * Check if a process is still running
@@ -30,48 +26,6 @@ function isProcessRunning(pid) {
30
26
  }
31
27
  }
32
28
 
33
- const LEGACY_MARKER_TARGET = 'rhel-openssl-3.0.x';
34
-
35
- /**
36
- * The inputs a completion marker records. A marker written before the
37
- * marker became JSON recorded nothing, and every layer then held the rhel
38
- * engine; its versions are unknown, so it never matches and the layer is
39
- * rebuilt once.
40
- * @param {string} markerText
41
- * @returns {{ prismaBinaryTarget: string, clientPackages: string[]|null, coreVersion: string|null, prismaClientVersion: string|null }}
42
- */
43
- function parseLayerMarker(markerText) {
44
- try {
45
- const marker = JSON.parse(markerText);
46
- return {
47
- prismaBinaryTarget: marker.prismaBinaryTarget,
48
- clientPackages: marker.clientPackages,
49
- coreVersion: marker.coreVersion,
50
- prismaClientVersion: marker.prismaClientVersion,
51
- };
52
- } catch {
53
- // A marker written before the JSON format is plain text: treat it as a legacy build
54
- return {
55
- prismaBinaryTarget: LEGACY_MARKER_TARGET,
56
- clientPackages: null,
57
- coreVersion: null,
58
- prismaClientVersion: null,
59
- };
60
- }
61
- }
62
-
63
- function sameLayerInputs(a, b) {
64
- return (
65
- a.prismaBinaryTarget === b.prismaBinaryTarget &&
66
- a.coreVersion === b.coreVersion &&
67
- a.prismaClientVersion === b.prismaClientVersion &&
68
- Array.isArray(a.clientPackages) &&
69
- Array.isArray(b.clientPackages) &&
70
- a.clientPackages.length === b.clientPackages.length &&
71
- a.clientPackages.every((pkg, i) => pkg === b.clientPackages[i])
72
- );
73
- }
74
-
75
29
  /**
76
30
  * Ensure Prisma Lambda Layer exists
77
31
  *
@@ -80,38 +34,23 @@ function sameLayerInputs(a, b) {
80
34
  * Prisma CLI is bundled separately in the dbMigrate function.
81
35
  *
82
36
  * Domain Concept: Build Completion State & Process Locking
83
- * - Uses .build-complete marker file to track successful builds; it records
84
- * the inputs the layer was built from, and a built layer is reused only
85
- * when they match the requested ones
37
+ * - Uses .build-complete marker file to track successful builds
86
38
  * - Uses .build-lock PID file to prevent concurrent builds
87
39
  * - Waits for active builds to complete before starting new one
88
40
  * - Cleans stale locks and incomplete builds before retry
89
41
  *
90
- * @param {Object} options
91
- * @param {Object} options.databaseConfig - Database configuration from app definition
92
- * @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
42
+ * @param {Object} databaseConfig - Database configuration from app definition
93
43
  * @returns {Promise<void>}
94
44
  * @throws {Error} If layer build fails
95
45
  */
96
- async function ensurePrismaLayerExists({
97
- databaseConfig = {},
98
- prismaBinaryTarget = resolveLambdaArchitecture().prismaBinaryTarget,
99
- } = {}) {
46
+ async function ensurePrismaLayerExists(databaseConfig = {}) {
100
47
  const projectRoot = process.cwd();
101
48
  const layerPath = path.join(projectRoot, 'layers/prisma');
102
49
  const completionMarkerPath = path.join(layerPath, '.build-complete');
103
50
  const lockFilePath = path.join(layerPath, '.build-lock');
104
- const inputs = layerBuildInputs({ databaseConfig, prismaBinaryTarget });
105
-
106
- const builtLayerMatches = () =>
107
- fs.existsSync(completionMarkerPath) &&
108
- sameLayerInputs(
109
- parseLayerMarker(fs.readFileSync(completionMarkerPath, 'utf-8')),
110
- inputs
111
- );
112
51
 
113
52
  // Check if build is complete (marker exists)
114
- if (builtLayerMatches()) {
53
+ if (fs.existsSync(completionMarkerPath)) {
115
54
  console.log('✓ Prisma Lambda Layer already exists at', layerPath);
116
55
  return;
117
56
  }
@@ -129,13 +68,8 @@ async function ensurePrismaLayerExists({
129
68
 
130
69
  // Check if build completed
131
70
  if (fs.existsSync(completionMarkerPath)) {
132
- if (builtLayerMatches()) {
133
- console.log('✓ Concurrent build completed successfully');
134
- return;
135
- }
136
- console.log('⚠ Concurrent build completed for other inputs - rebuilding');
137
- fs.rmSync(lockFilePath, { force: true });
138
- break;
71
+ console.log('✓ Concurrent build completed successfully');
72
+ return;
139
73
  }
140
74
 
141
75
  // Check if process died
@@ -147,16 +81,14 @@ async function ensurePrismaLayerExists({
147
81
  }
148
82
 
149
83
  // Timeout - check one final time
150
- if (builtLayerMatches()) {
84
+ if (fs.existsSync(completionMarkerPath)) {
151
85
  console.log('✓ Concurrent build completed');
152
86
  return;
153
87
  }
154
88
 
155
89
  // Still locked after 60s - remove stale lock
156
- if (fs.existsSync(lockFilePath)) {
157
- console.log('⚠ Build timeout - removing stale lock and rebuilding');
158
- fs.rmSync(lockFilePath, { force: true });
159
- }
90
+ console.log('⚠ Build timeout - removing stale lock and rebuilding');
91
+ fs.rmSync(lockFilePath, { force: true });
160
92
  } else {
161
93
  // Stale lock file (process not running)
162
94
  console.log(`⚠ Stale lock file detected (PID ${lockPid} not running) - cleaning up`);
@@ -167,8 +99,6 @@ async function ensurePrismaLayerExists({
167
99
  // Check if incomplete build exists (directory without marker)
168
100
  if (fs.existsSync(layerPath) && !fs.existsSync(completionMarkerPath)) {
169
101
  console.log('⚠ Incomplete Prisma layer detected - will be cleaned by buildPrismaLayer()');
170
- } else if (fs.existsSync(completionMarkerPath)) {
171
- console.log(`⚠ Built Prisma layer does not match ${JSON.stringify(inputs)} - rebuilding`);
172
102
  }
173
103
 
174
104
  // Build layer
@@ -189,21 +119,12 @@ async function ensurePrismaLayerExists({
189
119
 
190
120
  try {
191
121
  // Build layer WITHOUT CLI (runtime only for minimal size)
192
- await buildPrismaLayer({ databaseConfig, prismaBinaryTarget });
122
+ await buildPrismaLayer(databaseConfig);
193
123
 
194
124
  // Create completion marker
195
125
  fs.writeFileSync(
196
126
  completionMarkerPath,
197
- JSON.stringify(
198
- {
199
- ...inputs,
200
- builtAt: new Date().toISOString(),
201
- node: process.version,
202
- platform: process.platform,
203
- },
204
- null,
205
- 2
206
- )
127
+ `Build completed: ${new Date().toISOString()}\nNode: ${process.version}\nPlatform: ${process.platform}\n`
207
128
  );
208
129
 
209
130
  console.log('✓ Prisma Lambda Layer built successfully (~10-15MB)\n');
@@ -234,6 +155,5 @@ async function ensurePrismaLayerExists({
234
155
 
235
156
  module.exports = {
236
157
  ensurePrismaLayerExists,
237
- parseLayerMarker,
238
158
  };
239
159