You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 524ecdd
Browse filesBrowse the repository at this point in the historyBrowse files
feat(loaders): support sourceTest for loader input (#23029)
* feat(loaders): support sourceTest for loader input
* feat(loaders): take a rule condition in sourceTest
Compile sourceTest with RuleSetCompiler, so it accepts what a rule's test
takes (string prefix, RegExp, function, array, and/or/not, glob), once per
use item. Attach it to a loader item only when set, so other loaders' items
keep their size. Treat a buffer as undecodable only when re-encoding loses
bytes, so valid U+FFFD input is still filtered, and reset lastIndex of a
global or sticky regexp condition before each match.
* fix(loaders): type a use effect's value as EffectUse's
Effect's value includes EffectBasic's any, so sourceTest was inferred as any.
* fix(loaders): report a sourceTest that throws as a module error
The source test can run inside a loader callback that already finished,
whose catch only logs, so a throwing condition hung the build.
* fix(loaders): wrap a non-error thrown by sourceTest in an Error
A falsy thrown value reached the callback as success and failed later in
processResult with an unrelated TypeError.
* fix(loaders): describe a symbol thrown by sourceTest without throwing
A template literal throws on a symbol, which brought back the hang the
wrapper prevents; String converts it, with a fallback for any other throw.
* test: cover every changed line of the loader sourceTest
Cover a loader that returns no content, a cached loader resolve and a
sourceTest that throws a value String() can't convert. The resource is
always a Buffer, so matchesSourceTest no longer needs fromLoader.
---------
Co-authored-by: alexander-akait <[email protected]>
Copy file name to clipboardExpand all lines: declarations/WebpackOptions.ts
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5433,6 +5433,11 @@ export type RuleSetUseItem =
5433
5433
* Loader options.
5434
5434
*/
5435
5435
options?: RuleSetLoaderOptions;
5436
+
/**
5437
+
* Run the loader's normal function only when its current input matches this condition, the same kind of condition 'test' takes. Input that is not valid UTF-8 text always runs it.
Copy file name to clipboardExpand all lines: schemas/WebpackOptions.json
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7285,6 +7285,15 @@
7285
7285
"$ref": "#/definitions/RuleSetLoaderOptions"
7286
7286
}
7287
7287
]
7288
+
},
7289
+
"sourceTest": {
7290
+
"description": "Run the loader's normal function only when its current input matches this condition, the same kind of condition 'test' takes. Input that is not valid UTF-8 text always runs it.",
Copy file name to clipboardExpand all lines: test/__snapshots__/Cli.basictest.js.snap
+64Lines changed: 64 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -10936,6 +10936,70 @@ Object {
10936
10936
"multiple": true,
10937
10937
"simpleType": "string",
10938
10938
},
10939
+
"module-rules-use-source-test": Object {
10940
+
"configs": Array [
10941
+
Object {
10942
+
"description": "Run the loader's normal function only when its current input matches this condition, the same kind of condition 'test' takes. Input that is not valid UTF-8 text always runs it.",
10943
+
"multiple": true,
10944
+
"path": "module.rules[].use.sourceTest",
10945
+
"type": "RegExp",
10946
+
},
10947
+
Object {
10948
+
"description": "Run the loader's normal function only when its current input matches this condition, the same kind of condition 'test' takes. Input that is not valid UTF-8 text always runs it.",
10949
+
"multiple": true,
10950
+
"path": "module.rules[].use.sourceTest",
10951
+
"type": "string",
10952
+
},
10953
+
],
10954
+
"description": "Run the loader's normal function only when its current input matches this condition, the same kind of condition 'test' takes. Input that is not valid UTF-8 text always runs it.",
10955
+
"multiple": true,
10956
+
"simpleType": "string",
10957
+
},
10958
+
"module-rules-use-source-test-glob": Object {
10959
+
"configs": Array [
10960
+
Object {
10961
+
"description": "A glob pattern matched against a path, using \`/\` as path separator on every OS; a \`!\` prefix excludes what it matches.",
10962
+
"multiple": true,
10963
+
"path": "module.rules[].use.sourceTest.glob",
10964
+
"type": "string",
10965
+
},
10966
+
],
10967
+
"description": "A glob pattern matched against a path, using \`/\` as path separator on every OS; a \`!\` prefix excludes what it matches.",
10968
+
"multiple": true,
10969
+
"simpleType": "string",
10970
+
},
10971
+
"module-rules-use-source-test-not": Object {
10972
+
"configs": Array [
10973
+
Object {
10974
+
"description": "Logical NOT.",
10975
+
"multiple": true,
10976
+
"path": "module.rules[].use.sourceTest.not",
10977
+
"type": "RegExp",
10978
+
},
10979
+
Object {
10980
+
"description": "Logical NOT.",
10981
+
"multiple": true,
10982
+
"path": "module.rules[].use.sourceTest.not",
10983
+
"type": "string",
10984
+
},
10985
+
],
10986
+
"description": "Logical NOT.",
10987
+
"multiple": true,
10988
+
"simpleType": "string",
10989
+
},
10990
+
"module-rules-use-source-test-not-glob": Object {
10991
+
"configs": Array [
10992
+
Object {
10993
+
"description": "A glob pattern matched against a path, using \`/\` as path separator on every OS; a \`!\` prefix excludes what it matches.",
10994
+
"multiple": true,
10995
+
"path": "module.rules[].use.sourceTest.not.glob",
10996
+
"type": "string",
10997
+
},
10998
+
],
10999
+
"description": "A glob pattern matched against a path, using \`/\` as path separator on every OS; a \`!\` prefix excludes what it matches.",
0 commit comments