新增调试信息
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Copyright 2014 Google LLC
|
||||
|
||||
Use of this source code is governed by the MIT License, available in this package's LICENSE file
|
||||
or at http://opensource.org/licenses/MIT.
|
||||
*/
|
||||
function callFunction(targetPath, parentModule, func) {
|
||||
if (!func) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return func(targetPath, parentModule);
|
||||
}
|
||||
|
||||
exports.before = function before(targetPath, parentModule, options) {
|
||||
return callFunction(targetPath, parentModule, options.before);
|
||||
};
|
||||
|
||||
exports.after = function after(targetPath, parentModule, options) {
|
||||
return callFunction(targetPath, parentModule, options.after);
|
||||
};
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright 2014 Google LLC
|
||||
|
||||
Use of this source code is governed by the MIT License, available in this package's LICENSE file
|
||||
or at http://opensource.org/licenses/MIT.
|
||||
*/
|
||||
const path = require('path');
|
||||
|
||||
function resolvePaths({ filepath }, paths) {
|
||||
if (!paths) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return paths.slice(0).map((p) => path.resolve(filepath, p));
|
||||
}
|
||||
|
||||
function requirePaths(parentModule, opts) {
|
||||
const result = {
|
||||
before: [],
|
||||
after: [],
|
||||
};
|
||||
|
||||
if (!parentModule) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (Array.isArray(opts)) {
|
||||
result.before = resolvePaths(parentModule, opts);
|
||||
} else {
|
||||
result.before = resolvePaths(parentModule, opts.before);
|
||||
result.after = resolvePaths(parentModule, opts.after);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
exports.before = function before(targetPath, parentModule, opts) {
|
||||
const resolvedPaths = requirePaths(parentModule, opts);
|
||||
|
||||
return (
|
||||
`module.paths = ${JSON.stringify(resolvedPaths.before)}.concat(module.paths)` +
|
||||
`.concat(${JSON.stringify(resolvedPaths.after)}); `
|
||||
);
|
||||
};
|
||||
|
||||
exports.after = function after() {
|
||||
return '';
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
Copyright 2014 Google LLC
|
||||
|
||||
Use of this source code is governed by the MIT License, available in this package's LICENSE file
|
||||
or at http://opensource.org/licenses/MIT.
|
||||
*/
|
||||
exports.before = function before() {
|
||||
return '"use strict";';
|
||||
};
|
||||
|
||||
exports.after = function after() {
|
||||
return '';
|
||||
};
|
||||
Reference in New Issue
Block a user