@akanjs/devkit 3.3.0-rc.11 → 3.3.0-rc.13
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/CHANGELOG.md +51 -0
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/akanConfig/akanConfig.ts +4 -4
- package/app/applicationBuildRunner.test.ts +272 -0
- package/app/applicationBuildRunner.ts +87 -2
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/codeAgent/skills/akan-err/SKILL.md +11 -2
- package/codeAgent/skills/akan-page/SKILL.md +4 -14
- package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +14 -0
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/clientEntryDiscovery.test.ts +35 -0
- package/frontendBuild/clientEntryDiscovery.ts +14 -1
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +3 -3
- package/test/secretEnvFixture.ts +134 -0
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +115 -2
- package/transforms/serverEnvProfile.ts +117 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/typecheck/projectTypecheck.test.ts +29 -0
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
|
@@ -33,19 +33,13 @@ export default page()
|
|
|
33
33
|
dropped. `lang` reaches every stage and is never declared.
|
|
34
34
|
3. Gate with `.guard(() => signedIn())` on the `_layout.tsx`, and repeat a stricter guard on a page that needs more.
|
|
35
35
|
`.guard((_, { path }) => signedIn({ path }))` sends a refused visitor to `/signin?redirect=<path>`.
|
|
36
|
-
4. In `.render()`: `usePage()`, then fetch, then return.
|
|
37
|
-
|
|
38
|
-
5. `.head()` takes JSX (or a function returning it), never a metadata object.
|
|
39
|
-
6. Re-skin an `akanjs/ui` component for a subtree with `_overrides.tsx`:
|
|
36
|
+
4. In `.render()`: `usePage()`, then fetch, then return.
|
|
37
|
+
5. Re-skin an `akanjs/ui` component for a subtree with `_overrides.tsx`:
|
|
40
38
|
`export default override({ Slot: AppComponent })`, no logic. Nested ones merge slot by slot, the closest winning;
|
|
41
39
|
`componentRule` lists the slots.
|
|
42
40
|
|
|
43
41
|
## API at a glance
|
|
44
42
|
|
|
45
|
-
`page`, `layout` and `router` come from `akanjs/client`, `Link` from `akanjs/ui`, `usePageLocation` from
|
|
46
|
-
`akanjs/webkit`, and `fetch`, `usePage` and the model namespaces from `@apps/<app>/client`. A stage receives the
|
|
47
|
-
declared params and search keys plus `lang`.
|
|
48
|
-
|
|
49
43
|
- Data-driven title: `.head(async ({ id }) => <title>{((await fetch.book(id)) as Book | null)?.title}</title>)`,
|
|
50
44
|
where `Book` is the `common/` interface for the query's `Any` return (`akan-service`).
|
|
51
45
|
- Async page: `.render(async ({ id }) => { const book = (await fetch.book(id)) as Book | null; if (!book) return router.notFound(); … })`;
|
|
@@ -65,12 +59,8 @@ declared params and search keys plus `lang`.
|
|
|
65
59
|
scrollToTop: false })`` in a `"use client"` component, read back with `usePageLocation().searchParams`. Shallow
|
|
66
60
|
holds only while the path stays the same; a server `.search()` sees the value at the next full navigation.
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- A `fetch.<mutation>()` while rendering — it throws `base.error.mutationInRender`, because opening a link would
|
|
71
|
-
perform it. Send writes from a user action.
|
|
72
|
-
- `useState`, `useEffect`, comments, a named export beside the chain, or the legacy `export default async function`.
|
|
73
|
-
- Editing a lib page through its link in `page/(libs)/` — edit the lib's own `page/` source.
|
|
62
|
+
What a route file must never do — write while rendering, hooks, a second export — is the `page` rule, loaded with
|
|
63
|
+
any `page/` file.
|
|
74
64
|
|
|
75
65
|
Full detail: `get_guideline` with `pageRule` (guards in depth, heads, MCP apps, CSR root layouts, lib pages), or
|
|
76
66
|
`ssrRule` for what may render on the server. Every stage's signature, the router's methods, Link's props and every
|
|
@@ -18,6 +18,7 @@ the agent guide's Path Rules table.
|
|
|
18
18
|
| The production image | `docker: string \| { image, preRuns, postRuns, command }` |
|
|
19
19
|
| iOS, Android, desktop | the `native` section; `desktop: { server: true }` carries the server |
|
|
20
20
|
| SQLite, several databases, a cluster | `database: { modes: [...] }` (`single`, `multiple`, `cluster`), picked by `AKAN_DATABASE_MODE` |
|
|
21
|
+
| A secret of `env/env.server.<env>.ts` in a deployed server | nothing to declare: `akan build` leaves it out and the server reads it from a variable named after its key path; `akan secret-env <app> --env <env>` lists them |
|
|
21
22
|
| URLs without `/<locale>/`: one language, or paths fixed from outside (OAuth callback, QR code, mail link) | `i18n: { localePrefix: "as-needed" }` — the default locale's pages and `<Link>` hrefs drop the prefix, other locales keep it |
|
|
22
23
|
|
|
23
24
|
## Running and logs
|
|
@@ -28,6 +29,25 @@ the agent guide's Path Rules table.
|
|
|
28
29
|
- Run a build without Docker with `cd dist/apps/<app> && bun main.js`: it boots with the env the Dockerfile sets,
|
|
29
30
|
read from `akan.env.json` beside it, and a variable you set yourself (`PORT=3000`) wins.
|
|
30
31
|
|
|
32
|
+
## Secrets in a deployed server
|
|
33
|
+
|
|
34
|
+
- Write secrets in `env/env.server.<env>.ts` as before. `akan build` replaces each string under a secret-named key,
|
|
35
|
+
and each URL carrying a password, with a read of an environment variable: `security.sso.google.clientSecret` is
|
|
36
|
+
`SECURITY__SSO__GOOGLE__CLIENT_SECRET`, an array holding a secret is one JSON variable, `security.jwtSecret` is
|
|
37
|
+
`JWT_SECRET`. The built files hold the names (`AKAN_ENV_NAMES` in `akan.env.json`), never the values.
|
|
38
|
+
- `akan secret-env <app> --env <env>` prints the variables, never a value. `--out <file> --format k8s --name <name>`
|
|
39
|
+
writes a Kubernetes Secret for `envFrom`, `--format dotenv` a file for `bun --env-file`. Never write it
|
|
40
|
+
under `dist/` or a tracked path, and delete it once applied.
|
|
41
|
+
- At boot a variable left unset is one warning naming it. The framework does not stop for it, though whatever reads the value may; 3.5.0 will refuse to boot.
|
|
42
|
+
- A secret the env file computes or imports stops the build, whatever its length: write the string at the key, or
|
|
43
|
+
`process.env.<NAME>` there, which the build leaves as that read. A secret string a plain key or the app's code
|
|
44
|
+
holds as well stops it too when long and mixed, and is a warning when short. A key the name rule misses
|
|
45
|
+
(`stripeKey`) stays in the image unless read from `process.env`.
|
|
46
|
+
- The build loads the env file to list the secrets, with the shell's variables only when it cannot load without
|
|
47
|
+
them; a file that throws as it loads stops the build by error class and line.
|
|
48
|
+
- `akan start`, `akan test`, `akan build --profile …` and desktop and mobile builds read the env file as written.
|
|
49
|
+
`akan build --inline-secrets` keeps the values in the image for one release, for a deployment not ready yet.
|
|
50
|
+
|
|
31
51
|
## Native and desktop
|
|
32
52
|
|
|
33
53
|
A `start-*` command loads its pages from a running `akan start`; a desktop app carrying its server starts it itself.
|
|
@@ -28,6 +28,15 @@ describe("ApiReference", () => {
|
|
|
28
28
|
expect(rendered).toMatch(/^\/\*\* .+ \*\/\nserverMode\?: "batch" \| "federation";$/m);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
+
test("says what each listed subpath holds, and lists only subpaths the package exports", async () => {
|
|
32
|
+
const exports = Object.keys((await Bun.file(path.join(akanjsDir, "package.json")).json()).exports);
|
|
33
|
+
const listed = [...rendered.matchAll(/^- `akanjs\/([^`]+)` — .+\.$/gm)].map(([, subpath]) => `./${subpath}`);
|
|
34
|
+
expect(listed).toEqual(
|
|
35
|
+
["dictionary", "document", "service", "store", "client/native", "native/desktop", "test"].map((s) => `./${s}`),
|
|
36
|
+
);
|
|
37
|
+
for (const subpath of listed) expect(exports).toContain(subpath);
|
|
38
|
+
});
|
|
39
|
+
|
|
31
40
|
test("says what Link takes beyond its own props, and names its static parts", () => {
|
|
32
41
|
expect(rendered).toContain('Every prop of `Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href">`, and:');
|
|
33
42
|
expect(rendered).toMatch(/^Link\.Back\(.+\): Element$/m);
|
package/docs/apiReference.ts
CHANGED
|
@@ -118,6 +118,16 @@ const conventionImports = [
|
|
|
118
118
|
'import { signedIn } from "@libs/shared/webkit"; // a workspace created with --libs true',
|
|
119
119
|
];
|
|
120
120
|
|
|
121
|
+
const subpathPurposes = [
|
|
122
|
+
["akanjs/dictionary", "locales, translations and the dictionaries behind labels, descriptions and `Err` keys"],
|
|
123
|
+
["akanjs/document", "database documents, filters, query builders, full-text search and persistence"],
|
|
124
|
+
["akanjs/service", "services, adapters, dependency injection and the business-logic runtime"],
|
|
125
|
+
["akanjs/store", "domain state, actions and the in-page agent's `st.tool` / `st.use` surface"],
|
|
126
|
+
["akanjs/client/native", "the native bridge and the built-in plugins of iOS, Android and desktop apps"],
|
|
127
|
+
["akanjs/native/desktop", "what an app's or a lib's own native plugin builds its desktop part from"],
|
|
128
|
+
["akanjs/test", "signal-test setup, MCP catalogue checks and sample data (`sampleOf`)"],
|
|
129
|
+
] as const;
|
|
130
|
+
|
|
121
131
|
const routeInternals = ["assertPattern", "resolveArgs", "toRouteModule"];
|
|
122
132
|
|
|
123
133
|
export class ApiReference {
|
|
@@ -160,6 +170,10 @@ export class ApiReference {
|
|
|
160
170
|
...conventionImports,
|
|
161
171
|
"```",
|
|
162
172
|
"",
|
|
173
|
+
"What these subpaths hold:",
|
|
174
|
+
"",
|
|
175
|
+
...subpathPurposes.map(([from, purpose]) => `- \`${from}\` — ${purpose}.`),
|
|
176
|
+
"",
|
|
163
177
|
...body,
|
|
164
178
|
]
|
|
165
179
|
.join("\n")
|
|
@@ -8,12 +8,15 @@ import type { BaseDevEnv, TsConfigJson } from "../workspace/types";
|
|
|
8
8
|
import { Executor, execEmoji } from "./executor";
|
|
9
9
|
import { SysExecutor } from "./sysExecutor";
|
|
10
10
|
|
|
11
|
-
//? As Bun's
|
|
11
|
+
//? As Bun's .env loader reads it (1.4.4), which fills process.env too: `#` ends an unquoted value mid-word, `\$` is `$`.
|
|
12
12
|
const parseEnvValue = (value: string) => {
|
|
13
13
|
const [, quote, inner] = value.match(/^(["'`])((?:\\.|(?!\1)[^\\])*)\1/) ?? [];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const text = !quote
|
|
15
|
+
? value.replace(/#.*/, "").trim()
|
|
16
|
+
: quote !== '"'
|
|
17
|
+
? inner
|
|
18
|
+
: inner.replace(/\\(.)/g, (pair, char: string) => (char === "n" ? "\n" : char === "r" ? "\r" : pair));
|
|
19
|
+
return text.replaceAll("\\$", "$");
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
export const parseEnvFile = (envPath: string): Record<string, string> => {
|
|
@@ -189,4 +189,39 @@ describe("GraphClientEntryDiscovery", () => {
|
|
|
189
189
|
fresh.invalidate([file("Server.tsx")]);
|
|
190
190
|
expect(await fresh.discover([file("Page.tsx")], { importsAs })).toEqual([]);
|
|
191
191
|
});
|
|
192
|
+
|
|
193
|
+
test("a client file exporting only hooks is no entry of a server graph that imports it, one with a component still is", async () => {
|
|
194
|
+
const file = await tempDir();
|
|
195
|
+
await Bun.write(file("Layout.tsx"), 'import "./store";\nimport "./Panel";\n');
|
|
196
|
+
await Bun.write(
|
|
197
|
+
file("store.ts"),
|
|
198
|
+
'import { useForm } from "./useForm";\nimport { useEffect } from "./reactHooks";\nimport "./useMixed";\nexport const st = { useForm, useEffect };\n',
|
|
199
|
+
);
|
|
200
|
+
await Bun.write(
|
|
201
|
+
file("useForm.ts"),
|
|
202
|
+
'"use client";\nimport "./Inner";\nexport interface FormShape {}\nexport const useForm = () => null;\nexport function useOther() {}\n',
|
|
203
|
+
);
|
|
204
|
+
await Bun.write(file("reactHooks.ts"), '"use client";\nexport { useContext, useEffect } from "react";\n');
|
|
205
|
+
await Bun.write(
|
|
206
|
+
file("useMixed.ts"),
|
|
207
|
+
'"use client";\nexport const useMixed = () => null;\nexport const Mixed = () => null;\n',
|
|
208
|
+
);
|
|
209
|
+
await Bun.write(file("Inner.tsx"), '"use client";\nexport const Inner = () => null;\n');
|
|
210
|
+
await Bun.write(
|
|
211
|
+
file("Panel.tsx"),
|
|
212
|
+
'"use client";\nimport { useForm } from "./useForm";\nexport const Panel = () => useForm();\n',
|
|
213
|
+
);
|
|
214
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
215
|
+
expect(await discovery.discover([file("Layout.tsx")])).toEqual([file("Panel.tsx"), file("useMixed.ts")]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("a client file with a default export or a star re-export stays an entry", async () => {
|
|
219
|
+
const file = await tempDir();
|
|
220
|
+
await Bun.write(file("S.tsx"), 'import "./A";\nimport "./B";\nimport "./C";\n');
|
|
221
|
+
await Bun.write(file("A.ts"), '"use client";\nexport default function useA() {}\n');
|
|
222
|
+
await Bun.write(file("B.ts"), '"use client";\nexport * from "./C";\nexport const useB = () => null;\n');
|
|
223
|
+
await Bun.write(file("C.ts"), '"use client";\nexport const C = () => null;\n');
|
|
224
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
225
|
+
expect(await discovery.discover([file("S.tsx")])).toEqual([file("A.ts"), file("B.ts"), file("C.ts")]);
|
|
226
|
+
});
|
|
192
227
|
});
|
|
@@ -7,6 +7,8 @@ import { createTsconfigPackageResolver, rewriteBarrelImports } from "../transfor
|
|
|
7
7
|
import type { AkanConfig, ClientEntryDiscovery, DiscoverOptions, ScannedImport } from "./clientBuildTypes";
|
|
8
8
|
|
|
9
9
|
const USE_CLIENT_RE = /^\s*(?:\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\/\s*|\/\/[^\n]*\n\s*)*["']use client["']/;
|
|
10
|
+
const EXPORT_STAR_RE = /^\s*export\s*\*/m;
|
|
11
|
+
const HOOK_NAME_RE = /^use[A-Z0-9]/;
|
|
10
12
|
const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
11
13
|
const AKANJS_NODE_MODULE_RE = /[\\/]node_modules[\\/]akanjs[\\/]/;
|
|
12
14
|
// Bun's scanImports also surfaces CSS and asset imports, none of which can be a client component.
|
|
@@ -172,7 +174,7 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
172
174
|
.catch(() => null);
|
|
173
175
|
if (content === null) return null;
|
|
174
176
|
this.#readFiles.add(absPath);
|
|
175
|
-
if (USE_CLIENT_RE.test(content)) return { isClientEntry:
|
|
177
|
+
if (USE_CLIENT_RE.test(content)) return { isClientEntry: !this.#exportsOnlyHooks(content), imports: [] };
|
|
176
178
|
return { isClientEntry: false, imports: this.#scanImports(await this.#rewrite(content, absPath)) };
|
|
177
179
|
})();
|
|
178
180
|
this.#factsCache.set(absPath, cached);
|
|
@@ -191,6 +193,17 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
196
|
+
//? A hook is never rendered, so no flight row names its file; `export *` hides names from the scan, so it stays an entry.
|
|
197
|
+
#exportsOnlyHooks(content: string): boolean {
|
|
198
|
+
if (EXPORT_STAR_RE.test(content)) return false;
|
|
199
|
+
try {
|
|
200
|
+
const { exports } = this.#tsTranspiler.scan(content);
|
|
201
|
+
return exports.length > 0 && exports.every((name) => HOOK_NAME_RE.test(name));
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
194
207
|
#scanImports(source: string): ScannedImport[] {
|
|
195
208
|
try {
|
|
196
209
|
return this.#tsTranspiler.scanImports(source);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const Hex = () => <div className="bg-[#3b82f6]" />; // @flag
|
|
2
|
+
export const Rgb = () => <div className="bg-[rgb(0,0,0)]" />; // @flag
|
|
3
|
+
export const Rgba = () => <div className="bg-[rgba(0,0,0,0.5)]" />; // @flag
|
|
4
|
+
export const Hsl = () => <div className="bg-[hsl(210,100%,50%)]" />; // @flag
|
|
5
|
+
export const Hsla = () => <div className="bg-[hsla(210,100%,50%,0.5)]" />; // @flag
|
|
6
|
+
export const Oklch = () => <div className="bg-[oklch(0.5_0.1_200)]" />; // @flag
|
|
7
|
+
export const Oklab = () => <div className="bg-[oklab(0.5_0.1_0.1)]" />; // @flag
|
|
8
|
+
export const Lab = () => <div className="bg-[lab(50%_40_59)]" />; // @flag
|
|
9
|
+
export const Lch = () => <div className="bg-[lch(50%_60_40)]" />; // @flag
|
|
10
|
+
export const Hwb = () => <div className="bg-[hwb(210_10%_10%)]" />; // @flag
|
|
11
|
+
export const ColorFunction = () => <div className="bg-[color(display-p3_1_0_0)]" />; // @flag
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const SlotBgBase100 = () => <div className="bg-base-100" />; // @flag
|
|
2
|
+
export const SlotBgBase200 = () => <div className="bg-base-200" />; // @flag
|
|
3
|
+
export const SlotBgBase300 = () => <div className="bg-base-300" />; // @flag
|
|
4
|
+
export const SlotTextBaseContent = () => <div className="text-base-content" />; // @flag
|
|
5
|
+
export const SlotTextPrimaryContent = () => <div className="text-primary-content" />; // @flag
|
|
6
|
+
export const SlotTextSecondaryContent = () => <div className="text-secondary-content" />; // @flag
|
|
7
|
+
export const SlotTextAccentContent = () => <div className="text-accent-content" />; // @flag
|
|
8
|
+
export const SlotTextNeutralContent = () => <div className="text-neutral-content" />; // @flag
|
|
9
|
+
export const SlotTextInfoContent = () => <div className="text-info-content" />; // @flag
|
|
10
|
+
export const SlotTextSuccessContent = () => <div className="text-success-content" />; // @flag
|
|
11
|
+
export const SlotTextWarningContent = () => <div className="text-warning-content" />; // @flag
|
|
12
|
+
export const SlotTextErrorContent = () => <div className="text-error-content" />; // @flag
|
|
13
|
+
export const SlotBgError = () => <div className="bg-error" />; // @flag
|
|
14
|
+
export const ComponentBtnPrimary = () => <div className="btn-primary" />; // @warn
|
|
15
|
+
export const ComponentBadgeGhost = () => <div className="badge-ghost" />; // @warn
|
|
16
|
+
export const ComponentAlertInfo = () => <div className="alert-info" />; // @warn
|
|
17
|
+
export const ComponentInputBordered = () => <div className="input-bordered" />; // @warn
|
|
18
|
+
export const ComponentSelectBordered = () => <div className="select-bordered" />; // @warn
|
|
19
|
+
export const ComponentTextareaGhost = () => <div className="textarea-ghost" />; // @warn
|
|
20
|
+
export const ComponentCheckboxPrimary = () => <div className="checkbox-primary" />; // @warn
|
|
21
|
+
export const ComponentToggleAccent = () => <div className="toggle-accent" />; // @warn
|
|
22
|
+
export const ComponentLoadingSpinner = () => <div className="loading-spinner" />; // @warn
|
|
23
|
+
export const ComponentCardBody = () => <div className="card-body" />; // @warn
|
|
24
|
+
export const ComponentModalBox = () => <div className="modal-box" />; // @warn
|
|
25
|
+
export const ComponentCollapseTitle = () => <div className="collapse-title" />; // @warn
|
|
26
|
+
export const ComponentDropdownContent = () => <div className="dropdown-content" />; // @warn
|
|
27
|
+
export const ComponentStatValue = () => <div className="stat-value" />; // @warn
|
|
28
|
+
export const ComponentTabsBoxed = () => <div className="tabs-boxed" />; // @warn
|
|
29
|
+
export const ComponentTabActive = () => <div className="tab-active" />; // @warn
|
|
30
|
+
export const ComponentMenuTitle = () => <div className="menu-title" />; // @warn
|
|
31
|
+
export const ComponentStepsVertical = () => <div className="steps-vertical" />; // @warn
|
|
32
|
+
export const ComponentJoinItem = () => <div className="join-item" />; // @warn
|
|
33
|
+
export const ComponentMockupCode = () => <div className="mockup-code" />; // @warn
|
|
34
|
+
export const ComponentDrawerSide = () => <div className="drawer-side" />; // @warn
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const Hex = () => <div style={{ color: "#abc" }} />; // @flag
|
|
2
|
+
export const Rgb = () => <div style={{ color: "rgb(0,0,0)" }} />; // @flag
|
|
3
|
+
export const Rgba = () => <div style={{ color: "rgba(0,0,0,0.5)" }} />; // @flag
|
|
4
|
+
export const Hsl = () => <div style={{ color: "hsl(0 0% 0%)" }} />; // @flag
|
|
5
|
+
export const Hsla = () => <div style={{ color: "hsla(0,0%,0%,0.5)" }} />; // @flag
|
|
6
|
+
export const Oklch = () => <div style={{ color: "oklch(0.5 0.1 200)" }} />; // @flag
|
|
7
|
+
export const Oklab = () => <div style={{ color: "oklab(0.5 0.1 0.1)" }} />; // @flag
|
|
8
|
+
export const Lab = () => <div style={{ color: "lab(50% 40 59)" }} />; // @flag
|
|
9
|
+
export const Lch = () => <div style={{ color: "lch(50% 60 40)" }} />; // @flag
|
|
10
|
+
export const Hwb = () => <div style={{ color: "hwb(210 10% 10%)" }} />; // @flag
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const Slate = () => <div className="bg-slate-500" />; // @flag
|
|
2
|
+
export const Gray = () => <div className="bg-gray-500" />; // @flag
|
|
3
|
+
export const Zinc = () => <div className="bg-zinc-500" />; // @flag
|
|
4
|
+
export const Neutral = () => <div className="bg-neutral-500" />; // @flag
|
|
5
|
+
export const Stone = () => <div className="bg-stone-500" />; // @flag
|
|
6
|
+
export const Red = () => <div className="bg-red-500" />; // @flag
|
|
7
|
+
export const Orange = () => <div className="bg-orange-500" />; // @flag
|
|
8
|
+
export const Amber = () => <div className="bg-amber-500" />; // @flag
|
|
9
|
+
export const Yellow = () => <div className="bg-yellow-500" />; // @flag
|
|
10
|
+
export const Lime = () => <div className="bg-lime-500" />; // @flag
|
|
11
|
+
export const Green = () => <div className="bg-green-500" />; // @flag
|
|
12
|
+
export const Emerald = () => <div className="bg-emerald-500" />; // @flag
|
|
13
|
+
export const Teal = () => <div className="bg-teal-500" />; // @flag
|
|
14
|
+
export const Cyan = () => <div className="bg-cyan-500" />; // @flag
|
|
15
|
+
export const Sky = () => <div className="bg-sky-500" />; // @flag
|
|
16
|
+
export const Blue = () => <div className="bg-blue-500" />; // @flag
|
|
17
|
+
export const Indigo = () => <div className="bg-indigo-500" />; // @flag
|
|
18
|
+
export const Violet = () => <div className="bg-violet-500" />; // @flag
|
|
19
|
+
export const Purple = () => <div className="bg-purple-500" />; // @flag
|
|
20
|
+
export const Fuchsia = () => <div className="bg-fuchsia-500" />; // @flag
|
|
21
|
+
export const Pink = () => <div className="bg-pink-500" />; // @flag
|
|
22
|
+
export const Rose = () => <div className="bg-rose-500" />; // @flag
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, symlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { hasBiome, tempDirs, writeText } from "../test/testHelpers";
|
|
5
|
+
import { BiomeCheck } from "./biomeCheck";
|
|
6
|
+
|
|
7
|
+
const makeTempRoot = tempDirs("akan-devkit-biome-check-");
|
|
8
|
+
const repoRoot = path.resolve(import.meta.dir, "../../../..");
|
|
9
|
+
const sentinel = "SENTINEL_DB_PASSWORD_4f9c2a71e0b3";
|
|
10
|
+
|
|
11
|
+
const workspace = async () => {
|
|
12
|
+
const root = await makeTempRoot();
|
|
13
|
+
await mkdir(path.join(root, "node_modules"), { recursive: true });
|
|
14
|
+
await symlink(path.join(repoRoot, "node_modules/@biomejs"), path.join(root, "node_modules/@biomejs"));
|
|
15
|
+
await writeText(
|
|
16
|
+
path.join(root, "biome.json"),
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
vcs: { enabled: false },
|
|
19
|
+
linter: { rules: { suspicious: { noTemplateCurlyInString: "error", noExplicitAny: "error" } } },
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
await writeText(
|
|
23
|
+
path.join(root, "apps/demo/env/env.server.main.ts"),
|
|
24
|
+
`export const env = { apiKey: "${sentinel}", password: "${sentinel}\${x}" };\n`,
|
|
25
|
+
);
|
|
26
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card: any = 1;\n");
|
|
27
|
+
return root;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const run = async (root: string, options: { write: boolean; maxDiagnostics: number }) => {
|
|
31
|
+
const printed: string[] = [];
|
|
32
|
+
const error = await BiomeCheck.run({
|
|
33
|
+
root,
|
|
34
|
+
target: path.join(root, "apps/demo"),
|
|
35
|
+
configPath: path.join(root, "biome.json"),
|
|
36
|
+
print: (text) => printed.push(text),
|
|
37
|
+
...options,
|
|
38
|
+
}).then(
|
|
39
|
+
() => null,
|
|
40
|
+
(e: unknown) => e as Error,
|
|
41
|
+
);
|
|
42
|
+
return { output: printed.join("\n"), error };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe.skipIf(!hasBiome)("BiomeCheck", () => {
|
|
46
|
+
test.each([true, false])(
|
|
47
|
+
"names an env file's diagnostics by position and rule only, with write %p",
|
|
48
|
+
async (write) => {
|
|
49
|
+
const root = await workspace();
|
|
50
|
+
const { output, error } = await run(root, { write, maxDiagnostics: 200 });
|
|
51
|
+
|
|
52
|
+
expect(output).not.toContain(sentinel);
|
|
53
|
+
expect(output).not.toContain("apiKey");
|
|
54
|
+
expect(output).toMatch(
|
|
55
|
+
/apps\/demo\/env\/env\.server\.main\.ts:\d+:\d+ error lint\/suspicious\/noTemplateCurlyInString/,
|
|
56
|
+
);
|
|
57
|
+
expect(output).toContain("withheld");
|
|
58
|
+
expect(output).toContain("export const card: any = 1;");
|
|
59
|
+
expect(error?.message).toBe(write ? "Lint found 2 errors." : "Lint found 3 errors.");
|
|
60
|
+
if (!write) expect(output).toMatch(/env\.server\.main\.ts:0:0 error format/);
|
|
61
|
+
},
|
|
62
|
+
60_000,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
test("counts an env file's diagnostics when nothing else fails, and keeps to the cap", async () => {
|
|
66
|
+
const root = await workspace();
|
|
67
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card = 1;\n");
|
|
68
|
+
const all = await run(root, { write: true, maxDiagnostics: 0 });
|
|
69
|
+
expect(all.error?.message).toBe("Lint found 1 error.");
|
|
70
|
+
expect(all.output).not.toContain(sentinel);
|
|
71
|
+
|
|
72
|
+
const capped = await run(await workspace(), { write: false, maxDiagnostics: 1 });
|
|
73
|
+
expect(capped.output.match(/env\.server\.main\.ts:/g)).toHaveLength(1);
|
|
74
|
+
expect(capped.output).toContain("not shown");
|
|
75
|
+
expect(capped.output).not.toContain("export const card: any");
|
|
76
|
+
expect(capped.error).not.toBeNull();
|
|
77
|
+
}, 60_000);
|
|
78
|
+
|
|
79
|
+
test("explains a biome.json Biome cannot read, in Biome's own words", async () => {
|
|
80
|
+
const root = await workspace();
|
|
81
|
+
await writeText(path.join(root, "biome.json"), '{ // a comment\n "vcs": { "enabled": false } }');
|
|
82
|
+
const { error, output } = await run(root, { write: false, maxDiagnostics: 200 });
|
|
83
|
+
expect(output).toBe("");
|
|
84
|
+
expect(error?.message).toContain("biome.json");
|
|
85
|
+
expect(error?.message).not.toContain("gave no report");
|
|
86
|
+
}, 60_000);
|
|
87
|
+
|
|
88
|
+
test("reports every file of a large app in groups, and stops at the cap with the count left", async () => {
|
|
89
|
+
const root = await workspace();
|
|
90
|
+
await writeText(path.join(root, "apps/demo/env/env.server.main.ts"), "export const env = {};\n");
|
|
91
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card = 1;\n");
|
|
92
|
+
for (let idx = 0; idx < 250; idx += 1)
|
|
93
|
+
await writeText(path.join(root, `apps/demo/ui/many/file${idx}.ts`), `export const value${idx}: any = ${idx};\n`);
|
|
94
|
+
const reported = (output: string) => output.match(/noExplicitAny ━/g)?.length ?? 0;
|
|
95
|
+
|
|
96
|
+
const all = await run(root, { write: false, maxDiagnostics: 0 });
|
|
97
|
+
expect(reported(all.output)).toBe(250);
|
|
98
|
+
expect(all.output).not.toContain("not shown");
|
|
99
|
+
expect(all.output.match(/^Found 250 errors\.$/gm)).toHaveLength(1);
|
|
100
|
+
expect(all.output).not.toContain("Checked ");
|
|
101
|
+
expect(all.error?.message).toBe("Lint found 250 errors.");
|
|
102
|
+
|
|
103
|
+
const capped = await run(root, { write: false, maxDiagnostics: 150 });
|
|
104
|
+
expect(reported(capped.output)).toBe(150);
|
|
105
|
+
expect(capped.output).toContain("50 more diagnostics are not shown; --max-diagnostics 0 shows them all.");
|
|
106
|
+
}, 120_000);
|
|
107
|
+
|
|
108
|
+
test("lists after a write only what is still wrong", async () => {
|
|
109
|
+
const root = await workspace();
|
|
110
|
+
await writeText(path.join(root, "apps/demo/env/env.server.main.ts"), "export const env = {};\n");
|
|
111
|
+
await writeText(path.join(root, "apps/demo/ui/card.ts"), "export const card = 1;\nexport const other = 2\n");
|
|
112
|
+
const { output, error } = await run(root, { write: true, maxDiagnostics: 200 });
|
|
113
|
+
expect(output).toBe("");
|
|
114
|
+
expect(error).toBeNull();
|
|
115
|
+
expect(await Bun.file(path.join(root, "apps/demo/ui/card.ts")).text()).toContain("export const other = 2;");
|
|
116
|
+
}, 60_000);
|
|
117
|
+
|
|
118
|
+
test("withholds a grit plugin diagnostic on an env file", async () => {
|
|
119
|
+
const root = await workspace();
|
|
120
|
+
await writeText(
|
|
121
|
+
path.join(root, "no-marker.grit"),
|
|
122
|
+
'engine biome(1.0)\nlanguage js(typescript)\n`MARKER` as $m where { register_diagnostic(span = $m, message = "marker found", severity = "error") }\n',
|
|
123
|
+
);
|
|
124
|
+
await writeText(
|
|
125
|
+
path.join(root, "biome.json"),
|
|
126
|
+
JSON.stringify({ vcs: { enabled: false }, plugins: ["./no-marker.grit"] }),
|
|
127
|
+
);
|
|
128
|
+
await writeText(
|
|
129
|
+
path.join(root, "apps/demo/env/env.server.main.ts"),
|
|
130
|
+
`export const env = { password: MARKER, other: "${sentinel}" };\n`,
|
|
131
|
+
);
|
|
132
|
+
const { output, error } = await run(root, { write: false, maxDiagnostics: 200 });
|
|
133
|
+
expect(output).not.toContain(sentinel);
|
|
134
|
+
expect(output).toMatch(/env\.server\.main\.ts:\d+:\d+ error plugin - the text is withheld/);
|
|
135
|
+
expect(error).not.toBeNull();
|
|
136
|
+
}, 60_000);
|
|
137
|
+
|
|
138
|
+
test("drops a group's own summary lines, coloured or not", () => {
|
|
139
|
+
const coloured = "\u001b[1mChecked 100 files in 1s.\u001b[0m\n\u001b[31mFound 3 errors.\u001b[39m\na.ts:1:1 lint/x";
|
|
140
|
+
expect(BiomeCheck.withoutSummary(coloured)).toBe("a.ts:1:1 lint/x");
|
|
141
|
+
expect(BiomeCheck.withoutSummary("Checked 1 file in 2ms.\nFound 1 warning.\nb.ts:2:1 lint/y")).toBe(
|
|
142
|
+
"b.ts:2:1 lint/y",
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { CliError } from "../commandDecorators/cliError";
|
|
2
|
+
import { type BiomeDiagnostic, Linter, parseBiomeReport } from "./linter";
|
|
3
|
+
import { WithheldEnvFile } from "./withheldEnvFile";
|
|
4
|
+
|
|
5
|
+
export interface BiomeCheckOptions {
|
|
6
|
+
root: string;
|
|
7
|
+
target: string;
|
|
8
|
+
configPath: string | null;
|
|
9
|
+
write: boolean;
|
|
10
|
+
//? 0 shows every diagnostic.
|
|
11
|
+
maxDiagnostics: number;
|
|
12
|
+
print: (text: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//* Biome's own report quotes source lines, so a first run writes the fixes and reads the JSON report. An env file's
|
|
16
|
+
//* diagnostics are printed from it by position and rule alone; Biome prints the rest again, from the files that have any.
|
|
17
|
+
export class BiomeCheck {
|
|
18
|
+
static readonly #groupSize = 100;
|
|
19
|
+
static readonly #summary = /^(?:Checked \d+ files? in |Found \d+ (?:errors?|warnings?|info))/;
|
|
20
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: an ANSI colour sequence starts with the escape character
|
|
21
|
+
static readonly #colour = /\u001b\[[0-9;]*m/g;
|
|
22
|
+
|
|
23
|
+
static async run({ root, target, configPath, write, maxDiagnostics, print }: BiomeCheckOptions) {
|
|
24
|
+
const [biome, ...biomeArgs] = Linter.biomeCommand(root);
|
|
25
|
+
//? Pinned: without it a malformed biome.json makes Biome fall back to discovery and name the wrong file.
|
|
26
|
+
const config = configPath ? ["--config-path", configPath] : [];
|
|
27
|
+
const first = Bun.spawn(
|
|
28
|
+
[
|
|
29
|
+
biome,
|
|
30
|
+
...biomeArgs,
|
|
31
|
+
"check",
|
|
32
|
+
...(write ? ["--write"] : []),
|
|
33
|
+
"--reporter=json",
|
|
34
|
+
"--max-diagnostics=none",
|
|
35
|
+
"--no-errors-on-unmatched",
|
|
36
|
+
...config,
|
|
37
|
+
target,
|
|
38
|
+
],
|
|
39
|
+
{ cwd: root, stdout: "pipe", stderr: "pipe" },
|
|
40
|
+
);
|
|
41
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
42
|
+
new Response(first.stdout).text(),
|
|
43
|
+
new Response(first.stderr).text(),
|
|
44
|
+
first.exited,
|
|
45
|
+
]);
|
|
46
|
+
let diagnostics: BiomeDiagnostic[];
|
|
47
|
+
try {
|
|
48
|
+
diagnostics = parseBiomeReport(stdout).diagnostics ?? [];
|
|
49
|
+
} catch {
|
|
50
|
+
const cause = (stderr || stdout).trim();
|
|
51
|
+
throw new CliError(
|
|
52
|
+
"failed",
|
|
53
|
+
cause && !WithheldEnvFile.namesEnvFile(cause)
|
|
54
|
+
? cause
|
|
55
|
+
: `Biome exited with ${exitCode} and gave no report that could be read.`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const shown = diagnostics.filter(({ severity }) => severity !== "hint");
|
|
59
|
+
const inEnv = (diagnostic: BiomeDiagnostic) =>
|
|
60
|
+
WithheldEnvFile.isEnvFile(diagnostic.location?.path?.replaceAll("\\", "/"));
|
|
61
|
+
const fromEnv = shown.filter(inEnv);
|
|
62
|
+
const rest = shown.filter((diagnostic) => !inEnv(diagnostic));
|
|
63
|
+
let remaining = maxDiagnostics > 0 ? maxDiagnostics : Number.POSITIVE_INFINITY;
|
|
64
|
+
for (const diagnostic of fromEnv.slice(0, remaining)) print(BiomeCheck.#line(diagnostic));
|
|
65
|
+
let hidden = Math.max(0, fromEnv.length - remaining);
|
|
66
|
+
remaining -= Math.min(fromEnv.length, remaining);
|
|
67
|
+
for (const group of BiomeCheck.#groups(rest)) {
|
|
68
|
+
if (remaining <= 0) {
|
|
69
|
+
hidden += group.count;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const second = Bun.spawn(
|
|
73
|
+
[
|
|
74
|
+
biome,
|
|
75
|
+
...biomeArgs,
|
|
76
|
+
"check",
|
|
77
|
+
//? Biome shows 20 diagnostics unless told otherwise.
|
|
78
|
+
`--max-diagnostics=${Number.isFinite(remaining) ? remaining : "none"}`,
|
|
79
|
+
...(process.stdout.isTTY && !process.env.NO_COLOR ? ["--colors=force"] : []),
|
|
80
|
+
...config,
|
|
81
|
+
...group.files,
|
|
82
|
+
],
|
|
83
|
+
{ cwd: root, stdout: "pipe", stderr: "pipe" },
|
|
84
|
+
);
|
|
85
|
+
const [out, err] = await Promise.all([
|
|
86
|
+
new Response(second.stdout).text(),
|
|
87
|
+
new Response(second.stderr).text(),
|
|
88
|
+
second.exited,
|
|
89
|
+
]);
|
|
90
|
+
print(BiomeCheck.withoutSummary(`${out}${err}`));
|
|
91
|
+
remaining -= Math.min(group.count, remaining);
|
|
92
|
+
}
|
|
93
|
+
for (const diagnostic of rest.filter(({ location }) => !location?.path)) print(diagnostic.message);
|
|
94
|
+
if (hidden) print(`${hidden} more diagnostics are not shown; --max-diagnostics 0 shows them all.`);
|
|
95
|
+
const count = (severity: string) => shown.filter((diagnostic) => diagnostic.severity === severity).length;
|
|
96
|
+
for (const [severity, noun] of [
|
|
97
|
+
["error", "error"],
|
|
98
|
+
["warning", "warning"],
|
|
99
|
+
["information", "info"],
|
|
100
|
+
] as const)
|
|
101
|
+
if (count(severity))
|
|
102
|
+
print(`Found ${count(severity)} ${noun}${count(severity) === 1 || noun === "info" ? "" : "s"}.`);
|
|
103
|
+
const errors = count("error");
|
|
104
|
+
if (errors) throw new CliError("checkFailed", `Lint found ${errors} error${errors === 1 ? "" : "s"}.`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//? Each group's summary counts only its own files; the one printed at the end counts the whole run.
|
|
108
|
+
static withoutSummary(text: string) {
|
|
109
|
+
return text
|
|
110
|
+
.split("\n")
|
|
111
|
+
.filter((line) => !BiomeCheck.#summary.test(line.replace(BiomeCheck.#colour, "")))
|
|
112
|
+
.join("\n")
|
|
113
|
+
.trim();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static #groups(diagnostics: BiomeDiagnostic[]) {
|
|
117
|
+
const counts = new Map<string, number>();
|
|
118
|
+
for (const { location } of diagnostics)
|
|
119
|
+
if (location?.path) counts.set(location.path, (counts.get(location.path) ?? 0) + 1);
|
|
120
|
+
const entries = [...counts];
|
|
121
|
+
return Array.from({ length: Math.ceil(entries.length / BiomeCheck.#groupSize) }, (_, index) => {
|
|
122
|
+
const slice = entries.slice(index * BiomeCheck.#groupSize, (index + 1) * BiomeCheck.#groupSize);
|
|
123
|
+
return { files: slice.map(([file]) => file), count: slice.reduce((sum, [, count]) => sum + count, 0) };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static #line({ severity, category, location }: BiomeDiagnostic) {
|
|
128
|
+
const at = `${location?.path}:${location?.start?.line ?? 0}:${location?.start?.column ?? 0}`;
|
|
129
|
+
return `${at} ${severity} ${category ?? "biome"} - ${WithheldEnvFile.note}`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -10,6 +10,11 @@ or {
|
|
|
10
10
|
JsStringLiteralExpression() as $s,
|
|
11
11
|
JsTemplateChunkElement() as $s
|
|
12
12
|
} where {
|
|
13
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates it.
|
|
14
|
+
$s <: or {
|
|
15
|
+
includes "[#", includes "[rgb", includes "[hsl", includes "[ok", includes "[lab(", includes "[lch(",
|
|
16
|
+
includes "[hwb(", includes "[color("
|
|
17
|
+
},
|
|
13
18
|
$s <: r"[\s\S]*\[(?:#[0-9a-fA-F]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lab|lch|hwb|color)\([^\]]*\))\][\s\S]*",
|
|
14
19
|
register_diagnostic(
|
|
15
20
|
span = $s,
|
|
@@ -32,6 +32,8 @@ pattern st_hook_call() {
|
|
|
32
32
|
`$chain.value($args)` where { $chain <: r"st\s*\.\s*expose\s*\([\s\S]*" },
|
|
33
33
|
// Computed access (`st["use"].x()`, `st.use[key]()`) at any step, which would take a snippet per combination.
|
|
34
34
|
JsCallExpression(callee = $callee) where {
|
|
35
|
+
// GritQL compiles a regex anew for every node it tries, so a substring every match must contain gates it.
|
|
36
|
+
$callee <: or { includes "use", includes "sel", includes "ref" },
|
|
35
37
|
$callee <: or {
|
|
36
38
|
r"st\s*(?:\.\s*use|\[\s*[\x27\x22`]use[\x27\x22`]\s*\])\s*(?:\.\s*[\w$]+|\[[^\]]*\])",
|
|
37
39
|
r"st\s*(?:\.\s*slice|\[\s*[\x27\x22`]slice[\x27\x22`]\s*\])\s*(?:\.\s*[\w$]+|\[[^\]]*\])\s*(?:\.\s*use|\[\s*[\x27\x22`]use[\x27\x22`]\s*\])\s*(?:\.\s*[\w$]+|\[[^\]]*\])",
|
|
@@ -78,7 +80,9 @@ pattern passed_by_name($name) {
|
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
// GritQL copies its match state for every snippet it tries, so a substring every hook's callee contains goes first.
|
|
84
|
+
JsCallExpression(callee = $hookCallee) as $call where {
|
|
85
|
+
$hookCallee <: includes "st",
|
|
82
86
|
$call <: st_hook_call(),
|
|
83
87
|
or {
|
|
84
88
|
$call <: within JsLogicalExpression(right = $right) where { $right <: contains $call } until function_boundary(),
|