Skip to content

Commit 8fc1744

Browse files
[webpack5-plugin]: try to use project-level dependency (#5401)
* fix(webpack5): use project-level webpack dependency when installed Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * add changeset Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * Update common/changes/@rushstack/heft-webpack5-plugin/sennyeya-fix-webpack-resolution_2025-10-06-19-00.json * fallback to previous behavior for nested rig situations Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * add debug logs Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * use rig logs for happy path Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * add build-test for the webpack version checks Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * fix readme Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> * use module resolution for realz Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> --------- Signed-off-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com> Co-authored-by: Aramis Sennyey <aramissennyeydd@users.noreply.github.com>
1 parent 3514f6c commit 8fc1744

File tree

13 files changed

+756
-18
lines changed

13 files changed

+756
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ These GitHub repositories provide supplementary resources for Rush Stack:
210210
| [/build-tests/rush-project-change-analyzer-test](./build-tests/rush-project-change-analyzer-test/) | This is an example project that uses rush-lib's ProjectChangeAnalyzer to |
211211
| [/build-tests/rush-redis-cobuild-plugin-integration-test](./build-tests/rush-redis-cobuild-plugin-integration-test/) | Tests connecting to an redis server |
212212
| [/build-tests/set-webpack-public-path-plugin-test](./build-tests/set-webpack-public-path-plugin-test/) | Building this project tests the set-webpack-public-path-plugin |
213+
| [/build-tests/webpack-local-version-test](./build-tests/webpack-local-version-test/) | Building this project tests the rig loading for the local version of webpack |
213214
| [/eslint/local-eslint-config](./eslint/local-eslint-config/) | An ESLint configuration consumed projects inside the rushstack repo. |
214215
| [/libraries/rush-themed-ui](./libraries/rush-themed-ui/) | Rush Component Library: a set of themed components for rush projects |
215216
| [/libraries/rushell](./libraries/rushell/) | Execute shell commands using a consistent syntax on every platform |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist-*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Defines configuration used by core Heft.
3+
*/
4+
{
5+
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",
6+
7+
// TODO: Add comments
8+
"phasesByName": {
9+
"build": {
10+
"cleanFiles": [{ "includeGlobs": ["lib"] }],
11+
12+
"tasksByName": {
13+
"typescript": {
14+
"taskPlugin": {
15+
"pluginPackage": "@rushstack/heft-typescript-plugin"
16+
}
17+
},
18+
"lint": {
19+
"taskDependencies": ["typescript"],
20+
"taskPlugin": {
21+
"pluginPackage": "@rushstack/heft-lint-plugin"
22+
}
23+
},
24+
"webpack": {
25+
"taskDependencies": ["typescript"],
26+
"taskPlugin": {
27+
"pluginPackage": "@rushstack/heft-webpack5-plugin"
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-project.schema.json",
3+
4+
"operationSettings": [
5+
{
6+
"operationName": "_phase:build",
7+
"outputFolderNames": ["lib"]
8+
}
9+
]
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "webpack-local-version-test",
3+
"description": "Building this project tests the rig loading for the local version of webpack",
4+
"version": "1.0.0",
5+
"private": true,
6+
"scripts": {
7+
"build": "heft --debug build --clean",
8+
"start": "heft build-watch",
9+
"_phase:build": "heft run --only build -- --clean"
10+
},
11+
"devDependencies": {
12+
"@rushstack/heft-lint-plugin": "workspace:*",
13+
"@rushstack/heft-typescript-plugin": "workspace:*",
14+
"@rushstack/heft-webpack5-plugin": "workspace:*",
15+
"@rushstack/heft": "workspace:*",
16+
"@types/webpack-env": "1.18.8",
17+
"eslint": "~9.25.1",
18+
"html-webpack-plugin": "~5.5.0",
19+
"typescript": "~5.8.2",
20+
"webpack": "5.73.0"
21+
}
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
console.log('Hello world!');
2+
3+
export const test = 'Hello world!';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "http://json.schemastore.org/tsconfig",
3+
4+
"compilerOptions": {
5+
"outDir": "lib",
6+
"rootDir": "src",
7+
8+
"forceConsistentCasingInFileNames": true,
9+
"jsx": "react",
10+
"declaration": true,
11+
"sourceMap": true,
12+
"declarationMap": true,
13+
"inlineSources": true,
14+
"experimentalDecorators": true,
15+
"strict": true,
16+
"types": ["webpack-env"],
17+
18+
"module": "esnext",
19+
"moduleResolution": "node",
20+
"target": "es5",
21+
"lib": ["es5", "scripthost", "es2015.collection", "es2015.promise", "es2015.iterable", "dom"]
22+
},
23+
"include": ["src/**/*.ts", "src/**/*.tsx"]
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
module.exports = ({ webpack }) => {
4+
console.log(`Webpack version: ${webpack.version}`);
5+
const localWebpack = require.resolve('webpack');
6+
const bundledWebpack = require.resolve('webpack', {
7+
paths: [require.resolve('@rushstack/heft-webpack5-plugin')]
8+
});
9+
const localWebpackInstance = require(localWebpack);
10+
const bundledWebpackInstance = require(bundledWebpack);
11+
if (localWebpack === bundledWebpack || localWebpackInstance === bundledWebpackInstance) {
12+
throw new Error('Webpack versions match between bundled and local, cannot test rig loading.');
13+
}
14+
if (webpack.version !== localWebpackInstance.version) {
15+
throw new Error('Webpack is not the same version as the local installation');
16+
}
17+
18+
// Verify that the Compiler instances match the local version.
19+
if (webpack.Compiler !== localWebpackInstance.Compiler) {
20+
throw new Error('Webpack instances do not match the local installation');
21+
}
22+
if (webpack.Compiler === bundledWebpackInstance.Compiler) {
23+
throw new Error('Received webpack instance is the same as the bundled version');
24+
}
25+
return {
26+
mode: 'development',
27+
entry: {
28+
'test-bundle': `${__dirname}/lib/index.js`
29+
}
30+
};
31+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-webpack5-plugin",
5+
"comment": "Use project-level webpack dependency when it's installed.",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-webpack5-plugin"
10+
}

0 commit comments

Comments
 (0)