Skip to content

Commit

Permalink
fixes rxaviers#7
Browse files Browse the repository at this point in the history
  • Loading branch information
aruberto committed Feb 3, 2016
1 parent 437c800 commit 6239b24
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions DevelopmentModePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ DevelopmentModePlugin.prototype.apply = function(compiler) {
var moduleFilter = this.moduleFilter;

// Skip AMD part of Globalize Runtime UMD wrapper.
compiler.apply(new SkipAMDPlugin(/(^|\/)globalize($|\/)/));
compiler.apply(new SkipAMDPlugin(/(^|[\/\\])globalize($|[\/\\])/));

// "Intercepts" all `require("globalize")` by transforming them into a
// `require` to our custom generated template, which in turn requires
// Globalize, loads CLDR, set the default locale and then exports the
// Globalize object.
compiler.parser.plugin("call require:commonjs:item", function(expr, param) {
var request = this.state.current.request;

if(param.isString() && param.string === "globalize" && moduleFilter(request) &&
!(new RegExp(i18nData)).test(request)) {
!(new RegExp(util.escapeRegex(i18nData))).test(request)) {
var dep;

dep = new CommonJsRequireDependency(i18nData, param.range);
Expand Down
2 changes: 1 addition & 1 deletion GlobalizeCompilerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GlobalizeCompilerHelper.prototype.createCompiledDataModule = function(request) {
};

GlobalizeCompilerHelper.prototype.getModuleFilepath = function(request) {
return path.join(this.tmpdir, request.replace(/.*!/, "").replace(/[/?" ]/g, "-"));
return path.join(this.tmpdir, request.replace(/.*!/, "").replace(/[\/\\?" :]/g, "-"));
};

GlobalizeCompilerHelper.prototype.compile = function(locale, request) {
Expand Down
10 changes: 5 additions & 5 deletions ProductionModePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ ProductionModePlugin.prototype.apply = function(compiler) {

compiler.apply(
// Skip AMD part of Globalize Runtime UMD wrapper.
globalizeSkipAMDPlugin = new SkipAMDPlugin(/(^|\/)globalize($|\/)/),
globalizeSkipAMDPlugin = new SkipAMDPlugin(/(^|[\/\\])globalize($|[\/\\])/),

// Replaces `require("globalize")` with `require("globalize/dist/globalize-runtime")`.
new NormalModuleReplacementPlugin(/(^|\/)globalize$/, "globalize/dist/globalize-runtime"),
new NormalModuleReplacementPlugin(/(^|[\/\\])globalize$/, "globalize/dist/globalize-runtime"),

// Skip AMD part of Globalize Runtime UMD wrapper.
new SkipAMDPlugin(/(^|\/)globalize-runtime($|\/)/)
new SkipAMDPlugin(/(^|[\/\\])globalize-runtime($|[\/\\])/)
);

// Map each AST and its request filepath.
Expand Down Expand Up @@ -89,7 +89,7 @@ ProductionModePlugin.prototype.apply = function(compiler) {
// 1: Removes the leading and the trailing `/` from the regexp string.
globalizeSkipAMDPlugin.requestRegExp = new RegExp([
globalizeSkipAMDPlugin.requestRegExp.toString().slice(1, -1)/* 1 */,
compiledDataFilepath
util.escapeRegex(compiledDataFilepath)
].join("|"));

// Replace require("globalize") with require(<custom precompiled module>).
Expand Down Expand Up @@ -197,7 +197,7 @@ ProductionModePlugin.prototype.apply = function(compiler) {
var request = module.request;
if (request && util.isGlobalizeRuntimeModule(request)) {
// While request has the full pathname, aux has something like "globalize/dist/globalize-runtime/date".
aux = request.split("/");
aux = request.split(/[\/\\]/);
aux = aux.slice(aux.lastIndexOf("globalize")).join("/").replace(/\.js$/, "");
globalizeModuleIds.push(module.id);
globalizeModuleIdsMap[aux] = module.id;
Expand Down
8 changes: 6 additions & 2 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var path = require("path");
var mainFiles = ["ca-gregorian", "currencies", "dateFields", "numbers", "timeZoneNames", "units"];

var isGlobalizeModule = function(filepath) {
filepath = filepath.split( "/" );
filepath = filepath.split( /[\/\\]/ );
var i = filepath.lastIndexOf("globalize");
// 1: path should contain "globalize",
// 2: and it should appear either in the end (e.g., ../globalize) or right
Expand All @@ -23,7 +23,7 @@ module.exports = {
isGlobalizeModule: isGlobalizeModule,

isGlobalizeRuntimeModule: function(filepath) {
filepath = filepath.split( "/" );
filepath = filepath.split( /[\/\\]/ );
var i = filepath.lastIndexOf("globalize-runtime");
var j = filepath.lastIndexOf("globalize-runtime.js");
// Either (1 and 2) or (3 and 4):
Expand Down Expand Up @@ -68,5 +68,9 @@ module.exports = {
}

return tmpdir;
},

escapeRegex: function(string) {
return string.replace(/(?=[\/\\^$*+?.()|{}[\]])/g, "\\")
}
};

0 comments on commit 6239b24

Please sign in to comment.