feat(plugins): localize optional feature previews
This commit is contained in:
1 parent
fb752c7763
commit
37dbd15e0c
31 files changed
+220
-48
No files matched your search
@@ -312,7 +312,13 @@ describe('package payload constraints', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it.each(['icon.svg', 'preview.svg'])('accepts the badge skill artwork payload and rejects omission of %s', (image) => {
|
||||
it('includes each localized preview in the published payload without duplicate paths', () => {
|
||||
expect(expectedDshPackageFiles({ preview: { en: './preview.svg', zh: './preview.zh.svg', fr: './preview.svg' } })).toEqual([
|
||||
'preview.svg', 'preview.zh.svg', 'lib/index.js', 'lib/types/**/*.d.ts',
|
||||
])
|
||||
})
|
||||
|
||||
it.each(['icon.svg', 'preview.svg', 'preview.zh.svg'])('accepts the badge skill artwork payload and rejects omission of %s', (image) => {
|
||||
const dir = 'packages/experimental/badge-skill-bundle'
|
||||
const manifest = JSON.parse(readFileSync(new URL(`../${dir}/package.json`, import.meta.url), 'utf8')) as WorkspaceManifest['manifest']
|
||||
expect(checkWorkspaceManifest({ dir, manifest })).toEqual([])
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
PRIVATE_EXPERIMENTAL_PACKAGE_DIRECTORIES,
|
||||
} from './experimental-package-policy.ts'
|
||||
import { hasTypertRemoteNavigation, isForbiddenPublicationFile } from './publication-payload.ts'
|
||||
import type { DshBundleManifest } from '../packages/util/package-manifest/src/types.ts'
|
||||
import type { DshBundleManifest, LocalizedText } from '../packages/util/package-manifest/src/types.ts'
|
||||
import { OPTIONAL_BUNDLES, bundlePatchFiles } from '../packages/boot/app-boot/src/profile.ts'
|
||||
import { collectProjectReferenceFaceViolations } from './project-reference-faces.ts'
|
||||
|
||||
@@ -85,7 +85,7 @@ export interface PackageManifest {
|
||||
exports?: Record<string, ExportTarget | undefined>
|
||||
files?: string[]
|
||||
icon?: string
|
||||
preview?: string
|
||||
preview?: LocalizedText
|
||||
publishConfig?: { access?: string }
|
||||
repository?: { type?: string; url?: string; directory?: string }
|
||||
peerDependencies?: Record<string, string>
|
||||
@@ -259,7 +259,7 @@ export function expectedDshPackageFiles(manifest: PackageManifest): readonly str
|
||||
const targets = (value: ExportTarget | undefined): string[] => typeof value === 'string' ? [value]
|
||||
: typeof value === 'object' && value !== null ? Object.values(value).flatMap(targets) : []
|
||||
const images = [
|
||||
...[manifest.icon, manifest.preview].flatMap(image => typeof image === 'string' ? [image.replace(/^\.\//u, '')] : []),
|
||||
...[manifest.icon, manifest.preview].flatMap(targets).map(image => image.replace(/^\.\//u, '')),
|
||||
...Object.entries(manifest.exports ?? {}).filter(([key]) => /^\.\/(?:.+\/)?(?:icon|preview)$/u.test(key))
|
||||
.flatMap(([, target]) => targets(target)).filter(icon => icon.startsWith('./')).map(icon => icon.slice(2)),
|
||||
]
|
||||
|
||||
@@ -67,6 +67,19 @@ describe('Official bundle catalog generation', () => {
|
||||
expect(renderOfficialBundleCatalog(entries)).toContain(`preview: '${preview}'`)
|
||||
})
|
||||
|
||||
it('preserves translated preview images in offline discovery', () => {
|
||||
const root = fixture()
|
||||
const name = ON_DEMAND_BUNDLES[0]!
|
||||
updateManifest(root, name, { preview: { en: './preview.png', zh: './preview.zh.png' } })
|
||||
write(root, `${directory(name)}/preview.png`, 'English')
|
||||
write(root, `${directory(name)}/preview.zh.png`, '中文')
|
||||
const entries = generateOfficialBundleCatalog(root)
|
||||
const en = `data:image/png;base64,${Buffer.from('English').toString('base64')}`
|
||||
const zh = `data:image/png;base64,${Buffer.from('中文').toString('base64')}`
|
||||
expect(entries[0]?.meta.preview).toEqual({ en, zh })
|
||||
expect(renderOfficialBundleCatalog(entries)).toContain(`preview: { 'en': '${en}', 'zh': '${zh}' }`)
|
||||
})
|
||||
|
||||
it.each(['private', 'not-bundle', 'missing', 'duplicate'])('rejects %s catalog membership', (kind) => {
|
||||
const root = fixture()
|
||||
const name = ON_DEMAND_BUNDLES[0]!
|
||||
|
||||
@@ -95,7 +95,7 @@ export function renderOfficialBundleCatalog(entries: readonly OfficialBundleCata
|
||||
+ ` title: ${localized(entry.meta.title)},\n`
|
||||
+ ` description: ${localized(entry.meta.description)},\n`
|
||||
+ ` icon: ${quote(entry.meta.icon)},\n`
|
||||
+ (entry.meta.preview === undefined ? '' : ` preview: ${quote(entry.meta.preview)},\n`)
|
||||
+ (entry.meta.preview === undefined ? '' : ` preview: ${localized(entry.meta.preview)},\n`)
|
||||
+ ' },\n },\n').join('')
|
||||
+ ']\n'
|
||||
}
|
||||
|
||||
@@ -67,6 +67,18 @@ it('requires optional preview files to be published', () => {
|
||||
expect(packageMetaProblems(root)).toEqual([`${join(dir, 'package.json')}: files must include preview.png`])
|
||||
})
|
||||
|
||||
it('validates every localized preview and requires each variant in the published package', () => {
|
||||
const preview = { en: './preview.svg', ZH: './preview.zh.svg' }
|
||||
manifest({ preview, files: ['preview.svg'] })
|
||||
file('preview.svg', validSvg)
|
||||
file('preview.zh.svg', validSvg)
|
||||
expect(packageMetaProblems(root)).toEqual([`${join(dir, 'package.json')}: files must include preview.zh.svg`])
|
||||
manifest({ preview, files: ['preview*.svg'] })
|
||||
expect(packageMetaProblems(root)).toEqual([])
|
||||
file('preview.zh.svg', validSvg.replace('<path ', '<script>run()</script><path '))
|
||||
expect(packageMetaProblems(root).join('\n')).toContain('preview.zh.svg: SVG preview must use self-contained geometry')
|
||||
})
|
||||
|
||||
it('requires preview declarations to be discoverable', () => {
|
||||
manifest({ preview: './preview.png', exports: { '.': './lib/index.js' }, files: ['preview.png'] })
|
||||
file('preview.png', 'image')
|
||||
|
||||
@@ -198,16 +198,21 @@ function packageProblems(manifestPath: string, parser: DOMParser): string[] {
|
||||
if (sourceManifest && resources.every(({ file }) => byPath.has(file))) {
|
||||
const meta = readPluginMeta(specifier, parentURL)
|
||||
if (meta?.error !== undefined) problems.push(meta.error)
|
||||
const imageTargets = imageFields.map((field) => {
|
||||
const imageTargets = imageFields.flatMap((field) => {
|
||||
const image = meta?.[field]
|
||||
if (image === undefined) return undefined
|
||||
const path = displayDocument?.[field]
|
||||
const target = displayManifest !== undefined && typeof path === 'string'
|
||||
? resolve(dirname(displayManifest), path) : lookup(`${specifier}/${field}`)
|
||||
if (pkg.name.startsWith('@deepseek-ai/dsh-')) {
|
||||
problems.push(...svgArtworkProblems(image, parser, field).map(problem => `${target ?? specifier}: ${problem}`))
|
||||
}
|
||||
return target
|
||||
if (image === undefined) return []
|
||||
const declaration = displayDocument?.[field]
|
||||
const variants = typeof image === 'string' ? [['', image] as const] : Object.entries(image)
|
||||
return variants.map(([language, data]) => {
|
||||
const path: unknown = typeof declaration === 'object' && declaration !== null
|
||||
? Object.entries(declaration).find(([key]) => key.toLowerCase() === language)?.[1] : declaration
|
||||
const target = displayManifest !== undefined && typeof path === 'string'
|
||||
? resolve(dirname(displayManifest), path) : lookup(`${specifier}/${field}`)
|
||||
if (pkg.name.startsWith('@deepseek-ai/dsh-')) {
|
||||
problems.push(...svgArtworkProblems(data, parser, field).map(problem => `${target ?? specifier}: ${problem}`))
|
||||
}
|
||||
return target
|
||||
})
|
||||
})
|
||||
for (const target of [displayManifest, ...imageTargets]) {
|
||||
if (target === undefined) continue
|
||||
|
||||
Reference in new issue
Block a user