@matthesketh/utopia-vite-plugin 0.5.0 → 0.7.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/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.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Vite plugin for UtopiaJS .utopia files",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@matthesketh/utopia-compiler": "0.5.0"
42
+ "@matthesketh/utopia-compiler": "0.7.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vite": "^6.0.0 || ^7.0.0"