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
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"author": "Zack Jackson <zackary.l.jackson@gmail.com>",
"contributors": [
"Pavel Chertorogov, nodkz <pavel.chertorogov@gmail.com> (www.ps.kz)",
"Kyle Tsang (https://github.com/kyletsang)"
"Kyle Tsang (https://github.com/kyletsang)",
"Matteo Pietro Dazzi (https://github.com/ilteoood)"
],
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -136,9 +137,9 @@
"@types/webpack-sources": "3.2.3",
"@typescript-eslint/eslint-plugin": "6.16.0",
"@typescript-eslint/parser": "6.16.0",
"@vitest/coverage-c8": "0.33.0",
"@vitest/coverage-istanbul": "0.34.4",
"@vitest/ui": "0.34.4",
"@vitest/coverage-istanbul": "1.2.2",
"@vitest/coverage-v8": "1.2.2",
"@vitest/ui": "1.2.2",
"antora-navigator-extension": "https://gitlab.com/opendevise/oss/antora-navigator-extension/-/archive/main/antora-navigator-extension-main.tar.gz",
"autoprefixer": "10.4.17",
"babel-jest": "29.7.0",
Expand All @@ -164,6 +165,7 @@
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-simple-import-sort": "10.0.0",
"form-data": "4.0.0",
"graceful-fs": "^4.2.9",
"highlight.js": "10.7.3",
"html-webpack-plugin": "5.6.0",
"husky": "8.0.3",
Expand Down Expand Up @@ -193,8 +195,10 @@
"qwik-nx": "1.1.1",
"qwik-speak": "0.19.0",
"react-refresh": "0.14.0",
"rimraf": "^3.0.2",
"rollup-plugin-copy": "3.5.0",
"stopword": "2.0.8",
"strip-ansi": "^6.0.0",
"swc-loader": "0.2.3",
"tailwindcss": "3.4.0",
"ts-jest": "29.1.2",
Expand All @@ -207,16 +211,13 @@
"vinyl-fs": "4.0.0",
"vite": "4.4.11",
"vite-tsconfig-paths": "4.2.3",
"vitest": "0.32.4",
"vitest": "1.2.2",
"vitest-fetch-mock": "^0.2.2",
"vue-tsc": "1.8.27",
"wast-loader": "^1.11.5",
"webpack": "^5.88.2",
"webpack-virtual-modules": "0.6.1",
"whatwg-fetch": "^3.6.2",
"graceful-fs": "^4.2.9",
"rimraf": "^3.0.2",
"strip-ansi": "^6.0.0",
"wast-loader": "^1.11.5"
"whatwg-fetch": "^3.6.2"
},
"config": {
"commitizen": {
Expand Down
32 changes: 16 additions & 16 deletions packages/enhanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ This package provides enhanced features for module federation.

The following items are exported:

* ModuleFederationPlugin
* ContainerPlugin
* ContainerReferencePlugin
* SharePlugin
* ConsumeSharedPlugin
* ProvideSharedPlugin
* FederationRuntimePlugin
* AsyncBoundaryPlugin
* HoistContainerReferencesPlugin
- ModuleFederationPlugin
- ContainerPlugin
- ContainerReferencePlugin
- SharePlugin
- ConsumeSharedPlugin
- ProvideSharedPlugin
- FederationRuntimePlugin
- AsyncBoundaryPlugin
- HoistContainerReferencesPlugin

## ModuleFederationPlugin

Expand Down Expand Up @@ -58,10 +58,10 @@ module.exports = {
name: 'mfButton',
exposes: {
// Note: "./" is not supported
".": "./src/index.tsx",
"./add": "./src/utils/add.ts",
"./Button": "./src/components/Button.tsx",
}
'.': './src/index.tsx',
'./add': './src/utils/add.ts',
'./Button': './src/components/Button.tsx',
},
}),
],
};
Expand Down Expand Up @@ -98,8 +98,7 @@ Here, `remoteAlias` is the name actually used by the user and can be configured
- Required: No
- Default: `undefined`


`shared` is used to share common dependencies between consumers and producers, reducing runtime download size and thus improving performance.
`shared` is used to share common dependencies between consumers and producers, reducing runtime download size and thus improving performance.

The `Shared` type is defined as follows:

Expand Down Expand Up @@ -137,9 +136,10 @@ The required version can be a version range. The default value is the dependency
- When one side sets requiredVersion and the other side sets singleton, the dependency of requiredVersion will be loaded, and the singleton side will directly use the dependency of requiredVersion, regardless of the version.

#### eager

:::warning
When `eager` is set to true, the shared dependencies will be packaged into the entry file, which will cause the entry file to be too large. Please open with caution.
`eager: true` is rarely recommended
`eager: true` is rarely recommended
:::

- Type: `boolean`
Expand Down
1 change: 1 addition & 0 deletions packages/native-federation-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This plugin is used to download the concatenated components mock that will be us
testsFolder?: string; // folder where all the files have been stored, default is '@mf-tests',
mocksFolder?: string; // folder where the concatenated files will be stored, default is './__mocks__',
deleteTestsFolder?: boolean; // indicate if the tests mock folder will be deleted before the job starts, default is 'true'
maxRetries?: number; // The number of times the plugin will try to download the mocks before failing, default is 3
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('hostPlugin', () => {
testsFolder: '@mf-tests',
deleteTestsFolder: true,
mocksFolder: './__mocks__',
maxRetries: 3,
});

expect(mapRemotesToDownload).toStrictEqual({
Expand All @@ -46,6 +47,7 @@ describe('hostPlugin', () => {
mocksFolder: './__mocks__',
testsFolder: 'custom-tests',
deleteTestsFolder: false,
maxRetries: 1,
};

const { hostOptions, mapRemotesToDownload } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const defaultOptions = {
testsFolder: '@mf-tests',
mocksFolder: './__mocks__',
deleteTestsFolder: true,
};
maxRetries: 3,
} satisfies Partial<HostOptions>;

const retrieveRemoteStringUrl = (remote: string) => {
const splittedRemote = remote.split('@');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const defaultOptions = {
distFolder: './dist',
deleteTestsFolder: true,
additionalBundlerConfig: {},
};
} satisfies Partial<RemoteOptions>;

const EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'mjs'];

Expand Down
4 changes: 3 additions & 1 deletion packages/native-federation-tests/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ describe('index', () => {
) as UnpluginOptions;
await expect(unplugin.writeBundle?.()).resolves.not.toThrow();

expect(dirTree(options.mocksFolder)).toMatchObject({
const testsFolder = join(projectRoot, options.mocksFolder);

expect(dirTree(testsFolder)).toMatchObject({
name: '__mocks__',
children: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/native-federation-tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { retrieveHostConfig } from './configurations/hostPlugin';
import { retrieveRemoteConfig } from './configurations/remotePlugin';
import { HostOptions } from './interfaces/HostOptions';
import { RemoteOptions } from './interfaces/RemoteOptions';
import { createTypesArchive, downloadTypesArchive } from './lib/archiveHandler';
import { createTestsArchive, downloadTypesArchive } from './lib/archiveHandler';
import { cleanMocksFolder } from './lib/mocksClean';

export const NativeFederationTestsRemote = createUnplugin(
Expand All @@ -35,7 +35,7 @@ export const NativeFederationTestsRemote = createUnplugin(
try {
await build(buildConfig);

await createTypesArchive(remoteOptions, compiledFilesFolder);
await createTestsArchive(remoteOptions, compiledFilesFolder);

if (remoteOptions.deleteTestsFolder) {
await rm(compiledFilesFolder, { recursive: true, force: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface HostOptions {
testsFolder?: string;
mocksFolder?: string;
deleteTestsFolder?: boolean;
maxRetries?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { join } from 'path';
import { afterAll, describe, expect, it, vi } from 'vitest';

import { RemoteOptions } from '../interfaces/RemoteOptions';
import { createTypesArchive, downloadTypesArchive } from './archiveHandler';
import { createTestsArchive, downloadTypesArchive } from './archiveHandler';

describe('archiveHandler', () => {
const tmpDir = mkdtempSync(join(os.tmpdir(), 'archive-handler'));
Expand All @@ -29,14 +29,14 @@ describe('archiveHandler', () => {
it('correctly creates archive', async () => {
const archivePath = join(tmpDir, `${remoteOptions.testsFolder}.zip`);

const archiveCreated = await createTypesArchive(remoteOptions, outDir);
const archiveCreated = await createTestsArchive(remoteOptions, outDir);

expect(archiveCreated).toBeTruthy();
expect(existsSync(archivePath)).toBeTruthy();
});

it('throws for unexisting outDir', async () => {
expect(createTypesArchive(remoteOptions, '/foo')).rejects.toThrowError();
expect(createTestsArchive(remoteOptions, '/foo')).rejects.toThrowError();
});
});

Expand All @@ -47,6 +47,7 @@ describe('archiveHandler', () => {
mocksFolder: archivePath,
testsFolder: tmpDir,
deleteTestsFolder: true,
maxRetries: 3,
};

it('throws for unexisting url', async () => {
Expand Down
47 changes: 30 additions & 17 deletions packages/native-federation-tests/src/lib/archiveHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RemoteOptions } from '../interfaces/RemoteOptions';
const retrieveTestsZipPath = (remoteOptions: Required<RemoteOptions>) =>
join(remoteOptions.distFolder, `${remoteOptions.testsFolder}.zip`);

export const createTypesArchive = async (
export const createTestsArchive = async (
remoteOptions: Required<RemoteOptions>,
compiledFilesFolder: string,
) => {
Expand All @@ -20,25 +20,38 @@ export const createTypesArchive = async (

const downloadErrorLogger =
(destinationFolder: string, fileToDownload: string) => (reason: Error) => {
reason.message = ansiColors.red(
`Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}', skipping...`,
);
throw reason;
throw {
...reason,
message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`,
};
};

export const downloadTypesArchive =
(hostOptions: Required<HostOptions>) =>
async ([destinationFolder, fileToDownload]: string[]) => {
try {
const response = await axios.get(fileToDownload, {
responseType: 'arraybuffer',
});
export const downloadTypesArchive = (hostOptions: Required<HostOptions>) => {
let retries = 0;
return async ([destinationFolder, fileToDownload]: string[]) => {
const destinationPath = join(hostOptions.mocksFolder, destinationFolder);

const destinationPath = join(hostOptions.mocksFolder, destinationFolder);
while (retries++ < hostOptions.maxRetries) {
try {
const response = await axios
.get(fileToDownload, { responseType: 'arraybuffer' })
.catch(downloadErrorLogger(destinationFolder, fileToDownload));

const zip = new AdmZip(Buffer.from(response.data));
zip.extractAllTo(destinationPath, true);
} catch (error) {
downloadErrorLogger(destinationFolder, fileToDownload)(error as Error);
const zip = new AdmZip(Buffer.from(response.data));
zip.extractAllTo(destinationPath, true);
break;
} catch (error: any) {
console.error(
ansiColors.red(
`Error during types archive download: ${
error?.message || 'unknown error'
}`,
),
);
if (retries >= hostOptions.maxRetries) {
throw error;
}
}
}
};
};
4 changes: 2 additions & 2 deletions packages/native-federation-tests/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export default defineConfig({
// },

test: {
globals: true,
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'jsdom',
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
},
});
1 change: 1 addition & 0 deletions packages/native-federation-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This plugin is used to download the federated types.
moduleFederationConfig: any; // the configuration same configuration provided to the module federation plugin, it is MANDATORY
typesFolder?: string; // folder where all the files will be stored, default is '@mf-types',
deleteTypesFolder?: boolean; // indicate if the types folder will be deleted before the job starts, default is 'true'
maxRetries?: number; // The number of times the plugin will try to download the types before failing, default is 3
}
```

Expand Down
6 changes: 3 additions & 3 deletions packages/native-federation-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
"dependencies": {
"adm-zip": "^0.5.10",
"ansi-colors": "^4.1.3",
"axios": "^1.3.4",
"rambda": "^7.5.0",
"unplugin": "^1.3.1"
"axios": "^1.6.7",
"rambda": "^9.0.1",
"unplugin": "^1.6.0"
},
"peerDependencies": {
"typescript": "^4.9.0 || ^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('hostPlugin', () => {
moduleFederationConfig,
typesFolder: '@mf-types',
deleteTypesFolder: true,
maxRetries: 3,
});

expect(mapRemotesToDownload).toStrictEqual({
Expand All @@ -44,6 +45,7 @@ describe('hostPlugin', () => {
moduleFederationConfig,
typesFolder: 'custom-types',
deleteTypesFolder: false,
maxRetries: 1,
};

const { hostOptions, mapRemotesToDownload } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { HostOptions } from '../interfaces/HostOptions';
const defaultOptions = {
typesFolder: '@mf-types',
deleteTypesFolder: true,
};
maxRetries: 3,
} satisfies Partial<HostOptions>;

const retrieveRemoteStringUrl = (remote: string) => {
const splittedRemote = remote.split('@');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const defaultOptions = {
deleteTypesFolder: true,
additionalFilesToCompile: [],
compilerInstance: 'tsc' as const,
};
} satisfies Partial<RemoteOptions>;

const readTsConfig = ({
tsConfigPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface HostOptions {
moduleFederationConfig: any;
typesFolder?: string;
deleteTypesFolder?: boolean;
maxRetries?: number;
}
Loading