@friggframework/devtools 2.0.0--canary.707.df80bfd.0 → 2.0.0--canary.680.d670696.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/db-setup-command/index.js +0 -25
- 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/shared/types/app-definition.js +1 -15
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +3 -5
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -24
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +0 -10
- package/infrastructure/infrastructure-composer.js +1 -13
- 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__/compose-extension-prisma.test.js +0 -168
- package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
- package/infrastructure/compose-extension-prisma.js +0 -73
- package/infrastructure/provider-build.js +0 -126
- package/test/npm-install-guard.js +0 -104
- package/test/npm-install-guard.test.js +0 -53
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
const { spawnSync } = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
-
async function buildCommand(options
|
|
5
|
-
// A non-AWS provider (appDefinition.provider) builds through its plugin:
|
|
6
|
-
// platform config + function entry points, no serverless package
|
|
7
|
-
// (friggframework/frigg#545).
|
|
8
|
-
const providerResult = loadProviderIfConfigured();
|
|
9
|
-
if (providerResult) {
|
|
10
|
-
const { buildWithProvider } = require('../../infrastructure/provider-build');
|
|
11
|
-
buildWithProvider({
|
|
12
|
-
appDefinition: providerResult.appDefinition,
|
|
13
|
-
backendDir: providerResult.backendDir,
|
|
14
|
-
provider: providerResult.provider,
|
|
15
|
-
verbose: options.verbose,
|
|
16
|
-
});
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
4
|
+
async function buildCommand(options) {
|
|
20
5
|
console.log('Building the serverless application...');
|
|
21
6
|
|
|
22
7
|
// Suppress AWS SDK warning message about maintenance mode
|
|
@@ -78,20 +63,4 @@ async function buildCommand(options = {}) {
|
|
|
78
63
|
// });
|
|
79
64
|
}
|
|
80
65
|
|
|
81
|
-
/**
|
|
82
|
-
* The resolved non-AWS provider, or null for AWS / no app definition found.
|
|
83
|
-
*/
|
|
84
|
-
function loadProviderIfConfigured() {
|
|
85
|
-
const { loadProviderForCli } = require('../utils/provider-helper');
|
|
86
|
-
let result;
|
|
87
|
-
try {
|
|
88
|
-
result = loadProviderForCli();
|
|
89
|
-
} catch (error) {
|
|
90
|
-
// A non-AWS provider whose package is missing: say so, don't build for AWS.
|
|
91
|
-
console.error(error.message);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
return result && result.provider ? result : null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
66
|
module.exports = { buildCommand };
|
|
@@ -20,27 +20,6 @@ const {
|
|
|
20
20
|
getDatabaseSetupSuccess,
|
|
21
21
|
} = require('../utils/error-messages');
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* Composes the backend's core extension schemas into core's Prisma client.
|
|
25
|
-
* A backend whose index.js cannot be found has no extensions to compose.
|
|
26
|
-
*/
|
|
27
|
-
function composeExtensionPrismaForBackend(verbose) {
|
|
28
|
-
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
29
|
-
const backendPackageJson = findNearestBackendPackageJson();
|
|
30
|
-
if (!backendPackageJson) return;
|
|
31
|
-
const backendDir = path.dirname(backendPackageJson);
|
|
32
|
-
const indexPath = path.join(backendDir, 'index.js');
|
|
33
|
-
if (!require('fs').existsSync(indexPath)) return;
|
|
34
|
-
const appDefinition = require(indexPath).Definition;
|
|
35
|
-
const { composeAppExtensionPrisma } = require('../../infrastructure/compose-extension-prisma');
|
|
36
|
-
const { results } = composeAppExtensionPrisma({ appDefinition, backendDir });
|
|
37
|
-
if (verbose) {
|
|
38
|
-
for (const r of results) {
|
|
39
|
-
console.log(chalk.gray(` Extension schemas (${r.dbType}): ${r.changed ? 'composed' : 'unchanged'}`));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
23
|
function getDatabaseDisplayName(dbType) {
|
|
45
24
|
switch (dbType) {
|
|
46
25
|
case 'postgresql':
|
|
@@ -130,10 +109,6 @@ async function dbSetupCommand(options = {}) {
|
|
|
130
109
|
console.log(chalk.gray('Step 3: Checking Prisma client...'));
|
|
131
110
|
}
|
|
132
111
|
|
|
133
|
-
// Core extensions' models must be in the client (and, on PostgreSQL,
|
|
134
|
-
// their migrations next to core's) before generating or migrating.
|
|
135
|
-
composeExtensionPrismaForBackend(verbose);
|
|
136
|
-
|
|
137
112
|
const clientCheck = checkPrismaClientGenerated(dbType);
|
|
138
113
|
const forceRegenerate = options.force || false;
|
|
139
114
|
|
|
@@ -310,16 +310,9 @@ async function pushOffloadedParametersOrAbort(appDefinition, options) {
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
async function deployCommand(options) {
|
|
313
|
-
const appDefinition = loadAppDefinition();
|
|
314
|
-
|
|
315
|
-
// A non-AWS provider (appDefinition.provider) deploys through its plugin
|
|
316
|
-
// (friggframework/frigg#545).
|
|
317
|
-
const providerName = appDefinition?.provider;
|
|
318
|
-
if (providerName && providerName !== 'aws') {
|
|
319
|
-
return deployWithProvider(appDefinition, providerName, options);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
313
|
console.log('Deploying the serverless application...');
|
|
314
|
+
|
|
315
|
+
const appDefinition = loadAppDefinition();
|
|
323
316
|
const environment = validateAndBuildEnvironment(appDefinition, options);
|
|
324
317
|
|
|
325
318
|
await pushOffloadedParametersOrAbort(appDefinition, options);
|
|
@@ -353,45 +346,4 @@ async function deployCommand(options) {
|
|
|
353
346
|
}
|
|
354
347
|
}
|
|
355
348
|
|
|
356
|
-
/**
|
|
357
|
-
* Deploy with a provider plugin: validate(), then deploy() (which runs its
|
|
358
|
-
* own preflightCheck()).
|
|
359
|
-
*/
|
|
360
|
-
async function deployWithProvider(appDefinition, providerName, options = {}) {
|
|
361
|
-
let provider;
|
|
362
|
-
try {
|
|
363
|
-
const { resolveProvider } = require('@friggframework/core/providers/resolve-provider');
|
|
364
|
-
provider = resolveProvider(appDefinition);
|
|
365
|
-
} catch (error) {
|
|
366
|
-
console.error(`Failed to load provider '${providerName}': ${error.message}`);
|
|
367
|
-
process.exit(1);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
console.log(`Deploying with ${providerName} provider...`);
|
|
371
|
-
|
|
372
|
-
if (typeof provider.validate === 'function') {
|
|
373
|
-
const validation = provider.validate(appDefinition);
|
|
374
|
-
if (validation.errors?.length > 0) {
|
|
375
|
-
console.error(`\nValidation errors for ${providerName}:`);
|
|
376
|
-
for (const error of validation.errors) console.error(` - ${error}`);
|
|
377
|
-
process.exit(1);
|
|
378
|
-
}
|
|
379
|
-
for (const warning of validation.warnings || []) console.warn(` Warning: ${warning}`);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
const result = await provider.deploy(appDefinition, {
|
|
384
|
-
stage: options.stage,
|
|
385
|
-
prod: options.stage === 'production' || options.stage === 'prod',
|
|
386
|
-
dryRun: options.dryRun || false,
|
|
387
|
-
});
|
|
388
|
-
console.log('\nDeployment completed successfully.');
|
|
389
|
-
if (result?.url) console.log(` URL: ${result.url}`);
|
|
390
|
-
} catch (error) {
|
|
391
|
-
console.error(`\nDeployment failed: ${error.message}`);
|
|
392
|
-
for (const item of error.missing || []) console.error(` - ${item}`);
|
|
393
|
-
process.exit(1);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
349
|
module.exports = { deployCommand };
|
|
@@ -246,13 +246,6 @@ async function promptForStackSelection(region) {
|
|
|
246
246
|
*/
|
|
247
247
|
async function doctorCommand(stackName, options = {}) {
|
|
248
248
|
try {
|
|
249
|
-
// AWS-only (CloudFormation); a non-AWS provider has nothing to inspect.
|
|
250
|
-
if (require('../utils/provider-helper').isNonAwsProject()) {
|
|
251
|
-
output.error('The doctor command is only available for AWS deployments.');
|
|
252
|
-
output.log('Your appDefinition uses a non-AWS provider.');
|
|
253
|
-
process.exit(1);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
249
|
// Extract options with defaults
|
|
257
250
|
const region = options.region || process.env.AWS_REGION || 'us-east-1';
|
|
258
251
|
const format = options.format || 'console';
|
|
@@ -9,13 +9,6 @@ const { generateIAMCloudFormation, getFeatureSummary } = require('../infrastruct
|
|
|
9
9
|
*/
|
|
10
10
|
async function generateIamCommand(options = {}) {
|
|
11
11
|
try {
|
|
12
|
-
// AWS-only (CloudFormation); a non-AWS provider has nothing to inspect.
|
|
13
|
-
if (require('./utils/provider-helper').isNonAwsProject()) {
|
|
14
|
-
console.error('The generate-iam command is only available for AWS deployments.');
|
|
15
|
-
console.log('Your appDefinition uses a non-AWS provider.');
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
console.log('🔍 Finding Frigg application...');
|
|
20
13
|
|
|
21
14
|
// Find the backend package.json
|
|
@@ -453,13 +453,6 @@ async function handleReconcileRepair(stackIdentifier, report, options) {
|
|
|
453
453
|
*/
|
|
454
454
|
async function repairCommand(stackName, options = {}) {
|
|
455
455
|
try {
|
|
456
|
-
// AWS-only (CloudFormation); a non-AWS provider has nothing to inspect.
|
|
457
|
-
if (require('../utils/provider-helper').isNonAwsProject()) {
|
|
458
|
-
output.error('The repair command is only available for AWS deployments.');
|
|
459
|
-
output.log('Your appDefinition uses a non-AWS provider.');
|
|
460
|
-
process.exit(1);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
456
|
// Validate required parameter
|
|
464
457
|
if (!stackName) {
|
|
465
458
|
console.error('Error: Stack name is required');
|
|
@@ -37,12 +37,6 @@ async function startCommand(options) {
|
|
|
37
37
|
console.log(chalk.green('✓ Database checks passed\n'));
|
|
38
38
|
console.log('Starting backend and optional frontend...');
|
|
39
39
|
|
|
40
|
-
// A non-AWS provider runs its own local dev server (friggframework/frigg#545).
|
|
41
|
-
const providerResult = loadNonAwsProvider();
|
|
42
|
-
if (providerResult) {
|
|
43
|
-
return startWithProvider(providerResult, options);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
40
|
// Suppress AWS SDK warning message about maintenance mode
|
|
47
41
|
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
|
|
48
42
|
// Skip AWS discovery for local development
|
|
@@ -152,56 +146,4 @@ async function performDatabaseChecks(verbose) {
|
|
|
152
146
|
// connection when it starts.
|
|
153
147
|
}
|
|
154
148
|
|
|
155
|
-
function loadNonAwsProvider() {
|
|
156
|
-
try {
|
|
157
|
-
const { loadProviderForCli } = require('../utils/provider-helper');
|
|
158
|
-
const result = loadProviderForCli();
|
|
159
|
-
return result && result.provider ? result : null;
|
|
160
|
-
} catch {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Local dev server per provider: Netlify -> `netlify dev` (reads netlify.toml
|
|
167
|
-
* and serves the generated functions), run from the project root that holds
|
|
168
|
-
* backend/ and netlify.toml.
|
|
169
|
-
*/
|
|
170
|
-
function startWithProvider({ providerName, backendDir }, options = {}) {
|
|
171
|
-
const DEV_COMMANDS = {
|
|
172
|
-
netlify: { command: 'netlify', args: ['dev'] },
|
|
173
|
-
};
|
|
174
|
-
const devCmd = DEV_COMMANDS[providerName];
|
|
175
|
-
if (!devCmd) {
|
|
176
|
-
console.error(chalk.red(
|
|
177
|
-
`Provider '${providerName}' does not have a local dev server configured.\n` +
|
|
178
|
-
` Supported providers for local dev: ${Object.keys(DEV_COMMANDS).join(', ')}, aws`
|
|
179
|
-
));
|
|
180
|
-
process.exit(1);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const cwd = require('node:path').dirname(backendDir);
|
|
184
|
-
console.log(chalk.blue(`Starting local dev server (${providerName})...`));
|
|
185
|
-
if (options.verbose) {
|
|
186
|
-
console.log(`Executing command: ${devCmd.command} ${devCmd.args.join(' ')}`);
|
|
187
|
-
console.log(`Working directory: ${cwd}`);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const childProcess = spawn(devCmd.command, devCmd.args, {
|
|
191
|
-
cwd,
|
|
192
|
-
stdio: 'inherit',
|
|
193
|
-
env: { ...process.env },
|
|
194
|
-
});
|
|
195
|
-
childProcess.on('error', (error) => {
|
|
196
|
-
if (error.code === 'ENOENT') {
|
|
197
|
-
console.error(chalk.red(`'${devCmd.command}' not found. Install it with: npm install -g ${devCmd.command}-cli`));
|
|
198
|
-
} else {
|
|
199
|
-
console.error(`Error executing command: ${error.message}`);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
childProcess.on('close', (code) => {
|
|
203
|
-
if (code !== 0) console.log(`Child process exited with code ${code}`);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
149
|
module.exports = { startCommand };
|
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
* valid, consistent CloudFormation templates.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// Composing must not build the real Prisma layer: that runs npm install
|
|
9
|
-
// under packages/devtools, and two workers doing it at once once pruned the
|
|
10
|
-
// repository's root node_modules (test/npm-install-guard.js).
|
|
11
|
-
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
12
|
-
ensurePrismaLayerExists: jest.fn(async () => {}),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
8
|
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
16
9
|
|
|
17
10
|
describe('CloudFormation Template Generation', () => {
|
|
@@ -35,20 +35,6 @@ async function createFriggInfrastructure() {
|
|
|
35
35
|
throw new Error('Could not find index.js');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// A non-AWS provider (appDefinition.provider, e.g. 'netlify') builds
|
|
39
|
-
// through its provider plugin instead of serverless/CloudFormation
|
|
40
|
-
// (friggframework/frigg#545). Checked before the cache: the cache holds
|
|
41
|
-
// serverless definitions only. Returns an empty serverless definition,
|
|
42
|
-
// so an osls invocation has nothing to package.
|
|
43
|
-
{
|
|
44
|
-
const { isNonAwsProvider, buildWithProvider } = require('./provider-build');
|
|
45
|
-
const appDefinition = require(backendFilePath).Definition;
|
|
46
|
-
if (isNonAwsProvider(appDefinition)) {
|
|
47
|
-
buildWithProvider({ appDefinition, backendDir });
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
38
|
const cachePath = getCachePath(backendDir);
|
|
53
39
|
const lockPath = getLockPath(backendDir);
|
|
54
40
|
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
* @typedef {Object} AppDefinition
|
|
130
130
|
* @property {string} name - Application name
|
|
131
131
|
* @property {string} stage - Deployment stage (e.g., 'dev', 'production')
|
|
132
|
-
* @property {string} provider -
|
|
132
|
+
* @property {string} provider - Cloud provider (e.g., 'aws')
|
|
133
133
|
* @property {string} region - AWS region
|
|
134
134
|
*
|
|
135
135
|
* @property {VpcDefinition} [vpc] - VPC configuration
|
|
@@ -144,20 +144,6 @@
|
|
|
144
144
|
* @property {AdminConfig} [admin] - Admin configuration
|
|
145
145
|
*
|
|
146
146
|
* @property {Object} [environment] - Environment variables
|
|
147
|
-
*
|
|
148
|
-
* @property {ExtensionDefinition[]} [coreExtensions] - Core (app-level) extensions that add custom Prisma models, encrypted fields, admin routes and bootstrap hooks (not an integration's Definition.extensions, nor ADR-017's keyed appDefinition.extensions)
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* App-level extension: custom models, encryption, admin routes and bootstrap
|
|
153
|
-
* @typedef {Object} ExtensionDefinition
|
|
154
|
-
* @property {string} name - Unique identifier for this extension
|
|
155
|
-
* @property {string} [schema] - Absolute path to a .prisma schema fragment
|
|
156
|
-
* @property {Object<string, {fields: string[]}>} [encryption] - Model name → encrypted fields mapping
|
|
157
|
-
* @property {Object} [routes] - Express router configuration
|
|
158
|
-
* @property {string} routes.path - Base URL path for the extension routes: /admin/<segment>..., never /api (/admin/scripts, /admin/db-migrate and /admin/queue are reserved); served by the auth function
|
|
159
|
-
* @property {Function|Object} routes.handler - Router factory (prisma, appDefinition) → Router, or { router } object
|
|
160
|
-
* @property {Function} [bootstrap] - Async function (prisma, appDefinition) → void, run by initializeApp()
|
|
161
147
|
*/
|
|
162
148
|
|
|
163
149
|
/**
|
|
@@ -15,17 +15,15 @@ const {
|
|
|
15
15
|
} = require('@friggframework/core/management-api/route-registry');
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* HTTP API events for one function, from core's
|
|
19
|
-
* the same registry mounts the Express routers and
|
|
20
|
-
* documents, so the three cannot drift.
|
|
21
|
-
* extensions' admin routes (/admin/<name>, served by the auth Lambda).
|
|
18
|
+
* HTTP API events for one function, from core's Management API route
|
|
19
|
+
* registry (ADR-053): the same registry mounts the Express routers and
|
|
20
|
+
* builds the OpenAPI documents, so the three cannot drift.
|
|
22
21
|
*/
|
|
23
22
|
function managementApiEvents(AppDefinition, functionName) {
|
|
24
23
|
const managementApi = AppDefinition.managementApi || {};
|
|
25
24
|
return getGatewayRoutes({
|
|
26
25
|
v1: managementApi.v1 !== false,
|
|
27
26
|
proxy: managementApi.proxy?.enable === true,
|
|
28
|
-
coreExtensions: AppDefinition.coreExtensions,
|
|
29
27
|
})
|
|
30
28
|
.filter((route) => route.function === functionName)
|
|
31
29
|
.map(({ method, path }) => ({ httpApi: { path, method } }));
|
|
@@ -142,33 +142,9 @@ describe('Base Definition Factory', () => {
|
|
|
142
142
|
'GET /health/{proxy+}',
|
|
143
143
|
'GET /api/meta',
|
|
144
144
|
'GET /api/meta/{proxy+}',
|
|
145
|
-
// Redirects to /api/meta/openapi/v2.json (ADR-053 docs path)
|
|
146
|
-
'GET /api/docs',
|
|
147
145
|
]);
|
|
148
146
|
});
|
|
149
147
|
|
|
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
148
|
it('drops the v1 routes when managementApi.v1 is false, keeping the OAuth redirect', () => {
|
|
173
149
|
const result = createBaseDefinition({ managementApi: { v1: false } }, {}, {});
|
|
174
150
|
const routes = result.functions.auth.events.map(
|
|
@@ -153,17 +153,7 @@ async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
/**
|
|
157
|
-
* Forces the next ensurePrismaLayerExists() to rebuild the layer, e.g. after
|
|
158
|
-
* the Prisma client it copies was regenerated.
|
|
159
|
-
*/
|
|
160
|
-
function invalidatePrismaLayer() {
|
|
161
|
-
const marker = path.join(process.cwd(), 'layers/prisma', '.build-complete');
|
|
162
|
-
fs.rmSync(marker, { force: true });
|
|
163
|
-
}
|
|
164
|
-
|
|
165
156
|
module.exports = {
|
|
166
|
-
invalidatePrismaLayer,
|
|
167
157
|
ensurePrismaLayerExists,
|
|
168
158
|
};
|
|
169
159
|
|
|
@@ -60,8 +60,7 @@ function applySsmPreloadNodeOptions(appDefinition, functions, providerEnvironmen
|
|
|
60
60
|
}
|
|
61
61
|
const { modifyHandlerPaths } = require('./domains/shared/utilities/handler-path-resolver');
|
|
62
62
|
const { createBaseDefinition } = require('./domains/shared/utilities/base-definition-factory');
|
|
63
|
-
const { ensurePrismaLayerExists
|
|
64
|
-
const { composeAppExtensionPrisma } = require('./compose-extension-prisma');
|
|
63
|
+
const { ensurePrismaLayerExists } = require('./domains/shared/utilities/prisma-layer-manager');
|
|
65
64
|
const { validateAndCleanPlugins, validatePackagingConfiguration } = require('./domains/shared/validation/plugin-validator');
|
|
66
65
|
|
|
67
66
|
/**
|
|
@@ -76,17 +75,6 @@ const composeServerlessDefinition = async (AppDefinition) => {
|
|
|
76
75
|
// Determine if deployment should use Prisma Lambda Layer (default: true)
|
|
77
76
|
const usePrismaLayer = AppDefinition.usePrismaLambdaLayer !== false;
|
|
78
77
|
|
|
79
|
-
// Core extensions' models go into core's Prisma client before anything
|
|
80
|
-
// copies it (the layer, or the functions when bundling Prisma). A changed
|
|
81
|
-
// client invalidates a layer built from the previous one.
|
|
82
|
-
const extensionPrisma = composeAppExtensionPrisma({
|
|
83
|
-
appDefinition: AppDefinition,
|
|
84
|
-
backendDir: process.cwd(),
|
|
85
|
-
});
|
|
86
|
-
if (extensionPrisma.changed && usePrismaLayer) {
|
|
87
|
-
invalidatePrismaLayer();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
78
|
// Ensure Prisma layer exists only when configured to use it
|
|
91
79
|
if (usePrismaLayer) {
|
|
92
80
|
await ensurePrismaLayerExists(AppDefinition.database || {});
|
|
@@ -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.680.d670696.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.680.d670696.0",
|
|
30
|
+
"@friggframework/schemas": "2.0.0--canary.680.d670696.0",
|
|
31
|
+
"@friggframework/test": "2.0.0--canary.680.d670696.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.680.d670696.0",
|
|
60
|
+
"@friggframework/prettier-config": "2.0.0--canary.680.d670696.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": "d6706963c56674519299fca904c380268b721911"
|
|
93
93
|
}
|