diff --git a/e2e/js/src/js.test.ts b/e2e/js/src/js.test.ts index c99893a44a70a..b3b2e80178b07 100644 --- a/e2e/js/src/js.test.ts +++ b/e2e/js/src/js.test.ts @@ -317,16 +317,21 @@ export function ${lib}Wildcard() { const buildable = uniq('buildable'); runCLI(`generate @nrwl/js:lib ${buildable}`); + const buildableTwo = uniq('buildabletwo'); + runCLI(`generate @nrwl/js:lib ${buildableTwo}`); + const nonBuildable = uniq('nonbuildable'); runCLI(`generate @nrwl/js:lib ${nonBuildable} --buildable=false`); updateFile(`libs/${parent}/src/lib/${parent}.ts`, () => { return ` import { ${buildable} } from '@${scope}/${buildable}'; +import { ${buildableTwo} } from '@${scope}/${buildableTwo}'; import { ${nonBuildable} } from '@${scope}/${nonBuildable}'; export function ${parent}() { ${buildable}(); + ${buildableTwo}(); ${nonBuildable}(); } `; @@ -337,6 +342,7 @@ export function ${parent}() { runCLI(`build ${parent} --external=all`); checkFilesExist( `dist/libs/${buildable}/src/index.js`, // buildable + `dist/libs/${buildableTwo}/src/index.js`, // buildable two `dist/libs/${parent}/src/index.js`, // parent `dist/libs/${parent}/${nonBuildable}/src/index.js` // inlined non buildable ); @@ -350,22 +356,27 @@ export function ${parent}() { checkFilesExist( `dist/libs/${parent}/src/index.js`, // parent `dist/libs/${parent}/${buildable}/src/index.js`, // inlined buildable + `dist/libs/${parent}/${buildableTwo}/src/index.js`, // inlined buildable two `dist/libs/${parent}/${nonBuildable}/src/index.js` // inlined non buildable ); fileContent = readFile(`dist/libs/${parent}/src/lib/${parent}.js`); expect(fileContent).toContain(`${nonBuildable}/src`); expect(fileContent).toContain(`${buildable}/src`); + expect(fileContent).toContain(`${buildableTwo}/src`); // 3. external is set to an array of libs execSync(`rm -rf dist`); runCLI(`build ${parent} --external=${buildable}`); checkFilesExist( `dist/libs/${buildable}/src/index.js`, // buildable + `dist/libs/${buildableTwo}/src/index.js`, // buildable two original output should be persisted `dist/libs/${parent}/src/index.js`, // parent + `dist/libs/${parent}/${buildableTwo}/src/index.js`, // inlined buildable two `dist/libs/${parent}/${nonBuildable}/src/index.js` // inlined non buildable ); fileContent = readFile(`dist/libs/${parent}/src/lib/${parent}.js`); expect(fileContent).toContain(`${nonBuildable}/src`); + expect(fileContent).toContain(`${buildableTwo}/src`); expect(fileContent).not.toContain(`${buildable}/src`); }, 120000 diff --git a/packages/js/src/utils/inline.ts b/packages/js/src/utils/inline.ts index 64769e0946ef9..1cac5cb71690c 100644 --- a/packages/js/src/utils/inline.ts +++ b/packages/js/src/utils/inline.ts @@ -73,7 +73,16 @@ export function postProcessInlinedDependencies( inlineDependency.buildOutputPath || join(outputPath, inlineDependency.root); const destDepOutputPath = join(outputPath, inlineDependency.name); - movePackage(depOutputPath, destDepOutputPath); + const isBuildable = !!inlineDependency.buildOutputPath; + + if (isBuildable) { + copySync(depOutputPath, destDepOutputPath, { + overwrite: true, + recursive: true, + }); + } else { + movePackage(depOutputPath, destDepOutputPath); + } // TODO: hard-coded "src" inlinedDepsDestOutputRecord[inlineDependency.pathAlias] = @@ -238,7 +247,7 @@ function buildInlineGraphExternals( } } -export function movePackage(from: string, to: string) { +function movePackage(from: string, to: string) { copySync(from, to, { overwrite: true, recursive: true }); removeSync(from); } @@ -309,13 +318,12 @@ function getBuildOutputPath( context: ExecutorContext, options: NormalizedExecutorOptions ): string { + const projectTargets = context.projectGraph.nodes[projectName]?.data?.targets; + if (!projectTargets) return ''; + const buildTarget = options.externalBuildTargets.find( - (buildTarget) => - context.projectGraph.nodes[projectName]?.data?.targets?.[buildTarget] + (buildTarget) => projectTargets[buildTarget] ); - if (buildTarget) - return context.projectGraph.nodes[projectName].data.targets?.[buildTarget] - .options['outputPath']; - return ''; + return buildTarget ? projectTargets[buildTarget].options['outputPath'] : ''; }