Skip to content

Commit d491c80

Browse files
authored
Turbopack: remove unused ModuleWithDirection from Node runtime (#79458)
AFAICT, this is only used in dev to correctly remove modules during HMR. But that is not the case for Node.js, where they are set but never used (and Node.js also only has a single runtime, no build vs dev split).
1 parent 7ccdad9 commit d491c80

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/runtime.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const url = require('url') as typeof import('url')
6262
const fs = require('fs/promises') as typeof import('fs/promises')
6363

6464
const moduleFactories: ModuleFactories = Object.create(null)
65-
const moduleCache: ModuleCache<ModuleWithDirection> = Object.create(null)
65+
const moduleCache: ModuleCache<Module> = Object.create(null)
6666

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

216-
function instantiateModule(
217-
id: ModuleId,
218-
source: SourceInfo
219-
): ModuleWithDirection {
216+
function instantiateModule(id: ModuleId, source: SourceInfo): Module {
220217
const moduleFactory = moduleFactories[id]
221218
if (typeof moduleFactory !== 'function') {
222219
// This can happen if modules incorrectly handle HMR disposes/updates,
@@ -252,13 +249,11 @@ function instantiateModule(
252249
invariant(source, (source) => `Unknown source type: ${source?.type}`)
253250
}
254251

255-
const module: ModuleWithDirection = {
252+
const module: Module = {
256253
exports: {},
257254
error: undefined,
258255
loaded: false,
259256
id,
260-
parents,
261-
children: [],
262257
namespaceObject: undefined,
263258
}
264259
moduleCache[id] = module
@@ -315,19 +310,11 @@ function instantiateModule(
315310
// @ts-ignore
316311
function getOrInstantiateModuleFromParent(
317312
id: ModuleId,
318-
sourceModule: ModuleWithDirection
319-
): ModuleWithDirection {
313+
sourceModule: Module
314+
): Module {
320315
const module = moduleCache[id]
321316

322-
if (sourceModule.children.indexOf(id) === -1) {
323-
sourceModule.children.push(id)
324-
}
325-
326317
if (module) {
327-
if (module.parents.indexOf(sourceModule.id) === -1) {
328-
module.parents.push(sourceModule.id)
329-
}
330-
331318
return module
332319
}
333320

turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,6 @@ function instantiateModule(id, source) {
590590
error: undefined,
591591
loaded: false,
592592
id,
593-
parents,
594-
children: [],
595593
namespaceObject: undefined
596594
};
597595
moduleCache[id] = module1;
@@ -646,13 +644,7 @@ function instantiateModule(id, source) {
646644
*/ // @ts-ignore
647645
function getOrInstantiateModuleFromParent(id, sourceModule) {
648646
const module1 = moduleCache[id];
649-
if (sourceModule.children.indexOf(id) === -1) {
650-
sourceModule.children.push(id);
651-
}
652647
if (module1) {
653-
if (module1.parents.indexOf(sourceModule.id) === -1) {
654-
module1.parents.push(sourceModule.id);
655-
}
656648
return module1;
657649
}
658650
return instantiateModule(id, {

0 commit comments

Comments
 (0)