@matthesketh/utopia-vite-plugin 0.5.0 → 0.7.1
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/index.cjs +25 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +25 -1
- package/package.json +7 -7
- package/LICENSE +0 -21
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,9 @@ var import_node_path = __toESM(require("path"), 1);
|
|
|
40
40
|
var UTOPIA_EXT = ".utopia";
|
|
41
41
|
var CSS_SUFFIX = ".css";
|
|
42
42
|
var VIRTUAL_PREFIX = "\0";
|
|
43
|
+
var VIRTUAL_ROUTES_ID = "virtual:utopia-routes";
|
|
44
|
+
var RESOLVED_VIRTUAL_ROUTES_ID = VIRTUAL_PREFIX + VIRTUAL_ROUTES_ID;
|
|
45
|
+
var ROUTE_FILE_RE = /\+(?:page|layout|error|server)\.\w+$/;
|
|
43
46
|
var cssCache = /* @__PURE__ */ new Map();
|
|
44
47
|
function toCssId(utopiaId) {
|
|
45
48
|
return utopiaId + CSS_SUFFIX;
|
|
@@ -55,7 +58,7 @@ function cssIdToUtopiaId(cssId) {
|
|
|
55
58
|
return raw.slice(0, -CSS_SUFFIX.length);
|
|
56
59
|
}
|
|
57
60
|
function utopiaPlugin(options = {}) {
|
|
58
|
-
const { include = `**/*${UTOPIA_EXT}`, exclude } = options;
|
|
61
|
+
const { include = `**/*${UTOPIA_EXT}`, exclude, routesDir = "src/routes" } = options;
|
|
59
62
|
let filter;
|
|
60
63
|
let server;
|
|
61
64
|
const prevDescriptors = /* @__PURE__ */ new Map();
|
|
@@ -93,6 +96,9 @@ function utopiaPlugin(options = {}) {
|
|
|
93
96
|
// Resolve virtual CSS modules + SSR runtime alias
|
|
94
97
|
// -------------------------------------------------------------------
|
|
95
98
|
resolveId(id, importer, options2) {
|
|
99
|
+
if (id === VIRTUAL_ROUTES_ID) {
|
|
100
|
+
return RESOLVED_VIRTUAL_ROUTES_ID;
|
|
101
|
+
}
|
|
96
102
|
if (options2?.ssr && id === "@matthesketh/utopia-runtime") {
|
|
97
103
|
return this.resolve("@matthesketh/utopia-server/ssr-runtime", importer, {
|
|
98
104
|
skipSelf: true,
|
|
@@ -116,6 +122,17 @@ function utopiaPlugin(options = {}) {
|
|
|
116
122
|
// -------------------------------------------------------------------
|
|
117
123
|
load(id) {
|
|
118
124
|
if (!id.startsWith(VIRTUAL_PREFIX)) return void 0;
|
|
125
|
+
if (id === RESOLVED_VIRTUAL_ROUTES_ID) {
|
|
126
|
+
const globPattern = `/${routesDir}/**/+{page,layout,error,server}.{utopia,ts,js}`;
|
|
127
|
+
return [
|
|
128
|
+
`import { buildRouteTable } from '@matthesketh/utopia-router';`,
|
|
129
|
+
`const manifest = import.meta.glob(${JSON.stringify(globPattern)});`,
|
|
130
|
+
`const apiManifest = import.meta.glob('/${routesDir}/**/+server.{ts,js}');`,
|
|
131
|
+
`const routes = buildRouteTable(manifest);`,
|
|
132
|
+
`export default routes;`,
|
|
133
|
+
`export { routes, apiManifest };`
|
|
134
|
+
].join("\n");
|
|
135
|
+
}
|
|
119
136
|
const raw = stripVirtualPrefix(id);
|
|
120
137
|
if (isVirtualCssId(raw)) {
|
|
121
138
|
const utopiaId = cssIdToUtopiaId(raw);
|
|
@@ -160,6 +177,13 @@ import ${JSON.stringify(cssImportId)};
|
|
|
160
177
|
// -------------------------------------------------------------------
|
|
161
178
|
handleHotUpdate(ctx) {
|
|
162
179
|
const { file, read, server: hmrServer, modules } = ctx;
|
|
180
|
+
if (ROUTE_FILE_RE.test(file)) {
|
|
181
|
+
const routesMod = hmrServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ROUTES_ID);
|
|
182
|
+
if (routesMod) {
|
|
183
|
+
hmrServer.moduleGraph.invalidateModule(routesMod);
|
|
184
|
+
hmrServer.ws.send({ type: "full-reload" });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
163
187
|
if (!file.endsWith(UTOPIA_EXT)) return void 0;
|
|
164
188
|
return (async () => {
|
|
165
189
|
const source = await read();
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,11 @@ interface UtopiaPluginOptions {
|
|
|
14
14
|
* @default undefined
|
|
15
15
|
*/
|
|
16
16
|
exclude?: FilterPattern;
|
|
17
|
+
/**
|
|
18
|
+
* Directory containing route files, relative to the project root.
|
|
19
|
+
* @default 'src/routes'
|
|
20
|
+
*/
|
|
21
|
+
routesDir?: string;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* Vite plugin for UtopiaJS.
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ interface UtopiaPluginOptions {
|
|
|
14
14
|
* @default undefined
|
|
15
15
|
*/
|
|
16
16
|
exclude?: FilterPattern;
|
|
17
|
+
/**
|
|
18
|
+
* Directory containing route files, relative to the project root.
|
|
19
|
+
* @default 'src/routes'
|
|
20
|
+
*/
|
|
21
|
+
routesDir?: string;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* Vite plugin for UtopiaJS.
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ import path from "path";
|
|
|
5
5
|
var UTOPIA_EXT = ".utopia";
|
|
6
6
|
var CSS_SUFFIX = ".css";
|
|
7
7
|
var VIRTUAL_PREFIX = "\0";
|
|
8
|
+
var VIRTUAL_ROUTES_ID = "virtual:utopia-routes";
|
|
9
|
+
var RESOLVED_VIRTUAL_ROUTES_ID = VIRTUAL_PREFIX + VIRTUAL_ROUTES_ID;
|
|
10
|
+
var ROUTE_FILE_RE = /\+(?:page|layout|error|server)\.\w+$/;
|
|
8
11
|
var cssCache = /* @__PURE__ */ new Map();
|
|
9
12
|
function toCssId(utopiaId) {
|
|
10
13
|
return utopiaId + CSS_SUFFIX;
|
|
@@ -20,7 +23,7 @@ function cssIdToUtopiaId(cssId) {
|
|
|
20
23
|
return raw.slice(0, -CSS_SUFFIX.length);
|
|
21
24
|
}
|
|
22
25
|
function utopiaPlugin(options = {}) {
|
|
23
|
-
const { include = `**/*${UTOPIA_EXT}`, exclude } = options;
|
|
26
|
+
const { include = `**/*${UTOPIA_EXT}`, exclude, routesDir = "src/routes" } = options;
|
|
24
27
|
let filter;
|
|
25
28
|
let server;
|
|
26
29
|
const prevDescriptors = /* @__PURE__ */ new Map();
|
|
@@ -58,6 +61,9 @@ function utopiaPlugin(options = {}) {
|
|
|
58
61
|
// Resolve virtual CSS modules + SSR runtime alias
|
|
59
62
|
// -------------------------------------------------------------------
|
|
60
63
|
resolveId(id, importer, options2) {
|
|
64
|
+
if (id === VIRTUAL_ROUTES_ID) {
|
|
65
|
+
return RESOLVED_VIRTUAL_ROUTES_ID;
|
|
66
|
+
}
|
|
61
67
|
if (options2?.ssr && id === "@matthesketh/utopia-runtime") {
|
|
62
68
|
return this.resolve("@matthesketh/utopia-server/ssr-runtime", importer, {
|
|
63
69
|
skipSelf: true,
|
|
@@ -81,6 +87,17 @@ function utopiaPlugin(options = {}) {
|
|
|
81
87
|
// -------------------------------------------------------------------
|
|
82
88
|
load(id) {
|
|
83
89
|
if (!id.startsWith(VIRTUAL_PREFIX)) return void 0;
|
|
90
|
+
if (id === RESOLVED_VIRTUAL_ROUTES_ID) {
|
|
91
|
+
const globPattern = `/${routesDir}/**/+{page,layout,error,server}.{utopia,ts,js}`;
|
|
92
|
+
return [
|
|
93
|
+
`import { buildRouteTable } from '@matthesketh/utopia-router';`,
|
|
94
|
+
`const manifest = import.meta.glob(${JSON.stringify(globPattern)});`,
|
|
95
|
+
`const apiManifest = import.meta.glob('/${routesDir}/**/+server.{ts,js}');`,
|
|
96
|
+
`const routes = buildRouteTable(manifest);`,
|
|
97
|
+
`export default routes;`,
|
|
98
|
+
`export { routes, apiManifest };`
|
|
99
|
+
].join("\n");
|
|
100
|
+
}
|
|
84
101
|
const raw = stripVirtualPrefix(id);
|
|
85
102
|
if (isVirtualCssId(raw)) {
|
|
86
103
|
const utopiaId = cssIdToUtopiaId(raw);
|
|
@@ -125,6 +142,13 @@ import ${JSON.stringify(cssImportId)};
|
|
|
125
142
|
// -------------------------------------------------------------------
|
|
126
143
|
handleHotUpdate(ctx) {
|
|
127
144
|
const { file, read, server: hmrServer, modules } = ctx;
|
|
145
|
+
if (ROUTE_FILE_RE.test(file)) {
|
|
146
|
+
const routesMod = hmrServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ROUTES_ID);
|
|
147
|
+
if (routesMod) {
|
|
148
|
+
hmrServer.moduleGraph.invalidateModule(routesMod);
|
|
149
|
+
hmrServer.ws.send({ type: "full-reload" });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
128
152
|
if (!file.endsWith(UTOPIA_EXT)) return void 0;
|
|
129
153
|
return (async () => {
|
|
130
154
|
const source = await read();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matthesketh/utopia-vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Vite plugin for UtopiaJS .utopia files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
43
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch"
|
|
44
|
+
},
|
|
41
45
|
"dependencies": {
|
|
42
|
-
"@matthesketh/utopia-compiler": "0.
|
|
46
|
+
"@matthesketh/utopia-compiler": "^0.7.1"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
49
|
"vite": "^6.0.0 || ^7.0.0"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"vite": "^7.3.1"
|
|
49
|
-
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
52
|
-
"dev": "tsup src/index.ts --format esm,cjs --dts --watch"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Matt Hesketh
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|