@livestore/devtools-expo 0.3.0-dev.5 → 0.3.0-dev.51

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
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // eslint-disable-next-line unicorn/prefer-module
3
+ // eslint-disable-next-line unicorn/prefer-module, @typescript-eslint/no-require-imports
4
4
  module.exports = require('./metro-config.cjs');
5
5
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":";;AAAA,iDAAiD;AACjD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":";;AAAA,wFAAwF;AACxF,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA"}
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, unicorn/prefer-module, @typescript-eslint/consistent-type-imports, prettier/prettier
4
+ const { Effect, Logger, LogLevel } = require('@livestore/utils/effect');
5
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, unicorn/prefer-module, @typescript-eslint/consistent-type-imports, prettier/prettier
6
+ const { PlatformNode } = require('@livestore/utils/node');
3
7
  /**
4
8
  * Patches the Metro config to add a middleware via `config.server.enhanceMiddleware`.
5
9
  */
@@ -8,32 +12,42 @@ const addLiveStoreDevtoolsMiddleware = (config, options) => {
8
12
  if (process.env.CI || !process.stdout.isTTY) {
9
13
  return;
10
14
  }
11
- const viteMiddleware = makeLiveStoreDevtoolsMiddleware(options);
15
+ const host = options.host ?? '0.0.0.0'; // Defaulting to a hostname that can be reached from the device
16
+ const port = options.port ?? 4242;
17
+ // Needed for @livestore/adapter-expo
18
+ process.env.EXPO_PUBLIC_LIVESTORE_DEVTOOLS_URL = `ws://${host}:${port}`;
19
+ import('@livestore/adapter-node/devtools')
20
+ .then(async ({ startDevtoolsServer }) => {
21
+ startDevtoolsServer({
22
+ clientSessionInfo: undefined,
23
+ schemaPath: options.schemaPath,
24
+ host,
25
+ port,
26
+ }).pipe(Effect.provide(PlatformNode.NodeHttpClient.layer), Effect.provide(Logger.prettyWithThread('@livestore/devtools-expo:metro-config')), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.tapCauseLogPretty, Effect.runPromise);
27
+ })
28
+ .catch((error) => {
29
+ console.error(error);
30
+ });
12
31
  const previousEnhanceMiddleware = config.server.enhanceMiddleware;
32
+ /** Redirects requests to LiveStore DevTools to `http://${host}:${port}/_livestore/${...}` */
33
+ const redirectMiddleware = (req, res, next) => {
34
+ if (req.url?.startsWith('/_livestore') === false) {
35
+ return next();
36
+ }
37
+ const redirectUrl = `http://${host}:${port}/_livestore/${req.url.slice('/_livestore'.length)}`;
38
+ res.writeHead(302, { Location: redirectUrl });
39
+ res.end();
40
+ };
13
41
  const enhanceMiddleware = (metroMiddleware, server) => {
14
42
  const enhancedMiddleware = previousEnhanceMiddleware(metroMiddleware, server);
15
- return (req, res, next) => req.url?.startsWith('/livestore-devtools')
16
- ? viteMiddleware(req, res, () => enhancedMiddleware(req, res, next))
43
+ return (req, res, next) => req.url?.startsWith('/_livestore')
44
+ ? redirectMiddleware(req, res, () => enhancedMiddleware(req, res, next))
17
45
  : enhancedMiddleware(req, res, next);
18
46
  };
19
47
  config.server.enhanceMiddleware = enhanceMiddleware;
20
48
  };
21
- const makeLiveStoreDevtoolsMiddleware = (options) => {
22
- // TODO Once Expo supports proper ESM, we can make this a static import
23
- // const viteServerPromise = makeViteServer(options)
24
- const viteServerPromise = import('@livestore/node/devtools').then(({ makeViteServer }) => makeViteServer({ ...options, mode: { _tag: 'expo' } }));
25
- const middleware = async (req, res, next) => {
26
- if (req.url?.startsWith('/livestore-devtools') == false) {
27
- return next();
28
- }
29
- const viteServer = await viteServerPromise;
30
- return viteServer.middlewares(req, res, next);
31
- };
32
- return middleware;
33
- };
34
49
  // eslint-disable-next-line unicorn/prefer-module
35
50
  module.exports = {
36
51
  addLiveStoreDevtoolsMiddleware,
37
- makeLiveStoreDevtoolsMiddleware,
38
52
  };
39
53
  //# sourceMappingURL=metro-config.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"metro-config.cjs","sourceRoot":"","sources":["../src/metro-config.cts"],"names":[],"mappings":";;AAMA;;GAEG;AACH,MAAM,8BAA8B,GAAG,CAAC,MAAgC,EAAE,OAAgB,EAAE,EAAE;IAC5F,kCAAkC;IAClC,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC5C,OAAM;IACR,CAAC;IAED,MAAM,cAAc,GAAG,+BAA+B,CAAC,OAAO,CAAC,CAAA;IAE/D,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,CAAC,iBAGjC,CAAA;IAEf,MAAM,iBAAiB,GAAG,CAAC,eAA2B,EAAE,MAAW,EAAc,EAAE;QACjF,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAA;QAE7E,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CACxB,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,qBAAqB,CAAC;YACxC,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACpE,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC,CAAA;IAED,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;AACrD,C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CAAC,GAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAA;QAC/F,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA;QAC7C,GAAG,CAAC,GAAG,EAAE,CAAA;IACX,CAAC,CAAA;IAED,MAAM,iBAAiB,GAAG,CAAC,eAA2B,EAAE,MAAW,EAAc,EAAE;QACjF,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAA;QAE7E,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CACxB,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,aAAa,CAAC;YAChC,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACxE,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC,CAAA;IAED,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;AACrD,CAAC,CAAA;AAOD,iDAAiD;AACjD,MAAM,CAAC,OAAO,GAAG;IACf,8BAA8B;CAC/B,CAAA"}
@@ -1,14 +1,13 @@
1
- import type * as http from 'node:http';
2
1
  import type { MetroConfig } from 'expo/metro-config';
3
2
  import type { Options } from './types.js';
4
3
  /**
5
4
  * Patches the Metro config to add a middleware via `config.server.enhanceMiddleware`.
6
5
  */
7
6
  declare const addLiveStoreDevtoolsMiddleware: (config: MutableDeep<MetroConfig>, options: Options) => void;
8
- declare const makeLiveStoreDevtoolsMiddleware: (options: Options) => (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => Promise<void>;
9
7
  /** Remove readonly from all properties */
10
8
  type MutableDeep<T> = {
11
9
  -readonly [P in keyof T]: MutableDeep<T[P]>;
12
10
  };
13
- export type { addLiveStoreDevtoolsMiddleware, makeLiveStoreDevtoolsMiddleware };
11
+ export type { addLiveStoreDevtoolsMiddleware };
12
+ export type { Options } from './types.js';
14
13
  //# sourceMappingURL=metro-config.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metro-config.d.cts","sourceRoot":"","sources":["../src/metro-config.cts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,YAAY,CAAA;AAErD;;GAEG;AACH,QAAA,MAAM,8BAA8B,WAAY,WAAW,CAAC,WAAW,CAAC,WAAW,OAAO,SAuBzF,CAAA;AAED,QAAA,MAAM,+BAA+B,YAAa,OAAO,WAOxB,IAAI,CAAC,eAAe,OAAO,IAAI,CAAC,cAAc,QAAQ,MAAM,IAAI,kBAWhG,CAAA;AAED,0CAA0C;AAC1C,KAAK,WAAW,CAAC,CAAC,IAAI;IACpB,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAA;AAQD,YAAY,EAAE,8BAA8B,EAAE,+BAA+B,EAAE,CAAA"}
1
+ {"version":3,"file":"metro-config.d.cts","sourceRoot":"","sources":["../src/metro-config.cts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,YAAY,CAAA;AAErD;;GAEG;AACH,QAAA,MAAM,8BAA8B,GAAI,QAAQ,WAAW,CAAC,WAAW,CAAC,EAAE,SAAS,OAAO,SAwDzF,CAAA;AAED,0CAA0C;AAC1C,KAAK,WAAW,CAAC,CAAC,IAAI;IACpB,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAA;AAOD,YAAY,EAAE,8BAA8B,EAAE,CAAA;AAC9C,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA"}
package/package.json CHANGED
@@ -1,23 +1,27 @@
1
1
  {
2
2
  "name": "@livestore/devtools-expo",
3
- "version": "0.3.0-dev.5",
4
- "main": "./dist/index.cjs",
3
+ "version": "0.3.0-dev.51",
4
+ "sideEffects": false,
5
5
  "types": "./dist/index.d.cts",
6
6
  "dependencies": {
7
- "@livestore/devtools-react": "0.3.0-dev.5",
8
- "@livestore/wa-sqlite": "1.0.3-dev.7",
9
- "vite": "^5.4.10",
10
- "ws": "^8.18.0",
11
- "@livestore/web": "0.3.0-dev.5",
12
- "@livestore/node": "0.3.0-dev.5"
7
+ "@livestore/adapter-node": "0.3.0-dev.51",
8
+ "@livestore/utils": "0.3.0-dev.51"
13
9
  },
14
10
  "devDependencies": {
15
- "@types/node": "22.10.5",
16
- "@types/ws": "8.5.12",
17
- "expo": "52.0.18"
11
+ "@types/node": "^22.15.17",
12
+ "expo": "^53.0.7",
13
+ "vite": "^6.3.4"
18
14
  },
15
+ "files": [
16
+ "package.json",
17
+ "expo-module.config.json",
18
+ "webui",
19
+ "src",
20
+ "dist"
21
+ ],
22
+ "main": "./dist/index.cjs",
19
23
  "peerDependencies": {
20
- "expo": "52.0.18"
24
+ "expo": "~53.0.7"
21
25
  },
22
26
  "publishConfig": {
23
27
  "access": "public"
package/src/index.cts CHANGED
@@ -1,4 +1,4 @@
1
- // eslint-disable-next-line unicorn/prefer-module
1
+ // eslint-disable-next-line unicorn/prefer-module, @typescript-eslint/no-require-imports
2
2
  module.exports = require('./metro-config.cjs')
3
3
 
4
4
  export type * from './metro-config.cts'
@@ -1,4 +1,8 @@
1
- import type * as http from 'node:http'
1
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, unicorn/prefer-module, @typescript-eslint/consistent-type-imports, prettier/prettier
2
+ const { Effect, Logger, LogLevel } = require('@livestore/utils/effect') as typeof import('@livestore/utils/effect', { with: { "resolution-mode": "import" } })
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, unicorn/prefer-module, @typescript-eslint/consistent-type-imports, prettier/prettier
5
+ const { PlatformNode } = require('@livestore/utils/node') as typeof import('@livestore/utils/node', { with: { "resolution-mode": "import" } })
2
6
 
3
7
  import type { MetroConfig } from 'expo/metro-config'
4
8
 
@@ -12,46 +16,59 @@ const addLiveStoreDevtoolsMiddleware = (config: MutableDeep<MetroConfig>, option
12
16
  if (process.env.CI || !process.stdout.isTTY) {
13
17
  return
14
18
  }
15
-
16
- const viteMiddleware = makeLiveStoreDevtoolsMiddleware(options)
19
+ const host = options.host ?? '0.0.0.0' // Defaulting to a hostname that can be reached from the device
20
+ const port = options.port ?? 4242
21
+
22
+ // Needed for @livestore/adapter-expo
23
+ process.env.EXPO_PUBLIC_LIVESTORE_DEVTOOLS_URL = `ws://${host}:${port}`
24
+
25
+ import('@livestore/adapter-node/devtools')
26
+ .then(async ({ startDevtoolsServer }) => {
27
+ startDevtoolsServer({
28
+ clientSessionInfo: undefined,
29
+ schemaPath: options.schemaPath,
30
+ host,
31
+ port,
32
+ }).pipe(
33
+ Effect.provide(PlatformNode.NodeHttpClient.layer),
34
+ Effect.provide(Logger.prettyWithThread('@livestore/devtools-expo:metro-config')),
35
+ Logger.withMinimumLogLevel(LogLevel.Debug),
36
+ Effect.tapCauseLogPretty,
37
+ Effect.runPromise,
38
+ )
39
+ })
40
+ .catch((error) => {
41
+ console.error(error)
42
+ })
17
43
 
18
44
  const previousEnhanceMiddleware = config.server.enhanceMiddleware as (
19
45
  metroMiddleware: Middleware,
20
46
  server: any,
21
47
  ) => Middleware
22
48
 
49
+ /** Redirects requests to LiveStore DevTools to `http://${host}:${port}/_livestore/${...}` */
50
+ const redirectMiddleware: Middleware = (req, res, next) => {
51
+ if (req.url?.startsWith('/_livestore') === false) {
52
+ return next()
53
+ }
54
+
55
+ const redirectUrl = `http://${host}:${port}/_livestore/${req.url!.slice('/_livestore'.length)}`
56
+ res.writeHead(302, { Location: redirectUrl })
57
+ res.end()
58
+ }
59
+
23
60
  const enhanceMiddleware = (metroMiddleware: Middleware, server: any): Middleware => {
24
61
  const enhancedMiddleware = previousEnhanceMiddleware(metroMiddleware, server)
25
62
 
26
63
  return (req, res, next) =>
27
- req.url?.startsWith('/livestore-devtools')
28
- ? viteMiddleware(req, res, () => enhancedMiddleware(req, res, next))
64
+ req.url?.startsWith('/_livestore')
65
+ ? redirectMiddleware(req, res, () => enhancedMiddleware(req, res, next))
29
66
  : enhancedMiddleware(req, res, next)
30
67
  }
31
68
 
32
69
  config.server.enhanceMiddleware = enhanceMiddleware
33
70
  }
34
71
 
35
- const makeLiveStoreDevtoolsMiddleware = (options: Options) => {
36
- // TODO Once Expo supports proper ESM, we can make this a static import
37
- // const viteServerPromise = makeViteServer(options)
38
- const viteServerPromise = import('@livestore/node/devtools').then(({ makeViteServer }) =>
39
- makeViteServer({ ...options, mode: { _tag: 'expo' } }),
40
- )
41
-
42
- const middleware = async (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => {
43
- if (req.url?.startsWith('/livestore-devtools') == false) {
44
- return next()
45
- }
46
-
47
- const viteServer = await viteServerPromise
48
-
49
- return viteServer.middlewares(req, res, next)
50
- }
51
-
52
- return middleware
53
- }
54
-
55
72
  /** Remove readonly from all properties */
56
73
  type MutableDeep<T> = {
57
74
  -readonly [P in keyof T]: MutableDeep<T[P]>
@@ -60,7 +77,7 @@ type MutableDeep<T> = {
60
77
  // eslint-disable-next-line unicorn/prefer-module
61
78
  module.exports = {
62
79
  addLiveStoreDevtoolsMiddleware,
63
- makeLiveStoreDevtoolsMiddleware,
64
80
  }
65
81
 
66
- export type { addLiveStoreDevtoolsMiddleware, makeLiveStoreDevtoolsMiddleware }
82
+ export type { addLiveStoreDevtoolsMiddleware }
83
+ export type { Options } from './types.js'
package/src/types.d.ts CHANGED
@@ -13,4 +13,16 @@ export type Options = {
13
13
  * Example: `./src/schema.ts`
14
14
  */
15
15
  schemaPath: string
16
+ /**
17
+ * The port to listen on for the devtools server
18
+ *
19
+ * @default 4242
20
+ */
21
+ port: number
22
+ /**
23
+ * The host to listen on for the devtools server
24
+ *
25
+ * @default '0.0.0.0'
26
+ */
27
+ host: string
16
28
  }
package/webui/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>LiveStore DevTools Redirect</title>
7
7
  <script>
8
8
  const currentUrl = new URL(window.location.href);
9
- const redirectUrl = `http://localhost:${currentUrl.port}/livestore-devtools/`;
9
+ const redirectUrl = `http://localhost:${currentUrl.port}/_livestore/node?autoconnect`;
10
10
  window.location.href = redirectUrl;
11
11
  </script>
12
12
  </head>
@@ -1,4 +0,0 @@
1
- import * as Vite from 'vite';
2
- import type { Options } from './types.js';
3
- export declare const makeViteServer: (options: Options) => Promise<Vite.ViteDevServer>;
4
- //# sourceMappingURL=unused-vite-dev-server.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unused-vite-dev-server.d.mts","sourceRoot":"","sources":["../src/unused-vite-dev-server.mts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAIzC,eAAO,MAAM,cAAc,YAAmB,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC,aAAa,CAoCjF,CAAA"}
@@ -1,98 +0,0 @@
1
- import * as http from 'node:http';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- import * as Vite from 'vite';
5
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
- export const makeViteServer = async (options) => {
7
- const hmrPort = await getFreePort();
8
- const cwd = process.cwd();
9
- const defaultViteConfig = Vite.defineConfig({
10
- server: {
11
- middlewareMode: true,
12
- hmr: {
13
- port: hmrPort,
14
- },
15
- fs: {
16
- // Adds `node_modules` so we can import `@livestore/wa-sqlite` for WASM to work
17
- allow: [path.resolve(__dirname, '..', '..')],
18
- },
19
- },
20
- resolve: {
21
- alias: {
22
- '@schema': path.resolve(cwd, options.schemaPath),
23
- },
24
- },
25
- appType: 'spa',
26
- optimizeDeps: {
27
- // TODO remove once fixed https://github.com/vitejs/vite/issues/8427
28
- exclude: ['@livestore/wa-sqlite'],
29
- },
30
- root: __dirname,
31
- base: '/livestore-devtools/',
32
- plugins: [virtualHtmlPlugin],
33
- });
34
- const viteConfig = options.viteConfig?.(defaultViteConfig) ?? defaultViteConfig;
35
- const viteServer = Vite.createServer(viteConfig);
36
- return viteServer;
37
- };
38
- const virtualHtmlPlugin = {
39
- name: 'virtual-html',
40
- configureServer: (server) => {
41
- return () => {
42
- server.middlewares.use(async (req, res, next) => {
43
- if (req.url === '/' || req.url === '' || req.url === '/index.html') {
44
- const html = `
45
- <!doctype html>
46
- <html lang="en">
47
- <head>
48
- <meta charset="UTF-8" />
49
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
50
- <meta name="livestore-devtools" content="true" />
51
- <title>LiveStore Devtools</title>
52
- </head>
53
- <body>
54
- <div id="root"></div>
55
- <script type="module">
56
- import '@livestore/devtools-react/index.css'
57
- import { mountDevtools } from '@livestore/devtools-react'
58
- import sharedWorker from '@livestore/web/shared-worker?sharedworker'
59
- import { schema } from '@schema'
60
-
61
- mountDevtools({ schema, rootEl: document.getElementById('root'), sharedWorker, mode: 'expo' })
62
- </script>
63
- </body>
64
- </html>
65
- `;
66
- const transformedHtml = await server.transformIndexHtml(req.url, html);
67
- res.statusCode = 200;
68
- res.setHeader('Content-Type', 'text/html');
69
- res.end(transformedHtml);
70
- }
71
- else {
72
- next();
73
- }
74
- });
75
- };
76
- },
77
- };
78
- const getFreePort = () => {
79
- return new Promise((resolve, reject) => {
80
- const server = http.createServer();
81
- // Listen on port 0 to get an available port
82
- server.listen(0, () => {
83
- const address = server.address();
84
- if (address && typeof address === 'object') {
85
- const port = address.port;
86
- server.close(() => resolve(port));
87
- }
88
- else {
89
- server.close(() => reject(new Error('Failed to get a free port')));
90
- }
91
- });
92
- // Error handling in case the server encounters an error
93
- server.on('error', (err) => {
94
- server.close(() => reject(err));
95
- });
96
- });
97
- };
98
- //# sourceMappingURL=unused-vite-dev-server.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unused-vite-dev-server.mjs","sourceRoot":"","sources":["../src/unused-vite-dev-server.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAI5B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAE9D,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,OAAgB,EAA+B,EAAE;IACpF,MAAM,OAAO,GAAG,MAAM,WAAW,EAAE,CAAA;IAEnC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IAEzB,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,CAAC;QAC1C,MAAM,EAAE;YACN,cAAc,EAAE,IAAI;YACpB,GAAG,EAAE;gBACH,IAAI,EAAE,OAAO;aACd;YACD,EAAE,EAAE;gBACF,+EAA+E;gBAC/E,KAAK,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;aAC7C;SACF;QACD,OAAO,EAAE;YACP,KAAK,EAAE;gBACL,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC;aACjD;SACF;QACD,OAAO,EAAE,KAAK;QACd,YAAY,EAAE;YACZ,oEAAoE;YACpE,OAAO,EAAE,CAAC,sBAAsB,CAAC;SAClC;QACD,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,sBAAsB;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C,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE;YACpB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;YAEhC,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;gBACzB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;YACnC,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAA;YACpE,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,wDAAwD;QACxD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACzB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,110 +0,0 @@
1
- import * as http from 'node:http'
2
- import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
-
5
- import * as Vite from 'vite'
6
-
7
- import type { Options } from './types.js'
8
-
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
-
11
- export const makeViteServer = async (options: Options): Promise<Vite.ViteDevServer> => {
12
- const hmrPort = await getFreePort()
13
-
14
- const cwd = process.cwd()
15
-
16
- const defaultViteConfig = Vite.defineConfig({
17
- server: {
18
- middlewareMode: true,
19
- hmr: {
20
- port: hmrPort,
21
- },
22
- fs: {
23
- // Adds `node_modules` so we can import `@livestore/wa-sqlite` for WASM to work
24
- allow: [path.resolve(__dirname, '..', '..')],
25
- },
26
- },
27
- resolve: {
28
- alias: {
29
- '@schema': path.resolve(cwd, options.schemaPath),
30
- },
31
- },
32
- appType: 'spa',
33
- optimizeDeps: {
34
- // TODO remove once fixed https://github.com/vitejs/vite/issues/8427
35
- exclude: ['@livestore/wa-sqlite'],
36
- },
37
- root: __dirname,
38
- base: '/livestore-devtools/',
39
- plugins: [virtualHtmlPlugin],
40
- })
41
-
42
- const viteConfig = options.viteConfig?.(defaultViteConfig) ?? defaultViteConfig
43
-
44
- const viteServer = Vite.createServer(viteConfig)
45
-
46
- return viteServer
47
- }
48
-
49
- const virtualHtmlPlugin: Vite.Plugin = {
50
- name: 'virtual-html',
51
- configureServer: (server) => {
52
- return () => {
53
- server.middlewares.use(async (req, res, next) => {
54
- if (req.url === '/' || req.url === '' || req.url === '/index.html') {
55
- const html = `
56
- <!doctype html>
57
- <html lang="en">
58
- <head>
59
- <meta charset="UTF-8" />
60
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
61
- <meta name="livestore-devtools" content="true" />
62
- <title>LiveStore Devtools</title>
63
- </head>
64
- <body>
65
- <div id="root"></div>
66
- <script type="module">
67
- import '@livestore/devtools-react/index.css'
68
- import { mountDevtools } from '@livestore/devtools-react'
69
- import sharedWorker from '@livestore/web/shared-worker?sharedworker'
70
- import { schema } from '@schema'
71
-
72
- mountDevtools({ schema, rootEl: document.getElementById('root'), sharedWorker, mode: 'expo' })
73
- </script>
74
- </body>
75
- </html>
76
- `
77
- const transformedHtml = await server.transformIndexHtml(req.url, html)
78
- res.statusCode = 200
79
- res.setHeader('Content-Type', 'text/html')
80
- res.end(transformedHtml)
81
- } else {
82
- next()
83
- }
84
- })
85
- }
86
- },
87
- }
88
-
89
- const getFreePort = (): Promise<number> => {
90
- return new Promise((resolve, reject) => {
91
- const server = http.createServer()
92
-
93
- // Listen on port 0 to get an available port
94
- server.listen(0, () => {
95
- const address = server.address()
96
-
97
- if (address && typeof address === 'object') {
98
- const port = address.port
99
- server.close(() => resolve(port))
100
- } else {
101
- server.close(() => reject(new Error('Failed to get a free port')))
102
- }
103
- })
104
-
105
- // Error handling in case the server encounters an error
106
- server.on('error', (err) => {
107
- server.close(() => reject(err))
108
- })
109
- })
110
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
- "verbatimModuleSyntax": true,
7
- "tsBuildInfoFile": "./dist/.tsbuildinfo"
8
- },
9
- "include": ["./src", "src/types.d.ts"],
10
- "references": [
11
- { "path": "../web" },
12
- { "path": "../node" }
13
- ]
14
- }