webpack 3.5.6 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,73 +1,73 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- function getProperty(obj, name) {
8
- name = name.split(".");
9
- for(var i = 0; i < name.length - 1; i++) {
10
- obj = obj[name[i]];
11
- if(typeof obj !== "object" || !obj) return;
12
- }
13
- return obj[name.pop()];
14
- }
15
-
16
- function setProperty(obj, name, value) {
17
- name = name.split(".");
18
- for(var i = 0; i < name.length - 1; i++) {
19
- if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
20
- if(!obj[name[i]]) obj[name[i]] = {};
21
- obj = obj[name[i]];
22
- }
23
- obj[name.pop()] = value;
24
- }
25
-
26
- class OptionsDefaulter {
27
- constructor() {
28
- this.defaults = {};
29
- this.config = {};
30
- }
31
-
32
- process(options) {
33
- // TODO: change this for webpack 4: options = Object.assign({}, options);
34
- for(let name in this.defaults) {
35
- switch(this.config[name]) {
36
- case undefined:
37
- if(getProperty(options, name) === undefined)
38
- setProperty(options, name, this.defaults[name]);
39
- break;
40
- case "call":
41
- setProperty(options, name, this.defaults[name].call(this, getProperty(options, name), options), options);
42
- break;
43
- case "make":
44
- if(getProperty(options, name) === undefined)
45
- setProperty(options, name, this.defaults[name].call(this, options), options);
46
- break;
47
- case "append":
48
- {
49
- let oldValue = getProperty(options, name);
50
- if(!Array.isArray(oldValue)) oldValue = [];
51
- oldValue.push.apply(oldValue, this.defaults[name]);
52
- setProperty(options, name, oldValue);
53
- break;
54
- }
55
- default:
56
- throw new Error("OptionsDefaulter cannot process " + this.config[name]);
57
- }
58
- }
59
- // TODO: change this for webpack 4: return options;
60
- }
61
-
62
- set(name, config, def) {
63
- if(arguments.length === 3) {
64
- this.defaults[name] = def;
65
- this.config[name] = config;
66
- } else {
67
- this.defaults[name] = config;
68
- delete this.config[name];
69
- }
70
- }
71
- }
72
-
73
- module.exports = OptionsDefaulter;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ function getProperty(obj, name) {
8
+ name = name.split(".");
9
+ for(var i = 0; i < name.length - 1; i++) {
10
+ obj = obj[name[i]];
11
+ if(typeof obj !== "object" || !obj) return;
12
+ }
13
+ return obj[name.pop()];
14
+ }
15
+
16
+ function setProperty(obj, name, value) {
17
+ name = name.split(".");
18
+ for(var i = 0; i < name.length - 1; i++) {
19
+ if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
20
+ if(!obj[name[i]]) obj[name[i]] = {};
21
+ obj = obj[name[i]];
22
+ }
23
+ obj[name.pop()] = value;
24
+ }
25
+
26
+ class OptionsDefaulter {
27
+ constructor() {
28
+ this.defaults = {};
29
+ this.config = {};
30
+ }
31
+
32
+ process(options) {
33
+ // TODO: change this for webpack 4: options = Object.assign({}, options);
34
+ for(let name in this.defaults) {
35
+ switch(this.config[name]) {
36
+ case undefined:
37
+ if(getProperty(options, name) === undefined)
38
+ setProperty(options, name, this.defaults[name]);
39
+ break;
40
+ case "call":
41
+ setProperty(options, name, this.defaults[name].call(this, getProperty(options, name), options), options);
42
+ break;
43
+ case "make":
44
+ if(getProperty(options, name) === undefined)
45
+ setProperty(options, name, this.defaults[name].call(this, options), options);
46
+ break;
47
+ case "append":
48
+ {
49
+ let oldValue = getProperty(options, name);
50
+ if(!Array.isArray(oldValue)) oldValue = [];
51
+ oldValue.push.apply(oldValue, this.defaults[name]);
52
+ setProperty(options, name, oldValue);
53
+ break;
54
+ }
55
+ default:
56
+ throw new Error("OptionsDefaulter cannot process " + this.config[name]);
57
+ }
58
+ }
59
+ // TODO: change this for webpack 4: return options;
60
+ }
61
+
62
+ set(name, config, def) {
63
+ if(arguments.length === 3) {
64
+ this.defaults[name] = def;
65
+ this.config[name] = config;
66
+ } else {
67
+ this.defaults[name] = config;
68
+ delete this.config[name];
69
+ }
70
+ }
71
+ }
72
+
73
+ module.exports = OptionsDefaulter;
@@ -1,209 +1,209 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const path = require("path");
8
- const crypto = require("crypto");
9
- const RequestShortener = require("./RequestShortener");
10
- const ConcatSource = require("webpack-sources").ConcatSource;
11
- const RawSource = require("webpack-sources").RawSource;
12
- const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
13
- const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
14
-
15
- const basename = (name) => {
16
- if(name.indexOf("/") < 0) return name;
17
- return name.substr(name.lastIndexOf("/") + 1);
18
- };
19
-
20
- function getTaskForFile(file, chunk, options, compilation) {
21
- const asset = compilation.assets[file];
22
- if(asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
23
- const data = asset.__SourceMapDevToolData;
24
- for(const cachedFile in data) {
25
- compilation.assets[cachedFile] = data[cachedFile];
26
- if(cachedFile !== file)
27
- chunk.files.push(cachedFile);
28
- }
29
- return;
30
- }
31
- let source, sourceMap;
32
- if(asset.sourceAndMap) {
33
- const sourceAndMap = asset.sourceAndMap(options);
34
- sourceMap = sourceAndMap.map;
35
- source = sourceAndMap.source;
36
- } else {
37
- sourceMap = asset.map(options);
38
- source = asset.source();
39
- }
40
- if(sourceMap) {
41
- return {
42
- chunk,
43
- file,
44
- asset,
45
- source,
46
- sourceMap,
47
- modules: undefined
48
- };
49
- }
50
- }
51
-
52
- class SourceMapDevToolPlugin {
53
- constructor(options) {
54
- if(arguments.length > 1)
55
- throw new Error("SourceMapDevToolPlugin only takes one argument (pass an options object)");
56
- // TODO: remove in webpack 3
57
- if(typeof options === "string") {
58
- options = {
59
- sourceMapFilename: options
60
- };
61
- }
62
- if(!options) options = {};
63
- this.sourceMapFilename = options.filename;
64
- this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
65
- this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
66
- this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
67
- this.options = options;
68
- }
69
-
70
- apply(compiler) {
71
- const sourceMapFilename = this.sourceMapFilename;
72
- const sourceMappingURLComment = this.sourceMappingURLComment;
73
- const moduleFilenameTemplate = this.moduleFilenameTemplate;
74
- const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
75
- const requestShortener = new RequestShortener(compiler.context);
76
- const options = this.options;
77
- options.test = options.test || /\.(js|css)($|\?)/i;
78
-
79
- const matchObject = ModuleFilenameHelpers.matchObject.bind(undefined, options);
80
-
81
- compiler.plugin("compilation", compilation => {
82
- new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
83
-
84
- compilation.plugin("after-optimize-chunk-assets", function(chunks) {
85
- const moduleToSourceNameMapping = new Map();
86
- const tasks = [];
87
-
88
- chunks.forEach(function(chunk) {
89
- chunk.files.forEach(file => {
90
- if(matchObject(file)) {
91
- const task = getTaskForFile(file, chunk, options, compilation);
92
-
93
- if(task) {
94
- const modules = task.sourceMap.sources.map(source => {
95
- const module = compilation.findModule(source);
96
- return module || source;
97
- });
98
-
99
- for(let idx = 0; idx < modules.length; idx++) {
100
- const module = modules[idx];
101
- if(!moduleToSourceNameMapping.get(module)) {
102
- moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
103
- }
104
- }
105
-
106
- task.modules = modules;
107
-
108
- tasks.push(task);
109
- }
110
- }
111
- });
112
- });
113
-
114
- const usedNamesSet = new Set(moduleToSourceNameMapping.values());
115
- const conflictDetectionSet = new Set();
116
-
117
- // all modules in defined order (longest identifier first)
118
- const allModules = Array.from(moduleToSourceNameMapping.keys()).sort((a, b) => {
119
- const ai = typeof a === "string" ? a : a.identifier();
120
- const bi = typeof b === "string" ? b : b.identifier();
121
- return ai.length - bi.length;
122
- });
123
-
124
- // find modules with conflicting source names
125
- for(let idx = 0; idx < allModules.length; idx++) {
126
- const module = allModules[idx];
127
- let sourceName = moduleToSourceNameMapping.get(module);
128
- let hasName = conflictDetectionSet.has(sourceName);
129
- if(!hasName) {
130
- conflictDetectionSet.add(sourceName);
131
- continue;
132
- }
133
-
134
- // try the fallback name first
135
- sourceName = ModuleFilenameHelpers.createFilename(module, fallbackModuleFilenameTemplate, requestShortener);
136
- hasName = usedNamesSet.has(sourceName);
137
- if(!hasName) {
138
- moduleToSourceNameMapping.set(module, sourceName);
139
- usedNamesSet.add(sourceName);
140
- continue;
141
- }
142
-
143
- // elsewise just append stars until we have a valid name
144
- while(hasName) {
145
- sourceName += "*";
146
- hasName = usedNamesSet.has(sourceName);
147
- }
148
- moduleToSourceNameMapping.set(module, sourceName);
149
- usedNamesSet.add(sourceName);
150
- }
151
- tasks.forEach(function(task) {
152
- const chunk = task.chunk;
153
- const file = task.file;
154
- const asset = task.asset;
155
- const sourceMap = task.sourceMap;
156
- const source = task.source;
157
- const modules = task.modules;
158
- const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m));
159
- sourceMap.sources = moduleFilenames;
160
- if(sourceMap.sourcesContent && !options.noSources) {
161
- sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
162
- } else {
163
- sourceMap.sourcesContent = undefined;
164
- }
165
- sourceMap.sourceRoot = options.sourceRoot || "";
166
- sourceMap.file = file;
167
- asset.__SourceMapDevToolFile = file;
168
- asset.__SourceMapDevToolData = {};
169
- let currentSourceMappingURLComment = sourceMappingURLComment;
170
- if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
171
- currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
172
- }
173
- const sourceMapString = JSON.stringify(sourceMap);
174
- if(sourceMapFilename) {
175
- let filename = file;
176
- let query = "";
177
- const idx = filename.indexOf("?");
178
- if(idx >= 0) {
179
- query = filename.substr(idx);
180
- filename = filename.substr(0, idx);
181
- }
182
- let sourceMapFile = compilation.getPath(sourceMapFilename, {
183
- chunk,
184
- filename,
185
- query,
186
- basename: basename(filename)
187
- });
188
- if(sourceMapFile.indexOf("[contenthash]") !== -1) {
189
- sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
190
- }
191
- const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
192
- if(currentSourceMappingURLComment !== false) {
193
- asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
194
- }
195
- asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
196
- chunk.files.push(sourceMapFile);
197
- } else {
198
- asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
199
- .replace(/\[map\]/g, () => sourceMapString)
200
- .replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
201
- );
202
- }
203
- });
204
- });
205
- });
206
- }
207
- }
208
-
209
- module.exports = SourceMapDevToolPlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const path = require("path");
8
+ const crypto = require("crypto");
9
+ const RequestShortener = require("./RequestShortener");
10
+ const ConcatSource = require("webpack-sources").ConcatSource;
11
+ const RawSource = require("webpack-sources").RawSource;
12
+ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
13
+ const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
14
+
15
+ const basename = (name) => {
16
+ if(name.indexOf("/") < 0) return name;
17
+ return name.substr(name.lastIndexOf("/") + 1);
18
+ };
19
+
20
+ function getTaskForFile(file, chunk, options, compilation) {
21
+ const asset = compilation.assets[file];
22
+ if(asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
23
+ const data = asset.__SourceMapDevToolData;
24
+ for(const cachedFile in data) {
25
+ compilation.assets[cachedFile] = data[cachedFile];
26
+ if(cachedFile !== file)
27
+ chunk.files.push(cachedFile);
28
+ }
29
+ return;
30
+ }
31
+ let source, sourceMap;
32
+ if(asset.sourceAndMap) {
33
+ const sourceAndMap = asset.sourceAndMap(options);
34
+ sourceMap = sourceAndMap.map;
35
+ source = sourceAndMap.source;
36
+ } else {
37
+ sourceMap = asset.map(options);
38
+ source = asset.source();
39
+ }
40
+ if(sourceMap) {
41
+ return {
42
+ chunk,
43
+ file,
44
+ asset,
45
+ source,
46
+ sourceMap,
47
+ modules: undefined
48
+ };
49
+ }
50
+ }
51
+
52
+ class SourceMapDevToolPlugin {
53
+ constructor(options) {
54
+ if(arguments.length > 1)
55
+ throw new Error("SourceMapDevToolPlugin only takes one argument (pass an options object)");
56
+ // TODO: remove in webpack 3
57
+ if(typeof options === "string") {
58
+ options = {
59
+ sourceMapFilename: options
60
+ };
61
+ }
62
+ if(!options) options = {};
63
+ this.sourceMapFilename = options.filename;
64
+ this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
65
+ this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
66
+ this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
67
+ this.options = options;
68
+ }
69
+
70
+ apply(compiler) {
71
+ const sourceMapFilename = this.sourceMapFilename;
72
+ const sourceMappingURLComment = this.sourceMappingURLComment;
73
+ const moduleFilenameTemplate = this.moduleFilenameTemplate;
74
+ const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
75
+ const requestShortener = new RequestShortener(compiler.context);
76
+ const options = this.options;
77
+ options.test = options.test || /\.(js|css)($|\?)/i;
78
+
79
+ const matchObject = ModuleFilenameHelpers.matchObject.bind(undefined, options);
80
+
81
+ compiler.plugin("compilation", compilation => {
82
+ new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
83
+
84
+ compilation.plugin("after-optimize-chunk-assets", function(chunks) {
85
+ const moduleToSourceNameMapping = new Map();
86
+ const tasks = [];
87
+
88
+ chunks.forEach(function(chunk) {
89
+ chunk.files.forEach(file => {
90
+ if(matchObject(file)) {
91
+ const task = getTaskForFile(file, chunk, options, compilation);
92
+
93
+ if(task) {
94
+ const modules = task.sourceMap.sources.map(source => {
95
+ const module = compilation.findModule(source);
96
+ return module || source;
97
+ });
98
+
99
+ for(let idx = 0; idx < modules.length; idx++) {
100
+ const module = modules[idx];
101
+ if(!moduleToSourceNameMapping.get(module)) {
102
+ moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
103
+ }
104
+ }
105
+
106
+ task.modules = modules;
107
+
108
+ tasks.push(task);
109
+ }
110
+ }
111
+ });
112
+ });
113
+
114
+ const usedNamesSet = new Set(moduleToSourceNameMapping.values());
115
+ const conflictDetectionSet = new Set();
116
+
117
+ // all modules in defined order (longest identifier first)
118
+ const allModules = Array.from(moduleToSourceNameMapping.keys()).sort((a, b) => {
119
+ const ai = typeof a === "string" ? a : a.identifier();
120
+ const bi = typeof b === "string" ? b : b.identifier();
121
+ return ai.length - bi.length;
122
+ });
123
+
124
+ // find modules with conflicting source names
125
+ for(let idx = 0; idx < allModules.length; idx++) {
126
+ const module = allModules[idx];
127
+ let sourceName = moduleToSourceNameMapping.get(module);
128
+ let hasName = conflictDetectionSet.has(sourceName);
129
+ if(!hasName) {
130
+ conflictDetectionSet.add(sourceName);
131
+ continue;
132
+ }
133
+
134
+ // try the fallback name first
135
+ sourceName = ModuleFilenameHelpers.createFilename(module, fallbackModuleFilenameTemplate, requestShortener);
136
+ hasName = usedNamesSet.has(sourceName);
137
+ if(!hasName) {
138
+ moduleToSourceNameMapping.set(module, sourceName);
139
+ usedNamesSet.add(sourceName);
140
+ continue;
141
+ }
142
+
143
+ // elsewise just append stars until we have a valid name
144
+ while(hasName) {
145
+ sourceName += "*";
146
+ hasName = usedNamesSet.has(sourceName);
147
+ }
148
+ moduleToSourceNameMapping.set(module, sourceName);
149
+ usedNamesSet.add(sourceName);
150
+ }
151
+ tasks.forEach(function(task) {
152
+ const chunk = task.chunk;
153
+ const file = task.file;
154
+ const asset = task.asset;
155
+ const sourceMap = task.sourceMap;
156
+ const source = task.source;
157
+ const modules = task.modules;
158
+ const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m));
159
+ sourceMap.sources = moduleFilenames;
160
+ if(sourceMap.sourcesContent && !options.noSources) {
161
+ sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
162
+ } else {
163
+ sourceMap.sourcesContent = undefined;
164
+ }
165
+ sourceMap.sourceRoot = options.sourceRoot || "";
166
+ sourceMap.file = file;
167
+ asset.__SourceMapDevToolFile = file;
168
+ asset.__SourceMapDevToolData = {};
169
+ let currentSourceMappingURLComment = sourceMappingURLComment;
170
+ if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
171
+ currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
172
+ }
173
+ const sourceMapString = JSON.stringify(sourceMap);
174
+ if(sourceMapFilename) {
175
+ let filename = file;
176
+ let query = "";
177
+ const idx = filename.indexOf("?");
178
+ if(idx >= 0) {
179
+ query = filename.substr(idx);
180
+ filename = filename.substr(0, idx);
181
+ }
182
+ let sourceMapFile = compilation.getPath(sourceMapFilename, {
183
+ chunk,
184
+ filename,
185
+ query,
186
+ basename: basename(filename)
187
+ });
188
+ if(sourceMapFile.indexOf("[contenthash]") !== -1) {
189
+ sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
190
+ }
191
+ const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
192
+ if(currentSourceMappingURLComment !== false) {
193
+ asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
194
+ }
195
+ asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
196
+ chunk.files.push(sourceMapFile);
197
+ } else {
198
+ asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
199
+ .replace(/\[map\]/g, () => sourceMapString)
200
+ .replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
201
+ );
202
+ }
203
+ });
204
+ });
205
+ });
206
+ }
207
+ }
208
+
209
+ module.exports = SourceMapDevToolPlugin;