Skip to content

Commit 08e55b6

Browse files
committed
sync: update with merged changes
1 parent 8b21571 commit 08e55b6

Some content is hidden

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

41 files changed

+638
-176
lines changed

lib/CompatibilityPlugin.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import Compiler = require('./Compiler')
88
import Compilation = require('./Compilation')
99
import Parser = require('./Parser')
1010
import { CallExpression } from 'estree'
11-
import { CompilationParams, ParserOptions } from '../typings/webpack-types'
11+
import { CompilationParams, ParserOptions, NMFAfterResolveResult } from '../typings/webpack-types'
1212
import ContextDependency = require('./dependencies/ContextDependency')
1313

14+
const jsonLoaderPath = require.resolve('json-loader');
15+
const matchJson = /\.json$/i;
16+
1417
class CompatibilityPlugin {
1518
apply(compiler: Compiler) {
1619
compiler.plugin('compilation', function (compilation: Compilation, params: CompilationParams) {
@@ -48,6 +51,16 @@ class CompatibilityPlugin {
4851
return true;
4952
});
5053
});
54+
params.normalModuleFactory.plugin('after-resolve', function (data: NMFAfterResolveResult, done) {
55+
// if this is a json file and there are no loaders active, we use the json-loader in order to avoid
56+
// parse errors @see https://github.com/webpack/webpack/issues/3363
57+
if (matchJson.test(data.request) && data.loaders.length === 0) {
58+
data.loaders.push({
59+
loader: jsonLoaderPath
60+
});
61+
}
62+
done(null, data);
63+
});
5164
});
5265
}
5366
}

lib/Compilation.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
ErrCallback,
1313
PlainObject,
1414
TimeStampMap,
15-
WebpackError, AbstractInputFileSystem
15+
WebpackError,
16+
AbstractInputFileSystem,
17+
PerformanceOptions
1618
} from '../typings/webpack-types'
1719
import { ResolveError } from 'enhanced-resolve/lib/common-types'
1820
import async = require('async');
@@ -36,7 +38,6 @@ import ChunkRenderError = require('./ChunkRenderError');
3638
import NormalModule = require('./NormalModule')
3739
import DependenciesBlock = require('./DependenciesBlock')
3840
import AsyncDependenciesBlock = require('./AsyncDependenciesBlock')
39-
import * as Resolve from 'enhanced-resolve'
4041

4142
interface SlotChunk {
4243
name: string
@@ -82,6 +83,7 @@ class Compilation extends Tapable {
8283
options: WebpackOptions
8384
outputOptions: WebpackOutputOptions
8485
preparedChunks: SlotChunk[]
86+
performance: PerformanceOptions
8587
profile: boolean
8688
records: Record
8789
resolvers: Compiler.Resolvers
@@ -99,6 +101,7 @@ class Compilation extends Tapable {
99101
this.outputOptions = options && options.output;
100102
this.bail = options && options.bail;
101103
this.profile = options && options.profile;
104+
this.performance = options && options.performance;
102105

103106
this.mainTemplate = new MainTemplate(this.outputOptions);
104107
this.chunkTemplate = new ChunkTemplate(this.outputOptions);
@@ -437,12 +440,12 @@ class Compilation extends Tapable {
437440
const start = this.profile && +new Date();
438441

439442
const errorAndCallback = this.bail ? function errorAndCallback(err: ModuleNotFoundError) {
440-
callback(err);
441-
} : function errorAndCallback(err: ModuleNotFoundError) {
442-
err.dependencies = [dependency];
443-
this.errors.push(err);
444-
callback();
445-
}.bind(this);
443+
callback(err);
444+
} : function errorAndCallback(err: ModuleNotFoundError) {
445+
err.dependencies = [dependency];
446+
this.errors.push(err);
447+
callback();
448+
}.bind(this);
446449

447450
if (typeof dependency !== 'object' || dependency === null || !dependency.constructor) {
448451
throw new Error('Parameter \'dependency\' must be a Dependency');
@@ -1083,7 +1086,7 @@ class Compilation extends Tapable {
10831086
let source;
10841087
let file;
10851088
const filenameTemplate = chunk.filenameTemplate
1086-
? chunk.filenameTemplate as string
1089+
? chunk.filenameTemplate
10871090
: chunk.isInitial() ? filename : chunkFilename;
10881091
try {
10891092
const useChunkHash = !chunk.hasRuntime() || this.mainTemplate.useChunkHash && this.mainTemplate.useChunkHash(chunk);
@@ -1156,6 +1159,7 @@ declare namespace Compilation {
11561159
__SourceMapDevToolData?: Dictionary<RawSource | ConcatSource>
11571160
emitted?: boolean
11581161
existsAt?: string
1162+
isOverSizeLimit?: boolean
11591163
}
11601164
}
11611165

lib/Compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
TimeStampMap,
2121
WatchFileSystem,
2222
WatchOptions,
23-
AbstractInputFileSystem, AbstractStats
23+
AbstractInputFileSystem,
24+
AbstractStats
2425
} from '../typings/webpack-types'
2526
import Parser = require('./Parser')
2627
import Stats = require('./Stats')

lib/ContextModule.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import AsyncDependenciesBlock = require('./AsyncDependenciesBlock');
1010
import ModuleDependency = require('./dependencies/ModuleDependency');
1111
import RequestShortener = require('./RequestShortener')
1212
import Compilation = require('./Compilation')
13-
import * as Resolve from 'enhanced-resolve'
1413

1514
class ContextModule extends Module {
1615
async: boolean
@@ -90,7 +89,10 @@ class ContextModule extends Module {
9089
super.disconnect();
9190
}
9291

93-
build(options: WebpackOptions, compilation: Compilation, resolver: any, fs: AbstractInputFileSystem, callback: ErrCallback) {
92+
build(
93+
options: WebpackOptions, compilation: Compilation, resolver: any, fs: AbstractInputFileSystem,
94+
callback: ErrCallback
95+
) {
9496
this.built = true;
9597
this.builtTime = new Date().getTime();
9698
const addon = this.addon;

lib/ContextModuleFactory.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import Tapable = require('tapable');
88
import ContextModule = require('./ContextModule');
99
import ContextElementDependency = require('./dependencies/ContextElementDependency');
1010
import ContextDependency = require('./dependencies/ContextDependency')
11-
import { CMFBeforeResolveResult, ErrCallback, AlternativeModule, AbstractInputFileSystem } from '../typings/webpack-types'
11+
import {
12+
CMFBeforeResolveResult,
13+
ErrCallback,
14+
AlternativeModule,
15+
AbstractInputFileSystem
16+
} from '../typings/webpack-types'
1217
import { Stats } from 'fs'
1318
import Compiler = require('./Compiler')
14-
import * as Resolve from 'enhanced-resolve'
1519

1620
class ContextModuleFactory extends Tapable {
1721
constructor(public resolvers: Compiler.Resolvers) {
@@ -126,7 +130,10 @@ class ContextModuleFactory extends Tapable {
126130
});
127131
}
128132

129-
resolveDependencies(fs: AbstractInputFileSystem, resource: string, recursive: boolean, regExp: RegExp, callback: ErrCallback) {
133+
resolveDependencies(
134+
fs: AbstractInputFileSystem, resource: string, recursive: boolean, regExp: RegExp,
135+
callback: ErrCallback
136+
) {
130137
if (!regExp || !resource) {
131138
return callback(null, []);
132139
}

lib/ContextReplacementPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import Compiler = require('./Compiler')
88
import ContextModuleFactory = require('./ContextModuleFactory')
99
import ContextDependency = require('./dependencies/ContextDependency')
1010
import {
11-
CMFAfterResolveResult, CMFBeforeResolveResult, ErrCallback,
11+
CMFAfterResolveResult,
12+
CMFBeforeResolveResult,
13+
ErrCallback,
1214
AbstractInputFileSystem
1315
} from '../typings/webpack-types'
1416
import * as Resolve from 'enhanced-resolve'

lib/Entrypoint.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Author Tobias Koppers @sokra
44
*/
55
import Chunk = require('./Chunk')
6+
import Compilation = require('./Compilation')
67

78
class Entrypoint {
89
chunks: Chunk[]
@@ -26,6 +27,28 @@ class Entrypoint {
2627
}
2728
chunk.entrypoints.push(this);
2829
}
30+
31+
getFiles() {
32+
const files: string[] = [];
33+
34+
for (let chunk of this.chunks) {
35+
for (let file of chunk.files) {
36+
if (!files.includes(file)) {
37+
files.push(file)
38+
}
39+
}
40+
}
41+
42+
return files;
43+
}
44+
45+
getSize(compilation: Compilation) {
46+
const files = this.getFiles();
47+
48+
return files
49+
.map(file => compilation.assets[file].size())
50+
.reduce((currentSize, nextSize) => currentSize + nextSize, 0);
51+
}
2952
}
3053

3154
export = Entrypoint;

lib/JsonpMainTemplatePlugin.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ class JsonpMainTemplatePlugin {
142142
'while(resolves.length)',
143143
this.indent('resolves.shift()();'),
144144
this.entryPointInChildren(chunk) ? [
145-
'if(executeModules) {',
146-
this.indent([
147-
'for(i=0; i < executeModules.length; i++) {',
148-
this.indent(`result = ${this.requireFn}(${this.requireFn}.s = executeModules[i]);`),
149-
'}'
150-
]),
151-
'}',
152-
'return result;'
153-
] : ''
145+
'if(executeModules) {',
146+
this.indent([
147+
'for(i=0; i < executeModules.length; i++) {',
148+
this.indent(`result = ${this.requireFn}(${this.requireFn}.s = executeModules[i]);`),
149+
'}'
150+
]),
151+
'}',
152+
'return result;'
153+
] : ''
154154
]),
155155
'};'
156156
]);

lib/MainTemplate.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ class MainTemplate extends Template {
6868
'};',
6969
'',
7070
this.asString(outputOptions.strictModuleExceptionHandling ? [
71-
'// Execute the module function',
72-
'var threw = true;',
73-
'try {',
74-
this.indent([
71+
'// Execute the module function',
72+
'var threw = true;',
73+
'try {',
74+
this.indent([
75+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, 'moduleId')});`,
76+
'threw = false;'
77+
]),
78+
'} finally {',
79+
this.indent([
80+
'if(threw) delete installedModules[moduleId];'
81+
]),
82+
'}'
83+
] : [
84+
'// Execute the module function',
7585
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, 'moduleId')});`,
76-
'threw = false;'
7786
]),
78-
'} finally {',
79-
this.indent([
80-
'if(threw) delete installedModules[moduleId];'
81-
]),
82-
'}'
83-
] : [
84-
'// Execute the module function',
85-
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, 'moduleId')});`,
86-
]),
8787
'',
8888
'// Flag the module as loaded',
8989
'module.l = true;',
@@ -113,16 +113,20 @@ class MainTemplate extends Template {
113113
buf.push(`${this.requireFn}.c = installedModules;`);
114114

115115
buf.push('');
116-
buf.push('// identity function for calling harmory imports with the correct context');
116+
buf.push('// identity function for calling harmony imports with the correct context');
117117
buf.push(`${this.requireFn}.i = function(value) { return value; };`);
118118

119119
buf.push('');
120-
buf.push('// define getter function for harmory exports');
120+
buf.push('// define getter function for harmony exports');
121121
buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
122122
buf.push(this.indent([
123-
'Object.defineProperty(exports, name, {',
124-
this.indent(['configurable: false,', 'enumerable: true,', 'get: getter']),
125-
'});'
123+
`if(!${this.requireFn}.o(exports, name)) \{`,
124+
this.indent([
125+
'Object.defineProperty(exports, name, {',
126+
this.indent(['configurable: false,', 'enumerable: true,', 'get: getter']),
127+
'});'
128+
]),
129+
'}'
126130
]));
127131
buf.push('};');
128132

lib/Module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract class Module extends DependenciesBlock implements IRemoveAndDo {
3737
meta: Module.Meta;
3838
optional?: boolean
3939
parent: Module
40+
portableId: string
4041
prefetched: boolean
4142
profile?: Module.Profile
4243
providedExports: string[] | boolean;
@@ -56,6 +57,7 @@ abstract class Module extends DependenciesBlock implements IRemoveAndDo {
5657
this.debugId = debugId++;
5758
this.lastId = -1;
5859
this.id = null;
60+
this.portableId = null;
5961
this.index = null;
6062
this.index2 = null;
6163
this.used = null;

lib/NormalModule.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
WebpackOutputOptions,
2020
TimeStampMap,
2121
SourceRange,
22-
ErrCallback, AbstractInputFileSystem
22+
ErrCallback,
23+
AbstractInputFileSystem
2324
} from '../typings/webpack-types'
2425
import crypto = require('crypto')
2526
import path = require('path');
@@ -38,7 +39,6 @@ import DependenciesBlockVariable = require('./DependenciesBlockVariable')
3839
import DependenciesBlock = require('./DependenciesBlock')
3940
import Parser = require('./Parser')
4041
import Resolver = require('enhanced-resolve/lib/Resolver')
41-
import * as Resolve from 'enhanced-resolve'
4242

4343
function asString(buf: string | Buffer) {
4444
if (Buffer.isBuffer(buf)) {
@@ -110,7 +110,10 @@ class NormalModule extends Module {
110110
return this.resource;
111111
}
112112

113-
doBuild(options: WebpackOptions, compilation: Compilation, resolver: Resolver, fs: AbstractInputFileSystem, callback: ErrCallback) {
113+
doBuild(
114+
options: WebpackOptions, compilation: Compilation, resolver: Resolver, fs: AbstractInputFileSystem,
115+
callback: ErrCallback
116+
) {
114117
this.cacheable = false;
115118
const self = this;
116119
const loaderContext: LoaderContext = {
@@ -205,7 +208,10 @@ class NormalModule extends Module {
205208
super.disconnect();
206209
}
207210

208-
build(options: WebpackOptions, compilation: Compilation, resolver: Resolver, fs: AbstractInputFileSystem, callback: ErrCallback) {
211+
build(
212+
options: WebpackOptions, compilation: Compilation, resolver: Resolver, fs: AbstractInputFileSystem,
213+
callback: ErrCallback
214+
) {
209215
const self = this;
210216
self.buildTimestamp = new Date().getTime();
211217
self.built = true;

0 commit comments

Comments
 (0)