@appshell/webpack-plugin 1.0.0-alpha.24 → 1.0.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/main.js +3 -3
- package/dist/types/config/src/index.d.ts +1 -1
- package/dist/types/config/src/types.d.ts +2 -11
- package/dist/types/runtime/src/errors.d.ts +32 -0
- package/dist/types/runtime/src/index.d.ts +4 -0
- package/dist/types/runtime/src/store.d.ts +25 -0
- package/dist/types/runtime/src/types.d.ts +9 -0
- package/dist/types/runtime/src/wire.d.ts +26 -0
- package/dist/types/webpack-plugin/src/index.d.ts +1 -0
- package/dist/types/webpack-plugin/src/shared.d.ts +36 -0
- package/package.json +3 -3
|
@@ -11,6 +11,6 @@ export { default as outdated } from './outdated';
|
|
|
11
11
|
export { activate, publish } from './publish';
|
|
12
12
|
export type { PublishOptions, PublishResult } from './publish';
|
|
13
13
|
export { default as sync } from './sync';
|
|
14
|
-
export type { AppshellComposition, AppshellConfig, AppshellConfigRemote, AppshellIndex, AppshellManifest, AppshellRemote, AppshellTemplate, AppshellTokenUsage, ComparisonResult, ComparisonResults, ComparisonTarget, Metadata, ModuleFederationPluginOptions, PackageSpec, ResolvedRemote, Schema, SharedConfig, SharedModuleSpec, } from './types';
|
|
14
|
+
export type { AppshellComposition, AppshellConfig, AppshellConfigRemote, AppshellIndex, AppshellManifest, AppshellRemote, AppshellTemplate, AppshellTokenUsage, ComparisonResult, ComparisonResults, ComparisonTarget, Metadata, ModuleFederationPluginOptions, PackageSpec, ResolvedRemote, Schema, SharedConfig, SharedObject, SharedModuleSpec, } from './types';
|
|
15
15
|
export * as utils from './utils';
|
|
16
16
|
export * as validators from './validators';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { AppshellIndex, AppshellRemote, Metadata } from '@appshell/runtime';
|
|
1
2
|
import { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
|
|
3
|
+
export type { AppshellIndex, AppshellRemote, Metadata } from '@appshell/runtime';
|
|
2
4
|
export type Schema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
3
5
|
export type ConfigValidator = {
|
|
4
6
|
validate: <T>(...config: T[]) => void;
|
|
@@ -72,15 +74,6 @@ export type AppshellTemplate<TMetadata = Metadata> = {
|
|
|
72
74
|
overrides?: AppshellOverrides;
|
|
73
75
|
};
|
|
74
76
|
/** Appshell manifest types */
|
|
75
|
-
export type AppshellRemote<TMetadata = Metadata> = {
|
|
76
|
-
id: string;
|
|
77
|
-
manifestUrl: string;
|
|
78
|
-
remoteEntryUrl: string;
|
|
79
|
-
scope: string;
|
|
80
|
-
module: string;
|
|
81
|
-
shareScope?: string;
|
|
82
|
-
metadata: TMetadata;
|
|
83
|
-
};
|
|
84
77
|
export type AppshellOverrides = {
|
|
85
78
|
vars: Record<string, Record<string, string | number | undefined>>;
|
|
86
79
|
};
|
|
@@ -105,8 +98,6 @@ export type AppshellManifest<TMetadata = Metadata> = {
|
|
|
105
98
|
tokens?: Record<string, AppshellTokenUsage>;
|
|
106
99
|
overrides?: AppshellOverrides;
|
|
107
100
|
};
|
|
108
|
-
export type AppshellIndex = Record<string, string>;
|
|
109
|
-
export type Metadata = Record<string, unknown>;
|
|
110
101
|
/** An `AppshellRemote` the registry already resolved, so the browser needs no manifest fetch. */
|
|
111
102
|
export type ResolvedRemote<TMetadata = Metadata> = AppshellRemote<TMetadata>;
|
|
112
103
|
/**
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A package asked for vars that were never delivered.
|
|
3
|
+
*
|
|
4
|
+
* Almost always one of three things: the package was loaded outside `remoteLoader`
|
|
5
|
+
* (a test, a storybook, a direct import), the host and the package resolved separate
|
|
6
|
+
* copies of `@appshell/runtime` because one of them failed to declare it as a
|
|
7
|
+
* singleton, or the scope compiled into the package is not the scope the registry
|
|
8
|
+
* knows it by.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MissingVarsError extends Error {
|
|
11
|
+
readonly scope: string;
|
|
12
|
+
constructor(scope: string, known: string[]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Something tried to replace vars that were already delivered for a scope.
|
|
16
|
+
*
|
|
17
|
+
* The first write wins and is final. Within one page load a scope has exactly one
|
|
18
|
+
* vars object — both resolvers read it from the same `composition.vars[scope]` — so a
|
|
19
|
+
* differing second write is a bug or a package reaching for a scope that is not its own,
|
|
20
|
+
* and neither should be applied quietly.
|
|
21
|
+
*/
|
|
22
|
+
export declare class VarsConflictError extends Error {
|
|
23
|
+
readonly scope: string;
|
|
24
|
+
constructor(scope: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The package was built without `AppshellPlugin`, so nothing substituted the scope the
|
|
28
|
+
* `@appshell/runtime/vars` accessor needs to know which vars are its own.
|
|
29
|
+
*/
|
|
30
|
+
export declare class MissingScopeError extends Error {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Vars } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Delivers a scope's vars. Called by `@appshell/loader` immediately before the remote
|
|
4
|
+
* is loaded, so they are in place before the package's modules evaluate.
|
|
5
|
+
*
|
|
6
|
+
* The first write for a scope wins and is frozen. Re-delivering the identical vars is a
|
|
7
|
+
* no-op — the same remote can be mounted more than once — but replacing them throws.
|
|
8
|
+
* That is what keeps one package from overwriting another's: by the time any package
|
|
9
|
+
* evaluates, the host has already written for it.
|
|
10
|
+
*
|
|
11
|
+
* It does not make a scope's vars *private*. Any code on the page can still read another
|
|
12
|
+
* scope by name, and nothing short of a separate realm would change that.
|
|
13
|
+
*/
|
|
14
|
+
export declare const setVars: (scope: string, vars: Vars) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Reads a scope's vars, throwing rather than handing back an empty object — a package
|
|
17
|
+
* that silently renders with no configuration is the failure this replaced.
|
|
18
|
+
*
|
|
19
|
+
* Prefer `getVars()` from `@appshell/runtime/vars`, which supplies the scope for you.
|
|
20
|
+
*/
|
|
21
|
+
export declare const readVars: <TVars extends Vars = Vars>(scope: string) => TVars;
|
|
22
|
+
/** Whether a scope has been delivered, for callers that want to branch instead of catch. */
|
|
23
|
+
export declare const hasVars: (scope: string) => boolean;
|
|
24
|
+
/** Test seam. Not part of the contract a package should build on. */
|
|
25
|
+
export declare const resetVars: () => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A package's runtime configuration, already merged by the registry — a package's
|
|
3
|
+
* declared vars, then the application's `overrides.vars`.
|
|
4
|
+
*
|
|
5
|
+
* Structurally identical to `AppshellComposition['vars'][scope]` in `@appshell/config`,
|
|
6
|
+
* but declared here rather than imported. This package is a shared singleton loaded
|
|
7
|
+
* into every micro-frontend on the page, so it carries no dependencies at all.
|
|
8
|
+
*/
|
|
9
|
+
export type Vars = Record<string, string | number | undefined>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the browser is told about a remote.
|
|
3
|
+
*
|
|
4
|
+
* These live here rather than in `@appshell/config` because config is build tooling — it
|
|
5
|
+
* carries yaml, lodash and axios — and a package that only wants to type a remote should
|
|
6
|
+
* not install a compiler to get it. This package is already the one every micro-frontend
|
|
7
|
+
* on the page shares, and it has no dependencies of its own to pass on.
|
|
8
|
+
*
|
|
9
|
+
* `AppshellManifest` deliberately stays in `@appshell/config`. It is a build artifact, and
|
|
10
|
+
* its `modules` field is Module Federation plugin options — build-time webpack
|
|
11
|
+
* configuration the browser never sees and this package should never drag in.
|
|
12
|
+
*/
|
|
13
|
+
/** Arbitrary, application-defined description of a remote. Appshell never reads it. */
|
|
14
|
+
export type Metadata = Record<string, unknown>;
|
|
15
|
+
/** A remote the registry has already resolved, so the browser needs no manifest fetch. */
|
|
16
|
+
export type AppshellRemote<TMetadata = Metadata> = {
|
|
17
|
+
id: string;
|
|
18
|
+
manifestUrl: string;
|
|
19
|
+
remoteEntryUrl: string;
|
|
20
|
+
scope: string;
|
|
21
|
+
module: string;
|
|
22
|
+
shareScope?: string;
|
|
23
|
+
metadata: TMetadata;
|
|
24
|
+
};
|
|
25
|
+
/** Remote key to manifest url. */
|
|
26
|
+
export type AppshellIndex = Record<string, string>;
|
|
@@ -5,3 +5,4 @@ export type { AppshellManifest } from '@appshell/config';
|
|
|
5
5
|
export { default as AppshellPlugin } from './AppshellPlugin';
|
|
6
6
|
export { DEV_HINT_FILE, DEV_HINT_VERSION, devServerOrigin, writeDevHint } from './devHint';
|
|
7
7
|
export type { DevHint } from './devHint';
|
|
8
|
+
export { appshellShared, type AppshellSharedOptions } from './shared';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SharedObject } from '@appshell/config';
|
|
2
|
+
export type AppshellSharedOptions = {
|
|
3
|
+
/** Include the React bindings and React itself. */
|
|
4
|
+
react?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Usually your package.json `dependencies`. Anything named here is pinned to the range
|
|
7
|
+
* you depend on; anything absent is left for module federation to infer, which it does
|
|
8
|
+
* from the installed package.
|
|
9
|
+
*/
|
|
10
|
+
dependencies?: Record<string, string>;
|
|
11
|
+
/** Merged last, so a package can still say something the preset does not. */
|
|
12
|
+
extra?: SharedObject;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The `shared` block an Appshell package needs, so it is not written out by hand in every
|
|
16
|
+
* webpack config and wrong in one of them.
|
|
17
|
+
*
|
|
18
|
+
* It exists because the alternative failed in practice: the examples in this repo declared
|
|
19
|
+
* `@appshell/react` as a singleton in three configs and omitted it in a fourth, which is
|
|
20
|
+
* silent until a root package calls `useRemote()` and gets `undefined`.
|
|
21
|
+
*
|
|
22
|
+
* `AppshellPlugin` cannot inject this itself — `ModuleFederationPlugin` reads its own
|
|
23
|
+
* options during its `apply`, which webpack has already run by the time it reaches ours.
|
|
24
|
+
* Spread into your own config, it sidesteps plugin ordering entirely:
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* const { appshellShared } = require('@appshell/webpack-plugin');
|
|
28
|
+
* const { dependencies } = require('./package.json');
|
|
29
|
+
*
|
|
30
|
+
* new ModuleFederationPlugin({
|
|
31
|
+
* shared: appshellShared({ react: true, dependencies }),
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const appshellShared: ({ react, dependencies, extra, }?: AppshellSharedOptions) => SharedObject;
|
|
36
|
+
export default appshellShared;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appshell/webpack-plugin",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.25",
|
|
4
4
|
"description": "Webpack plugin used to generate a global Appshell configuration for micro-frontends built with Module Federation",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/types/webpack-plugin/src/index.d.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"plugin"
|
|
33
33
|
],
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "7d90eb91be3cb50aae5aaa680063878dfcaafea2",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@appshell/tokens": "^1.0.0-alpha.
|
|
37
|
+
"@appshell/tokens": "^1.0.0-alpha.25"
|
|
38
38
|
}
|
|
39
39
|
}
|