File tree Expand file tree Collapse file tree
test/configCases/source-map
default-source-map-properties
eval-default-source-map-properties Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " webpack " : patch
3+ ---
4+
5+ Optimize source map generation: only include ` ignoreList ` property when it has content, avoiding empty arrays in source maps.
Original file line number Diff line number Diff line change @@ -165,20 +165,23 @@ class EvalSourceMapDevToolPlugin {
165165 }
166166 ) ;
167167 sourceMap . sources = moduleFilenames ;
168- sourceMap . ignoreList = options . ignoreList
169- ? sourceMap . sources . reduce (
170- /** @type {(acc: number[], sourceName: string, idx: number) => number[] } */ (
171- ( acc , sourceName , idx ) => {
172- const rule = /** @type {Rules } */ ( options . ignoreList ) ;
173- if ( ModuleFilenameHelpers . matchPart ( sourceName , rule ) ) {
174- acc . push ( idx ) ;
175- }
176- return acc ;
168+ if ( options . ignoreList ) {
169+ const ignoreList = sourceMap . sources . reduce (
170+ /** @type {(acc: number[], sourceName: string, idx: number) => number[] } */ (
171+ ( acc , sourceName , idx ) => {
172+ const rule = /** @type {Rules } */ ( options . ignoreList ) ;
173+ if ( ModuleFilenameHelpers . matchPart ( sourceName , rule ) ) {
174+ acc . push ( idx ) ;
177175 }
178- ) ,
179- [ ]
180- )
181- : [ ] ;
176+ return acc ;
177+ }
178+ ) ,
179+ [ ]
180+ ) ;
181+ if ( ignoreList . length > 0 ) {
182+ sourceMap . ignoreList = ignoreList ;
183+ }
184+ }
182185
183186 if ( options . noSources ) {
184187 sourceMap . sourcesContent = undefined ;
Original file line number Diff line number Diff line change @@ -435,24 +435,27 @@ class SourceMapDevToolPlugin {
435435 moduleToSourceNameMapping . get ( m )
436436 ) ;
437437 sourceMap . sources = /** @type {string[] } */ ( moduleFilenames ) ;
438- sourceMap . ignoreList = options . ignoreList
439- ? sourceMap . sources . reduce (
440- /** @type {(acc: number[], sourceName: string, idx: number) => number[] } */ (
441- ( acc , sourceName , idx ) => {
442- const rule = /** @type {Rules } */ (
443- options . ignoreList
444- ) ;
445- if (
446- ModuleFilenameHelpers . matchPart ( sourceName , rule )
447- ) {
448- acc . push ( idx ) ;
449- }
450- return acc ;
438+ if ( options . ignoreList ) {
439+ const ignoreList = sourceMap . sources . reduce (
440+ /** @type {(acc: number[], sourceName: string, idx: number) => number[] } */ (
441+ ( acc , sourceName , idx ) => {
442+ const rule = /** @type {Rules } */ (
443+ options . ignoreList
444+ ) ;
445+ if (
446+ ModuleFilenameHelpers . matchPart ( sourceName , rule )
447+ ) {
448+ acc . push ( idx ) ;
451449 }
452- ) ,
453- [ ]
454- )
455- : [ ] ;
450+ return acc ;
451+ }
452+ ) ,
453+ [ ]
454+ ) ;
455+ if ( ignoreList . length > 0 ) {
456+ sourceMap . ignoreList = ignoreList ;
457+ }
458+ }
456459
457460 if ( options . noSources ) {
458461 sourceMap . sourcesContent = undefined ;
Original file line number Diff line number Diff line change 1+ it ( "should not include empty ignoreList in source map" , ( ) => {
2+ const fs = require ( "fs" ) ;
3+ const path = require ( "path" ) ;
4+ const sourceMapPath = path . join ( __dirname , "bundle0.js.map" ) ;
5+ const sourceMapContent = fs . readFileSync ( sourceMapPath , "utf-8" ) ;
6+
7+ expect ( sourceMapContent ) . not . toMatch ( / " i g n o r e L i s t " \s * : \s * \[ \s * \] / ) ;
8+
9+ // Verify default source map properties are present
10+ const sourceMap = JSON . parse ( sourceMapContent ) ;
11+ expect ( sourceMap ) . toHaveProperty ( "version" , 3 ) ;
12+ expect ( sourceMap ) . toHaveProperty ( "sources" ) ;
13+ expect ( Array . isArray ( sourceMap . sources ) ) . toBe ( true ) ;
14+ expect ( sourceMap . sources . length ) . toBeGreaterThan ( 0 ) ;
15+ } ) ;
16+
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ /** @type {import("../../../../").Configuration } */
4+ module . exports = {
5+ mode : "development" ,
6+ devtool : "source-map" ,
7+ entry : "./index.js"
8+ } ;
Original file line number Diff line number Diff line change 1+ it ( "should not include empty ignoreList in eval source map" , ( ) => {
2+ const fs = require ( "fs" ) ;
3+ const source = fs . readFileSync ( __filename , "utf-8" ) ;
4+
5+ const match = / s o u r c e M a p p i n g U R L \s * = \s * d a t a : a p p l i c a t i o n \/ j s o n ; c h a r s e t = u t f - 8 ; b a s e 6 4 , ( [ A - Z a - z 0 - 9 + \/ = ] + ) / . exec (
6+ source
7+ ) ;
8+ expect ( match ) . not . toBeNull ( ) ;
9+ const mapString = Buffer . from ( match [ 1 ] , "base64" ) . toString ( "utf-8" ) ;
10+
11+ expect ( mapString ) . not . toMatch ( / " i g n o r e L i s t " \s * : \s * \[ \s * \] / ) ;
12+
13+ // Verify default source map properties are present
14+ const sourceMap = JSON . parse ( mapString ) ;
15+ expect ( sourceMap ) . toHaveProperty ( "version" , 3 ) ;
16+ expect ( sourceMap ) . toHaveProperty ( "sources" ) ;
17+ expect ( Array . isArray ( sourceMap . sources ) ) . toBe ( true ) ;
18+ expect ( sourceMap . sources . length ) . toBeGreaterThan ( 0 ) ;
19+ } ) ;
20+
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ /** @type {import("../../../../").Configuration } */
4+ module . exports = {
5+ mode : "development" ,
6+ devtool : "eval-source-map" ,
7+ entry : "./index.js"
8+ } ;
You can’t perform that action at this time.
0 commit comments