@sssb/tools 0.0.0 → 0.3.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/LICENSE +21 -0
- package/bin/sssb.js +116 -0
- package/package.json +89 -5
- package/src/app-port.js +77 -0
- package/src/app.js +142 -0
- package/src/assembly-checks.d.ts +57 -0
- package/src/assembly-checks.js +259 -0
- package/src/commands/add-app.js +344 -0
- package/src/commands/check-demo-size.js +80 -0
- package/src/commands/check-doc-paths.js +48 -0
- package/src/commands/check-e2e.js +611 -0
- package/src/commands/check-fences.js +51 -0
- package/src/commands/check-real-env.js +165 -0
- package/src/commands/check-tmpdir-leak.js +78 -0
- package/src/commands/ci.js +350 -0
- package/src/commands/dev-tick.js +25 -0
- package/src/commands/doctor-checks.js +1396 -0
- package/src/commands/doctor-settings.js +583 -0
- package/src/commands/doctor-vitest.js +262 -0
- package/src/commands/doctor.js +1033 -0
- package/src/commands/e2e-profile.js +94 -0
- package/src/commands/guide.js +108 -0
- package/src/commands/launch-json.js +55 -0
- package/src/commands/pin.js +411 -0
- package/src/commands/port.js +22 -0
- package/src/commands/remove-items.js +191 -0
- package/src/commands/serve-standalone.js +78 -0
- package/src/commands/tick.js +27 -0
- package/src/doc-paths.d.ts +106 -0
- package/src/doc-paths.js +328 -0
- package/src/framework-guard.js +35 -0
- package/src/kit.d.ts +49 -0
- package/src/kit.js +216 -0
- package/src/next.d.ts +16 -0
- package/src/next.js +55 -0
- package/src/ports.d.ts +72 -0
- package/src/ports.js +307 -0
- package/src/prune-mantine-css.js +171 -0
- package/src/remove-items/code.patch +798 -0
- package/src/remove-items/database.patch +218 -0
- package/src/remove-items/exact-patch.js +122 -0
- package/src/testing/tmp-dir-marker.js +9 -0
- package/src/testing/tmp-dir-setup.d.ts +2 -0
- package/src/testing/tmp-dir-setup.js +9 -0
- package/src/testing/tmp-dir.d.ts +20 -0
- package/src/testing/tmp-dir.js +174 -0
- package/src/tick/dev-tick.js +128 -0
- package/src/tick/tick.js +317 -0
- package/src/tick/ticker-marker.d.ts +17 -0
- package/src/tick/ticker-marker.js +83 -0
- package/src/tick/ticker.d.ts +36 -0
- package/src/tick/ticker.js +142 -0
- package/src/vite.d.ts +38 -0
- package/src/vite.js +64 -0
- package/src/vitest.d.ts +38 -0
- package/src/vitest.js +82 -0
- package/tsconfig.base.json +33 -0
- package/README.md +0 -3
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The dev ticker: one object that owns start, stop, the interval and whether it is running.
|
|
3
|
+
//
|
|
4
|
+
// It has two users, each with its own policy: `sssb dev-tick` (dev-tick.js) (`DEV_TICK_SECONDS=30 pnpm dev`, `resolveDevTick`)
|
|
5
|
+
// and the showcase Simulator's control (`apps/showcase/src/app/api/simulator/ticker/dev-ticker.ts`), which runs it inside
|
|
6
|
+
// the dev server. It is a module of its own, with no reading of the environment and no process wiring, so that both can;
|
|
7
|
+
// each caller owns the policy that keeps the ticker off by default and out of e2e and the static demo.
|
|
8
|
+
//
|
|
9
|
+
// A tick is `tickOnce` (tick.js): an HTTP client of the route `pnpm tick` calls, with the same dev secret.
|
|
10
|
+
import { removeTickerMarker, writeTickerMarker } from './ticker-marker.js'
|
|
11
|
+
import { summarizeTick, tickDidWork, tickOnce } from './tick.js'
|
|
12
|
+
|
|
13
|
+
/** A tick is a few queries; under a second is a typo for a unit. Over a day is a typo for another unit, and far below the ~24.8 days (2^31 ms) where `setTimeout` overflows and the loop would spin. */
|
|
14
|
+
export const MIN_INTERVAL_SECONDS = 1
|
|
15
|
+
export const MAX_INTERVAL_SECONDS = 86_400
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {unknown} seconds
|
|
19
|
+
* @returns {string | null} what is wrong with it, or null
|
|
20
|
+
*/
|
|
21
|
+
export function intervalProblem(seconds) {
|
|
22
|
+
if (
|
|
23
|
+
typeof seconds !== 'number' ||
|
|
24
|
+
!Number.isInteger(seconds) ||
|
|
25
|
+
seconds < MIN_INTERVAL_SECONDS ||
|
|
26
|
+
seconds > MAX_INTERVAL_SECONDS
|
|
27
|
+
) {
|
|
28
|
+
return `a whole number of seconds from ${MIN_INTERVAL_SECONDS} to ${MAX_INTERVAL_SECONDS}`
|
|
29
|
+
}
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {number} ms
|
|
35
|
+
* @param {AbortSignal} signal
|
|
36
|
+
*/
|
|
37
|
+
export function abortableSleep(ms, signal) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
const timer = setTimeout(done, ms)
|
|
40
|
+
signal.addEventListener('abort', done, { once: true })
|
|
41
|
+
function done() {
|
|
42
|
+
clearTimeout(timer)
|
|
43
|
+
signal.removeEventListener('abort', done)
|
|
44
|
+
resolve(undefined)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {{ running: boolean, seconds: number | null, ticks: number, lastTickAt: string | null, lastError: string | null }} TickerStatus
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {{
|
|
55
|
+
* origin: string,
|
|
56
|
+
* markerFile?: string,
|
|
57
|
+
* tick?: typeof tickOnce,
|
|
58
|
+
* log?: (line: string) => void,
|
|
59
|
+
* sleep?: (ms: number, signal: AbortSignal) => Promise<void>,
|
|
60
|
+
* now?: () => Date,
|
|
61
|
+
* }} options `markerFile`: where a live ticker is recorded (ticker-marker.js); none, none written.
|
|
62
|
+
*/
|
|
63
|
+
export function createTicker({
|
|
64
|
+
origin,
|
|
65
|
+
markerFile,
|
|
66
|
+
tick = tickOnce,
|
|
67
|
+
log = console.log,
|
|
68
|
+
sleep = abortableSleep,
|
|
69
|
+
now = () => new Date(),
|
|
70
|
+
}) {
|
|
71
|
+
/** @type {AbortController | null} */
|
|
72
|
+
let controller = null
|
|
73
|
+
/** @type {Promise<void>} */
|
|
74
|
+
let loop = Promise.resolve()
|
|
75
|
+
/** @type {TickerStatus} */
|
|
76
|
+
let state = { running: false, seconds: null, ticks: 0, lastTickAt: null, lastError: null }
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Ticks every `seconds` until `signal` aborts. One tick at a time (the next is timed from the end of the last, so a
|
|
80
|
+
* slow tick never overlaps itself), speaking only when something ran or when the state changed: a dev server that is
|
|
81
|
+
* still compiling is "not up yet", said once, not an error every interval.
|
|
82
|
+
*
|
|
83
|
+
* @param {number} seconds
|
|
84
|
+
* @param {AbortSignal} signal
|
|
85
|
+
*/
|
|
86
|
+
async function run(seconds, signal) {
|
|
87
|
+
/** @type {string | null} */
|
|
88
|
+
let previousError = null
|
|
89
|
+
while (!signal.aborted) {
|
|
90
|
+
await sleep(seconds * 1000, signal)
|
|
91
|
+
if (signal.aborted) return
|
|
92
|
+
try {
|
|
93
|
+
const body = await tick({ origin, timeoutMs: Math.max(seconds * 1000, 30_000), signal })
|
|
94
|
+
state = { ...state, ticks: state.ticks + 1, lastTickAt: now().toISOString(), lastError: null }
|
|
95
|
+
if (previousError !== null) log('[tick] ok again')
|
|
96
|
+
previousError = null
|
|
97
|
+
if (tickDidWork(body)) log(`[tick] ${summarizeTick(body)}`)
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (signal.aborted) return
|
|
100
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
101
|
+
state = { ...state, lastError: message }
|
|
102
|
+
if (message !== previousError) log(`[tick] ${message} (will keep trying every ${seconds}s)`)
|
|
103
|
+
previousError = message
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
/**
|
|
110
|
+
* Starts ticking, or does nothing if it already is (an interval change is a `stop()` then a `start()`).
|
|
111
|
+
*
|
|
112
|
+
* @param {number} seconds
|
|
113
|
+
* @returns {TickerStatus}
|
|
114
|
+
*/
|
|
115
|
+
start(seconds) {
|
|
116
|
+
const problem = intervalProblem(seconds)
|
|
117
|
+
if (problem) throw new RangeError(`the ticker interval must be ${problem}, got ${String(seconds)}`)
|
|
118
|
+
if (controller) return { ...state }
|
|
119
|
+
controller = new AbortController()
|
|
120
|
+
state = { running: true, seconds, ticks: 0, lastTickAt: null, lastError: null }
|
|
121
|
+
if (markerFile) writeTickerMarker(markerFile, seconds)
|
|
122
|
+
loop = run(seconds, controller.signal)
|
|
123
|
+
return { ...state }
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
/** Stops it, cancels a tick in flight, and resolves once the loop has ended. Safe to call when not running. */
|
|
127
|
+
async stop() {
|
|
128
|
+
const stopping = controller
|
|
129
|
+
controller = null
|
|
130
|
+
if (!stopping) return
|
|
131
|
+
stopping.abort()
|
|
132
|
+
if (markerFile) removeTickerMarker(markerFile)
|
|
133
|
+
state = { ...state, running: false }
|
|
134
|
+
await loop
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
/** @returns {TickerStatus} */
|
|
138
|
+
status() {
|
|
139
|
+
return { ...state }
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/vite.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CSSOptions, Plugin, PluginOption, UserConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
export interface StaticDemoOptions {
|
|
4
|
+
/** The app's directory (`__dirname` in its vite.demo.config.ts). */
|
|
5
|
+
appDir: string
|
|
6
|
+
/** Aliases beside the preset's `@sssb/app-config` and `@`: a workspace package the demo reaches by source. */
|
|
7
|
+
alias?: Record<string, string>
|
|
8
|
+
/** Plugins of the app's own, placed after React's and before the pruning and the single-file inlining. */
|
|
9
|
+
plugins?: PluginOption[]
|
|
10
|
+
/** Vite's `css` options (an app with its own PostCSS pipeline points `css.postcss` at its directory). */
|
|
11
|
+
css?: CSSOptions
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The static demo's whole Vite config: single-file, file://-safe, pruned, with the app's seam passed explicitly. */
|
|
15
|
+
export declare function staticDemoConfig(options: StaticDemoOptions): Promise<UserConfig>
|
|
16
|
+
|
|
17
|
+
export interface PruneResult {
|
|
18
|
+
css: string
|
|
19
|
+
/** Rules removed because a hashed class they need ships nowhere. */
|
|
20
|
+
removedRules: number
|
|
21
|
+
/** Rules left, counting every one nested in an at-rule. */
|
|
22
|
+
keptRules: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The hashed Mantine classes a selector REQUIRES: those written outside every `(...)` and `[...]`. `.m_a .m_b > i`
|
|
27
|
+
* yields both; `.m_a:not(.m_b)` yields only `m_a`; `[data-x='.m_c']` yields none.
|
|
28
|
+
*/
|
|
29
|
+
export declare function requiredHashedClasses(selector: string): string[]
|
|
30
|
+
|
|
31
|
+
/** The hashed class names written in `shipped`: the JavaScript and HTML the stylesheet is shipped with. */
|
|
32
|
+
export declare function shippedHashedClasses(shipped: string): Set<string>
|
|
33
|
+
|
|
34
|
+
/** Removes every rule of `css` that needs a hashed class not in `shipped`. Pure; throws on CSS postcss cannot parse. */
|
|
35
|
+
export declare function pruneUnreachableRules(css: string, shipped: ReadonlySet<string>): PruneResult
|
|
36
|
+
|
|
37
|
+
/** The Vite plugin that prunes the demo's stylesheet against what the demo ships. `staticDemoConfig` includes it. */
|
|
38
|
+
export declare function pruneMantineCss(): Plugin
|
package/src/vite.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// THE VITE PRESET for an app's single-file static demo (ADR-0014 parts 3 and 6), and the Mantine CSS pruning it
|
|
3
|
+
// carries.
|
|
4
|
+
//
|
|
5
|
+
// // apps/<app>/vite.demo.config.ts
|
|
6
|
+
// import { staticDemoConfig } from '@sssb/tools/vite'
|
|
7
|
+
// export default staticDemoConfig({ appDir: __dirname })
|
|
8
|
+
//
|
|
9
|
+
// It builds the hash-routed demo shell (`src/demo-static`) that runs from file://, ALWAYS as one file: Chrome blocks
|
|
10
|
+
// external `type="module"` scripts on the file:// origin (CORS), but inline module scripts run, so everything is
|
|
11
|
+
// inlined into one index.html, which is also one shareable file.
|
|
12
|
+
//
|
|
13
|
+
// THE SEAM IS PASSED EXPLICITLY: `@sssb/app-config` is aliased to the app's own `src/app-config`, as every SSSB
|
|
14
|
+
// builder passes it (ADR-0014 part 1). In an adopter's app that is the same directory pnpm links, so it changes
|
|
15
|
+
// nothing; in SSSB's own repository, where the seam is not linked, it is the only thing that makes the framework
|
|
16
|
+
// resolve against this app's registrations rather than another's. `@` is the app's own `src`. The framework itself
|
|
17
|
+
// resolves as a package, through its `exports` map.
|
|
18
|
+
//
|
|
19
|
+
// A guard plugin (framework-guard.js) fails the build if any module it
|
|
20
|
+
// loads is framework source from an instance other than the app's own.
|
|
21
|
+
//
|
|
22
|
+
// Vite loads this file with Node, which is why it is JavaScript (part 2), and the Vite plugins it configures are
|
|
23
|
+
// the app's own copies, loaded from the app's directory, so the preset never brings a second Vite of its own.
|
|
24
|
+
import path from 'node:path'
|
|
25
|
+
import { frameworkGuard } from './framework-guard.js'
|
|
26
|
+
import { importFromApp } from './kit.js'
|
|
27
|
+
import { pruneMantineCss } from './prune-mantine-css.js'
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
pruneMantineCss,
|
|
31
|
+
pruneUnreachableRules,
|
|
32
|
+
requiredHashedClasses,
|
|
33
|
+
shippedHashedClasses,
|
|
34
|
+
} from './prune-mantine-css.js'
|
|
35
|
+
|
|
36
|
+
/** @type {import('./vite.d.ts').staticDemoConfig} */
|
|
37
|
+
export async function staticDemoConfig({ appDir, alias = {}, plugins = [], css }) {
|
|
38
|
+
const root = path.resolve(appDir)
|
|
39
|
+
const reactPlugin = await importFromApp(root, '@vitejs/plugin-react', "the static demo's React transform needs")
|
|
40
|
+
const singleFile = await importFromApp(root, 'vite-plugin-singlefile', 'the single-file static demo needs')
|
|
41
|
+
const react = /** @type {() => import('vite').PluginOption} */ (reactPlugin['default'])
|
|
42
|
+
const viteSingleFile = /** @type {() => import('vite').PluginOption} */ (
|
|
43
|
+
singleFile['viteSingleFile'] ?? /** @type {Record<string, unknown>} */ (singleFile['default'])['viteSingleFile']
|
|
44
|
+
)
|
|
45
|
+
return {
|
|
46
|
+
root: path.join(root, 'src', 'demo-static'),
|
|
47
|
+
base: './',
|
|
48
|
+
// The pruning runs before vite-plugin-singlefile, the other `post` plugin, so the inlined stylesheet is the
|
|
49
|
+
// pruned one (prune-mantine-css.js says why the order is load-bearing).
|
|
50
|
+
plugins: [frameworkGuard(root), react(), ...plugins, pruneMantineCss(), viteSingleFile()],
|
|
51
|
+
...(css === undefined ? {} : { css }),
|
|
52
|
+
resolve: {
|
|
53
|
+
alias: {
|
|
54
|
+
'@sssb/app-config': path.join(root, 'src', 'app-config'),
|
|
55
|
+
'@': path.join(root, 'src'),
|
|
56
|
+
...alias,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
build: {
|
|
60
|
+
outDir: path.join(root, 'dist-demo'),
|
|
61
|
+
emptyOutDir: true,
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/vitest.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TestProjectInlineConfiguration } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export interface AppTestProjectOptions {
|
|
4
|
+
/** The app's directory, absolute or relative to the working directory. */
|
|
5
|
+
appDir: string
|
|
6
|
+
/** The project's name. Defaults to the app directory's name. */
|
|
7
|
+
name?: string
|
|
8
|
+
/** Test globs beside `src/**\/*.test.{ts,tsx}`, relative to the app. */
|
|
9
|
+
include?: string[]
|
|
10
|
+
/** Aliases beside the preset's `@sssb/app-config` and `@`. */
|
|
11
|
+
alias?: Record<string, string>
|
|
12
|
+
/** Environment variables for the project's tests. */
|
|
13
|
+
env?: Record<string, string>
|
|
14
|
+
/** Setup files run after jest-dom's matchers are installed. */
|
|
15
|
+
setupFiles?: string[]
|
|
16
|
+
/** Per-test timeout; defaults to 20s (the first test cold-migrates pglite). */
|
|
17
|
+
testTimeout?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** One app's Vitest project: rooted at the app, happy-dom, jest-dom, and the app's seam passed explicitly. */
|
|
21
|
+
export declare function appTestProject(options: AppTestProjectOptions): Promise<TestProjectInlineConfiguration>
|
|
22
|
+
|
|
23
|
+
export interface WorkspaceAppProjectsOptions {
|
|
24
|
+
/** The workspace root, whose package.json's `sssb.apps` names the apps (else every `apps/<name>` that is a package). */
|
|
25
|
+
root: string
|
|
26
|
+
/** Each app's options beside its directory, given the app's absolute directory. */
|
|
27
|
+
options?: (appDir: string) => Omit<AppTestProjectOptions, 'appDir'>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* One `appTestProject` per app of the workspace, in the order `sssb.apps` names them: the root's Vitest configs read the
|
|
32
|
+
* workspace's one list of apps rather than keeping a copy. Each project is named for its app's directory, or its path
|
|
33
|
+
* from the root with `/` as `-` when two apps' directories share a name (unless `options` names it). Throws when the workspace names
|
|
34
|
+
* no app.
|
|
35
|
+
*/
|
|
36
|
+
export declare function workspaceAppProjects(
|
|
37
|
+
options: WorkspaceAppProjectsOptions,
|
|
38
|
+
): Promise<TestProjectInlineConfiguration[]>
|
package/src/vitest.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// THE VITEST PRESET: one app's test project (ADR-0014 part 3), and one for every app of the workspace.
|
|
3
|
+
//
|
|
4
|
+
// // vitest.config.ts, at the workspace root or in the app
|
|
5
|
+
// import { defineConfig } from 'vitest/config'
|
|
6
|
+
// import { appTestProject } from '@sssb/tools/vitest'
|
|
7
|
+
// export default defineConfig({ test: { projects: [await appTestProject({ appDir: 'apps/console' })] } })
|
|
8
|
+
//
|
|
9
|
+
// // vitest.config.ts, at the workspace root: a project for every app the root's `sssb.apps` names
|
|
10
|
+
// import { workspaceAppProjects } from '@sssb/tools/vitest'
|
|
11
|
+
// export default defineConfig(async () => ({ test: { projects: await workspaceAppProjects({ root: '.' }) } }))
|
|
12
|
+
//
|
|
13
|
+
// One project per app, because the seam is a bare specifier: whatever resolves `@sssb/app-config` can name only one
|
|
14
|
+
// app (ADR-0012's reason for a project per app). The project's root is the app, its tests are the app's colocated
|
|
15
|
+
// `src/**/*.test.{ts,tsx}`, it runs in happy-dom with jest-dom's matchers, and, as every SSSB builder does, it passes
|
|
16
|
+
// the seam explicitly (`@sssb/app-config` to the app's `src/app-config`), beside the app's own `@` alias. The React
|
|
17
|
+
// plugin and jest-dom are the app's own copies, loaded from the app's directory.
|
|
18
|
+
// A guard plugin (framework-guard.js) fails a test file that loads framework source from any instance but the app's.
|
|
19
|
+
import path from 'node:path'
|
|
20
|
+
import { appLabels, workspaceApps } from './app.js'
|
|
21
|
+
import { frameworkGuard } from './framework-guard.js'
|
|
22
|
+
import { importFromApp, resolveFromApp } from './kit.js'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The first test to touch the fake database cold-migrates and seeds pglite in-process; under full-suite parallel
|
|
26
|
+
* load that can exceed Vitest's 5s default and flake a unit run (which, unlike e2e, has no retry). 20s gives
|
|
27
|
+
* generous headroom without masking a hung test.
|
|
28
|
+
*/
|
|
29
|
+
const TEST_TIMEOUT_MS = 20_000
|
|
30
|
+
|
|
31
|
+
/** @type {import('./vitest.d.ts').appTestProject} */
|
|
32
|
+
export async function appTestProject({ appDir, name, include = [], alias = {}, env, setupFiles = [], testTimeout }) {
|
|
33
|
+
const root = path.resolve(appDir)
|
|
34
|
+
const reactPlugin = await importFromApp(root, '@vitejs/plugin-react', "the app's component tests need")
|
|
35
|
+
const react = /** @type {() => import('vite').PluginOption} */ (reactPlugin['default'])
|
|
36
|
+
// Checked here for a clear error, but handed to Vitest as the bare specifier: Vitest resolves a setup file from
|
|
37
|
+
// the project's root (the app) with the `import` condition, and gets jest-dom's ES module. Resolved here instead,
|
|
38
|
+
// through Node's `require` conditions, it would be the CommonJS build, which cannot load Vitest.
|
|
39
|
+
resolveFromApp(root, '@testing-library/jest-dom/vitest', "the app's DOM assertions need")
|
|
40
|
+
return {
|
|
41
|
+
plugins: [frameworkGuard(root), react()],
|
|
42
|
+
resolve: {
|
|
43
|
+
alias: {
|
|
44
|
+
'@sssb/app-config': path.join(root, 'src', 'app-config'),
|
|
45
|
+
'@': path.join(root, 'src'),
|
|
46
|
+
...alias,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
test: {
|
|
50
|
+
name: name ?? path.basename(root),
|
|
51
|
+
root,
|
|
52
|
+
environment: 'happy-dom',
|
|
53
|
+
include: ['src/**/*.test.{ts,tsx}', ...include],
|
|
54
|
+
// The scratch-directory helper's per-file cleanup, which `isolate: false` needs (./testing/tmp-dir-setup.js).
|
|
55
|
+
setupFiles: ['@testing-library/jest-dom/vitest', '@sssb/tools/testing/tmp-dir-setup', ...setupFiles],
|
|
56
|
+
testTimeout: testTimeout ?? TEST_TIMEOUT_MS,
|
|
57
|
+
...(env === undefined ? {} : { env }),
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @type {import('./vitest.d.ts').workspaceAppProjects} */
|
|
63
|
+
export async function workspaceAppProjects({ root, options = () => ({}) }) {
|
|
64
|
+
const workspace = path.resolve(root)
|
|
65
|
+
// The one list of the workspace's apps, as `sssb doctor`, `sssb ci` and `sssb launch-json` read it: the root
|
|
66
|
+
// package.json's `sssb.apps`, else every apps/<name> that is a package.
|
|
67
|
+
const apps = workspaceApps(workspace)
|
|
68
|
+
if (apps.length === 0) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`@sssb/tools/vitest: ${workspace} names no app (\`sssb.apps\` in its package.json, or apps/<name>): nothing to test`,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
// Each project named as `sssb ci` and `launch-json` name the app (its directory's name, or its path when two apps
|
|
74
|
+
// share one): Vitest refuses two projects of one name, and `apps/web` beside `services/web` is a valid list.
|
|
75
|
+
const labels = appLabels(workspace, apps)
|
|
76
|
+
return Promise.all(
|
|
77
|
+
apps.map((app) => {
|
|
78
|
+
const appDir = path.join(workspace, app)
|
|
79
|
+
return appTestProject({ name: labels.get(app), ...options(appDir), appDir })
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
// THE TSCONFIG BASE an SSSB app extends (ADR-0014 part 2): `"extends": "@sssb/tools/tsconfig.base.json"`, then the
|
|
3
|
+
// app's own `paths` (its `@/*`) and `include`. It carries THE FRAMEWORK'S COMPILER CONTRACT. @sssb/kit ships
|
|
4
|
+
// TypeScript source, so the framework's files are compiled under the app's options, and `skipLibCheck` does not
|
|
5
|
+
// cover a `.ts` file. Off any of these, the framework's own files fail to compile, measured over the framework
|
|
6
|
+
// with the strict set off and each option overridden in turn (2026-11-17, SSSB's packages/kit/tsconfig.strict.json
|
|
7
|
+
// records the numbers): `strict: true` (105 errors with it off), `moduleResolution: "bundler"` (`nodenext` 1479),
|
|
8
|
+
// `jsx: "react-jsx"` (`react` 675, unset 749), `dom` in `lib` for the components (94 without it), and `skipLibCheck:
|
|
9
|
+
// true` (22 errors without it, all in dependencies' declarations).
|
|
10
|
+
//
|
|
11
|
+
// `lib` and `target` sit at the floor the framework promises to compile at, ES2022: its source uses
|
|
12
|
+
// `Object.hasOwn`, `.at()` and Error's `cause`. An app may raise them; lowering them breaks the framework.
|
|
13
|
+
//
|
|
14
|
+
// Beyond this base the framework also compiles with every flag of the strict set on (noUncheckedIndexedAccess,
|
|
15
|
+
// exactOptionalPropertyTypes, noPropertyAccessFromIndexSignature, erasableSyntaxOnly, noUnusedLocals,
|
|
16
|
+
// noUnusedParameters, noImplicitReturns, noImplicitOverride, noFallthroughCasesInSwitch), so an app may turn any
|
|
17
|
+
// of them on. They are not set here: that is the app's choice.
|
|
18
|
+
"compilerOptions": {
|
|
19
|
+
"target": "ES2022",
|
|
20
|
+
"lib": ["dom", "dom.iterable", "es2022"],
|
|
21
|
+
"module": "esnext",
|
|
22
|
+
"moduleResolution": "bundler",
|
|
23
|
+
"jsx": "react-jsx",
|
|
24
|
+
"strict": true,
|
|
25
|
+
"skipLibCheck": true,
|
|
26
|
+
"allowJs": true,
|
|
27
|
+
"noEmit": true,
|
|
28
|
+
"esModuleInterop": true,
|
|
29
|
+
"resolveJsonModule": true,
|
|
30
|
+
"isolatedModules": true,
|
|
31
|
+
"plugins": [{ "name": "next" }]
|
|
32
|
+
}
|
|
33
|
+
}
|
package/README.md
DELETED