@rexezuge/tooling 1.1.0 → 1.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/README.md +66 -10
- package/dist/eslint-boundaries.d.ts +19 -3
- package/dist/eslint-boundaries.d.ts.map +1 -1
- package/dist/eslint-boundaries.js +89 -3
- package/dist/eslint-boundaries.js.map +1 -1
- package/dist/eslint.d.ts +12 -7
- package/dist/eslint.d.ts.map +1 -1
- package/dist/eslint.js +13 -8
- package/dist/eslint.js.map +1 -1
- package/dist/index.d.ts +20 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/scripts/backup/d1-target.js +1 -1
- package/dist/scripts/backup/d1-target.js.map +1 -1
- package/dist/scripts/backup/encrypt-backup.js +2 -2
- package/dist/scripts/backup/encrypt-backup.js.map +1 -1
- package/dist/scripts/check-god-files.js +2 -2
- package/dist/scripts/check-god-files.js.map +1 -1
- package/dist/scripts/ensure-spa-shell-stub.js +1 -1
- package/dist/scripts/ensure-spa-shell-stub.js.map +1 -1
- package/dist/scripts/init-secrets.d.ts +1 -1
- package/dist/scripts/init-secrets.d.ts.map +1 -1
- package/dist/scripts/init-secrets.js +3 -3
- package/dist/scripts/init-secrets.js.map +1 -1
- package/dist/scripts/migrations-lock.js +1 -1
- package/dist/scripts/migrations-lock.js.map +1 -1
- package/dist/scripts/prepare-wrangler-config.js +3 -3
- package/dist/scripts/prepare-wrangler-config.js.map +1 -1
- package/dist/scripts/verify-spa-shell.js +1 -1
- package/dist/scripts/verify-spa-shell.js.map +1 -1
- package/dist/scripts/wrangler-config/patches.d.ts +1 -1
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/patches.js +1 -1
- package/dist/scripts/wrangler-config/patches.js.map +1 -1
- package/dist/scripts/wrangler-config/resources.d.ts +1 -1
- package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/resources.js +4 -4
- package/dist/scripts/wrangler-config/resources.js.map +1 -1
- package/dist/vitest-aliases.d.ts +90 -0
- package/dist/vitest-aliases.d.ts.map +1 -0
- package/dist/vitest-aliases.js +81 -0
- package/dist/vitest-aliases.js.map +1 -0
- package/dist/vitest-integration.d.ts +96 -0
- package/dist/vitest-integration.d.ts.map +1 -0
- package/dist/vitest-integration.js +64 -0
- package/dist/vitest-integration.js.map +1 -0
- package/dist/vitest-repo.d.ts +154 -0
- package/dist/vitest-repo.d.ts.map +1 -0
- package/dist/vitest-repo.js +146 -0
- package/dist/vitest-repo.js.map +1 -0
- package/dist/vitest-web.d.ts +76 -19
- package/dist/vitest-web.d.ts.map +1 -1
- package/dist/vitest-web.js +62 -25
- package/dist/vitest-web.js.map +1 -1
- package/dist/vitest.d.ts +70 -19
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +42 -37
- package/dist/vitest.js.map +1 -1
- package/package.json +8 -2
- package/src/eslint-boundaries.ts +99 -6
- package/src/eslint.test.ts +22 -1
- package/src/eslint.ts +14 -9
- package/src/functions/pages-proxy.test.ts +2 -2
- package/src/index.ts +23 -14
- package/src/scripts/backup/backup-rules.test.ts +3 -3
- package/src/scripts/backup/d1-target.ts +1 -1
- package/src/scripts/backup/encrypt-backup.ts +2 -2
- package/src/scripts/check-god-files.test.ts +1 -1
- package/src/scripts/check-god-files.ts +2 -2
- package/src/scripts/ensure-spa-shell-stub.ts +1 -1
- package/src/scripts/init-secrets.ts +3 -3
- package/src/scripts/migrations-lock.ts +1 -1
- package/src/scripts/prepare-wrangler-config.ts +3 -3
- package/src/scripts/spa-shell.test.ts +1 -1
- package/src/scripts/validate-locales.test.ts +1 -1
- package/src/scripts/verify-migrations.test.ts +1 -1
- package/src/scripts/verify-spa-shell.ts +1 -1
- package/src/scripts/wrangler-config/patches.ts +1 -1
- package/src/scripts/wrangler-config/resources.ts +4 -4
- package/src/test/integration-migrations.test.ts +1 -1
- package/src/vite.test.ts +1 -1
- package/src/vitest-aliases.test.ts +53 -0
- package/src/vitest-aliases.ts +127 -0
- package/src/vitest-factories.test.ts +127 -0
- package/src/vitest-integration.ts +118 -0
- package/src/vitest-repo.ts +269 -0
- package/src/vitest-web.ts +110 -28
- package/src/vitest.ts +96 -47
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAEL,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,EACzB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,GAKrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAQtE,0EAA0E;AAC1E,MAAM,UAAU,OAAO,CAAC,QAAoB;IAC1C,OAAO,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,cAAc,CAAa,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAC;AACtG,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAoB;IACnD,IAAI,QAAQ,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;IACtF,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;Q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,CAAC","sourcesContent":["/**\n * Creating the resources `wrangler.jsonc` names, and writing their real ids over\n * the placeholders.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/resources.ts`.\n *\n * The placeholder rule: a template carries an all-zero id meaning \"resolve me\",\n * and a config carrying one cannot be deployed. So provisioning walks the config,\n * creates what is missing, and patches the id in place. A placeholder with nothing\n * to create it *under* — a KV id with no binding, a D1 id with no name — is\n * refused rather than skipped, because a silently skipped placeholder is a deploy\n * that fails later with no link back to the reason.\n */\n\nimport { writeFileSync } from 'node:fs';\nimport { parse } from 'jsonc-parser';\nimport { parseWranglerTableRows } from '../lib/wrangler-table';\nimport {\n CONFIG_PATH,\n DEFAULT_HEX_ID,\n DEFAULT_KV_NAMESPACE_NAMES,\n DEFAULT_SECRET_STORE_NAME,\n DEFAULT_UUID,\n DEFAULT_WORKER_NAME,\n VECTORIZE_DIMENSIONS,\n type D1Database,\n type KVNamespace,\n type SecretStore,\n type WranglerConfig,\n} from './types';\nimport { parseJsonArray, runWrangler } from './cli';\nimport { readConfig, writeConfig, writeConfigValue } from './patches';\n\n/** What `ensure*` did, so a caller can act on the difference. */\nexport interface Provisioned {\n id: string;\n created: boolean;\n}\n\n/** The id a D1 database is reported under, whichever key the CLI used. */\nexport function getD1Id(database: D1Database): string | undefined {\n return database.uuid ?? database.database_id ?? database.id;\n}\n\nexport function listD1Databases(): D1Database[] {\n return parseJsonArray<D1Database>(runWrangler(['d1', 'list', '--json']), 'wrangler d1 list --json');\n}\n\n/**\n * The D1 database `binding` names, created when it does not exist.\n *\n * Whether it was created is reported, not inferred: a database created moments ago\n * holds no user data, so a backup workflow must refuse to upload its empty dump.\n * The caller cannot re-derive that from the config, because this very function\n * patches the placeholder away before the reader ever runs.\n */\nexport function ensureD1Database(databaseName: string): Provisioned {\n let database = listD1Databases().find((candidate) => candidate.name === databaseName);\n let created = false;\n if (database === undefined) {\n console.log(`Creating D1 database: ${databaseName}`);\n runWrangler(['d1', 'create', databaseName]);\n database = listD1Databases().find((candidate) => candidate.name === databaseName);\n created = true;\n }\n const databaseId = database === undefined ? undefined : getD1Id(database);\n if (databaseId === undefined || databaseId === '') {\n throw new Error(`Unable to discover D1 database ID for ${databaseName}.`);\n }\n return { id: databaseId, created };\n}\n\nexport function listKVNamespaces(): KVNamespace[] {\n return parseJsonArray<KVNamespace>(runWrangler(['kv', 'namespace', 'list']), 'wrangler kv namespace list');\n}\n\n/** The namespace name a binding's namespace is created under. */\nexport function getKVNamespaceName(config: WranglerConfig, binding: string): string {\n return DEFAULT_KV_NAMESPACE_NAMES[binding] ?? `${config.name ?? DEFAULT_WORKER_NAME}-${binding.toLowerCase()}`;\n}\n\nexport function ensureKVNamespace(config: WranglerConfig, binding: string): Provisioned {\n const namespaceName = getKVNamespaceName(config, binding);\n const candidateNames = new Set([namespaceName, `${config.name ?? DEFAULT_WORKER_NAME}-${binding}`, binding]);\n let namespace = listKVNamespaces().find((candidate) => {\n const candidateName = candidate.title ?? candidate.name;\n return candidate.id !== undefined && candidateName !== undefined && candidateNames.has(candidateName);\n });\n let created = false;\n if (namespace === undefined) {\n console.log(`Creating KV namespace: ${namespaceName}`);\n runWrangler(['kv', 'namespace', 'create', namespaceName]);\n namespace = listKVNamespaces().find((candidate) => candidate.id !== undefined && (candidate.title ?? candidate.name) === namespaceName);\n created = true;\n }\n if (namespace?.id === undefined) {\n throw new Error(`Unable to discover KV namespace ID for ${namespaceName}.`);\n }\n return { id: namespace.id, created };\n}\n\n/** The bindings a deployment always needs, whether or not a custom config lists them. */\nexport function getRequiredKvBindings(): string[] {\n return Object.keys(DEFAULT_KV_NAMESPACE_NAMES);\n}\n\n/**\n * Add the always-needed KV bindings a hand-written config left out.\n *\n * A config supplied through `WRANGLER_JSONC` is edited by hand and drifts; without\n * this the worker starts with an unbound `CACHE` and fails on the first read.\n */\nexport function ensureRequiredKvBindings(content: string, config: WranglerConfig): string {\n const existing = new Set((config.kv_namespaces ?? []).map((namespace) => namespace.binding).filter((binding) => binding !== undefined));\n const missing = getRequiredKvBindings().filter((binding) => !existing.has(binding));\n if (missing.length === 0) {\n return content;\n }\n const next = [...(config.kv_namespaces ?? [])];\n for (const binding of missing) {\n console.log(`Adding missing KV namespace binding: ${binding}`);\n next.push({ binding, id: DEFAULT_HEX_ID });\n }\n return writeConfigValue(content, ['kv_namespaces'], next);\n}\n\n/** The stores in a `secrets-store store list` table. */\nexport function parseSecretStoresTable(output: string): SecretStore[] {\n const stores: SecretStore[] = [];\n // Through the shared table parser rather than a second inline split: `wrangler`\n // renders through `cli-table3`, whose cells are separated by U+2502 and are *not*\n // space-aligned, so a parser written for aligned output silently matches nothing\n // — which reads as \"the store does not exist\" and makes provisioning create a\n // duplicate.\n for (const row of parseWranglerTableRows(output)) {\n const name = row[0];\n const id = row[1];\n // Store ids are 32 hex characters; a row without one is a header, a border, or\n // an unrelated column, and is skipped rather than stored with an undefined id.\n if (name !== undefined && id !== undefined && /^[a-f0-9]{32}$/i.test(id)) {\n stores.push({ name, id });\n }\n }\n return stores;\n}\n\nexport function listSecretStores(): SecretStore[] {\n const output = runWrangler(['secrets-store', 'store', 'list', '--remote']);\n try {\n return parseJsonArray<SecretStore>(output, 'wrangler secrets-store store list --remote');\n } catch {\n // The subcommand prints a table rather than JSON on some versions.\n return parseSecretStoresTable(output);\n }\n}\n\nexport function ensureSecretStore(): string {\n const stores = listSecretStores();\n const existing = stores.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? stores[0];\n if (existing !== undefined) {\n return existing.id;\n }\n console.log(`Creating Secrets Store: ${DEFAULT_SECRET_STORE_NAME}`);\n const output = runWrangler(['secrets-store', 'store', 'create', DEFAULT_SECRET_STORE_NAME, '--remote']);\n const createdStoreId = /ID:\\s*([a-f0-9]{32})/i.exec(output)?.[1];\n if (createdStoreId !== undefined) {\n return createdStoreId;\n }\n // The create output did not name the id, so read it back rather than guessing.\n const refreshed = listSecretStores();\n const store = refreshed.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? refreshed[0];\n if (store?.id === undefined) {\n throw new Error(`Unable to discover Secrets Store ID for ${DEFAULT_SECRET_STORE_NAME}.`);\n }\n return store.id;\n}\n\n/** Create a queue when it is absent, reporting whether it had to be created. */\nexport function ensureQueue(queueName: string): boolean {\n try {\n runWrangler(['queues', 'info', queueName]);\n console.log(`Queue ${queueName} already exists.`);\n return false;\n } catch {\n console.log(`Creating queue: ${queueName}`);\n runWrangler(['queues', 'create', queueName]);\n return true;\n }\n}\n\n/**\n * Queue names a deployment needs, in first-seen order.\n *\n * Producers and consumers name the same queue twice — one queue, two roles — and a\n * name appearing in both must be created once. Pure so it is testable without\n * wrangler.\n */\nexport function queueNamesIn(config: WranglerConfig): string[] {\n const names: string[] = [];\n const seen = new Set<string>();\n for (const producer of config.queues?.producers ?? []) {\n if (producer.queue === '' || seen.has(producer.queue)) continue;\n seen.add(producer.queue);\n names.push(producer.queue);\n }\n for (const consumer of config.queues?.consumers ?? []) {\n if (consumer.queue === '' || seen.has(consumer.queue)) continue;\n seen.add(consumer.queue);\n names.push(consumer.queue);\n }\n return names;\n}\n\nexport function ensureVectorizeIndex(indexName: string, dimensions: number): void {\n try {\n runWrangler(['vectorize', 'info', indexName]);\n console.log(`Vectorize index ${indexName} already exists.`);\n } catch {\n console.log(`Creating Vectorize index: ${indexName} with ${dimensions} dimensions`);\n runWrangler(['vectorize', 'create', indexName, `--dimensions=${dimensions}`, '--metric=cosine']);\n }\n}\n\n/** Replace each placeholder D1 `database_id` with a real one. */\nfunction provisionD1Databases(content: string, config: WranglerConfig, created: string[]): string {\n let patched = content;\n for (const [index, database] of config.d1_databases?.entries() ?? []) {\n if (database.database_id !== DEFAULT_UUID) continue;\n if (database.database_name === undefined || database.database_name === '') {\n throw new Error(`D1 database binding ${database.binding ?? index} has a placeholder database_id but no database_name.`);\n }\n const resolved = ensureD1Database(database.database_name);\n if (resolved.created) {\n created.push(`d1:${database.database_name}`);\n }\n console.log(`Using D1 database ${database.database_name}: ${resolved.id}`);\n patched = writeConfigValue(patched, ['d1_databases', index, 'database_id'], resolved.id);\n }\n return patched;\n}\n\n/** Replace each placeholder KV namespace id with a real one. */\nfunction provisionKvNamespaces(content: string, config: WranglerConfig, created: string[]): string {\n let patched = content;\n for (const [index, namespace] of config.kv_namespaces?.entries() ?? []) {\n if (namespace.id !== DEFAULT_HEX_ID) continue;\n if (namespace.binding === undefined || namespace.binding === '') {\n throw new Error(`KV namespace at index ${index} has a placeholder id but no binding.`);\n }\n const resolved = ensureKVNamespace(config, namespace.binding);\n const namespaceName = getKVNamespaceName(config, namespace.binding);\n if (resolved.created) {\n created.push(`kv:${namespaceName}`);\n }\n console.log(`Using KV namespace ${namespaceName}: ${resolved.id}`);\n patched = writeConfigValue(patched, ['kv_namespaces', index, 'id'], resolved.id);\n }\n return patched;\n}\n\n/**\n * Point every placeholder Secrets Store `store_id` at one store, creating it if\n * absent. `existed` is read **before** the create, because whether the store was\n * created is what the caller reports.\n */\nfunction provisionSecretStore(content: string, config: WranglerConfig, created: string[]): string {\n const placeholders = (config.secrets_store_secrets ?? [])\n .map((secret, index) => ({ secret, index }))\n .filter(({ secret }) => secret.store_id === DEFAULT_HEX_ID);\n if (placeholders.length === 0) {\n return content;\n }\n const existed = listSecretStores().some((store) => store.name === DEFAULT_SECRET_STORE_NAME);\n const storeId = ensureSecretStore();\n if (!existed) {\n created.push(`secrets-store:${DEFAULT_SECRET_STORE_NAME}`);\n }\n console.log(`Using Secrets Store: ${storeId}`);\n return placeholders.reduce(\n (patched, { index }) => writeConfigValue(patched, ['secrets_store_secrets', index, 'store_id'], storeId),\n content,\n );\n}\n\n/**\n * Create every resource the config names, and write the real ids over the\n * placeholders.\n *\n * Returns what it had to create, as `<kind>:<name>` — returned rather than logged,\n * because a caller acts on it: the backup workflow refuses to export a D1 database\n * that appears here, since one created moments ago holds no user data and an empty\n * dump uploaded on schedule is a false sense of safety.\n */\nexport function provisionWranglerResources(): string[] {\n const created: string[] = [];\n let { content, config } = readConfig();\n\n content = ensureRequiredKvBindings(content, config);\n config = parse(content) as WranglerConfig;\n\n // Each of the three below re-parses before it patches, because each writes into\n // the config text the previous one produced. They are separate functions because\n // they are separate resources with separate rules, and one loop holding all\n // three would read as a single resource list with the differences hidden in the\n // bodies.\n content = provisionD1Databases(content, config, created);\n config = parse(content) as WranglerConfig;\n\n content = provisionKvNamespaces(content, config, created);\n config = parse(content) as WranglerConfig;\n\n content = provisionSecretStore(content, config, created);\n\n writeConfig(content);\n\n config = parse(content) as WranglerConfig;\n for (const queueName of queueNamesIn(config)) {\n if (ensureQueue(queueName)) {\n created.push(`queue:${queueName}`);\n }\n }\n\n // Vectorize indexes are name-based, so nothing in the file is patched — but the\n // created names are still reported like every other resource, so a deploy log\n // shows what appeared.\n for (const binding of config.vectorize ?? []) {\n ensureVectorizeIndex(binding.index_name, VECTORIZE_DIMENSIONS);\n }\n\n return created;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAEL,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,EACzB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,GAKrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQzE,0EAA0E;AAC1E,MAAM,UAAU,OAAO,CAAC,QAAoB;IAC1C,OAAO,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,cAAc,CAAa,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AE,CAAC;QAC7C,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,gFAAgF;IAChF,8EAA8E;IAC9E,uBAAuB;IACvB,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;QAC7C,oBAAoB,CAAC,OAAO,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * Creating the resources `wrangler.jsonc` names, and writing their real ids over\n * the placeholders.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/resources.ts`.\n *\n * The placeholder rule: a template carries an all-zero id meaning \"resolve me\",\n * and a config carrying one cannot be deployed. So provisioning walks the config,\n * creates what is missing, and patches the id in place. A placeholder with nothing\n * to create it *under* — a KV id with no binding, a D1 id with no name — is\n * refused rather than skipped, because a silently skipped placeholder is a deploy\n * that fails later with no link back to the reason.\n */\n\nimport { writeFileSync } from 'node:fs';\nimport { parse } from 'jsonc-parser';\nimport { parseWranglerTableRows } from '../lib/wrangler-table.ts';\nimport {\n CONFIG_PATH,\n DEFAULT_HEX_ID,\n DEFAULT_KV_NAMESPACE_NAMES,\n DEFAULT_SECRET_STORE_NAME,\n DEFAULT_UUID,\n DEFAULT_WORKER_NAME,\n VECTORIZE_DIMENSIONS,\n type D1Database,\n type KVNamespace,\n type SecretStore,\n type WranglerConfig,\n} from './types.ts';\nimport { parseJsonArray, runWrangler } from './cli.ts';\nimport { readConfig, writeConfig, writeConfigValue } from './patches.ts';\n\n/** What `ensure*` did, so a caller can act on the difference. */\nexport interface Provisioned {\n id: string;\n created: boolean;\n}\n\n/** The id a D1 database is reported under, whichever key the CLI used. */\nexport function getD1Id(database: D1Database): string | undefined {\n return database.uuid ?? database.database_id ?? database.id;\n}\n\nexport function listD1Databases(): D1Database[] {\n return parseJsonArray<D1Database>(runWrangler(['d1', 'list', '--json']), 'wrangler d1 list --json');\n}\n\n/**\n * The D1 database `binding` names, created when it does not exist.\n *\n * Whether it was created is reported, not inferred: a database created moments ago\n * holds no user data, so a backup workflow must refuse to upload its empty dump.\n * The caller cannot re-derive that from the config, because this very function\n * patches the placeholder away before the reader ever runs.\n */\nexport function ensureD1Database(databaseName: string): Provisioned {\n let database = listD1Databases().find((candidate) => candidate.name === databaseName);\n let created = false;\n if (database === undefined) {\n console.log(`Creating D1 database: ${databaseName}`);\n runWrangler(['d1', 'create', databaseName]);\n database = listD1Databases().find((candidate) => candidate.name === databaseName);\n created = true;\n }\n const databaseId = database === undefined ? undefined : getD1Id(database);\n if (databaseId === undefined || databaseId === '') {\n throw new Error(`Unable to discover D1 database ID for ${databaseName}.`);\n }\n return { id: databaseId, created };\n}\n\nexport function listKVNamespaces(): KVNamespace[] {\n return parseJsonArray<KVNamespace>(runWrangler(['kv', 'namespace', 'list']), 'wrangler kv namespace list');\n}\n\n/** The namespace name a binding's namespace is created under. */\nexport function getKVNamespaceName(config: WranglerConfig, binding: string): string {\n return DEFAULT_KV_NAMESPACE_NAMES[binding] ?? `${config.name ?? DEFAULT_WORKER_NAME}-${binding.toLowerCase()}`;\n}\n\nexport function ensureKVNamespace(config: WranglerConfig, binding: string): Provisioned {\n const namespaceName = getKVNamespaceName(config, binding);\n const candidateNames = new Set([namespaceName, `${config.name ?? DEFAULT_WORKER_NAME}-${binding}`, binding]);\n let namespace = listKVNamespaces().find((candidate) => {\n const candidateName = candidate.title ?? candidate.name;\n return candidate.id !== undefined && candidateName !== undefined && candidateNames.has(candidateName);\n });\n let created = false;\n if (namespace === undefined) {\n console.log(`Creating KV namespace: ${namespaceName}`);\n runWrangler(['kv', 'namespace', 'create', namespaceName]);\n namespace = listKVNamespaces().find((candidate) => candidate.id !== undefined && (candidate.title ?? candidate.name) === namespaceName);\n created = true;\n }\n if (namespace?.id === undefined) {\n throw new Error(`Unable to discover KV namespace ID for ${namespaceName}.`);\n }\n return { id: namespace.id, created };\n}\n\n/** The bindings a deployment always needs, whether or not a custom config lists them. */\nexport function getRequiredKvBindings(): string[] {\n return Object.keys(DEFAULT_KV_NAMESPACE_NAMES);\n}\n\n/**\n * Add the always-needed KV bindings a hand-written config left out.\n *\n * A config supplied through `WRANGLER_JSONC` is edited by hand and drifts; without\n * this the worker starts with an unbound `CACHE` and fails on the first read.\n */\nexport function ensureRequiredKvBindings(content: string, config: WranglerConfig): string {\n const existing = new Set((config.kv_namespaces ?? []).map((namespace) => namespace.binding).filter((binding) => binding !== undefined));\n const missing = getRequiredKvBindings().filter((binding) => !existing.has(binding));\n if (missing.length === 0) {\n return content;\n }\n const next = [...(config.kv_namespaces ?? [])];\n for (const binding of missing) {\n console.log(`Adding missing KV namespace binding: ${binding}`);\n next.push({ binding, id: DEFAULT_HEX_ID });\n }\n return writeConfigValue(content, ['kv_namespaces'], next);\n}\n\n/** The stores in a `secrets-store store list` table. */\nexport function parseSecretStoresTable(output: string): SecretStore[] {\n const stores: SecretStore[] = [];\n // Through the shared table parser rather than a second inline split: `wrangler`\n // renders through `cli-table3`, whose cells are separated by U+2502 and are *not*\n // space-aligned, so a parser written for aligned output silently matches nothing\n // — which reads as \"the store does not exist\" and makes provisioning create a\n // duplicate.\n for (const row of parseWranglerTableRows(output)) {\n const name = row[0];\n const id = row[1];\n // Store ids are 32 hex characters; a row without one is a header, a border, or\n // an unrelated column, and is skipped rather than stored with an undefined id.\n if (name !== undefined && id !== undefined && /^[a-f0-9]{32}$/i.test(id)) {\n stores.push({ name, id });\n }\n }\n return stores;\n}\n\nexport function listSecretStores(): SecretStore[] {\n const output = runWrangler(['secrets-store', 'store', 'list', '--remote']);\n try {\n return parseJsonArray<SecretStore>(output, 'wrangler secrets-store store list --remote');\n } catch {\n // The subcommand prints a table rather than JSON on some versions.\n return parseSecretStoresTable(output);\n }\n}\n\nexport function ensureSecretStore(): string {\n const stores = listSecretStores();\n const existing = stores.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? stores[0];\n if (existing !== undefined) {\n return existing.id;\n }\n console.log(`Creating Secrets Store: ${DEFAULT_SECRET_STORE_NAME}`);\n const output = runWrangler(['secrets-store', 'store', 'create', DEFAULT_SECRET_STORE_NAME, '--remote']);\n const createdStoreId = /ID:\\s*([a-f0-9]{32})/i.exec(output)?.[1];\n if (createdStoreId !== undefined) {\n return createdStoreId;\n }\n // The create output did not name the id, so read it back rather than guessing.\n const refreshed = listSecretStores();\n const store = refreshed.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? refreshed[0];\n if (store?.id === undefined) {\n throw new Error(`Unable to discover Secrets Store ID for ${DEFAULT_SECRET_STORE_NAME}.`);\n }\n return store.id;\n}\n\n/** Create a queue when it is absent, reporting whether it had to be created. */\nexport function ensureQueue(queueName: string): boolean {\n try {\n runWrangler(['queues', 'info', queueName]);\n console.log(`Queue ${queueName} already exists.`);\n return false;\n } catch {\n console.log(`Creating queue: ${queueName}`);\n runWrangler(['queues', 'create', queueName]);\n return true;\n }\n}\n\n/**\n * Queue names a deployment needs, in first-seen order.\n *\n * Producers and consumers name the same queue twice — one queue, two roles — and a\n * name appearing in both must be created once. Pure so it is testable without\n * wrangler.\n */\nexport function queueNamesIn(config: WranglerConfig): string[] {\n const names: string[] = [];\n const seen = new Set<string>();\n for (const producer of config.queues?.producers ?? []) {\n if (producer.queue === '' || seen.has(producer.queue)) continue;\n seen.add(producer.queue);\n names.push(producer.queue);\n }\n for (const consumer of config.queues?.consumers ?? []) {\n if (consumer.queue === '' || seen.has(consumer.queue)) continue;\n seen.add(consumer.queue);\n names.push(consumer.queue);\n }\n return names;\n}\n\nexport function ensureVectorizeIndex(indexName: string, dimensions: number): void {\n try {\n runWrangler(['vectorize', 'info', indexName]);\n console.log(`Vectorize index ${indexName} already exists.`);\n } catch {\n console.log(`Creating Vectorize index: ${indexName} with ${dimensions} dimensions`);\n runWrangler(['vectorize', 'create', indexName, `--dimensions=${dimensions}`, '--metric=cosine']);\n }\n}\n\n/** Replace each placeholder D1 `database_id` with a real one. */\nfunction provisionD1Databases(content: string, config: WranglerConfig, created: string[]): string {\n let patched = content;\n for (const [index, database] of config.d1_databases?.entries() ?? []) {\n if (database.database_id !== DEFAULT_UUID) continue;\n if (database.database_name === undefined || database.database_name === '') {\n throw new Error(`D1 database binding ${database.binding ?? index} has a placeholder database_id but no database_name.`);\n }\n const resolved = ensureD1Database(database.database_name);\n if (resolved.created) {\n created.push(`d1:${database.database_name}`);\n }\n console.log(`Using D1 database ${database.database_name}: ${resolved.id}`);\n patched = writeConfigValue(patched, ['d1_databases', index, 'database_id'], resolved.id);\n }\n return patched;\n}\n\n/** Replace each placeholder KV namespace id with a real one. */\nfunction provisionKvNamespaces(content: string, config: WranglerConfig, created: string[]): string {\n let patched = content;\n for (const [index, namespace] of config.kv_namespaces?.entries() ?? []) {\n if (namespace.id !== DEFAULT_HEX_ID) continue;\n if (namespace.binding === undefined || namespace.binding === '') {\n throw new Error(`KV namespace at index ${index} has a placeholder id but no binding.`);\n }\n const resolved = ensureKVNamespace(config, namespace.binding);\n const namespaceName = getKVNamespaceName(config, namespace.binding);\n if (resolved.created) {\n created.push(`kv:${namespaceName}`);\n }\n console.log(`Using KV namespace ${namespaceName}: ${resolved.id}`);\n patched = writeConfigValue(patched, ['kv_namespaces', index, 'id'], resolved.id);\n }\n return patched;\n}\n\n/**\n * Point every placeholder Secrets Store `store_id` at one store, creating it if\n * absent. `existed` is read **before** the create, because whether the store was\n * created is what the caller reports.\n */\nfunction provisionSecretStore(content: string, config: WranglerConfig, created: string[]): string {\n const placeholders = (config.secrets_store_secrets ?? [])\n .map((secret, index) => ({ secret, index }))\n .filter(({ secret }) => secret.store_id === DEFAULT_HEX_ID);\n if (placeholders.length === 0) {\n return content;\n }\n const existed = listSecretStores().some((store) => store.name === DEFAULT_SECRET_STORE_NAME);\n const storeId = ensureSecretStore();\n if (!existed) {\n created.push(`secrets-store:${DEFAULT_SECRET_STORE_NAME}`);\n }\n console.log(`Using Secrets Store: ${storeId}`);\n return placeholders.reduce(\n (patched, { index }) => writeConfigValue(patched, ['secrets_store_secrets', index, 'store_id'], storeId),\n content,\n );\n}\n\n/**\n * Create every resource the config names, and write the real ids over the\n * placeholders.\n *\n * Returns what it had to create, as `<kind>:<name>` — returned rather than logged,\n * because a caller acts on it: the backup workflow refuses to export a D1 database\n * that appears here, since one created moments ago holds no user data and an empty\n * dump uploaded on schedule is a false sense of safety.\n */\nexport function provisionWranglerResources(): string[] {\n const created: string[] = [];\n let { content, config } = readConfig();\n\n content = ensureRequiredKvBindings(content, config);\n config = parse(content) as WranglerConfig;\n\n // Each of the three below re-parses before it patches, because each writes into\n // the config text the previous one produced. They are separate functions because\n // they are separate resources with separate rules, and one loop holding all\n // three would read as a single resource list with the differences hidden in the\n // bodies.\n content = provisionD1Databases(content, config, created);\n config = parse(content) as WranglerConfig;\n\n content = provisionKvNamespaces(content, config, created);\n config = parse(content) as WranglerConfig;\n\n content = provisionSecretStore(content, config, created);\n\n writeConfig(content);\n\n config = parse(content) as WranglerConfig;\n for (const queueName of queueNamesIn(config)) {\n if (ensureQueue(queueName)) {\n created.push(`queue:${queueName}`);\n }\n }\n\n // Vectorize indexes are name-based, so nothing in the file is patched — but the\n // created names are still reported like every other resource, so a deploy log\n // shows what appeared.\n for (const binding of config.vectorize ?? []) {\n ensureVectorizeIndex(binding.index_name, VECTORIZE_DIMENSIONS);\n }\n\n return created;\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One `{ find, replacement }` pair for Vitest's resolver.
|
|
3
|
+
*
|
|
4
|
+
* A `string` find is a prefix match in Vite; a `RegExp` find is tested against
|
|
5
|
+
* the specifier. Workspace scopes use plain strings (`'@scope/name'` matches
|
|
6
|
+
* `'@scope/name'` and `'@scope/name/sub'` alike); `@/` and `~/` use regexps so
|
|
7
|
+
* the trailing slash is part of the match.
|
|
8
|
+
*/
|
|
9
|
+
export interface VitestAlias {
|
|
10
|
+
readonly find: string | RegExp;
|
|
11
|
+
readonly replacement: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Every workspace package the family has converged on, as directory names under
|
|
15
|
+
* `packages/`.
|
|
16
|
+
*
|
|
17
|
+
* The union across all nine repos: the universal core (`shared`,
|
|
18
|
+
* `backend-errors`, `backend-runtime`, `backend-data`, `backend-services`) plus
|
|
19
|
+
* the domain packages (`provider-clients`, `webdav`, `dav-store`,
|
|
20
|
+
* `git-protocol`, `git-service`). `media-tags`/`subsonic` (Edge-Sonic) are
|
|
21
|
+
* unconstrained utility leaves with no boundary block and no alias in their
|
|
22
|
+
* source repo, so they are not listed — a repo that needs them passes
|
|
23
|
+
* `packages` explicitly or appends `aliases`.
|
|
24
|
+
*
|
|
25
|
+
* A superset is safe: an alias for a package the consumer does not have never
|
|
26
|
+
* matches a specifier, and Vite only resolves the replacement when something
|
|
27
|
+
* imports it.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_WORKSPACE_PACKAGES: readonly string[];
|
|
30
|
+
/**
|
|
31
|
+
* The Cloudflare runtime mocks the unit suite aliases.
|
|
32
|
+
*
|
|
33
|
+
* `workers` exists in every repo; `sockets` in five; `workflows` in four. All
|
|
34
|
+
* three are listed by default: an alias whose mock file is absent never fires
|
|
35
|
+
* unless a test imports the specifier, and then the missing file is the correct
|
|
36
|
+
* error rather than Node's `ERR_UNKNOWN_SCHEME` for `cloudflare:*`.
|
|
37
|
+
*/
|
|
38
|
+
export declare const DEFAULT_CLOUDFLARE_MOCKS: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Keep the kit's own `dist/` inside Vite's pipeline.
|
|
41
|
+
*
|
|
42
|
+
* The kit ships ESM `dist/` with bundler-style extensionless relative imports
|
|
43
|
+
* (its tsconfig is `moduleResolution: Bundler`), which Node's ESM resolver
|
|
44
|
+
* refuses. Vitest externalizes `node_modules` deps by default and would import
|
|
45
|
+
* that dist with Node; `noExternal` routes `@rexezuge/*` back through Vite —
|
|
46
|
+
* the same resolver that bundles the worker — so a test loads the very dist
|
|
47
|
+
* the worker ships. Without this, the run dies on `./BaseDAO` inside
|
|
48
|
+
* `@rexezuge/d1`'s `dist/index.js`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const KIT_NO_EXTERNAL: readonly RegExp[];
|
|
51
|
+
/**
|
|
52
|
+
* What `workspaceAliases` accepts.
|
|
53
|
+
*/
|
|
54
|
+
export interface WorkspaceAliasesOptions {
|
|
55
|
+
/**
|
|
56
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`. Every `@scope/*` alias is
|
|
57
|
+
* derived from it, so the same factory serves all nine repos.
|
|
58
|
+
*/
|
|
59
|
+
readonly scope: string;
|
|
60
|
+
/**
|
|
61
|
+
* The repo root, as a file URL. Pass `new URL('.', import.meta.url).href`
|
|
62
|
+
* from the calling config — never `import.meta.url` of this module, which
|
|
63
|
+
* points inside `node_modules/@rexezuge/tooling`.
|
|
64
|
+
*/
|
|
65
|
+
readonly root: string;
|
|
66
|
+
/**
|
|
67
|
+
* Workspace package directory names under `packages/` plus `background`
|
|
68
|
+
* (which lives under `apps/`). Defaults to {@link DEFAULT_WORKSPACE_PACKAGES}.
|
|
69
|
+
*/
|
|
70
|
+
readonly packages?: readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* Which `cloudflare:*` mocks to alias. Defaults to {@link DEFAULT_CLOUDFLARE_MOCKS}.
|
|
73
|
+
*/
|
|
74
|
+
readonly mocks?: readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
* Extra resolver entries, applied after the canonical ones.
|
|
77
|
+
*/
|
|
78
|
+
readonly extraAliases?: readonly VitestAlias[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build the workspace alias table for a consumer repo.
|
|
82
|
+
*
|
|
83
|
+
* Aliases point at source rather than at built output, so a test exercises the
|
|
84
|
+
* code the worker would run without a build step. `background` resolves under
|
|
85
|
+
* `apps/`; every other package under `packages/`. `@/` maps to the API worker
|
|
86
|
+
* source and `~/` to the SPA source, matching the two `tsconfig` path prefixes
|
|
87
|
+
* every repo shares.
|
|
88
|
+
*/
|
|
89
|
+
export declare function workspaceAliases(options: WorkspaceAliasesOptions): VitestAlias[];
|
|
90
|
+
//# sourceMappingURL=vitest-aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest-aliases.d.ts","sourceRoot":"","sources":["../src/vitest-aliases.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAYvD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAwC,CAAC;AAE/F;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAA6B,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;CAChD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,WAAW,EAAE,CAmBhF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
/**
|
|
3
|
+
* Every workspace package the family has converged on, as directory names under
|
|
4
|
+
* `packages/`.
|
|
5
|
+
*
|
|
6
|
+
* The union across all nine repos: the universal core (`shared`,
|
|
7
|
+
* `backend-errors`, `backend-runtime`, `backend-data`, `backend-services`) plus
|
|
8
|
+
* the domain packages (`provider-clients`, `webdav`, `dav-store`,
|
|
9
|
+
* `git-protocol`, `git-service`). `media-tags`/`subsonic` (Edge-Sonic) are
|
|
10
|
+
* unconstrained utility leaves with no boundary block and no alias in their
|
|
11
|
+
* source repo, so they are not listed — a repo that needs them passes
|
|
12
|
+
* `packages` explicitly or appends `aliases`.
|
|
13
|
+
*
|
|
14
|
+
* A superset is safe: an alias for a package the consumer does not have never
|
|
15
|
+
* matches a specifier, and Vite only resolves the replacement when something
|
|
16
|
+
* imports it.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_WORKSPACE_PACKAGES = [
|
|
19
|
+
'shared',
|
|
20
|
+
'backend-errors',
|
|
21
|
+
'backend-runtime',
|
|
22
|
+
'backend-data',
|
|
23
|
+
'provider-clients',
|
|
24
|
+
'webdav',
|
|
25
|
+
'dav-store',
|
|
26
|
+
'git-protocol',
|
|
27
|
+
'git-service',
|
|
28
|
+
'backend-services',
|
|
29
|
+
'background',
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* The Cloudflare runtime mocks the unit suite aliases.
|
|
33
|
+
*
|
|
34
|
+
* `workers` exists in every repo; `sockets` in five; `workflows` in four. All
|
|
35
|
+
* three are listed by default: an alias whose mock file is absent never fires
|
|
36
|
+
* unless a test imports the specifier, and then the missing file is the correct
|
|
37
|
+
* error rather than Node's `ERR_UNKNOWN_SCHEME` for `cloudflare:*`.
|
|
38
|
+
*/
|
|
39
|
+
export const DEFAULT_CLOUDFLARE_MOCKS = ['workers', 'sockets', 'workflows'];
|
|
40
|
+
/**
|
|
41
|
+
* Keep the kit's own `dist/` inside Vite's pipeline.
|
|
42
|
+
*
|
|
43
|
+
* The kit ships ESM `dist/` with bundler-style extensionless relative imports
|
|
44
|
+
* (its tsconfig is `moduleResolution: Bundler`), which Node's ESM resolver
|
|
45
|
+
* refuses. Vitest externalizes `node_modules` deps by default and would import
|
|
46
|
+
* that dist with Node; `noExternal` routes `@rexezuge/*` back through Vite —
|
|
47
|
+
* the same resolver that bundles the worker — so a test loads the very dist
|
|
48
|
+
* the worker ships. Without this, the run dies on `./BaseDAO` inside
|
|
49
|
+
* `@rexezuge/d1`'s `dist/index.js`.
|
|
50
|
+
*/
|
|
51
|
+
export const KIT_NO_EXTERNAL = [/(^|[/\\])@rexezuge\//];
|
|
52
|
+
/**
|
|
53
|
+
* Build the workspace alias table for a consumer repo.
|
|
54
|
+
*
|
|
55
|
+
* Aliases point at source rather than at built output, so a test exercises the
|
|
56
|
+
* code the worker would run without a build step. `background` resolves under
|
|
57
|
+
* `apps/`; every other package under `packages/`. `@/` maps to the API worker
|
|
58
|
+
* source and `~/` to the SPA source, matching the two `tsconfig` path prefixes
|
|
59
|
+
* every repo shares.
|
|
60
|
+
*/
|
|
61
|
+
export function workspaceAliases(options) {
|
|
62
|
+
const { scope, root } = options;
|
|
63
|
+
const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
|
|
64
|
+
const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
|
|
65
|
+
const at = (relative) => fileURLToPath(new URL(relative, root));
|
|
66
|
+
const aliases = [];
|
|
67
|
+
for (const name of packages) {
|
|
68
|
+
const dir = name === 'background' ? 'apps/background/src' : `packages/${name}/src`;
|
|
69
|
+
aliases.push({ find: `${scope}/${name}`, replacement: at(dir) });
|
|
70
|
+
}
|
|
71
|
+
for (const mock of mocks) {
|
|
72
|
+
aliases.push({ find: `cloudflare:${mock}`, replacement: at(`test/mocks/cloudflare-${mock}.ts`) });
|
|
73
|
+
}
|
|
74
|
+
const apiSrc = at('apps/api/src');
|
|
75
|
+
const webSrc = at('apps/web/src');
|
|
76
|
+
aliases.push({ find: /^@\//, replacement: `${apiSrc}/` });
|
|
77
|
+
aliases.push({ find: /^~\//, replacement: `${webSrc}/` });
|
|
78
|
+
aliases.push(...(options.extraAliases ?? []));
|
|
79
|
+
return aliases;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=vitest-aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest-aliases.js","sourceRoot":"","sources":["../src/vitest-aliases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAezC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC3D,QAAQ;IACR,gBAAgB;IAChB,iBAAiB;IACjB,cAAc;IACd,kBAAkB;IAClB,QAAQ;IACR,WAAW;IACX,cAAc;IACd,aAAa;IACb,kBAAkB;IAClB,YAAY;CACb,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAsB,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAE/F;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAsB,CAAC,sBAAsB,CAAC,CAAC;AAgC3E;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC/D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,0BAA0B,CAAC;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,wBAAwB,CAAC;IACxD,MAAM,EAAE,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAChF,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC;QACnF,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,IAAI,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,IAAI,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,yBAAyB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;IACpG,CAAC;IACD,MAAM,MAAM,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC;IAClC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { fileURLToPath } from 'node:url';\n\n/**\n * One `{ find, replacement }` pair for Vitest's resolver.\n *\n * A `string` find is a prefix match in Vite; a `RegExp` find is tested against\n * the specifier. Workspace scopes use plain strings (`'@scope/name'` matches\n * `'@scope/name'` and `'@scope/name/sub'` alike); `@/` and `~/` use regexps so\n * the trailing slash is part of the match.\n */\nexport interface VitestAlias {\n readonly find: string | RegExp;\n readonly replacement: string;\n}\n\n/**\n * Every workspace package the family has converged on, as directory names under\n * `packages/`.\n *\n * The union across all nine repos: the universal core (`shared`,\n * `backend-errors`, `backend-runtime`, `backend-data`, `backend-services`) plus\n * the domain packages (`provider-clients`, `webdav`, `dav-store`,\n * `git-protocol`, `git-service`). `media-tags`/`subsonic` (Edge-Sonic) are\n * unconstrained utility leaves with no boundary block and no alias in their\n * source repo, so they are not listed — a repo that needs them passes\n * `packages` explicitly or appends `aliases`.\n *\n * A superset is safe: an alias for a package the consumer does not have never\n * matches a specifier, and Vite only resolves the replacement when something\n * imports it.\n */\nexport const DEFAULT_WORKSPACE_PACKAGES: readonly string[] = [\n 'shared',\n 'backend-errors',\n 'backend-runtime',\n 'backend-data',\n 'provider-clients',\n 'webdav',\n 'dav-store',\n 'git-protocol',\n 'git-service',\n 'backend-services',\n 'background',\n];\n\n/**\n * The Cloudflare runtime mocks the unit suite aliases.\n *\n * `workers` exists in every repo; `sockets` in five; `workflows` in four. All\n * three are listed by default: an alias whose mock file is absent never fires\n * unless a test imports the specifier, and then the missing file is the correct\n * error rather than Node's `ERR_UNKNOWN_SCHEME` for `cloudflare:*`.\n */\nexport const DEFAULT_CLOUDFLARE_MOCKS: readonly string[] = ['workers', 'sockets', 'workflows'];\n\n/**\n * Keep the kit's own `dist/` inside Vite's pipeline.\n *\n * The kit ships ESM `dist/` with bundler-style extensionless relative imports\n * (its tsconfig is `moduleResolution: Bundler`), which Node's ESM resolver\n * refuses. Vitest externalizes `node_modules` deps by default and would import\n * that dist with Node; `noExternal` routes `@rexezuge/*` back through Vite —\n * the same resolver that bundles the worker — so a test loads the very dist\n * the worker ships. Without this, the run dies on `./BaseDAO` inside\n * `@rexezuge/d1`'s `dist/index.js`.\n */\nexport const KIT_NO_EXTERNAL: readonly RegExp[] = [/(^|[/\\\\])@rexezuge\\//];\n\n/**\n * What `workspaceAliases` accepts.\n */\nexport interface WorkspaceAliasesOptions {\n /**\n * The consuming repo's npm scope, e.g. `'@myapp'`. Every `@scope/*` alias is\n * derived from it, so the same factory serves all nine repos.\n */\n readonly scope: string;\n /**\n * The repo root, as a file URL. Pass `new URL('.', import.meta.url).href`\n * from the calling config — never `import.meta.url` of this module, which\n * points inside `node_modules/@rexezuge/tooling`.\n */\n readonly root: string;\n /**\n * Workspace package directory names under `packages/` plus `background`\n * (which lives under `apps/`). Defaults to {@link DEFAULT_WORKSPACE_PACKAGES}.\n */\n readonly packages?: readonly string[];\n /**\n * Which `cloudflare:*` mocks to alias. Defaults to {@link DEFAULT_CLOUDFLARE_MOCKS}.\n */\n readonly mocks?: readonly string[];\n /**\n * Extra resolver entries, applied after the canonical ones.\n */\n readonly extraAliases?: readonly VitestAlias[];\n}\n\n/**\n * Build the workspace alias table for a consumer repo.\n *\n * Aliases point at source rather than at built output, so a test exercises the\n * code the worker would run without a build step. `background` resolves under\n * `apps/`; every other package under `packages/`. `@/` maps to the API worker\n * source and `~/` to the SPA source, matching the two `tsconfig` path prefixes\n * every repo shares.\n */\nexport function workspaceAliases(options: WorkspaceAliasesOptions): VitestAlias[] {\n const { scope, root } = options;\n const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;\n const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;\n const at = (relative: string): string => fileURLToPath(new URL(relative, root));\n const aliases: VitestAlias[] = [];\n for (const name of packages) {\n const dir = name === 'background' ? 'apps/background/src' : `packages/${name}/src`;\n aliases.push({ find: `${scope}/${name}`, replacement: at(dir) });\n }\n for (const mock of mocks) {\n aliases.push({ find: `cloudflare:${mock}`, replacement: at(`test/mocks/cloudflare-${mock}.ts`) });\n }\n const apiSrc = at('apps/api/src');\n const webSrc = at('apps/web/src');\n aliases.push({ find: /^@\\//, replacement: `${apiSrc}/` });\n aliases.push({ find: /^~\\//, replacement: `${webSrc}/` });\n aliases.push(...(options.extraAliases ?? []));\n return aliases;\n}\n"]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The integration-suite Vitest config.
|
|
3
|
+
*
|
|
4
|
+
* Provenance: the eight `test/integration/vitest.config.mts` workerd suites
|
|
5
|
+
* plus CalDAV-Bridge's `node:sqlite` suite. Every one hand-writes the same
|
|
6
|
+
* `@scope/* → src` workspace table (8–20 entries) beside its own harness
|
|
7
|
+
* wiring; this factory generates that table from `scope` so the two cannot
|
|
8
|
+
* drift apart — a suite resolving a workspace import differently from the unit
|
|
9
|
+
* suite fails in a way that looks like a product bug.
|
|
10
|
+
*
|
|
11
|
+
* What the factory does not do, deliberately: the workerd suites' `plugins`
|
|
12
|
+
* (`@cloudflare/vitest-pool-workers`), `pool` and migration-SQL `define` are
|
|
13
|
+
* harness wiring that belongs to the repo, and importing the workerd plugin
|
|
14
|
+
* here would make the tooling package undownloadable for a consumer without
|
|
15
|
+
* it. The factory takes them as opaque pass-through and returns them
|
|
16
|
+
* untouched. CalDAV-Bridge's suite passes none of them (plain `node` +
|
|
17
|
+
* `node:sqlite`, no coverage); the workerd suites pass all three.
|
|
18
|
+
*/
|
|
19
|
+
import { defineConfig, type Plugin } from 'vitest/config';
|
|
20
|
+
import type { Pool } from 'vitest/node';
|
|
21
|
+
import type { VitestAlias } from './vitest-aliases.ts';
|
|
22
|
+
/**
|
|
23
|
+
* What `defineIntegrationVitestConfig` accepts.
|
|
24
|
+
*/
|
|
25
|
+
export interface IntegrationVitestConfigOptions {
|
|
26
|
+
/**
|
|
27
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`.
|
|
28
|
+
*/
|
|
29
|
+
readonly scope: string;
|
|
30
|
+
/**
|
|
31
|
+
* Workspace package directory names. Defaults to the family superset.
|
|
32
|
+
*/
|
|
33
|
+
readonly packages?: readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* The repo root, as a file URL.
|
|
36
|
+
*/
|
|
37
|
+
readonly root?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Extra resolver entries, applied after the workspace table (e.g. the
|
|
40
|
+
* `hono` dedupe two repos carry).
|
|
41
|
+
*/
|
|
42
|
+
readonly aliases?: readonly VitestAlias[];
|
|
43
|
+
/**
|
|
44
|
+
* Which suites to collect. Workerd suites use
|
|
45
|
+
* `test/integration/**/*.int.test.ts`; CalDAV-Bridge's sqlite suite uses
|
|
46
|
+
* `test/integration/**/*.test.ts`.
|
|
47
|
+
*/
|
|
48
|
+
readonly include?: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* The Vitest plugins (the workerd `cloudflareTest()` plugin). Typed as the
|
|
51
|
+
* runner's own plugin so a workerd plugin is accepted and nothing new is
|
|
52
|
+
* imported — this package stays dependency-free.
|
|
53
|
+
*/
|
|
54
|
+
readonly plugins?: readonly Plugin[];
|
|
55
|
+
/**
|
|
56
|
+
* The pool (the workerd `cloudflarePool()`). The runner's own `Pool` type,
|
|
57
|
+
* so a custom pool is accepted without importing its provider.
|
|
58
|
+
*/
|
|
59
|
+
readonly pool?: Pool;
|
|
60
|
+
/**
|
|
61
|
+
* Compile-time defines (the migration SQL/SQLite bundle each suite injects).
|
|
62
|
+
* Opaque, passed through.
|
|
63
|
+
*/
|
|
64
|
+
readonly define?: Readonly<Record<string, string>>;
|
|
65
|
+
/**
|
|
66
|
+
* SSR `noExternal` (workerd suites list `hono`, `chanfana` and their scope).
|
|
67
|
+
* Passed through untouched.
|
|
68
|
+
*/
|
|
69
|
+
readonly ssrNoExternal?: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build the integration-suite config.
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* // test/integration/vitest.config.mts — workerd suite
|
|
76
|
+
* import { cloudflareTest, cloudflarePool } from '@cloudflare/vitest-pool-workers';
|
|
77
|
+
* import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';
|
|
78
|
+
* export default defineIntegrationVitestConfig({
|
|
79
|
+
* scope: '@myapp',
|
|
80
|
+
* define: { __INTEGRATION_MIGRATION_SQL__: JSON.stringify(migrationSql) },
|
|
81
|
+
* plugins: [cloudflareTest({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } })],
|
|
82
|
+
* pool: cloudflarePool({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } }),
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* ```ts
|
|
87
|
+
* // test/integration/vitest.config.mts — sqlite suite (no workerd)
|
|
88
|
+
* import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';
|
|
89
|
+
* export default defineIntegrationVitestConfig({
|
|
90
|
+
* scope: '@myapp',
|
|
91
|
+
* include: ['test/integration/**/*.test.ts'],
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function defineIntegrationVitestConfig(options: IntegrationVitestConfigOptions): ReturnType<typeof defineConfig>;
|
|
96
|
+
//# sourceMappingURL=vitest-integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest-integration.d.ts","sourceRoot":"","sources":["../src/vitest-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,8BAA8B,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAmBtH"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The integration-suite Vitest config.
|
|
3
|
+
*
|
|
4
|
+
* Provenance: the eight `test/integration/vitest.config.mts` workerd suites
|
|
5
|
+
* plus CalDAV-Bridge's `node:sqlite` suite. Every one hand-writes the same
|
|
6
|
+
* `@scope/* → src` workspace table (8–20 entries) beside its own harness
|
|
7
|
+
* wiring; this factory generates that table from `scope` so the two cannot
|
|
8
|
+
* drift apart — a suite resolving a workspace import differently from the unit
|
|
9
|
+
* suite fails in a way that looks like a product bug.
|
|
10
|
+
*
|
|
11
|
+
* What the factory does not do, deliberately: the workerd suites' `plugins`
|
|
12
|
+
* (`@cloudflare/vitest-pool-workers`), `pool` and migration-SQL `define` are
|
|
13
|
+
* harness wiring that belongs to the repo, and importing the workerd plugin
|
|
14
|
+
* here would make the tooling package undownloadable for a consumer without
|
|
15
|
+
* it. The factory takes them as opaque pass-through and returns them
|
|
16
|
+
* untouched. CalDAV-Bridge's suite passes none of them (plain `node` +
|
|
17
|
+
* `node:sqlite`, no coverage); the workerd suites pass all three.
|
|
18
|
+
*/
|
|
19
|
+
import { defineConfig } from 'vitest/config';
|
|
20
|
+
import { DEFAULT_WORKSPACE_PACKAGES, workspaceAliases } from "./vitest-aliases.js";
|
|
21
|
+
/**
|
|
22
|
+
* Build the integration-suite config.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* // test/integration/vitest.config.mts — workerd suite
|
|
26
|
+
* import { cloudflareTest, cloudflarePool } from '@cloudflare/vitest-pool-workers';
|
|
27
|
+
* import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';
|
|
28
|
+
* export default defineIntegrationVitestConfig({
|
|
29
|
+
* scope: '@myapp',
|
|
30
|
+
* define: { __INTEGRATION_MIGRATION_SQL__: JSON.stringify(migrationSql) },
|
|
31
|
+
* plugins: [cloudflareTest({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } })],
|
|
32
|
+
* pool: cloudflarePool({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } }),
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* // test/integration/vitest.config.mts — sqlite suite (no workerd)
|
|
38
|
+
* import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';
|
|
39
|
+
* export default defineIntegrationVitestConfig({
|
|
40
|
+
* scope: '@myapp',
|
|
41
|
+
* include: ['test/integration/**/*.test.ts'],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function defineIntegrationVitestConfig(options) {
|
|
46
|
+
const root = options.root ?? new URL('.', import.meta.url).href;
|
|
47
|
+
const aliases = [
|
|
48
|
+
...workspaceAliases({ scope: options.scope, root, packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES, mocks: [] }),
|
|
49
|
+
...(options.aliases ?? []),
|
|
50
|
+
];
|
|
51
|
+
return defineConfig({
|
|
52
|
+
...(options.define !== undefined && { define: { ...options.define } }),
|
|
53
|
+
...(options.plugins !== undefined && { plugins: [...options.plugins] }),
|
|
54
|
+
resolve: { alias: aliases },
|
|
55
|
+
test: {
|
|
56
|
+
globals: true,
|
|
57
|
+
environment: 'node',
|
|
58
|
+
include: [...(options.include ?? ['test/integration/**/*.int.test.ts'])],
|
|
59
|
+
...(options.pool !== undefined && { pool: options.pool }),
|
|
60
|
+
},
|
|
61
|
+
...(options.ssrNoExternal !== undefined && { ssr: { noExternal: [...options.ssrNoExternal] } }),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=vitest-integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest-integration.js","sourceRoot":"","sources":["../src/vitest-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAqDnF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAuC;IACnF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IAChE,MAAM,OAAO,GAAG;QACd,GAAG,gBAAgB,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,0BAA0B,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QACxH,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;KAC3B,CAAC;IAEF,OAAO,YAAY,CAAC;QAClB,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QACtE,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACvE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;QAC3B,IAAI,EAAE;YACJ,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,MAAM;YACnB,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,mCAAmC,CAAC,CAAC,CAAC;YACxE,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;SAC1D;QACD,GAAG,CAAC,OAAO,CAAC,aAAa,KAAK,SAAS,IAAI,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;KAChG,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The integration-suite Vitest config.\n *\n * Provenance: the eight `test/integration/vitest.config.mts` workerd suites\n * plus CalDAV-Bridge's `node:sqlite` suite. Every one hand-writes the same\n * `@scope/* → src` workspace table (8–20 entries) beside its own harness\n * wiring; this factory generates that table from `scope` so the two cannot\n * drift apart — a suite resolving a workspace import differently from the unit\n * suite fails in a way that looks like a product bug.\n *\n * What the factory does not do, deliberately: the workerd suites' `plugins`\n * (`@cloudflare/vitest-pool-workers`), `pool` and migration-SQL `define` are\n * harness wiring that belongs to the repo, and importing the workerd plugin\n * here would make the tooling package undownloadable for a consumer without\n * it. The factory takes them as opaque pass-through and returns them\n * untouched. CalDAV-Bridge's suite passes none of them (plain `node` +\n * `node:sqlite`, no coverage); the workerd suites pass all three.\n */\n\nimport { defineConfig, type Plugin } from 'vitest/config';\nimport type { Pool } from 'vitest/node';\nimport { DEFAULT_WORKSPACE_PACKAGES, workspaceAliases } from './vitest-aliases.ts';\nimport type { VitestAlias } from './vitest-aliases.ts';\n\n/**\n * What `defineIntegrationVitestConfig` accepts.\n */\nexport interface IntegrationVitestConfigOptions {\n /**\n * The consuming repo's npm scope, e.g. `'@myapp'`.\n */\n readonly scope: string;\n /**\n * Workspace package directory names. Defaults to the family superset.\n */\n readonly packages?: readonly string[];\n /**\n * The repo root, as a file URL.\n */\n readonly root?: string;\n /**\n * Extra resolver entries, applied after the workspace table (e.g. the\n * `hono` dedupe two repos carry).\n */\n readonly aliases?: readonly VitestAlias[];\n /**\n * Which suites to collect. Workerd suites use\n * `test/integration/**/*.int.test.ts`; CalDAV-Bridge's sqlite suite uses\n * `test/integration/**/*.test.ts`.\n */\n readonly include?: readonly string[];\n /**\n * The Vitest plugins (the workerd `cloudflareTest()` plugin). Typed as the\n * runner's own plugin so a workerd plugin is accepted and nothing new is\n * imported — this package stays dependency-free.\n */\n readonly plugins?: readonly Plugin[];\n /**\n * The pool (the workerd `cloudflarePool()`). The runner's own `Pool` type,\n * so a custom pool is accepted without importing its provider.\n */\n readonly pool?: Pool;\n /**\n * Compile-time defines (the migration SQL/SQLite bundle each suite injects).\n * Opaque, passed through.\n */\n readonly define?: Readonly<Record<string, string>>;\n /**\n * SSR `noExternal` (workerd suites list `hono`, `chanfana` and their scope).\n * Passed through untouched.\n */\n readonly ssrNoExternal?: readonly string[];\n}\n\n/**\n * Build the integration-suite config.\n *\n * ```ts\n * // test/integration/vitest.config.mts — workerd suite\n * import { cloudflareTest, cloudflarePool } from '@cloudflare/vitest-pool-workers';\n * import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';\n * export default defineIntegrationVitestConfig({\n * scope: '@myapp',\n * define: { __INTEGRATION_MIGRATION_SQL__: JSON.stringify(migrationSql) },\n * plugins: [cloudflareTest({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } })],\n * pool: cloudflarePool({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } }),\n * });\n * ```\n *\n * ```ts\n * // test/integration/vitest.config.mts — sqlite suite (no workerd)\n * import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';\n * export default defineIntegrationVitestConfig({\n * scope: '@myapp',\n * include: ['test/integration/**/*.test.ts'],\n * });\n * ```\n */\nexport function defineIntegrationVitestConfig(options: IntegrationVitestConfigOptions): ReturnType<typeof defineConfig> {\n const root = options.root ?? new URL('.', import.meta.url).href;\n const aliases = [\n ...workspaceAliases({ scope: options.scope, root, packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES, mocks: [] }),\n ...(options.aliases ?? []),\n ];\n\n return defineConfig({\n ...(options.define !== undefined && { define: { ...options.define } }),\n ...(options.plugins !== undefined && { plugins: [...options.plugins] }),\n resolve: { alias: aliases },\n test: {\n globals: true,\n environment: 'node',\n include: [...(options.include ?? ['test/integration/**/*.int.test.ts'])],\n ...(options.pool !== undefined && { pool: options.pool }),\n },\n ...(options.ssrNoExternal !== undefined && { ssr: { noExternal: [...options.ssrNoExternal] } }),\n });\n}\n"]}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single-file `projects` composition: backend (`node`) plus SPA (DOM).
|
|
3
|
+
*
|
|
4
|
+
* Provenance: AWS-AccessBridge (split by `.ts`/`.tsx` extension),
|
|
5
|
+
* Mail-Meow (split by `test/web/**` directory, with per-project `setupFiles`
|
|
6
|
+
* and the React plugin on the web project), CalDAV-Bridge (split by directory
|
|
7
|
+
* with `happy-dom`). The two-file repos (Durable-DAV-Router, Mail-Otter) keep
|
|
8
|
+
* `defineUnitVitestConfig()` + `defineWebVitestConfig()`; this factory is the
|
|
9
|
+
* same two halves as `projects` entries in one file, sharing one root coverage
|
|
10
|
+
* gate.
|
|
11
|
+
*
|
|
12
|
+
* Canonical decisions (all three sources agree):
|
|
13
|
+
*
|
|
14
|
+
* 1. **Coverage lives at the root**, not per project: one floor for the whole
|
|
15
|
+
* unit suite. (Durable-DAV-Router's warning about a shared floor stands for
|
|
16
|
+
* the two-file split; within one file the three sources all gate once.)
|
|
17
|
+
* 2. **Each project repeats the alias table.** Vitest projects do not inherit
|
|
18
|
+
* the root `resolve` (Mail-Meow), so a suite resolving `@scope/*`
|
|
19
|
+
* differently from its sibling fails like a product bug. Both entries carry
|
|
20
|
+
* the full table — backend with `@/` → API, web with `@/` + `~/` → SPA.
|
|
21
|
+
* 3. **The web project keeps `pool: 'threads'`** and its DOM from
|
|
22
|
+
* `defineWebVitestConfig()`; the backend project keeps `environment:
|
|
23
|
+
* 'node'` and `server.deps.inline` from `defineUnitVitestConfig()`.
|
|
24
|
+
*/
|
|
25
|
+
import { defineConfig, type Plugin } from 'vitest/config';
|
|
26
|
+
import type { VitestAlias } from './vitest-aliases.ts';
|
|
27
|
+
import type { CoverageThresholds } from './vitest.ts';
|
|
28
|
+
/**
|
|
29
|
+
* The backend half of the `projects` pair.
|
|
30
|
+
*/
|
|
31
|
+
export interface RepoBackendOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Which suites to collect. Defaults to the whole unit suite minus SPA and
|
|
34
|
+
* integration shapes.
|
|
35
|
+
*/
|
|
36
|
+
readonly include?: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* Suite paths to skip, replacing the default.
|
|
39
|
+
*/
|
|
40
|
+
readonly exclude?: readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* Setup files run before each backend test file.
|
|
43
|
+
*/
|
|
44
|
+
readonly setupFiles?: readonly string[];
|
|
45
|
+
/**
|
|
46
|
+
* `node_modules` specifiers to inline through Vite. Defaults to `['dofs']`.
|
|
47
|
+
*/
|
|
48
|
+
readonly serverDepsInline?: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* Extra resolver entries for the backend project only.
|
|
51
|
+
*/
|
|
52
|
+
readonly aliases?: readonly VitestAlias[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The SPA half of the `projects` pair.
|
|
56
|
+
*/
|
|
57
|
+
export interface RepoWebOptions {
|
|
58
|
+
/**
|
|
59
|
+
* The DOM implementation. `jsdom` is the family default; `happy-dom` is
|
|
60
|
+
* CalDAV-Bridge's.
|
|
61
|
+
*/
|
|
62
|
+
readonly environment?: 'jsdom' | 'happy-dom';
|
|
63
|
+
/**
|
|
64
|
+
* Which suites to collect. Defaults to every SPA shape the family uses.
|
|
65
|
+
*/
|
|
66
|
+
readonly include?: readonly string[];
|
|
67
|
+
/**
|
|
68
|
+
* Suite paths to skip, replacing the default.
|
|
69
|
+
*/
|
|
70
|
+
readonly exclude?: readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* Setup files run before each SPA test file.
|
|
73
|
+
*/
|
|
74
|
+
readonly setupFiles?: readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
* Vite plugins the SPA needs (`react()` for JSX).
|
|
77
|
+
*/
|
|
78
|
+
readonly plugins?: readonly Plugin[];
|
|
79
|
+
/**
|
|
80
|
+
* Extra resolver entries for the web project only.
|
|
81
|
+
*/
|
|
82
|
+
readonly aliases?: readonly VitestAlias[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* What `defineRepoVitestConfig` accepts.
|
|
86
|
+
*/
|
|
87
|
+
export interface RepoVitestConfigOptions {
|
|
88
|
+
/**
|
|
89
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`.
|
|
90
|
+
*/
|
|
91
|
+
readonly scope: string;
|
|
92
|
+
/**
|
|
93
|
+
* Workspace package directory names. Defaults to the family superset.
|
|
94
|
+
*/
|
|
95
|
+
readonly packages?: readonly string[];
|
|
96
|
+
/**
|
|
97
|
+
* Which `cloudflare:*` mocks to alias. Defaults to workers/sockets/workflows.
|
|
98
|
+
*/
|
|
99
|
+
readonly mocks?: readonly string[];
|
|
100
|
+
/**
|
|
101
|
+
* The repo root, as a file URL.
|
|
102
|
+
*/
|
|
103
|
+
readonly root?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Extra resolver entries applied to *both* projects (e.g. the `hono`
|
|
106
|
+
* dedupe). Per-project extras go on `backend.aliases` / `web.aliases`.
|
|
107
|
+
*/
|
|
108
|
+
readonly aliases?: readonly VitestAlias[];
|
|
109
|
+
/**
|
|
110
|
+
* Resolver `noExternal` patterns, merged after {@link KIT_NO_EXTERNAL}.
|
|
111
|
+
*/
|
|
112
|
+
readonly noExternal?: readonly (string | RegExp)[];
|
|
113
|
+
/**
|
|
114
|
+
* The backend half. Omitted fields take the `defineUnitVitestConfig`
|
|
115
|
+
* defaults.
|
|
116
|
+
*/
|
|
117
|
+
readonly backend?: RepoBackendOptions;
|
|
118
|
+
/**
|
|
119
|
+
* The SPA half. Omitted fields take the `defineWebVitestConfig` defaults.
|
|
120
|
+
*/
|
|
121
|
+
readonly web?: RepoWebOptions;
|
|
122
|
+
/**
|
|
123
|
+
* Coverage `include` globs. Defaults to the worker, the SPA and every
|
|
124
|
+
* workspace package's `src`.
|
|
125
|
+
*/
|
|
126
|
+
readonly coverageInclude?: readonly string[];
|
|
127
|
+
/**
|
|
128
|
+
* Coverage `exclude` globs, merged with the canonical set.
|
|
129
|
+
*/
|
|
130
|
+
readonly coverageExclude?: readonly string[];
|
|
131
|
+
/**
|
|
132
|
+
* Coverage floors. Omitted by default; a repo that wants them sets them.
|
|
133
|
+
*/
|
|
134
|
+
readonly thresholds?: CoverageThresholds;
|
|
135
|
+
/**
|
|
136
|
+
* Where the coverage report is written.
|
|
137
|
+
*/
|
|
138
|
+
readonly reportsDirectory?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Build the single-file `projects` config.
|
|
142
|
+
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* // vitest.config.mts
|
|
145
|
+
* import { defineRepoVitestConfig } from '@rexezuge/tooling/vitest-repo';
|
|
146
|
+
* export default defineRepoVitestConfig({
|
|
147
|
+
* scope: '@myapp',
|
|
148
|
+
* web: { environment: 'happy-dom' },
|
|
149
|
+
* thresholds: { statements: 87, branches: 77, functions: 88, lines: 90 },
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function defineRepoVitestConfig(options: RepoVitestConfigOptions): ReturnType<typeof defineConfig>;
|
|
154
|
+
//# sourceMappingURL=vitest-repo.d.ts.map
|