@tileflow/vite 0.1.0-alpha.7 → 0.1.0-alpha.8

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 (2) hide show
  1. package/dist/index.js +54 -5
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  // src/index.ts
2
+ import { resolve } from "path";
2
3
  import {
3
4
  createTileflowBuildArtifacts,
4
5
  createTileflowDevRequestHandler,
5
6
  defaultTileflowConfigPath,
7
+ getTileflowWatchPaths,
6
8
  normalizeTileflowBasePath
7
9
  } from "@tileflow/dev";
8
- import { resolve } from "path";
9
10
  function tileflow(options = {}) {
10
11
  const basePath = normalizeTileflowBasePath(options.base ?? "/tileflow");
11
12
  const configPath = options.config ?? defaultTileflowConfigPath;
@@ -18,6 +19,7 @@ function tileflow(options = {}) {
18
19
  configureServer(server) {
19
20
  const root = server.config.root;
20
21
  const configFile = resolve(root, configPath);
22
+ const watchedIconPaths = /* @__PURE__ */ new Set();
21
23
  const handler = createTileflowDevRequestHandler({
22
24
  basePath,
23
25
  config: configPath,
@@ -28,12 +30,38 @@ function tileflow(options = {}) {
28
30
  },
29
31
  tileBaseUrl: options.tileBaseUrl
30
32
  });
31
- server.watcher.add(configFile);
32
- server.watcher.on("change", (file) => {
33
+ const refreshWatchedIconPaths = async () => {
34
+ try {
35
+ const watchPaths = await getTileflowWatchPaths({
36
+ config: configPath,
37
+ cwd: root
38
+ });
39
+ for (const watchPath of watchPaths) {
40
+ if (!watchedIconPaths.has(watchPath)) {
41
+ server.watcher.add(watchPath);
42
+ watchedIconPaths.add(watchPath);
43
+ }
44
+ }
45
+ } catch (error) {
46
+ const message = error instanceof Error ? error.message : "Unknown Tileflow error";
47
+ server.config.logger.warn(`[tileflow] Unable to watch icon paths: ${message}`);
48
+ }
49
+ };
50
+ const reloadIfTileflowInput = (file) => {
33
51
  if (file === configFile) {
52
+ void refreshWatchedIconPaths();
34
53
  server.ws.send({ type: "full-reload" });
54
+ return;
35
55
  }
36
- });
56
+ if (isWatchedIconPath(file, watchedIconPaths)) {
57
+ server.ws.send({ type: "full-reload" });
58
+ }
59
+ };
60
+ server.watcher.add(configFile);
61
+ void refreshWatchedIconPaths();
62
+ server.watcher.on("add", reloadIfTileflowInput);
63
+ server.watcher.on("change", reloadIfTileflowInput);
64
+ server.watcher.on("unlink", reloadIfTileflowInput);
37
65
  server.middlewares.use(async (request, response, next) => {
38
66
  if (!isTileflowRequest(request.url, basePath)) {
39
67
  next();
@@ -57,6 +85,7 @@ function tileflow(options = {}) {
57
85
  return;
58
86
  }
59
87
  const artifacts = await createTileflowBuildArtifacts({
88
+ assetBaseUrl: joinPublicUrl(config.base, basePath),
60
89
  config: configPath,
61
90
  cwd: config.root,
62
91
  styleBaseUrl: joinPublicUrl(config.base, basePath),
@@ -77,6 +106,13 @@ function tileflow(options = {}) {
77
106
  type: "asset"
78
107
  });
79
108
  }
109
+ for (const asset of artifacts.assets) {
110
+ this.emitFile({
111
+ fileName: assetFileName(assetBase, asset.fileName),
112
+ source: asset.source,
113
+ type: "asset"
114
+ });
115
+ }
80
116
  }
81
117
  };
82
118
  }
@@ -84,10 +120,23 @@ var index_default = tileflow;
84
120
  function isTileflowRequest(url, basePath) {
85
121
  const pathname = (url ?? "/").split("?")[0] ?? "/";
86
122
  if (!basePath) {
87
- return pathname === "/manifest.json" || pathname === "/style.json" || pathname === "/" || pathname.startsWith("/styles/");
123
+ return pathname === "/manifest.json" || pathname === "/style.json" || pathname === "/" || pathname.startsWith("/icons/") || pathname.startsWith("/styles/");
88
124
  }
89
125
  return pathname === basePath || pathname.startsWith(`${basePath}/`);
90
126
  }
127
+ function isWatchedIconPath(file, watchedIconPaths) {
128
+ const normalizedFile = normalizePath(file);
129
+ for (const watchPath of watchedIconPaths) {
130
+ const normalizedWatchPath = normalizePath(watchPath);
131
+ if (normalizedFile === normalizedWatchPath || normalizedFile.startsWith(`${normalizedWatchPath}/`)) {
132
+ return true;
133
+ }
134
+ }
135
+ return false;
136
+ }
137
+ function normalizePath(value) {
138
+ return value.replace(/\\/g, "/");
139
+ }
91
140
  function toWebRequest(request) {
92
141
  const protocol = getHeader(request, "x-forwarded-proto") ?? "http";
93
142
  const host = getHeader(request, "host") ?? "localhost";
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@tileflow/vite",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "Vite plugin for Tileflow map style development and static artifacts.",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "homepage": "https://tileflow.dev",
7
8
  "repository": {
8
9
  "type": "git",
@@ -35,7 +36,7 @@
35
36
  "access": "public"
36
37
  },
37
38
  "dependencies": {
38
- "@tileflow/dev": "0.1.0-alpha.7"
39
+ "@tileflow/dev": "0.1.0-alpha.8"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "vite": ">=5"