Compare commits

...
6 Commits
Author SHA1 Message Date
yiling edd550b9f2 Release v0.0.4 2026-06-12 22:02:39 +08:00
Yiling-J ea71954deb Merge pull request #100 from shumaiOne/fix/npm-external-resolution
fix(cli/docker): resolve global CLI external dependencies and fix Docker 404 error
2026-06-12 21:56:22 +08:00
yiling dc63ab3eaf fix(npm): resolve binary output path mapping in build-npm script 2026-06-12 21:54:15 +08:00
yiling d06dfc0ab3 perf(npm): optimize platform binary compilation using dummy runner 2026-06-12 21:50:18 +08:00
yiling 84aa1662be fix(docker): align build output structure and fix web 404 error 2026-06-12 21:24:59 +08:00
yiling 91fedf1477 fix(cli): resolve all external module imports in global CLI package 2026-06-12 21:08:40 +08:00
16 changed files with 183 additions and 63 deletions
+1 -1
View File
@@ -70,4 +70,4 @@ COPY --chown=bun:bun --from=builder /app/prisma.config.ts.prod ./prisma.config.t
EXPOSE 3000 EXPOSE 3000
# Default command: run migrations and start API server # Default command: run migrations and start API server
CMD ["sh", "-c", "bun prisma migrate deploy && bun apps/web/src/index.js"] CMD ["sh", "-c", "bun prisma migrate deploy && bun index.js"]
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/agent-app", "name": "@shumai/agent-app",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/transcode-app", "name": "@shumai/transcode-app",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/web-app", "name": "@shumai/web-app",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"dependencies": { "dependencies": {
+64 -17
View File
@@ -1,3 +1,4 @@
import { join } from 'node:path'
import { loadEnvConfig } from '@shumai/core/src/env-loader' import { loadEnvConfig } from '@shumai/core/src/env-loader'
loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production') loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production')
@@ -41,25 +42,71 @@ if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
Promise.all(queuesToStart.map((q) => workflowService.startWorkers(q))).catch(console.error) Promise.all(queuesToStart.map((q) => workflowService.startWorkers(q))).catch(console.error)
} }
const server = Bun.serve({ const isProd = process.env.NODE_ENV === 'production'
port: 3000,
fetch: app.fetch,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
routes: {
// Serve index.html for root
'/': index,
// Proxy API requests to Hono const server = Bun.serve(
'/api/*': app.fetch, isProd
'/files/*': app.fetch, ? {
port: 3000,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
development: false,
async fetch(req) {
const url = new URL(req.url)
// Catch-all for SPA routing (fallback to index.html) if (!url.pathname.startsWith('/api/') && !url.pathname.startsWith('/files/')) {
'/*': index, const filepath = join(import.meta.dir, url.pathname)
}, const file = Bun.file(filepath)
development: process.env.NODE_ENV !== 'production', if (await file.exists()) {
}) try {
const stat = await file.stat()
if (stat.isFile()) {
return new Response(file)
}
} catch {
// ignore stat errors
}
}
const htmlFile = Bun.file(join(import.meta.dir, 'index.html'))
if (await htmlFile.exists()) {
return new Response(htmlFile, {
headers: { 'Content-Type': 'text/html' },
})
}
const htmlFileNpm = Bun.file(join(import.meta.dir, 'shumai-app.html'))
if (await htmlFileNpm.exists()) {
return new Response(htmlFileNpm, {
headers: { 'Content-Type': 'text/html' },
})
}
}
return app.fetch(req)
},
}
: {
port: 3000,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
development: true,
fetch: app.fetch,
routes: {
// Serve index.html for root
'/': index,
// Proxy API requests to Hono
'/api/*': app.fetch,
'/files/*': app.fetch,
// Catch-all for SPA routing (fallback to index.html)
'/*': index,
},
},
)
console.log(`🚀 Server running at ${server.url}`) console.log(`🚀 Server running at ${server.url}`)
+1
View File
@@ -20,6 +20,7 @@ await Bun.build({
target: 'bun', target: 'bun',
outdir: outdir, outdir: outdir,
minify: false, minify: false,
naming: '[name].[ext]',
plugins: [ plugins: [
temporalWorkflow({ temporalWorkflow({
bundleOptions: {}, bundleOptions: {},
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "shumai", "name": "shumai",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"repository": { "repository": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/agent", "name": "@shumai/agent",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/api", "name": "@shumai/api",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/core", "name": "@shumai/core",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/db", "name": "@shumai/db",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/dtos", "name": "@shumai/dtos",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/transcode", "name": "@shumai/transcode",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/webui", "name": "@shumai/webui",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./index.html", "main": "./index.html",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/workflow-core", "name": "@shumai/workflow-core",
"version": "0.0.3", "version": "0.0.4",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+105 -33
View File
@@ -1,4 +1,4 @@
import { rm, mkdir, cp, writeFile } from 'node:fs/promises' import { rm, mkdir, cp, writeFile, readdir } from 'node:fs/promises'
import { existsSync } from 'node:fs' import { existsSync } from 'node:fs'
import path from 'node:path' import path from 'node:path'
import tailwindPlugin from 'bun-plugin-tailwind' import tailwindPlugin from 'bun-plugin-tailwind'
@@ -16,6 +16,9 @@ if (existsSync(distDir)) {
} }
await mkdir(distDir, { recursive: true }) await mkdir(distDir, { recursive: true })
const dummyRunnerPath = path.join(distDir, 'dummy-runner.ts')
await writeFile(dummyRunnerPath, '// Shumai Runner Stub\n', 'utf-8')
const rootPackageJson = JSON.parse(await Bun.file('package.json').text()) const rootPackageJson = JSON.parse(await Bun.file('package.json').text())
const version = rootPackageJson.version || '0.1.0' const version = rootPackageJson.version || '0.1.0'
@@ -112,21 +115,18 @@ async function compileApp({
process.exit(1) process.exit(1)
} }
// Rename generated binary (usually Bun names it 'src' or the folder name of the entrypoint) // Rename generated binary dynamically by finding the output file in outdir
const generatedFile = path.join(outdir, 'src')
const generatedFileExe = path.join(outdir, 'src.exe')
const finalFile = path.join(outdir, binaryName) const finalFile = path.join(outdir, binaryName)
const files = await readdir(outdir)
const generatedFilename = files.find((f) => f !== binaryName)
if (existsSync(generatedFile)) { if (generatedFilename) {
const generatedPath = path.join(outdir, generatedFilename)
console.log(`➡️ Moving binary to final location: ${finalFile}`) console.log(`➡️ Moving binary to final location: ${finalFile}`)
await cp(generatedFile, finalFile) await cp(generatedPath, finalFile)
await rm(generatedFile) await rm(generatedPath)
} else if (existsSync(generatedFileExe)) { } else if (!existsSync(finalFile)) {
console.log(`➡️ Moving binary to final location: ${finalFile}`) console.error(`❌ Could not find compiled binary in ${outdir}`)
await cp(generatedFileExe, finalFile)
await rm(generatedFileExe)
} else {
console.error(`❌ Could not find compiled binary at ${generatedFile} or ${generatedFileExe}`)
process.exit(1) process.exit(1)
} }
} }
@@ -173,17 +173,62 @@ async function buildPlatformPackages(
} }
// Function to build main wrapper package // Function to build main wrapper package
async function buildMainPackage( // Function to build main wrapper package
appName: string, async function buildMainPackage({
description: string, appName,
hasPrisma: boolean, description,
extraDependencies: Record<string, string> = {}, hasPrisma,
) { entrypoint,
plugins = [],
extraDependencies = {},
}: {
appName: string
description: string
hasPrisma: boolean
entrypoint: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
plugins?: any[]
extraDependencies?: Record<string, string>
}) {
console.log(`\n📄 Packaging wrapper app ${appName}...`) console.log(`\n📄 Packaging wrapper app ${appName}...`)
const mainOutDir = path.join(distDir, appName) const mainOutDir = path.join(distDir, appName)
const binOutDir = path.join(mainOutDir, 'bin') const binOutDir = path.join(mainOutDir, 'bin')
await mkdir(binOutDir, { recursive: true }) await mkdir(binOutDir, { recursive: true })
// 1. Bundle the JS application code for wrapper
console.log(`📦 Bundling JS application code for wrapper ${appName}...`)
const appJsName = `${appName}-app.js`
const buildResult = await Bun.build({
entrypoints: [entrypoint],
root: '.',
target: 'bun',
outdir: binOutDir,
minify: true,
naming: `${appName}-app.[ext]`,
plugins,
external: commonExternal,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
publicPath: '/',
})
if (!buildResult.success) {
console.error(`❌ JS bundling failed for ${appName}!`)
for (const log of buildResult.logs) {
console.error(log)
}
process.exit(1)
}
// Confirm that the bundle exists
const finalJsFile = path.join(binOutDir, appJsName)
if (!existsSync(finalJsFile)) {
console.error(`❌ Could not find compiled JS bundle at ${finalJsFile}`)
process.exit(1)
}
// Write JS wrapper script // Write JS wrapper script
const wrapperContent = `#!/usr/bin/env node const wrapperContent = `#!/usr/bin/env node
import { spawn } from 'node:child_process' import { spawn } from 'node:child_process'
@@ -239,8 +284,14 @@ if (!binaryPath) {
process.exit(1) process.exit(1)
} }
const child = spawn(binaryPath, process.argv.slice(2), { const appJsPath = join(__dirname, '${appName}-app.js')
const child = spawn(binaryPath, ['run', appJsPath, ...process.argv.slice(2)], {
stdio: 'inherit', stdio: 'inherit',
env: {
...process.env,
BUN_BE_BUN: '1',
},
}) })
child.on('close', (code) => { child.on('close', (code) => {
@@ -301,32 +352,53 @@ child.on('error', (err) => {
} }
// 2. Build shumai (Main app & platform binaries) // 2. Build shumai (Main app & platform binaries)
await buildPlatformPackages('shumai', './apps/web/src/index.ts', [ const shumaiPlugins = [
temporalWorkflow({ temporalWorkflow({
bundleOptions: {}, bundleOptions: {},
}), }),
tailwindPlugin, tailwindPlugin,
]) ]
await buildMainPackage('shumai', 'A fullstack AI-powered media workspace and workflow engine', true) await buildPlatformPackages('shumai', dummyRunnerPath)
await buildMainPackage({
appName: 'shumai',
description: 'A fullstack AI-powered media workspace and workflow engine',
hasPrisma: true,
entrypoint: './apps/web/src/index.ts',
plugins: shumaiPlugins,
})
// 3. Build shumai-agent (Agent app & platform binaries) // 3. Build shumai-agent (Agent app & platform binaries)
await buildPlatformPackages('shumai-agent', './apps/agent/src/index.ts', [ const agentPlugins = [
temporalWorkflow({ temporalWorkflow({
bundleOptions: {}, bundleOptions: {},
}), }),
]) ]
await buildMainPackage('shumai-agent', 'AI worker agent for the shumai media workspace', false) await buildPlatformPackages('shumai-agent', dummyRunnerPath)
await buildMainPackage({
appName: 'shumai-agent',
description: 'AI worker agent for the shumai media workspace',
hasPrisma: false,
entrypoint: './apps/agent/src/index.ts',
plugins: agentPlugins,
})
// 4. Build shumai-transcode (Transcode app & platform binaries) // 4. Build shumai-transcode (Transcode app & platform binaries)
await buildPlatformPackages('shumai-transcode', './apps/transcode/src/index.ts', [ const transcodePlugins = [
temporalWorkflow({ temporalWorkflow({
bundleOptions: {}, bundleOptions: {},
}), }),
]) ]
await buildMainPackage( await buildPlatformPackages('shumai-transcode', dummyRunnerPath)
'shumai-transcode', await buildMainPackage({
'Media transcoding worker for the shumai media workspace', appName: 'shumai-transcode',
false, description: 'Media transcoding worker for the shumai media workspace',
) hasPrisma: false,
entrypoint: './apps/transcode/src/index.ts',
plugins: transcodePlugins,
})
if (existsSync(dummyRunnerPath)) {
await rm(dummyRunnerPath)
}
console.log('\n✅ All applications and platform binaries built and packaged successfully!') console.log('\n✅ All applications and platform binaries built and packaged successfully!')