Skip to content

Commit

Permalink
Merge pull request #172 from NekR/feature/runtime-usage-detection
Browse files Browse the repository at this point in the history
Move runtime usage detection into compilation 'emit' event
  • Loading branch information
NekR committed Feb 3, 2017
2 parents 96d1bc5 + 6084585 commit 1a41cc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
9 changes: 4 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ var OfflinePlugin = (function () {
this.errors = [];

this.__tests = this.options.__tests;
this.flags = {
runtimeAdded: false
};
this.flags = {};

if (this.__tests.pluginVersion) {
this.pluginVersion = this.__tests.pluginVersion;
Expand Down Expand Up @@ -264,7 +262,6 @@ var OfflinePlugin = (function () {

result.loaders.push(_path3['default'].join(__dirname, 'misc/runtime-loader.js') + '?' + JSON.stringify(data));

_this2.flags.runtimeAdded = true;
callback(null, result);
});
});
Expand All @@ -288,7 +285,9 @@ var OfflinePlugin = (function () {
});

compiler.plugin('emit', function (compilation, callback) {
if (!_this2.flags.runtimeAdded && !_this2.__tests.ignoreRuntime) {
var runtimeTemplatePath = _path3['default'].resolve(__dirname, '../tpls/runtime-template.js');

if (compilation.fileDependencies.indexOf(runtimeTemplatePath) === -1 && !_this2.__tests.ignoreRuntime) {
compilation.errors.push(new Error('OfflinePlugin: Plugin\'s runtime wasn\'t added to one of your bundle entries. See this https://goo.gl/YwewYp for details.'));
callback();
return;
Expand Down
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ export default class OfflinePlugin {
this.errors = [];

this.__tests = this.options.__tests;
this.flags = {
runtimeAdded: false
};
this.flags = {};

if (this.__tests.pluginVersion) {
this.pluginVersion = this.__tests.pluginVersion;
Expand Down Expand Up @@ -255,7 +253,6 @@ export default class OfflinePlugin {
'?' + JSON.stringify(data)
);

this.flags.runtimeAdded = true;
callback(null, result);
});
});
Expand All @@ -279,15 +276,19 @@ export default class OfflinePlugin {
});

compiler.plugin('emit', (compilation, callback) => {
if (!this.flags.runtimeAdded && !this.__tests.ignoreRuntime) {
const runtimeTemplatePath = path.resolve(__dirname, '../tpls/runtime-template.js')

if (
compilation.fileDependencies.indexOf(runtimeTemplatePath) === -1 &&
!this.__tests.ignoreRuntime
) {
compilation.errors.push(
new Error(`OfflinePlugin: Plugin's runtime wasn't added to one of your bundle entries. See this https://goo.gl/YwewYp for details.`)
);
callback();
return;
}


const stats = compilation.getStats().toJson();

// By some reason errors raised here are not fatal,
Expand Down

0 comments on commit 1a41cc3

Please sign in to comment.