@livestore/devtools-vite 0.3.0-dev.12 → 0.3.0-dev.14

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,52 +1,76 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
3
2
  export const livestoreDevtoolsPlugin = (options) => {
4
3
  return {
5
- name: 'devtools-vite',
4
+ name: '@livestore/devtools-vite',
6
5
  // `vite dev` support
7
6
  configureServer: (server) => {
8
- server.middlewares.use('/_devtools.html', async (_, res) => {
7
+ server.middlewares.use('/_livestore', async (_, res) => {
9
8
  res.setHeader('Content-Type', 'text/html');
10
- const template = makeIndexHtml({ schemaPath: options.schemaPath });
11
- const html = await server.transformIndexHtml('/_devtools.html', template);
12
- res.end(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);
13
21
  });
14
22
  },
15
- // `vite build` support below
16
23
  config: (config) => {
17
- if (config.build === undefined) {
18
- config.build = {};
19
- }
20
- if (config.build.rollupOptions === undefined) {
21
- config.build.rollupOptions = {};
24
+ if (config.optimizeDeps === undefined) {
25
+ config.optimizeDeps = {};
22
26
  }
23
- if (config.build.rollupOptions.input === undefined) {
24
- config.build.rollupOptions.input = {
25
- main: path.resolve('./index.html'),
26
- };
27
+ if (config.optimizeDeps.exclude === undefined) {
28
+ config.optimizeDeps.exclude = [];
27
29
  }
28
- if (isRecord(config.build.rollupOptions.input)) {
29
- config.build.rollupOptions.input.devtools = 'virtual:_devtools.html';
30
- // config.build.rollupOptions.input.devtools = '_devtools.html'
30
+ const toAdd = ['@livestore/devtools-vite', '@livestore/wa-sqlite'];
31
+ for (const dep of toAdd) {
32
+ if (!config.optimizeDeps.exclude.includes(dep)) {
33
+ config.optimizeDeps.exclude.push(dep);
34
+ }
31
35
  }
32
36
  return config;
33
37
  },
34
- writeBundle: (_) => {
35
- fs.renameSync(path.join(_.dir, 'virtual:_devtools.html'), path.join(_.dir, '_devtools.html'));
36
- },
37
- resolveId: (id) => {
38
- if (id === 'virtual:_devtools.html') {
39
- return id;
40
- }
41
- },
42
- load: (id) => {
43
- if (id === 'virtual:_devtools.html') {
44
- return makeIndexHtml({ schemaPath: options.schemaPath });
45
- }
46
- },
38
+ // `vite build` support below
39
+ // TODO maybe bring back at some point
40
+ // config: (config) => {
41
+ // if (config.build === undefined) {
42
+ // config.build = {}
43
+ // }
44
+ // if (config.build.rollupOptions === undefined) {
45
+ // config.build.rollupOptions = {}
46
+ // }
47
+ // if (config.build.rollupOptions.input === undefined) {
48
+ // config.build.rollupOptions.input = {
49
+ // main: path.resolve('./index.html'),
50
+ // }
51
+ // }
52
+ // if (isRecord(config.build.rollupOptions.input)) {
53
+ // config.build.rollupOptions.input.devtools = 'virtual:_devtools.html'
54
+ // // config.build.rollupOptions.input.devtools = '_devtools.html'
55
+ // }
56
+ // return config
57
+ // },
58
+ // writeBundle: (_) => {
59
+ // fs.renameSync(path.join(_.dir!, 'virtual:_devtools.html'), path.join(_.dir!, '_devtools.html'))
60
+ // },
61
+ // resolveId: (id) => {
62
+ // if (id === 'virtual:_devtools.html') {
63
+ // return id
64
+ // }
65
+ // },
66
+ // load: (id) => {
67
+ // if (id === 'virtual:_devtools.html') {
68
+ // return makeIndexHtml({ schemaPath: options.schemaPath })
69
+ // }
70
+ // },
47
71
  };
48
72
  };
49
- const makeIndexHtml = ({ schemaPath }) => {
73
+ const makeIndexHtml = ({ schemaPath, bundlePath, cssPath, }) => {
50
74
  return /*html*/ `
51
75
  <!doctype html>
52
76
  <html lang="en">
@@ -59,25 +83,24 @@ const makeIndexHtml = ({ schemaPath }) => {
59
83
  <body>
60
84
  <div id="root"></div>
61
85
  <script type="module">
86
+ import '${cssPath}'
62
87
  // NOTE we need to re-export dependencies from "@livestore/devtools-react"
63
88
  // as it's not a direct dependency of the Vite setup of a plugin user
64
- import '@livestore/devtools-vite/index.css'
65
- import { mountDevtools } from '@livestore/devtools-vite/devtools'
66
- import sharedWorker from '@livestore/web/shared-worker?sharedworker'
67
- import { schema } from '${path.resolve(schemaPath)}'
89
+ import { run } from '${bundlePath}'
90
+ import { schema } from '${schemaPath}'
91
+ import sharedWorker from '@livestore/adapter-web/shared-worker?sharedworker'
68
92
 
69
- mountDevtools({
93
+ run({
70
94
  schema,
71
- rootEl: document.getElementById('root'),
72
- sharedWorker,
73
95
  license: ${process.env.LSD_LICENSE} ? '${process.env.LSD_LICENSE}' : undefined,
74
96
  // Mode will be provided via URL search params
75
97
  mode: undefined,
98
+ sharedWorker,
76
99
  })
77
100
  </script>
78
101
  </body>
79
102
  </html>
80
103
  `;
81
104
  };
82
- const isRecord = (value) => typeof value === 'object' && value !== null;
105
+ // const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null
83
106
  //# sourceMappingURL=plugin.js.map
package/package.json CHANGED
@@ -1,32 +1,12 @@
1
1
  {
2
2
  "name": "@livestore/devtools-vite",
3
- "version": "0.3.0-dev.12",
3
+ "version": "0.3.0-dev.14",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/plugin.d.ts",
8
8
  "default": "./dist/plugin.js"
9
9
  },
10
- "./devtools": {
11
- "types": "./dist/devtools.d.ts",
12
- "default": "./dist/devtools.js"
13
- },
14
- "./index.css": {
15
- "default": "./index.css"
16
- }
17
- },
18
- "dependencies": {
19
- "@livestore/devtools-react": "0.3.0-dev.12",
20
- "@livestore/web": "0.3.0-dev.12"
21
- },
22
- "devDependencies": {
23
- "vite": "^6.0.11"
24
- },
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
- "scripts": {
29
- "build": "vite build",
30
- "dev": "vite build --watch"
10
+ "./build": "./build.ts"
31
11
  }
32
12
  }