@ai-ecoverse/slicc-shared-web 1.29.2 → 1.29.4
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 +18 -3
- package/bin/slicc-install-hooks.sh +14 -0
- package/bin/slicc-unit-cover.mjs +25 -2
- package/lefthook.yml +1 -1
- package/mcr.config.mjs +10 -9
- package/package.json +4 -1
- package/unit/sources.mjs +37 -0
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
|
|
|
8
8
|
| `.github/workflows/node-ci.yml` | Reusable CI: `npm ci`, lint, Chromium's system libraries, integration tests, hotspots and the stack of every crash dump in the job summary, coverage/profiles/screenshots/crash dumps as artifacts. The browser itself comes from each repo's `pretest` | `jobs: { ci: { uses: ai-ecoverse/slicc-shared-web/.github/workflows/node-ci.yml@vX.Y.Z } }` |
|
|
9
9
|
| `biome.json` | Formatter settings and slicc's strict linter: cognitive complexity ≤ 25, functions ≤ 150 lines, no unused variables or imports, no floating or misused promises, naming conventions, `import type`/`export type`. Test files under `test/` get slicc's test exemptions | `biome.json`: `{ "extends": ["@ai-ecoverse/slicc-shared-web/biome"] }` |
|
|
10
10
|
| `tsconfig.json` | TypeScript base for Node's type stripping | `tsconfig.json`: `{ "extends": "@ai-ecoverse/slicc-shared-web/tsconfig.json", "include": ["src/**/*.ts"] }` |
|
|
11
|
-
| `lefthook.yml` | Pre-commit hooks: Biome, typecheck, no comments, no unit tests in git, AGENTS.md, and diff coverage over [only the unit tests the change reaches](#which-unit-tests-a-commit-runs) | `lefthook.yml`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]` |
|
|
12
|
-
| `mcr.config.mjs` | Unit-test coverage for JS and TS sources in `src/` (TS types are stripped first), written to `coverage/unit/lcov.info`. Every source file is in it, tested or not, and paths are matched relative to the repo root, so a checkout under a dot-directory such as `~/.bb/` still reports untested files to diff coverage. With `SLICC_UNIT_TESTS` set, `node --test` runs only those files ([below](#which-unit-tests-a-commit-runs)) | `test:unit`: `mcr -c node_modules/@ai-ecoverse/slicc-shared-web/mcr.config.mjs node --test 'test/unit/**/*.test.mjs'` |
|
|
13
|
-
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. Every step prints its own `<step>: PASS …` line, and slicc-lint checks for it: a step that exits 0 without one fails the run with exit 70 (`slicc-lint: FAIL <step> (no PASS line from it)`), so a check that silently stops early can't pass. The last line, `slicc-lint: PASS`, comes only after every step has printed its PASS, and a gate can require it. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps). `slicc-memory-peak` prints the job's [memory peak](#memory-peak) | `lint`: `slicc-lint`, and the hooks above |
|
|
11
|
+
| `lefthook.yml` | Pre-commit hooks: Biome, typecheck, no comments, no unit tests in git, AGENTS.md, and diff coverage over [only the unit tests the change reaches](#which-unit-tests-a-commit-runs) | `lefthook.yml`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]`, and `prepare`: `slicc-install-hooks` ([one hooks directory per worktree](#one-hooks-directory-per-worktree)) |
|
|
12
|
+
| `mcr.config.mjs` | Unit-test coverage for JS and TS sources (`.js`, `.mjs`, `.cjs`, `.ts`, `.mts`, `.cts`) in `src/` or the `slicc.unitSources` directories (TS types are stripped first), written to `coverage/unit/lcov.info`. Every source file is in it, tested or not, and paths are matched relative to the repo root, so a checkout under a dot-directory such as `~/.bb/` still reports untested files to diff coverage. With `SLICC_UNIT_TESTS` set, `node --test` runs only those files ([below](#which-unit-tests-a-commit-runs)) | `test:unit`: `mcr -c node_modules/@ai-ecoverse/slicc-shared-web/mcr.config.mjs node --test 'test/unit/**/*.test.mjs'` |
|
|
13
|
+
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. Every step prints its own `<step>: PASS …` line, and slicc-lint checks for it: a step that exits 0 without one fails the run with exit 70 (`slicc-lint: FAIL <step> (no PASS line from it)`), so a check that silently stops early can't pass. The last line, `slicc-lint: PASS`, comes only after every step has printed its PASS, and a gate can require it. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps). `slicc-memory-peak` prints the job's [memory peak](#memory-peak). `slicc-install-hooks` installs the hooks into [this worktree's own directory](#one-hooks-directory-per-worktree) | `lint`: `slicc-lint`, and the hooks above |
|
|
14
14
|
| `pnpmfile.mjs` | pnpm's counterpart to the Renovate preset: an `updateConfig` hook that adds `@ai-ecoverse/*` to `minimumReleaseAgeExclude`, so pnpm 12 doesn't hold back our own fresh releases (`ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`) while third-party packages keep its age check | in a repo with a pnpm lockfile, as a [config dependency](https://pnpm.io/config-dependencies) in `pnpm-workspace.yaml`: `configDependencies: { '@ai-ecoverse/slicc-shared-web': X.Y.Z }` plus `pnpmfile: node_modules/.pnpm-config/@ai-ecoverse/slicc-shared-web/pnpmfile.mjs` |
|
|
15
15
|
| `harness/` | The CDP integration-test harness, described [below](#integration-test-harness) | `import { launch } from '@ai-ecoverse/slicc-shared-web/harness'`, and `--test-global-setup=node_modules/@ai-ecoverse/slicc-shared-web/harness/global.mjs` |
|
|
16
16
|
|
|
@@ -204,16 +204,31 @@ jobs:
|
|
|
204
204
|
- **The one label:** `cert-review-approved` is the single exception to "no labels" (PM, provisional): it applies only to pull requests that change the certifier, it can't turn a failure into a pass (success needs the guard's approval and a pass verdict), and the approver is an agent. Dropping it is the `approval-label` input plus the guard step, with nothing else depending on it.
|
|
205
205
|
- **Releases** carry no cert line: merged on main means certified; supply-chain provenance stays a code-only check in each repo.
|
|
206
206
|
|
|
207
|
+
## One hooks directory per worktree
|
|
208
|
+
|
|
209
|
+
Without it, every worktree of a repo shares `.git/hooks/` with the main clone, and each `lefthook install` repoints that one hook at its own worktree's lefthook, so a commit anywhere runs with whichever worktree installed last, until that worktree is deleted. A repo's `package.json` installs the hooks with:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
"prepare": "slicc-install-hooks"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- **What it does:** moves `core.bare` and `core.worktree` from the shared config into the main worktree's `config.worktree` (so worktrees of a bare repo stay work trees), turns on `extensions.worktreeConfig`, sets this worktree's own `core.hooksPath` (`git config --worktree`) to `worktree-hooks/` in its git directory (`.git/worktree-hooks/` in the main clone, `.git/worktrees/<name>/worktree-hooks/` in a linked worktree), then runs `lefthook install` there. Running it again changes nothing.
|
|
216
|
+
- **Hooks are never shared:** each worktree's hook calls its own `node_modules` lefthook, whatever another worktree installs later, and removing a worktree removes only its own hooks. Once it has run, lefthook's own `postinstall` and later `lefthook install` runs follow the same `core.hooksPath`. The first `npm install` in a new worktree runs that `postinstall` before `prepare`, so it still writes the shared `.git/hooks/` once.
|
|
217
|
+
- **A worktree that never ran it:** it still falls back to the shared `.git/hooks/`, which any new worktree can repoint, until `npm install` runs there.
|
|
218
|
+
- **Outside a git checkout** (a packed tarball, say) it does nothing and exits 0.
|
|
219
|
+
|
|
207
220
|
## Which unit tests a commit runs
|
|
208
221
|
|
|
209
222
|
The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover the staged change, then `slicc-diff-cover` on their `coverage/unit/lcov.info`, so every staged line in `src/` still has to run:
|
|
210
223
|
|
|
224
|
+
- **Which directories are source:** `src/` by default, anywhere in the path, as before. A repo whose code lives elsewhere lists its directories in `package.json`: `"slicc": { "unitSources": ["extension", "six", "scripts"] }`, repo-relative, without `.` or `..` segments. `mcr.config.mjs` then collects coverage only from those directories, and the hook treats a staged file outside them as no code. A malformed list fails the hook.
|
|
211
225
|
- **What counts as changed:** the staged files (`git diff --cached --name-only`), and nothing else. `test/unit/` is gitignored, and repos that keep their unit tests in a store outside git sync the whole store into it before a commit, which brings in tests for code that is on other branches; so a unit test that is new or edited runs only when its imports reach a staged file, like any other. One that reaches nothing staged adds no coverage to the staged lines.
|
|
212
226
|
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a repo file that doesn't exist and isn't a staged deletion (a store test for a module on another branch) is skipped, and the hook names it in one line before the count.
|
|
213
227
|
- **Which tests run:** every `*.test.*` file in `test/unit/` that is changed, or whose static imports reach a changed file. The import graph is parsed with [acorn](https://github.com/acornjs/acorn), TypeScript after Node's type stripping. It follows `import`, `export … from`, `import()`, `require()` and `new URL(…, import.meta.url)` with literal paths, relative or through the `paths` of `tsconfig.json` (and the files it extends). A path may leave out its extension or name `index`, and `.js` also finds `.ts`. Type-only imports don't count, and nothing is followed into `node_modules/`.
|
|
214
228
|
- **Barrels are followed by name:** a test that imports `{ a, b }` from a module follows only what provides `a` and `b`: `export { a } from`, `export { default as a } from`, an imported binding exported again, and `export * from`, by the target's own exports. `const { a, b } = await import('…')` with a literal path is followed by name too. A name the module declares itself follows all of that module's imports. A namespace import (`import * as`), any other `import()` (bound to a namespace, with `.then`, or destructured with a computed key or a rest element), a `require()`, and an `export *` that leads outside the repo or into CommonJS (any `.cjs` or `.cts` file) all count as the whole module.
|
|
215
229
|
- **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
|
|
216
230
|
- **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
|
|
231
|
+
- **A staged source file missing from the lcov:** the hook fails and names it, so no file passes diff coverage just because nothing measured it. `.jsx` and `.tsx` files are not transformed for coverage, so staging one under the sources fails the hook too.
|
|
217
232
|
- **A file that won't parse:** one warning line, then every unit test.
|
|
218
233
|
|
|
219
234
|
The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A selection of more than `SLICC_UNIT_BATCH` files (60 by default) runs in batches of that size, one `test:unit` run each with its own coverage in `coverage/unit/batch-N/` (the shared `mcr.config.mjs` writes to `SLICC_UNIT_COVERAGE_DIR` when it's set), and `slicc-diff-cover` gets every batch's `lcov.info`; diff-cover counts a line covered when any batch covered it. The hook ends with one verdict line over all batches, `slicc-unit-cover: PASS …` or `slicc-unit-cover: FAIL …` (the first failing batch stops the run and fails it; diff coverage then doesn't run). That keeps the coverage merge, which grows with the number of test files, small enough for a memory-capped hook on a widely imported file. A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. To force a full run in the hook:
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
git rev-parse --git-dir >/dev/null 2>&1 || exit 0
|
|
4
|
+
common="$(git rev-parse --path-format=absolute --git-common-dir)"
|
|
5
|
+
for key in core.bare core.worktree; do
|
|
6
|
+
if value=$(git config --file "$common/config" --get "$key"); then
|
|
7
|
+
git config --file "$common/config.worktree" --get "$key" >/dev/null || git config --file "$common/config.worktree" "$key" "$value"
|
|
8
|
+
git config --file "$common/config" --unset "$key"
|
|
9
|
+
fi
|
|
10
|
+
done
|
|
11
|
+
hooks="$(git rev-parse --absolute-git-dir)/worktree-hooks"
|
|
12
|
+
git config extensions.worktreeConfig true
|
|
13
|
+
git config --worktree core.hooksPath "$hooks"
|
|
14
|
+
exec lefthook install "$@"
|
package/bin/slicc-unit-cover.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { code, ParseError, select } from '../unit/graph.mjs';
|
|
7
7
|
import { inject } from '../unit/inject.mjs';
|
|
8
|
+
import { inSources } from '../unit/sources.mjs';
|
|
8
9
|
|
|
9
10
|
const root = process.cwd();
|
|
10
11
|
const say = (line) => process.stderr.write(`slicc-unit-cover: ${line}\n`);
|
|
@@ -47,10 +48,20 @@ function selection(staged) {
|
|
|
47
48
|
const staged = (git('diff', '--cached', '--name-only', '--relative', '--no-renames', '-z') ?? '')
|
|
48
49
|
.split('\0')
|
|
49
50
|
.filter(Boolean);
|
|
50
|
-
if (
|
|
51
|
+
if (
|
|
52
|
+
process.env.SLICC_UNIT_ALL !== '1' &&
|
|
53
|
+
!staged.some((file) => code.test(file) && inSources(file, root))
|
|
54
|
+
) {
|
|
51
55
|
say('no code staged, skipping unit tests and diff coverage');
|
|
52
56
|
verdict(true, 'no code staged');
|
|
53
57
|
}
|
|
58
|
+
const measured = staged.filter(
|
|
59
|
+
(file) => code.test(file) && inSources(file, root) && existsSync(join(root, file))
|
|
60
|
+
);
|
|
61
|
+
const jsx = measured.filter((file) => /x$/.test(file));
|
|
62
|
+
if (jsx.length > 0) {
|
|
63
|
+
verdict(false, `coverage cannot be measured for JSX, which is not transformed: ${jsx.join(' ')}`);
|
|
64
|
+
}
|
|
54
65
|
|
|
55
66
|
const size = Number(process.env.SLICC_UNIT_BATCH ?? 60);
|
|
56
67
|
const tests = selection(staged);
|
|
@@ -82,6 +93,18 @@ const cover = existsSync(local)
|
|
|
82
93
|
: fileURLToPath(new URL('slicc-diff-cover.sh', import.meta.url));
|
|
83
94
|
const files = tests === undefined ? 'every unit test file' : `${tests.length} unit test files`;
|
|
84
95
|
const counted = `${batches.length} ${batches.length === 1 ? 'batch' : 'batches'}`;
|
|
96
|
+
const lcov = (reports.length > 0 ? reports : [join('coverage', 'unit', 'lcov.info')])
|
|
97
|
+
.map((report) => {
|
|
98
|
+
try {
|
|
99
|
+
return readFileSync(join(root, report), 'utf8');
|
|
100
|
+
} catch {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
.join('\n');
|
|
105
|
+
const seen = new Set(lcov.match(/^SF:.*$/gm)?.map((line) => line.slice(3)) ?? []);
|
|
106
|
+
const missing = measured.filter((file) => !seen.has(file));
|
|
107
|
+
if (missing.length > 0) verdict(false, `no coverage was collected for ${missing.join(' ')}`);
|
|
85
108
|
const covered = run(cover, reports, process.env);
|
|
86
109
|
if (covered !== 0) verdict(false, `diff coverage is not 100% (${files} in ${counted})`);
|
|
87
110
|
verdict(true, `${files} in ${counted}, diff coverage 100%`);
|
package/lefthook.yml
CHANGED
package/mcr.config.mjs
CHANGED
|
@@ -2,21 +2,22 @@ import { stripTypeScriptTypes } from 'node:module';
|
|
|
2
2
|
import { relative, sep } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { inject } from './unit/inject.mjs';
|
|
5
|
+
import { inSources, unitSources } from './unit/sources.mjs';
|
|
5
6
|
|
|
6
7
|
if (process.env.SLICC_UNIT_TESTS !== undefined) process.env.NODE_OPTIONS = inject();
|
|
7
8
|
|
|
9
|
+
const code = /\.(m|c)?(j|t)s$/;
|
|
10
|
+
const typed = /\.(m|c)?ts$/;
|
|
11
|
+
|
|
8
12
|
const strip = (entry) => {
|
|
9
|
-
if (entry.url
|
|
13
|
+
if (typed.test(entry.url)) entry.source = stripTypeScriptTypes(entry.source);
|
|
10
14
|
};
|
|
11
15
|
|
|
12
|
-
const
|
|
16
|
+
const listed = unitSources();
|
|
13
17
|
|
|
14
|
-
const source = (file) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
parts[0] !== '..' && parts.includes('src') && !parts.includes('node_modules') && code.test(file)
|
|
18
|
-
);
|
|
19
|
-
};
|
|
18
|
+
const source = (file) =>
|
|
19
|
+
code.test(file) &&
|
|
20
|
+
inSources(relative(process.cwd(), file).split(sep).join('/'), process.cwd(), listed);
|
|
20
21
|
|
|
21
22
|
const ours = (url) => url.startsWith('file:') && source(fileURLToPath(url));
|
|
22
23
|
|
|
@@ -24,7 +25,7 @@ export default {
|
|
|
24
25
|
name: process.env.npm_package_name ?? 'unit',
|
|
25
26
|
outputDir: process.env.SLICC_UNIT_COVERAGE_DIR ?? 'coverage/unit',
|
|
26
27
|
reports: ['lcovonly', 'console-details'],
|
|
27
|
-
all: { dir: 'src', filter: source, transformer: strip },
|
|
28
|
+
all: { dir: listed ?? 'src', filter: source, transformer: strip },
|
|
28
29
|
entryFilter: (entry) => ours(entry.url),
|
|
29
30
|
onEntry: strip,
|
|
30
31
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.4",
|
|
4
4
|
"description": "Shared Renovate, Biome, TypeScript, lefthook and GitHub Actions configuration, plus the CDP integration-test harness, for SLICC's web repos",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"bin": {
|
|
35
35
|
"slicc-agents-md": "bin/slicc-agents-md.sh",
|
|
36
36
|
"slicc-diff-cover": "bin/slicc-diff-cover.sh",
|
|
37
|
+
"slicc-install-hooks": "bin/slicc-install-hooks.sh",
|
|
37
38
|
"slicc-lint": "bin/slicc-lint.sh",
|
|
38
39
|
"slicc-lint-comments": "bin/slicc-lint-comments.sh",
|
|
39
40
|
"slicc-memory-peak": "bin/slicc-memory-peak.sh",
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
"unit"
|
|
54
55
|
],
|
|
55
56
|
"scripts": {
|
|
57
|
+
"prepare": "bin/slicc-install-hooks.sh",
|
|
56
58
|
"lint": "bin/slicc-lint.sh && shellcheck bin/*.sh",
|
|
57
59
|
"pretest": "playwright-core install --no-shell chromium",
|
|
58
60
|
"test": "SLICC_PROFILE=1 node --test --test-global-setup=harness/global.mjs test/integration/*.test.mjs && node test/integration/verify.mjs",
|
|
@@ -64,6 +66,7 @@
|
|
|
64
66
|
"devDependencies": {
|
|
65
67
|
"@ai-ecoverse/slicc-browsers": "1.11.0",
|
|
66
68
|
"@biomejs/biome": "2.5.15",
|
|
69
|
+
"lefthook": "2.2.2",
|
|
67
70
|
"monocart-coverage-reports": "2.13.2",
|
|
68
71
|
"playwright-core": "1.64.0",
|
|
69
72
|
"pnpm": "12.13.0",
|
package/unit/sources.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function unitSources(root = process.cwd()) {
|
|
5
|
+
let pkg;
|
|
6
|
+
try {
|
|
7
|
+
pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const list = pkg?.slicc?.unitSources;
|
|
12
|
+
if (list === undefined) return null;
|
|
13
|
+
if (
|
|
14
|
+
!Array.isArray(list) ||
|
|
15
|
+
!list.length ||
|
|
16
|
+
!list.every(
|
|
17
|
+
(d) =>
|
|
18
|
+
typeof d === 'string' &&
|
|
19
|
+
/^[\w.-]+(\/[\w.-]+)*$/.test(d) &&
|
|
20
|
+
d.split('/').every((p) => p !== '.' && p !== '..')
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
throw new Error(
|
|
24
|
+
`package.json slicc.unitSources must be a list of repo-relative directories, not ${JSON.stringify(list)}`
|
|
25
|
+
);
|
|
26
|
+
return list;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function inSources(file, root = process.cwd(), list = unitSources(root)) {
|
|
30
|
+
const parts = relative(root, join(root, file)).split(sep);
|
|
31
|
+
if (parts[0] === '..' || parts.includes('node_modules')) return false;
|
|
32
|
+
if (!list) return parts.includes('src');
|
|
33
|
+
return list.some((dir) => {
|
|
34
|
+
const want = dir.split('/');
|
|
35
|
+
return want.every((p, i) => parts[i] === p) && parts.length > want.length;
|
|
36
|
+
});
|
|
37
|
+
}
|