mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(plugins): build-less TS/TSX plugins, typings and authoring tools - Plugin frames transpile .ts/.tsx/.mts/.jsx on load (sucrase on a shared worker thread with a 2 s budget, cached in main), resolve relative imports to exact files, and refuse bare package imports by name. Components and html panel/editor entries may be .ts/.tsx. - orca plugin types writes typings for the components orca module, window.orca, worker activate(orca), host.call and events into .orca/types, from one host-typings generator. - orca plugin create --template components; templates omit publisher and target 1.4.246. - orca plugin release-entry, dev inspect and restart; validate:plugin checks named files. - Guest console errors reach orca plugin logs; dev workers restart on edits; the dev watcher ignores .git, .orca and node_modules; Git and folder installs cannot replace catalog installs. - examples/plugins/hello-tsx, docs, and the plugin-buildless-tsx e2e spec. * ci: run the Windows parity probes with one tsgo checker tsconfig.node peaks near 22 GB with tsgo's default four checkers (each holds its own types) and about 16 GB with one; the 16 GB Windows runner paged the native probe past its 900 s timeout once this branch's package.json change triggered the job. One checker gives the same diagnostics (verified locally with --parity-only); the timing benchmark is unchanged.
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import type { Plugin } from 'vite'
|
|
|
|
/** Sucrase transformers plugin frames never enable; each embeds a bare `require('…')` as code text. */
|
|
const UNUSED_TRANSFORMERS = /^\.\/(?:FlowTransformer|ReactHotLoaderTransformer)(?:\.js)?$/
|
|
const SUCRASE_TRANSFORMERS_DIR =
|
|
/[\\/]node_modules[\\/]sucrase[\\/]dist[\\/](?:esm[\\/])?transformers[\\/]/
|
|
const STUB_ID = '\0orca-sucrase-unused-transformer'
|
|
|
|
export const SUCRASE_UNUSED_TRANSFORMER_STUB =
|
|
"export default class UnusedSucraseTransformer {\n constructor() {\n throw new Error('this sucrase transform is not bundled in Orca')\n }\n}\n"
|
|
|
|
/** The stub's id when sucrase's transformer index imports an unused transformer; else null. */
|
|
export function resolveSucraseUnusedTransformer(
|
|
source: string,
|
|
importer: string | undefined
|
|
): string | null {
|
|
return importer && SUCRASE_TRANSFORMERS_DIR.test(importer) && UNUSED_TRANSFORMERS.test(source)
|
|
? STUB_ID
|
|
: null
|
|
}
|
|
|
|
/**
|
|
* Replaces sucrase's flow and react-hot-loader transformers with a stub that throws. Why: their
|
|
* emitted `require('flow-enums-runtime')` / `require('react-hot-loader')` strings read as runtime
|
|
* imports to the packaged-dependency check, and the transpile worker only uses typescript and jsx.
|
|
*/
|
|
export function createSucraseUnusedTransformersPlugin(): Plugin {
|
|
return {
|
|
name: 'orca-sucrase-unused-transformers',
|
|
enforce: 'pre',
|
|
resolveId: resolveSucraseUnusedTransformer,
|
|
load: (id) => (id === STUB_ID ? SUCRASE_UNUSED_TRANSFORMER_STUB : null)
|
|
}
|
|
}
|