@friggframework/devtools 2.0.0--canary.707.df52379.0 → 2.0.0--canary.686.20eda6e.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.
@@ -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
 
@@ -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, invalidatePrismaLayer } = require('./domains/shared/utilities/prisma-layer-manager');
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 || {});
@@ -3,9 +3,7 @@
3
3
  * c8705715).
4
4
  *
5
5
  * Instead of the serverless/CloudFormation pipeline, the provider plugin
6
- * (resolved from appDefinition.provider) does the build. First, core
7
- * extensions' Prisma models are composed into the backend's Prisma client
8
- * (compose-extension-prisma.js), since the functions bundle that client:
6
+ * (resolved from appDefinition.provider) does the build:
9
7
  * 1. validate(appDefinition) - errors abort, warnings print
10
8
  * 2. generateConfig(appDefinition) - e.g. netlify.toml
11
9
  * 3. getFunctionEntryPoints(appDefinition) - written to <project>/netlify/functions
@@ -21,7 +19,6 @@
21
19
  */
22
20
  const path = require('path');
23
21
  const fs = require('fs');
24
- const { composeAppExtensionPrisma } = require('./compose-extension-prisma');
25
22
 
26
23
  const CONFIG_FILE_NAMES = { netlify: 'netlify.toml' };
27
24
 
@@ -32,7 +29,6 @@ const CONFIG_FILE_NAMES = { netlify: 'netlify.toml' };
32
29
  * @param {Object} [params.provider] - resolved plugin; defaults to resolveProvider(appDefinition)
33
30
  * @param {boolean} [params.verbose]
34
31
  * @param {Function} [params.exit] - called with 1 on validation errors (default process.exit)
35
- * @param {Function} [params.composePrisma] - extension Prisma composition (injected in tests)
36
32
  * @returns {{ projectDir: string, written: string[] }}
37
33
  */
38
34
  function buildWithProvider({
@@ -41,7 +37,6 @@ function buildWithProvider({
41
37
  provider,
42
38
  verbose = false,
43
39
  exit = (code) => process.exit(code),
44
- composePrisma = composeAppExtensionPrisma,
45
40
  }) {
46
41
  const providerName = appDefinition.provider;
47
42
  const plugin =
@@ -69,8 +64,6 @@ function buildWithProvider({
69
64
  }
70
65
  }
71
66
 
72
- composePrisma({ appDefinition, backendDir });
73
-
74
67
  const write = (filePath, content) => {
75
68
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
76
69
  fs.writeFileSync(filePath, content, 'utf-8');
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.707.df52379.0",
4
+ "version": "2.0.0--canary.686.20eda6e.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.707.df52379.0",
30
- "@friggframework/schemas": "2.0.0--canary.707.df52379.0",
31
- "@friggframework/test": "2.0.0--canary.707.df52379.0",
29
+ "@friggframework/core": "2.0.0--canary.686.20eda6e.0",
30
+ "@friggframework/schemas": "2.0.0--canary.686.20eda6e.0",
31
+ "@friggframework/test": "2.0.0--canary.686.20eda6e.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.707.df52379.0",
60
- "@friggframework/prettier-config": "2.0.0--canary.707.df52379.0",
59
+ "@friggframework/eslint-config": "2.0.0--canary.686.20eda6e.0",
60
+ "@friggframework/prettier-config": "2.0.0--canary.686.20eda6e.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": "df52379ae496d26aec99abe2127f304230e86f36"
92
+ "gitHead": "20eda6e4013af2a8b0432122b697a352b40350c0"
93
93
  }
@@ -1,168 +0,0 @@
1
- /**
2
- * The build step that composes core extension schemas into the backend's
3
- * installed @friggframework/core. Uses a temp backend whose node_modules holds
4
- * a core with the real composer and a minimal PostgreSQL schema.
5
- */
6
- const fs = require('fs');
7
- const os = require('os');
8
- const path = require('path');
9
- const { composeAppExtensionPrisma } = require('../compose-extension-prisma');
10
- const { buildWithProvider } = require('../provider-build');
11
-
12
- const REAL_CORE = path.dirname(
13
- require.resolve('@friggframework/core/package.json')
14
- );
15
-
16
- const BASE = `datasource db {
17
- provider = "postgresql"
18
- url = env("DATABASE_URL")
19
- }
20
-
21
- model User {
22
- id Int @id
23
- }
24
- `;
25
-
26
- function makeBackend({ withCore = true } = {}) {
27
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-compose-ext-'));
28
- const backend = path.join(dir, 'backend');
29
- fs.mkdirSync(backend);
30
- fs.writeFileSync(path.join(backend, 'package.json'), '{"name":"backend"}');
31
- const extSchema = path.join(dir, 'ext.prisma');
32
- fs.writeFileSync(
33
- extSchema,
34
- 'model OAuthAppCredential {\n id Int @id\n}\n'
35
- );
36
- let core = null;
37
- if (withCore) {
38
- core = path.join(backend, 'node_modules', '@friggframework', 'core');
39
- fs.mkdirSync(path.join(core, 'prisma-postgresql'), { recursive: true });
40
- fs.writeFileSync(
41
- path.join(core, 'package.json'),
42
- '{"name":"@friggframework/core"}'
43
- );
44
- fs.writeFileSync(
45
- path.join(core, 'prisma-postgresql', 'schema.prisma'),
46
- BASE
47
- );
48
- fs.symlinkSync(
49
- path.join(REAL_CORE, 'extensions'),
50
- path.join(core, 'extensions'),
51
- 'dir'
52
- );
53
- fs.symlinkSync(
54
- path.join(REAL_CORE, 'management-api'),
55
- path.join(core, 'management-api'),
56
- 'dir'
57
- );
58
- }
59
- return { dir, backend, core, extSchema };
60
- }
61
-
62
- const appDefinition = (extSchema) => ({
63
- name: 'compose-app',
64
- provider: 'netlify',
65
- integrations: [],
66
- database: { postgres: { enable: true } },
67
- coreExtensions: [{ name: 'db-credentials', schema: extSchema }],
68
- });
69
-
70
- describe('composeAppExtensionPrisma', () => {
71
- const dirs = [];
72
- afterAll(() =>
73
- dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true }))
74
- );
75
-
76
- it("composes into the backend's installed core, not devtools' copy", () => {
77
- const { dir, backend, core, extSchema } = makeBackend();
78
- dirs.push(dir);
79
- const generated = [];
80
- const result = composeAppExtensionPrisma({
81
- appDefinition: appDefinition(extSchema),
82
- backendDir: backend,
83
- generate: ({ corePath }) => generated.push(corePath),
84
- log: () => {},
85
- });
86
- expect(result.changed).toBe(true);
87
- expect(generated).toEqual([core]);
88
- expect(
89
- fs.readFileSync(
90
- path.join(core, 'prisma-postgresql', 'schema.prisma'),
91
- 'utf-8'
92
- )
93
- ).toContain('model OAuthAppCredential');
94
- });
95
-
96
- it('is a no-op without an installed core when no extension declares a schema', () => {
97
- const { dir, backend } = makeBackend({ withCore: false });
98
- dirs.push(dir);
99
- expect(
100
- composeAppExtensionPrisma({
101
- appDefinition: { coreExtensions: [{ name: 'x' }] },
102
- backendDir: backend,
103
- })
104
- ).toEqual({ changed: false, results: [] });
105
- });
106
-
107
- it('refuses to build without an installed core when an extension declares a schema', () => {
108
- const { dir, backend, extSchema } = makeBackend({ withCore: false });
109
- dirs.push(dir);
110
- expect(() =>
111
- composeAppExtensionPrisma({
112
- appDefinition: appDefinition(extSchema),
113
- backendDir: backend,
114
- })
115
- ).toThrow(
116
- /declare Prisma schemas, but @friggframework\/core is not installed/
117
- );
118
- });
119
- });
120
-
121
- describe('buildWithProvider composes extension schemas', () => {
122
- const plugin = {
123
- validate: () => ({ errors: [], warnings: [] }),
124
- generateConfig: () => '# config',
125
- };
126
-
127
- it('composes before writing the provider files', () => {
128
- const { dir, backend } = makeBackend({ withCore: false });
129
- try {
130
- const order = [];
131
- const def = { provider: 'netlify', integrations: [] };
132
- buildWithProvider({
133
- appDefinition: def,
134
- backendDir: backend,
135
- provider: {
136
- ...plugin,
137
- generateConfig: () => (order.push('config'), '# config'),
138
- },
139
- composePrisma: (args) =>
140
- order.push([
141
- 'compose',
142
- args.appDefinition,
143
- args.backendDir,
144
- ]),
145
- });
146
- expect(order).toEqual([['compose', def, backend], 'config']);
147
- } finally {
148
- fs.rmSync(dir, { recursive: true, force: true });
149
- }
150
- });
151
-
152
- it('does not compose when validation fails', () => {
153
- const { dir, backend } = makeBackend({ withCore: false });
154
- try {
155
- const compose = jest.fn();
156
- buildWithProvider({
157
- appDefinition: { provider: 'netlify' },
158
- backendDir: backend,
159
- provider: { validate: () => ({ errors: ['bad'] }) },
160
- composePrisma: compose,
161
- exit: () => {},
162
- });
163
- expect(compose).not.toHaveBeenCalled();
164
- } finally {
165
- fs.rmSync(dir, { recursive: true, force: true });
166
- }
167
- });
168
- });
@@ -1,73 +0,0 @@
1
- /**
2
- * Build-time step: put the app's core extension models (and PostgreSQL
3
- * migrations) into the Prisma client of the @friggframework/core the backend
4
- * installed. See core's extensions/prisma-composer.js.
5
- *
6
- * It must run on the backend's own core, not devtools' copy: that is the
7
- * package the functions bundle and the Lambda layer copy their client from.
8
- */
9
- const fs = require('fs');
10
- const path = require('path');
11
-
12
- /**
13
- * Directory of the @friggframework/core the backend resolves.
14
- * @param {string} backendDir
15
- */
16
- function resolveBackendCorePath(backendDir) {
17
- return path.dirname(
18
- require.resolve('@friggframework/core/package.json', {
19
- paths: [backendDir],
20
- })
21
- );
22
- }
23
-
24
- /**
25
- * @param {Object} params
26
- * @param {Object} params.appDefinition
27
- * @param {string} params.backendDir - directory holding the backend's package.json
28
- * @param {Function} [params.generate] - injected prisma generate (tests)
29
- * @param {Function} [params.log]
30
- * @returns {{ changed: boolean, results: Array<Object> }}
31
- */
32
- function composeAppExtensionPrisma({
33
- appDefinition,
34
- backendDir,
35
- generate,
36
- log,
37
- }) {
38
- const declares = (appDefinition?.coreExtensions || []).some(
39
- (ext) => ext && (ext.schema || ext.migrations)
40
- );
41
- let corePath;
42
- try {
43
- corePath = resolveBackendCorePath(backendDir);
44
- } catch (error) {
45
- // No installed core to compose into. Fine when nothing needs composing.
46
- if (!declares) return { changed: false, results: [] };
47
- throw new Error(
48
- `Core extensions declare Prisma schemas, but @friggframework/core is not installed for ${backendDir}`,
49
- { cause: error }
50
- );
51
- }
52
- const composerPath = path.join(
53
- corePath,
54
- 'extensions',
55
- 'prisma-composer.js'
56
- );
57
- if (!fs.existsSync(composerPath)) {
58
- if (!declares) return { changed: false, results: [] };
59
- throw new Error(
60
- `@friggframework/core at ${corePath} cannot compose extension schemas; ` +
61
- 'upgrade it to the version devtools was built with'
62
- );
63
- }
64
- const { composeExtensionPrisma } = require(composerPath);
65
- return composeExtensionPrisma({
66
- appDefinition,
67
- corePath,
68
- ...(generate ? { generate } : {}),
69
- ...(log ? { log } : {}),
70
- });
71
- }
72
-
73
- module.exports = { composeAppExtensionPrisma, resolveBackendCorePath };