Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/tools/esbuild/update-federation-tsconfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { EntryPoint } from '@softarc/native-federation';

vi.mock('fs');

function entry(fileName: string): EntryPoint {
return { fileName, outName: 'out.js' } as EntryPoint;
function entry(fileName: string, kind: EntryPoint['kind'] = 'source'): EntryPoint {
return { fileName, outName: 'out.js', kind };
}

function written() {
Expand Down Expand Up @@ -143,4 +143,32 @@ describe('updateFederationTsConfig', () => {

expect(fs.writeFileSync).not.toHaveBeenCalled();
});

// A prebuilt mapping is compiled JS; ngtsc rejects it as a root file, and it does not need
// compiling in the first place.
it('leaves package entry points out of the program', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
vi.mocked(fs.readFileSync).mockReturnValue('{}');

updateFederationTsConfig('/ws', 'tsconfig.federation.json', [
entry('projects/app/src/bootstrap.ts'),
entry('dist/ui/fesm2022/ui.mjs', 'package'),
]);

expect(written().files).toEqual(['projects/app/src/bootstrap.ts']);
});

it('falls back to the app entry points when every mapping is prebuilt', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
vi.mocked(fs.readFileSync).mockReturnValue('{}');

updateFederationTsConfig(
'/ws',
'tsconfig.federation.json',
[entry('dist/ui/fesm2022/ui.mjs', 'package')],
['projects/app/src/main.ts']
);

expect(written().files).toEqual(['projects/app/src/main.ts']);
});
});
7 changes: 6 additions & 1 deletion src/tools/esbuild/update-federation-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
return path.relative(tsconfigDir, absolute).replace(/\\/g, '/');
};

const resolved = entryPoints.map(ep => toTsConfigRelative(ep.fileName));
// A 'package' entry point is already-compiled JS. esbuild loads it through the linker like
// any dependency, and putting it in `files` only makes ngtsc reject it as a non-TypeScript
// root file.
const resolved = entryPoints
.filter(ep => ep.kind !== 'package')

Check failure on line 39 in src/tools/esbuild/update-federation-tsconfig.ts

View workflow job for this annotation

GitHub Actions / verify

Property 'kind' does not exist on type 'EntryPoint'.
.map(ep => toTsConfigRelative(ep.fileName));

// A host without exposes or shared mappings has no entry points of its own; the app's
// main.ts keeps the program from being empty.
Expand Down
Loading