Skip to content

Commit d088b15

Browse files
feat: add webpack 4 support to ts-loader v9 (#1697)
* feat: widen webpack peer support Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/74b74f2d-76ad-4022-9635-77d0c5acce76 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: plan isWebpack5 refactor Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/e322b7ed-e010-4d60-9a2d-3672c9d55324 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: propagate webpack major version through instance flow Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/55527c90-acbb-42e1-b384-95f6fdfe9283 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: use instance.isWebpack5 consistently for strategy decisions Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/84c8d79e-30f1-46f5-baf3-bc669466d3ba Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: localize webpack5 detection to instance setup Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/faa27c75-efcd-4e5a-8062-443dce3bf610 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: use module methods directly in webpack5 error cleanup Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/5d863b98-4c30-478e-8205-7c3a7387b0f1 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * Apply suggestion from @johnnyreilly * refactor: consolidate webpack5 build dependency registration Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/f0ead9d8-6749-4f8c-9b23-a5989c21dcbe Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: add getLoaderOptions webpack 4 changes * fix: resolve src/index.ts webpack4 loader options regression Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/e3bff588-a014-408c-b189-25f3f9f840ae Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: make loader-utils optional peer for webpack4 path Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/7890d2b2-6ade-4dc1-9ea6-6bf89c4a60de Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: investigate and address failing webpack4 and comparison tests Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/584f3756-84fa-48c5-b740-30f99f1002d6 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: loaderOptions separate file * refactor: use isWebpack5 in after-compile module mapping Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/6940b64c-bb0d-431f-b8cf-7e83f58ff811 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: derive and reuse isWebpack5 in index loader Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/45ce3f0d-3ab9-47ff-8520-23271ab092af Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * refactor: pass isWebpack5 into instance creation flow Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/80f981d4-a9e6-4dce-8da0-93e82749d5f2 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: restore comparison outputs and normalize ts-loader module errors Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/018a7a6f-9335-4dc8-a21d-32da8f812c6b Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: inline require * chore: reduce number of tested versions * chore: exclude test to see if fixes webpack 4 * chore: introduce minimum webpack version * chore: lockfile * fix: build * fix: check is object * chore: upgrade eslint * fix: tidy * Revert "chore: lockfile" This reverts commit 7878c8f. Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: restore module error guard in after-compile Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/72a9d59f-c15a-451b-a293-48ee4ddae4e6 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: drop unintended yarn.lock changes Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/72a9d59f-c15a-451b-a293-48ee4ddae4e6 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/72a9d59f-c15a-451b-a293-48ee4ddae4e6 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: pin @types/eslint to unblock CI type checks Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/6c6888a9-7744-4fee-b616-05f505226581 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: comment some stuff * fix: restore moduleHasErrors guard in after-compile Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/caa59e7e-b86c-4051-9d2e-f6f6bea4b768 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: revert unintended yarn.lock changes Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/caa59e7e-b86c-4051-9d2e-f6f6bea4b768 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: update progress after moduleHasErrors reply Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/caa59e7e-b86c-4051-9d2e-f6f6bea4b768 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: revert unintended lockfile re-add Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/caa59e7e-b86c-4051-9d2e-f6f6bea4b768 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * docs(changelog): add 9.6.0 entry for webpack 4 support feature Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/5ab3e8ae-31b4-4a96-917d-adcd027e3593 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: revert unintended yarn.lock changes Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/5ab3e8ae-31b4-4a96-917d-adcd027e3593 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * chore: input fiddling * fix: make isWebpack5 a shared constant * fix: add back webpack 5 check * chore: lock file * fix: stabilize nodeModulesMeaningfulErrorWhenImportingTs comparison output Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/df34fd80-1718-4769-8f01-fbc15f96c807 Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: restore lockfile resolution to unblock comparison tests Agent-Logs-Url: https://github.com/TypeStrong/ts-loader/sessions/22ab19a4-eb4b-4cf6-8efc-423776e48f2d Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> * fix: do not use feature detection * fix: invalid output for test * fix: remove hallucinations * chore: update eslint * fix: remove more hallucinations / add min ts version to matrix * fix: webpack 4 * chore: drop old * fix: make loader-utils * as a peerDependencies * fix: watchRun should cater for webpack 4 dates * fix: webpack 4 errors * fix: lint * fix: loaderSource -> details * fix: WebpackError wouldn't work for webpack 4 * fix: nits * fix: whoops * fix: do not use SourceMapConsumer if correct version not available * chore: experiment removing resourceResolveData * fix: guard module.addError for webpack 4 * feat: add common addErrorToModule * chore: CHANGELOG --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: johnnyreilly <1010525+johnnyreilly@users.noreply.github.com> Co-authored-by: John Reilly <johnny_reilly@hotmail.com>
1 parent e714be1 commit d088b15

42 files changed

Lines changed: 1523 additions & 1170 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/push.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
strategy:
5050
matrix:
5151
node: [26, 24, 22]
52-
ts: [5.0.4, 5.1.3, 5.2.2, 5.3.3, 5.4.2, 5.5.3, 5.6.2, 5.7.2, 5.8.2, 5.9.2, 6.0.2] # next excluded for now
52+
ts: [5.6.2, 5.7.2, 5.8.2, 5.9.2, 6.0.2] # next excluded for now
53+
webpack: [4, 5]
5354
runs-on: ubuntu-latest
5455
steps:
5556
- uses: actions/checkout@v6
@@ -68,6 +69,10 @@ jobs:
6869
- name: install typescript
6970
run: yarn add typescript@${{ matrix.ts }}
7071

72+
- name: install webpack 4
73+
if: matrix.webpack == 4
74+
run: yarn add webpack@^4.47.0 karma-webpack@^4.0.2
75+
7176
- name: test
7277
run: yarn execution-tests
7378

@@ -76,7 +81,8 @@ jobs:
7681
strategy:
7782
matrix:
7883
node: [26, 24, 22]
79-
ts: [5.0.4, 5.1.3, 5.2.2, 5.3.3, 5.4.2, 5.5.3, 5.6.2, 5.7.2, 5.8.2, 5.9.2, 6.0.2] # next excluded for now
84+
ts: [5.6.2, 5.7.2, 5.8.2, 5.9.2, 6.0.2] # next excluded for now
85+
webpack: [4, 5]
8086
runs-on: windows-latest
8187
steps:
8288
- uses: actions/checkout@v6
@@ -104,6 +110,11 @@ jobs:
104110
run: yarn add typescript@${{ matrix.ts }}
105111
working-directory: C:\source\ts-loader
106112

113+
- name: install webpack 4
114+
if: matrix.webpack == 4
115+
run: yarn add webpack@^4.47.0 karma-webpack@^4.0.2
116+
working-directory: C:\source\ts-loader
117+
107118
- name: test
108119
run: yarn execution-tests
109120
working-directory: C:\source\ts-loader

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"git blame": true,
88
"sed": true,
99
"yarn": true,
10+
"git check-ignore": true
1011
}
1112
}

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Use `yarn` (not npm).
88

99
## Key commands
1010

11+
Note: test scripts clean test directories first using `git clean -xfd`.
12+
1113
```bash
1214
yarn build # compile src/ → dist/ (tsc --project "./src")
1315
yarn lint # type-check + ESLint (no separate typecheck script)
@@ -43,7 +45,7 @@ yarn comparison-tests -- --save-output --single-test <name> # regenerate o
4345
4446
## Execution tests (`test/execution-tests/`)
4547

46-
Each sub-directory is a mini webpack project with a Karma/Jasmine test suite. The harness compiles the project and **runs the compiled code** — useful for asserting correct runtime behaviour. These are matrix-tested in CI across Node 20/22 and TypeScript 5.x versions.
48+
Each sub-directory is a mini webpack project with a Karma/Jasmine test suite. The harness compiles the project and **runs the compiled code** — useful for asserting correct runtime behaviour. These are matrix-tested in CI across multiple Node and TypeScript versions (see `.github/workflows/push.yml` for the current matrix).
4749

4850
Full docs: [`test/execution-tests/README.md`](test/execution-tests/README.md)
4951

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 9.6.0
4+
* [feat: add webpack 4 support back](https://github.com/TypeStrong/ts-loader/pull/1697) - thanks @johnnyreilly and @tweet
5+
36
## 9.5.7
47
* [fix: TS5011 errors with TypeScript 6.0: transpileModule called with rootDir: undefined](https://github.com/TypeStrong/ts-loader/pull/1679) [#1678] - thanks @julioz and @errorx666
58
* [feat: migrate to trusted publishing](https://github.com/TypeStrong/ts-loader/pull/1680) - thanks @johnnyreilly

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ If you'd like to see a simple setup take a look at [our example](examples/fork-t
133133
### Compatibility
134134

135135
* TypeScript: 3.6.3+
136-
* webpack: 5.x+ (please use `ts-loader` 8.x if you need webpack 4 support)
136+
* webpack: 4.x+ and 5.x+
137137
* node: 12.x+
138138

139-
A full test suite runs each night (and on each pull request). It runs both on Linux and Windows, testing `ts-loader` against major releases of TypeScript. The test suite also runs against TypeScript@next (because we want to use it as much as you do).
139+
A full test suite runs each night (and on each pull request). It runs both on Linux and Windows, testing `ts-loader` against major releases of TypeScript and against both webpack 4 and webpack 5. Comparison tests run against webpack 5 only; execution tests run against both webpack 4 and webpack 5. The test suite also runs against TypeScript@next (because we want to use it as much as you do).
140140

141141
If you become aware of issues not caught by the test suite then please let us know. Better yet, write a test and submit it in a PR!
142142

eslint.config.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import js from '@eslint/js';
2+
import { defineConfig } from 'eslint/config';
3+
import tseslint from 'typescript-eslint';
4+
5+
export default defineConfig(
6+
js.configs.recommended,
7+
tseslint.configs.recommendedTypeChecked,
8+
{
9+
files: ['eslint.config.mjs'],
10+
extends: [tseslint.configs.disableTypeChecked],
11+
},
12+
{
13+
files: ['**/*.ts', '**/*.tsx'],
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true
17+
},
18+
},
19+
rules: {
20+
'no-prototype-builtins': 'off',
21+
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
22+
'@typescript-eslint/unbound-method': 'off',
23+
'@typescript-eslint/no-unsafe-call': 'off',
24+
'@typescript-eslint/no-unsafe-assignment': 'off',
25+
'@typescript-eslint/no-unsafe-member-access': 'off',
26+
'@typescript-eslint/no-unsafe-return': 'off',
27+
'@typescript-eslint/no-explicit-any': 'off',
28+
'@typescript-eslint/no-require-imports': 'off',
29+
'@typescript-eslint/consistent-type-imports': 'error',
30+
'@typescript-eslint/no-unsafe-argument': 'off',
31+
'@typescript-eslint/no-unused-vars': [
32+
'error',
33+
{
34+
'args': 'all',
35+
'argsIgnorePattern': '^_',
36+
'caughtErrors': 'all',
37+
'caughtErrorsIgnorePattern': '^_',
38+
'destructuredArrayIgnorePattern': '^_',
39+
'varsIgnorePattern': '^_',
40+
'ignoreRestSiblings': true
41+
}
42+
]
43+
},
44+
},
45+
);

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "dist",
77
"scripts": {
88
"build": "tsc --version && tsc --project \"./src\"",
9-
"lint": "tsc --project \"./src\" --noEmit && eslint -c .eslintrc.js --ext .ts ./src",
9+
"lint": "tsc --project \"./src\" --noEmit && eslint --ext .ts ./src",
1010
"comparison-tests": "git clean -xfd test/comparison-tests && npm link --legacy-peer-deps ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js",
1111
"execution-tests": "git clean -xfd test/execution-tests && node test/execution-tests/run-tests.js",
1212
"test": "git clean -xfd test/comparison-tests && git clean -xfd test/execution-tests && node test/run-tests.js",
@@ -60,11 +60,10 @@
6060
"source-map": "^0.7.4"
6161
},
6262
"devDependencies": {
63+
"@eslint/js": "^10.0.1",
6364
"@types/micromatch": "^4.0.0",
6465
"@types/node": "*",
6566
"@types/semver": "^7.3.4",
66-
"@typescript-eslint/eslint-plugin": "^6.0.0",
67-
"@typescript-eslint/parser": "^6.0.0",
6867
"babel": "^6.0.0",
6968
"babel-core": "^6.0.0",
7069
"babel-loader": "^7.0.0",
@@ -73,10 +72,9 @@
7372
"babel-preset-es2016": "^6.16.0",
7473
"babel-preset-react": "^6.0.0",
7574
"escape-string-regexp": "^2.0.0",
76-
"eslint": "^8.0.0",
77-
"eslint-config-prettier": "^8.0.0",
78-
"eslint-plugin-node": "^11.1.0",
79-
"eslint-plugin-prettier": "^4.0.0",
75+
"eslint": "^10.0.0",
76+
"eslint-config-prettier": "^10.0.0",
77+
"eslint-plugin-n": "^17.0.0",
8078
"fs-extra": "^11.0.0",
8179
"glob": "^7.1.1",
8280
"husky": "^8.0.0",
@@ -88,18 +86,26 @@
8886
"karma-sourcemap-loader": "^0.4.0",
8987
"karma-webpack": "^5.0.0",
9088
"lint-staged": "^8.0.0",
89+
"loader-utils": "^1.4.2",
9190
"markdown-toc": "^1.2.0",
9291
"mkdirp": "^0.5.1",
9392
"mocha": "^6.0.0",
9493
"prettier": "^2.0.5",
9594
"rimraf": "^2.6.2",
9695
"typescript": "^6.0.2",
96+
"typescript-eslint": "^8.59.4",
9797
"webpack": "^5.74.0",
9898
"webpack-cli": "^4.10.0"
9999
},
100100
"peerDependencies": {
101+
"loader-utils": "*",
101102
"typescript": "*",
102-
"webpack": "^5.0.0"
103+
"webpack": "^4.0.0 || ^5.0.0"
104+
},
105+
"peerDependenciesMeta": {
106+
"loader-utils": {
107+
"optional": true
108+
}
103109
},
104110
"publishConfig": {
105111
"provenance": true

0 commit comments

Comments
 (0)