@livestore/devtools-vite 0.3.0-dev.4 → 0.3.0-dev.41

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.
Files changed (38) hide show
  1. package/README.md +17 -0
  2. package/dist/devtools-bundle/data-grid-overlay-editor-BBAPzzoM.js +103 -0
  3. package/dist/devtools-bundle/devtools-react-bundle-BpYw33FL.js +137280 -0
  4. package/dist/devtools-bundle/devtools-vite.css +1 -0
  5. package/dist/devtools-bundle/index-IMEI-cgl.js +44 -0
  6. package/dist/devtools-bundle/index.js +4 -0
  7. package/dist/devtools-bundle/mod-2ScWT2NO.js +368 -0
  8. package/dist/devtools-bundle/number-overlay-editor-f7gD0_gg.js +596 -0
  9. package/dist/empty-module.d.ts +3 -0
  10. package/dist/empty-module.d.ts.map +1 -0
  11. package/dist/empty-module.js +3 -0
  12. package/dist/empty-module.js.map +1 -0
  13. package/dist/generous.d.ts +8 -0
  14. package/dist/generous.d.ts.map +1 -0
  15. package/dist/generous.js +101 -0
  16. package/dist/generous.js.map +1 -0
  17. package/dist/plugin.d.ts +28 -5
  18. package/dist/plugin.d.ts.map +1 -1
  19. package/dist/plugin.js +215 -48
  20. package/dist/plugin.js.map +1 -1
  21. package/dist/vite-path.d.ts +5 -0
  22. package/dist/vite-path.d.ts.map +1 -0
  23. package/dist/vite-path.js +6 -0
  24. package/dist/vite-path.js.map +1 -0
  25. package/dist/vite-path.test.d.ts +2 -0
  26. package/dist/vite-path.test.d.ts.map +1 -0
  27. package/dist/vite-path.test.js +14 -0
  28. package/dist/vite-path.test.js.map +1 -0
  29. package/package.json +8 -19
  30. package/dist/.tsbuildinfo +0 -1
  31. package/dist/devtools.d.ts +0 -2
  32. package/dist/devtools.d.ts.map +0 -1
  33. package/dist/devtools.js +0 -2
  34. package/dist/devtools.js.map +0 -1
  35. package/index.css +0 -1
  36. package/src/devtools.ts +0 -1
  37. package/src/plugin.ts +0 -112
  38. package/tsconfig.json +0 -12
@@ -0,0 +1,101 @@
1
+ import * as os from 'node:os';
2
+ import { Readable } from 'node:stream';
3
+ import * as Generous from '@generousbuilders/effect-sdk';
4
+ import { GenerousRpc } from '@livestore/devtools-common';
5
+ import { Effect, HttpServer, KeyValueStore, Layer, Option, RpcSerialization, RpcServer, Schedule, } from '@livestore/utils/effect';
6
+ import { PlatformNode } from '@livestore/utils/node';
7
+ const options = {
8
+ name: 'livestore',
9
+ id: 'devtools',
10
+ domain: 'schickling-sandbox.generous.builders',
11
+ };
12
+ const RuntimeLayer = Layer.mergeAll(Layer.provide(KeyValueStore.layerFileSystem(`${os.homedir()}/.config/${options.name}/${options.id}`), PlatformNode.NodeContext.layer), Generous.Generous.layer({
13
+ domain: options.domain,
14
+ }));
15
+ const MANIFEST_KEY = 'manifest';
16
+ export const makeGenerousHandler = Effect.gen(function* () {
17
+ const generous = yield* Generous.Generous;
18
+ const kv = yield* KeyValueStore.KeyValueStore;
19
+ let logged = false;
20
+ const continousVerification = Effect.repeat(Effect.gen(function* () {
21
+ const maybeManifest = yield* kv.get(MANIFEST_KEY);
22
+ if (Option.isSome(maybeManifest)) {
23
+ // yield* Effect.logInfo('About to perform a device verification.')
24
+ const manifest = Generous.DeviceRegistrationManifest(maybeManifest.value);
25
+ const maybeUpdatedManifest = yield* generous.licensing.devices
26
+ .ensure({
27
+ manifest,
28
+ })
29
+ .pipe(Effect.catchTags({
30
+ DeviceExpiredError: () => Effect.succeed(undefined),
31
+ DeviceDeregisteredError: () => Effect.succeed(undefined),
32
+ }));
33
+ if (maybeUpdatedManifest) {
34
+ if (!logged) {
35
+ const supporter = yield* generous.users.getSupporter({
36
+ manifest: Generous.DeviceRegistrationManifest(maybeManifest.value),
37
+ });
38
+ yield* Effect.logInfo(`[@livestore/devtools-vite:license] Device is registered to ${supporter.name}`);
39
+ logged = true;
40
+ }
41
+ yield* kv.set(MANIFEST_KEY, maybeUpdatedManifest);
42
+ }
43
+ else {
44
+ yield* kv.remove(MANIFEST_KEY);
45
+ }
46
+ }
47
+ }), Schedule.addDelay(Schedule.forever, () => '5 minutes'));
48
+ yield* continousVerification.pipe(Effect.tapCauseLogPretty, Effect.forkDaemon);
49
+ yield* Effect.yieldNow();
50
+ const RpcLive = GenerousRpc.GenerousRpc.toLayer(Effect.gen(function* () {
51
+ return {
52
+ RegisterDevice: ({ code }) => Effect.gen(function* () {
53
+ const manifest = yield* generous.licensing.devices.register({ code });
54
+ yield* kv.set(MANIFEST_KEY, manifest);
55
+ }).pipe(Effect.mapError((e) => e.toString())),
56
+ GetRegisteredDevice: () => Effect.gen(function* () {
57
+ const maybeManifest = yield* kv.get(MANIFEST_KEY);
58
+ if (Option.isSome(maybeManifest)) {
59
+ const supporter = yield* generous.users.getSupporter({
60
+ manifest: Generous.DeviceRegistrationManifest(maybeManifest.value),
61
+ });
62
+ return { supporter: Option.some(supporter) };
63
+ }
64
+ return { supporter: Option.none() };
65
+ }).pipe(Effect.tapCauseLogPretty, Effect.mapError((e) => e.toString())),
66
+ };
67
+ }));
68
+ const handler = RpcServer.toWebHandler(GenerousRpc.GenerousRpc, {
69
+ layer: Layer.mergeAll(RpcLive, RpcSerialization.layerJson, HttpServer.layerContext),
70
+ });
71
+ return toNodeHandler(handler.handler);
72
+ }).pipe(Effect.provide(RuntimeLayer));
73
+ export const toNodeHandler = (webHandler) => async (req, res) => {
74
+ try {
75
+ // 1️⃣ create a Fetch Request from the Node request
76
+ const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
77
+ const body = ['GET', 'HEAD'].includes(req.method ?? '') ? undefined : req;
78
+ const webReq = new Request(url, {
79
+ method: req.method,
80
+ headers: req.headers,
81
+ body,
82
+ duplex: 'half', // required when `body` is a stream in Node 18–22 [oai_citation:0‡undici.nodejs.org](https://undici.nodejs.org/?utm_source=chatgpt.com)
83
+ });
84
+ // 2️⃣ let your existing handler do the work
85
+ const webRes = await webHandler(webReq);
86
+ // 3️⃣ copy status & headers back to Node
87
+ res.writeHead(webRes.status, webRes.statusText, Object.fromEntries(webRes.headers));
88
+ if (webRes.body) {
89
+ // Convert the WHATWG ReadableStream to a Node stream and pipe it [oai_citation:1‡Node.js — Run JavaScript Everywhere](https://nodejs.org/api/webstreams.html?utm_source=chatgpt.com)
90
+ Readable.fromWeb(webRes.body).pipe(res);
91
+ }
92
+ else {
93
+ res.end();
94
+ }
95
+ }
96
+ catch (err) {
97
+ console.error(err);
98
+ res.writeHead(500).end('Internal Server Error');
99
+ }
100
+ };
101
+ //# sourceMappingURL=generous.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generous.js","sourceRoot":"","sources":["../src/generous.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EACL,MAAM,EACN,UAAU,EACV,aAAa,EACb,KAAK,EACL,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,QAAQ,GACT,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,WAAW;IACjB,EAAE,EAAE,UAAU;IACd,MAAM,EAAE,sCAAsC;CAC/C,CAAA;AAED,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CACjC,KAAK,CAAC,OAAO,CACX,aAAa,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,YAAY,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,EACtF,YAAY,CAAC,WAAW,CAAC,KAAK,CAC/B,EACD,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CACH,CAAA;AAED,MAAM,YAAY,GAAG,U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;QAChF,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAA;QAEzE,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;YAC9B,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,GAAG,CAAC,OAAiC;YAC9C,IAAI;YACJ,MAAM,EAAE,MAAM,EAAE,wIAAwI;SACzJ,CAAC,CAAA;QAEF,6CAA6C;QAC7C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAA;QAEvC,0CAA0C;QAC1C,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;QAEnF,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAChB,sLAAsL;YACtL,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,IAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAChD,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,EAAE,CAAA;QACX,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;IACjD,CAAC;AACH,CAAC,CAAA"}
package/dist/plugin.d.ts CHANGED
@@ -1,19 +1,42 @@
1
+ import { Schema } from '@livestore/utils/effect';
1
2
  import type { Plugin } from 'vite';
2
- export type PluginOptions = {
3
+ export declare const PluginOptions: Schema.Struct<{
3
4
  /**
4
- * The path to the schema file. Needs to be a valid ESM import and relative to the root of the project.
5
+ * The path to the schema file. The schema file needs to export the schema as `export const schema`.
6
+ * Path needs to be relative to the Vite `root`.
5
7
  *
6
8
  * Example:
7
9
  * ```ts
8
10
  * import { devtoolsVitePlugin } from '@livestore/devtools-vite'
9
11
  *
10
12
  * devtoolsVitePlugin({
11
- * schemaPath: './src/db/schema/index.js'
13
+ * schemaPath: './src/db/schema/index.ts'
14
+ * // ...
15
+ * })
16
+ *
17
+ * If your app uses multiple schemas, you can provide an array of schema paths.
18
+ * ```ts
19
+ * devtoolsVitePlugin({
20
+ * schemaPath: ['./src/db/schema/index.ts', './src/db/schema2/index.ts']
12
21
  * // ...
13
22
  * })
14
23
  * ```
15
24
  */
16
- schemaPath: string;
17
- };
25
+ schemaPath: Schema.Union<[typeof Schema.String, Schema.Array$<typeof Schema.String>]>;
26
+ /**
27
+ * Where to serve the devtools UI.
28
+ *
29
+ * @default '/_livestore'
30
+ */
31
+ mode: Schema.optional<Schema.Union<[Schema.TaggedStruct<"node", {
32
+ url: typeof Schema.String;
33
+ }>, Schema.TaggedStruct<"web", {}>, Schema.TaggedStruct<"browser-extension", {}>]>>;
34
+ path: Schema.optional<typeof Schema.String>;
35
+ experimental: Schema.optional<Schema.Struct<{
36
+ continueOnError: Schema.optional<typeof Schema.Boolean>;
37
+ enforceLicense: Schema.optional<typeof Schema.Boolean>;
38
+ }>>;
39
+ }>;
40
+ export type PluginOptions = typeof PluginOptions.Type;
18
41
  export declare const livestoreDevtoolsPlugin: (options: PluginOptions) => Plugin;
19
42
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;;;;;;OAYG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,uBAAuB,YAAa,aAAa,KAAG,MAqDhE,CAAA"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,eAAO,MAAM,aAAa;IACxB;;;;;;;;;;;;;;;;;;;;OAoBG;;IAEH;;;;OAIG;;;;;;;;;EASH,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;AAIrD,eAAO,MAAM,uBAAuB,GAAI,SAAS,aAAa,KAAG,MA+NhE,CAAA"}
package/dist/plugin.js CHANGED
@@ -1,52 +1,222 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { Devtools } from '@livestore/common';
3
+ import { Effect, Logger, Schema } from '@livestore/utils/effect';
4
+ import { makeGenerousHandler } from './generous.js';
5
+ import { getMountPath } from './vite-path.js';
6
+ const IS_LOCAL_PREVIEW = process.env.LSD_DEVTOOLS_LOCAL_PREVIEW !== undefined;
7
+ export const PluginOptions = Schema.Struct({
8
+ /**
9
+ * The path to the schema file. The schema file needs to export the schema as `export const schema`.
10
+ * Path needs to be relative to the Vite `root`.
11
+ *
12
+ * Example:
13
+ * ```ts
14
+ * import { devtoolsVitePlugin } from '@livestore/devtools-vite'
15
+ *
16
+ * devtoolsVitePlugin({
17
+ * schemaPath: './src/db/schema/index.ts'
18
+ * // ...
19
+ * })
20
+ *
21
+ * If your app uses multiple schemas, you can provide an array of schema paths.
22
+ * ```ts
23
+ * devtoolsVitePlugin({
24
+ * schemaPath: ['./src/db/schema/index.ts', './src/db/schema2/index.ts']
25
+ * // ...
26
+ * })
27
+ * ```
28
+ */
29
+ schemaPath: Schema.Union(Schema.String, Schema.Array(Schema.String)),
30
+ /**
31
+ * Where to serve the devtools UI.
32
+ *
33
+ * @default '/_livestore'
34
+ */
35
+ mode: Schema.optional(Devtools.DevtoolsMode),
36
+ path: Schema.optional(Schema.String),
37
+ experimental: Schema.optional(Schema.Struct({
38
+ continueOnError: Schema.optional(Schema.Boolean),
39
+ enforceLicense: Schema.optional(Schema.Boolean),
40
+ })),
41
+ });
42
+ const pluginName = '@livestore/devtools-vite';
3
43
  export const livestoreDevtoolsPlugin = (options) => {
44
+ const result = Schema.validateEither(PluginOptions)(options);
45
+ if (result._tag === 'Left') {
46
+ console.error(`[@livestore/devtools-vite] Invalid options: ${result.left}`);
47
+ return {
48
+ name: pluginName,
49
+ };
50
+ }
4
51
  return {
5
- name: 'devtools-vite',
52
+ name: pluginName,
6
53
  // `vite dev` support
7
- configureServer: (server) => {
8
- server.middlewares.use('/_devtools.html', async (_, res) => {
9
- 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);
54
+ configureServer: (server) => Effect.gen(function* () {
55
+ const mountPath = getMountPath({ path: options.path, base: server.config.base });
56
+ // console.debug('[livestore-devtools-vite]', {
57
+ // 'server.config.base': server.config.base,
58
+ // mountPath,
59
+ // })
60
+ const schemaPathsInput = Array.isArray(options.schemaPath) ? options.schemaPath : [options.schemaPath];
61
+ const schemaPaths = schemaPathsInput.map((schemaPath) => path.isAbsolute(schemaPath) ? schemaPath : path.resolve(path.join(server.config.root, schemaPath)));
62
+ for (const schemaPath of schemaPaths) {
63
+ try {
64
+ const schemaExports = yield* Effect.promise(() => server.ssrLoadModule(schemaPath));
65
+ if (!('schema' in schemaExports)) {
66
+ console.error(`\
67
+ [@livestore/devtools-vite] Could not find an export named \`schema\` in the provided schema file.
68
+ Please make sure to export the schema from your schema file like this: \`export const schema = ...\`.
69
+
70
+ Found exports: ${Object.keys(schemaExports).join(', ')}
71
+ Resolved schema path: ${schemaPath}
72
+ `);
73
+ return;
74
+ }
75
+ }
76
+ catch (error) {
77
+ console.error(`[@livestore/devtools-vite] Error loading schema file ${schemaPath}`, error);
78
+ if (options.experimental?.continueOnError !== true) {
79
+ return;
80
+ }
81
+ }
82
+ }
83
+ let bundlePath;
84
+ let cssPath;
85
+ // Allows for loading the devtools via Vite without having to build the bundle
86
+ // Simply set `LSD_DEVTOOLS_LOCAL_PREVIEW=1` when running `pnpm dev` in the app
87
+ if (IS_LOCAL_PREVIEW) {
88
+ // We're pointing to the `dist` css file here because our current Vite setup doesn't have the needed Tailwind processing
89
+ // Make sure to run `pnpm dev` in the devtools-react package to keep it in sync
90
+ cssPath = path.resolve(import.meta.dirname, '..', '..', 'devtools-react', 'dist', 'index.css');
91
+ bundlePath = path.join(import.meta.dirname, '..', 'devtools-react-bundle.ts');
92
+ }
93
+ else {
94
+ // Make sure to run `pnpm build` before to generate the bundle
95
+ const bundleDir = path.join(import.meta.dirname, '..', 'dist', 'devtools-bundle');
96
+ bundlePath = path.resolve(bundleDir, 'index.js');
97
+ cssPath = path.resolve(bundleDir, 'devtools-vite.css');
98
+ }
99
+ const hasWebAdapterDep = yield* Effect.promise(() => server
100
+ .ssrLoadModule('@livestore/adapter-web')
101
+ .then(() => true)
102
+ .catch(() => false));
103
+ const template = makeIndexHtml({
104
+ schemaPaths,
105
+ bundlePath,
106
+ cssPath,
107
+ mountPath,
108
+ mode: options.mode,
109
+ hasWebAdapterDep,
13
110
  });
14
- },
15
- // `vite build` support below
16
- config: (config) => {
17
- if (config.build === undefined) {
18
- config.build = {};
111
+ const html = yield* Effect.promise(() => server.transformIndexHtml(mountPath, template));
112
+ if (options.experimental?.enforceLicense === true) {
113
+ yield* Effect.logInfo('[@livestore/devtools-vite:license] Enforcing license');
114
+ const generousMiddleware = yield* makeGenerousHandler;
115
+ server.middlewares.use('/livestore-devtools/rpc', generousMiddleware);
19
116
  }
20
- if (config.build.rollupOptions === undefined) {
21
- config.build.rollupOptions = {};
117
+ server.middlewares.use(mountPath, async (req, res, next) => {
118
+ if (req.url === undefined) {
119
+ next();
120
+ return;
121
+ }
122
+ const url = new URL(req.url, typeof server.config.server.host === 'string' ? server.config.server.host : 'http://localhost');
123
+ // console.log('livestore-devtools-vite:req', url)
124
+ // Forward all Vite requests to Vite
125
+ if (url.pathname.startsWith('/@') === true) {
126
+ next();
127
+ return;
128
+ }
129
+ else {
130
+ // Serve the devtools index.html
131
+ res.setHeader('Content-Type', 'text/html');
132
+ // Remove line that contains `vinxi/runtime`
133
+ const trimmedHtml = html
134
+ .split('\n')
135
+ .filter((line) => !line.includes('vinxi/runtime'))
136
+ .join('\n');
137
+ res.end(trimmedHtml);
138
+ return;
139
+ }
140
+ });
141
+ // yield* Effect.never
142
+ }).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.provide(Logger.prettyWithThread('livestore-devtools-vite')), Effect.runPromise),
143
+ config: async (config, env) => {
144
+ if (config.optimizeDeps === undefined) {
145
+ config.optimizeDeps = {};
22
146
  }
23
- if (config.build.rollupOptions.input === undefined) {
24
- config.build.rollupOptions.input = {
25
- main: path.resolve('./index.html'),
26
- };
147
+ if (config.optimizeDeps.exclude === undefined) {
148
+ config.optimizeDeps.exclude = [];
27
149
  }
28
- if (isRecord(config.build.rollupOptions.input)) {
29
- config.build.rollupOptions.input.devtools = 'virtual:_devtools.html';
30
- // config.build.rollupOptions.input.devtools = '_devtools.html'
150
+ if (env.command === 'serve') {
151
+ if (config.define === undefined) {
152
+ config.define = {};
153
+ }
154
+ const mountPath = getMountPath({ path: options.path, base: config.base ?? '/' });
155
+ config.define['LIVESTORE_DEVTOOLS_PATH'] = `'${mountPath}'`;
156
+ if (options.experimental?.enforceLicense === true) {
157
+ config.define['LIVESTORE_DEVTOOLS_ENFORCE_LICENSE'] = 'true';
158
+ }
31
159
  }
32
- return config;
33
- },
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;
160
+ const toAdd = ['@livestore/devtools-vite', '@livestore/wa-sqlite', '@livestore/utils'];
161
+ for (const dep of toAdd) {
162
+ if (!config.optimizeDeps.exclude.includes(dep)) {
163
+ config.optimizeDeps.exclude.push(dep);
164
+ }
40
165
  }
41
- },
42
- load: (id) => {
43
- if (id === 'virtual:_devtools.html') {
44
- return makeIndexHtml({ schemaPath: options.schemaPath });
166
+ if (IS_LOCAL_PREVIEW) {
167
+ console.debug(`[@livestore/devtools-vite] Using local preview`);
168
+ if (config.resolve === undefined) {
169
+ config.resolve = {};
170
+ }
171
+ if (config.resolve.alias === undefined) {
172
+ config.resolve.alias = {};
173
+ }
174
+ const emptyModulePath = path.resolve(import.meta.dirname, '..', 'src', 'empty-module.ts');
175
+ // @ts-expect-error needed for `glide-data-grid`
176
+ config.resolve.alias['react-responsive-carousel'] = emptyModulePath;
177
+ // @ts-expect-error needed for `glide-data-grid`
178
+ config.resolve.alias['marked'] = emptyModulePath;
45
179
  }
180
+ return config;
46
181
  },
182
+ // `vite build` support below
183
+ // TODO maybe bring back at some point
184
+ // config: (config) => {
185
+ // if (config.build === undefined) {
186
+ // config.build = {}
187
+ // }
188
+ // if (config.build.rollupOptions === undefined) {
189
+ // config.build.rollupOptions = {}
190
+ // }
191
+ // if (config.build.rollupOptions.input === undefined) {
192
+ // config.build.rollupOptions.input = {
193
+ // main: path.resolve('./index.html'),
194
+ // }
195
+ // }
196
+ // if (isRecord(config.build.rollupOptions.input)) {
197
+ // config.build.rollupOptions.input.devtools = 'virtual:_devtools.html'
198
+ // // config.build.rollupOptions.input.devtools = '_devtools.html'
199
+ // }
200
+ // return config
201
+ // },
202
+ // writeBundle: (_) => {
203
+ // fs.renameSync(path.join(_.dir!, 'virtual:_devtools.html'), path.join(_.dir!, '_devtools.html'))
204
+ // },
205
+ // resolveId: (id) => {
206
+ // if (id === 'virtual:_devtools.html') {
207
+ // return id
208
+ // }
209
+ // },
210
+ // load: (id) => {
211
+ // if (id === 'virtual:_devtools.html') {
212
+ // return makeIndexHtml({ schemaPath: options.schemaPath })
213
+ // }
214
+ // },
47
215
  };
48
216
  };
49
- const makeIndexHtml = ({ schemaPath }) => {
217
+ const makeIndexHtml = ({ schemaPaths, bundlePath, cssPath, mountPath, mode, hasWebAdapterDep, }) => {
218
+ // `sharedWorker` is only needed for @livestore/adapter-web
219
+ // We're trying to import it dynamically for the web-adapter and fallback to the bundled one if it fails
50
220
  return /*html*/ `
51
221
  <!doctype html>
52
222
  <html lang="en">
@@ -59,25 +229,22 @@ const makeIndexHtml = ({ schemaPath }) => {
59
229
  <body>
60
230
  <div id="root"></div>
61
231
  <script type="module">
62
- // NOTE we need to re-export dependencies from "@livestore/devtools-react"
63
- // 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)}'
232
+ import '${cssPath}'
68
233
 
69
- mountDevtools({
70
- schema,
71
- rootEl: document.getElementById('root'),
72
- sharedWorker,
234
+ import { run } from '${bundlePath}'
235
+ ${schemaPaths.map((schemaPath, index) => ` import { schema as schema${index} } from '${schemaPath}'`).join('\n')}
236
+ ${hasWebAdapterDep ? 'import sharedWorker from "@livestore/adapter-web/shared-worker?sharedworker"' : 'const sharedWorker = undefined'}
237
+
238
+ run({
239
+ schemas: [${schemaPaths.map((_schemaPath, index) => `schema${index}`).join(', ')}],
73
240
  license: ${process.env.LSD_LICENSE} ? '${process.env.LSD_LICENSE}' : undefined,
74
- // Mode will be provided via URL search params
75
- mode: undefined,
241
+ mode: ${mode ? Schema.encodeSync(Schema.parseJson(Devtools.DevtoolsMode))(mode) : undefined},
242
+ sharedWorker,
243
+ mountPath: '${mountPath}',
76
244
  })
77
245
  </script>
78
246
  </body>
79
247
  </html>
80
248
  `;
81
249
  };
82
- const isRecord = (value) => typeof value === 'object' && value !== null;
83
250
  //# sourceMappingURL=plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin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E7E,SAAS;;;;;EAK7B,CAAA;AACF,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare const getMountPath: ({ path: explicitPath, base }: {
2
+ path: string | undefined;
3
+ base: string;
4
+ }) => string;
5
+ //# sourceMappingURL=vite-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-path.d.ts","sourceRoot":"","sources":["../src/vite-path.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,GAAI,8BAA8B;IAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,MAGvG,CAAA"}
@@ -0,0 +1,6 @@
1
+ import path from 'node:path';
2
+ export const getMountPath = ({ path: explicitPath, base }) => {
3
+ const pathname = explicitPath ?? '/_livestore';
4
+ return path.join(base, pathname);
5
+ };
6
+ //# sourceMappingURL=vite-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-path.js","sourceRoot":"","sources":["../src/vite-path.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAA8C,EAAU,EAAE;IAC/G,MAAM,QAAQ,GAAG,YAAY,IAAI,aAAa,CAAA;IAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAClC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vite-path.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-path.test.d.ts","sourceRoot":"","sources":["../src/vite-path.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getMountPath } from './vite-path.js';
3
+ describe('getMountPath', () => {
4
+ it('default vite / node adapter case', () => {
5
+ expect(getMountPath({ path: undefined, base: '/' })).toEqual('/_livestore');
6
+ });
7
+ it('Tanstack Start case', () => {
8
+ expect(getMountPath({ path: undefined, base: '/_build' })).toEqual('/_build/_livestore');
9
+ });
10
+ it('Tanstack Start case', () => {
11
+ expect(getMountPath({ path: '/_livestore', base: '/_build' })).toEqual('/_build/_livestore');
12
+ });
13
+ });
14
+ //# sourceMappingURL=vite-path.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-path.test.js","sourceRoot":"","sources":["../src/vite-path.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;IAC7E,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;QAC7B,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;IAC1F,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;QAC7B,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;IAC9F,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,32 +1,21 @@
1
1
  {
2
2
  "name": "@livestore/devtools-vite",
3
- "version": "0.3.0-dev.4",
3
+ "version": "0.3.0-dev.41",
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
- }
10
+ "./build": "./build.ts"
17
11
  },
18
12
  "dependencies": {
19
- "@livestore/devtools-react": "0.3.0-dev.4",
20
- "@livestore/web": "0.3.0-dev.4"
21
- },
22
- "devDependencies": {
23
- "vite": "^5.4.10"
24
- },
25
- "publishConfig": {
26
- "access": "public"
13
+ "@livestore/adapter-web": "0.3.0-dev.41"
27
14
  },
28
- "scripts": {
29
- "dev": "vite build --watch",
30
- "build": "vite build"
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "peerDependencies": {
19
+ "vite": "~6.2.1"
31
20
  }
32
21
  }