@tileflow/vite 0.1.0-alpha.14 → 0.1.0-alpha.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/README.md CHANGED
@@ -3,13 +3,23 @@
3
3
  Vite plugin for local Tileflow style development and static build artifacts.
4
4
 
5
5
  ```ts
6
- import react from "@vitejs/plugin-react";
7
- import { tileflow } from "@tileflow/vite";
8
- import { defineConfig } from "vite";
6
+ import react from '@vitejs/plugin-react';
7
+ import {defineConfig} from 'vite';
8
+ import {tileflow} from '@tileflow/vite';
9
9
 
10
10
  export default defineConfig({
11
11
  plugins: [react(), tileflow()],
12
12
  });
13
13
  ```
14
14
 
15
+ The Vite process is the only application server needed. It watches config, transitive imports, and
16
+ local icons, serves the Tileflow manifest/styles/sprites, and reloads from the latest valid
17
+ generation. To capture an application scene, keep `vite` running and point the short-lived headless
18
+ command at that same loopback origin; do not start `tileflow dev`:
19
+
20
+ ```sh
21
+ npm run dev
22
+ TILEFLOW_APP_ORIGIN=http://127.0.0.1:5173 npm exec --no -- tileflow capture app-desktop
23
+ ```
24
+
15
25
  Docs: https://tileflow.dev/docs
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
3
  type TileflowVitePluginOptions = {
4
+ apiBaseUrl?: string;
4
5
  base?: string;
5
6
  config?: string;
6
7
  emitBuildArtifacts?: boolean;
7
- tileBaseUrl?: string;
8
8
  };
9
9
  declare function tileflow(options?: TileflowVitePluginOptions): Plugin;
10
10
 
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  // src/index.ts
2
2
  import { resolve } from "path";
3
3
  import {
4
+ createTileflowArtifactSession,
4
5
  createTileflowBuildArtifacts,
5
6
  createTileflowDevRequestHandler,
6
7
  createTileflowNodeRequest,
7
8
  defaultTileflowConfigPath,
8
9
  getTileflowAssetBasePath,
9
10
  getTileflowAssetFileName,
10
- getTileflowWatchPaths,
11
11
  isTileflowRequestUrl,
12
12
  joinTileflowPublicUrl,
13
13
  normalizeTileflowBasePath,
@@ -26,22 +26,36 @@ function tileflow(options = {}) {
26
26
  const root = server.config.root;
27
27
  const configFile = resolve(root, configPath);
28
28
  const watchedIconPaths = /* @__PURE__ */ new Set();
29
- const handler = createTileflowDevRequestHandler({
30
- basePath,
29
+ const sessionPromise = createTileflowArtifactSession({
30
+ assetBaseUrl: basePath,
31
31
  config: configPath,
32
32
  cwd: root,
33
- onError(error) {
34
- const message = error instanceof Error ? error.message : "Unknown Tileflow error";
35
- server.config.logger.error(`[tileflow] ${message}`);
36
- },
37
- tileBaseUrl: options.tileBaseUrl
33
+ styleBaseUrl: basePath,
34
+ apiBaseUrl: options.apiBaseUrl,
35
+ watch: false
36
+ });
37
+ const handlerPromise = sessionPromise.then((session) => {
38
+ session.subscribe((state) => {
39
+ if (state.status === "ready" && state.generation > 1) {
40
+ server.ws.send({ type: "full-reload" });
41
+ }
42
+ });
43
+ return createTileflowDevRequestHandler({
44
+ basePath,
45
+ config: configPath,
46
+ cwd: root,
47
+ onError(error) {
48
+ const message = error instanceof Error ? error.message : "Unknown Tileflow error";
49
+ server.config.logger.error(`[tileflow] ${message}`);
50
+ },
51
+ session,
52
+ apiBaseUrl: options.apiBaseUrl
53
+ });
38
54
  });
39
55
  const refreshWatchedIconPaths = async () => {
40
56
  try {
41
- const watchPaths = await getTileflowWatchPaths({
42
- config: configPath,
43
- cwd: root
44
- });
57
+ const session = await sessionPromise;
58
+ const watchPaths = session.getLastGoodArtifacts()?.watchPaths ?? [];
45
59
  for (const watchPath of watchPaths) {
46
60
  if (!watchedIconPaths.has(watchPath)) {
47
61
  server.watcher.add(watchPath);
@@ -54,20 +68,20 @@ function tileflow(options = {}) {
54
68
  }
55
69
  };
56
70
  const reloadIfTileflowInput = (file) => {
57
- if (file === configFile) {
58
- void refreshWatchedIconPaths();
59
- server.ws.send({ type: "full-reload" });
60
- return;
61
- }
62
- if (isWatchedIconPath(file, watchedIconPaths)) {
63
- server.ws.send({ type: "full-reload" });
64
- }
71
+ if (!isTileflowInputPath(file, root, configFile, watchedIconPaths)) return;
72
+ void sessionPromise.then(async (session) => {
73
+ await session.refresh("vite watcher");
74
+ await refreshWatchedIconPaths();
75
+ });
65
76
  };
66
77
  server.watcher.add(configFile);
67
78
  void refreshWatchedIconPaths();
68
79
  server.watcher.on("add", reloadIfTileflowInput);
69
80
  server.watcher.on("change", reloadIfTileflowInput);
70
81
  server.watcher.on("unlink", reloadIfTileflowInput);
82
+ server.httpServer?.once("close", () => {
83
+ void sessionPromise.then((session) => session.close());
84
+ });
71
85
  server.middlewares.use(async (request, response, next) => {
72
86
  if (!isTileflowRequestUrl(request.url, basePath)) {
73
87
  next();
@@ -75,7 +89,7 @@ function tileflow(options = {}) {
75
89
  }
76
90
  try {
77
91
  const tileflowRequest = createTileflowNodeRequest(request);
78
- const tileflowResponse = await handler(tileflowRequest);
92
+ const tileflowResponse = await (await handlerPromise)(tileflowRequest);
79
93
  await writeTileflowNodeResponse(response, tileflowResponse);
80
94
  } catch (error) {
81
95
  next(error);
@@ -95,7 +109,7 @@ function tileflow(options = {}) {
95
109
  config: configPath,
96
110
  cwd: config.root,
97
111
  styleBaseUrl: joinTileflowPublicUrl(config.base, basePath),
98
- tileBaseUrl: options.tileBaseUrl
112
+ apiBaseUrl: options.apiBaseUrl
99
113
  });
100
114
  const assetBase = getTileflowAssetBasePath(basePath);
101
115
  this.emitFile({
@@ -133,6 +147,18 @@ function isWatchedIconPath(file, watchedIconPaths) {
133
147
  }
134
148
  return false;
135
149
  }
150
+ function isTileflowInputPath(file, root, configFile, watchedIconPaths) {
151
+ if (file === configFile || isWatchedIconPath(file, watchedIconPaths)) return true;
152
+ const normalizedFile = normalizePath(file);
153
+ const normalizedRoot = normalizePath(root).replace(/\/+$/, "");
154
+ if (!normalizedFile.startsWith(`${normalizedRoot}/`)) return false;
155
+ if (/\/(?:node_modules|\.git|\.tileflow|dist|build|coverage|\.next|\.cache|\.turbo)\//.test(
156
+ normalizedFile
157
+ )) {
158
+ return false;
159
+ }
160
+ return /\.(?:cjs|cts|js|json|mjs|mts|ts|tsx)$/.test(normalizedFile);
161
+ }
136
162
  function normalizePath(value) {
137
163
  return value.replace(/\\/g, "/");
138
164
  }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@tileflow/vite",
3
- "version": "0.1.0-alpha.14",
3
+ "version": "0.1.0-alpha.17",
4
4
  "description": "Vite plugin for Tileflow map style development and static artifacts.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "homepage": "https://tileflow.dev",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/tileflow/tileflow.git",
10
+ "url": "git+https://github.com/tileflow/tileflow-sdk.git",
11
11
  "directory": "packages/vite"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/tileflow/tileflow/issues"
14
+ "url": "https://github.com/tileflow/tileflow-sdk/issues"
15
15
  },
16
16
  "keywords": [
17
17
  "tileflow",
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@tileflow/dev": "0.1.0-alpha.14"
39
+ "@tileflow/dev": ">=0.1.0-alpha.18 <0.1.0-beta.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "vite": ">=5"