diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts index 0198fdbbed89a..ff00ca33ea694 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts @@ -112,6 +112,48 @@ describe('explicit project dependencies', () => { ]); }); + it('should build explicit dependencies for static exports in .mts files', async () => { + const sourceProjectName = 'proj'; + const { ctx, builder } = await createVirtualWorkspace({ + sourceProjectName, + sourceProjectFiles: [ + { + path: 'libs/proj/index.mts', + content: ` + export {a} from '@proj/my-second-proj'; + export * as project3 from '@proj/project-3'; + export * from '@proj/proj4ab'; + `, + }, + ], + }); + + const res = buildExplicitTypeScriptDependencies( + builder.graph, + ctx.filesToProcess + ); + expect(res).toEqual([ + { + sourceProjectName, + sourceProjectFile: 'libs/proj/index.mts', + targetProjectName: 'proj2', + type: 'static', + }, + { + sourceProjectName, + sourceProjectFile: 'libs/proj/index.mts', + targetProjectName: 'proj3a', + type: 'static', + }, + { + sourceProjectName, + sourceProjectFile: 'libs/proj/index.mts', + targetProjectName: 'proj4ab', + type: 'static', + }, + ]); + }); + it(`should build explicit dependencies for TypeScript's import/export require syntax, and side-effectful import`, async () => { const sourceProjectName = 'proj'; const { ctx, builder } = await createVirtualWorkspace({ diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.ts index 0a33ff3ae14a4..1dd28df10f31f 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.ts @@ -25,8 +25,10 @@ export class TypeScriptImportLocator { const extension = path.extname(filePath); if ( extension !== '.ts' && + extension !== '.mts' && extension !== '.tsx' && extension !== '.js' && + extension !== '.mjs' && extension !== '.jsx' ) { return;