Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: split execution entry points into main scripts #25667

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/internal/bootstrap/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,32 @@ const { hasTracing, hasInspector } = process.binding('config');

// Modules with source code compiled in js2c that
// cannot be compiled with the code cache.
const cannotUseCache = [
const cannotBeRequired = [
'sys', // Deprecated.
'internal/v8_prof_polyfill',
'internal/v8_prof_processor',

'internal/per_context',

'internal/test/binding',
// TODO(joyeecheung): update the C++ side so that
// the code cache is also used when compiling these two files.

'internal/bootstrap/loaders',
'internal/bootstrap/node'
];

// Skip modules that cannot be required when they are not
// built into the binary.
if (!hasInspector) {
cannotUseCache.push(
cannotBeRequired.push(
'inspector',
'internal/util/inspector',
);
}
if (!hasTracing) {
cannotUseCache.push('trace_events');
cannotBeRequired.push('trace_events');
}
if (!process.versions.openssl) {
cannotUseCache.push(
cannotBeRequired.push(
'crypto',
'https',
'http2',
Expand Down Expand Up @@ -67,10 +66,10 @@ if (!process.versions.openssl) {

const cachableBuiltins = [];
for (const id of NativeModule.map.keys()) {
if (id.startsWith('internal/deps')) {
cannotUseCache.push(id);
if (id.startsWith('internal/deps') || id.startsWith('internal/main')) {
cannotBeRequired.push(id);
}
if (!cannotUseCache.includes(id)) {
if (!cannotBeRequired.includes(id)) {
cachableBuiltins.push(id);
}
}
Expand All @@ -79,5 +78,5 @@ module.exports = {
cachableBuiltins,
getCodeCache,
compileFunction,
cannotUseCache
cannotBeRequired
};
12 changes: 9 additions & 3 deletions lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ internalBinding('module_wrap').callbackMap = new WeakMap();

// Think of this as module.exports in this file even though it is not
// written in CommonJS style.
const loaderExports = { internalBinding, NativeModule };
const loaderExports = {
internalBinding,
NativeModule,
require: nativeModuleRequire
};

const loaderId = 'internal/bootstrap/loaders';

// Set up NativeModule.
Expand Down Expand Up @@ -194,7 +199,7 @@ for (var i = 0; i < moduleIds.length; ++i) {
NativeModule.map.set(id, mod);
}

NativeModule.require = function(id) {
function nativeModuleRequire(id) {
if (id === loaderId) {
return loaderExports;
}
Expand All @@ -218,8 +223,9 @@ NativeModule.require = function(id) {
moduleLoadList.push(`NativeModule ${id}`);
mod.compile();
return mod.exports;
};
}

NativeModule.require = nativeModuleRequire;
NativeModule.exists = function(id) {
return NativeModule.map.has(id);
};
Expand Down
Loading