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

WIP: exports fields #3227

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/honest-yaks-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

ensure when dev is false that type generation only runs once
38 changes: 36 additions & 2 deletions apps/website-new/docs/en/configure/shared.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,45 @@ interface SharedObject {
[sharedName: string]: SharedConfig;
}

type SharedItem = string;

interface SharedConfig {
singleton?: boolean;
requiredVersion?: string;
/**
* Include the provided and fallback module directly instead behind an async request. This allows to use this shared module in initial load too. All possible shared modules need to be eager too.
*/
eager?: boolean;
/**
* Provided module that should be provided to share scope. Also acts as fallback module if no shared module is found in share scope or version isn't valid. Defaults to the property name.
*/
import?: false | SharedItem;
/**
* Package name to determine required version from description file. This is only needed when package name can't be automatically determined from request.
*/
packageName?: string;
/**
* Version requirement from module in share scope.
*/
requiredVersion?: false | string;
/**
* Module is looked up under this key from the share scope.
*/
shareKey?: string;
/**
* Share scope name.
*/
shareScope?: string;
/**
* Allow only a single version of the shared module in share scope (disabled by default).
*/
singleton?: boolean;
/**
* Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).
*/
strictVersion?: boolean;
/**
* Version of the provided module. Will replace lower matching versions, but not higher.
*/
version?: false | string;
}
```

Expand Down
38 changes: 36 additions & 2 deletions apps/website-new/docs/zh/configure/shared.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,45 @@ interface SharedObject {
[sharedName: string]: SharedConfig;
}

type SharedItem = string;

interface SharedConfig {
singleton?: boolean;
requiredVersion?: string;
/**
* Include the provided and fallback module directly instead behind an async request. This allows to use this shared module in initial load too. All possible shared modules need to be eager too.
*/
eager?: boolean;
/**
* Provided module that should be provided to share scope. Also acts as fallback module if no shared module is found in share scope or version isn't valid. Defaults to the property name.
*/
import?: false | SharedItem;
/**
* Package name to determine required version from description file. This is only needed when package name can't be automatically determined from request.
*/
packageName?: string;
/**
* Version requirement from module in share scope.
*/
requiredVersion?: false | string;
/**
* Module is looked up under this key from the share scope.
*/
shareKey?: string;
/**
* Share scope name.
*/
shareScope?: string;
/**
* Allow only a single version of the shared module in share scope (disabled by default).
*/
singleton?: boolean;
/**
* Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).
*/
strictVersion?: boolean;
/**
* Version of the provided module. Will replace lower matching versions, but not higher.
*/
version?: false | string;
}
```

Expand Down
1 change: 1 addition & 0 deletions packages/bridge/bridge-react-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"module": "./dist/index.es.js",
"types": "./dist/index.cjs.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.cjs.d.ts",
"import": "./dist/index.es.js",
Expand Down
1 change: 1 addition & 0 deletions packages/bridge/bridge-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.es.js",
Expand Down
1 change: 1 addition & 0 deletions packages/chrome-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"README.md"
],
"exports": {
"./package.json": "./package.json",
".": {
"require": "./dist/lib/App.js",
"import": "./dist/es/App.js",
Expand Down
1 change: 1 addition & 0 deletions packages/data-prefetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"access": "public"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.mjs",
"require": "./dist/index.cjs",
Expand Down
1 change: 1 addition & 0 deletions packages/dts-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"README.md"
],
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"require": "./dist/index.js"
Expand Down
6 changes: 5 additions & 1 deletion packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
return fn;
};
const generateTypesFn = getGenerateTypesFn();

let compiledOnce = false;
compiler.hooks.thisCompilation.tap('mf:generateTypes', (compilation) => {
compilation.hooks.processAssets.tapPromise(
{
Expand All @@ -82,6 +82,9 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,
},
async () => {
if (pluginOptions.dev === false && compiledOnce) {
return;
}
try {
const { zipTypesPath, apiTypesPath, zipName, apiFileName } =
retrieveTypesAssetsInfo(finalOptions.remote);
Expand Down Expand Up @@ -124,6 +127,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
),
);
}
compiledOnce = true;
} catch (err) {
console.error(err);
}
Expand Down
1 change: 1 addition & 0 deletions packages/enhanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}
},
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/src/index.d.ts",
"require": "./dist/src/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/enhanced/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"executor": "@nx/js:tsc",
"outputs": ["{workspaceRoot}/packages/enhanced/dist"],
"options": {
"generatePackageJson": false,
"outputPath": "packages/enhanced/dist",
"main": "packages/enhanced/src/index.ts",
"tsConfig": "packages/enhanced/tsconfig.lib.json",
Expand Down
1 change: 1 addition & 0 deletions packages/error-codes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"module": "./dist/index.esm.mjs",
"types": "./dist/index.cjs.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.mjs",
"require": "./dist/index.cjs.js"
Expand Down
1 change: 1 addition & 0 deletions packages/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"README.md"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.cjs.d.ts",
"import": "./dist/index.esm.js",
Expand Down
1 change: 1 addition & 0 deletions packages/managers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"webpack": "5.93.0"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
Expand Down
1 change: 1 addition & 0 deletions packages/manifest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"chalk": "3.0.0"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
Expand Down
1 change: 1 addition & 0 deletions packages/modernjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build": "modern build"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/esm/cli/index.js",
"require": "./dist/cjs/cli/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/native-federation-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"README.md"
],
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/native-federation-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"access": "public"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs-mf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"postinstall": "echo \"Deprecation Notice: We intend to deprecate 'nextjs-mf'. Please see https://github.com/module-federation/core/issues/3153 for more details.\""
},
"exports": {
"./package.json": "./package.json",
".": "./dist/src/index.js",
"./utils": "./dist/utils/index.js",
"./*": "./*"
Expand Down
5 changes: 1 addition & 4 deletions packages/nextjs-mf/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"generatePackageJson": false,
"outputPath": "packages/nextjs-mf/dist",
"main": "packages/nextjs-mf/src/index.ts",
"tsConfig": "packages/nextjs-mf/tsconfig.lib.json",
Expand Down Expand Up @@ -51,10 +52,6 @@
{
"command": "nx run nextjs-mf:build",
"forwardAllArgs": false
},
{
"command": "rm ./packages/nextjs-mf/dist/package.json",
"forwardAllArgs": false
}
]
}
Expand Down
5 changes: 1 addition & 4 deletions packages/node/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"generatePackageJson": false,
"outputPath": "packages/node/dist",
"main": "packages/node/src/index.js",
"tsConfig": "packages/node/tsconfig.lib.json",
Expand Down Expand Up @@ -48,10 +49,6 @@
{
"command": "nx run node:build",
"forwardAllArgs": false
},
{
"command": "rm ./packages/node/dist/package.json",
"forwardAllArgs": false
}
]
}
Expand Down
1 change: 1 addition & 0 deletions packages/retry-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"README.md"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/rsbuild-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"license": "MIT",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@rspack/core": "^1.0.2"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"access": "public"
},
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.cjs.d.ts",
"import": "./dist/index.esm.mjs",
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"README.md"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.cjs.d.ts",
"import": "./dist/index.esm.mjs",
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"module": "./dist/index.esm.mjs",
"types": "./dist/index.cjs.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.cjs.d.ts",
"import": "./dist/index.esm.mjs",
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"module": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/src/index.js",
"require": "./dist/src/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/third-party-dts-extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"access": "public"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
}
},
"exports": {
"./package.json": "./package.json",
".": {
"require": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-bundler-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@module-federation/sdk": "workspace:*"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.esm.mjs",
"require": "./dist/index.cjs.js"
Expand Down
Loading