Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 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
9651808
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 25, 2026
ddb7b52
fix(module-federation): build shared packages in metro windows job
ScriptedAlchemy Feb 25, 2026
ec44c70
ci(module-federation): limit metro windows prebuild to required packages
ScriptedAlchemy Feb 25, 2026
1517d0d
ci(module-federation): remove metro windows e2e job
ScriptedAlchemy Feb 25, 2026
5c060ba
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 25, 2026
cc99a5c
fix(metro-core): revert workflow and jest config changes per review
ScriptedAlchemy Feb 26, 2026
2062b29
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 26, 2026
4250f2b
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 26, 2026
925400f
chore: merge main into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 27, 2026
986ed96
fix(metro-core): restore dts default in normalized options
ScriptedAlchemy Feb 27, 2026
58e3887
fix(metro-core): preserve package runtime plugin specifiers
ScriptedAlchemy Feb 27, 2026
571df2b
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 27, 2026
db7f2c0
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 28, 2026
8ee5250
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Feb 28, 2026
96478e6
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Mar 2, 2026
d8e354f
Merge branch 'main' into cursor/module-federation-windows-runtime-606f
ScriptedAlchemy Mar 2, 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.
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');
Comment thread
ScriptedAlchemy marked this conversation as resolved.
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 @@ -88,8 +89,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 @@ -200,9 +201,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)),
]);
});

Expand Down
28 changes: 7 additions & 21 deletions packages/metro-core/__tests__/plugin/rewrite-request.spec.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { createRewriteRequest } from '../../src/plugin/rewrite-request';

describe('createRewriteRequest', () => {
it('rewrites dts asset requests to tmp dir when names are available', () => {
const projectRoot = '/virtual/metro-core';
it('normalizes manifest rewrite paths to posix separators', () => {
const rewriteRequest = createRewriteRequest({
config: {
projectRoot,
projectRoot: 'C:\\repo\\app',
server: {},
} as any,
originalEntryFilename: 'index.js',
remoteEntryFilename: 'remoteEntry.js',
manifestPath: path.join(
projectRoot,
'node_modules',
'.mf-metro',
'mf-manifest.json',
),
tmpDirPath: path.join(projectRoot, 'node_modules', '.mf-metro'),
getDtsAssetNames: () => ({
zipName: '@mf-types.zip',
apiFileName: '@mf-types.d.ts',
}),
remoteEntryFilename: 'mini.bundle',
manifestPath: 'C:\\repo\\app\\node_modules\\.mf\\mf-manifest.json',
tmpDirPath: 'C:\\repo\\app\\node_modules\\.mf',
});

expect(rewriteRequest('/@mf-types.zip')).toBe(
'/node_modules/.mf-metro/@mf-types.zip',
);
expect(rewriteRequest('/@mf-types.d.ts')).toBe(
'/node_modules/.mf-metro/@mf-types.d.ts',
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);
});
});
42 changes: 34 additions & 8 deletions packages/metro-core/__tests__/plugin/validate-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,54 @@ describe('validateOptions', () => {
).toThrow('shared');
});

it('accepts dts as a boolean or object', () => {
it('throws for windows-style relative shared module names', () => {
expect(() =>
validateOptions({
...getValidConfig(),
dts: true,
shared: {
...getValidConfig().shared,
'.\\local-shared': {
singleton: false,
eager: false,
version: '1.0.0',
requiredVersion: '1.0.0',
},
},
} as any),
).not.toThrow();
).toThrow('Relative paths are not supported');
});

it('throws for windows-style absolute shared module names', () => {
expect(() =>
validateOptions({
...getValidConfig(),
dts: { generateAPITypes: true },
shared: {
...getValidConfig().shared,
'C:\\project\\shared\\module': {
singleton: false,
eager: false,
version: '1.0.0',
requiredVersion: '1.0.0',
},
},
} as any),
).not.toThrow();
).toThrow('Absolute paths are not supported');
});

it('throws for invalid dts type', () => {
it('throws for UNC absolute shared module names', () => {
expect(() =>
validateOptions({
...getValidConfig(),
dts: 1,
shared: {
...getValidConfig().shared,
'\\\\server\\share\\module': {
singleton: false,
eager: false,
version: '1.0.0',
requiredVersion: '1.0.0',
},
},
} as any),
).toThrow("Option 'dts' must be a boolean or a plain object.");
).toThrow('Absolute paths are not supported');
});
});
Loading
Loading