Serve libraries from node_modules.
parent
766c301a44
commit
b8faf1f78b
|
@ -35,6 +35,9 @@ var ROOT_DIR = path.normalize(__dirname + "/../../static/");
|
|||
var TAR_PATH = path.join(__dirname, 'tar.json');
|
||||
var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
|
||||
|
||||
|
||||
var LIBRARY_WHITELIST = [];
|
||||
|
||||
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
||||
var LIBRARY_PREFIX = 'ep_etherpad-lite/static/js';
|
||||
exports.tar = {};
|
||||
|
@ -131,20 +134,26 @@ function minify(req, res, next)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Handle static files for plugins:
|
||||
/* Handle static files for plugins/libraries:
|
||||
paths like "plugins/ep_myplugin/static/js/test.js"
|
||||
are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
|
||||
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
||||
*/
|
||||
var match = filename.match(/^plugins\/([^\/]+)\/static\/(.*)/);
|
||||
var match = filename.match(/^plugins\/([^\/]+)(\/(?:(static\/.*)|.*))?$/);
|
||||
if (match) {
|
||||
var pluginName = match[1];
|
||||
var resourcePath = match[2];
|
||||
var plugin = plugins.plugins[pluginName];
|
||||
if (plugin) {
|
||||
var library = match[1];
|
||||
var libraryPath = match[2] || '';
|
||||
|
||||
if (plugins.plugins[library] && match[3]) {
|
||||
var plugin = plugins.plugins[library];
|
||||
var pluginPath = plugin.package.realPath;
|
||||
filename = path.relative(ROOT_DIR, pluginPath + '/static/' + resourcePath);
|
||||
filename = path.relative(ROOT_DIR, pluginPath + libraryPath);
|
||||
filename = filename.replace(/\\/g, '/'); // Windows (safe generally?)
|
||||
} else if (LIBRARY_WHITELIST.indexOf(library) != -1) {
|
||||
// Go straight into node_modules
|
||||
// Avoid `require.resolve()`, since 'mustache' and 'mustache/index.js'
|
||||
// would end up resolving to logically distinct resources.
|
||||
filename = '../node_modules/' + library + libraryPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue