Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/plugin-micro-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
"*.d.ts"
],
"devDependencies": {
"@types/babel__core": "^7",
"@vitest/coverage-v8": "^4.0.12",
"tsdown": "catalog:tools",
"typescript": "catalog:tools",
"vitest": "^4.0.12"
},
"dependencies": {
"@babel/core": "7.28.5",
"@granite-js/plugin-core": "workspace:*",
"@granite-js/utils": "workspace:*",
"es-toolkit": "^1.39.8",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-micro-frontend/src/microFrontendPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { getPreludeConfig } from './prelude';
import { fetchRemoteBundle } from './remote';
import { virtualSharedConfig } from './resolver';
import { createScopedTimersTransformer } from './scopedTimers';
import type { MicroFrontendPluginOptions } from './types';
import { intoShared } from './utils/intoShared';

Expand All @@ -21,7 +22,7 @@
const preludePath = path.join(localDir, 'micro-frontend-runtime.js');
fs.writeFileSync(preludePath, preludeConfig.preludeScript);

/**

Check warning on line 25 in packages/plugin-micro-frontend/src/microFrontendPlugin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'TODO' comment: '* * @todo `MPACK_DEV_SERVER` flag should...'
* @TODO `MPACK_DEV_SERVER` flag should be removed after next version of bundle loader is released and load bundle dynamically at JS runtime.
*/
if (process.env.MPACK_DEV_SERVER === 'true' && options.remote) {
Expand All @@ -35,10 +36,16 @@
const isReactNativeShared = Boolean(nonEagerEntries.find(([libName]) => libName === 'react-native'));

const virtualShared = virtualSharedConfig(nonEagerEntries);
const isRemoteContainer = options.remote == null;

return {
name: 'micro-frontend-plugin',
config: {
transformer: isRemoteContainer
? {
transformSync: createScopedTimersTransformer({ containerName: options.name }),
}
: undefined,
extra: isReactNativeShared ? { skipReactNativePolyfills: true, skipReactNativeInitializeCore: true } : undefined,
resolver: {
alias: virtualShared.alias,
Expand Down
22 changes: 17 additions & 5 deletions packages/plugin-micro-frontend/src/runtime/createContainer.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import type { RemoteConfig, SharedConfig, ExposeConfig } from '../types';
import { createScopeRef, getContainerScope, getRemoteContext } from './remoteScope';
import type { Container } from './types';

export function createContainer(
name: string,
config: { remote?: RemoteConfig; shared?: SharedConfig; exposes?: ExposeConfig }
) {
if (typeof global.__MICRO_FRONTEND__.__INSTANCES__[name] === 'number') {
throw new Error(`'${name}' container already registered`);
}

const containerIndex = global.__MICRO_FRONTEND__.__INSTANCES__.length;
const scope = getContainerScope(name, config);
const container: Container = {
name,
config,
exposeMap: {},
};

if (scope != null) {
container.scope = scope;
scope.name = name;
scope.container = container;
getRemoteContext().scopes[name] = createScopeRef(scope);

return container;
}

if (typeof global.__MICRO_FRONTEND__.__INSTANCES__[name] === 'number') {
throw new Error(`'${name}' container already registered`);
}

const containerIndex = global.__MICRO_FRONTEND__.__INSTANCES__.length;

Object.defineProperty(global.__MICRO_FRONTEND__.__INSTANCES__, name, {
value: containerIndex,
enumerable: false,
Expand Down
16 changes: 16 additions & 0 deletions packages/plugin-micro-frontend/src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,21 @@ export { createContainer } from './createContainer';
export { registerShared } from './registerShared';
export { exposeModule } from './exposeModule';
export { getContainer, parseRemotePath, importRemoteModule } from './utils';
export {
cancelScopedAnimationFrame,
clearCurrentRemoteScope,
clearScopedInterval,
clearScopedTimeout,
createRemoteScope,
getCurrentRemoteScope,
getRemoteContext,
getRemoteScope,
getScopedResourceScope,
releaseRemoteScope,
requestScopedAnimationFrame,
setScopedInterval,
setScopedTimeout,
} from './remoteScope';

export type { RuntimeContext, Container, Module, SharedModuleRegistry } from './types';
export type { RemoteContext, RemoteScope, RemoteScopeRef } from './remoteScope';
Loading
Loading