本文整理汇总了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
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:55,代码来源:factory.ts
示例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;
}
开发者ID:also,项目名称:book-loader,代码行数:11,代码来源:plugin.ts
示例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'];
}
开发者ID:angular,项目名称:material-tools,代码行数:16,代码来源:PackageResolver.ts
示例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
开发者ID:electron,项目名称:electron,代码行数:31,代码来源:init.ts
示例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;
}
开发者ID:blinkjs,项目名称:blink,代码行数:6,代码来源:VinylCompiler.ts
注:本文中的module._nodeModulePaths函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论