Skip to content
This repository was archived by the owner on Nov 18, 2018. It is now read-only.

Commit 274bec9

Browse files
committed
proper handling of unmodified, saved files. Fixes #1
1 parent 1bbab68 commit 274bec9

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

index.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"use strict";
22

3+
/**
4+
* Matches the entire AMD header (excluding the webpack return statement)
5+
* $1: e.g.: define("dojo/request/xhr", function(xhr) {
6+
*/
7+
const replacementExpr = /(define\(\[.*\]\,\s?function\(.*\)\s?\{\s?return.*)\(function\([a-z]*\)\s?\{\s?.*/;
38
/**
49
* used to parse the AMD source built by webpack
510
* Matches the following items:
611
* - $1: extract the dependency list (e.g. "dojo/request/xhr")
712
* - $2: extract the variables referring to the dependency (e.g. "xhr")
8-
*/
9-
const replacementExpr = /(define\(\[.*\]\,\s?function\(.*\)\s?\{\s?return.*)\(function\([a-z]*\)\s?\{\s?.*/;
10-
/**
11-
* Matches the entire AMD header (excluding the webpack return statement)
12-
* $1: e.g.: define("dojo/request/xhr", function(xhr) {
1313
*/
1414
const dependencyExtractorExpr = /define\(\[(.*)\]\,\s?function\((.*)\)\s?\{\s?return.*(\(function\([a-z]*\)\s?\{)\s?.*/;
1515
/** expression to catch the end of the webpack AMD file */
@@ -36,29 +36,35 @@ DojoModuleWrapperPlugin.prototype.apply = function(compiler) {
3636
const moduleName = this.options[chunk].moduleName || '';
3737

3838
let source = compilation.assets[distChunk].source();
39-
4039
const depExtractions = source.match(dependencyExtractorExpr);
41-
const toReplace = source.match(replacementExpr)[1];
40+
41+
if(depExtractions != null) {
42+
const toReplace = source.match(replacementExpr);
43+
if(toReplace && toReplace.length == 1) {
44+
source = source.replace(toReplace[1], "");
45+
}
4246

43-
const dojoDeclareLoaderStatement = this.generateStartStatement(moduleName, depExtractions[1], depExtractions[2], baseUrl, fileNameSuffix);
47+
const dojoDeclareLoaderStatement = this.generateStartStatement(moduleName, depExtractions[1], depExtractions[2], baseUrl, fileNameSuffix);
4448

45-
source = source.replace(toReplace, "");
46-
source = source.replace(endBracketExpr, endBracketString);
49+
source = source.replace(endBracketExpr, endBracketString);
4750

48-
const newName = distChunk.substring(0, distChunk.indexOf(".js")) + fileNameSuffix;
51+
const newName = distChunk.substring(0, distChunk.indexOf(".js")) + fileNameSuffix;
4952

50-
compilation.assets[newName] = {
51-
source: function() {
52-
return source;
53-
},
54-
size: function() {
55-
return source.length;
56-
}
57-
};
53+
compilation.assets[newName] = {
54+
source: function() {
55+
return source;
56+
},
57+
size: function() {
58+
return source.length;
59+
}
60+
};
5861

59-
compilation.assets[distChunk].source = () => {
60-
return dojoDeclareLoaderStatement;
61-
};
62+
compilation.assets[distChunk].source = () => {
63+
return dojoDeclareLoaderStatement;
64+
};
65+
} else {
66+
console.log("No change detected. Skipping 'dojo-module-wrapper-webpack-plugin'")
67+
}
6268
});
6369
callback();
6470
});

0 commit comments

Comments
 (0)