File size: 1,589 Bytes
c7d34c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
import { copyFile, mkdir, stat } from 'node:fs/promises';
import path from 'node:path';

const requiredFiles = [
  'app-route-turbo.runtime.prod.js',
  'app-route-turbo.runtime.prod.js.map'
];

const root = process.cwd();
const sourceDir = path.join(root, 'node_modules', 'next', 'dist', 'compiled', 'next-server');
const targetDir = path.join(
  root,
  '.next',
  'standalone',
  'node_modules',
  'next',
  'dist',
  'compiled',
  'next-server'
);

async function assertFile(filepath) {
  let info;
  try {
    info = await stat(filepath);
  } catch (error) {
    if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
      throw new Error(`文件不存在:${filepath}`);
    }
    const message = error instanceof Error ? error.message : String(error);
    throw new Error(`读取文件状态失败:${filepath}${message}`);
  }
  if (!info.isFile()) {
    throw new Error(`预期是文件,但实际不是文件路径:${filepath}`);
  }
}

try {
  console.info(`准备补齐 standalone runtime:${targetDir}`);
  await mkdir(targetDir, { recursive: true });

  for (const filename of requiredFiles) {
    const source = path.join(sourceDir, filename);
    const target = path.join(targetDir, filename);
    console.info(`复制 standalone runtime 文件:${source} -> ${target}`);
    await assertFile(source);
    await copyFile(source, target);
  }
  console.info('standalone runtime 文件补齐完成。');
} catch (error) {
  console.error('补齐 standalone runtime 文件失败。', error);
  process.exit(1);
}