@friggframework/devtools 2.0.0-next.127 → 2.0.0-next.128
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/infrastructure/README.md +32 -5
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +3 -0
- package/infrastructure/__tests__/postgres-config.test.js +3 -0
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +3 -0
- package/infrastructure/__tests__/scoped-environment.test.js +3 -0
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
- package/infrastructure/__tests__/template-generation.test.js +3 -0
- package/infrastructure/app-definition-schema-contract.test.js +5 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +22 -6
- package/infrastructure/domains/database/migration-builder.js +21 -2
- package/infrastructure/domains/database/migration-builder.test.js +61 -6
- package/infrastructure/domains/database/migration-engines.js +93 -0
- package/infrastructure/domains/database/migration-engines.test.js +142 -0
- package/infrastructure/domains/integration/integration-builder.js +2 -0
- package/infrastructure/domains/integration/integration-builder.test.js +22 -6
- package/infrastructure/domains/shared/environment-builder.js +31 -5
- package/infrastructure/domains/shared/environment-builder.test.js +93 -7
- package/infrastructure/domains/shared/lambda-architectures.js +113 -0
- package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +13 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +51 -4
- package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
- package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
- package/infrastructure/infrastructure-composer.js +12 -1
- package/infrastructure/infrastructure-composer.test.js +71 -0
- package/infrastructure/scripts/build-prisma-layer.js +136 -50
- package/infrastructure/scripts/build-prisma-layer.test.js +100 -0
- package/package.json +7 -7
|
@@ -12,9 +12,19 @@ const { ensurePrismaLayerExists } = require('./prisma-layer-manager');
|
|
|
12
12
|
jest.mock('fs');
|
|
13
13
|
jest.mock('../../../scripts/build-prisma-layer', () => ({
|
|
14
14
|
buildPrismaLayer: jest.fn(),
|
|
15
|
+
layerBuildInputs: jest.fn(),
|
|
15
16
|
}));
|
|
16
17
|
|
|
17
|
-
const { buildPrismaLayer } = require('../../../scripts/build-prisma-layer');
|
|
18
|
+
const { buildPrismaLayer, layerBuildInputs } = require('../../../scripts/build-prisma-layer');
|
|
19
|
+
|
|
20
|
+
const inputsFor = ({ prismaBinaryTarget = 'rhel-openssl-3.0.x' } = {}) => ({
|
|
21
|
+
prismaBinaryTarget,
|
|
22
|
+
clientPackages: ['generated/prisma-postgresql'],
|
|
23
|
+
coreVersion: '2.0.0-next.120',
|
|
24
|
+
prismaClientVersion: '6.19.3',
|
|
25
|
+
});
|
|
26
|
+
const markerFor = (overrides = {}) =>
|
|
27
|
+
JSON.stringify({ ...inputsFor(), ...overrides });
|
|
18
28
|
|
|
19
29
|
// Helper to mock fs methods for different scenarios
|
|
20
30
|
const mockFs = {
|
|
@@ -50,6 +60,8 @@ describe('Prisma Layer Manager', () => {
|
|
|
50
60
|
originalCwd = process.cwd;
|
|
51
61
|
process.cwd = jest.fn().mockReturnValue('/project');
|
|
52
62
|
jest.clearAllMocks();
|
|
63
|
+
layerBuildInputs.mockImplementation(inputsFor);
|
|
64
|
+
fs.readFileSync = jest.fn((p) => (p.endsWith('.build-lock') ? '99999' : markerFor()));
|
|
53
65
|
});
|
|
54
66
|
|
|
55
67
|
afterEach(() => {
|
|
@@ -87,9 +99,27 @@ describe('Prisma Layer Manager', () => {
|
|
|
87
99
|
postgres: { enable: true },
|
|
88
100
|
};
|
|
89
101
|
|
|
90
|
-
await ensurePrismaLayerExists(databaseConfig);
|
|
102
|
+
await ensurePrismaLayerExists({ databaseConfig });
|
|
103
|
+
|
|
104
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
105
|
+
databaseConfig,
|
|
106
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should pass the Prisma binary target of the deployed architecture to buildPrismaLayer', async () => {
|
|
111
|
+
fs.existsSync = jest.fn().mockReturnValue(false);
|
|
112
|
+
buildPrismaLayer.mockResolvedValue();
|
|
113
|
+
|
|
114
|
+
await ensurePrismaLayerExists({
|
|
115
|
+
databaseConfig: {},
|
|
116
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
117
|
+
});
|
|
91
118
|
|
|
92
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith(
|
|
119
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
120
|
+
databaseConfig: {},
|
|
121
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
122
|
+
});
|
|
93
123
|
});
|
|
94
124
|
|
|
95
125
|
it('should handle build errors and rethrow', async () => {
|
|
@@ -105,7 +135,10 @@ describe('Prisma Layer Manager', () => {
|
|
|
105
135
|
|
|
106
136
|
await ensurePrismaLayerExists();
|
|
107
137
|
|
|
108
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
138
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
139
|
+
databaseConfig: {},
|
|
140
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
141
|
+
});
|
|
109
142
|
});
|
|
110
143
|
|
|
111
144
|
it('should use correct layer path relative to project root', async () => {
|
|
@@ -123,6 +156,7 @@ describe('Prisma Layer Manager', () => {
|
|
|
123
156
|
|
|
124
157
|
it('should log success when layer already exists', async () => {
|
|
125
158
|
fs.existsSync = jest.fn().mockReturnValue(true);
|
|
159
|
+
fs.readFileSync = jest.fn().mockReturnValue(markerFor());
|
|
126
160
|
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
127
161
|
|
|
128
162
|
await ensurePrismaLayerExists();
|
|
@@ -169,6 +203,120 @@ describe('Prisma Layer Manager', () => {
|
|
|
169
203
|
consoleErrorSpy.mockRestore();
|
|
170
204
|
});
|
|
171
205
|
|
|
206
|
+
describe('layer cache keyed by its inputs', () => {
|
|
207
|
+
const existingMarker = () => {
|
|
208
|
+
fs.existsSync = jest.fn((p) => p.endsWith('.build-complete') || p.endsWith('layers/prisma'));
|
|
209
|
+
fs.writeFileSync = jest.fn();
|
|
210
|
+
fs.rmSync = jest.fn();
|
|
211
|
+
buildPrismaLayer.mockResolvedValue();
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
it('reuses the layer when the marker records the same target, clients and versions', async () => {
|
|
215
|
+
existingMarker();
|
|
216
|
+
fs.readFileSync = jest.fn().mockReturnValue(markerFor());
|
|
217
|
+
|
|
218
|
+
await ensurePrismaLayerExists({ prismaBinaryTarget: 'rhel-openssl-3.0.x' });
|
|
219
|
+
|
|
220
|
+
expect(buildPrismaLayer).not.toHaveBeenCalled();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('rebuilds when the deployed architecture changes the target', async () => {
|
|
224
|
+
existingMarker();
|
|
225
|
+
fs.readFileSync = jest.fn().mockReturnValue(markerFor());
|
|
226
|
+
|
|
227
|
+
await ensurePrismaLayerExists({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' });
|
|
228
|
+
|
|
229
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
230
|
+
databaseConfig: {},
|
|
231
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('rebuilds when the installed core version changes', async () => {
|
|
236
|
+
existingMarker();
|
|
237
|
+
fs.readFileSync = jest.fn().mockReturnValue(markerFor({ coreVersion: '2.0.0-next.105' }));
|
|
238
|
+
|
|
239
|
+
await ensurePrismaLayerExists();
|
|
240
|
+
|
|
241
|
+
expect(buildPrismaLayer).toHaveBeenCalledTimes(1);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('rebuilds when the client set changes', async () => {
|
|
245
|
+
existingMarker();
|
|
246
|
+
fs.readFileSync = jest.fn().mockReturnValue(
|
|
247
|
+
markerFor({ clientPackages: ['generated/prisma-postgresql', 'generated/prisma-mongodb'] })
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
await ensurePrismaLayerExists();
|
|
251
|
+
|
|
252
|
+
expect(buildPrismaLayer).toHaveBeenCalledTimes(1);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('rebuilds over a legacy plain-text marker, which records no target or versions', async () => {
|
|
256
|
+
existingMarker();
|
|
257
|
+
fs.readFileSync = jest.fn().mockReturnValue(
|
|
258
|
+
'Build completed: 2026-01-01T00:00:00.000Z\nNode: v22.0.0\nPlatform: darwin\n'
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
await ensurePrismaLayerExists();
|
|
262
|
+
|
|
263
|
+
expect(buildPrismaLayer).toHaveBeenCalledTimes(1);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('writes the inputs into the marker after a build', async () => {
|
|
267
|
+
mockFs.noBuild();
|
|
268
|
+
buildPrismaLayer.mockResolvedValue();
|
|
269
|
+
|
|
270
|
+
await ensurePrismaLayerExists({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' });
|
|
271
|
+
|
|
272
|
+
const [, written] = fs.writeFileSync.mock.calls.find(
|
|
273
|
+
([p]) => p === '/project/layers/prisma/.build-complete'
|
|
274
|
+
);
|
|
275
|
+
expect(JSON.parse(written)).toEqual(
|
|
276
|
+
expect.objectContaining(inputsFor({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' }))
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('rebuilds after waiting on a concurrent build that finished for the other target', async () => {
|
|
281
|
+
jest.useFakeTimers();
|
|
282
|
+
let completionMarkerExists = false;
|
|
283
|
+
fs.existsSync = jest.fn((p) => {
|
|
284
|
+
if (p.endsWith('.build-complete')) return completionMarkerExists;
|
|
285
|
+
if (p.endsWith('.build-lock')) return !completionMarkerExists;
|
|
286
|
+
if (p.endsWith('layers/prisma')) return true;
|
|
287
|
+
return false;
|
|
288
|
+
});
|
|
289
|
+
fs.readFileSync = jest.fn((p) =>
|
|
290
|
+
p.endsWith('.build-lock') ? '12345' : markerFor({ prismaBinaryTarget: 'rhel-openssl-3.0.x' })
|
|
291
|
+
);
|
|
292
|
+
fs.writeFileSync = jest.fn();
|
|
293
|
+
fs.mkdirSync = jest.fn();
|
|
294
|
+
fs.rmSync = jest.fn();
|
|
295
|
+
buildPrismaLayer.mockResolvedValue();
|
|
296
|
+
const originalKill = process.kill;
|
|
297
|
+
let polls = 0;
|
|
298
|
+
process.kill = jest.fn(() => {
|
|
299
|
+
if (++polls >= 3) completionMarkerExists = true;
|
|
300
|
+
return true;
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const promise = ensurePrismaLayerExists({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' });
|
|
304
|
+
for (let i = 0; i < 5; i++) {
|
|
305
|
+
jest.advanceTimersByTime(1000);
|
|
306
|
+
await Promise.resolve();
|
|
307
|
+
}
|
|
308
|
+
await promise;
|
|
309
|
+
|
|
310
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
311
|
+
databaseConfig: {},
|
|
312
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
process.kill = originalKill;
|
|
316
|
+
jest.useRealTimers();
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
172
320
|
describe('Concurrent Build Protection', () => {
|
|
173
321
|
it('should skip build if completion marker exists (TDD)', async () => {
|
|
174
322
|
mockFs.completedBuild();
|
|
@@ -191,7 +339,9 @@ describe('Prisma Layer Manager', () => {
|
|
|
191
339
|
if (path.endsWith('layers/prisma')) return true;
|
|
192
340
|
return false;
|
|
193
341
|
});
|
|
194
|
-
fs.readFileSync = jest.fn(
|
|
342
|
+
fs.readFileSync = jest.fn((p) =>
|
|
343
|
+
p.endsWith('.build-lock') ? activePid.toString() : markerFor()
|
|
344
|
+
);
|
|
195
345
|
fs.writeFileSync = jest.fn();
|
|
196
346
|
fs.rmSync = jest.fn();
|
|
197
347
|
|
|
@@ -405,7 +555,9 @@ describe('Prisma Layer Manager', () => {
|
|
|
405
555
|
if (path.endsWith('layers/prisma')) return true;
|
|
406
556
|
return false;
|
|
407
557
|
});
|
|
408
|
-
fs.readFileSync = jest.fn(
|
|
558
|
+
fs.readFileSync = jest.fn((p) =>
|
|
559
|
+
p.endsWith('.build-lock') ? '12345' : markerFor()
|
|
560
|
+
);
|
|
409
561
|
fs.writeFileSync = jest.fn();
|
|
410
562
|
fs.rmSync = jest.fn();
|
|
411
563
|
|
|
@@ -61,6 +61,8 @@ function applySsmPreloadNodeOptions(appDefinition, functions, providerEnvironmen
|
|
|
61
61
|
const { modifyHandlerPaths } = require('./domains/shared/utilities/handler-path-resolver');
|
|
62
62
|
const { createBaseDefinition } = require('./domains/shared/utilities/base-definition-factory');
|
|
63
63
|
const { ensurePrismaLayerExists } = require('./domains/shared/utilities/prisma-layer-manager');
|
|
64
|
+
const { resolveLambdaArchitecture } = require('./domains/shared/lambda-architectures');
|
|
65
|
+
const { ensureMigrationEngines } = require('./domains/database/migration-engines');
|
|
64
66
|
const { validateAndCleanPlugins, validatePackagingConfiguration } = require('./domains/shared/validation/plugin-validator');
|
|
65
67
|
|
|
66
68
|
/**
|
|
@@ -74,14 +76,23 @@ const composeServerlessDefinition = async (AppDefinition) => {
|
|
|
74
76
|
|
|
75
77
|
// Determine if deployment should use Prisma Lambda Layer (default: true)
|
|
76
78
|
const usePrismaLayer = AppDefinition.usePrismaLambdaLayer !== false;
|
|
79
|
+
const { prismaBinaryTarget } = resolveLambdaArchitecture(AppDefinition);
|
|
77
80
|
|
|
78
81
|
// Ensure Prisma layer exists only when configured to use it
|
|
79
82
|
if (usePrismaLayer) {
|
|
80
|
-
await ensurePrismaLayerExists(
|
|
83
|
+
await ensurePrismaLayerExists({
|
|
84
|
+
databaseConfig: AppDefinition.database || {},
|
|
85
|
+
prismaBinaryTarget,
|
|
86
|
+
});
|
|
81
87
|
} else {
|
|
82
88
|
console.log('📦 Skipping Prisma Lambda Layer (usePrismaLambdaLayer=false - bundling Prisma with functions)');
|
|
83
89
|
}
|
|
84
90
|
|
|
91
|
+
// The migration worker ships its own Prisma CLI engines (layer or not)
|
|
92
|
+
if (new MigrationBuilder().shouldExecute(AppDefinition)) {
|
|
93
|
+
await ensureMigrationEngines({ prismaBinaryTarget });
|
|
94
|
+
}
|
|
95
|
+
|
|
85
96
|
// Create orchestrator with all domain builders
|
|
86
97
|
const orchestrator = new BuilderOrchestrator([
|
|
87
98
|
new VpcBuilder(),
|
|
@@ -40,6 +40,9 @@ jest.mock('./domains/shared/resource-discovery', () => {
|
|
|
40
40
|
jest.mock('./domains/shared/utilities/prisma-layer-manager', () => ({
|
|
41
41
|
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
42
42
|
}));
|
|
43
|
+
jest.mock('./domains/database/migration-engines', () => ({
|
|
44
|
+
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
45
|
+
}));
|
|
43
46
|
|
|
44
47
|
const { gatherDiscoveredResources } = require('./domains/shared/resource-discovery');
|
|
45
48
|
|
|
@@ -1474,6 +1477,74 @@ describe('composeServerlessDefinition', () => {
|
|
|
1474
1477
|
});
|
|
1475
1478
|
});
|
|
1476
1479
|
|
|
1480
|
+
describe('Lambda architecture (architecture)', () => {
|
|
1481
|
+
const appDefinition = (architecture) => ({
|
|
1482
|
+
name: 'arch-app',
|
|
1483
|
+
integrations: [{ Definition: { name: 'crm' } }],
|
|
1484
|
+
...(architecture && { architecture }),
|
|
1485
|
+
});
|
|
1486
|
+
|
|
1487
|
+
beforeEach(() => {
|
|
1488
|
+
process.argv = ['node', 'test'];
|
|
1489
|
+
gatherDiscoveredResources.mockResolvedValue(createDiscoveryResponse());
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1492
|
+
it('an explicit x86_64 only adds provider.architecture and the layer compatibleArchitectures to the unset template', async () => {
|
|
1493
|
+
const unset = await composeServerlessDefinition(appDefinition());
|
|
1494
|
+
const explicit = await composeServerlessDefinition(appDefinition('x86_64'));
|
|
1495
|
+
|
|
1496
|
+
expect(explicit.provider.architecture).toBe('x86_64');
|
|
1497
|
+
expect(explicit.layers.prisma.compatibleArchitectures).toEqual(['x86_64']);
|
|
1498
|
+
|
|
1499
|
+
delete explicit.provider.architecture;
|
|
1500
|
+
delete explicit.layers.prisma.compatibleArchitectures;
|
|
1501
|
+
expect(explicit).toEqual(unset);
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
it('fetches the migration worker engines for the deployed architecture before packaging', async () => {
|
|
1505
|
+
const { ensureMigrationEngines } = require('./domains/database/migration-engines');
|
|
1506
|
+
|
|
1507
|
+
await composeServerlessDefinition(appDefinition('arm64'));
|
|
1508
|
+
|
|
1509
|
+
expect(ensureMigrationEngines).toHaveBeenCalledWith({
|
|
1510
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
1511
|
+
});
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
it('fetches no migration engines when there is no migration worker (PostgreSQL disabled)', async () => {
|
|
1515
|
+
const { ensureMigrationEngines } = require('./domains/database/migration-engines');
|
|
1516
|
+
ensureMigrationEngines.mockClear();
|
|
1517
|
+
|
|
1518
|
+
await composeServerlessDefinition({
|
|
1519
|
+
...appDefinition('arm64'),
|
|
1520
|
+
database: { postgres: { enable: false }, mongoDB: { enable: true } },
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
expect(ensureMigrationEngines).not.toHaveBeenCalled();
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
it('builds the Prisma layer for the engine of the deployed architecture', async () => {
|
|
1527
|
+
const { ensurePrismaLayerExists } = require('./domains/shared/utilities/prisma-layer-manager');
|
|
1528
|
+
|
|
1529
|
+
await composeServerlessDefinition(appDefinition('arm64'));
|
|
1530
|
+
|
|
1531
|
+
expect(ensurePrismaLayerExists).toHaveBeenCalledWith({
|
|
1532
|
+
databaseConfig: {},
|
|
1533
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
1534
|
+
});
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
it('arm64 sets provider.architecture, which osls applies to every function, and the layer compatibleArchitectures', async () => {
|
|
1538
|
+
const result = await composeServerlessDefinition(appDefinition('arm64'));
|
|
1539
|
+
|
|
1540
|
+
expect(result.provider.architecture).toBe('arm64');
|
|
1541
|
+
expect(result.layers.prisma.compatibleArchitectures).toEqual(['arm64']);
|
|
1542
|
+
for (const fn of Object.values(result.functions)) {
|
|
1543
|
+
expect(fn.architecture).toBeUndefined();
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
});
|
|
1547
|
+
|
|
1477
1548
|
describe('applySsmPreloadNodeOptions', () => {
|
|
1478
1549
|
const appDefinition = {
|
|
1479
1550
|
ssm: { enable: true },
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
const fs = require('fs-extra');
|
|
35
35
|
const path = require('path');
|
|
36
36
|
const { execSync } = require('child_process');
|
|
37
|
+
const {
|
|
38
|
+
resolveLambdaArchitecture,
|
|
39
|
+
} = require('../domains/shared/lambda-architectures');
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* Find @friggframework/core package, handling workspace hoisting
|
|
@@ -93,6 +96,31 @@ function getGeneratedClientPackages(databaseConfig = {}) {
|
|
|
93
96
|
return packages;
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Everything the layer contents depend on. The layer manager keys its cache
|
|
101
|
+
* on this, so a change in any of them rebuilds the layer.
|
|
102
|
+
* @param {Object} options
|
|
103
|
+
* @param {Object} options.databaseConfig - Database configuration from AppDefinition.database
|
|
104
|
+
* @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
|
|
105
|
+
* @returns {{ prismaBinaryTarget: string, clientPackages: string[], coreVersion: string, prismaClientVersion: string }}
|
|
106
|
+
*/
|
|
107
|
+
function layerBuildInputs({
|
|
108
|
+
databaseConfig = {},
|
|
109
|
+
prismaBinaryTarget = resolveLambdaArchitecture().prismaBinaryTarget,
|
|
110
|
+
} = {}) {
|
|
111
|
+
return {
|
|
112
|
+
prismaBinaryTarget,
|
|
113
|
+
clientPackages: getGeneratedClientPackages(databaseConfig),
|
|
114
|
+
coreVersion: fs.readJsonSync(path.join(CORE_PACKAGE_PATH, 'package.json'))
|
|
115
|
+
.version,
|
|
116
|
+
prismaClientVersion: fs.readJsonSync(
|
|
117
|
+
require.resolve('@prisma/client/package.json', {
|
|
118
|
+
paths: [CORE_PACKAGE_PATH],
|
|
119
|
+
})
|
|
120
|
+
).version,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
96
124
|
function getMigrationsPackages(clientPackages) {
|
|
97
125
|
return clientPackages.map((pkg) => ({
|
|
98
126
|
dbType: pkg.replace('generated/prisma-', ''),
|
|
@@ -158,15 +186,34 @@ const CORE_PACKAGE_PATH = findCorePackage(PROJECT_ROOT);
|
|
|
158
186
|
const LAYER_OUTPUT_PATH = path.join(PROJECT_ROOT, 'layers/prisma');
|
|
159
187
|
const LAYER_NODE_MODULES = path.join(LAYER_OUTPUT_PATH, 'nodejs/node_modules');
|
|
160
188
|
|
|
161
|
-
// Binary patterns
|
|
189
|
+
// Binary patterns no Lambda architecture runs
|
|
162
190
|
const BINARY_PATTERNS_TO_REMOVE = [
|
|
163
191
|
'*darwin*',
|
|
164
192
|
'*debian*',
|
|
165
|
-
'*linux-arm*',
|
|
166
193
|
'*linux-musl*',
|
|
167
194
|
'*windows*',
|
|
168
195
|
];
|
|
169
196
|
|
|
197
|
+
const ENGINE_FILE_PREFIXES = [
|
|
198
|
+
'libquery_engine-',
|
|
199
|
+
'query-engine-',
|
|
200
|
+
'schema-engine-',
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Engine files built for a target other than the one the layer deploys to
|
|
205
|
+
* @param {string[]} fileNames - Basenames found in the layer
|
|
206
|
+
* @param {string} prismaBinaryTarget - The engine the deployed architecture loads
|
|
207
|
+
* @returns {string[]}
|
|
208
|
+
*/
|
|
209
|
+
function engineFilesToRemove(fileNames, prismaBinaryTarget) {
|
|
210
|
+
return fileNames.filter(
|
|
211
|
+
(name) =>
|
|
212
|
+
ENGINE_FILE_PREFIXES.some((prefix) => name.startsWith(prefix)) &&
|
|
213
|
+
!name.includes(prismaBinaryTarget)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
170
217
|
// Files to remove for size optimization
|
|
171
218
|
const FILES_TO_REMOVE = [
|
|
172
219
|
'*.map', // Source maps (37MB savings)
|
|
@@ -276,21 +323,15 @@ async function installPrismaPackages() {
|
|
|
276
323
|
await fs.writeJson(packageJsonPath, layerPackageJson, { spaces: 2 });
|
|
277
324
|
logSuccess('Created layer package.json');
|
|
278
325
|
|
|
279
|
-
//
|
|
280
|
-
//
|
|
281
|
-
log('Installing @prisma/client
|
|
326
|
+
// The runtime client has no engine postinstall; the query engines come
|
|
327
|
+
// from the generated clients copied out of @friggframework/core.
|
|
328
|
+
log('Installing @prisma/client...');
|
|
282
329
|
try {
|
|
283
|
-
const env = {
|
|
284
|
-
...process.env,
|
|
285
|
-
PRISMA_CLI_BINARY_TARGETS: 'rhel-openssl-3.0.x',
|
|
286
|
-
};
|
|
287
|
-
|
|
288
330
|
execSync('npm install --omit=dev --no-package-lock', {
|
|
289
331
|
cwd: path.join(LAYER_OUTPUT_PATH, 'nodejs'),
|
|
290
332
|
stdio: 'inherit',
|
|
291
|
-
env,
|
|
292
333
|
});
|
|
293
|
-
logSuccess('Prisma packages installed
|
|
334
|
+
logSuccess('Prisma packages installed');
|
|
294
335
|
} catch (error) {
|
|
295
336
|
throw new Error(`Failed to install Prisma packages: ${error.message}`);
|
|
296
337
|
}
|
|
@@ -466,23 +507,40 @@ async function removeUnnecessaryFiles() {
|
|
|
466
507
|
}
|
|
467
508
|
|
|
468
509
|
/**
|
|
469
|
-
* Remove
|
|
510
|
+
* Remove engine binaries the deployed architecture does not load
|
|
511
|
+
* @param {string} prismaBinaryTarget - The engine the deployed architecture loads
|
|
470
512
|
*/
|
|
471
|
-
async function
|
|
472
|
-
logStep(7,
|
|
513
|
+
async function removeForeignBinaries(prismaBinaryTarget) {
|
|
514
|
+
logStep(7, `Removing engine binaries other than ${prismaBinaryTarget}`);
|
|
473
515
|
|
|
474
516
|
let removedCount = 0;
|
|
475
517
|
let totalSize = 0;
|
|
476
518
|
|
|
477
|
-
|
|
519
|
+
const findPatterns = [
|
|
520
|
+
...BINARY_PATTERNS_TO_REMOVE,
|
|
521
|
+
...ENGINE_FILE_PREFIXES.map((prefix) => `${prefix}*`),
|
|
522
|
+
];
|
|
523
|
+
for (const pattern of findPatterns) {
|
|
478
524
|
try {
|
|
479
525
|
// Find files matching the pattern
|
|
480
526
|
const findCmd = `find "${LAYER_NODE_MODULES}" -name "${pattern}" 2>/dev/null || true`;
|
|
481
527
|
const files = execSync(findCmd, { encoding: 'utf8' })
|
|
482
528
|
.split('\n')
|
|
483
529
|
.filter((f) => f.trim());
|
|
530
|
+
const foreign = new Set(
|
|
531
|
+
engineFilesToRemove(
|
|
532
|
+
files.map((f) => path.basename(f)),
|
|
533
|
+
prismaBinaryTarget
|
|
534
|
+
)
|
|
535
|
+
);
|
|
484
536
|
|
|
485
537
|
for (const file of files) {
|
|
538
|
+
const isEngine = ENGINE_FILE_PREFIXES.some((prefix) =>
|
|
539
|
+
path.basename(file).startsWith(prefix)
|
|
540
|
+
);
|
|
541
|
+
if (isEngine && !foreign.has(path.basename(file))) {
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
486
544
|
if (await fs.pathExists(file)) {
|
|
487
545
|
const stats = await fs.stat(file);
|
|
488
546
|
totalSize += stats.size;
|
|
@@ -498,48 +556,59 @@ async function removeNonRhelBinaries() {
|
|
|
498
556
|
if (removedCount > 0) {
|
|
499
557
|
const sizeMB = (totalSize / (1024 * 1024)).toFixed(2);
|
|
500
558
|
logSuccess(
|
|
501
|
-
`Removed ${removedCount}
|
|
559
|
+
`Removed ${removedCount} foreign binaries (saved ${sizeMB} MB)`
|
|
502
560
|
);
|
|
503
561
|
} else {
|
|
504
|
-
log('No
|
|
562
|
+
log('No foreign binaries found to remove');
|
|
505
563
|
}
|
|
506
564
|
}
|
|
507
565
|
|
|
508
566
|
/**
|
|
509
|
-
* Verify
|
|
510
|
-
*
|
|
567
|
+
* Verify each generated client holds the target query engine and no other
|
|
568
|
+
* Linux engine
|
|
569
|
+
* @param {string} layerNodeModules - The layer's nodejs/node_modules
|
|
570
|
+
* @param {string} prismaBinaryTarget - The engine the deployed architecture loads
|
|
571
|
+
* @param {Array} clientPackages - Generated client packages copied into the layer
|
|
572
|
+
* @param {string} coreVersion - The @friggframework/core the clients came from
|
|
511
573
|
*/
|
|
512
|
-
async function
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
574
|
+
async function verifyTargetBinaries(
|
|
575
|
+
layerNodeModules,
|
|
576
|
+
prismaBinaryTarget,
|
|
577
|
+
clientPackages,
|
|
578
|
+
coreVersion
|
|
579
|
+
) {
|
|
580
|
+
logStep(8, `Verifying ${prismaBinaryTarget} query engines are present`);
|
|
581
|
+
|
|
582
|
+
const expectedEngine = `libquery_engine-${prismaBinaryTarget}.so.node`;
|
|
583
|
+
for (const pkg of clientPackages) {
|
|
584
|
+
const clientDir = path.join(layerNodeModules, pkg);
|
|
585
|
+
const files = (await fs.pathExists(clientDir))
|
|
586
|
+
? await fs.readdir(clientDir)
|
|
587
|
+
: [];
|
|
520
588
|
|
|
521
|
-
if (
|
|
589
|
+
if (!files.includes(expectedEngine)) {
|
|
522
590
|
throw new Error(
|
|
523
|
-
|
|
524
|
-
|
|
591
|
+
`Binary verification failed: ${pkg} has no ${expectedEngine}.\n` +
|
|
592
|
+
`@friggframework/core ${coreVersion} did not generate the ${prismaBinaryTarget} engine. ` +
|
|
593
|
+
`Upgrade to a core release whose Prisma schemas list ${prismaBinaryTarget} in binaryTargets.`
|
|
525
594
|
);
|
|
526
595
|
}
|
|
527
596
|
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
597
|
+
const otherEngines = engineFilesToRemove(files, prismaBinaryTarget);
|
|
598
|
+
if (otherEngines.length > 0) {
|
|
599
|
+
throw new Error(
|
|
600
|
+
`Binary verification failed: ${pkg} still holds ${otherEngines.join(
|
|
601
|
+
', '
|
|
602
|
+
)} next to ${expectedEngine}.`
|
|
603
|
+
);
|
|
604
|
+
}
|
|
534
605
|
|
|
535
|
-
|
|
536
|
-
rhelFiles.forEach((file) => {
|
|
537
|
-
const relativePath = path.relative(LAYER_NODE_MODULES, file);
|
|
538
|
-
log(` - ${relativePath}`, 'reset');
|
|
539
|
-
});
|
|
540
|
-
} catch (error) {
|
|
541
|
-
throw new Error(`Binary verification failed: ${error.message}`);
|
|
606
|
+
log(` - ${pkg}/${expectedEngine}`, 'reset');
|
|
542
607
|
}
|
|
608
|
+
|
|
609
|
+
logSuccess(
|
|
610
|
+
`Each of ${clientPackages.length} client(s) holds only ${expectedEngine}`
|
|
611
|
+
);
|
|
543
612
|
}
|
|
544
613
|
|
|
545
614
|
/**
|
|
@@ -607,7 +676,7 @@ async function displayLayerSummary() {
|
|
|
607
676
|
log(' - generated/prisma-postgresql (PostgreSQL client)', 'reset');
|
|
608
677
|
log('\nPackages EXCLUDED for minimal size:', 'bright');
|
|
609
678
|
log(' - prisma CLI (excluded - only in dbMigrate function)', 'yellow');
|
|
610
|
-
log(' - @prisma/engines (minimal - only
|
|
679
|
+
log(' - @prisma/engines (minimal - only the target engine)', 'yellow');
|
|
611
680
|
|
|
612
681
|
log('\nNext steps:', 'bright');
|
|
613
682
|
log(
|
|
@@ -626,9 +695,14 @@ async function displayLayerSummary() {
|
|
|
626
695
|
|
|
627
696
|
/**
|
|
628
697
|
* Main build function
|
|
629
|
-
* @param {Object}
|
|
698
|
+
* @param {Object} options
|
|
699
|
+
* @param {Object} options.databaseConfig - Database configuration from AppDefinition.database
|
|
700
|
+
* @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
|
|
630
701
|
*/
|
|
631
|
-
async function buildPrismaLayer(
|
|
702
|
+
async function buildPrismaLayer({
|
|
703
|
+
databaseConfig = {},
|
|
704
|
+
prismaBinaryTarget = resolveLambdaArchitecture().prismaBinaryTarget,
|
|
705
|
+
} = {}) {
|
|
632
706
|
const startTime = Date.now();
|
|
633
707
|
|
|
634
708
|
log('\n' + '='.repeat(60), 'bright');
|
|
@@ -638,7 +712,11 @@ async function buildPrismaLayer(databaseConfig = {}) {
|
|
|
638
712
|
// Log paths
|
|
639
713
|
log(`Project root: ${PROJECT_ROOT}`, 'reset');
|
|
640
714
|
log(`Core package: ${CORE_PACKAGE_PATH}`, 'reset');
|
|
641
|
-
log(`Layer output: ${LAYER_OUTPUT_PATH}
|
|
715
|
+
log(`Layer output: ${LAYER_OUTPUT_PATH}`, 'reset');
|
|
716
|
+
log(`Prisma binary target: ${prismaBinaryTarget}\n`, 'reset');
|
|
717
|
+
const coreVersion = fs.readJsonSync(
|
|
718
|
+
path.join(CORE_PACKAGE_PATH, 'package.json')
|
|
719
|
+
).version;
|
|
642
720
|
|
|
643
721
|
// Determine which database clients to include
|
|
644
722
|
const clientPackages = getGeneratedClientPackages(databaseConfig);
|
|
@@ -650,8 +728,13 @@ async function buildPrismaLayer(databaseConfig = {}) {
|
|
|
650
728
|
await copyPrismaPackages(clientPackages); // Copy generated clients from core
|
|
651
729
|
await copyMigrations(clientPackages); // Copy migrations from core
|
|
652
730
|
await removeUnnecessaryFiles(); // Remove source maps, docs, tests (37MB+)
|
|
653
|
-
await
|
|
654
|
-
await
|
|
731
|
+
await removeForeignBinaries(prismaBinaryTarget); // Keep only the target's engines
|
|
732
|
+
await verifyTargetBinaries(
|
|
733
|
+
LAYER_NODE_MODULES,
|
|
734
|
+
prismaBinaryTarget,
|
|
735
|
+
clientPackages,
|
|
736
|
+
coreVersion
|
|
737
|
+
);
|
|
655
738
|
await verifyLayerStructure(clientPackages); // Verify minimal runtime structure
|
|
656
739
|
await displayLayerSummary();
|
|
657
740
|
|
|
@@ -698,4 +781,7 @@ module.exports = {
|
|
|
698
781
|
getMigrationSourcePath,
|
|
699
782
|
getMigrationDestinationPath,
|
|
700
783
|
getRequiredLayerPaths,
|
|
784
|
+
engineFilesToRemove,
|
|
785
|
+
verifyTargetBinaries,
|
|
786
|
+
layerBuildInputs,
|
|
701
787
|
};
|