@friggframework/devtools 2.0.0--canary.686.821f8a3.0 → 2.0.0--canary.705.9cfd819.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 (28) hide show
  1. package/frigg-cli/build-command/index.js +1 -32
  2. package/frigg-cli/deploy-command/index.js +2 -50
  3. package/frigg-cli/doctor-command/index.js +0 -7
  4. package/frigg-cli/generate-iam-command.js +0 -7
  5. package/frigg-cli/repair-command/index.js +0 -7
  6. package/frigg-cli/start-command/index.js +0 -58
  7. package/infrastructure/README.md +2 -4
  8. package/infrastructure/__tests__/template-generation.test.js +0 -7
  9. package/infrastructure/create-frigg-infrastructure.js +0 -14
  10. package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
  11. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
  12. package/infrastructure/domains/parameters/offload-utils.js +0 -1
  13. package/infrastructure/domains/shared/environment-builder.js +1 -12
  14. package/infrastructure/domains/shared/environment-builder.test.js +0 -20
  15. package/infrastructure/domains/shared/types/app-definition.js +1 -15
  16. package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -28
  17. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -85
  18. package/infrastructure/infrastructure-composer.test.js +0 -7
  19. package/infrastructure/scripts/build-prisma-layer.js +5 -32
  20. package/infrastructure/scripts/build-prisma-layer.test.js +0 -35
  21. package/package.json +7 -7
  22. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -140
  23. package/frigg-cli/utils/provider-helper.js +0 -80
  24. package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
  25. package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -335
  26. package/infrastructure/provider-build.js +0 -119
  27. package/test/npm-install-guard.js +0 -104
  28. package/test/npm-install-guard.test.js +0 -53
@@ -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
- runLayerInstall(path.join(LAYER_OUTPUT_PATH, 'nodejs'), { env });
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.686.821f8a3.0",
4
+ "version": "2.0.0--canary.705.9cfd819.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.686.821f8a3.0",
30
- "@friggframework/schemas": "2.0.0--canary.686.821f8a3.0",
31
- "@friggframework/test": "2.0.0--canary.686.821f8a3.0",
29
+ "@friggframework/core": "2.0.0--canary.705.9cfd819.0",
30
+ "@friggframework/schemas": "2.0.0--canary.705.9cfd819.0",
31
+ "@friggframework/test": "2.0.0--canary.705.9cfd819.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.686.821f8a3.0",
60
- "@friggframework/prettier-config": "2.0.0--canary.686.821f8a3.0",
59
+ "@friggframework/eslint-config": "2.0.0--canary.705.9cfd819.0",
60
+ "@friggframework/prettier-config": "2.0.0--canary.705.9cfd819.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": "821f8a3973804b1b2ddd671dfdd49b726960731e"
92
+ "gitHead": "9cfd819cc94f0c7dc1fd2710775cfb93aba3a424"
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
- });