@rmc-toolkit/core 0.2.0 → 0.2.4
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 +64 -0
- package/dist/externals.d.ts.map +1 -1
- package/dist/externals.js +3 -2
- package/package.json +6 -1
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @rmc-toolkit/core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic core of [Runtime Module Composition](https://runtime-module-composition.dev): manifest-driven import map generation, route resolution, dynamic module loading, and a runtime host lifecycle that the Vite/React/Vue adapters build on. Has no dependency on any bundler or UI framework.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rmc-toolkit/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick example
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// runtime-composition.manifest.ts
|
|
15
|
+
import { defineManifest } from "@rmc-toolkit/core";
|
|
16
|
+
|
|
17
|
+
export const manifest = defineManifest({
|
|
18
|
+
namespace: "@acme",
|
|
19
|
+
assetsOrigin: "https://assets.example.com",
|
|
20
|
+
externalDepsOrigin: "https://esm.sh",
|
|
21
|
+
externalDeps: [
|
|
22
|
+
// The shared React singleton every other entry's peerDeps pins to by
|
|
23
|
+
// name. Has no peer deps of its own, so it opts out of defaultPeerDeps
|
|
24
|
+
// rather than self-referencing itself.
|
|
25
|
+
{ name: "react", version: "19.2.7", peerDeps: false },
|
|
26
|
+
// Needs the same React instance — matches defaultPeerDeps below, so no
|
|
27
|
+
// peerDeps field needed here.
|
|
28
|
+
{ name: "react-dom/client", version: "19.2.7" },
|
|
29
|
+
{
|
|
30
|
+
name: "@radix-ui/themes",
|
|
31
|
+
version: "3.3.0",
|
|
32
|
+
// Needs both react and react-dom, which differs from defaultPeerDeps
|
|
33
|
+
// — their versions are looked up from the entries above at
|
|
34
|
+
// generation time, never hand-typed here.
|
|
35
|
+
peerDeps: ["react", "react-dom"],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
// Applied automatically to every externalDeps entry that doesn't set its
|
|
39
|
+
// own peerDeps (react-dom/client, above).
|
|
40
|
+
defaultPeerDeps: ["react"],
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`createRuntimeHost` resolves a path to a slice's module specifier via the manifest, imports it, and mounts/unmounts it — with built-in error recovery and protection against rapid-navigation races. It only reacts to a path string; wire it to whatever produces navigation events (a `popstate` listener, as above, or a router's own navigation callback).
|
|
45
|
+
|
|
46
|
+
If you're building a React or Vue host, use [`@rmc-toolkit/react`](https://www.npmjs.com/package/@rmc-toolkit/react) or [`@rmc-toolkit/vue`](https://www.npmjs.com/package/@rmc-toolkit/vue) instead — both wrap this same lifecycle in a framework-idiomatic hook/composable. Use this package directly for a host with no framework, or one without a dedicated adapter yet.
|
|
47
|
+
|
|
48
|
+
## What's in here
|
|
49
|
+
|
|
50
|
+
- `defineManifest`, `validateManifest` — declare and lint the manifest that drives everything else.
|
|
51
|
+
- `createImportMap`, `createImportMapBootstrapScript`, `resolveImportMapSpecifier` — generate the browser import map from a manifest.
|
|
52
|
+
- `resolveRoute` — resolve a URL path to a slice's module specifier.
|
|
53
|
+
- `createExternalMatcher`, `listExternalSpecifiers` — determine which specifiers a bundler should leave external (used by `@rmc-toolkit/vite`).
|
|
54
|
+
- `importModule`, `unwrapDefault` — the dynamic-import primitive slices/hosts load through.
|
|
55
|
+
- `createRuntimeHost`, `createRuntimeHostObservable`, `notifyInternalNavigation` — the resolve/import/mount/unmount lifecycle, plain and as a subscribable observable.
|
|
56
|
+
|
|
57
|
+
Full signatures and behavior for every export: [API Reference](https://runtime-module-composition.dev/api-reference/#core-rmc-toolkitcore).
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
- [Getting Started](https://runtime-module-composition.dev/getting-started/) — install and wire up a host + slice end to end
|
|
62
|
+
- [API Reference](https://runtime-module-composition.dev/api-reference/#core-rmc-toolkitcore)
|
|
63
|
+
- [Technical Implementation](https://runtime-module-composition.dev/technical-implementation/) — the architecture and failure modes behind the pattern
|
|
64
|
+
- [Multi-Framework Demo](https://runtime-module-composition.dev/demo/) — a full, runnable reference implementation
|
package/dist/externals.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"externals.d.ts","sourceRoot":"","sources":["../src/externals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"externals.d.ts","sourceRoot":"","sources":["../src/externals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,YAAY,CAAC;AAMpB,eAAO,MAAM,sBAAsB,GACjC,UAAU,0BAA0B,KACnC,MAAM,EAiBR,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,UAAU,0BAA0B,KACnC,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAW9B,CAAC"}
|
package/dist/externals.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { trimTrailingSlash } from "./manifest.js";
|
|
1
2
|
const isSharedExternal = (config) => typeof config === "string" ? true : config.external !== false;
|
|
2
3
|
export const listExternalSpecifiers = (manifest) => {
|
|
3
4
|
const prefixes = [
|
|
4
|
-
`${manifest.namespace}/`,
|
|
5
|
+
`${trimTrailingSlash(manifest.namespace)}/`,
|
|
5
6
|
manifest.externalDepsOrigin
|
|
6
7
|
? (manifest.externalDepsPrefix ?? "@esm.sh/")
|
|
7
8
|
: null,
|
|
@@ -16,7 +17,7 @@ export const listExternalSpecifiers = (manifest) => {
|
|
|
16
17
|
};
|
|
17
18
|
export const createExternalMatcher = (manifest) => {
|
|
18
19
|
const exactSpecifiers = new Set(listExternalSpecifiers(manifest));
|
|
19
|
-
const namespacePrefix = `${manifest.namespace}/`;
|
|
20
|
+
const namespacePrefix = `${trimTrailingSlash(manifest.namespace)}/`;
|
|
20
21
|
const externalDepsPrefix = manifest.externalDepsOrigin
|
|
21
22
|
? (manifest.externalDepsPrefix ?? "@esm.sh/")
|
|
22
23
|
: null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmc-toolkit/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/runtime-module-composition/rmc-toolkit",
|
|
8
|
+
"directory": "packages/core"
|
|
9
|
+
},
|
|
5
10
|
"main": "./dist/index.js",
|
|
6
11
|
"types": "./dist/index.d.ts",
|
|
7
12
|
"exports": {
|