@friggframework/devtools 2.0.0--canary.686.00d79d8.0 → 2.0.0--canary.688.e850868.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/shared/types/app-definition.js +1 -15
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -26
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -61
- 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
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build for a non-AWS provider (friggframework/frigg#545, 302ab9ba /
|
|
3
|
-
* c8705715).
|
|
4
|
-
*
|
|
5
|
-
* Instead of the serverless/CloudFormation pipeline, the provider plugin
|
|
6
|
-
* (resolved from appDefinition.provider) does the build:
|
|
7
|
-
* 1. validate(appDefinition) - errors abort, warnings print
|
|
8
|
-
* 2. generateConfig(appDefinition) - e.g. netlify.toml
|
|
9
|
-
* 3. getFunctionEntryPoints(appDefinition) - written to <project>/netlify/functions
|
|
10
|
-
* 4. getLibEntryPoints(appDefinition) - written to <project>/netlify/lib
|
|
11
|
-
*
|
|
12
|
-
* <project> is the directory that holds backend/: the generated entry points
|
|
13
|
-
* require '../../backend/...', so they must sit beside it. #545 had two
|
|
14
|
-
* copies of this, and the CLI one wrote into the backend directory itself,
|
|
15
|
-
* where those relative requires do not resolve.
|
|
16
|
-
*
|
|
17
|
-
* Shared by createFriggInfrastructure() (`node infrastructure.js package`,
|
|
18
|
-
* what a backend's `npm run build` runs) and `frigg build`.
|
|
19
|
-
*/
|
|
20
|
-
const path = require('path');
|
|
21
|
-
const fs = require('fs');
|
|
22
|
-
|
|
23
|
-
const CONFIG_FILE_NAMES = { netlify: 'netlify.toml' };
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {Object} params
|
|
27
|
-
* @param {Object} params.appDefinition
|
|
28
|
-
* @param {string} params.backendDir - directory containing the backend's index.js
|
|
29
|
-
* @param {Object} [params.provider] - resolved plugin; defaults to resolveProvider(appDefinition)
|
|
30
|
-
* @param {boolean} [params.verbose]
|
|
31
|
-
* @param {Function} [params.exit] - called with 1 on validation errors (default process.exit)
|
|
32
|
-
* @returns {{ projectDir: string, written: string[] }}
|
|
33
|
-
*/
|
|
34
|
-
function buildWithProvider({
|
|
35
|
-
appDefinition,
|
|
36
|
-
backendDir,
|
|
37
|
-
provider,
|
|
38
|
-
verbose = false,
|
|
39
|
-
exit = (code) => process.exit(code),
|
|
40
|
-
}) {
|
|
41
|
-
const providerName = appDefinition.provider;
|
|
42
|
-
const plugin =
|
|
43
|
-
provider ||
|
|
44
|
-
require('@friggframework/core/providers/resolve-provider').resolveProvider(
|
|
45
|
-
appDefinition
|
|
46
|
-
);
|
|
47
|
-
const projectDir = path.dirname(path.resolve(backendDir));
|
|
48
|
-
const written = [];
|
|
49
|
-
|
|
50
|
-
console.log(`Building for ${providerName} provider (skipping AWS infrastructure)...`);
|
|
51
|
-
|
|
52
|
-
if (typeof plugin.validate === 'function') {
|
|
53
|
-
const validation = plugin.validate(appDefinition);
|
|
54
|
-
if (validation.errors?.length > 0) {
|
|
55
|
-
console.error(`\nValidation errors for ${providerName}:`);
|
|
56
|
-
for (const error of validation.errors) {
|
|
57
|
-
console.error(` - ${error}`);
|
|
58
|
-
}
|
|
59
|
-
exit(1);
|
|
60
|
-
return { projectDir, written };
|
|
61
|
-
}
|
|
62
|
-
for (const warning of validation.warnings || []) {
|
|
63
|
-
console.warn(` Warning: ${warning}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const write = (filePath, content) => {
|
|
68
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
69
|
-
fs.writeFileSync(filePath, content, 'utf-8');
|
|
70
|
-
written.push(filePath);
|
|
71
|
-
if (verbose) console.log(` Written ${path.relative(projectDir, filePath)}`);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
if (typeof plugin.generateConfig === 'function') {
|
|
75
|
-
const fileName = CONFIG_FILE_NAMES[providerName] || `${providerName}.config`;
|
|
76
|
-
write(path.join(projectDir, fileName), plugin.generateConfig(appDefinition));
|
|
77
|
-
console.log(` Written ${fileName}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (typeof plugin.getFunctionEntryPoints === 'function') {
|
|
81
|
-
const entryPoints = plugin.getFunctionEntryPoints(appDefinition);
|
|
82
|
-
for (const [fileName, content] of Object.entries(entryPoints)) {
|
|
83
|
-
write(path.join(projectDir, 'netlify', 'functions', fileName), content);
|
|
84
|
-
}
|
|
85
|
-
console.log(` Generated ${Object.keys(entryPoints).length} function entry points`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof plugin.getLibEntryPoints === 'function') {
|
|
89
|
-
const libEntryPoints = plugin.getLibEntryPoints(appDefinition);
|
|
90
|
-
for (const [fileName, content] of Object.entries(libEntryPoints)) {
|
|
91
|
-
write(path.join(projectDir, 'netlify', 'lib', fileName), content);
|
|
92
|
-
}
|
|
93
|
-
console.log(` Generated ${Object.keys(libEntryPoints).length} lib entry points`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (typeof plugin.generateEnvTemplate === 'function') {
|
|
97
|
-
const missing = Object.entries(plugin.generateEnvTemplate(appDefinition)).filter(
|
|
98
|
-
([key]) => !process.env[key]
|
|
99
|
-
);
|
|
100
|
-
if (missing.length > 0) {
|
|
101
|
-
console.log('\n Environment variables not set locally (configure them on the platform):');
|
|
102
|
-
for (const [key] of missing) console.log(` - ${key}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
console.log(`\nBuild complete for ${providerName}.`);
|
|
107
|
-
return { projectDir, written };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* True when the app definition names a provider other than AWS.
|
|
112
|
-
* @param {Object} [appDefinition]
|
|
113
|
-
*/
|
|
114
|
-
function isNonAwsProvider(appDefinition) {
|
|
115
|
-
const name = appDefinition?.provider;
|
|
116
|
-
return Boolean(name) && name !== 'aws';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = { buildWithProvider, isNonAwsProvider };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Jest setup: no test may run a package-manager command that rewrites a
|
|
3
|
-
* node_modules tree outside the OS temp directory.
|
|
4
|
-
*
|
|
5
|
-
* Why: two infrastructure tests composed a serverless definition in parallel,
|
|
6
|
-
* each building the real Prisma layer under packages/devtools/layers/prisma.
|
|
7
|
-
* One cleaned the layer while the other's `npm install --omit=dev` was
|
|
8
|
-
* starting, npm found no package.json in its cwd, walked up into the
|
|
9
|
-
* monorepo workspace and pruned the devDependencies (jest, jest-util) out of
|
|
10
|
-
* the repository's root node_modules. Every later workspace then failed with
|
|
11
|
-
* `jest: not found`.
|
|
12
|
-
*
|
|
13
|
-
* The guard wraps the real child_process functions. A test that mocks
|
|
14
|
-
* child_process (jest.mock) gets its mock and is unaffected; anything that
|
|
15
|
-
* reaches the real module with, for example, `npm install` in a repository
|
|
16
|
-
* directory throws instead of running.
|
|
17
|
-
*/
|
|
18
|
-
const childProcess = require('child_process');
|
|
19
|
-
const fs = require('fs');
|
|
20
|
-
const os = require('os');
|
|
21
|
-
const path = require('path');
|
|
22
|
-
|
|
23
|
-
const PACKAGE_MANAGERS = new Set(['npm', 'npx', 'yarn', 'pnpm']);
|
|
24
|
-
const MUTATING = new Set([
|
|
25
|
-
'install', 'i', 'in', 'ci', 'add', 'prune', 'uninstall', 'remove', 'rm', 'r', 'un',
|
|
26
|
-
'update', 'up', 'upgrade', 'dedupe', 'link', 'rebuild',
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
function realpathOrSelf(p) {
|
|
30
|
-
try {
|
|
31
|
-
return fs.realpathSync(p);
|
|
32
|
-
} catch {
|
|
33
|
-
return path.resolve(p);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const TMP = realpathOrSelf(os.tmpdir());
|
|
38
|
-
// The monorepo root (packages/devtools/test -> ../../..). A checkout can
|
|
39
|
-
// itself live under the temp directory, so "under tmp" alone is not enough.
|
|
40
|
-
const REPO_ROOT = realpathOrSelf(path.resolve(__dirname, '..', '..', '..'));
|
|
41
|
-
|
|
42
|
-
const within = (dir, root) => dir === root || dir.startsWith(root + path.sep);
|
|
43
|
-
|
|
44
|
-
/** True only for a scratch directory: under tmp and outside this repository. */
|
|
45
|
-
function insideTmp(dir) {
|
|
46
|
-
const real = realpathOrSelf(dir);
|
|
47
|
-
return within(real, TMP) && !within(real, REPO_ROOT);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @returns {string|null} the offending command, or null when allowed */
|
|
51
|
-
function offending(tokens, cwd) {
|
|
52
|
-
const [bin, ...args] = tokens;
|
|
53
|
-
if (!bin || !PACKAGE_MANAGERS.has(path.basename(String(bin)))) return null;
|
|
54
|
-
const sub = args.find((a) => !String(a).startsWith('-'));
|
|
55
|
-
// npx <pkg> runs a package; only installs/prunes rewrite node_modules.
|
|
56
|
-
if (path.basename(String(bin)) === 'npx' || !MUTATING.has(sub)) return null;
|
|
57
|
-
const prefixAt = args.indexOf('--prefix');
|
|
58
|
-
const target = prefixAt >= 0 ? args[prefixAt + 1] : cwd;
|
|
59
|
-
if (insideTmp(target || process.cwd())) return null;
|
|
60
|
-
return tokens.join(' ');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const GUARDED = Symbol.for('frigg.devtools.npmInstallGuard');
|
|
64
|
-
|
|
65
|
-
function guard(name, fn, toTokens) {
|
|
66
|
-
// setupFiles runs once per test file in a shared worker: wrap once.
|
|
67
|
-
if (fn[GUARDED]) return fn;
|
|
68
|
-
const guarded = function guarded(...callArgs) {
|
|
69
|
-
const { tokens, cwd } = toTokens(callArgs);
|
|
70
|
-
const bad = offending(tokens, cwd);
|
|
71
|
-
if (bad) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`Test tried to run "${bad}" outside the temp directory (cwd ${cwd || process.cwd()}); ` +
|
|
74
|
-
'it would rewrite a real node_modules. Mock it or run it in a temp dir.'
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
return fn.apply(this, callArgs);
|
|
78
|
-
};
|
|
79
|
-
guarded[GUARDED] = true;
|
|
80
|
-
return guarded;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const fromString = ([command, options]) => ({
|
|
84
|
-
tokens: String(command).trim().split(/\s+/),
|
|
85
|
-
cwd: options?.cwd,
|
|
86
|
-
});
|
|
87
|
-
const fromFile = ([file, args, options]) =>
|
|
88
|
-
Array.isArray(args)
|
|
89
|
-
? { tokens: [file, ...args], cwd: options?.cwd }
|
|
90
|
-
: { tokens: [file], cwd: args?.cwd };
|
|
91
|
-
|
|
92
|
-
for (const name of ['execSync', 'exec']) {
|
|
93
|
-
childProcess[name] = guard(name, childProcess[name], fromString);
|
|
94
|
-
}
|
|
95
|
-
for (const name of ['execFileSync', 'execFile', 'spawn', 'spawnSync']) {
|
|
96
|
-
const original = childProcess[name];
|
|
97
|
-
childProcess[name] = guard(name, original, (callArgs) => {
|
|
98
|
-
const opts = Array.isArray(callArgs[1]) ? callArgs[2] : callArgs[1];
|
|
99
|
-
if (opts?.shell && !Array.isArray(callArgs[1])) return fromString([callArgs[0], opts]);
|
|
100
|
-
return fromFile(callArgs);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = { offending, insideTmp };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const childProcess = require('child_process');
|
|
4
|
-
// Read before this file loads the guard itself: jest's setupFiles must have
|
|
5
|
-
// installed it already, for every test file.
|
|
6
|
-
const guardedBySetup = Boolean(childProcess.execSync[Symbol.for('frigg.devtools.npmInstallGuard')]);
|
|
7
|
-
const { offending } = require('./npm-install-guard');
|
|
8
|
-
|
|
9
|
-
const repoDir = path.resolve(__dirname, '..');
|
|
10
|
-
|
|
11
|
-
describe('npm install guard (jest setupFiles)', () => {
|
|
12
|
-
// Every command here is a --dry-run, so even a broken guard that let it
|
|
13
|
-
// through could not rewrite this repository's node_modules.
|
|
14
|
-
it('is installed by jest setupFiles, before any test code runs', () => {
|
|
15
|
-
expect(guardedBySetup).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('blocks installs and prunes on the real child_process', () => {
|
|
19
|
-
expect(() =>
|
|
20
|
-
childProcess.execSync('npm install --dry-run --omit=dev', { cwd: repoDir, stdio: 'ignore' })
|
|
21
|
-
).toThrow(/outside the temp directory/);
|
|
22
|
-
expect(() =>
|
|
23
|
-
childProcess.spawnSync('npm', ['prune', '--dry-run'], { cwd: repoDir, stdio: 'ignore' })
|
|
24
|
-
).toThrow(/outside the temp directory/);
|
|
25
|
-
expect(() =>
|
|
26
|
-
childProcess.execFileSync('/usr/bin/npm', ['ci', '--dry-run'], { cwd: repoDir, stdio: 'ignore' })
|
|
27
|
-
).toThrow(/outside the temp directory/);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('treats a temp dir inside this repository as part of the repository', () => {
|
|
31
|
-
// A checkout may itself live under os.tmpdir() (as in some sandboxes).
|
|
32
|
-
expect(offending(['npm', 'install'], path.join(repoDir, 'layers/prisma/nodejs'))).not.toBeNull();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it.each([
|
|
36
|
-
[['npm', 'install', '--omit=dev'], repoDir, true],
|
|
37
|
-
[['npm', 'ci'], repoDir, true],
|
|
38
|
-
[['yarn', 'add', 'x'], repoDir, true],
|
|
39
|
-
[['npm', 'install', '--prefix', repoDir], os.tmpdir(), true],
|
|
40
|
-
[['npm', 'install'], os.tmpdir(), false],
|
|
41
|
-
[['npm', 'install', '--prefix', path.join(os.tmpdir(), 'layer')], repoDir, false],
|
|
42
|
-
[['npm', 'root'], repoDir, false],
|
|
43
|
-
[['npm', 'run', 'build'], repoDir, false],
|
|
44
|
-
[['npx', 'netlify-cli', 'deploy'], repoDir, false],
|
|
45
|
-
[['git', 'install'], repoDir, false],
|
|
46
|
-
])('%j in %s -> blocked %s', (tokens, cwd, blocked) => {
|
|
47
|
-
expect(offending(tokens, cwd) !== null).toBe(blocked);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('lets harmless commands through', () => {
|
|
51
|
-
expect(childProcess.execSync('node -e "process.stdout.write(\'ok\')"', { encoding: 'utf8' })).toBe('ok');
|
|
52
|
-
});
|
|
53
|
-
});
|