Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
216bbeb
fix(metro-core): normalize windows module paths
cursoragent Feb 16, 2026
4c98cc6
chore(metro-core): format helper paths
cursoragent Feb 16, 2026
75fa156
ci(module-federation): add metro windows job
cursoragent Feb 17, 2026
339d121
test(metro-core): normalize path expectations
cursoragent Feb 17, 2026
c65be96
test(module-federation): fix metro app jest transforms
cursoragent Feb 17, 2026
0e4ce11
test(module-federation): set metro app babel transform
cursoragent Feb 17, 2026
a946207
test(module-federation): widen metro jest transforms
cursoragent Feb 17, 2026
6ccce11
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 19, 2026
ace3a15
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 19, 2026
e501e1e
fix(metro-core): address windows runtime review comments
ScriptedAlchemy Feb 20, 2026
2164568
fix(metro-core): normalize virtual entry paths on windows
ScriptedAlchemy Feb 20, 2026
b140982
fix: normalize metro path handling on windows
ScriptedAlchemy Feb 20, 2026
163726e
refactor(metro-core): use node absolute path checks
ScriptedAlchemy Feb 20, 2026
c7484fe
test(metro-core): make path utils spec windows-safe
ScriptedAlchemy Feb 20, 2026
cb3464c
chore: add metro windows compatibility changeset
ScriptedAlchemy Feb 20, 2026
2266bbb
ci(metro-core): align windows job with e2e intent
ScriptedAlchemy Feb 24, 2026
6aa30c5
Merge remote-tracking branch 'origin/main' into cursor/module-federat…
ScriptedAlchemy Feb 24, 2026
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/fair-eels-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/metro': patch
---

fix Metro Windows compatibility by normalizing path handling and source URL generation across absolute and relative entry paths, and tighten expose key resolution to avoid incorrect extension fallback matches.
40 changes: 40 additions & 0 deletions .github/workflows/e2e-metro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,46 @@ jobs:
name: maestro-logs-android-${{ env.METRO_APP_NAME }}
path: ~/.maestro/tests/

e2e-metro-windows:
needs: e2e-metro-check-affected
if: needs.e2e-metro-check-affected.outputs.should_run_e2e == 'true'
runs-on: windows-latest
timeout-minutes: 30
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Set up pnpm
uses: pnpm/action-setup@v4

- name: Set up Node.js 20
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'

- name: Export SKIP_DEVTOOLS_POSTINSTALL
run: echo "SKIP_DEVTOOLS_POSTINSTALL=true" >> "$GITHUB_ENV"
shell: bash

- name: Install pnpm dependencies
run: pnpm install --frozen-lockfile

- name: Build Metro packages
run: npx nx run-many --targets=build --projects=metro-core,metro-plugin-rnc-cli,metro-plugin-rnef --parallel=2

- name: Test Metro packages
run: npx nx run-many --targets=test --projects=metro-core,metro-plugin-rnc-cli --parallel=2

- name: Build Metro example remotes for iOS
run: pnpm --filter example-mini --filter example-nested-mini run build:ios

- name: Build Metro example remotes for Android
run: pnpm --filter example-mini --filter example-nested-mini run build:android

e2e-metro-ios:
needs: e2e-metro-check-affected
if: needs.e2e-metro-check-affected.outputs.should_run_e2e == 'true'
Expand Down
6 changes: 6 additions & 0 deletions apps/metro-example-host/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
preset: 'react-native',
transformIgnorePatterns: [
'node_modules[\\\\/](?!.*(react-native|@react-native)[\\\\/])',
],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', {configFile: './babel.config.js'}],
},
};
6 changes: 6 additions & 0 deletions apps/metro-example-mini/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
preset: 'react-native',
transformIgnorePatterns: [
'node_modules[\\\\/](?!.*(react-native|@react-native)[\\\\/])',
],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', {configFile: './babel.config.js'}],
},
};
6 changes: 6 additions & 0 deletions apps/metro-example-nested-mini/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
preset: 'react-native',
transformIgnorePatterns: [
'node_modules[\\\\/](?!.*(react-native|@react-native)[\\\\/])',
],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', {configFile: './babel.config.js'}],
},
};
36 changes: 36 additions & 0 deletions packages/metro-core/__tests__/commands/utils/path-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, it } from 'vitest';
import {
normalizeOutputRelativePath,
toFileSourceUrl,
} from '../../../src/commands/utils/path-utils';

describe('commands path utils', () => {
it('normalizes relative output paths to posix separators', () => {
expect(normalizeOutputRelativePath('shared\\lodash.bundle')).toBe(
'shared/lodash.bundle',
);
});

it('builds file urls from normalized relative paths', () => {
const parsed = new URL(toFileSourceUrl('exposed\\info.bundle'));
expect(parsed.protocol).toBe('file:');
expect(parsed.search).toBe('');
expect(parsed.hash).toBe('');
expect(parsed.pathname.endsWith('/exposed/info.bundle')).toBe(true);
});

it('encodes reserved characters as pathname segments', () => {
const hashParsed = new URL(toFileSourceUrl('shared/#hash.bundle'));
expect(hashParsed.hash).toBe('');
expect(hashParsed.pathname.endsWith('/shared/%23hash.bundle')).toBe(true);

const queryParsed = new URL(toFileSourceUrl('shared/?query.bundle'));
expect(queryParsed.search).toBe('');
expect(queryParsed.pathname.endsWith('/shared/%3Fquery.bundle')).toBe(true);

const percentParsed = new URL(toFileSourceUrl('shared/%25literal.bundle'));
expect(percentParsed.pathname.endsWith('/shared/%2525literal.bundle')).toBe(
true,
);
});
});
62 changes: 62 additions & 0 deletions packages/metro-core/__tests__/plugin/babel-transformer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import fs from 'node:fs';
import path from 'node:path';
import { vol } from 'memfs';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createBabelTransformer } from '../../src/plugin/babel-transformer';
import type { ModuleFederationConfigNormalized } from '../../src/types';

function createConfig(): ModuleFederationConfigNormalized {
return {
name: 'test-app',
filename: 'remote.js',
remotes: {},
exposes: {},
shared: {},
shareStrategy: 'loaded-first',
plugins: [],
};
}

describe('createBabelTransformer', () => {
afterEach(() => {
vol.reset();
vi.restoreAllMocks();
});

it('escapes Windows paths for require()', () => {
const realReadFileSync = fs.readFileSync.bind(fs);
vi.spyOn(fs, 'readFileSync').mockImplementation(((filePath, options) => {
const targetPath = filePath.toString();
if (vol.existsSync(targetPath)) {
return vol.readFileSync(targetPath, options as never);
}
return realReadFileSync(filePath, options as never);
}) as typeof fs.readFileSync);
vi.spyOn(fs, 'writeFileSync').mockImplementation(((
filePath,
data,
options,
) => {
const targetPath = filePath.toString();
vol.mkdirSync(path.dirname(targetPath), { recursive: true });
vol.writeFileSync(targetPath, data, options as never);
}) as typeof fs.writeFileSync);

const tmpDirPath = path.join('/virtual', '.mf');
vol.mkdirSync(tmpDirPath, { recursive: true });
const windowsPath =
'C:\\Users\\someone\\project\\node_modules\\metro-babel-transformer\\src\\index.js';

const outputPath = createBabelTransformer({
blacklistedPaths: [],
federationConfig: createConfig(),
originalBabelTransformerPath: windowsPath,
tmpDirPath,
enableInitializeCorePatching: false,
enableRuntimeRequirePatching: false,
});

const output = fs.readFileSync(outputPath, 'utf-8');
expect(output).toContain(`require(${JSON.stringify(windowsPath)})`);
});
});
14 changes: 14 additions & 0 deletions packages/metro-core/__tests__/plugin/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, it } from 'vitest';
import { toPosixPath } from '../../src/plugin/helpers';

describe('toPosixPath', () => {
it('converts backslashes to forward slashes', () => {
expect(toPosixPath('C:\\Users\\someone\\project\\src\\index.js')).toBe(
'C:/Users/someone/project/src/index.js',
);
});

it('leaves posix paths unchanged', () => {
expect(toPosixPath('/usr/local/bin')).toBe('/usr/local/bin');
});
});
11 changes: 6 additions & 5 deletions packages/metro-core/__tests__/plugin/normalize-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vi.mock('node:fs', () => {
return { ...memfs, default: memfs };
});

import { toPosixPath } from '../../src/plugin/helpers';
import { normalizeOptions } from '../../src/plugin/normalize-options';

let projectCount = 0;
Expand Down Expand Up @@ -69,8 +70,8 @@ describe('normalizeOptions', () => {
'../../src/modules/metroCorePlugin.ts',
);
expect(normalized.plugins).toEqual([
path.relative(tmpDirPath, metroCorePluginPath),
path.relative(tmpDirPath, runtimePluginPath),
toPosixPath(path.relative(tmpDirPath, metroCorePluginPath)),
toPosixPath(path.relative(tmpDirPath, runtimePluginPath)),
]);
});

Expand Down Expand Up @@ -104,9 +105,9 @@ describe('normalizeOptions', () => {
'../../src/modules/metroCorePlugin.ts',
);
expect(normalized.plugins).toEqual([
path.relative(tmpDirPath, metroCorePluginPath),
path.relative(tmpDirPath, runtimePluginPath),
path.relative(tmpDirPath, runtimePluginTwoPath),
toPosixPath(path.relative(tmpDirPath, metroCorePluginPath)),
toPosixPath(path.relative(tmpDirPath, runtimePluginPath)),
toPosixPath(path.relative(tmpDirPath, runtimePluginTwoPath)),
]);
});
});
21 changes: 21 additions & 0 deletions packages/metro-core/__tests__/plugin/rewrite-request.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest';
import { createRewriteRequest } from '../../src/plugin/rewrite-request';

describe('createRewriteRequest', () => {
it('normalizes manifest rewrite paths to posix separators', () => {
const rewriteRequest = createRewriteRequest({
config: {
projectRoot: 'C:\\repo\\app',
server: {},
} as any,
originalEntryFilename: 'index.js',
remoteEntryFilename: 'mini.bundle',
manifestPath: 'C:\\repo\\app\\node_modules\\.mf\\mf-manifest.json',
tmpDirPath: 'C:\\repo\\app\\node_modules\\.mf',
});

expect(rewriteRequest('/mf-manifest.json')).toBe(
'/[metro-project]/node_modules/.mf/mf-manifest.json',
);
});
});
112 changes: 112 additions & 0 deletions packages/metro-core/__tests__/plugin/serializer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ConfigError } from '../../src/utils/errors';

vi.mock('../../src/utils/metro-compat', () => {
const baseJSBundle = vi.fn(() => ({ mocked: true }));

return {
CountingSet: class CountingSet<T> extends Set<T> {},
baseJSBundle,
bundleToString: vi.fn(() => ({ code: 'serialized-output' })),
};
});

import { getModuleFederationSerializer } from '../../src/plugin/serializer';
import { baseJSBundle } from '../../src/utils/metro-compat';

function createSerializer(exposes: Record<string, string>) {
return getModuleFederationSerializer(
{
name: 'MFExampleMini',
filename: 'mini.bundle',
remotes: {},
exposes,
shared: {},
shareStrategy: 'loaded-first',
plugins: [],
},
true,
);
}

function createSerializerOptions(projectRoot = '/projectRoot') {
return {
runModule: false,
modulesOnly: true,
projectRoot,
} as any;
}

function createGraph() {
return {
dependencies: new Map(),
} as any;
}

describe('getModuleFederationSerializer', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('matches expose paths when the entry path contains backslashes', async () => {
const serializer = createSerializer({ './info': './src/info.tsx' });

await expect(
serializer(
'/projectRoot/src\\info.tsx',
[],
createGraph(),
createSerializerOptions(),
),
).resolves.toBe('serialized-output');
expect(baseJSBundle).toHaveBeenCalledTimes(1);
});

it('matches expose paths without extension against resolved entry files', async () => {
const serializer = createSerializer({ './info': './src/info' });

await expect(
serializer(
'/projectRoot/src/info.tsx',
[],
createGraph(),
createSerializerOptions(),
),
).resolves.toBe('serialized-output');
expect(baseJSBundle).toHaveBeenCalledTimes(1);
});

it('prefers exact expose path match over extensionless fallback', async () => {
const serializer = createSerializer({
'./js': './src/info.js',
'./tsx': './src/info.tsx',
});

await expect(
serializer(
'/projectRoot/src/info.tsx',
[],
createGraph(),
createSerializerOptions(),
),
).resolves.toBe('serialized-output');
expect(baseJSBundle).toHaveBeenCalledTimes(1);

const preModules = vi.mocked(baseJSBundle).mock.calls[0][1] as any[];
expect(preModules[0].output[0].data.code).toContain('["exposed/tsx"]');
expect(preModules[1].output[0].data.code).toContain('["exposed/tsx"]');
});

it('throws a config error when no expose entry matches', async () => {
const serializer = createSerializer({ './other': './src/other.tsx' });

await expect(
serializer(
'/projectRoot/src/info.tsx',
[],
createGraph(),
createSerializerOptions(),
),
).rejects.toBeInstanceOf(ConfigError);
});
});
Loading
Loading