@friggframework/devtools 2.0.0--canary.731.44132f0.0 → 2.0.0--canary.730.541f199.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/infrastructure/README.md +0 -27
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -3
- package/infrastructure/__tests__/postgres-config.test.js +0 -3
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -3
- package/infrastructure/__tests__/scoped-environment.test.js +0 -3
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +0 -3
- package/infrastructure/__tests__/template-generation.test.js +0 -3
- package/infrastructure/app-definition-schema-contract.test.js +0 -5
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -16
- package/infrastructure/domains/database/migration-builder.js +2 -21
- package/infrastructure/domains/database/migration-builder.test.js +0 -55
- package/infrastructure/domains/integration/integration-builder.js +0 -2
- package/infrastructure/domains/integration/integration-builder.test.js +0 -16
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -13
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -47
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +12 -92
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +6 -158
- package/infrastructure/infrastructure-composer.js +1 -12
- package/infrastructure/infrastructure-composer.test.js +0 -71
- package/infrastructure/scripts/build-prisma-layer.js +50 -136
- package/infrastructure/scripts/build-prisma-layer.test.js +0 -100
- package/package.json +7 -7
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +0 -39
- package/infrastructure/domains/database/migration-engines.js +0 -88
- package/infrastructure/domains/database/migration-engines.test.js +0 -106
- package/infrastructure/domains/shared/lambda-architectures.js +0 -113
- package/infrastructure/domains/shared/lambda-architectures.test.js +0 -164
|
@@ -8,9 +8,6 @@ const {
|
|
|
8
8
|
getMigrationsPackages,
|
|
9
9
|
getMigrationSourcePath,
|
|
10
10
|
getMigrationDestinationPath,
|
|
11
|
-
engineFilesToRemove,
|
|
12
|
-
verifyTargetBinaries,
|
|
13
|
-
layerBuildInputs,
|
|
14
11
|
} = require('./build-prisma-layer');
|
|
15
12
|
|
|
16
13
|
// Mock the log function
|
|
@@ -192,100 +189,3 @@ describe('getMigrationDestinationPath()', () => {
|
|
|
192
189
|
);
|
|
193
190
|
});
|
|
194
191
|
});
|
|
195
|
-
|
|
196
|
-
describe('engineFilesToRemove()', () => {
|
|
197
|
-
const files = [
|
|
198
|
-
'libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
199
|
-
'libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
200
|
-
'libquery_engine-debian-openssl-3.0.x.so.node',
|
|
201
|
-
'schema-engine-rhel-openssl-3.0.x',
|
|
202
|
-
'query-engine-linux-arm64-openssl-3.0.x',
|
|
203
|
-
'query_engine_bg.wasm',
|
|
204
|
-
'index.js',
|
|
205
|
-
];
|
|
206
|
-
|
|
207
|
-
it('keeps the rhel engines and the non-engine files for an x86_64 target', () => {
|
|
208
|
-
expect(engineFilesToRemove(files, 'rhel-openssl-3.0.x')).toEqual([
|
|
209
|
-
'libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
210
|
-
'libquery_engine-debian-openssl-3.0.x.so.node',
|
|
211
|
-
'query-engine-linux-arm64-openssl-3.0.x',
|
|
212
|
-
]);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('keeps the linux-arm64 engines and the non-engine files for an arm64 target', () => {
|
|
216
|
-
expect(engineFilesToRemove(files, 'linux-arm64-openssl-3.0.x')).toEqual([
|
|
217
|
-
'libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
218
|
-
'libquery_engine-debian-openssl-3.0.x.so.node',
|
|
219
|
-
'schema-engine-rhel-openssl-3.0.x',
|
|
220
|
-
]);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('verifyTargetBinaries()', () => {
|
|
225
|
-
const fs = require('fs');
|
|
226
|
-
const os = require('os');
|
|
227
|
-
const path = require('path');
|
|
228
|
-
const clients = ['generated/prisma-postgresql', 'generated/prisma-mongodb'];
|
|
229
|
-
let layerNodeModules;
|
|
230
|
-
|
|
231
|
-
const writeEngine = (client, engine) => {
|
|
232
|
-
const dir = path.join(layerNodeModules, client);
|
|
233
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
234
|
-
fs.writeFileSync(path.join(dir, engine), '');
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
beforeEach(() => {
|
|
238
|
-
layerNodeModules = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-prisma-layer-'));
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
afterEach(() => {
|
|
242
|
-
fs.rmSync(layerNodeModules, { recursive: true, force: true });
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it.each([
|
|
246
|
-
['rhel-openssl-3.0.x'],
|
|
247
|
-
['linux-arm64-openssl-3.0.x'],
|
|
248
|
-
])('passes when every client holds only the %s engine', async (target) => {
|
|
249
|
-
for (const client of clients) {
|
|
250
|
-
writeEngine(client, `libquery_engine-${target}.so.node`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
await expect(
|
|
254
|
-
verifyTargetBinaries(layerNodeModules, target, clients, '2.0.0-next.0')
|
|
255
|
-
).resolves.toBeUndefined();
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('fails naming the client, the target and the core version when one client lacks the engine', async () => {
|
|
259
|
-
writeEngine('generated/prisma-postgresql', 'libquery_engine-linux-arm64-openssl-3.0.x.so.node');
|
|
260
|
-
writeEngine('generated/prisma-mongodb', 'libquery_engine-rhel-openssl-3.0.x.so.node');
|
|
261
|
-
|
|
262
|
-
await expect(
|
|
263
|
-
verifyTargetBinaries(layerNodeModules, 'linux-arm64-openssl-3.0.x', clients, '2.0.0-next.105')
|
|
264
|
-
).rejects.toThrow(/prisma-mongodb.*linux-arm64-openssl-3\.0\.x[\s\S]*2\.0\.0-next\.105/);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('fails when a client still holds an engine for another Linux target', async () => {
|
|
268
|
-
writeEngine('generated/prisma-postgresql', 'libquery_engine-rhel-openssl-3.0.x.so.node');
|
|
269
|
-
writeEngine('generated/prisma-postgresql', 'libquery_engine-linux-arm64-openssl-3.0.x.so.node');
|
|
270
|
-
|
|
271
|
-
await expect(
|
|
272
|
-
verifyTargetBinaries(layerNodeModules, 'rhel-openssl-3.0.x', ['generated/prisma-postgresql'], '2.0.0-next.0')
|
|
273
|
-
).rejects.toThrow(/libquery_engine-linux-arm64-openssl-3\.0\.x\.so\.node/);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe('layerBuildInputs()', () => {
|
|
278
|
-
it('names the target, the client set and the core and @prisma/client versions the layer is built from', () => {
|
|
279
|
-
const inputs = layerBuildInputs({
|
|
280
|
-
databaseConfig: { postgres: { enable: true }, mongoDB: { enable: true } },
|
|
281
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
expect(inputs).toEqual({
|
|
285
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
286
|
-
clientPackages: ['generated/prisma-mongodb', 'generated/prisma-postgresql'],
|
|
287
|
-
coreVersion: require('@friggframework/core/package.json').version,
|
|
288
|
-
prismaClientVersion: require('@prisma/client/package.json').version,
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/devtools",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.730.541f199.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frigg": "./frigg-cli/index.js"
|
|
7
7
|
},
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"@babel/eslint-parser": "^7.18.9",
|
|
29
29
|
"@babel/parser": "^7.25.3",
|
|
30
30
|
"@babel/traverse": "^7.25.3",
|
|
31
|
-
"@friggframework/core": "2.0.0--canary.
|
|
32
|
-
"@friggframework/schemas": "2.0.0--canary.
|
|
33
|
-
"@friggframework/test": "2.0.0--canary.
|
|
31
|
+
"@friggframework/core": "2.0.0--canary.730.541f199.0",
|
|
32
|
+
"@friggframework/schemas": "2.0.0--canary.730.541f199.0",
|
|
33
|
+
"@friggframework/test": "2.0.0--canary.730.541f199.0",
|
|
34
34
|
"@hapi/boom": "^10.0.1",
|
|
35
35
|
"@inquirer/prompts": "^5.3.8",
|
|
36
36
|
"axios": "^1.18.0",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"validate-npm-package-name": "^5.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
62
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
61
|
+
"@friggframework/eslint-config": "2.0.0--canary.730.541f199.0",
|
|
62
|
+
"@friggframework/prettier-config": "2.0.0--canary.730.541f199.0",
|
|
63
63
|
"aws-sdk-client-mock": "^4.1.0",
|
|
64
64
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
65
65
|
"jest": "^30.1.3",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "541f1999903bcfbc049dee0a97c0b1d1047143e6"
|
|
95
95
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared cases for every builder whose functions bundle Prisma when the
|
|
3
|
-
* Prisma layer is off.
|
|
4
|
-
* @param {(usePrismaLayer: boolean, architecture?: string) => Promise<Object[]>|Object[]} functionsOf
|
|
5
|
-
* Builds the app and returns its function definitions
|
|
6
|
-
*/
|
|
7
|
-
function itBundlesOnlyTheTargetPrismaEngine(functionsOf) {
|
|
8
|
-
it.each([
|
|
9
|
-
[undefined, 'rhel-openssl-3.0.x', 'linux-arm64-openssl-3.0.x'],
|
|
10
|
-
['x86_64', 'rhel-openssl-3.0.x', 'linux-arm64-openssl-3.0.x'],
|
|
11
|
-
['arm64', 'linux-arm64-openssl-3.0.x', 'rhel-openssl-3.0.x'],
|
|
12
|
-
])(
|
|
13
|
-
'with the layer off and architecture %s, the bundled Prisma keeps only the %s engine',
|
|
14
|
-
async (architecture, target, otherTarget) => {
|
|
15
|
-
for (const fn of await functionsOf(false, architecture)) {
|
|
16
|
-
expect(fn.package.exclude).toEqual(
|
|
17
|
-
expect.arrayContaining([
|
|
18
|
-
'**/libquery_engine-debian*',
|
|
19
|
-
`**/libquery_engine-${otherTarget}*`,
|
|
20
|
-
])
|
|
21
|
-
);
|
|
22
|
-
expect(fn.package.exclude).not.toContain(`**/libquery_engine-${target}*`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
it('with the layer on, adds no engine patterns, since the layer carries the engines', async () => {
|
|
28
|
-
for (const fn of await functionsOf(true, 'arm64')) {
|
|
29
|
-
expect(fn.package.exclude).not.toEqual(
|
|
30
|
-
expect.arrayContaining(['**/libquery_engine-rhel-openssl-3.0.x*'])
|
|
31
|
-
);
|
|
32
|
-
expect(fn.package.exclude).not.toEqual(
|
|
33
|
-
expect.arrayContaining(['**/libquery_engine-debian*'])
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = { itBundlesOnlyTheTargetPrismaEngine };
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Migration worker engines
|
|
3
|
-
*
|
|
4
|
-
* Domain Layer - Hexagonal Architecture
|
|
5
|
-
*
|
|
6
|
-
* The migration worker runs the Prisma CLI, which needs the schema engine
|
|
7
|
-
* and the query engine library for the Lambda architecture it runs on. Both
|
|
8
|
-
* ship from node_modules/@prisma/engines/, where the @prisma/engines
|
|
9
|
-
* postinstall put the deploy host's own engines. This fetches the deployed
|
|
10
|
-
* architecture's pair before packaging, and fails packaging when either is
|
|
11
|
-
* still missing, so a worker can never try to download an engine into the
|
|
12
|
-
* read-only /var/task at cold start.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const fs = require('fs');
|
|
16
|
-
const path = require('path');
|
|
17
|
-
const { execFileSync } = require('child_process');
|
|
18
|
-
const { prismaEngineFileNames, PRISMA_ENGINES_PACKAGE_DIR } = require('../shared/lambda-architectures');
|
|
19
|
-
|
|
20
|
-
function resolveEnginesDir(cwd) {
|
|
21
|
-
const enginesDir = path.join(cwd, PRISMA_ENGINES_PACKAGE_DIR);
|
|
22
|
-
if (!fs.existsSync(path.join(enginesDir, 'scripts', 'postinstall.js'))) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
`@prisma/engines was not found at ${enginesDir}.\n` +
|
|
25
|
-
'The app must have prisma installed in its own node_modules, not only in a hoisted parent: ' +
|
|
26
|
-
'the migration worker ships its engines from the app\'s node_modules.'
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return enginesDir;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Runs the @prisma/engines postinstall for one target. It downloads only
|
|
34
|
-
* the engines that are missing, so the host's own engines stay.
|
|
35
|
-
*/
|
|
36
|
-
function runEnginesPostinstall({ enginesDir, prismaBinaryTarget }) {
|
|
37
|
-
execFileSync(
|
|
38
|
-
process.execPath,
|
|
39
|
-
[path.join(enginesDir, 'scripts', 'postinstall.js')],
|
|
40
|
-
{
|
|
41
|
-
cwd: enginesDir,
|
|
42
|
-
stdio: 'inherit',
|
|
43
|
-
env: { ...process.env, PRISMA_CLI_BINARY_TARGETS: prismaBinaryTarget },
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @param {Object} options
|
|
50
|
-
* @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
|
|
51
|
-
* @param {string} [options.cwd] - The app root
|
|
52
|
-
* @param {string} [options.enginesDir] - node_modules/@prisma/engines of the app
|
|
53
|
-
* @param {Function} [options.fetchEngines] - Fetches the target's engines into enginesDir
|
|
54
|
-
* @throws {Error} When either engine is missing after the fetch
|
|
55
|
-
*/
|
|
56
|
-
async function ensureMigrationEngines({
|
|
57
|
-
prismaBinaryTarget,
|
|
58
|
-
cwd = process.cwd(),
|
|
59
|
-
enginesDir = resolveEnginesDir(cwd),
|
|
60
|
-
fetchEngines = runEnginesPostinstall,
|
|
61
|
-
}) {
|
|
62
|
-
const engineNames = Object.values(prismaEngineFileNames(prismaBinaryTarget));
|
|
63
|
-
const missing = () =>
|
|
64
|
-
engineNames.filter((name) => !fs.existsSync(path.join(enginesDir, name)));
|
|
65
|
-
|
|
66
|
-
if (missing().length === 0) {
|
|
67
|
-
console.log(`✓ Prisma ${prismaBinaryTarget} migration engines present in ${enginesDir}`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
console.log(
|
|
72
|
-
`📦 Fetching ${missing().join(', ')} (Prisma ${prismaBinaryTarget}) into ${enginesDir}...`
|
|
73
|
-
);
|
|
74
|
-
fetchEngines({ enginesDir, prismaBinaryTarget });
|
|
75
|
-
|
|
76
|
-
const stillMissing = missing();
|
|
77
|
-
if (stillMissing.length > 0) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Prisma migration engines for ${prismaBinaryTarget} are missing after the fetch: ` +
|
|
80
|
-
`${stillMissing.join(', ')} (in ${enginesDir}).\n` +
|
|
81
|
-
"The deploy host must reach Prisma's engine CDN (binaries.prisma.sh) at package time."
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = {
|
|
87
|
-
ensureMigrationEngines,
|
|
88
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { ensureMigrationEngines } = require('./migration-engines');
|
|
5
|
-
|
|
6
|
-
describe('ensureMigrationEngines()', () => {
|
|
7
|
-
const target = 'linux-arm64-openssl-3.0.x';
|
|
8
|
-
const schemaEngine = `schema-engine-${target}`;
|
|
9
|
-
const queryEngineLibrary = `libquery_engine-${target}.so.node`;
|
|
10
|
-
let enginesDir;
|
|
11
|
-
|
|
12
|
-
const writeEngines = (...names) => {
|
|
13
|
-
for (const name of names) {
|
|
14
|
-
fs.writeFileSync(path.join(enginesDir, name), '');
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
enginesDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-prisma-engines-'));
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
fs.rmSync(enginesDir, { recursive: true, force: true });
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('fetches nothing when both engines for the target are already present', async () => {
|
|
27
|
-
writeEngines(schemaEngine, queryEngineLibrary);
|
|
28
|
-
const fetchEngines = jest.fn();
|
|
29
|
-
|
|
30
|
-
await ensureMigrationEngines({ prismaBinaryTarget: target, enginesDir, fetchEngines });
|
|
31
|
-
|
|
32
|
-
expect(fetchEngines).not.toHaveBeenCalled();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('fetches the target engines into the engines directory when one is missing', async () => {
|
|
36
|
-
writeEngines(schemaEngine);
|
|
37
|
-
const fetchEngines = jest.fn(({ enginesDir: dir }) => {
|
|
38
|
-
fs.writeFileSync(path.join(dir, queryEngineLibrary), '');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
await ensureMigrationEngines({ prismaBinaryTarget: target, enginesDir, fetchEngines });
|
|
42
|
-
|
|
43
|
-
expect(fetchEngines).toHaveBeenCalledWith({ enginesDir, prismaBinaryTarget: target });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it.each([
|
|
47
|
-
['the schema engine', [queryEngineLibrary], schemaEngine],
|
|
48
|
-
['the query engine library', [schemaEngine], queryEngineLibrary],
|
|
49
|
-
['both engines', [], `${schemaEngine}, ${queryEngineLibrary}`],
|
|
50
|
-
])('fails packaging naming %s when the fetch leaves it missing', async (_, present, missing) => {
|
|
51
|
-
writeEngines(...present);
|
|
52
|
-
const fetchEngines = jest.fn();
|
|
53
|
-
|
|
54
|
-
await expect(
|
|
55
|
-
ensureMigrationEngines({ prismaBinaryTarget: target, enginesDir, fetchEngines })
|
|
56
|
-
).rejects.toThrow(missing);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('resolving the engines directory from cwd', () => {
|
|
60
|
-
let root;
|
|
61
|
-
|
|
62
|
-
const installEngines = (dir) => {
|
|
63
|
-
const engines = path.join(dir, 'node_modules', '@prisma', 'engines');
|
|
64
|
-
fs.mkdirSync(path.join(engines, 'scripts'), { recursive: true });
|
|
65
|
-
fs.writeFileSync(path.join(engines, 'scripts', 'postinstall.js'), '');
|
|
66
|
-
return engines;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
root = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-app-root-'));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
afterEach(() => {
|
|
74
|
-
fs.rmSync(root, { recursive: true, force: true });
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("uses the engines in the app's own node_modules", async () => {
|
|
78
|
-
const appDir = path.join(root, 'app');
|
|
79
|
-
const appEngines = installEngines(appDir);
|
|
80
|
-
fs.writeFileSync(path.join(appEngines, schemaEngine), '');
|
|
81
|
-
fs.writeFileSync(path.join(appEngines, queryEngineLibrary), '');
|
|
82
|
-
const fetchEngines = jest.fn();
|
|
83
|
-
|
|
84
|
-
await ensureMigrationEngines({ prismaBinaryTarget: target, cwd: appDir, fetchEngines });
|
|
85
|
-
|
|
86
|
-
expect(fetchEngines).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('fails with a readable error when only a parent directory has the engines', async () => {
|
|
90
|
-
installEngines(root);
|
|
91
|
-
const appDir = path.join(root, 'app');
|
|
92
|
-
fs.mkdirSync(appDir);
|
|
93
|
-
const fetchEngines = jest.fn();
|
|
94
|
-
|
|
95
|
-
const failure = ensureMigrationEngines({
|
|
96
|
-
prismaBinaryTarget: target,
|
|
97
|
-
cwd: appDir,
|
|
98
|
-
fetchEngines,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
await expect(failure).rejects.toThrow(/prisma.*own node_modules.*hoisted parent/is);
|
|
102
|
-
await expect(failure).rejects.not.toHaveProperty('code', 'MODULE_NOT_FOUND');
|
|
103
|
-
expect(fetchEngines).not.toHaveBeenCalled();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lambda architectures and the Prisma engine each one runs.
|
|
3
|
-
*
|
|
4
|
-
* The registry keys are the AWS architecture names, so they go into
|
|
5
|
-
* `provider.architecture` and the layer `compatibleArchitectures` as they
|
|
6
|
-
* are. Every architecture-dependent value (layer build, layer cache key,
|
|
7
|
-
* migration worker engines, package excludes) reads from here.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const LAMBDA_ARCHITECTURES = {
|
|
11
|
-
x86_64: { prismaBinaryTarget: 'rhel-openssl-3.0.x' },
|
|
12
|
-
arm64: { prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' },
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const DEFAULT_LAMBDA_ARCHITECTURE = 'x86_64';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {Object} appDefinition
|
|
19
|
-
* @returns {{ name: string, prismaBinaryTarget: string, explicit: boolean }}
|
|
20
|
-
* `explicit` is false when the app definition does not set `architecture`,
|
|
21
|
-
* so callers can leave the template unchanged for existing apps.
|
|
22
|
-
* @throws {Error} on an architecture the registry does not know
|
|
23
|
-
*/
|
|
24
|
-
function resolveLambdaArchitecture(appDefinition = {}) {
|
|
25
|
-
const explicit = appDefinition.architecture !== undefined;
|
|
26
|
-
const name = explicit
|
|
27
|
-
? appDefinition.architecture
|
|
28
|
-
: DEFAULT_LAMBDA_ARCHITECTURE;
|
|
29
|
-
const entry = LAMBDA_ARCHITECTURES[name];
|
|
30
|
-
if (!entry) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Unknown Lambda architecture '${name}'. ` +
|
|
33
|
-
`Set architecture to one of: ${Object.keys(
|
|
34
|
-
LAMBDA_ARCHITECTURES
|
|
35
|
-
).join(', ')}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
return { name, prismaBinaryTarget: entry.prismaBinaryTarget, explicit };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Where the migration worker's engines live, relative to the app root and to /var/task. */
|
|
42
|
-
const PRISMA_ENGINES_PACKAGE_DIR = 'node_modules/@prisma/engines';
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The two engine files `prisma migrate` needs for a target, as
|
|
46
|
-
* @prisma/engines names them.
|
|
47
|
-
* @param {string} prismaBinaryTarget
|
|
48
|
-
* @returns {{ schemaEngine: string, queryEngineLibrary: string }}
|
|
49
|
-
*/
|
|
50
|
-
function prismaEngineFileNames(prismaBinaryTarget) {
|
|
51
|
-
return {
|
|
52
|
-
schemaEngine: `schema-engine-${prismaBinaryTarget}`,
|
|
53
|
-
queryEngineLibrary: `libquery_engine-${prismaBinaryTarget}.so.node`,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const PRISMA_ENGINE_FILE_PREFIXES = [
|
|
58
|
-
'libquery_engine-',
|
|
59
|
-
'query-engine-',
|
|
60
|
-
'query_engine-',
|
|
61
|
-
'schema-engine-',
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
const HOST_PLATFORM_ENGINE_TOKENS = [
|
|
65
|
-
'darwin',
|
|
66
|
-
'debian',
|
|
67
|
-
'linux-musl',
|
|
68
|
-
'windows',
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Package exclude patterns for every Prisma engine file the named
|
|
73
|
-
* architecture does not load: the deploy host's own platforms and the other
|
|
74
|
-
* Lambda architectures. Each pattern starts with an engine file prefix, so a
|
|
75
|
-
* runtime dependency that only has a platform word in its name is kept.
|
|
76
|
-
* @param {string} name - A registry key
|
|
77
|
-
* @returns {string[]}
|
|
78
|
-
*/
|
|
79
|
-
function foreignPrismaEngineExcludes(name) {
|
|
80
|
-
const foreignTokens = [
|
|
81
|
-
...HOST_PLATFORM_ENGINE_TOKENS,
|
|
82
|
-
...Object.entries(LAMBDA_ARCHITECTURES)
|
|
83
|
-
.filter(([other]) => other !== name)
|
|
84
|
-
.map(([, { prismaBinaryTarget }]) => prismaBinaryTarget),
|
|
85
|
-
];
|
|
86
|
-
return PRISMA_ENGINE_FILE_PREFIXES.flatMap((prefix) =>
|
|
87
|
-
foreignTokens.map((token) => `**/${prefix}${token}*`)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Package exclude patterns for a function that bundles Prisma itself. With
|
|
93
|
-
* the Prisma layer on, the layer carries the engines and nothing is added.
|
|
94
|
-
* @param {Object} appDefinition
|
|
95
|
-
* @param {boolean} usePrismaLayer
|
|
96
|
-
* @returns {string[]}
|
|
97
|
-
*/
|
|
98
|
-
function bundledPrismaEngineExcludes(appDefinition, usePrismaLayer) {
|
|
99
|
-
return usePrismaLayer
|
|
100
|
-
? []
|
|
101
|
-
: foreignPrismaEngineExcludes(resolveLambdaArchitecture(appDefinition).name);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = {
|
|
105
|
-
LAMBDA_ARCHITECTURES,
|
|
106
|
-
DEFAULT_LAMBDA_ARCHITECTURE,
|
|
107
|
-
resolveLambdaArchitecture,
|
|
108
|
-
PRISMA_ENGINE_FILE_PREFIXES,
|
|
109
|
-
PRISMA_ENGINES_PACKAGE_DIR,
|
|
110
|
-
prismaEngineFileNames,
|
|
111
|
-
foreignPrismaEngineExcludes,
|
|
112
|
-
bundledPrismaEngineExcludes,
|
|
113
|
-
};
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
const micromatch = require('micromatch');
|
|
2
|
-
const {
|
|
3
|
-
LAMBDA_ARCHITECTURES,
|
|
4
|
-
resolveLambdaArchitecture,
|
|
5
|
-
prismaEngineFileNames,
|
|
6
|
-
foreignPrismaEngineExcludes,
|
|
7
|
-
bundledPrismaEngineExcludes,
|
|
8
|
-
} = require('./lambda-architectures');
|
|
9
|
-
|
|
10
|
-
describe('resolveLambdaArchitecture()', () => {
|
|
11
|
-
it('resolves to x86_64 with the rhel engine when the key is unset', () => {
|
|
12
|
-
expect(resolveLambdaArchitecture({})).toEqual({
|
|
13
|
-
name: 'x86_64',
|
|
14
|
-
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
15
|
-
explicit: false,
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('resolves an explicit x86_64', () => {
|
|
20
|
-
expect(resolveLambdaArchitecture({ architecture: 'x86_64' })).toEqual({
|
|
21
|
-
name: 'x86_64',
|
|
22
|
-
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
23
|
-
explicit: true,
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('resolves arm64 to the linux-arm64 engine', () => {
|
|
28
|
-
expect(resolveLambdaArchitecture({ architecture: 'arm64' })).toEqual({
|
|
29
|
-
name: 'arm64',
|
|
30
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
31
|
-
explicit: true,
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('throws on an unknown architecture, naming the accepted ones', () => {
|
|
36
|
-
expect(() =>
|
|
37
|
-
resolveLambdaArchitecture({ architecture: 'aarch64' })
|
|
38
|
-
).toThrow(/aarch64.*x86_64.*arm64/);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('uses the AWS architecture names as registry keys', () => {
|
|
42
|
-
expect(Object.keys(LAMBDA_ARCHITECTURES)).toEqual(['x86_64', 'arm64']);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('prismaEngineFileNames()', () => {
|
|
47
|
-
it('names the schema engine and the query engine library the migrate CLI needs for a target', () => {
|
|
48
|
-
expect(prismaEngineFileNames('linux-arm64-openssl-3.0.x')).toEqual({
|
|
49
|
-
schemaEngine: 'schema-engine-linux-arm64-openssl-3.0.x',
|
|
50
|
-
queryEngineLibrary: 'libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('foreignPrismaEngineExcludes()', () => {
|
|
56
|
-
const matches = (name, filePath) =>
|
|
57
|
-
micromatch([filePath], foreignPrismaEngineExcludes(name), {
|
|
58
|
-
dot: true,
|
|
59
|
-
}).length > 0;
|
|
60
|
-
|
|
61
|
-
const foreignEngineFiles = {
|
|
62
|
-
x86_64: [
|
|
63
|
-
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
64
|
-
'node_modules/@prisma/engines/schema-engine-darwin-arm64',
|
|
65
|
-
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
66
|
-
'node_modules/@prisma/engines/query-engine-debian-openssl-3.0.x',
|
|
67
|
-
'node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node',
|
|
68
|
-
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
69
|
-
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
70
|
-
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
71
|
-
],
|
|
72
|
-
arm64: [
|
|
73
|
-
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
74
|
-
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
75
|
-
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
76
|
-
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
77
|
-
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const targetEngineFiles = {
|
|
82
|
-
x86_64: [
|
|
83
|
-
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
84
|
-
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
85
|
-
],
|
|
86
|
-
arm64: [
|
|
87
|
-
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
88
|
-
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
89
|
-
],
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const nonEngineFiles = [
|
|
93
|
-
'node_modules/is-windows/index.js',
|
|
94
|
-
'node_modules/is-windows/package.json',
|
|
95
|
-
'node_modules/darwin-utils/lib/index.js',
|
|
96
|
-
'node_modules/some-pkg/lib/debian-release.js',
|
|
97
|
-
'node_modules/some-pkg/linux-musl-detect.js',
|
|
98
|
-
'node_modules/@prisma/engines/query_engine_bg.wasm',
|
|
99
|
-
'node_modules/.prisma/client/query_engine_bg.js',
|
|
100
|
-
'node_modules/some-pkg/dist/linux-arm64-notes.js',
|
|
101
|
-
'src/handlers/windows-handler.js',
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
it.each(['x86_64', 'arm64'])(
|
|
105
|
-
'matches every foreign engine file for %s',
|
|
106
|
-
(name) => {
|
|
107
|
-
foreignEngineFiles[name].forEach((file) =>
|
|
108
|
-
expect({ name, file, hit: matches(name, file) }).toEqual({
|
|
109
|
-
name,
|
|
110
|
-
file,
|
|
111
|
-
hit: true,
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
it.each(['x86_64', 'arm64'])(
|
|
118
|
-
'keeps the engine files of the %s target',
|
|
119
|
-
(name) => {
|
|
120
|
-
targetEngineFiles[name].forEach((file) =>
|
|
121
|
-
expect({ file, hit: matches(name, file) }).toEqual({
|
|
122
|
-
file,
|
|
123
|
-
hit: false,
|
|
124
|
-
})
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
it.each(['x86_64', 'arm64'])(
|
|
130
|
-
'keeps runtime files that only share a platform word with an engine for %s',
|
|
131
|
-
(name) => {
|
|
132
|
-
nonEngineFiles.forEach((file) =>
|
|
133
|
-
expect({ file, hit: matches(name, file) }).toEqual({
|
|
134
|
-
file,
|
|
135
|
-
hit: false,
|
|
136
|
-
})
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
it('never uses negation', () => {
|
|
142
|
-
['x86_64', 'arm64'].forEach((name) =>
|
|
143
|
-
foreignPrismaEngineExcludes(name).forEach((pattern) =>
|
|
144
|
-
expect(pattern.startsWith('!')).toBe(false)
|
|
145
|
-
)
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe('bundledPrismaEngineExcludes()', () => {
|
|
151
|
-
it('adds nothing when the Prisma layer carries the engines', () => {
|
|
152
|
-
expect(bundledPrismaEngineExcludes({ architecture: 'arm64' }, true)).toEqual([]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it.each([
|
|
156
|
-
[{}, 'x86_64'],
|
|
157
|
-
[{ architecture: 'x86_64' }, 'x86_64'],
|
|
158
|
-
[{ architecture: 'arm64' }, 'arm64'],
|
|
159
|
-
])('with the layer off, excludes the engines %j does not load', (appDefinition, name) => {
|
|
160
|
-
expect(bundledPrismaEngineExcludes(appDefinition, false)).toEqual(
|
|
161
|
-
foreignPrismaEngineExcludes(name)
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
});
|