@friggframework/devtools 2.0.0--canary.704.79d9a63.0 → 2.0.0--canary.686.e94de4d.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/README.md +0 -14
- package/frigg-cli/README.md +0 -6
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +140 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +5 -3
- package/frigg-cli/build-command/index.js +32 -1
- package/frigg-cli/deploy-command/index.js +50 -2
- package/frigg-cli/doctor-command/index.js +7 -0
- package/frigg-cli/generate-iam-command.js +7 -0
- package/frigg-cli/index.js +0 -3
- package/frigg-cli/package.json +3 -3
- package/frigg-cli/repair-command/index.js +7 -0
- package/frigg-cli/start-command/index.js +58 -0
- package/frigg-cli/utils/provider-helper.js +80 -0
- package/infrastructure/README.md +4 -22
- package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +64 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
- package/infrastructure/__tests__/template-generation.test.js +7 -0
- package/infrastructure/create-frigg-infrastructure.js +14 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +48 -56
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +7 -76
- package/infrastructure/domains/database/migration-builder.js +175 -182
- package/infrastructure/domains/database/migration-builder.test.js +5 -36
- package/infrastructure/domains/integration/integration-builder.js +61 -65
- package/infrastructure/domains/integration/integration-builder.test.js +8 -73
- package/infrastructure/domains/parameters/offload-utils.js +1 -0
- package/infrastructure/domains/shared/environment-builder.js +12 -1
- package/infrastructure/domains/shared/environment-builder.test.js +20 -0
- package/infrastructure/domains/shared/types/app-definition.js +15 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +150 -86
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +111 -96
- package/infrastructure/domains/shared/utilities/logging-config.js +4 -3
- package/infrastructure/domains/shared/utilities/logging-config.test.js +2 -1
- package/infrastructure/infrastructure-composer.test.js +10 -3
- package/infrastructure/provider-build.js +119 -0
- package/infrastructure/scripts/build-prisma-layer.js +32 -5
- package/infrastructure/scripts/build-prisma-layer.test.js +35 -0
- package/package.json +8 -11
- package/test/npm-install-guard.js +104 -0
- package/test/npm-install-guard.test.js +53 -0
- package/frigg-cli/__tests__/unit/utils/node-version.test.js +0 -66
- package/frigg-cli/utils/node-version.js +0 -51
- package/infrastructure/__tests__/package-patterns-composition.test.js +0 -153
- package/infrastructure/domains/shared/utilities/framework-version.js +0 -14
- package/infrastructure/domains/shared/utilities/framework-version.test.js +0 -27
- package/infrastructure/domains/shared/utilities/package-patterns.js +0 -35
- package/infrastructure/domains/shared/utilities/package-patterns.test.js +0 -112
|
@@ -0,0 +1,104 @@
|
|
|
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 };
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
SUPPORTED_NODE_RANGE,
|
|
3
|
-
checkNodeVersion,
|
|
4
|
-
enforceNodeVersion,
|
|
5
|
-
} = require('../../../utils/node-version');
|
|
6
|
-
|
|
7
|
-
describe('Node.js host version check (ADR-050)', () => {
|
|
8
|
-
it('uses the engines.node range from package.json', () => {
|
|
9
|
-
expect(SUPPORTED_NODE_RANGE).toBe(require('../../../package.json').engines.node);
|
|
10
|
-
expect(SUPPORTED_NODE_RANGE).toBe('^22.13.0 || >=24');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it.each([
|
|
14
|
-
['22.13.0', true],
|
|
15
|
-
['v22.20.1', true],
|
|
16
|
-
['24.0.0', true],
|
|
17
|
-
['v24.10.0', true],
|
|
18
|
-
['25.1.0', true],
|
|
19
|
-
['22.12.0', false],
|
|
20
|
-
['v22.11.0', false],
|
|
21
|
-
['23.5.0', false],
|
|
22
|
-
['v23.11.1', false],
|
|
23
|
-
['20.19.0', false],
|
|
24
|
-
['18.20.0', false],
|
|
25
|
-
])('Node %s supported: %s', (version, supported) => {
|
|
26
|
-
expect(checkNodeVersion(version).supported).toBe(supported);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('explains the supported range and the fix when unsupported', () => {
|
|
30
|
-
const { message } = checkNodeVersion('v23.5.0');
|
|
31
|
-
expect(message).toContain('Node.js v23.5.0');
|
|
32
|
-
expect(message).toContain('^22.13.0 || >=24');
|
|
33
|
-
expect(message).toContain('Node 23');
|
|
34
|
-
expect(message).toContain('FRIGG_SKIP_NODE_VERSION_CHECK');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('prints the message and exits 1 on an unsupported host', () => {
|
|
38
|
-
const log = jest.fn();
|
|
39
|
-
const exit = jest.fn();
|
|
40
|
-
const ok = enforceNodeVersion({ version: '23.5.0', env: {}, log, exit });
|
|
41
|
-
expect(ok).toBe(false);
|
|
42
|
-
expect(log).toHaveBeenCalledWith(expect.stringContaining('does not support Node.js'));
|
|
43
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('continues silently on a supported host', () => {
|
|
47
|
-
const log = jest.fn();
|
|
48
|
-
const exit = jest.fn();
|
|
49
|
-
expect(enforceNodeVersion({ version: '24.10.0', env: {}, log, exit })).toBe(true);
|
|
50
|
-
expect(log).not.toHaveBeenCalled();
|
|
51
|
-
expect(exit).not.toHaveBeenCalled();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('can be bypassed with FRIGG_SKIP_NODE_VERSION_CHECK=true', () => {
|
|
55
|
-
const exit = jest.fn();
|
|
56
|
-
expect(
|
|
57
|
-
enforceNodeVersion({
|
|
58
|
-
version: '23.5.0',
|
|
59
|
-
env: { FRIGG_SKIP_NODE_VERSION_CHECK: 'true' },
|
|
60
|
-
log: jest.fn(),
|
|
61
|
-
exit,
|
|
62
|
-
})
|
|
63
|
-
).toBe(true);
|
|
64
|
-
expect(exit).not.toHaveBeenCalled();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js host version check for the Frigg CLI.
|
|
3
|
-
*
|
|
4
|
-
* osls 4 supports `^20.19.0 || ^22.13.0 || >=24`; Frigg's floor is Node 22, so
|
|
5
|
-
* the CLI runs on `^22.13.0 || >=24` (ADR-050). Node 23 and Node 22.0-22.12 are
|
|
6
|
-
* excluded. The range is read from this package's `engines.node`, so the check
|
|
7
|
-
* and the published metadata cannot drift.
|
|
8
|
-
*/
|
|
9
|
-
const semver = require('semver');
|
|
10
|
-
const { engines } = require('../package.json');
|
|
11
|
-
|
|
12
|
-
const SUPPORTED_NODE_RANGE = engines.node;
|
|
13
|
-
const SKIP_ENV = 'FRIGG_SKIP_NODE_VERSION_CHECK';
|
|
14
|
-
|
|
15
|
-
function checkNodeVersion(version = process.versions.node, range = SUPPORTED_NODE_RANGE) {
|
|
16
|
-
const coerced = semver.coerce(version);
|
|
17
|
-
if (coerced && semver.satisfies(coerced, range)) {
|
|
18
|
-
return { supported: true, version, range };
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
supported: false,
|
|
22
|
-
version,
|
|
23
|
-
range,
|
|
24
|
-
message: [
|
|
25
|
-
`Frigg CLI does not support Node.js v${String(version).replace(/^v/, '')}.`,
|
|
26
|
-
`Supported versions: ${range} (the range osls 4 supports at or above Frigg's Node 22 floor).`,
|
|
27
|
-
'Node 23 and Node 22.0-22.12 are not supported. Install Node 22.13+ or Node 24+, for example `nvm install 24`.',
|
|
28
|
-
`To run anyway, set ${SKIP_ENV}=true (osls may fail).`,
|
|
29
|
-
].join('\n'),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Print a clear error and exit when the host Node.js is unsupported.
|
|
35
|
-
* @returns {boolean} true when the CLI may continue
|
|
36
|
-
*/
|
|
37
|
-
function enforceNodeVersion({
|
|
38
|
-
version = process.versions.node,
|
|
39
|
-
env = process.env,
|
|
40
|
-
log = console.error,
|
|
41
|
-
exit = process.exit,
|
|
42
|
-
} = {}) {
|
|
43
|
-
if (env[SKIP_ENV] === 'true') return true;
|
|
44
|
-
const result = checkNodeVersion(version);
|
|
45
|
-
if (result.supported) return true;
|
|
46
|
-
log(result.message);
|
|
47
|
-
exit(1);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = { SUPPORTED_NODE_RANGE, checkNodeVersion, enforceNodeVersion };
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Composer-level guard for ADR-050 (osls 4).
|
|
3
|
-
*
|
|
4
|
-
* osls 4 rejects package.include / package.exclude at every level and only
|
|
5
|
-
* accepts `useDotenv: true` (or no key). Walk every function of a fully
|
|
6
|
-
* featured composed definition and assert Frigg emits neither.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
10
|
-
|
|
11
|
-
jest.mock('../domains/shared/resource-discovery', () => {
|
|
12
|
-
const originalModule = jest.requireActual('../domains/shared/resource-discovery');
|
|
13
|
-
return {
|
|
14
|
-
...originalModule,
|
|
15
|
-
gatherDiscoveredResources: jest.fn().mockResolvedValue({
|
|
16
|
-
defaultVpcId: 'vpc-123456',
|
|
17
|
-
defaultSecurityGroupId: 'sg-123456',
|
|
18
|
-
privateSubnetId1: 'subnet-123456',
|
|
19
|
-
privateSubnetId2: 'subnet-789012',
|
|
20
|
-
defaultKmsKeyId:
|
|
21
|
-
'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
|
|
22
|
-
auroraClusterEndpoint: 'test-cluster.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
23
|
-
auroraPort: 5432,
|
|
24
|
-
}),
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const featuredApp = () => ({
|
|
29
|
-
name: 'featured-app',
|
|
30
|
-
provider: 'aws',
|
|
31
|
-
vpc: { enable: true },
|
|
32
|
-
encryption: { useDefaultKMSForFieldLevelEncryption: true },
|
|
33
|
-
database: {
|
|
34
|
-
postgres: { enable: true },
|
|
35
|
-
documentDB: { tlsCAFile: './global-bundle.pem' },
|
|
36
|
-
},
|
|
37
|
-
adminScripts: [{ Definition: { name: 'fixThings' } }],
|
|
38
|
-
reports: [{ Definition: { name: 'usageReport' } }],
|
|
39
|
-
integrations: [
|
|
40
|
-
{
|
|
41
|
-
Definition: {
|
|
42
|
-
name: 'hubspot',
|
|
43
|
-
webhooks: true,
|
|
44
|
-
extensions: {
|
|
45
|
-
hubspotWebhooks: {
|
|
46
|
-
extension: {
|
|
47
|
-
name: 'hubspot-webhooks',
|
|
48
|
-
routes: [
|
|
49
|
-
{
|
|
50
|
-
path: '/webhooks',
|
|
51
|
-
method: 'POST',
|
|
52
|
-
event: 'HUBSPOT_WEBHOOK_RECEIVED',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
events: {
|
|
56
|
-
HUBSPOT_WEBHOOK_RECEIVED: {
|
|
57
|
-
type: 'LIFE_CYCLE_EVENT',
|
|
58
|
-
handler: () => {},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
handlers: {},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
{ Definition: { name: 'slack' } },
|
|
68
|
-
],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('composed definition is valid for osls 4 packaging (ADR-050)', () => {
|
|
72
|
-
const originalArgv = process.argv;
|
|
73
|
-
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
process.argv = originalArgv;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('no function, the service or a layer carries package.include or package.exclude', async () => {
|
|
83
|
-
process.argv = ['node', 'osls', 'package', '--stage', 'prod'];
|
|
84
|
-
const definition = await composeServerlessDefinition(featuredApp());
|
|
85
|
-
|
|
86
|
-
expect(definition.package).not.toHaveProperty('include');
|
|
87
|
-
expect(definition.package).not.toHaveProperty('exclude');
|
|
88
|
-
for (const layer of Object.values(definition.layers || {})) {
|
|
89
|
-
expect(layer.package?.include).toBeUndefined();
|
|
90
|
-
expect(layer.package?.exclude).toBeUndefined();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const functionNames = Object.keys(definition.functions);
|
|
94
|
-
expect(functionNames).toEqual(
|
|
95
|
-
expect.arrayContaining([
|
|
96
|
-
'auth',
|
|
97
|
-
'user',
|
|
98
|
-
'health',
|
|
99
|
-
'hubspot',
|
|
100
|
-
'hubspotWebhook',
|
|
101
|
-
'hubspot__hubspotWebhooks',
|
|
102
|
-
'hubspotQueueWorker',
|
|
103
|
-
'slack',
|
|
104
|
-
'slackQueueWorker',
|
|
105
|
-
'dlqProcessor',
|
|
106
|
-
'dbMigrationWorker',
|
|
107
|
-
'dbMigrationRouter',
|
|
108
|
-
'adminScriptExecutor',
|
|
109
|
-
'adminScriptRouter',
|
|
110
|
-
])
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
for (const [name, fn] of Object.entries(definition.functions)) {
|
|
114
|
-
if (!fn.package) continue;
|
|
115
|
-
expect({ name, include: fn.package.include }).toEqual({ name, include: undefined });
|
|
116
|
-
expect({ name, exclude: fn.package.exclude }).toEqual({ name, exclude: undefined });
|
|
117
|
-
expect(Array.isArray(fn.package.patterns)).toBe(true);
|
|
118
|
-
|
|
119
|
-
// Excludes first, then includes: once a positive pattern appears,
|
|
120
|
-
// no negated pattern may follow it.
|
|
121
|
-
const firstInclude = fn.package.patterns.findIndex((p) => !p.startsWith('!'));
|
|
122
|
-
if (firstInclude !== -1) {
|
|
123
|
-
expect(
|
|
124
|
-
fn.package.patterns.slice(firstInclude).every((p) => !p.startsWith('!'))
|
|
125
|
-
).toBe(true);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// The skipEsbuild core and admin functions re-add the DocumentDB CA file.
|
|
130
|
-
for (const name of ['auth', 'user', 'health', 'adminScriptExecutor', 'adminScriptRouter']) {
|
|
131
|
-
const { patterns } = definition.functions[name].package;
|
|
132
|
-
expect(patterns[patterns.length - 1]).toBe('global-bundle.pem');
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it.each([['package'], ['deploy']])('never emits useDotenv for `osls %s`', async (command) => {
|
|
137
|
-
process.argv = ['node', 'osls', command, '--stage', 'prod'];
|
|
138
|
-
const definition = await composeServerlessDefinition(featuredApp());
|
|
139
|
-
|
|
140
|
-
expect(definition).not.toHaveProperty('useDotenv');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('emits useDotenv: true for `osls offline`', async () => {
|
|
144
|
-
process.argv = ['node', 'osls', 'offline', '--stage', 'dev'];
|
|
145
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
146
|
-
try {
|
|
147
|
-
const definition = await composeServerlessDefinition(featuredApp());
|
|
148
|
-
expect(definition.useDotenv).toBe(true);
|
|
149
|
-
} finally {
|
|
150
|
-
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* osls framework version
|
|
3
|
-
*
|
|
4
|
-
* Utility Layer - Hexagonal Architecture
|
|
5
|
-
*
|
|
6
|
-
* The single `frameworkVersion` every composed definition emits (ADR-050).
|
|
7
|
-
* It matches the osls range in devtools and frigg-cli, so an app whose own
|
|
8
|
-
* package.json still resolves osls 3 fails at once with
|
|
9
|
-
* FRAMEWORK_VERSION_MISMATCH instead of packaging a different artifact.
|
|
10
|
-
* It subsumes the ADR-048 LoggingConfig floor (>=3.58.0).
|
|
11
|
-
*/
|
|
12
|
-
const OSLS_FRAMEWORK_VERSION = '^4.4.0';
|
|
13
|
-
|
|
14
|
-
module.exports = { OSLS_FRAMEWORK_VERSION };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const { OSLS_FRAMEWORK_VERSION } = require('./framework-version');
|
|
2
|
-
const semver = require('semver');
|
|
3
|
-
|
|
4
|
-
describe('OSLS_FRAMEWORK_VERSION (ADR-050)', () => {
|
|
5
|
-
it('is the osls 4 range Frigg targets', () => {
|
|
6
|
-
expect(OSLS_FRAMEWORK_VERSION).toBe('^4.4.0');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it.each([
|
|
10
|
-
['4.4.0', true],
|
|
11
|
-
['4.9.1', true],
|
|
12
|
-
['4.3.9', false],
|
|
13
|
-
['3.78.0', false],
|
|
14
|
-
['5.0.0', false],
|
|
15
|
-
])('osls %s satisfies it: %s', (version, expected) => {
|
|
16
|
-
// osls compares frameworkVersion with semver.satisfies and fails
|
|
17
|
-
// with FRAMEWORK_VERSION_MISMATCH otherwise.
|
|
18
|
-
expect(semver.satisfies(version, OSLS_FRAMEWORK_VERSION)).toBe(expected);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('matches the osls range devtools and frigg-cli depend on', () => {
|
|
22
|
-
const devtools = require('../../../../package.json');
|
|
23
|
-
const cli = require('../../../../frigg-cli/package.json');
|
|
24
|
-
expect(devtools.devDependencies.osls).toBe(OSLS_FRAMEWORK_VERSION);
|
|
25
|
-
expect(cli.dependencies.osls).toBe(OSLS_FRAMEWORK_VERSION);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Function package patterns
|
|
3
|
-
*
|
|
4
|
-
* Utility Layer - Hexagonal Architecture
|
|
5
|
-
*
|
|
6
|
-
* osls 4 rejects `package.include` / `package.exclude` and only reads
|
|
7
|
-
* `package.patterns` (ADR-050). Builders keep their include and exclude lists
|
|
8
|
-
* and pass them through this helper, so one place owns the negation.
|
|
9
|
-
*
|
|
10
|
-
* osls resolves a function's files with `resolveFilePathsFromPatterns`: an
|
|
11
|
-
* ordered list evaluated last-match-wins. On osls 3 a function `exclude` was
|
|
12
|
-
* placed (negated) ahead of the function `include`. Frigg emits no
|
|
13
|
-
* service-level include, exclude or patterns, so `[!exclude..., include...]`
|
|
14
|
-
* reproduces the osls 3 order exactly, and is valid on osls 3 and osls 4.
|
|
15
|
-
*
|
|
16
|
-
* An exclude that already starts with `!` was treated by osls 3 as an include
|
|
17
|
-
* in exclude position; it is emitted un-negated in the same position here.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {Object} [lists]
|
|
22
|
-
* @param {string[]} [lists.include] - Globs to (re-)add after the excludes
|
|
23
|
-
* @param {string[]} [lists.exclude] - Globs to remove
|
|
24
|
-
* @returns {string[]} Value for `package.patterns`
|
|
25
|
-
*/
|
|
26
|
-
function toPackagePatterns({ include = [], exclude = [] } = {}) {
|
|
27
|
-
return [
|
|
28
|
-
...exclude.map((pattern) =>
|
|
29
|
-
pattern.startsWith('!') ? pattern.slice(1) : `!${pattern}`
|
|
30
|
-
),
|
|
31
|
-
...include,
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = { toPackagePatterns };
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the function package patterns helper (ADR-050)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const { toPackagePatterns } = require('./package-patterns');
|
|
6
|
-
const { nestedNodeModulesExcludes } = require('./nested-node-modules');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The ordered list osls 3 built in resolveFilePathsFromPatterns for a function
|
|
10
|
-
* that set `package.include` / `package.exclude` (no service-level patterns,
|
|
11
|
-
* which Frigg never emits, and before the dev-dependency patterns that both
|
|
12
|
-
* versions append identically).
|
|
13
|
-
*/
|
|
14
|
-
function osls3FunctionOrder({ include = [], exclude = [] }) {
|
|
15
|
-
const patterns = [];
|
|
16
|
-
exclude.forEach((p) => patterns.push(p.charAt(0) !== '!' ? `!${p}` : p.substring(1)));
|
|
17
|
-
include.forEach((p) => patterns.push(p));
|
|
18
|
-
return patterns;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The ordered list osls 3 and osls 4 build for a function that sets
|
|
23
|
-
* `package.patterns`: the patterns go in include position, unchanged.
|
|
24
|
-
*/
|
|
25
|
-
function patternsFunctionOrder(patterns) {
|
|
26
|
-
return [...patterns];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe('toPackagePatterns', () => {
|
|
30
|
-
const cases = [
|
|
31
|
-
{
|
|
32
|
-
name: 'excludes first (negated), then includes',
|
|
33
|
-
lists: {
|
|
34
|
-
include: ['ca.pem'],
|
|
35
|
-
exclude: ['node_modules/aws-sdk/**', '.env'],
|
|
36
|
-
},
|
|
37
|
-
expected: ['!node_modules/aws-sdk/**', '!.env', 'ca.pem'],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'an exclude that already starts with ! becomes an include in exclude position',
|
|
41
|
-
lists: {
|
|
42
|
-
include: [],
|
|
43
|
-
exclude: ['node_modules/**', '!node_modules/keep/**'],
|
|
44
|
-
},
|
|
45
|
-
expected: ['!node_modules/**', 'node_modules/keep/**'],
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'an include re-adds a path that an exclude removed',
|
|
49
|
-
lists: {
|
|
50
|
-
include: ['config/ca.pem'],
|
|
51
|
-
exclude: ['config/**'],
|
|
52
|
-
},
|
|
53
|
-
expected: ['!config/**', 'config/ca.pem'],
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'empty lists',
|
|
57
|
-
lists: { include: [], exclude: [] },
|
|
58
|
-
expected: [],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: 'only excludes',
|
|
62
|
-
lists: { exclude: ['test/**'] },
|
|
63
|
-
expected: ['!test/**'],
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'only includes',
|
|
67
|
-
lists: { include: ['ca.pem'] },
|
|
68
|
-
expected: ['ca.pem'],
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
it.each(cases)('$name', ({ lists, expected }) => {
|
|
73
|
-
const patterns = toPackagePatterns(lists);
|
|
74
|
-
expect(patterns).toEqual(expected);
|
|
75
|
-
// Same evaluation order osls 3 applied to include/exclude.
|
|
76
|
-
expect(patternsFunctionOrder(patterns)).toEqual(osls3FunctionOrder(lists));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('returns an empty list when called with no arguments', () => {
|
|
80
|
-
expect(toPackagePatterns()).toEqual([]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('does not mutate its inputs', () => {
|
|
84
|
-
const exclude = ['a/**'];
|
|
85
|
-
const include = ['b'];
|
|
86
|
-
toPackagePatterns({ include, exclude });
|
|
87
|
-
expect(exclude).toEqual(['a/**']);
|
|
88
|
-
expect(include).toEqual(['b']);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('with nestedNodeModulesExcludes output', () => {
|
|
92
|
-
it('negates the single catch-all glob by default', () => {
|
|
93
|
-
const exclude = nestedNodeModulesExcludes({}, true);
|
|
94
|
-
expect(toPackagePatterns({ exclude })).toEqual([
|
|
95
|
-
'!node_modules/**/node_modules/**',
|
|
96
|
-
]);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('negates every scoped glob when keepNestedNodeModules is set', () => {
|
|
100
|
-
const appDefinition = { lambda: { keepNestedNodeModules: true } };
|
|
101
|
-
const exclude = nestedNodeModulesExcludes(appDefinition, true);
|
|
102
|
-
const patterns = toPackagePatterns({ exclude });
|
|
103
|
-
|
|
104
|
-
expect(patterns).toEqual(exclude.map((p) => `!${p}`));
|
|
105
|
-
expect(patterns).toContain('!node_modules/**/node_modules/@friggframework/**');
|
|
106
|
-
expect(patterns).not.toContain('!node_modules/**/node_modules/**');
|
|
107
|
-
expect(patternsFunctionOrder(patterns)).toEqual(
|
|
108
|
-
osls3FunctionOrder({ exclude })
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|