Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/empty-donkeys-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/native-federation-typescript': patch
---

rollback without piscina
3 changes: 1 addition & 2 deletions packages/native-federation-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"ansi-colors": "^4.1.3",
"axios": "^1.6.7",
"rambda": "^9.1.0",
"unplugin": "^1.9.0",
"piscina": "^4.4.0"
"unplugin": "^1.9.0"
},
"peerDependencies": {
"typescript": "^4.9.0 || ^5.0.0",
Expand Down
11 changes: 0 additions & 11 deletions packages/native-federation-typescript/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ describe('index', () => {
children: [
{ name: 'archiveHandler.d.ts' },
{ name: 'typeScriptCompiler.d.ts' },
{
name: 'writeBundle',
children: [{ name: 'host.d.ts' }, { name: 'remote.d.ts' }],
},
],
},
],
Expand Down Expand Up @@ -241,13 +237,6 @@ describe('index', () => {
children: [
{ name: 'archiveHandler.d.ts' },
{ name: 'typeScriptCompiler.d.ts' },
{
name: 'writeBundle',
children: [
{ name: 'host.d.ts' },
{ name: 'remote.d.ts' },
],
},
],
},
],
Expand Down
44 changes: 34 additions & 10 deletions packages/native-federation-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ansiColors from 'ansi-colors';
import { rm } from 'fs/promises';
import { resolve } from 'path';
import { mergeDeepRight } from 'rambda';
import { UnpluginOptions, createUnplugin } from 'unplugin';
Expand All @@ -7,22 +8,31 @@ import { retrieveHostConfig } from './configurations/hostPlugin';
import { retrieveRemoteConfig } from './configurations/remotePlugin';
import { HostOptions } from './interfaces/HostOptions';
import { RemoteOptions } from './interfaces/RemoteOptions';
import { retrieveOriginalOutDir } from './lib/typeScriptCompiler';
// @ts-expect-error function exported through module.exports
import remoteWriteBundle from './lib/writeBundle/remote';
// @ts-expect-error function exported through module.exports
import hostWriteBundle from './lib/writeBundle/host';
import { createTypesArchive, downloadTypesArchive } from './lib/archiveHandler';
import {
compileTs,
retrieveMfTypesPath,
retrieveOriginalOutDir,
} from './lib/typeScriptCompiler';

export const NativeFederationTypeScriptRemote = createUnplugin(
(options: RemoteOptions) => {
const remoteConfig = retrieveRemoteConfig(options);
const { remoteOptions, tsConfig } = remoteConfig;
const { remoteOptions, tsConfig, mapComponentsToExpose } =
retrieveRemoteConfig(options);
return {
name: 'native-federation-typescript/remote',
async writeBundle() {
try {
await remoteWriteBundle(remoteConfig);
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);

await createTypesArchive(tsConfig, remoteOptions);

if (remoteOptions.deleteTypesFolder) {
await rm(retrieveMfTypesPath(tsConfig, remoteOptions), {
recursive: true,
force: true,
});
}
console.log(ansiColors.green('Federated types created correctly'));
} catch (error) {
console.error(
Expand Down Expand Up @@ -68,12 +78,26 @@ export const NativeFederationTypeScriptRemote = createUnplugin(

export const NativeFederationTypeScriptHost = createUnplugin(
(options: HostOptions) => {
const hostConfig = retrieveHostConfig(options);
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
return {
name: 'native-federation-typescript/host',
async writeBundle() {
await hostWriteBundle(hostConfig);
if (hostOptions.deleteTypesFolder) {
await rm(hostOptions.typesFolder, {
recursive: true,
force: true,
}).catch((error) =>
console.error(
ansiColors.red(`Unable to remove types folder, ${error}`),
),
);
}

const typesDownloader = downloadTypesArchive(hostOptions);
const downloadPromises =
Object.entries(mapRemotesToDownload).map(typesDownloader);

await Promise.allSettled(downloadPromises);
console.log(ansiColors.green('Federated types extraction completed'));
},
get vite() {
Expand Down
40 changes: 0 additions & 40 deletions packages/native-federation-typescript/src/lib/writeBundle/host.ts

This file was deleted.

This file was deleted.

21 changes: 2 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.