@enhance-eng/archangel 0.0.1 → 0.1.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.
@@ -0,0 +1,45 @@
1
+ // The Next.js preset: code that a client component reaches stays out of server-only code and
2
+ // Node's built-in modules.
3
+
4
+ const page = (text) => `'use client';\n${text}export default function Page() { return null; }\n`;
5
+
6
+ /**
7
+ * The Next.js preset. A file whose first statement is `'use client'`, and every file it reaches
8
+ * through runtime imports, may not import `server-only` or a Node built-in module; a chain stops
9
+ * at a file that starts with `'use server'`, whose import Next.js turns into a network call.
10
+ */
11
+ export const nextjs = ({ name = 'nextjs', root = '' } = {}) => ({
12
+ name,
13
+ package: '@enhance-eng/archangel',
14
+ root,
15
+ selectors: {
16
+ client: { directive: 'use client' },
17
+ server: { directive: 'use server' },
18
+ },
19
+ rules: [
20
+ {
21
+ name: 'client-stays-client',
22
+ reason: 'Code that runs in the browser cannot use server-only code or Node built-in modules.',
23
+ link: 'https://nextjs.org/docs/app/getting-started/server-and-client-components',
24
+ files: 'client',
25
+ mayNotImport: { packages: ['server-only', 'node:*'] },
26
+ transitively: true,
27
+ stopAt: 'server',
28
+ imports: 'runtime',
29
+ examples: {
30
+ rejected: [
31
+ {
32
+ 'app/example-page.tsx': page("import { read } from './example-helper';\n"),
33
+ 'app/example-helper.ts': "import { readFile } from 'node:fs';\nexport const read = readFile;\n",
34
+ },
35
+ ],
36
+ accepted: [
37
+ {
38
+ 'app/example-page.tsx': page("import { save } from './example-actions';\n"),
39
+ 'app/example-actions.ts': "'use server';\nimport { readFile } from 'node:fs';\nexport async function save() { return readFile; }\n",
40
+ },
41
+ ],
42
+ },
43
+ },
44
+ ],
45
+ });