Skip to content

Commit 8521cef

Browse files
committed
fix: sandpack react template
1 parent 16e0cb0 commit 8521cef

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

packages/toolkit/sandpack-react/scripts/template.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,17 @@ async function handleCodesandboxTemplate() {
5454
}
5555

5656
async function handleCreateTemplate() {
57-
// 获取 @modern-js/create 包的模板目录
58-
// 使用 require.resolve 来定位包的位置,然后获取模板目录
59-
let createPackagePath: string;
60-
try {
61-
// 尝试通过 require.resolve 找到包
62-
const createPackageJsonPath = require.resolve(
63-
'@modern-js/create/package.json',
64-
);
65-
createPackagePath = path.dirname(createPackageJsonPath);
66-
} catch {
67-
// 如果找不到,使用相对路径(在 monorepo 中)
68-
// 从 packages/generator/sandpack-react/scripts 到 packages/toolkit/create
69-
createPackagePath = path.resolve(__dirname, '../../../toolkit/create');
70-
}
57+
const createPackageMainPath = require.resolve('@modern-js/create');
58+
const createPackagePath = path.dirname(path.dirname(createPackageMainPath));
59+
const createPackageJsonPath = path.join(createPackagePath, 'package.json');
7160

7261
const templateDir = path.join(createPackagePath, 'template');
7362

74-
// 读取 @modern-js/create 的 package.json 获取版本号
75-
const createPackageJsonPath = path.join(createPackagePath, 'package.json');
7663
const createPackageJson = JSON.parse(
7764
fs.readFileSync(createPackageJsonPath, 'utf-8'),
7865
);
79-
const version = createPackageJson.version || '2.68.1';
66+
const version = createPackageJson.version || '3.0.0';
8067

81-
// 处理模板,提供 handlebars 需要的数据
8268
const files = await handleTemplate(templateDir, {
8369
packageName: 'modern-app',
8470
version,

0 commit comments

Comments
 (0)