@@ -9,6 +9,7 @@ import type { Manifest } from '../manager';
99import DependencyNotFoundError from '../../errors/dependency-not-found-error' ;
1010import getDependencyName from '../utils/get-dependency-name' ;
1111import { packageFilter } from '../utils/resolve-utils' ;
12+ import type { default as TranspiledModule } from '../transpiled-module' ;
1213
1314type Meta = {
1415 [ path : string ] : any ,
@@ -128,18 +129,21 @@ function downloadDependency(depName: string, depVersion: string, path: string) {
128129 . then ( x => ( {
129130 path,
130131 code : x ,
132+ downloaded : true ,
131133 } ) ) ;
132134
133135 return packages [ path ] ;
134136}
135137
136138function resolvePath (
137139 path : string ,
138- currentPath : string ,
140+ currentTModule : TranspiledModule ,
139141 manager : Manager ,
140142 defaultExtensions : Array < string > = [ 'js' , 'jsx' , 'json' ] ,
141143 meta = { }
142144) : Promise < string > {
145+ const currentPath = currentTModule . module . path ;
146+
143147 return new Promise ( ( res , reject ) => {
144148 resolve (
145149 path ,
@@ -160,7 +164,10 @@ function resolvePath(
160164 const callback = cb || c ;
161165
162166 try {
163- return callback ( null , manager . readFileSync ( p ) ) ;
167+ const tModule = manager . resolveTranspiledModule ( p , '/' ) ;
168+ tModule . initiators . add ( currentTModule ) ;
169+ currentTModule . dependencies . add ( tModule ) ;
170+ return callback ( null , tModule . module . code ) ;
164171 } catch ( e ) {
165172 const depPath = p . replace ( '/node_modules/' , '' ) ;
166173 const depName = getDependencyName ( depPath ) ;
@@ -192,6 +199,10 @@ function resolvePath(
192199
193200 if ( module ) {
194201 manager . addModule ( module ) ;
202+ const tModule = manager . addTranspiledModule ( module , '' ) ;
203+
204+ tModule . initiators . add ( currentTModule ) ;
205+ currentTModule . dependencies . add ( tModule ) ;
195206
196207 callback ( null , module . code ) ;
197208 return null ;
@@ -217,7 +228,7 @@ function resolvePath(
217228}
218229
219230async function findDependencyVersion (
220- currentPath : string ,
231+ currentTModule : TranspiledModule ,
221232 manager : Manager ,
222233 defaultExtensions : Array < string > = [ 'js' , 'jsx' , 'json' ] ,
223234 dependencyName : string
@@ -227,7 +238,7 @@ async function findDependencyVersion(
227238 try {
228239 const foundPackageJSONPath = await resolvePath (
229240 pathUtils . join ( dependencyName , 'package.json' ) ,
230- currentPath ,
241+ currentTModule ,
231242 manager ,
232243 defaultExtensions
233244 ) ;
@@ -265,10 +276,11 @@ async function findDependencyVersion(
265276
266277export default async function fetchModule (
267278 path : string ,
268- currentPath : string ,
279+ currentTModule : TranspiledModule ,
269280 manager : Manager ,
270281 defaultExtensions : Array < string > = [ 'js' , 'jsx' , 'json' ]
271282) : Promise < Module > {
283+ const currentPath = currentTModule . module . path ;
272284 // Get the last part of the path as dependency name for paths like
273285 // instantsearch.js/node_modules/lodash/sum.js
274286 // In this case we want to get the lodash dependency info
@@ -277,7 +289,7 @@ export default async function fetchModule(
277289 ) ;
278290
279291 const versionInfo = await findDependencyVersion (
280- currentPath ,
292+ currentTModule ,
281293 manager ,
282294 defaultExtensions ,
283295 dependencyName
@@ -304,7 +316,7 @@ export default async function fetchModule(
304316
305317 const foundPath = await resolvePath (
306318 path ,
307- currentPath ,
319+ currentTModule ,
308320 manager ,
309321 defaultExtensions ,
310322 normalizedMeta
0 commit comments