GithubHelp home page GithubHelp logo

Espresso, NodeJS 16.3 about espresso HOT 2 OPEN

prepare avatar prepare commented on May 28, 2024
Espresso, NodeJS 16.3

from espresso.

Comments (2)

prepare avatar prepare commented on May 28, 2024

/lib/internal/modules/cjs/loader.js

about line 860

Module._resolveFilename = function(request, parent, isMain, options) {
  if (StringPrototypeStartsWith(request, 'node:') ||
      NativeModule.canBeRequiredByUsers(request)) {
    return request;
  }
    ////////////////////////////////////////////
    //#espresso, #4
    if (request.endsWith(".espr")) {
        return request;
    }
  ////////////////////////////////////////////
  let paths;

patch 4: /lib/internal/modules/cjs/loader.js


about line 1123

// Native extension for .js
Module._extensions['.js'] = function(module, filename) {
  if (StringPrototypeEndsWith(filename, '.js')) {
    const pkg = readPackageScope(filename);
    // Function require shouldn't be used in ES modules.
    if (pkg?.data?.type === 'module') {
      const parent = moduleParentCache.get(module);
      const parentPath = parent?.filename;
      const packageJsonPath = path.resolve(pkg.path, 'package.json');
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
    }
  }
  // If already analyzed the source, then it will be cached.
  const cached = cjsParseCache.get(module);
  let content;
  if (cached?.source) {
    content = cached.source;
    cached.source = undefined;
  } else {
    content = fs.readFileSync(filename, 'utf8');
  }
  module._compile(content, filename);
};
//////////////////////////////////
//#espresso, #5 
Module._extensions['.espr'] = function (module, filename) {
    //this make node to callback to our module
    var content = LibEspresso.LoadMainSrcFile();
    module._compile(content, filename);
};
//////////////////////////////////

patch 5: /lib/internal/modules/cjs/loader.js


from espresso.

prepare avatar prepare commented on May 28, 2024

file /lib/internal/main/run_main_module.js
line 1

'use strict';

const {
  prepareMainThreadExecution
} = require('internal/bootstrap/pre_execution');

prepareMainThreadExecution(true);

markBootstrapComplete();

// Note: this loads the module through the ESM loader if the module is
// determined to be an ES module. This hangs from the CJS module loader
// because we currently allow monkey-patching of the module loaders
// in the preloaded scripts through require('module').
// runMain here might be monkey-patched by users in --require.
// XXX: the monkey-patchability here should probably be deprecated.
 
//////////////////////////////////
//#espresso, #6 
/////////////////////////////////
if (typeof LibEspresso !== 'undefined') {
    //we use our lib espr LibEspresso
    require('internal/modules/cjs/loader').Module.runMain("hello.espr");
    return;
} 
/////////////////////////////////
require('internal/modules/cjs/loader').Module.runMain(process.argv[1]);

patch 6: /lib/internal/main/run_main_module.js

from espresso.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.