evolit 0.1.0-alpha.19 → 0.1.0-alpha.20

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/package.json +1 -1
  2. package/src/server.js +39 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evolit",
3
- "version": "0.1.0-alpha.19",
3
+ "version": "0.1.0-alpha.20",
4
4
  "description": "A convention-driven application framework for LitSX and web components.",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@4.10.3",
package/src/server.js CHANGED
@@ -5,7 +5,7 @@ import path from "node:path";
5
5
  import { WebSocketServer, WebSocket } from "ws";
6
6
  import { loadEvolitConfig } from "./config.js";
7
7
  import { createDeploymentRuntime } from "./deployment-runtime.js";
8
- import { APP_DIRECTORY, BUILD_DIRECTORY, INTERNAL_DIRECTORY, MANIFEST_FILENAME } from "./constants.js";
8
+ import { BUILD_DIRECTORY, INTERNAL_DIRECTORY, MANIFEST_FILENAME } from "./constants.js";
9
9
  import { normalizeClientAssetManifest } from "./client-assets.js";
10
10
  import { pathExists, readJson } from "./fs-utils.js";
11
11
  import { createDefaultRouteCacheKey, resolveResponseCacheRuntime } from "./response-cache.js";
@@ -67,22 +67,26 @@ function createLiveReloadSnippet() {
67
67
  return `<script data-evolit-live-reload>const evolitProtocol=window.location.protocol==="https:"?"wss:":"ws:";const evolitSocket=new WebSocket(evolitProtocol+"//"+window.location.host+${JSON.stringify(LIVE_RELOAD_PATHNAME)});evolitSocket.addEventListener("message",({data})=>{if(data==="reload")window.location.reload()});</script>`;
68
68
  }
69
69
 
70
- async function createRecursiveDirectoryWatcher(rootDirectory, onChange) {
70
+ async function createRecursiveDirectoryWatcher(rootDirectory, onChange, options = {}) {
71
71
  const watchers = new Map();
72
+ const shouldIgnorePath = options.shouldIgnorePath ?? (() => false);
72
73
  let closed = false;
73
74
 
74
75
  async function watchDirectory(directory) {
75
- if (closed || watchers.has(directory)) {
76
+ if (closed || watchers.has(directory) || shouldIgnorePath(directory)) {
76
77
  return;
77
78
  }
78
79
 
79
80
  let watcher;
80
81
  try {
81
82
  watcher = watch(directory, (eventType, fileName) => {
82
- onChange(fileName ? path.join(directory, String(fileName)) : null);
83
+ const changedPath = fileName ? path.join(directory, String(fileName)) : null;
84
+ if (!changedPath || !shouldIgnorePath(changedPath)) {
85
+ onChange(changedPath);
86
+ }
83
87
 
84
- if (eventType === "rename" && fileName) {
85
- void watchNewDirectory(path.join(directory, fileName));
88
+ if (eventType === "rename" && changedPath && !shouldIgnorePath(changedPath)) {
89
+ void watchNewDirectory(changedPath);
86
90
  }
87
91
  });
88
92
  } catch (error) {
@@ -114,6 +118,10 @@ async function createRecursiveDirectoryWatcher(rootDirectory, onChange) {
114
118
  }
115
119
 
116
120
  async function watchNewDirectory(candidate) {
121
+ if (shouldIgnorePath(candidate)) {
122
+ return;
123
+ }
124
+
117
125
  try {
118
126
  const stat = await fs.stat(candidate);
119
127
  if (stat.isDirectory()) {
@@ -139,6 +147,29 @@ async function createRecursiveDirectoryWatcher(rootDirectory, onChange) {
139
147
  };
140
148
  }
141
149
 
150
+ function createProjectWatchIgnorePath(projectRoot) {
151
+ const ignoredDirectoryNames = new Set([
152
+ "node_modules",
153
+ INTERNAL_DIRECTORY,
154
+ ".git",
155
+ ]);
156
+
157
+ return (candidate) => {
158
+ const relativePath = path.relative(projectRoot, candidate);
159
+ if (
160
+ relativePath === ".."
161
+ || relativePath.startsWith(`..${path.sep}`)
162
+ || path.isAbsolute(relativePath)
163
+ ) {
164
+ return true;
165
+ }
166
+
167
+ return relativePath
168
+ .split(path.sep)
169
+ .some((segment) => ignoredDirectoryNames.has(segment));
170
+ };
171
+ }
172
+
142
173
  async function createServer(projectRoot, mode, explicitPort, options = {}) {
143
174
  const reportDevelopmentEvent = mode === "development"
144
175
  ? options.onDevelopmentEvent ?? createDevelopmentEventReporter()
@@ -215,8 +246,9 @@ async function createServer(projectRoot, mode, explicitPort, options = {}) {
215
246
 
216
247
  const watcher = mode === "development"
217
248
  ? await createRecursiveDirectoryWatcher(
218
- path.join(projectRoot, APP_DIRECTORY),
249
+ projectRoot,
219
250
  scheduleDevelopmentInvalidation,
251
+ { shouldIgnorePath: createProjectWatchIgnorePath(projectRoot) },
220
252
  )
221
253
  : null;
222
254