How to use the module.wrap function in module

To help you get started, we’ve selected a few module examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coveraje / coveraje / lib / helper / index.js View on Github external
function compile(content, mod, filename, dirname) {
                    var Script = process.binding('evals').NodeScript;
                    var runInThisContext = Script.runInThisContext;

                    // create wrapper function
                    //
                    var wrapper = Module.wrap(content);

                    var compiledWrapper = runInThisContext(wrapper, filename, true);
                    var args = [mod.exports, requireSubst(mod), mod, filename, dirname];

                    return compiledWrapper.apply(mod.exports, args);
                }
github ustbhuangyi / vue-analysis / vue / src / server / bundle-renderer / create-bundle-runner.js View on Github external
function getCompiledScript (filename) {
    if (compiledScripts[filename]) {
      return compiledScripts[filename]
    }
    const code = files[filename]
    const wrapper = NativeModule.wrap(code)
    const script = new vm.Script(wrapper, {
      filename,
      displayErrors: true
    })
    compiledScripts[filename] = script
    return script
  }
github kaola-fed / megalo / src / server / bundle-renderer / create-bundle-runner.js View on Github external
function getCompiledScript (filename) {
    if (compiledScripts[filename]) {
      return compiledScripts[filename]
    }
    const code = files[filename]
    const wrapper = NativeModule.wrap(code)
    const script = new vm.Script(wrapper, {
      filename,
      displayErrors: true
    })
    compiledScripts[filename] = script
    return script
  }
github easy-team / egg-react-webpack-boilerplate / plugin / egg-webpack-react / app.js View on Github external
app.react.render = function* (name, locals, options) {
      const filePath = path.isAbsolute(name) ? name : path.join(app.config.view.root[0], name);
      const code = yield app.webpack.fileSystem.readWebpackMemoryFile(filePath, name);
      if (!code) {
        throw new Error(`read webpack memory file[${filePath}] content is empty, please check if the file exists`);
      }
      const wrapper = NativeModule.wrap(code);
      vm.runInThisContext(wrapper)(exports, require, module, __filename, __dirname);
      const reactClass = module.exports;
      if (options && options.markup) {
        return app.react.renderToStaticMarkup(reactClass, locals);
      }
      return app.react.renderToString(reactClass, locals);
    };
  }

module

Generate the minimal skeleton/boilerplate for a new Node.js module.

MIT
Latest version published 9 years ago

Package Health Score

41 / 100
Full package analysis