olum-compiler 0.8.5 → 0.8.6

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/bin/copySrc.js CHANGED
@@ -2,14 +2,9 @@
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
4
  const { copy, remove, routerParamsParser, ls, generateRouteManifest, generateImports, generateRoutes } = require("../lib/helpers");
5
+ const entryPoint = path.resolve(process.cwd(), "src").replace(/\/module/, "");
6
+ const entryPoint2 = path.resolve(process.cwd(), "public").replace(/\/module/, "");
5
7
 
6
-
7
- // for testing
8
- // const entryPoint = path.resolve(__dirname, "../../src");
9
- // const entryPoint2 = path.resolve(__dirname, "../../public");
10
- // for production
11
- const entryPoint = path.resolve(process.cwd(), "src");
12
- const entryPoint2 = path.resolve(process.cwd(), "public");
13
8
  module.exports = function copySrc() {
14
9
  return new Promise((resolve, reject) => {
15
10
  try {
@@ -38,8 +33,8 @@ module.exports = function copySrc() {
38
33
  const manifest = generateRouteManifest(routes, entryPoint);
39
34
  let has404Page = false;
40
35
  if (manifest['not-found']) has404Page = true;
41
- const libImports = `import Olum from "/node_modules/olum/dist/olum.js";\nimport Router from "/node_modules/olum-router/dist/router.js";`; // for production
42
- // const libImports = `import Olum from "../core/app.js";\nimport Router from "../core/router.js";`; // for testing
36
+ const libImports = `import Olum from "/node_modules/olum/dist/olum.js";\nimport Router from "/node_modules/olum-router/dist/router.js";`;
37
+ // const libImports = `import Olum from "../core/olum.js";\nimport Router from "../core/router.js";`; // for testing
43
38
  const imports = generateImports(manifest).replace(/.html/g, ".js"); // fix extension by replacing .html with .js since components are js modules
44
39
  const config = `const config = { mode: "history", root: "/", ${has404Page? `err: "/404",` : "" } routes: routes };\nconst router = new Router(config);\nnew Olum().$("#app").use(router);`;
45
40
  routes = generateRoutes(manifest);
package/bin/dev.js CHANGED
@@ -16,7 +16,12 @@ serve(entryPoint).then(({ server, wsPort, PORT, log, setWsPort }) => {
16
16
  server.on("error", (e) => { if (e.code === "EADDRINUSE") server.listen(++PORT); });
17
17
  server.listen(PORT, () => console.log(log.replace(/:\d+/, ":" + PORT)));
18
18
 
19
+ // Listen for adds, edits and deletes. Editors that save atomically
20
+ // (temp file + rename) surface edits as unlink+add rather than change,
21
+ // so watching only "change" misses new files and many edits.
22
+ watch.on("add", handleChange);
19
23
  watch.on("change", handleChange);
24
+ watch.on("unlink", handleChange);
20
25
 
21
26
  (function startWs(port) {
22
27
  const wss = new WebSocket.Server({ port });
package/bin/watcher.js CHANGED
@@ -1,7 +1,17 @@
1
1
  const chokidar = require("chokidar");
2
2
  const path = require("path");
3
- const entryPoint = path.resolve(__dirname, "../../src");
4
- const entryPoint2 = path.resolve(__dirname, "../../public");
3
+ // Resolve against the project root (process.cwd()), same as copySrc.js.
4
+ // The old "../../src" pointed at node_modules/src, which doesn't exist, so
5
+ // chokidar watched 0 directories and never detected any changes.
6
+ const entryPoint = path.resolve(process.cwd(), "src").replace(/\/module/, "");
7
+ const entryPoint2 = path.resolve(process.cwd(), "public").replace(/\/module/, "");
5
8
  // let ignoreRegex = /\_\.js$/;
6
9
  // module.exports = chokidar.watch(entryPoint, {ignored: ignoreRegex, persistent: true });
7
- module.exports = chokidar.watch([entryPoint, entryPoint2], { persistent: true });
10
+ // ignoreInitial: don't fire "add" for every existing file on startup (initial
11
+ // compile is handled separately in dev.js). awaitWriteFinish: coalesce the
12
+ // temp-file/rename churn from atomic saves into a single event.
13
+ module.exports = chokidar.watch([entryPoint, entryPoint2], {
14
+ persistent: true,
15
+ ignoreInitial: true,
16
+ awaitWriteFinish: { stabilityThreshold: 150, pollInterval: 50 },
17
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {