Skip to content

Turbopack: remove unused ModuleWithDirection from Node runtime #79458

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

Merged
merged 2 commits into from
May 22, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const url = require('url') as typeof import('url')
const fs = require('fs/promises') as typeof import('fs/promises')

const moduleFactories: ModuleFactories = Object.create(null)
const moduleCache: ModuleCache<ModuleWithDirection> = Object.create(null)
const moduleCache: ModuleCache<Module> = Object.create(null)

/**
* Returns an absolute path to the given module's id.
Expand Down Expand Up @@ -213,10 +213,7 @@ function getWorkerBlobURL(_chunks: ChunkPath[]): string {
throw new Error('Worker blobs are not implemented yet for Node.js')
}

function instantiateModule(
id: ModuleId,
source: SourceInfo
): ModuleWithDirection {
function instantiateModule(id: ModuleId, source: SourceInfo): Module {
const moduleFactory = moduleFactories[id]
if (typeof moduleFactory !== 'function') {
// This can happen if modules incorrectly handle HMR disposes/updates,
Expand Down Expand Up @@ -252,13 +249,11 @@ function instantiateModule(
invariant(source, (source) => `Unknown source type: ${source?.type}`)
}

const module: ModuleWithDirection = {
const module: Module = {
exports: {},
error: undefined,
loaded: false,
id,
parents,
children: [],
namespaceObject: undefined,
}
moduleCache[id] = module
Expand Down Expand Up @@ -315,19 +310,11 @@ function instantiateModule(
// @ts-ignore
function getOrInstantiateModuleFromParent(
id: ModuleId,
sourceModule: ModuleWithDirection
): ModuleWithDirection {
sourceModule: Module
): Module {
const module = moduleCache[id]

if (sourceModule.children.indexOf(id) === -1) {
sourceModule.children.push(id)
}

if (module) {
if (module.parents.indexOf(sourceModule.id) === -1) {
module.parents.push(sourceModule.id)
}

return module
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,6 @@ function instantiateModule(id, source) {
error: undefined,
loaded: false,
id,
parents,
children: [],
namespaceObject: undefined
};
moduleCache[id] = module1;
Expand Down Expand Up @@ -646,13 +644,7 @@ function instantiateModule(id, source) {
*/ // @ts-ignore
function getOrInstantiateModuleFromParent(id, sourceModule) {
const module1 = moduleCache[id];
if (sourceModule.children.indexOf(id) === -1) {
sourceModule.children.push(id);
}
if (module1) {
if (module1.parents.indexOf(sourceModule.id) === -1) {
module1.parents.push(sourceModule.id);
}
return module1;
}
return instantiateModule(id, {
Expand Down
Loading
Loading