fix: scripts support win32 (#12613)

Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
huangkairan
2026-03-03 19:19:56 +08:00
committed by GitHub
parent 138788b1d4
commit 1cf0257326
10 changed files with 40 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ on:
branches: [canary] branches: [canary]
paths: paths:
- 'apps/device-gateway/**' - 'apps/device-gateway/**'
workflow_dispatch: workflow_dispatch: {}
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}

View File

@@ -3,8 +3,8 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "wrangler dev",
"deploy": "wrangler deploy", "deploy": "wrangler deploy",
"dev": "wrangler dev",
"type-check": "tsc --noEmit" "type-check": "tsc --noEmit"
}, },
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
import { DurableObject } from 'cloudflare:workers'; import { DurableObject } from 'cloudflare:workers';
import { DeviceAttachment, Env } from './types'; import type { DeviceAttachment, Env } from './types';
export class DeviceGatewayDO extends DurableObject<Env> { export class DeviceGatewayDO extends DurableObject<Env> {
private pendingRequests = new Map< private pendingRequests = new Map<
@@ -95,7 +95,11 @@ export class DeviceGatewayDO extends DurableObject<Env> {
); );
} }
const { deviceId, timeout = 30_000, toolCall } = (await request.json()) as { const {
deviceId,
timeout = 30_000,
toolCall,
} = (await request.json()) as {
deviceId?: string; deviceId?: string;
timeout?: number; timeout?: number;
toolCall: unknown; toolCall: unknown;

View File

@@ -1,6 +1,6 @@
import { importJWK, jwtVerify } from 'jose'; import { importJWK, jwtVerify } from 'jose';
import { Env } from './types'; import type { Env } from './types';
let cachedKey: CryptoKey | null = null; let cachedKey: CryptoKey | null = null;

View File

@@ -1,6 +1,6 @@
import { verifyDesktopToken } from './auth'; import { verifyDesktopToken } from './auth';
import { DeviceGatewayDO } from './DeviceGatewayDO'; import { DeviceGatewayDO } from './DeviceGatewayDO';
import { Env } from './types'; import type { Env } from './types';
export { DeviceGatewayDO }; export { DeviceGatewayDO };

View File

@@ -39,7 +39,7 @@
"build:docker": "pnpm run build:spa && pnpm run build:spa:mobile && pnpm run build:spa:copy && cross-env NODE_OPTIONS=--max-old-space-size=8192 DOCKER=true next build && pnpm run build-sitemap", "build:docker": "pnpm run build:spa && pnpm run build:spa:mobile && pnpm run build:spa:copy && cross-env NODE_OPTIONS=--max-old-space-size=8192 DOCKER=true next build && pnpm run build-sitemap",
"build:next": "cross-env NODE_OPTIONS=--max-old-space-size=6144 next build", "build:next": "cross-env NODE_OPTIONS=--max-old-space-size=6144 next build",
"build:spa": "rm -rf public/spa && cross-env NODE_OPTIONS=--max-old-space-size=6144 vite build", "build:spa": "rm -rf public/spa && cross-env NODE_OPTIONS=--max-old-space-size=6144 vite build",
"build:spa:copy": "mkdir -p public/spa && for dir in assets i18n vendor; do ([ -d dist/desktop/$dir ] && cp -r dist/desktop/$dir public/spa/ || true) && ([ -d dist/mobile/$dir ] && cp -r dist/mobile/$dir public/spa/ || true); done && tsx scripts/generateSpaTemplates.mts", "build:spa:copy": "tsx scripts/copySpaBuild.mts && tsx scripts/generateSpaTemplates.mts",
"build:spa:mobile": "cross-env NODE_OPTIONS=--max-old-space-size=8192 MOBILE=true vite build", "build:spa:mobile": "cross-env NODE_OPTIONS=--max-old-space-size=8192 MOBILE=true vite build",
"build:vercel": "bun run build && bun run db:migrate", "build:vercel": "bun run build && bun run db:migrate",
"build-migrate-db": "bun run db:migrate", "build-migrate-db": "bun run db:migrate",

View File

@@ -1,7 +1,7 @@
{ {
"extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "./dist" "outDir": "./dist"
}, },
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"] "include": ["src/**/*.ts"]
} }

View File

@@ -1,9 +1,9 @@
import { type UserMemoryData } from '@lobechat/prompts'; import { type UserMemoryData } from '@lobechat/prompts';
import { promptUserMemory } from '@lobechat/prompts'; import { promptUserMemory } from '@lobechat/prompts';
import debug from 'debug'; import debug from 'debug';
import { BaseFirstUserContentProvider } from '../base/BaseFirstUserContentProvider'; import { BaseFirstUserContentProvider } from '../base/BaseFirstUserContentProvider';
import { type PipelineContext, type ProcessorOptions } from '../types'; import { type PipelineContext, type ProcessorOptions } from '../types';
const log = debug('context-engine:provider:UserMemoryInjector'); const log = debug('context-engine:provider:UserMemoryInjector');

21
scripts/copySpaBuild.mts Normal file
View File

@@ -0,0 +1,21 @@
import { cpSync, existsSync, mkdirSync } from 'node:fs';
import path from 'node:path';
const root = path.resolve(import.meta.dirname, '..');
const spaDir = path.resolve(root, 'public/spa');
const distDirs = ['desktop', 'mobile'] as const;
const copyDirs = ['assets', 'i18n', 'vendor'] as const;
mkdirSync(spaDir, { recursive: true });
for (const distDir of distDirs) {
for (const dir of copyDirs) {
const sourceDir = path.resolve(root, `dist/${distDir}/${dir}`);
const targetDir = path.resolve(spaDir, dir);
if (!existsSync(sourceDir)) continue;
cpSync(sourceDir, targetDir, { recursive: true });
console.log(`Copied dist/${distDir}/${dir} -> public/spa/${dir}`);
}
}

View File

@@ -1,7 +1,7 @@
import { type ChildProcess, spawn } from 'node:child_process'; import { type ChildProcess, spawn } from 'node:child_process';
import { readFileSync } from 'node:fs'; import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import net from 'node:net'; import net from 'node:net';
import { resolve } from 'node:path';
const NEXT_HOST = 'localhost'; const NEXT_HOST = 'localhost';
@@ -17,7 +17,9 @@ const resolveNextPort = (): number => {
const match = devNext.match(/(?:--port|-p)\s+(\d+)/); const match = devNext.match(/(?:--port|-p)\s+(\d+)/);
if (match) return Number(match[1]); if (match) return Number(match[1]);
} }
} catch { /* fallback */ } } catch {
/* fallback */
}
return 3010; return 3010;
}; };
@@ -36,6 +38,7 @@ const runNpmScript = (scriptName: string) =>
spawn(npmCommand, ['run', scriptName], { spawn(npmCommand, ['run', scriptName], {
env: process.env, env: process.env,
stdio: 'inherit', stdio: 'inherit',
shell: process.platform === 'win32',
}); });
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));