Skip to content

Commit c8ce8eb

Browse files
committed
fix(builder): 统一使用api.paths.cwd获取工作目录路径
修改vite和webpack构建器的版本信息插件,不再直接使用process.cwd(),而是通过api.paths.cwd获取工作目录路径,确保路径获取的一致性
1 parent 45ecfa5 commit c8ce8eb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/builder-vite/src/features/versionEmit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default (api: IPluginAPI) => {
88
const versionPlugin = {
99
name: 'fes-version-emit',
1010
generateBundle() {
11-
const pkgPath = join(process.cwd(), 'package.json');
11+
const pkgPath = join(api.paths.cwd, 'package.json');
1212
let name = '';
1313
let version = '';
1414
if (existsSync(pkgPath)) {

packages/builder-webpack/src/plugins/features/versionEmit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import process from 'node:process';
55
import webpack from 'webpack';
66

77
class VersionEmitPlugin {
8+
constructor(private cwd: string) {}
89
apply(compiler: webpack.Compiler) {
910
compiler.hooks.thisCompilation.tap('VersionEmitPlugin', (compilation) => {
1011
compilation.hooks.processAssets.tap({ name: 'VersionEmitPlugin', stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, () => {
11-
const pkgPath = join(process.cwd(), 'package.json');
12+
const pkgPath = join(this.cwd, 'package.json');
1213
let name = '';
1314
let version = '';
1415
if (existsSync(pkgPath)) {
@@ -41,7 +42,7 @@ class VersionEmitPlugin {
4142
export default (api: IPluginAPI) => {
4243
api.modifyBundleConfig((memo: any) => {
4344
memo.plugins = memo.plugins || [];
44-
memo.plugins.push(new VersionEmitPlugin());
45+
memo.plugins.push(new VersionEmitPlugin(api.paths.cwd));
4546
return memo;
4647
});
4748
};

0 commit comments

Comments
 (0)