@friggframework/devtools 2.0.0--canary.731.1c0b281.0 → 2.0.0--canary.730.f2ba24a.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 (30) hide show
  1. package/infrastructure/README.md +5 -32
  2. package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -3
  3. package/infrastructure/__tests__/postgres-config.test.js +0 -3
  4. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -3
  5. package/infrastructure/__tests__/scoped-environment.test.js +0 -3
  6. package/infrastructure/__tests__/ssm-preload-node-options.test.js +0 -3
  7. package/infrastructure/__tests__/template-generation.test.js +0 -3
  8. package/infrastructure/app-definition-schema-contract.test.js +0 -5
  9. package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -2
  10. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +6 -22
  11. package/infrastructure/domains/database/migration-builder.js +2 -21
  12. package/infrastructure/domains/database/migration-builder.test.js +6 -61
  13. package/infrastructure/domains/integration/integration-builder.js +0 -2
  14. package/infrastructure/domains/integration/integration-builder.test.js +6 -22
  15. package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -13
  16. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +4 -51
  17. package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
  18. package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
  19. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +12 -92
  20. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +6 -158
  21. package/infrastructure/infrastructure-composer.js +1 -12
  22. package/infrastructure/infrastructure-composer.test.js +0 -71
  23. package/infrastructure/scripts/build-prisma-layer.js +50 -136
  24. package/infrastructure/scripts/build-prisma-layer.test.js +0 -100
  25. package/package.json +7 -7
  26. package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +0 -39
  27. package/infrastructure/domains/database/migration-engines.js +0 -93
  28. package/infrastructure/domains/database/migration-engines.test.js +0 -142
  29. package/infrastructure/domains/shared/lambda-architectures.js +0 -113
  30. package/infrastructure/domains/shared/lambda-architectures.test.js +0 -164
@@ -1,142 +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
-
107
- describe('running the @prisma/engines postinstall', () => {
108
- const pinnedEngineVars = ['PRISMA_SCHEMA_ENGINE_BINARY', 'PRISMA_QUERY_ENGINE_LIBRARY'];
109
- let appDir;
110
- let seenEnvPath;
111
-
112
- beforeEach(() => {
113
- appDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-app-'));
114
- const engines = path.join(appDir, 'node_modules', '@prisma', 'engines');
115
- fs.mkdirSync(path.join(engines, 'scripts'), { recursive: true });
116
- seenEnvPath = path.join(appDir, 'seen-env.json');
117
- fs.writeFileSync(
118
- path.join(engines, 'scripts', 'postinstall.js'),
119
- `const fs = require('fs');
120
- fs.writeFileSync(${JSON.stringify(seenEnvPath)}, JSON.stringify(process.env));
121
- for (const name of ${JSON.stringify([schemaEngine, queryEngineLibrary])}) fs.writeFileSync(name, '');`
122
- );
123
- });
124
-
125
- afterEach(() => {
126
- fs.rmSync(appDir, { recursive: true, force: true });
127
- pinnedEngineVars.forEach((name) => delete process.env[name]);
128
- });
129
-
130
- it("hides the host's pinned engine paths, so the postinstall does not skip the download", async () => {
131
- pinnedEngineVars.forEach((name) => {
132
- process.env[name] = `/host/${name}`;
133
- });
134
-
135
- await ensureMigrationEngines({ prismaBinaryTarget: target, cwd: appDir });
136
-
137
- const seenEnv = JSON.parse(fs.readFileSync(seenEnvPath, 'utf-8'));
138
- expect(seenEnv.PRISMA_CLI_BINARY_TARGETS).toBe(target);
139
- pinnedEngineVars.forEach((name) => expect(seenEnv).not.toHaveProperty(name));
140
- });
141
- });
142
- });
@@ -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
- });