@appshell/runtime 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 +25 -2
- package/dist/main.js +1 -1
- package/dist/types/errors.d.ts +7 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/store.d.ts +1 -1
- package/dist/types/vars.d.ts +31 -0
- package/dist/types/wire.d.ts +26 -0
- package/dist/vars.js +1 -0
- package/package.json +20 -2
package/README.md
CHANGED
|
@@ -6,8 +6,31 @@ This is a **shared singleton**. There is exactly one instance per page, held in
|
|
|
6
6
|
module federation share scope, and both the host and every package must declare it as
|
|
7
7
|
such. It replaced `window.__appshell_vars__<scope>`.
|
|
8
8
|
|
|
9
|
-
Most packages should not import this directly — use
|
|
10
|
-
|
|
9
|
+
Most packages should not import this directly — use `@appshell/runtime/vars` below,
|
|
10
|
+
which supplies the scope for you.
|
|
11
|
+
|
|
12
|
+
## `@appshell/runtime/vars`
|
|
13
|
+
|
|
14
|
+
The accessor most packages actually want. It reads *this* package's vars, with no scope
|
|
15
|
+
to pass and no way to name someone else's:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { getVars } from '@appshell/runtime/vars';
|
|
19
|
+
|
|
20
|
+
const { BACKGROUND_COLOR } = getVars<{ BACKGROUND_COLOR: string }>();
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
It is a subpath rather than a main-entry export for a reason. `AppshellPlugin` compiles
|
|
24
|
+
the package's own scope into whatever imports it, and the main entry is the *shared*
|
|
25
|
+
module — one instance for the whole page — so a scope baked in there would be one
|
|
26
|
+
package's, and every other package would read the wrong vars.
|
|
27
|
+
|
|
28
|
+
The exact-match share key `'@appshell/runtime'` does not catch `'@appshell/runtime/vars'`,
|
|
29
|
+
so each package bundles its own copy of the accessor with its own scope, while the store
|
|
30
|
+
they all reach stays the single shared instance.
|
|
31
|
+
|
|
32
|
+
`getVars` throws `MissingScopeError` when the package was built without `AppshellPlugin`,
|
|
33
|
+
since nothing substituted the scope.
|
|
11
34
|
|
|
12
35
|
## Contract
|
|
13
36
|
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var s in t)("object"==typeof exports?exports:e)[s]=t[s]}}(
|
|
1
|
+
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var s in t)("object"==typeof exports?exports:e)[s]=t[s]}}(this,(()=>(()=>{"use strict";var e={d:(r,t)=>{for(var s in t)e.o(t,s)&&!e.o(r,s)&&Object.defineProperty(r,s,{enumerable:!0,get:t[s]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{MissingScopeError:()=>o,MissingVarsError:()=>t,VarsConflictError:()=>s,hasVars:()=>c,readVars:()=>i,resetVars:()=>p,setVars:()=>n});class t extends Error{constructor(e,r){super(`No vars were delivered for '${e}'. ${r.length?`Vars are present for ${r.map((e=>`'${e}'`)).join(", ")} — check that '${e}' matches the module federation name the registry knows this package by.`:"Nothing has delivered vars on this page — check that the host and this package both declare '@appshell/runtime' as a shared singleton."}`),this.name="MissingVarsError",this.scope=e}}class s extends Error{constructor(e){super(`Vars for '${e}' were already delivered and cannot be replaced. A scope receives its vars once per page load.`),this.name="VarsConflictError",this.scope=e}}class o extends Error{constructor(){super("Cannot tell which package this is. '@appshell/runtime/vars' needs the scope that AppshellPlugin injects at build time — add it to this package's webpack plugins, or read the store directly with readVars(scope) from '@appshell/runtime'."),this.name="MissingScopeError"}}const a=new Map,n=(e,r)=>{const t=a.get(e);var o,n;if(t){if(o=t,n=r,![...new Set([...Object.keys(o),...Object.keys(n)])].every((e=>o[e]===n[e])))throw new s(e)}else a.set(e,Object.freeze({...r}))},i=e=>{const r=a.get(e);if(!r)throw new t(e,[...a.keys()]);return r},c=e=>a.has(e),p=()=>{a.clear()};return r})()));
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -23,3 +23,10 @@ export declare class VarsConflictError extends Error {
|
|
|
23
23
|
readonly scope: string;
|
|
24
24
|
constructor(scope: string);
|
|
25
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
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { MissingVarsError, VarsConflictError } from './errors';
|
|
1
|
+
export { MissingScopeError, MissingVarsError, VarsConflictError } from './errors';
|
|
2
2
|
export { hasVars, readVars, resetVars, setVars } from './store';
|
|
3
3
|
export type { Vars } from './types';
|
|
4
|
+
export type { AppshellIndex, AppshellRemote, Metadata } from './wire';
|
package/dist/types/store.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare const setVars: (scope: string, vars: Vars) => void;
|
|
|
16
16
|
* Reads a scope's vars, throwing rather than handing back an empty object — a package
|
|
17
17
|
* that silently renders with no configuration is the failure this replaced.
|
|
18
18
|
*
|
|
19
|
-
* Prefer `getVars()` from `@appshell/vars`, which supplies the scope for you.
|
|
19
|
+
* Prefer `getVars()` from `@appshell/runtime/vars`, which supplies the scope for you.
|
|
20
20
|
*/
|
|
21
21
|
export declare const readVars: <TVars extends Vars = Vars>(scope: string) => TVars;
|
|
22
22
|
/** Whether a scope has been delivered, for callers that want to branch instead of catch. */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope-aware accessor, deliberately kept out of this package's main entry.
|
|
3
|
+
*
|
|
4
|
+
* `@appshell/runtime` is shared as a singleton, so exactly one copy of it exists on the
|
|
5
|
+
* page — whichever package wins the share negotiation. A `__APPSHELL_SCOPE__` compiled
|
|
6
|
+
* into that copy would be one package's scope, and every other package would silently
|
|
7
|
+
* read the wrong vars. So this module ships as the `@appshell/runtime/vars` subpath,
|
|
8
|
+
* which the exact-match share key does not catch: each package bundles its own copy and
|
|
9
|
+
* gets its own scope substituted, while the store they all reach through the bare
|
|
10
|
+
* `@appshell/runtime` import below stays the one shared instance.
|
|
11
|
+
*
|
|
12
|
+
* That bare specifier is load-bearing. A relative import of the store here would bind to
|
|
13
|
+
* a local copy and bypass the singleton entirely.
|
|
14
|
+
*/
|
|
15
|
+
import { type Vars } from '@appshell/runtime';
|
|
16
|
+
/**
|
|
17
|
+
* This package's runtime configuration, as the registry composed it — the vars the
|
|
18
|
+
* package declared in its `appshell.config.yaml`, with the application's
|
|
19
|
+
* `overrides.vars` layered over them.
|
|
20
|
+
*
|
|
21
|
+
* Throws rather than returning an empty object when nothing was delivered. A package
|
|
22
|
+
* that renders with no configuration at all is the failure this is here to prevent.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { getVars } from '@appshell/runtime/vars';
|
|
26
|
+
*
|
|
27
|
+
* const { BACKGROUND_COLOR } = getVars<{ BACKGROUND_COLOR: string }>();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const getVars: <TVars extends Vars = Vars>() => TVars;
|
|
31
|
+
export { MissingScopeError, MissingVarsError, type Vars } from '@appshell/runtime';
|
|
@@ -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>;
|
package/dist/vars.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("@appshell/runtime"));else if("function"==typeof define&&define.amd)define(["@appshell/runtime"],r);else{var o="object"==typeof exports?r(require("@appshell/runtime")):r(e["@appshell/runtime"]);for(var t in o)("object"==typeof exports?exports:e)[t]=o[t]}}(this,(e=>(()=>{"use strict";var r={164(r){r.exports=e}},o={};function t(e){var n=o[e];if(void 0!==n)return n.exports;var i=o[e]={exports:{}};return r[e](i,i.exports,t),i.exports}t.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};t.r(n),t.d(n,{MissingScopeError:()=>i.MissingScopeError,MissingVarsError:()=>i.MissingVarsError,getVars:()=>s});var i=t(164);const s=()=>(0,i.readVars)((()=>{if("undefined"==typeof __APPSHELL_SCOPE__)throw new i.MissingScopeError;return __APPSHELL_SCOPE__})());return n})()));
|
package/package.json
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appshell/runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.25",
|
|
4
4
|
"description": "The shared singleton that delivers a package's runtime configuration to it",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"default": "./dist/main.js"
|
|
11
|
+
},
|
|
12
|
+
"./vars": {
|
|
13
|
+
"types": "./dist/types/vars.d.ts",
|
|
14
|
+
"default": "./dist/vars.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"typesVersions": {
|
|
19
|
+
"*": {
|
|
20
|
+
"vars": [
|
|
21
|
+
"./dist/types/vars.d.ts"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
7
25
|
"repository": {
|
|
8
26
|
"type": "git",
|
|
9
27
|
"url": "git+https://github.com/appshellhq/appshell.git"
|
|
@@ -30,5 +48,5 @@
|
|
|
30
48
|
"appshell"
|
|
31
49
|
],
|
|
32
50
|
"license": "MIT",
|
|
33
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "7d90eb91be3cb50aae5aaa680063878dfcaafea2"
|
|
34
52
|
}
|