mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-07-09 09:14:07 +08:00
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com> Signed-off-by: jd <59188306+zhangjiadi225@users.noreply.github.com>
42 lines
2.1 KiB
TypeScript
42 lines
2.1 KiB
TypeScript
/**
|
|
* Bundling contract for `@cherrystudio/provider-registry`.
|
|
*
|
|
* The package is INTERNAL and source-resolved (`private`, no published `dist`). The main-process Rollup
|
|
* build externalizes every root `dependencies` entry (electron.vite.config.ts `mainExternalDependencies`),
|
|
* so if this package were a `dependency` it would be externalized and resolve to
|
|
* `node_modules/@cherrystudio/provider-registry/dist/*` — which is never built — and a packaged app would
|
|
* crash at runtime with MODULE_NOT_FOUND. It must stay a `devDependency` (bundled from source via the
|
|
* `@cherrystudio/provider-registry` alias). This is the build/pack smoke check guarding that contract.
|
|
*/
|
|
import * as fs from 'node:fs'
|
|
import * as path from 'node:path'
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { isMainExternalModule } from '../../electron.vite.config'
|
|
|
|
const root = path.resolve(__dirname, '..', '..')
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
const viteConfig = fs.readFileSync(path.join(root, 'electron.vite.config.ts'), 'utf8')
|
|
|
|
describe('@cherrystudio/provider-registry bundling contract', () => {
|
|
it('is a devDependency (bundled from source), never an externalized root dependency', () => {
|
|
expect(pkg.devDependencies?.['@cherrystudio/provider-registry']).toBeDefined()
|
|
expect(pkg.dependencies?.['@cherrystudio/provider-registry']).toBeUndefined()
|
|
})
|
|
|
|
it('is source-aliased in electron.vite.config.ts so the main build bundles src, not dist', () => {
|
|
expect(viteConfig).toMatch(/'@cherrystudio\/provider-registry':\s*resolve\('packages\/provider-registry\/src'\)/)
|
|
expect(viteConfig).toMatch(
|
|
/'@cherrystudio\/provider-registry\/node':\s*resolve\('packages\/provider-registry\/src\/registry-loader'\)/
|
|
)
|
|
})
|
|
|
|
it('externalizes dependency subpath imports in the main build', () => {
|
|
expect(isMainExternalModule('pdf-parse')).toBe(true)
|
|
expect(isMainExternalModule('pdf-parse/worker')).toBe(true)
|
|
expect(isMainExternalModule('@cherrystudio/provider-registry')).toBe(false)
|
|
expect(isMainExternalModule('@cherrystudio/provider-registry/node')).toBe(false)
|
|
})
|
|
})
|