Skip to content

Commit

Permalink
fix(builder-cli): load provider based on package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Oct 16, 2023
1 parent a777c9a commit be1b8ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/wild-zoos-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/builder': patch
---

fix(builder-cli): load provider based on package.json

fix(builder-cli): 优先基于 package.json 加载 provider
18 changes: 16 additions & 2 deletions packages/builder/builder/src/cli/provider.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { RSPACK_PROVIDER, WEBPACK_PROVIDER } from '@modern-js/builder-shared';
import { isPackageInstalled } from '@modern-js/utils';
import { fs, isPackageInstalled } from '@modern-js/utils';
import path from 'path';

export function getProviderType() {
const root = process.cwd();
const pkgJsonPath = path.join(root, 'package.json');
const pkgJson = fs.readJSONSync(pkgJsonPath);
const deps = {
...pkgJson.dependencies,
...pkgJson.devDependencies,
};

if (isPackageInstalled(RSPACK_PROVIDER, root)) {
// Judging based on package.json, this is more accurate
if (deps[RSPACK_PROVIDER]) {
return 'rspack';
}
if (deps[WEBPACK_PROVIDER]) {
return 'webpack';
}

if (isPackageInstalled(RSPACK_PROVIDER, root)) {
return 'rspack';
}
if (isPackageInstalled(WEBPACK_PROVIDER, root)) {
return 'webpack';
}
Expand Down

0 comments on commit be1b8ef

Please sign in to comment.