olum-compiler 1.5.0 → 1.6.0
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/.claude/settings.local.json +2 -1
- package/bin/build.js +1 -1
- package/bin/bundle.js +32 -30
- package/bin/compiler.js +20 -10
- package/bin/copySrc.js +45 -41
- package/bin/dev.js +46 -39
- package/bin/index.js +6 -4
- package/bin/server.js +58 -33
- package/bin/watcher.js +11 -14
- package/bin/ws.js +16 -11
- package/lib/attr.js +1 -25
- package/lib/boolAttr.js +32 -15
- package/lib/chokidar.js +52 -101
- package/lib/colors.js +1 -7
- package/lib/compPlaceholder.js +5 -3
- package/lib/compiler.js +3 -6
- package/lib/coreLibs.js +1 -10
- package/lib/cross-spawn.js +45 -59
- package/lib/cssParser.js +61 -37
- package/lib/domEvents.js +6 -2
- package/lib/events.js +75 -77
- package/lib/for.js +56 -28
- package/lib/getImports.js +35 -17
- package/lib/getTempPath.js +8 -4
- package/lib/helpers.js +289 -184
- package/lib/html.js +3 -10
- package/lib/htmlParser.js +45 -45
- package/lib/if.js +40 -20
- package/lib/importMap.js +49 -24
- package/lib/jsParser.js +8 -13
- package/lib/lineCounter.js +18 -5
- package/lib/liveProps.js +124 -78
- package/lib/log.js +30 -0
- package/lib/magic-string.js +45 -52
- package/lib/models.js +8 -7
- package/lib/parser.js +76 -44
- package/lib/placeholder.js +73 -58
- package/lib/regex.js +4 -3
- package/lib/show.js +16 -8
- package/lib/sourcemap.js +23 -24
- package/lib/styles.js +7 -13
- package/lib/textarea.js +3 -6
- package/lib/toJs.js +1 -1
- package/lib/tokens.js +10 -22
- package/lib/transition.js +86 -0
- package/lib/websocket.js +68 -62
- package/package.json +1 -1
- package/tests/compiler.test.js +423 -188
package/bin/ws.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
if ("WebSocket" in window) {
|
|
3
|
-
const parse = str => str.replace(/>/g, ">").replace(/</g, "<");
|
|
3
|
+
const parse = (str) => str.replace(/>/g, ">").replace(/</g, "<");
|
|
4
4
|
const interval = 500;
|
|
5
5
|
const maxAttempts = 30;
|
|
6
6
|
let attempts = 0;
|
|
7
7
|
const wsProtocol = location.protocol === "https:" ? "wss:" : "ws:";
|
|
8
|
-
|
|
9
|
-
const socketUrl = `${wsProtocol}//${location.host}`;
|
|
8
|
+
|
|
9
|
+
const socketUrl = `${wsProtocol}//${location.host}`;
|
|
10
10
|
let socket = new WebSocket(socketUrl);
|
|
11
11
|
|
|
12
12
|
socket.onmessage = function (res) {
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
const stderr = obj.data.trim();
|
|
19
19
|
const arr = stderr.split("<<Olum Warning>>");
|
|
20
20
|
const markup = arr
|
|
21
|
-
.map(item => {
|
|
22
|
-
if (item.trim() !== "")
|
|
21
|
+
.map((item) => {
|
|
22
|
+
if (item.trim() !== "")
|
|
23
|
+
return `<pre style="border-bottom: 1px solid #ccc; padding-bottom:10px;">${parse(item)}</pre>`;
|
|
23
24
|
})
|
|
24
25
|
.join("");
|
|
25
26
|
document.body.innerHTML = markup;
|
|
@@ -30,27 +31,31 @@
|
|
|
30
31
|
let key = "IS_FIRST_TIME_OLUM_HOT_RELOAD";
|
|
31
32
|
if (sessionStorage && !sessionStorage.getItem(key)) {
|
|
32
33
|
sessionStorage.setItem(key, true);
|
|
33
|
-
|
|
34
|
-
// else console.log("Olum hot-reload enabled.");
|
|
34
|
+
|
|
35
35
|
console.log("Olum hot-reload enabled.");
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function css() {
|
|
40
40
|
const sheets = document.querySelectorAll("link[rel='stylesheet']");
|
|
41
|
-
sheets.forEach(sheet => sheet.replaceWith(sheet));
|
|
41
|
+
sheets.forEach((sheet) => sheet.replaceWith(sheet));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
socket.addEventListener("close", () => {
|
|
45
45
|
const reloadIfCanConnect = () => {
|
|
46
46
|
attempts++;
|
|
47
|
-
if (attempts > maxAttempts)
|
|
47
|
+
if (attempts > maxAttempts)
|
|
48
|
+
return console.error("Could not reconnect to dev server.");
|
|
48
49
|
socket = new WebSocket(socketUrl);
|
|
49
|
-
socket.addEventListener("error", () =>
|
|
50
|
+
socket.addEventListener("error", () =>
|
|
51
|
+
setTimeout(reloadIfCanConnect, interval),
|
|
52
|
+
);
|
|
50
53
|
};
|
|
51
54
|
reloadIfCanConnect();
|
|
52
55
|
});
|
|
53
56
|
} else {
|
|
54
|
-
console.error(
|
|
57
|
+
console.error(
|
|
58
|
+
"Upgrade your browser. This Browser is doesn't support WebSocket for Live-Reloading.",
|
|
59
|
+
);
|
|
55
60
|
}
|
|
56
61
|
})();
|
package/lib/attr.js
CHANGED
|
@@ -3,36 +3,12 @@ const path = require("path");
|
|
|
3
3
|
|
|
4
4
|
function handleAttr(body, counter, filePath) {
|
|
5
5
|
let name = path.basename(filePath).replace(/\.html/i, "");
|
|
6
|
-
name = name.slice(0, 1).toLowerCase() + name.slice(1);
|
|
6
|
+
name = name.slice(0, 1).toLowerCase() + name.slice(1);
|
|
7
7
|
|
|
8
8
|
const elms = new Array().slice.call(body.querySelectorAll("*"));
|
|
9
9
|
elms.forEach((item) => {
|
|
10
10
|
const attrs = item.getAttributeNames();
|
|
11
11
|
if (attrs.length) {
|
|
12
|
-
// DISABLED — {identifier} shorthand (<img {src} /> → src="{src}"). Naked braces aren't allowed
|
|
13
|
-
// in attribute position anymore (values live in ""); write src="{src}" instead. Uncomment to re-enable.
|
|
14
|
-
// attrs.filter(attr => /^\{\w+\}$/.test(attr)).forEach(attr => {
|
|
15
|
-
// const attrName = attr.slice(1, -1);
|
|
16
|
-
// item.removeAttribute(attr);
|
|
17
|
-
// item.setAttribute(attrName, "{" + attrName + "}");
|
|
18
|
-
// });
|
|
19
|
-
|
|
20
|
-
// DISABLED — :attr dynamic binding (:src="expr"). Colon attributes are gone; regular
|
|
21
|
-
// attributes are literal strings with {expr} interpolation inside. Uncomment to re-enable.
|
|
22
|
-
// const dynamicAttrs = attrs.filter((attr) => attr.startsWith(":"));
|
|
23
|
-
// if (dynamicAttrs.length) {
|
|
24
|
-
// dynamicAttrs.forEach((attrName) => {
|
|
25
|
-
// let attrValue = item.getAttribute(attrName);
|
|
26
|
-
// if (attrValue) {
|
|
27
|
-
// attrName = attrName.trim().slice(1);
|
|
28
|
-
// attrValue = attrValue.trim();
|
|
29
|
-
// let chain = "-[[-${JSON.parse(JSON.stringify(" + attrValue + "))}-]]-";
|
|
30
|
-
// chain = chain.replace(/{/g, "<-olum->"); // using <-olum-> (<-olum->) as placeholder for "{"
|
|
31
|
-
// item.setAttribute(attrName, chain);
|
|
32
|
-
// item.removeAttribute(":"+attrName);
|
|
33
|
-
// }
|
|
34
|
-
// });
|
|
35
|
-
// }
|
|
36
12
|
}
|
|
37
13
|
});
|
|
38
14
|
}
|
package/lib/boolAttr.js
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
const { RAW_OPEN, RAW_CLOSE } = require("./tokens");
|
|
2
2
|
|
|
3
|
-
// Boolean attributes are truthy by PRESENCE: the browser treats checked="false" as checked and
|
|
4
|
-
// disabled="false" as disabled. So value interpolation (checked="${olum.esc(expr)}") can never
|
|
5
|
-
// turn them off. For these attributes, attr="{expr}" compiles to a conditional that emits the
|
|
6
|
-
// bare attribute name or nothing at all: ${(expr) ? "checked" : ""}.
|
|
7
|
-
//
|
|
8
|
-
// Runs on the serialized markup string, BEFORE the generic {expr} escape pass (which would
|
|
9
|
-
// otherwise claim these braces) and emitted with RAW sentinels so the code is not esc-wrapped.
|
|
10
|
-
// Only fires when the ENTIRE value is a single {expr}; mixed values (checked="a {b}") are
|
|
11
|
-
// meaningless for boolean attributes and fall through to the generic pass. Component props are
|
|
12
|
-
// already packed into data-o-props by placeholder() and can't match here.
|
|
13
3
|
const BOOL_ATTRS = [
|
|
14
|
-
"checked",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
4
|
+
"checked",
|
|
5
|
+
"disabled",
|
|
6
|
+
"selected",
|
|
7
|
+
"readonly",
|
|
8
|
+
"required",
|
|
9
|
+
"hidden",
|
|
10
|
+
"autofocus",
|
|
11
|
+
"multiple",
|
|
12
|
+
"open",
|
|
13
|
+
"loop",
|
|
14
|
+
"muted",
|
|
15
|
+
"controls",
|
|
16
|
+
"autoplay",
|
|
17
|
+
"novalidate",
|
|
18
|
+
"default",
|
|
19
|
+
"defer",
|
|
20
|
+
"ismap",
|
|
21
|
+
"reversed",
|
|
17
22
|
];
|
|
18
23
|
|
|
19
|
-
const boolAttrRegex = new RegExp(
|
|
24
|
+
const boolAttrRegex = new RegExp(
|
|
25
|
+
"(\\s)(" + BOOL_ATTRS.join("|") + ")=([\"'])\\{([^{}]+)\\}\\3",
|
|
26
|
+
"gi",
|
|
27
|
+
);
|
|
20
28
|
|
|
21
29
|
function handleBoolAttrs(content) {
|
|
22
30
|
return content.replace(boolAttrRegex, (match, ws, name, quote, expr) => {
|
|
23
|
-
return
|
|
31
|
+
return (
|
|
32
|
+
ws +
|
|
33
|
+
RAW_OPEN +
|
|
34
|
+
"(" +
|
|
35
|
+
expr.trim() +
|
|
36
|
+
') ? "' +
|
|
37
|
+
name.toLowerCase() +
|
|
38
|
+
'" : ""' +
|
|
39
|
+
RAW_CLOSE
|
|
40
|
+
);
|
|
24
41
|
});
|
|
25
42
|
}
|
|
26
43
|
|
package/lib/chokidar.js
CHANGED
|
@@ -1,77 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* chokidar.js — standalone single-file recursive file watcher
|
|
3
|
-
* Minimal replacement for the `chokidar` package, using only node built-ins
|
|
4
|
-
* (fs, path, events). Cross-platform: instead of fs.watch's `recursive` flag
|
|
5
|
-
* (whose support and event detail differ per OS), every directory gets its own
|
|
6
|
-
* non-recursive fs.watch and events trigger a rescan-and-diff of that
|
|
7
|
-
* directory against a stat snapshot — so add/change/unlink detection behaves
|
|
8
|
-
* identically on Linux, macOS and Windows.
|
|
9
|
-
*
|
|
10
|
-
* Covered (same API shape as chokidar@5.0.0):
|
|
11
|
-
* const chokidar = require("./chokidar");
|
|
12
|
-
* const watcher = chokidar.watch(paths, {
|
|
13
|
-
* persistent: true, // keep the process alive (default true)
|
|
14
|
-
* ignoreInitial: false, // suppress add/addDir for the initial scan
|
|
15
|
-
* ignored: regex|fn|array, // paths to skip entirely
|
|
16
|
-
* awaitWriteFinish: { stabilityThreshold, pollIntervall } | true,
|
|
17
|
-
* });
|
|
18
|
-
* watcher.on("add" | "change" | "unlink" | "addDir" | "unlinkDir" | "ready" | "error", ...)
|
|
19
|
-
* watcher.close();
|
|
20
|
-
*
|
|
21
|
-
* Watched roots that don't exist yet (or get deleted) are polled for and
|
|
22
|
-
* picked up when they appear, like chokidar does.
|
|
23
|
-
*
|
|
24
|
-
* KNOWN LIMITATIONS vs the real chokidar (future maintenance):
|
|
25
|
-
*
|
|
26
|
-
* 1. No `usePolling` fallback — NFS / Docker / VM compatibility.
|
|
27
|
-
* fs.watch relies on OS change events (inotify on Linux, FSEvents/kqueue on
|
|
28
|
-
* macOS, ReadDirectoryChangesW on Windows). On filesystems that don't
|
|
29
|
-
* propagate those events — NFS mounts, Docker bind-mounted volumes with a
|
|
30
|
-
* macOS/Windows host, some VM shared folders (VirtualBox vboxsf, older
|
|
31
|
-
* Vagrant/WSL1 setups) — the watcher goes silent: no errors, just no
|
|
32
|
-
* events. Real chokidar covers this with `usePolling: true` (fs.watchFile
|
|
33
|
-
* stat polling). If dev-inside-Docker/NFS ever becomes a use case, add a
|
|
34
|
-
* polling mode here: replace fs.watch per directory with a setInterval
|
|
35
|
-
* that calls _rescan(dir) (the diffing logic already works unchanged);
|
|
36
|
-
* only _watchDir needs the branch.
|
|
37
|
-
*
|
|
38
|
-
* 2. Whole-directory rescan per event burst.
|
|
39
|
-
* On any event we readdir+stat the affected directory instead of stat-ing
|
|
40
|
-
* just the named file like chokidar. Identical behavior, negligible cost
|
|
41
|
-
* for source trees (measured: 305-dir Next.js project ready in ~41ms,
|
|
42
|
-
* 1000-file burst handled 1:1 with chokidar@5), but a single flat
|
|
43
|
-
* directory with tens of thousands of entries would rescan slowly. If that
|
|
44
|
-
* happens, use the filename argument from fs.watch's callback to stat only
|
|
45
|
-
* that entry, falling back to a full rescan when it's null.
|
|
46
|
-
*
|
|
47
|
-
* 3. Linux inotify limits apply (as they do to chokidar).
|
|
48
|
-
* One watch descriptor per directory, capped by
|
|
49
|
-
* /proc/sys/fs/inotify/max_user_watches (typically 8k–128k). Always pass
|
|
50
|
-
* `ignored` for node_modules/.git/build-output dirs on big repos.
|
|
51
|
-
*
|
|
52
|
-
* 4. Not implemented (unused by this project): add()/unwatch()/getWatched(),
|
|
53
|
-
* depth, cwd, alwaysStat, atomic, followSymlinks:false (symlinked dirs are
|
|
54
|
-
* watched, with realpath-based cycle protection), and sub-mtime-resolution
|
|
55
|
-
* edge: a rewrite with identical size landing in the same mtime tick is
|
|
56
|
-
* undetectable by stat diffing (theoretical on ext4/APFS/NTFS — ns mtime).
|
|
57
|
-
*/
|
|
58
1
|
"use strict";
|
|
59
2
|
|
|
60
3
|
const fs = require("fs");
|
|
61
4
|
const path = require("path");
|
|
62
5
|
const { EventEmitter } = require("events");
|
|
63
6
|
|
|
64
|
-
const SCAN_DEBOUNCE = 25;
|
|
65
|
-
const ROOT_POLL = 1000;
|
|
7
|
+
const SCAN_DEBOUNCE = 25;
|
|
8
|
+
const ROOT_POLL = 1000;
|
|
66
9
|
|
|
67
10
|
function normalizeIgnored(ignored) {
|
|
68
11
|
if (!ignored) return () => false;
|
|
69
12
|
const list = Array.isArray(ignored) ? ignored : [ignored];
|
|
70
|
-
return p =>
|
|
71
|
-
list.some(entry => {
|
|
13
|
+
return (p) =>
|
|
14
|
+
list.some((entry) => {
|
|
72
15
|
if (typeof entry === "function") return entry(p);
|
|
73
16
|
if (entry instanceof RegExp) return entry.test(p);
|
|
74
|
-
return p === entry || p.startsWith(entry + path.sep);
|
|
17
|
+
return p === entry || p.startsWith(entry + path.sep);
|
|
75
18
|
});
|
|
76
19
|
}
|
|
77
20
|
|
|
@@ -84,17 +27,24 @@ class FSWatcher extends EventEmitter {
|
|
|
84
27
|
this._ignored = normalizeIgnored(options.ignored);
|
|
85
28
|
|
|
86
29
|
const awf = options.awaitWriteFinish;
|
|
87
|
-
|
|
88
|
-
this._awf = awf
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
|
|
30
|
+
|
|
31
|
+
this._awf = awf
|
|
32
|
+
? {
|
|
33
|
+
threshold: awf.stabilityThreshold || 2000,
|
|
34
|
+
poll: awf.pollInterval || 100,
|
|
35
|
+
}
|
|
36
|
+
: null;
|
|
37
|
+
|
|
38
|
+
this._roots = (Array.isArray(paths) ? paths : [paths]).map((p) =>
|
|
39
|
+
path.resolve(p),
|
|
40
|
+
);
|
|
41
|
+
this._watchers = new Map();
|
|
42
|
+
this._snapshots = new Map();
|
|
43
|
+
this._scanTimers = new Map();
|
|
44
|
+
this._pending = new Map();
|
|
45
|
+
this._rootTimers = new Map();
|
|
46
|
+
this._realPaths = new Set();
|
|
47
|
+
this._realByDir = new Map();
|
|
98
48
|
this._closed = false;
|
|
99
49
|
|
|
100
50
|
process.nextTick(() => {
|
|
@@ -104,7 +54,6 @@ class FSWatcher extends EventEmitter {
|
|
|
104
54
|
});
|
|
105
55
|
}
|
|
106
56
|
|
|
107
|
-
// ------------------------------------------------------------ setup
|
|
108
57
|
_addRoot(root, isInitial) {
|
|
109
58
|
let stat;
|
|
110
59
|
try {
|
|
@@ -114,12 +63,9 @@ class FSWatcher extends EventEmitter {
|
|
|
114
63
|
return;
|
|
115
64
|
}
|
|
116
65
|
if (stat.isDirectory()) {
|
|
117
|
-
// chokidar reports the watched root itself, subject to ignoreInitial
|
|
118
66
|
if (!(isInitial && this._ignoreInitial)) this.emit("addDir", root);
|
|
119
67
|
this._watchDir(root, isInitial);
|
|
120
|
-
}
|
|
121
|
-
// single-file roots: watch the parent dir but only report this file
|
|
122
|
-
else this._watchDir(path.dirname(root), isInitial, root);
|
|
68
|
+
} else this._watchDir(path.dirname(root), isInitial, root);
|
|
123
69
|
}
|
|
124
70
|
|
|
125
71
|
_waitForRoot(root) {
|
|
@@ -128,7 +74,7 @@ class FSWatcher extends EventEmitter {
|
|
|
128
74
|
if (fs.existsSync(root)) {
|
|
129
75
|
clearInterval(timer);
|
|
130
76
|
this._rootTimers.delete(root);
|
|
131
|
-
this._addRoot(root, false);
|
|
77
|
+
this._addRoot(root, false);
|
|
132
78
|
}
|
|
133
79
|
}, ROOT_POLL);
|
|
134
80
|
if (!this._persistent && timer.unref) timer.unref();
|
|
@@ -138,8 +84,6 @@ class FSWatcher extends EventEmitter {
|
|
|
138
84
|
_watchDir(dir, isInitial, onlyFile) {
|
|
139
85
|
if (this._closed || this._watchers.has(dir) || this._ignored(dir)) return;
|
|
140
86
|
|
|
141
|
-
// symlink-cycle guard: a link pointing back into the watched tree must not
|
|
142
|
-
// cause infinite recursion — track the real path of every watched dir
|
|
143
87
|
let real;
|
|
144
88
|
try {
|
|
145
89
|
real = fs.realpathSync(dir);
|
|
@@ -157,8 +101,7 @@ class FSWatcher extends EventEmitter {
|
|
|
157
101
|
this.emit("error", err);
|
|
158
102
|
return;
|
|
159
103
|
}
|
|
160
|
-
|
|
161
|
-
// fatal: the parent directory's rescan tears this watcher down
|
|
104
|
+
|
|
162
105
|
watcher.on("error", () => watcher.close());
|
|
163
106
|
watcher.on("change", () => this._scheduleScan(dir));
|
|
164
107
|
|
|
@@ -168,7 +111,6 @@ class FSWatcher extends EventEmitter {
|
|
|
168
111
|
this._rescan(dir, isInitial);
|
|
169
112
|
}
|
|
170
113
|
|
|
171
|
-
// ------------------------------------------------------------ scanning
|
|
172
114
|
_scheduleScan(dir) {
|
|
173
115
|
if (this._closed || this._scanTimers.has(dir)) return;
|
|
174
116
|
this._scanTimers.set(
|
|
@@ -176,7 +118,7 @@ class FSWatcher extends EventEmitter {
|
|
|
176
118
|
setTimeout(() => {
|
|
177
119
|
this._scanTimers.delete(dir);
|
|
178
120
|
this._rescan(dir, false);
|
|
179
|
-
}, SCAN_DEBOUNCE)
|
|
121
|
+
}, SCAN_DEBOUNCE),
|
|
180
122
|
);
|
|
181
123
|
}
|
|
182
124
|
|
|
@@ -187,7 +129,6 @@ class FSWatcher extends EventEmitter {
|
|
|
187
129
|
try {
|
|
188
130
|
names = fs.readdirSync(dir);
|
|
189
131
|
} catch (e) {
|
|
190
|
-
// directory itself vanished
|
|
191
132
|
this._teardownDir(dir, true);
|
|
192
133
|
if (this._roots.includes(dir)) this._waitForRoot(dir);
|
|
193
134
|
return;
|
|
@@ -204,10 +145,14 @@ class FSWatcher extends EventEmitter {
|
|
|
204
145
|
try {
|
|
205
146
|
stat = fs.statSync(full);
|
|
206
147
|
} catch (e) {
|
|
207
|
-
continue;
|
|
148
|
+
continue;
|
|
208
149
|
}
|
|
209
150
|
|
|
210
|
-
const entry = {
|
|
151
|
+
const entry = {
|
|
152
|
+
isDir: stat.isDirectory(),
|
|
153
|
+
mtimeMs: stat.mtimeMs,
|
|
154
|
+
size: stat.size,
|
|
155
|
+
};
|
|
211
156
|
next.set(name, entry);
|
|
212
157
|
|
|
213
158
|
const prev = old.get(name);
|
|
@@ -216,12 +161,11 @@ class FSWatcher extends EventEmitter {
|
|
|
216
161
|
if (!prev) {
|
|
217
162
|
if (entry.isDir) {
|
|
218
163
|
if (!silent) this.emit("addDir", full);
|
|
219
|
-
this._watchDir(full, isInitial);
|
|
164
|
+
this._watchDir(full, isInitial);
|
|
220
165
|
} else if (!silent) {
|
|
221
166
|
this._settle(full, "add");
|
|
222
167
|
}
|
|
223
168
|
} else if (prev.isDir !== entry.isDir) {
|
|
224
|
-
// replaced by the other kind: unlink the old, add the new
|
|
225
169
|
if (prev.isDir) this._teardownDir(full, true);
|
|
226
170
|
else this.emit("unlink", full);
|
|
227
171
|
if (entry.isDir) {
|
|
@@ -230,7 +174,10 @@ class FSWatcher extends EventEmitter {
|
|
|
230
174
|
} else {
|
|
231
175
|
this._settle(full, "add");
|
|
232
176
|
}
|
|
233
|
-
} else if (
|
|
177
|
+
} else if (
|
|
178
|
+
!entry.isDir &&
|
|
179
|
+
(prev.mtimeMs !== entry.mtimeMs || prev.size !== entry.size)
|
|
180
|
+
) {
|
|
234
181
|
this._settle(full, "change");
|
|
235
182
|
}
|
|
236
183
|
}
|
|
@@ -250,8 +197,7 @@ class FSWatcher extends EventEmitter {
|
|
|
250
197
|
if (pending) {
|
|
251
198
|
clearInterval(pending.timer);
|
|
252
199
|
this._pending.delete(file);
|
|
253
|
-
|
|
254
|
-
// reported, so there is nothing to unlink
|
|
200
|
+
|
|
255
201
|
if (pending.event === "add") return;
|
|
256
202
|
}
|
|
257
203
|
this.emit("unlink", file);
|
|
@@ -284,27 +230,30 @@ class FSWatcher extends EventEmitter {
|
|
|
284
230
|
if (emitEvents) this.emit("unlinkDir", dir);
|
|
285
231
|
}
|
|
286
232
|
|
|
287
|
-
// ------------------------------------------------- awaitWriteFinish
|
|
288
233
|
_settle(file, event) {
|
|
289
|
-
if (this._onlyFile && file !== this._onlyFile) return;
|
|
234
|
+
if (this._onlyFile && file !== this._onlyFile) return;
|
|
290
235
|
|
|
291
236
|
if (!this._awf) return this.emit(event, file);
|
|
292
237
|
|
|
293
|
-
// an event already stabilizing keeps its original type: more writes while
|
|
294
|
-
// an "add" settles must still surface as a single "add", not a "change"
|
|
295
238
|
const existing = this._pending.get(file);
|
|
296
239
|
if (existing) {
|
|
297
240
|
existing.stableSince = Date.now();
|
|
298
241
|
return;
|
|
299
242
|
}
|
|
300
243
|
|
|
301
|
-
const state = {
|
|
244
|
+
const state = {
|
|
245
|
+
event,
|
|
246
|
+
stableSince: Date.now(),
|
|
247
|
+
mtimeMs: -1,
|
|
248
|
+
size: -1,
|
|
249
|
+
timer: null,
|
|
250
|
+
};
|
|
302
251
|
state.timer = setInterval(() => {
|
|
303
252
|
let stat;
|
|
304
253
|
try {
|
|
305
254
|
stat = fs.statSync(file);
|
|
306
255
|
} catch (e) {
|
|
307
|
-
clearInterval(state.timer);
|
|
256
|
+
clearInterval(state.timer);
|
|
308
257
|
this._pending.delete(file);
|
|
309
258
|
return;
|
|
310
259
|
}
|
|
@@ -323,7 +272,6 @@ class FSWatcher extends EventEmitter {
|
|
|
323
272
|
this._pending.set(file, state);
|
|
324
273
|
}
|
|
325
274
|
|
|
326
|
-
// ------------------------------------------------------------ teardown
|
|
327
275
|
close() {
|
|
328
276
|
this._closed = true;
|
|
329
277
|
for (const watcher of this._watchers.values()) watcher.close();
|
|
@@ -341,4 +289,7 @@ class FSWatcher extends EventEmitter {
|
|
|
341
289
|
}
|
|
342
290
|
}
|
|
343
291
|
|
|
344
|
-
module.exports = {
|
|
292
|
+
module.exports = {
|
|
293
|
+
watch: (paths, options) => new FSWatcher(paths, options),
|
|
294
|
+
FSWatcher,
|
|
295
|
+
};
|
package/lib/colors.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// todo check how to convert colors.bgRed.white into colors("bgRed.white")
|
|
2
1
|
let map = {
|
|
3
2
|
reset: { start: "\x1B[0m", end: "\x1B[0m" },
|
|
4
3
|
bold: { start: "\x1B[1m", end: "\x1B[22m" },
|
|
@@ -64,9 +63,4 @@ function colors(props, text) {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
// console.log(colors("cyan", "Serving"), colors("green", "localhost"));
|
|
69
|
-
// console.log(colors("red", "err"));
|
|
70
|
-
// console.log(colors("yellow.bold", "<<Olum Warning>>"));
|
|
71
|
-
// console.log(colors("yellow", "File"));
|
|
72
|
-
module.exports = colors;
|
|
66
|
+
module.exports = colors;
|
package/lib/compPlaceholder.js
CHANGED
|
@@ -2,9 +2,11 @@ const { getLineInfo } = require("./lineCounter");
|
|
|
2
2
|
|
|
3
3
|
function handleCompPlaceholder(body, counter, filePath) {
|
|
4
4
|
const comps = new Array().slice.call(body.querySelectorAll("olum"));
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
return comps
|
|
6
|
+
.map((comp) => {
|
|
7
|
+
if (comp.hasAttribute("name")) return comp.getAttribute("name");
|
|
8
|
+
})
|
|
9
|
+
.filter((item) => item);
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
module.exports = handleCompPlaceholder;
|
package/lib/compiler.js
CHANGED
|
@@ -4,23 +4,20 @@ const parser = require("./parser");
|
|
|
4
4
|
const { lineCounter } = require("./lineCounter");
|
|
5
5
|
const { compExt } = require("./regex");
|
|
6
6
|
|
|
7
|
-
// todo handle the component when it has these cases [null, only html, html + css, html+js, html+css+js, only css, only js]
|
|
8
7
|
function compileFile(filePath) {
|
|
9
|
-
// console.warn("final: ", filePath);
|
|
10
8
|
if (fs.existsSync(filePath)) {
|
|
11
9
|
const fileContent = fs.readFileSync(filePath).toString();
|
|
12
10
|
const counter = lineCounter(fileContent);
|
|
13
11
|
let parsedData = parser(fileContent, counter, filePath);
|
|
14
12
|
const newFilePath = filePath.replace(compExt, ".js");
|
|
15
|
-
|
|
13
|
+
|
|
16
14
|
fs.writeFileSync(newFilePath, parsedData);
|
|
17
|
-
|
|
15
|
+
|
|
18
16
|
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
|
-
module.exports = compileFile;
|
|
19
|
+
module.exports = compileFile;
|
|
22
20
|
|
|
23
|
-
// script mode (npm run build / full compile): compile one file (arg) or all
|
|
24
21
|
if (require.main === module) {
|
|
25
22
|
const pathsArr = process.argv[2] ? [process.argv[2]] : getTempPath();
|
|
26
23
|
pathsArr.forEach(compileFile);
|
package/lib/coreLibs.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
// true -> the local copies in module/core, served at /core by the dev server (framework development)
|
|
3
|
-
// false -> the published npm packages ("olum", "olum-router", "olum-store") installed at the project root
|
|
4
|
-
// both the generated main.js (helpers.js compileRoutes) and the import map (importMap.js)
|
|
5
|
-
// read this flag — they must agree, otherwise two runtime copies load and fight over window.olum
|
|
6
|
-
const useLocalCore = process?.env?.LOCAL_CORE == 'true';
|
|
1
|
+
const useLocalCore = process?.env?.LOCAL_CORE == "true";
|
|
7
2
|
|
|
8
|
-
// import-map entries for the local mode. "olum-store" must be listed even though no app file
|
|
9
|
-
// imports it directly: olum.js loads it via a bare dynamic import("olum-store"), which the
|
|
10
|
-
// importMap.js src scan never sees — without this entry the import rejects (silently) and
|
|
11
|
-
// store() throws "store is unavailable".
|
|
12
3
|
const localLibs = {
|
|
13
4
|
olum: "/core/olum.js",
|
|
14
5
|
"olum-router": "/core/router.js",
|