Skip to content

Commit 29c9002

Browse files
committed
fix(create-plugin): load json with fs for node compatibility
1 parent 232ee73 commit 29c9002

File tree

1 file changed

+9
-4
lines changed
  • packages/create-plugin/templates/common/.config/webpack

1 file changed

+9
-4
lines changed

packages/create-plugin/templates/common/.config/webpack/utils.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ export function isWSL() {
2121
}
2222
}
2323

24+
function loadJson(path: string) {
25+
const rawJson = fs.readFileSync(path, 'utf8');
26+
return JSON.parse(rawJson);
27+
}
28+
2429
export function getPackageJson() {
25-
return require(path.resolve(process.cwd(), 'package.json'));
30+
return loadJson(path.resolve(process.cwd(), 'package.json'));
2631
}
2732

2833
export function getPluginJson() {
29-
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
34+
return loadJson(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
3035
}
3136

3237
export function getCPConfigVersion() {
33-
const cprcJson = path.resolve(__dirname, '../', '.cprc.json');
34-
return fs.existsSync(cprcJson) ? require(cprcJson).version : { version: 'unknown' };
38+
const cprcJson = path.resolve(process.cwd(), './.config', '.cprc.json');
39+
return fs.existsSync(cprcJson) ? loadJson(cprcJson).version : { version: 'unknown' };
3540
}
3641

3742
export function hasReadme() {

0 commit comments

Comments
 (0)