diff --git a/packages/dependency-finder/src/lib/entrypoints/additional.ts b/packages/dependency-finder/src/lib/entrypoints/additional.ts index c9a0fa922d8f0..8fc259072c949 100644 --- a/packages/dependency-finder/src/lib/entrypoints/additional.ts +++ b/packages/dependency-finder/src/lib/entrypoints/additional.ts @@ -2,11 +2,12 @@ * External dependencies */ import globby from 'globby'; +import { resolve } from 'path'; export const findAdditionalEntryPoints = async ( additionalEntryPoints: string[] ): Promise< string[] > => { - return ( - await Promise.all( additionalEntryPoints.map( ( pattern ) => globby( pattern ) ) ) - ).flat(); + return ( await Promise.all( additionalEntryPoints.map( ( pattern ) => globby( pattern ) ) ) ) + .flat() + .map( ( entry ) => resolve( entry ) ); }; diff --git a/packages/dependency-finder/src/lib/find-dependencies.ts b/packages/dependency-finder/src/lib/find-dependencies.ts index 8884e9601e068..0afe385944bcb 100644 --- a/packages/dependency-finder/src/lib/find-dependencies.ts +++ b/packages/dependency-finder/src/lib/find-dependencies.ts @@ -57,6 +57,17 @@ export const findDependencies = async ( { } } )(); + const webpackConfig = ( () => { + try { + const webpackPath = path.join( pkg, 'webpack.config.js' ); + fs.accessSync( webpackPath ); + modules.add( webpackPath ); + return webpackPath; + } catch { + return null; + } + } )(); + const absoluteAdditionalEntryPoints = await findAdditionalEntryPoints( additionalEntryPoints ); // Handles monorepo and npm results from parsed files. @@ -77,10 +88,13 @@ export const findDependencies = async ( { return true; }; + // Entrypoints need to be absolute paths at this point so that the webpack resolver + // knows to parse up the filesystem further. (Otherwise, it stops short before reaching the root node_modules.) for ( const entrypoint of [ ...entrypoints, ...jestTests, ...absoluteAdditionalEntryPoints ] ) { const tree = dependencyTree.toList( { filename: entrypoint, directory: path.dirname( entrypoint ), + webpackConfig: webpackConfig ?? undefined, tsConfig: tsConfig ?? undefined, visited, filter: fileFilter,