Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rsbuild-plugin): update mf format judgment conditions #3564

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/many-rings-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/rsbuild-plugin': patch
---

chore(rsbuild-plugin): update mf format judgment conditions
2 changes: 1 addition & 1 deletion packages/modernjs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';

export default defineConfig({
cacheDir: '../../node_modules/.vite/native-federation-tests',
cacheDir: '../../node_modules/.vite/modernjs',

plugins: [nxViteTsPaths()],

Expand Down
4 changes: 4 additions & 0 deletions packages/rsbuild-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
]
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/packages/rsbuild-plugin"]
},
"pre-release": {
"executor": "nx:run-commands",
"options": {
Expand Down
85 changes: 85 additions & 0 deletions packages/rsbuild-plugin/src/cli/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { describe, expect, it } from 'vitest';
import { isMFFormat } from '../../src/cli';
import type { Rspack } from '@rsbuild/core';

describe('isMFFormat', () => {
it('should return true when library config is not present', () => {
const config: Partial<Rspack.Configuration> = {
output: {},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(true);
});

it('should return true when library is not an object', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: 'myLib',
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(true);
});

it('should return true when library is an array', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: ['myLib'],
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(true);
});

it('should return false when library.type is commonjs', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: {
type: 'commonjs',
},
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(false);
});

it('should return false when library.type is umd', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: {
type: 'umd',
},
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(false);
});

it('should return false when library.type is modern-module', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: {
type: 'modern-module',
},
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(false);
});

it('should return false when library.type contains commonjs', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: {
type: 'commonjs-static',
},
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(false);
});

it('should return true when library.type is other value', () => {
const config: Partial<Rspack.Configuration> = {
output: {
library: {
type: 'var',
},
},
};
expect(isMFFormat(config as Rspack.Configuration)).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/rsbuild-plugin/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function isMFFormat(bundlerConfig: Rspack.Configuration) {
typeof library === 'object' &&
!Array.isArray(library) &&
'type' in library &&
LIB_FORMAT.includes(library.type)
(LIB_FORMAT.includes(library.type) || /commonjs/.test(library.type))
);
}

Expand Down
24 changes: 24 additions & 0 deletions packages/rsbuild-plugin/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';

import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';

export default defineConfig({
cacheDir: '../../node_modules/.vite/rsbuild-plugin',

plugins: [nxViteTsPaths()],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

test: {
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
},
});
Loading