@livestore/devtools-vite 0.3.0-dev.15 → 0.3.0-dev.17

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/plugin.js CHANGED
@@ -1,23 +1,46 @@
1
1
  import path from 'node:path';
2
+ import { Devtools } from '@livestore/common';
3
+ import { Schema } from '@livestore/utils/effect';
4
+ export const PluginOptions = Schema.Struct({
5
+ schemaPath: Schema.String,
6
+ license: Schema.optional(Schema.String),
7
+ mode: Schema.optional(Devtools.DevtoolsMode),
8
+ path: Schema.optional(Schema.String),
9
+ });
2
10
  export const livestoreDevtoolsPlugin = (options) => {
11
+ Schema.validateSync(PluginOptions)(options);
12
+ const mountPath = options.path ?? '/_livestore';
3
13
  return {
4
14
  name: '@livestore/devtools-vite',
5
15
  // `vite dev` support
6
16
  configureServer: (server) => {
7
- server.middlewares.use('/_livestore', async (_, res) => {
8
- res.setHeader('Content-Type', 'text/html');
9
- const schemaPath = path.resolve(options.schemaPath);
10
- const bundleDir = path.join(import.meta.dirname, '..', 'dist', 'devtools-bundle');
11
- const bundlePath = path.resolve(bundleDir, 'index.js');
12
- const cssPath = path.resolve(bundleDir, 'devtools-vite.css');
13
- const template = makeIndexHtml({ schemaPath, bundlePath, cssPath });
14
- const html = await server.transformIndexHtml('/_livestore', template);
15
- // Remove line that contains `vinxi/runtime`
16
- const trimmedHtml = html
17
- .split('\n')
18
- .filter((line) => !line.includes('vinxi/runtime'))
19
- .join('\n');
20
- res.end(trimmedHtml);
17
+ const basedMountPath = path.join(server.config.base, mountPath);
18
+ // console.log('basedMountPath', basedMountPath)
19
+ server.middlewares.use(basedMountPath, async (req, res, next) => {
20
+ if (req.url === undefined) {
21
+ next();
22
+ return;
23
+ }
24
+ const url = new URL(req.url, typeof server.config.server.host === 'string' ? server.config.server.host : 'http://localhost');
25
+ // console.log('livestore-devtools-vite:req', url)
26
+ if (url.pathname === '/') {
27
+ res.setHeader('Content-Type', 'text/html');
28
+ const schemaPath = path.resolve(options.schemaPath);
29
+ const bundleDir = path.join(import.meta.dirname, '..', 'dist', 'devtools-bundle');
30
+ const bundlePath = path.resolve(bundleDir, 'index.js');
31
+ const cssPath = path.resolve(bundleDir, 'devtools-vite.css');
32
+ const template = makeIndexHtml({ schemaPath, bundlePath, cssPath, mode: options.mode });
33
+ const html = await server.transformIndexHtml(mountPath, template);
34
+ // Remove line that contains `vinxi/runtime`
35
+ const trimmedHtml = html
36
+ .split('\n')
37
+ .filter((line) => !line.includes('vinxi/runtime'))
38
+ .join('\n');
39
+ res.end(trimmedHtml);
40
+ }
41
+ else {
42
+ next();
43
+ }
21
44
  });
22
45
  },
23
46
  config: (config) => {
@@ -70,7 +93,7 @@ export const livestoreDevtoolsPlugin = (options) => {
70
93
  // },
71
94
  };
72
95
  };
73
- const makeIndexHtml = ({ schemaPath, bundlePath, cssPath, }) => {
96
+ const makeIndexHtml = ({ schemaPath, bundlePath, cssPath, mode, }) => {
74
97
  return /*html*/ `
75
98
  <!doctype html>
76
99
  <html lang="en">
@@ -94,7 +117,7 @@ const makeIndexHtml = ({ schemaPath, bundlePath, cssPath, }) => {
94
117
  schema,
95
118
  license: ${process.env.LSD_LICENSE} ? '${process.env.LSD_LICENSE}' : undefined,
96
119
  // Mode will be provided via URL search params
97
- mode: undefined,
120
+ mode: ${mode ? Schema.encodeSync(Schema.parseJson(Devtools.DevtoolsMode))(mode) : undefined},
98
121
  sharedWorker,
99
122
  })
100
123
  </script>
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AA4BhD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC,M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C,CAAA;AAED,qHAAqH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/devtools-vite",
3
- "version": "0.3.0-dev.15",
3
+ "version": "0.3.0-dev.17",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/dist/devtools.js DELETED
@@ -1,2 +0,0 @@
1
- export * from '@livestore/devtools-react';
2
- //# sourceMappingURL=devtools.js.map