Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.0 KB
Raw Blame
import { writeFile } from 'node:fs/promises'
import path from 'node:path'
import { createRequire } from 'node:module'
import * as esbuild from 'esbuild'

const require = createRequire(import.meta.url)
const mobileRoot = path.resolve(import.meta.dirname, '..')
const outputPath = path.join(
  mobileRoot,
  'src',
  'components',
  'pr-sidebar',
  'mermaid-page-engine.generated.ts'
)

// Bundle mermaid as one deferred module: internal lazy imports otherwise emit 103 assets against the shell’s 256 cap, despite all bytes already being downloaded.
// Unlike WebView engine’s string artifact, page evaluates this source module typed by mermaid-page-engine.ts.
async function main() {
  const { version } = require(require.resolve('mermaid/package.json'))
  const { outputFiles } = await esbuild.build({
    absWorkingDir: mobileRoot,
    stdin: {
      contents: "export { default } from 'mermaid'\n",
      resolveDir: mobileRoot,
      loader: 'ts',
      sourcefile: 'mermaid-page-engine-entry.ts'
    },
    bundle: true,
    format: 'esm',
    splitting: false,
    // Metro transforms this module again; preserve enum assignments for its export analysis.
    minifyWhitespace: true,
    minifyIdentifiers: true,
    minifySyntax: false,
    // The floor the shell's WebViews hold, the same pair the terminal engine is built for.
    target: ['chrome74', 'safari15'],
    write: false,
    charset: 'utf8',
    legalComments: 'none',
    logLevel: 'silent',
    nodePaths: [path.join(mobileRoot, 'node_modules')],
    define: { 'process.env.NODE_ENV': '"production"' }
  })
  const bundle = Buffer.from(outputFiles[0].contents).toString('utf8')
  const source = [
    '// Generated by scripts/build-mermaid-page-engine.mjs.',
    `// Package: mermaid@${version}, bundled as one ESM module for the page.`,
    '// Do not edit by hand; regenerate via pnpm postinstall.',
    '// @ts-nocheck -- minified vendor output; mermaid-page-engine.ts is where this is typed.',
    bundle,
    ''
  ].join('\n')
  await writeFile(outputPath, source)
}

await main()