Files
ComfyUI_frontend/scripts/prepare-workflow-validation.ts
Glary-Bot 1f795c7fbe fix(validation): address CodeRabbit review feedback
- linkRepair: `continue` on `idx === -1` so we don't `splice(-1, 1)`
  and clobber the last unrelated link.
- linkTopology: report origin- and target-slot-out-of-bounds errors
  independently for the same link instead of bailing after the first.
- useWorkflowValidation: re-throw non-`LinkRepairAbortedError` failures
  so unrelated bugs don't get silently downgraded to an aborted load.
- useWorkflowValidation: route every toast string through
  `vue-i18n` (`validation.topology.*` keys in
  `src/locales/en/main.json`).
- Convert `scripts/prepare-workflow-validation.js` to TypeScript per
  repo policy and run it via `tsx`. Make the catalog regex robust by
  appending a synthetic terminator instead of changing the existing
  `\\n\\S` semantics, which broke for the multiline catalog block.
- Add object-form link tests covering the both-shapes contract.
2026-05-03 06:33:07 +00:00

97 lines
2.6 KiB
TypeScript

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const repoRoot = path.resolve(__dirname, '..')
const packageDir = path.join(repoRoot, 'packages', 'workflow-validation')
const distDir = path.join(packageDir, 'dist')
interface SourcePackage {
name: string
version: string
description?: string
license?: string
repository?: string
homepage?: string
dependencies?: Record<string, string>
publishConfig?: Record<string, unknown>
}
const sourcePackage = JSON.parse(
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')
) as SourcePackage
const workspaceYaml =
fs
.readFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), 'utf8')
.replace(/\r\n/g, '\n') + '\n___end:'
const workspaceCatalog =
workspaceYaml.match(/^catalog:\n([\s\S]*?)\n\S/m)?.[1] ?? ''
function resolveCatalog(name: string): string {
const sourceVersion = sourcePackage.dependencies?.[name]
if (sourceVersion && sourceVersion !== 'catalog:') return sourceVersion
const re = new RegExp(`^\\s+'?${name}'?:\\s*([^\\n]+)$`, 'm')
const match = workspaceCatalog.match(re)
if (!match) {
throw new Error(
`Could not resolve catalog version for ${name}. ` +
`Expected entry under \`catalog:\` in pnpm-workspace.yaml.`
)
}
return match[1]!.trim()
}
const distPackage = {
name: sourcePackage.name,
version: sourcePackage.version,
description: sourcePackage.description,
license: sourcePackage.license,
repository: sourcePackage.repository,
homepage: sourcePackage.homepage,
type: 'module',
main: './index.js',
module: './index.js',
types: './index.d.ts',
exports: {
'.': {
types: './index.d.ts',
import: './index.js'
},
'./linkRepair': {
types: './linkRepair.d.ts',
import: './index.js'
},
'./linkTopology': {
types: './linkTopology.d.ts',
import: './index.js'
},
'./workflowSchema': {
types: './workflowSchema.d.ts',
import: './index.js'
},
'./serialised': {
types: './serialised.d.ts',
import: './index.js'
}
},
files: ['*.js', '*.d.ts'],
publishConfig: sourcePackage.publishConfig ?? { access: 'public' },
dependencies: {
zod: resolveCatalog('zod'),
'zod-validation-error': resolveCatalog('zod-validation-error')
}
}
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true })
}
fs.writeFileSync(
path.join(distDir, 'package.json'),
JSON.stringify(distPackage, null, 2) + '\n'
)
console.warn(`Prepared ${distPackage.name}@${distPackage.version} in dist/`)