本文整理匯總了TypeScript中module._nodeModulePaths函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript _nodeModulePaths函數的具體用法?TypeScript _nodeModulePaths怎麽用?TypeScript _nodeModulePaths使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了_nodeModulePaths函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createSandbox
function createSandbox(filename: string, logger: Logger): ISandbox {
const module = new Module(filename)
module.paths = Module._nodeModulePaths(filename)
const sandbox = vm.createContext({
module,
Buffer,
console: {
log: (...args: any[]) => {
logger.debug.apply(logger, args)
},
error: (...args: any[]) => {
logger.error.apply(logger, args)
},
info: (...args: any[]) => {
logger.info.apply(logger, args)
},
warn: (...args: any[]) => {
logger.warn.apply(logger, args)
}
}
}) as ISandbox
defaults(sandbox, global)
sandbox.Reflect = Reflect
sandbox.require = function sandboxRequire(p): any {
const oldCompile = Module.prototype._compile
Module.prototype._compile = compileInSandbox(sandbox)
const moduleExports = sandbox.module.require(p)
Module.prototype._compile = oldCompile
return moduleExports
}
// patch `require` in sandbox to run loaded module in sandbox context
// if you need any of these, it might be worth discussing spawning separate processes
sandbox.process = new (process as any).constructor()
for (let key of Object.keys(process)) {
sandbox.process[key] = process[key]
}
REMOVED_GLOBALS.forEach(name => {
sandbox.process[name] = removedGlobalStub(name)
})
// read-only umask
sandbox.process.umask = (mask: number) => {
if (typeof mask !== 'undefined') {
throw new Error('Cannot use process.umask() to change mask (read-only)')
}
return process.umask()
}
return sandbox
}
示例2: compile
function compile(compilation: WebpackCompilation, chunk: WebpackChunk) {
const mainSource: string = compilation.assets[chunk.files[0]].source();
const entryModule = chunk.entryModule.dependencies[0].module;
const filename = entryModule.resource;
const m = new Module(filename, entryModule);
m.paths = Module._nodeModulePaths(entryModule.context);
m.filename = filename;
m._compile(`module.exports = ${mainSource}`, filename);
return m.exports;
}
示例3: _retrieveLocalVersion
/**
* Retrieves the local installed AngularJS Material version form the current PWD.
*/
private static _retrieveLocalVersion(): string {
// Create a Node module which runs at the current process working directory.
let _cliModule = new NodeModule(process.cwd());
_cliModule.paths = NodeModule._nodeModulePaths(process.cwd());
// Resolve the angular-material module form the CWD module.
let resolvedModule = path.dirname(NodeModule._resolveFilename('angular-material', _cliModule));
let packageFile = path.join(resolvedModule, 'package.json');
// Load the version from the local installed AngularJS Material dependency.
return require(packageFile)['version'];
}
示例4: function
if (pathname[0] === '/') pathname = pathname.substr(1)
const isWindowsNetworkSharePath = location.hostname.length > 0 && globalPaths[0].startsWith('\\')
if (isWindowsNetworkSharePath) {
pathname = `//${location.host}/${pathname}`
}
}
global.__filename = path.normalize(decodeURIComponent(pathname))
global.__dirname = path.dirname(global.__filename)
// Set module's filename so relative require can work as expected.
module.filename = global.__filename
// Also search for module under the html file.
module.paths = module.paths.concat(Module._nodeModulePaths(global.__dirname))
} else {
global.__filename = __filename
global.__dirname = __dirname
if (appPath) {
// Search for module under the app directory
module.paths = module.paths.concat(Module._nodeModulePaths(appPath))
}
}
// Redirect window.onerror to uncaughtException.
window.onerror = function (_message, _filename, _lineno, _colno, error) {
if (global.process.listenerCount('uncaughtException') > 0) {
// We do not want to add `uncaughtException` to our definitions
// because we don't want anyone else (anywhere) to throw that kind
示例5: compileModule
function compileModule(file: File) {
var m = new mod();
m.paths = mod._nodeModulePaths(path.dirname(file.path));
m._compile(file.contents.toString());
return m.exports;
}