@rebasepro/app 0.19.2-canary.gef769df → 0.20.0
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/dist/vitePlugin.d.ts +17 -25
- package/dist/vitePlugin.js +29 -0
- package/package.json +7 -7
package/dist/vitePlugin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
|
+
import type { Plugin } from "vite";
|
|
2
3
|
export interface RebaseCollectionsPluginOptions {
|
|
3
4
|
/**
|
|
4
5
|
* The path to the collections directory containing the schema definitions.
|
|
@@ -33,31 +34,22 @@ export declare function transformCollectionSource(code: string, id: string): {
|
|
|
33
34
|
* (`{ __rebaseLazy: true, load: () => import(...) }`), enabling code-splitting
|
|
34
35
|
* and preventing the backend from loading React-dependent modules.
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* // Output
|
|
53
|
-
* Field: { __rebaseLazy: true, load: () => import("../../frontend/src/components/MyField") }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
transform(code: string, id: string): {
|
|
57
|
-
code: string;
|
|
58
|
-
map: ReturnType<MagicString["generateMap"]>;
|
|
59
|
-
} | null;
|
|
60
|
-
};
|
|
37
|
+
/**
|
|
38
|
+
* Annotated `Plugin` rather than inferred.
|
|
39
|
+
*
|
|
40
|
+
* The return used to be a bare object literal, and TypeScript 6 stopped
|
|
41
|
+
* accepting it where vite wants a `PluginOption`: `configureServer` is an
|
|
42
|
+
* `ObjectHook`, so a plain method's inferred signature is not assignable, and
|
|
43
|
+
* the whole config object then failed with "Excessive stack depth comparing
|
|
44
|
+
* types" — an error naming the caller's `defineConfig` rather than the plugin
|
|
45
|
+
* that caused it. A scaffolded frontend runs `vite build && tsc` with
|
|
46
|
+
* `vite.config.ts` in its `include`, so that was a broken `pnpm build` for
|
|
47
|
+
* every new project on TS 6, reported against a file the user did not write.
|
|
48
|
+
*
|
|
49
|
+
* Declaring the type puts the check here, where the hooks are, instead of at
|
|
50
|
+
* every call site.
|
|
51
|
+
*/
|
|
52
|
+
export declare function rebaseCollectionsPlugin(options: RebaseCollectionsPluginOptions): Plugin;
|
|
61
53
|
/**
|
|
62
54
|
* How the admin's dependencies are split into cached chunks.
|
|
63
55
|
*
|
package/dist/vitePlugin.js
CHANGED
|
@@ -66,6 +66,35 @@ function rebaseCollectionsPlugin(options) {
|
|
|
66
66
|
configResolved(config) {
|
|
67
67
|
resolvedCollectionsDir = path.isAbsolute(options.collectionsDir) ? options.collectionsDir : path.resolve(config.root, options.collectionsDir);
|
|
68
68
|
},
|
|
69
|
+
/**
|
|
70
|
+
* Watch the collections directory itself, not just the files in it.
|
|
71
|
+
*
|
|
72
|
+
* The virtual module below is an `import.meta.glob`, and Vite already
|
|
73
|
+
* invalidates a glob's importer when a matching file appears — but only
|
|
74
|
+
* for files its watcher sees. The watcher watches the Vite root, plus
|
|
75
|
+
* whatever individual files the module graph reached; a collections
|
|
76
|
+
* directory outside the root (`collectionsDir: "../config/collections"`
|
|
77
|
+
* is the shape every scaffold ships) is therefore watched one existing
|
|
78
|
+
* file at a time, and a *new* file in it raises no event at all.
|
|
79
|
+
*
|
|
80
|
+
* That is the whole of the "created a collection, it is in the source,
|
|
81
|
+
* it is not in the admin" bug: the editor wrote the file, nothing
|
|
82
|
+
* invalidated the virtual module, and the collection list stayed
|
|
83
|
+
* whatever it was when the dev server booted — a reload did not fix it,
|
|
84
|
+
* because the stale glob was already transformed and cached. Only a
|
|
85
|
+
* restart did.
|
|
86
|
+
*
|
|
87
|
+
* Editing an existing collection was always fine, which is why this hid
|
|
88
|
+
* for so long: that file IS in the module graph, so it IS watched.
|
|
89
|
+
*
|
|
90
|
+
* Watching the directory is the whole fix. Vite's own glob invalidation
|
|
91
|
+
* does the rest — it is listening on this same watcher, and once the
|
|
92
|
+
* event reaches it, it invalidates the virtual module and reloads the
|
|
93
|
+
* page exactly as it does for a collections directory inside the root.
|
|
94
|
+
*/
|
|
95
|
+
configureServer(server) {
|
|
96
|
+
server.watcher.add(resolvedCollectionsDir);
|
|
97
|
+
},
|
|
69
98
|
resolveId(id) {
|
|
70
99
|
if (id === virtualModuleId) {
|
|
71
100
|
return resolvedVirtualModuleId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Rebase core — framework-agnostic runtime for data-driven admin panels",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rebase",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"magic-string": "^0.30.0",
|
|
64
64
|
"notistack": "^3.0.2",
|
|
65
65
|
"react-i18next": "^17.0.11",
|
|
66
|
-
"@rebasepro/cms-types": "0.
|
|
67
|
-
"@rebasepro/common": "0.
|
|
68
|
-
"@rebasepro/forms": "0.
|
|
69
|
-
"@rebasepro/ui": "0.
|
|
70
|
-
"@rebasepro/types": "0.
|
|
71
|
-
"@rebasepro/utils": "0.
|
|
66
|
+
"@rebasepro/cms-types": "0.20.0",
|
|
67
|
+
"@rebasepro/common": "0.20.0",
|
|
68
|
+
"@rebasepro/forms": "0.20.0",
|
|
69
|
+
"@rebasepro/ui": "0.20.0",
|
|
70
|
+
"@rebasepro/types": "0.20.0",
|
|
71
|
+
"@rebasepro/utils": "0.20.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"react": "^19.2.7",
|