@friggframework/devtools 2.0.0--canary.686.45cab16.0 → 2.0.0--canary.694.f66a64a.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/frigg-cli/build-command/index.js +1 -32
- package/frigg-cli/deploy-command/index.js +2 -50
- package/frigg-cli/doctor-command/index.js +0 -7
- package/frigg-cli/generate-iam-command.js +0 -7
- package/frigg-cli/repair-command/index.js +0 -7
- package/frigg-cli/start-command/index.js +0 -58
- package/infrastructure/__tests__/template-generation.test.js +0 -7
- package/infrastructure/create-frigg-infrastructure.js +0 -14
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
- package/infrastructure/domains/scheduler/trigger-builder.js +114 -0
- package/infrastructure/domains/scheduler/trigger-builder.test.js +82 -0
- package/infrastructure/domains/shared/function-environments.js +9 -1
- package/infrastructure/domains/shared/function-environments.test.js +14 -0
- package/infrastructure/domains/shared/types/app-definition.js +1 -15
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -28
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -85
- package/infrastructure/infrastructure-composer.js +2 -0
- package/infrastructure/infrastructure-composer.test.js +0 -7
- package/infrastructure/scripts/build-prisma-layer.js +5 -32
- package/infrastructure/scripts/build-prisma-layer.test.js +0 -35
- package/package.json +7 -7
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -140
- package/frigg-cli/utils/provider-helper.js +0 -80
- package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -335
- package/infrastructure/provider-build.js +0 -119
- package/test/npm-install-guard.js +0 -104
- package/test/npm-install-guard.test.js +0 -53
|
@@ -10,26 +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
|
-
getGatewayRoutes,
|
|
15
|
-
} = require('@friggframework/core/management-api/route-registry');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* HTTP API events for one function, from core's route registry (ADR-053):
|
|
19
|
-
* the same registry mounts the Express routers and builds the OpenAPI
|
|
20
|
-
* documents, so the three cannot drift. It also lists /api/docs and the core
|
|
21
|
-
* extensions' admin routes (/admin/<name>, served by the auth Lambda).
|
|
22
|
-
*/
|
|
23
|
-
function managementApiEvents(AppDefinition, functionName) {
|
|
24
|
-
const managementApi = AppDefinition.managementApi || {};
|
|
25
|
-
return getGatewayRoutes({
|
|
26
|
-
v1: managementApi.v1 !== false,
|
|
27
|
-
proxy: managementApi.proxy?.enable === true,
|
|
28
|
-
coreExtensions: AppDefinition.coreExtensions,
|
|
29
|
-
})
|
|
30
|
-
.filter((route) => route.function === functionName)
|
|
31
|
-
.map(({ method, path }) => ({ httpApi: { path, method } }));
|
|
32
|
-
}
|
|
33
13
|
|
|
34
14
|
/**
|
|
35
15
|
* Create base serverless definition with core functions and resources
|
|
@@ -306,12 +286,16 @@ function createBaseDefinition(
|
|
|
306
286
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
307
287
|
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
308
288
|
package: skipEsbuildPackageConfig,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
289
|
+
events: [
|
|
290
|
+
{ httpApi: { path: '/api/integrations', method: 'ANY' } },
|
|
291
|
+
{
|
|
292
|
+
httpApi: {
|
|
293
|
+
path: '/api/integrations/{proxy+}',
|
|
294
|
+
method: 'ANY',
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
{ httpApi: { path: '/api/authorize', method: 'ANY' } },
|
|
298
|
+
],
|
|
315
299
|
},
|
|
316
300
|
user: {
|
|
317
301
|
handler: 'node_modules/@friggframework/core/handlers/routers/user.handler',
|
|
@@ -328,8 +312,6 @@ function createBaseDefinition(
|
|
|
328
312
|
events: [
|
|
329
313
|
{ httpApi: { path: '/health', method: 'GET' } },
|
|
330
314
|
{ httpApi: { path: '/health/{proxy+}', method: 'GET' } },
|
|
331
|
-
// GET /api/meta and the OpenAPI documents: public, DB-free.
|
|
332
|
-
...managementApiEvents(AppDefinition, 'health'),
|
|
333
315
|
],
|
|
334
316
|
},
|
|
335
317
|
// Reporting is an admin operation (ADR-010): the report router runs on the admin-scripts Lambda, not as a standalone function here.
|
|
@@ -94,91 +94,7 @@ describe('Base Definition Factory', () => {
|
|
|
94
94
|
|
|
95
95
|
expect(result.functions.auth.handler).toBe('node_modules/@friggframework/core/handlers/routers/auth.handler');
|
|
96
96
|
expect(result.functions.auth.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
|
|
97
|
-
expect(
|
|
98
|
-
result.functions.auth.events.map(
|
|
99
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
100
|
-
)
|
|
101
|
-
).toEqual([
|
|
102
|
-
// v1 (deprecated, ADR-053)
|
|
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/{proxy+}',
|
|
109
|
-
// v2, per resource: never ANY /api/v2/{proxy+}, which would
|
|
110
|
-
// shadow /api/v2/reports on the admin-scripts Lambda
|
|
111
|
-
'ANY /api/v2/integrations',
|
|
112
|
-
'ANY /api/v2/integrations/{proxy+}',
|
|
113
|
-
'ANY /api/v2/entities',
|
|
114
|
-
'ANY /api/v2/entities/{proxy+}',
|
|
115
|
-
'ANY /api/v2/credentials',
|
|
116
|
-
'ANY /api/v2/credentials/{proxy+}',
|
|
117
|
-
'ANY /api/v2/authorize',
|
|
118
|
-
]);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('takes the Management API routes from the core route registry', () => {
|
|
122
|
-
const { getGatewayRoutes } = require('@friggframework/core/management-api/route-registry');
|
|
123
|
-
const result = createBaseDefinition({}, {}, {});
|
|
124
|
-
const declared = (fn) =>
|
|
125
|
-
result.functions[fn].events
|
|
126
|
-
.map((e) => `${e.httpApi.method} ${e.httpApi.path}`)
|
|
127
|
-
.filter((route) => route.includes('/api/'));
|
|
128
|
-
const registry = (fn) =>
|
|
129
|
-
getGatewayRoutes()
|
|
130
|
-
.filter((r) => r.function === fn)
|
|
131
|
-
.map((r) => `${r.method} ${r.path}`);
|
|
132
|
-
expect(declared('auth')).toEqual(registry('auth'));
|
|
133
|
-
expect(declared('health')).toEqual(registry('health'));
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('serves /api/meta from the DB-free health function', () => {
|
|
137
|
-
const result = createBaseDefinition({}, {}, {});
|
|
138
|
-
expect(
|
|
139
|
-
result.functions.health.events.map((e) => `${e.httpApi.method} ${e.httpApi.path}`)
|
|
140
|
-
).toEqual([
|
|
141
|
-
'GET /health',
|
|
142
|
-
'GET /health/{proxy+}',
|
|
143
|
-
'GET /api/meta',
|
|
144
|
-
'GET /api/meta/{proxy+}',
|
|
145
|
-
// Redirects to /api/meta/openapi/v2.json (ADR-053 docs path)
|
|
146
|
-
'GET /api/docs',
|
|
147
|
-
]);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('routes each core extension admin path (and below) to the auth function', () => {
|
|
151
|
-
const result = createBaseDefinition(
|
|
152
|
-
{
|
|
153
|
-
coreExtensions: [
|
|
154
|
-
{ name: 'db-credentials', routes: { path: '/admin/oauth-credentials' } },
|
|
155
|
-
{ name: 'no-routes' },
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
{},
|
|
159
|
-
{}
|
|
160
|
-
);
|
|
161
|
-
const routes = result.functions.auth.events.map(
|
|
162
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
163
|
-
);
|
|
164
|
-
expect(routes).toContain('ANY /admin/oauth-credentials');
|
|
165
|
-
expect(routes).toContain('ANY /admin/oauth-credentials/{proxy+}');
|
|
166
|
-
// Never a catch-all that would shadow /admin/scripts or /admin/db-migrate.
|
|
167
|
-
expect(routes).not.toContain('ANY /admin/{proxy+}');
|
|
168
|
-
// The HTTP queue route is for hosts without SQS, never AWS.
|
|
169
|
-
expect(JSON.stringify(result.functions)).not.toContain('/admin/queue');
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('drops the v1 routes when managementApi.v1 is false, keeping the OAuth redirect', () => {
|
|
173
|
-
const result = createBaseDefinition({ managementApi: { v1: false } }, {}, {});
|
|
174
|
-
const routes = result.functions.auth.events.map(
|
|
175
|
-
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
176
|
-
);
|
|
177
|
-
expect(routes).not.toContain('ANY /api/integrations');
|
|
178
|
-
expect(routes).not.toContain('ANY /api/authorize');
|
|
179
|
-
expect(routes).not.toContain('ANY /api/entity');
|
|
180
|
-
expect(routes).toContain('GET /api/integrations/redirect/{appId}');
|
|
181
|
-
expect(routes).toContain('ANY /api/v2/integrations');
|
|
97
|
+
expect(result.functions.auth.events).toHaveLength(3);
|
|
182
98
|
});
|
|
183
99
|
|
|
184
100
|
it('should NOT include legacy dbMigrate function', () => {
|
|
@@ -17,6 +17,7 @@ const { SsmBuilder } = require('./domains/parameters/ssm-builder');
|
|
|
17
17
|
const { WebsocketBuilder } = require('./domains/integration/websocket-builder');
|
|
18
18
|
const { IntegrationBuilder } = require('./domains/integration/integration-builder');
|
|
19
19
|
const { SchedulerBuilder } = require('./domains/scheduler/scheduler-builder');
|
|
20
|
+
const { TriggerBuilder } = require('./domains/scheduler/trigger-builder');
|
|
20
21
|
const { AdminScriptBuilder } = require('./domains/admin-scripts/admin-script-builder');
|
|
21
22
|
|
|
22
23
|
// Utilities
|
|
@@ -92,6 +93,7 @@ const composeServerlessDefinition = async (AppDefinition) => {
|
|
|
92
93
|
new WebsocketBuilder(),
|
|
93
94
|
new IntegrationBuilder(),
|
|
94
95
|
new SchedulerBuilder(), // Add scheduler after IntegrationBuilder (depends on it)
|
|
96
|
+
new TriggerBuilder(), // One trigger tick function per integration with triggers (ADR-055)
|
|
95
97
|
new AdminScriptBuilder(),
|
|
96
98
|
]);
|
|
97
99
|
|
|
@@ -2,13 +2,6 @@ const {
|
|
|
2
2
|
composeServerlessDefinition,
|
|
3
3
|
applySsmPreloadNodeOptions,
|
|
4
4
|
} = require('./infrastructure-composer');
|
|
5
|
-
// Composing must not build the real Prisma layer: that runs npm install
|
|
6
|
-
// under packages/devtools, and two workers doing it at once once pruned the
|
|
7
|
-
// repository's root node_modules (test/npm-install-guard.js).
|
|
8
|
-
jest.mock('./domains/shared/utilities/prisma-layer-manager', () => ({
|
|
9
|
-
ensurePrismaLayerExists: jest.fn(async () => {}),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
5
|
const {
|
|
13
6
|
SSM_PRELOAD_NODE_OPTIONS,
|
|
14
7
|
} = require('./domains/parameters/offload-utils');
|
|
@@ -249,36 +249,6 @@ async function createLayerStructure() {
|
|
|
249
249
|
logSuccess(`Created ${LAYER_NODE_MODULES}`);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
/**
|
|
253
|
-
* Run `npm install --omit=dev` confined to the layer directory.
|
|
254
|
-
*
|
|
255
|
-
* npm resolves its project root by walking up from cwd to the nearest
|
|
256
|
-
* package.json. If the layer's package.json is missing when npm starts (a
|
|
257
|
-
* concurrent build cleaned the directory, as two jest workers composing at
|
|
258
|
-
* once did), npm walked up into the enclosing workspace and ran
|
|
259
|
-
* `install --omit=dev` there, pruning the devDependencies (jest, jest-util)
|
|
260
|
-
* out of the repository's root node_modules. So: the package.json must exist,
|
|
261
|
-
* and `--prefix` pins npm's root to the layer directory while
|
|
262
|
-
* `--workspaces=false` stops it acting on an enclosing workspace.
|
|
263
|
-
*
|
|
264
|
-
* @param {string} layerNodejsDir - absolute path of <layer>/nodejs
|
|
265
|
-
* @param {Object} [options]
|
|
266
|
-
* @param {Object} [options.env]
|
|
267
|
-
* @param {Function} [options.exec] - execSync stand-in (tests)
|
|
268
|
-
*/
|
|
269
|
-
function runLayerInstall(layerNodejsDir, { env = process.env, exec = execSync } = {}) {
|
|
270
|
-
const manifest = path.join(layerNodejsDir, 'package.json');
|
|
271
|
-
if (!fs.existsSync(manifest)) {
|
|
272
|
-
throw new Error(
|
|
273
|
-
`Refusing to run npm install: ${manifest} does not exist (npm would install into an enclosing project)`
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
exec(
|
|
277
|
-
`npm install --omit=dev --no-package-lock --workspaces=false --prefix ${JSON.stringify(layerNodejsDir)}`,
|
|
278
|
-
{ cwd: layerNodejsDir, stdio: 'inherit', env }
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
252
|
/**
|
|
283
253
|
* Install Prisma client directly into layer (RUNTIME ONLY - NO CLI)
|
|
284
254
|
*
|
|
@@ -315,7 +285,11 @@ async function installPrismaPackages() {
|
|
|
315
285
|
PRISMA_CLI_BINARY_TARGETS: 'rhel-openssl-3.0.x',
|
|
316
286
|
};
|
|
317
287
|
|
|
318
|
-
|
|
288
|
+
execSync('npm install --omit=dev --no-package-lock', {
|
|
289
|
+
cwd: path.join(LAYER_OUTPUT_PATH, 'nodejs'),
|
|
290
|
+
stdio: 'inherit',
|
|
291
|
+
env,
|
|
292
|
+
});
|
|
319
293
|
logSuccess('Prisma packages installed with Lambda binary target');
|
|
320
294
|
} catch (error) {
|
|
321
295
|
throw new Error(`Failed to install Prisma packages: ${error.message}`);
|
|
@@ -719,7 +693,6 @@ if (require.main === module) {
|
|
|
719
693
|
|
|
720
694
|
module.exports = {
|
|
721
695
|
buildPrismaLayer,
|
|
722
|
-
runLayerInstall,
|
|
723
696
|
getGeneratedClientPackages,
|
|
724
697
|
getMigrationsPackages,
|
|
725
698
|
getMigrationSourcePath,
|
|
@@ -168,38 +168,3 @@ describe('getMigrationDestinationPath()', () => {
|
|
|
168
168
|
);
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
describe('runLayerInstall', () => {
|
|
174
|
-
const fs = require('fs');
|
|
175
|
-
const os = require('os');
|
|
176
|
-
const path = require('path');
|
|
177
|
-
const { runLayerInstall } = require('./build-prisma-layer');
|
|
178
|
-
|
|
179
|
-
it('refuses when the layer package.json is missing (npm would walk up into the workspace)', () => {
|
|
180
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'layer-'));
|
|
181
|
-
const exec = jest.fn();
|
|
182
|
-
try {
|
|
183
|
-
expect(() => runLayerInstall(dir, { exec })).toThrow(/Refusing to run npm install/);
|
|
184
|
-
expect(exec).not.toHaveBeenCalled();
|
|
185
|
-
} finally {
|
|
186
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('pins npm to the layer directory and off any enclosing workspace', () => {
|
|
191
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'layer-'));
|
|
192
|
-
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
193
|
-
const exec = jest.fn();
|
|
194
|
-
try {
|
|
195
|
-
runLayerInstall(dir, { exec, env: { X: '1' } });
|
|
196
|
-
const [command, options] = exec.mock.calls[0];
|
|
197
|
-
expect(command).toContain('npm install --omit=dev');
|
|
198
|
-
expect(command).toContain('--workspaces=false');
|
|
199
|
-
expect(command).toContain(`--prefix ${JSON.stringify(dir)}`);
|
|
200
|
-
expect(options).toMatchObject({ cwd: dir, env: { X: '1' } });
|
|
201
|
-
} finally {
|
|
202
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
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.694.f66a64a.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frigg": "./frigg-cli/index.js"
|
|
7
7
|
},
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"@babel/eslint-parser": "^7.18.9",
|
|
27
27
|
"@babel/parser": "^7.25.3",
|
|
28
28
|
"@babel/traverse": "^7.25.3",
|
|
29
|
-
"@friggframework/core": "2.0.0--canary.
|
|
30
|
-
"@friggframework/schemas": "2.0.0--canary.
|
|
31
|
-
"@friggframework/test": "2.0.0--canary.
|
|
29
|
+
"@friggframework/core": "2.0.0--canary.694.f66a64a.0",
|
|
30
|
+
"@friggframework/schemas": "2.0.0--canary.694.f66a64a.0",
|
|
31
|
+
"@friggframework/test": "2.0.0--canary.694.f66a64a.0",
|
|
32
32
|
"@hapi/boom": "^10.0.1",
|
|
33
33
|
"@inquirer/prompts": "^5.3.8",
|
|
34
34
|
"axios": "^1.18.0",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"validate-npm-package-name": "^5.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
60
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
59
|
+
"@friggframework/eslint-config": "2.0.0--canary.694.f66a64a.0",
|
|
60
|
+
"@friggframework/prettier-config": "2.0.0--canary.694.f66a64a.0",
|
|
61
61
|
"aws-sdk-client-mock": "^4.1.0",
|
|
62
62
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
63
63
|
"jest": "^30.1.3",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"publishConfig": {
|
|
90
90
|
"access": "public"
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "f66a64af4882d4da330f78e13bf570c4e22f6640"
|
|
93
93
|
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider dispatch (friggframework/frigg#545): appDefinition.provider
|
|
3
|
-
* decides whether a CLI command runs the AWS/serverless path or the
|
|
4
|
-
* provider plugin. Uses real temp projects and the real provider-netlify.
|
|
5
|
-
*/
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const os = require('os');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
function writeProject(definitionSource) {
|
|
11
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-dispatch-'));
|
|
12
|
-
const backend = path.join(dir, 'backend');
|
|
13
|
-
fs.mkdirSync(backend);
|
|
14
|
-
fs.writeFileSync(path.join(backend, 'package.json'), '{"name":"backend"}');
|
|
15
|
-
fs.writeFileSync(path.join(backend, 'index.js'), `module.exports = { Definition: ${definitionSource} };`);
|
|
16
|
-
return { dir, backend };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const NETLIFY_APP = `{
|
|
20
|
-
name: 'dispatch-app',
|
|
21
|
-
provider: 'netlify',
|
|
22
|
-
integrations: [],
|
|
23
|
-
database: { postgres: { enable: true } },
|
|
24
|
-
}`;
|
|
25
|
-
|
|
26
|
-
describe('provider-helper', () => {
|
|
27
|
-
const { loadProviderForCli, loadCliAppDefinition, isNonAwsProject } = require('../../../utils/provider-helper');
|
|
28
|
-
const dirs = [];
|
|
29
|
-
afterAll(() => dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true })));
|
|
30
|
-
|
|
31
|
-
it('returns null without an app definition', () => {
|
|
32
|
-
expect(loadProviderForCli({ cwd: os.tmpdir() })).toBeNull();
|
|
33
|
-
expect(loadCliAppDefinition('/nonexistent/path')).toBeNull();
|
|
34
|
-
expect(isNonAwsProject({ cwd: os.tmpdir() })).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('treats a missing provider as aws with no plugin', () => {
|
|
38
|
-
const { dir, backend } = writeProject(`{ integrations: [] }`);
|
|
39
|
-
dirs.push(dir);
|
|
40
|
-
expect(loadProviderForCli({ cwd: backend })).toEqual(
|
|
41
|
-
expect.objectContaining({ providerName: 'aws', provider: null, backendDir: backend })
|
|
42
|
-
);
|
|
43
|
-
expect(isNonAwsProject({ cwd: backend })).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('resolves the netlify plugin from the project root or from backend/', () => {
|
|
47
|
-
const { dir, backend } = writeProject(NETLIFY_APP);
|
|
48
|
-
dirs.push(dir);
|
|
49
|
-
for (const cwd of [dir, backend]) {
|
|
50
|
-
const result = loadProviderForCli({ cwd });
|
|
51
|
-
expect(result.providerName).toBe('netlify');
|
|
52
|
-
expect(result.provider.name).toBe('netlify');
|
|
53
|
-
expect(result.backendDir).toBe(backend);
|
|
54
|
-
}
|
|
55
|
-
expect(isNonAwsProject({ cwd: backend })).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('buildWithProvider', () => {
|
|
60
|
-
const { buildWithProvider } = require('../../../../infrastructure/provider-build');
|
|
61
|
-
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
jest.spyOn(console, 'log').mockImplementation();
|
|
64
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
65
|
-
jest.spyOn(console, 'error').mockImplementation();
|
|
66
|
-
});
|
|
67
|
-
afterEach(() => jest.restoreAllMocks());
|
|
68
|
-
|
|
69
|
-
it('writes netlify.toml, functions and lib shims beside backend/, where their requires resolve', () => {
|
|
70
|
-
const { dir, backend } = writeProject(NETLIFY_APP);
|
|
71
|
-
try {
|
|
72
|
-
const appDefinition = require(path.join(backend, 'index.js')).Definition;
|
|
73
|
-
const { projectDir } = buildWithProvider({ appDefinition, backendDir: backend });
|
|
74
|
-
|
|
75
|
-
expect(projectDir).toBe(dir);
|
|
76
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(true);
|
|
77
|
-
const auth = fs.readFileSync(path.join(dir, 'netlify/functions/auth.js'), 'utf8');
|
|
78
|
-
expect(auth).toContain("require('../../backend/index.js')");
|
|
79
|
-
expect(fs.existsSync(path.join(dir, 'netlify/lib/create-netlify-app-handler.js'))).toBe(true);
|
|
80
|
-
// Nothing is written into the backend directory itself.
|
|
81
|
-
expect(fs.existsSync(path.join(backend, 'netlify'))).toBe(false);
|
|
82
|
-
} finally {
|
|
83
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('stops on validation errors and writes nothing', () => {
|
|
88
|
-
const exit = jest.fn();
|
|
89
|
-
const { dir, backend } = writeProject(`{ provider: 'netlify', integrations: [] }`);
|
|
90
|
-
try {
|
|
91
|
-
const appDefinition = require(path.join(backend, 'index.js')).Definition;
|
|
92
|
-
const { written } = buildWithProvider({ appDefinition, backendDir: backend, exit });
|
|
93
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
94
|
-
expect(written).toEqual([]);
|
|
95
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(false);
|
|
96
|
-
} finally {
|
|
97
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('frigg build dispatch', () => {
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
jest.resetModules();
|
|
105
|
-
jest.spyOn(console, 'log').mockImplementation();
|
|
106
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
107
|
-
});
|
|
108
|
-
afterEach(() => {
|
|
109
|
-
jest.restoreAllMocks();
|
|
110
|
-
jest.dontMock('child_process');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('builds a netlify app through the plugin, never through osls', async () => {
|
|
114
|
-
const spawnSync = jest.fn(() => ({ status: 0 }));
|
|
115
|
-
jest.doMock('child_process', () => ({ ...jest.requireActual('child_process'), spawnSync }));
|
|
116
|
-
const { dir, backend } = writeProject(NETLIFY_APP);
|
|
117
|
-
try {
|
|
118
|
-
jest.spyOn(process, 'cwd').mockReturnValue(backend);
|
|
119
|
-
await require('../../../build-command').buildCommand({});
|
|
120
|
-
expect(spawnSync).not.toHaveBeenCalled();
|
|
121
|
-
expect(fs.existsSync(path.join(dir, 'netlify/functions/worker-background.js'))).toBe(true);
|
|
122
|
-
} finally {
|
|
123
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('keeps the serverless path for an aws app', async () => {
|
|
128
|
-
const spawnSync = jest.fn(() => ({ status: 0 }));
|
|
129
|
-
jest.doMock('child_process', () => ({ ...jest.requireActual('child_process'), spawnSync }));
|
|
130
|
-
const { dir, backend } = writeProject(`{ integrations: [] }`);
|
|
131
|
-
try {
|
|
132
|
-
jest.spyOn(process, 'cwd').mockReturnValue(backend);
|
|
133
|
-
await require('../../../build-command').buildCommand({});
|
|
134
|
-
expect(spawnSync).toHaveBeenCalledWith('osls', expect.any(Array), expect.any(Object));
|
|
135
|
-
expect(fs.existsSync(path.join(dir, 'netlify'))).toBe(false);
|
|
136
|
-
} finally {
|
|
137
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Provider Helper (friggframework/frigg#545, 88cf983e / c8705715)
|
|
3
|
-
*
|
|
4
|
-
* Loads the app definition from the user's project and resolves its
|
|
5
|
-
* provider plugin, so CLI commands can delegate to it (Netlify, ...) or fall
|
|
6
|
-
* through to the AWS/serverless behaviour.
|
|
7
|
-
*/
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Find the backend: <cwd>/backend/index.js, then <cwd>/index.js.
|
|
13
|
-
* @param {string} cwd
|
|
14
|
-
* @returns {{ appDefinition: Object, backendDir: string } | null}
|
|
15
|
-
*/
|
|
16
|
-
function loadCliBackend(cwd) {
|
|
17
|
-
for (const dir of [path.join(cwd, 'backend'), cwd]) {
|
|
18
|
-
const indexPath = path.join(dir, 'index.js');
|
|
19
|
-
if (!fs.existsSync(indexPath)) continue;
|
|
20
|
-
try {
|
|
21
|
-
const exported = require(indexPath);
|
|
22
|
-
if (exported && exported.Definition) {
|
|
23
|
-
return { appDefinition: exported.Definition, backendDir: dir };
|
|
24
|
-
}
|
|
25
|
-
} catch {
|
|
26
|
-
// Failed to load, try next
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {string} cwd
|
|
34
|
-
* @returns {Object|null} the app Definition
|
|
35
|
-
*/
|
|
36
|
-
function loadCliAppDefinition(cwd) {
|
|
37
|
-
return loadCliBackend(cwd)?.appDefinition || null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Load the app definition and resolve the provider plugin for CLI commands.
|
|
42
|
-
*
|
|
43
|
-
* @param {Object} [options]
|
|
44
|
-
* @param {string} [options.cwd] - Working directory (default: process.cwd())
|
|
45
|
-
* @returns {{ appDefinition: Object, backendDir: string, provider: Object|null, providerName: string } | null}
|
|
46
|
-
* null when no app definition is found; provider null for 'aws' (the
|
|
47
|
-
* caller keeps its existing behaviour).
|
|
48
|
-
*/
|
|
49
|
-
function loadProviderForCli(options = {}) {
|
|
50
|
-
const cwd = options.cwd || process.cwd();
|
|
51
|
-
const backend = loadCliBackend(cwd);
|
|
52
|
-
if (!backend) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const providerName = backend.appDefinition.provider || 'aws';
|
|
57
|
-
if (providerName === 'aws') {
|
|
58
|
-
return { ...backend, provider: null, providerName: 'aws' };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
resolveProvider,
|
|
63
|
-
} = require('@friggframework/core/providers/resolve-provider');
|
|
64
|
-
return { ...backend, provider: resolveProvider(backend.appDefinition), providerName };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* True when the project's app definition names a non-AWS provider. Used to
|
|
69
|
-
* guard the AWS-only commands (doctor, repair, generate-iam).
|
|
70
|
-
*/
|
|
71
|
-
function isNonAwsProject(options = {}) {
|
|
72
|
-
try {
|
|
73
|
-
const result = loadProviderForCli(options);
|
|
74
|
-
return Boolean(result && result.providerName !== 'aws');
|
|
75
|
-
} catch {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = { loadProviderForCli, loadCliAppDefinition, loadCliBackend, isNonAwsProject };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `node infrastructure.js package` (what a backend's `npm run build` runs)
|
|
3
|
-
* for an app with provider 'netlify': createFriggInfrastructure() builds
|
|
4
|
-
* through provider-netlify and returns an empty serverless definition
|
|
5
|
-
* instead of composing CloudFormation (friggframework/frigg#545, 302ab9ba).
|
|
6
|
-
*/
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const os = require('os');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
|
|
11
|
-
jest.mock('../infrastructure-composer', () => ({
|
|
12
|
-
composeServerlessDefinition: jest.fn(async () => ({ service: 'aws-app' })),
|
|
13
|
-
}));
|
|
14
|
-
jest.mock('@friggframework/core', () => ({
|
|
15
|
-
findNearestBackendPackageJson: jest.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
19
|
-
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
20
|
-
const { createFriggInfrastructure } = require('../create-frigg-infrastructure');
|
|
21
|
-
|
|
22
|
-
function writeProject(definitionSource) {
|
|
23
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-infra-'));
|
|
24
|
-
const backend = path.join(dir, 'backend');
|
|
25
|
-
fs.mkdirSync(backend);
|
|
26
|
-
fs.writeFileSync(path.join(backend, 'package.json'), '{"name":"backend"}');
|
|
27
|
-
fs.writeFileSync(path.join(backend, 'index.js'), `module.exports = { Definition: ${definitionSource} };`);
|
|
28
|
-
findNearestBackendPackageJson.mockReturnValue(path.join(backend, 'package.json'));
|
|
29
|
-
return dir;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('createFriggInfrastructure with a non-AWS provider', () => {
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
jest.clearAllMocks();
|
|
35
|
-
jest.spyOn(console, 'log').mockImplementation();
|
|
36
|
-
jest.spyOn(console, 'warn').mockImplementation();
|
|
37
|
-
});
|
|
38
|
-
afterEach(() => jest.restoreAllMocks());
|
|
39
|
-
|
|
40
|
-
it('generates the Netlify project and composes no serverless definition', async () => {
|
|
41
|
-
const dir = writeProject(`{
|
|
42
|
-
provider: 'netlify', integrations: [], database: { postgres: { enable: true } }
|
|
43
|
-
}`);
|
|
44
|
-
try {
|
|
45
|
-
await expect(createFriggInfrastructure()).resolves.toEqual({});
|
|
46
|
-
expect(composeServerlessDefinition).not.toHaveBeenCalled();
|
|
47
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(true);
|
|
48
|
-
expect(fs.existsSync(path.join(dir, 'netlify/functions/auth.js'))).toBe(true);
|
|
49
|
-
expect(fs.existsSync(path.join(dir, 'netlify/lib/create-netlify-app-handler.js'))).toBe(true);
|
|
50
|
-
} finally {
|
|
51
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('keeps composing the serverless definition for AWS', async () => {
|
|
56
|
-
const dir = writeProject(`{ provider: 'aws', integrations: [] }`);
|
|
57
|
-
try {
|
|
58
|
-
await expect(createFriggInfrastructure()).resolves.toEqual({ service: 'aws-app' });
|
|
59
|
-
expect(fs.existsSync(path.join(dir, 'netlify.toml'))).toBe(false);
|
|
60
|
-
} finally {
|
|
61
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|