From 7cdcb83a98e2c625448d645dd7924b06e884aacb Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 22 Jul 2014 13:53:09 -0400 Subject: [PATCH 1/2] fixed #1640 --- minifier.js | 2 +- src/meta/js.js | 51 +++++++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/minifier.js b/minifier.js index a56578898d..5418659e16 100644 --- a/minifier.js +++ b/minifier.js @@ -24,7 +24,7 @@ Minifier.js.minify = function (scripts, minify, callback) { options.outSourceMap = 'nodebb.min.js.map'; options.mangle = false; options.compress = false; - options.prefix = __dirname.split(path.sep).length; + // options.prefix = __dirname.split(path.sep).length; } try { diff --git a/src/meta/js.js b/src/meta/js.js index b772f0ac05..4f0a94f187 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -5,6 +5,7 @@ var winston = require('winston'), path = require('path'), async = require('async'), _ = require('underscore'), + os = require('os'), plugins = require('../plugins'), emitter = require('../emitter'), @@ -74,30 +75,30 @@ module.exports = function(Meta) { Meta.js.prepare = function (callback) { plugins.fireHook('filter:scripts.get', Meta.js.scripts, function(err, scripts) { var jsPaths = scripts.map(function (jsPath) { - jsPath = path.normalize(jsPath); - - if (jsPath.substring(0, 7) === 'plugins') { - var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) { - if (jsPath.match(mappedPath)) { - return mappedPath; + jsPath = path.normalize(jsPath); + + if (jsPath.substring(0, 7) === 'plugins') { + var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) { + if (jsPath.match(mappedPath)) { + return mappedPath; + } else { + return null; + } + }).filter(function(a) { return a; }); + + if (matches.length) { + var relPath = jsPath.slice(('plugins/' + matches[0]).length), + pluginId = matches[0].split(path.sep)[0]; + + return plugins.staticDirs[matches[0]] + relPath; } else { + winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?'); return null; } - }).filter(function(a) { return a; }); - - if (matches.length) { - var relPath = jsPath.slice(('plugins/' + matches[0]).length), - pluginId = matches[0].split(path.sep)[0]; - - return plugins.staticDirs[matches[0]] + relPath; } else { - winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?'); - return null; + return path.join(__dirname, '../..', '/public', jsPath); } - } else { - return path.join(__dirname, '../..', '/public', jsPath); - } - }); + }); Meta.js.scripts = jsPaths.filter(function(path) { return path !== null; @@ -123,6 +124,11 @@ module.exports = function(Meta) { next(err); }); }, function(err) { + // Translate into relative paths + Meta.js.scripts = Meta.js.scripts.map(function(script) { + return path.relative(path.resolve(__dirname, '../../'), script).replace(/\\/g, '/'); + }); + Meta.js.prepared = true; callback(err); }); @@ -163,4 +169,11 @@ module.exports = function(Meta) { Meta.js.minifierProc.kill('SIGTERM'); } }; + + // OS detection and handling + // if (os.platform() === 'win32') { + // Meta.js.scripts = Meta.js.scripts.map(function(script) { + // return script.replace(/\//g, '\\'); + // }); + // } }; \ No newline at end of file From ce8bec5edb5e42ca4ae988a34f124737f7a4351c Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 23 Jul 2014 14:27:01 -0400 Subject: [PATCH 2/2] fixed mapping in web inspector --- minifier.js | 2 +- src/meta/js.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/minifier.js b/minifier.js index 5418659e16..3bd306a07c 100644 --- a/minifier.js +++ b/minifier.js @@ -24,7 +24,7 @@ Minifier.js.minify = function (scripts, minify, callback) { options.outSourceMap = 'nodebb.min.js.map'; options.mangle = false; options.compress = false; - // options.prefix = __dirname.split(path.sep).length; + options.prefix = 1; } try { diff --git a/src/meta/js.js b/src/meta/js.js index 4f0a94f187..3476f891da 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -126,7 +126,7 @@ module.exports = function(Meta) { }, function(err) { // Translate into relative paths Meta.js.scripts = Meta.js.scripts.map(function(script) { - return path.relative(path.resolve(__dirname, '../../'), script).replace(/\\/g, '/'); + return path.relative(path.resolve(__dirname, '../..'), script).replace(/\\/g, '/'); }); Meta.js.prepared = true;