Skip to content

Commit

Permalink
fix(cli): Bring back webpack5 dependency module resolution (#171)
Browse files Browse the repository at this point in the history
* fix(cli): Fix webpack5 dependency module resolution

* Revert back to historical solution

* Reduces changes

* put back filter
  • Loading branch information
tchock authored Mar 16, 2021
1 parent cab367a commit e5674e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/steps/compile/dependencies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe.each([[4], [5]])('Webpack version %s', webpackMajorVersion => {
],
modules: webpackCompilationOutput().modules,
webpackMajorVersion,
compilation: webpackCompilationOutput(),
projectGitPath: `${process.cwd()}`,
})
).toEqual(compilationDependencies());
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/steps/compile/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';
import { Dependency, DependencyReference, LocalDependency } from '../../types';

export function getDependencies(
{ dependencyPackages, modules, webpackMajorVersion, projectGitPath },
{ dependencyPackages, modules, projectGitPath, compilation, webpackMajorVersion },
initial = {}
) {
return modules
Expand All @@ -15,6 +15,9 @@ export function getDependencies(
}

const subDependencies = module.dependencies
.map(dep =>
webpackMajorVersion > 4 ? { ...dep, module: compilation.moduleGraph.getModule(dep) } : dep
)
.filter(dep => dep.module)
.filter(dep => !!dep.module.request || !!dep.module.resource)
.filter(onlyUnique)
Expand All @@ -36,8 +39,8 @@ export function getDependencies(
dependencyPackages,
modules: subDependencies.map(dep => dep.module),
webpackMajorVersion,

projectGitPath,
compilation,
},
result
),
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/steps/compile/runWebpackCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const runWebpackCompiler = ({
const dependencies = getDependencies({
dependencyPackages,
webpackMajorVersion,
compilation: output.compilation,
modules: componentModules,
projectGitPath,
});
Expand Down

0 comments on commit e5674e6

Please sign in to comment.