( project: Project, p: FsProject, targets: Target[], opts: EntrypointPermutation )
| 546 | } |
| 547 | |
| 548 | function generateEntrypoint( |
| 549 | project: Project, |
| 550 | p: FsProject, |
| 551 | targets: Target[], |
| 552 | opts: EntrypointPermutation |
| 553 | ) { |
| 554 | const { entrypointExt, withExt, entrypointLocation, entrypointTargetting } = |
| 555 | opts; |
| 556 | const entrypointFilename = `entrypoint-${entrypointSeq()}-${entrypointLocation}-to-${entrypointTargetting}${ |
| 557 | withExt ? '-withext' : '' |
| 558 | }.${entrypointExt}`; |
| 559 | const { isMjs: entrypointIsMjs, isCompiled: entrypointIsCompiled } = fileInfo( |
| 560 | entrypointFilename, |
| 561 | project.typeModule, |
| 562 | project.allowJs |
| 563 | ); |
| 564 | let entrypointContent = 'let mod;\n'; |
| 565 | entrypointContent += 'let testsRun = 0;\n'; |
| 566 | if (entrypointIsMjs) { |
| 567 | entrypointContent += `import assert from 'assert';\n`; |
| 568 | } else { |
| 569 | entrypointContent += `const assert = require('assert');\n`; |
| 570 | entrypointContent += `${declareDynamicImportFunction}\n`; |
| 571 | } |
| 572 | entrypointContent += `async function main() {\n`; |
| 573 | |
| 574 | for (const target of targets) { |
| 575 | // TODO re-enable these when we have outDir <-> rootDir mapping |
| 576 | if (target.srcName.includes('onlyout') && entrypointTargetting === 'src') |
| 577 | continue; |
| 578 | if (target.srcName.includes('onlysrc') && entrypointTargetting === 'out') |
| 579 | continue; |
| 580 | |
| 581 | const { |
| 582 | ext: targetSrcExt, |
| 583 | isMjs: targetIsMjs, |
| 584 | isCompiled: targetIsCompiled, |
| 585 | } = fileInfo(target.srcName, target.typeModule, project.allowJs); |
| 586 | |
| 587 | let targetExtPermutations = ['']; |
| 588 | if (!target.isPackage) { |
| 589 | if (entrypointTargetting === 'out' && target.outExt !== target.srcExt) { |
| 590 | // TODO re-enable when we have out <-> src mapping |
| 591 | targetExtPermutations = [target.outExt]; |
| 592 | } else if (target.srcExt !== target.outExt) { |
| 593 | targetExtPermutations = [target.srcExt, target.outExt]; |
| 594 | } else { |
| 595 | targetExtPermutations = [target.srcExt]; |
| 596 | } |
| 597 | } |
| 598 | const externalPackageSelfImportPermutations = target.isPackage |
| 599 | ? [false, true] |
| 600 | : [false]; |
| 601 | for (const targetExt of targetExtPermutations) { |
| 602 | for (const externalPackageSelfImport of externalPackageSelfImportPermutations) { |
| 603 | entrypointContent += `\n// ${target.targetIdentifier}`; |
| 604 | if (target.isPackage) { |
| 605 | entrypointContent += ` node_modules package`; |
no test coverage detected
searching dependent graphs…