@friggframework/devtools 2.0.0--canary.707.df52379.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.
Files changed (26) hide show
  1. package/frigg-cli/build-command/index.js +1 -32
  2. package/frigg-cli/db-setup-command/index.js +0 -25
  3. package/frigg-cli/deploy-command/index.js +2 -50
  4. package/frigg-cli/doctor-command/index.js +0 -7
  5. package/frigg-cli/generate-iam-command.js +0 -7
  6. package/frigg-cli/repair-command/index.js +0 -7
  7. package/frigg-cli/start-command/index.js +0 -58
  8. package/infrastructure/__tests__/template-generation.test.js +0 -7
  9. package/infrastructure/create-frigg-infrastructure.js +0 -14
  10. package/infrastructure/domains/shared/types/app-definition.js +1 -15
  11. package/infrastructure/domains/shared/utilities/base-definition-factory.js +3 -5
  12. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -24
  13. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +0 -10
  14. package/infrastructure/infrastructure-composer.js +1 -13
  15. package/infrastructure/infrastructure-composer.test.js +0 -7
  16. package/infrastructure/scripts/build-prisma-layer.js +5 -32
  17. package/infrastructure/scripts/build-prisma-layer.test.js +0 -35
  18. package/package.json +7 -7
  19. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -140
  20. package/frigg-cli/utils/provider-helper.js +0 -80
  21. package/infrastructure/__tests__/compose-extension-prisma.test.js +0 -168
  22. package/infrastructure/__tests__/create-frigg-infrastructure-provider.test.js +0 -64
  23. package/infrastructure/compose-extension-prisma.js +0 -73
  24. package/infrastructure/provider-build.js +0 -126
  25. package/test/npm-install-guard.js +0 -104
  26. package/test/npm-install-guard.test.js +0 -53
@@ -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
- });