olum-compiler 2.1.1 → 2.1.4

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
@@ -6,4 +6,75 @@
6
6
  </p>
7
7
 
8
8
  # Olum-Compiler
9
- See [Documentation](https://olumjs.top/docs)
9
+ A module for compiling/bundling Olumjs projects.
10
+
11
+ See [Documentation](https://olumjs.top/docs)
12
+
13
+ ## Contributing
14
+ Thanks for wanting to help make Olum-Compiler better! 💙 Bug fixes, new features, and docs improvements are all welcome.
15
+
16
+ ### The branch rule (important)
17
+ Olum-Compiler uses **one branch per version** (`v2.1.0`, `v2.1.1`, ...). Each new version branch is created from the previous one, so the **latest version branch always contains everything**.
18
+
19
+ > ✅ Always base your work on the **latest** version branch (currently **`v2.1.3`**).
20
+ > ❌ Never base it on an older one like `v2.1.0` — your PR will be missing recent changes and will conflict.
21
+
22
+ Not sure which one is the latest? Check the branch list on GitHub (or run `git branch -r`) and pick the highest version number.
23
+
24
+ ### Step by step
25
+ 1. **Fork** the repo and clone your fork:
26
+ ```bash
27
+ git clone https://github.com/<your-username>/olum-compiler.git
28
+ cd olum-compiler
29
+ ```
30
+ 2. **Check out the latest version branch** (replace `v2.1.3` with the newest one):
31
+ ```bash
32
+ git fetch origin
33
+ git checkout v2.1.3
34
+ ```
35
+ 3. **Create your own branch from it** — a copy of the latest version with your changes on top:
36
+ ```bash
37
+ git checkout -b feat/my-awesome-feature
38
+ # or: git checkout -b fix/describe-the-bug
39
+ ```
40
+ 4. **Install dependencies:**
41
+ ```bash
42
+ npm install
43
+ ```
44
+ 5. **Make your change.** Source lives in `lib/` and the CLI entry in `bin/`. Keep the change focused: one feature or fix per PR.
45
+ 6. **Run the tests** and add or update them in `tests/` when behavior changes:
46
+ ```bash
47
+ npm test
48
+ ```
49
+ 7. **Update the docs** if your change affects user-facing behavior (see below).
50
+ 8. **Commit** using a clear message, following the existing style:
51
+ ```
52
+ feat: support alias in import statements
53
+ fix: hmr goes into infinite loop if multiple apps running at the same time
54
+ ```
55
+ 9. **Push** your branch to your fork:
56
+ ```bash
57
+ git push origin feat/my-awesome-feature
58
+ ```
59
+ 10. **Open a Pull Request** against the **latest version branch** (e.g. `v2.1.3`) — *not* `v2.1.0` or an older version. Describe what changed, why, and include a small example if it's user-facing.
60
+
61
+ ### Docs are part of the change
62
+ User-facing documentation lives on [olumjs.top/docs](https://olumjs.top/docs). If your PR changes behavior or adds a feature, mention in the PR description what the docs need so they can be updated alongside it. No docs change needed? Just say so (e.g. internal refactor).
63
+
64
+ ### PR checklist
65
+ - [ ] Branched from the **latest** version branch (not an older one)
66
+ - [ ] PR targets the latest version branch
67
+ - [ ] `npm test` passes
68
+ - [ ] Docs impact noted in the PR description
69
+ - [ ] One focused change, clear commit messages
70
+
71
+ Questions or unsure about an idea? Ask in [Discord](https://discord.gg/2zK7tb2Cg9) before you start — we're happy to help.
72
+
73
+ ## Community
74
+ - [X](https://x.com/olumjs)
75
+ - [Bluesky](https://bsky.app/profile/olumjs.bsky.social)
76
+ - [Discord](https://discord.gg/2zK7tb2Cg9)
77
+
78
+ ## Contact
79
+ - General: [hello@olumjs.top](mailto:hello@olumjs.top)
80
+ - Security: [security@olumjs.top](mailto:security@olumjs.top) — please report vulnerabilities here privately rather than opening a public issue
package/bin/build.js CHANGED
@@ -4,6 +4,38 @@ const bundle = require("./bundle");
4
4
  const compile = require("./compiler");
5
5
  const copySrc = require("./copySrc");
6
6
  const ssg = require("./ssg");
7
+ const colors = require("../lib/colors");
8
+
9
+ const lockFile = path.resolve(__dirname, "../.dev.lock");
10
+ const devPid = (() => {
11
+ try {
12
+ return Number(fs.readFileSync(lockFile, "utf8").trim());
13
+ } catch (e) {
14
+ return 0;
15
+ }
16
+ })();
17
+ const devAlive = (() => {
18
+ try {
19
+ return !!devPid && !!process.kill(devPid, 0);
20
+ } catch (e) {
21
+ return e.code === "EPERM";
22
+ }
23
+ })();
24
+ if (devAlive) {
25
+ console.error(
26
+ colors(
27
+ "red",
28
+ `A dev server is running (pid ${devPid}) — refusing to build.`,
29
+ ),
30
+ );
31
+ console.error(
32
+ colors(
33
+ "white",
34
+ `The build would overwrite the files it serves and break the page in the browser.\nStop the dev server first, then build. # or delete ${lockFile} if that process is gone`,
35
+ ),
36
+ );
37
+ process.exit(1);
38
+ }
7
39
 
8
40
  (async function () {
9
41
  const bootAt = Date.now();
package/bin/bundle.js CHANGED
@@ -3,6 +3,21 @@ const fs = require("fs");
3
3
  const colors = require("../lib/colors");
4
4
  const spawn = require("../lib/cross-spawn");
5
5
  const { useLocalCore, localLibs, optionalLibs } = require("../lib/coreLibs");
6
+ const env = require("../lib/env");
7
+
8
+ function envDefine() {
9
+ const vars = env.load();
10
+ const runtime = "globalThis.process.env";
11
+ const define = {
12
+ "process.env": runtime,
13
+ "global.process.env": runtime,
14
+ "globalThis.process.env": runtime,
15
+ };
16
+ for (const key of Object.keys(vars))
17
+ if (/^[A-Za-z_$][\w$]*$/.test(key))
18
+ define[`process.env.${key}`] = JSON.stringify(vars[key]);
19
+ return define;
20
+ }
6
21
 
7
22
  const cwd = process.cwd();
8
23
  const public = path.resolve(__dirname, "../public");
@@ -153,7 +168,7 @@ async function bundle(bootAt) {
153
168
  resolve: { alias },
154
169
  plugins: base === "/" ? [] : [staticUrlPlugin(base)],
155
170
 
156
- define: { "globalThis.__OLUM_DEV__": "false" },
171
+ define: { "globalThis.__OLUM_DEV__": "false", ...envDefine() },
157
172
  build: {
158
173
  outDir,
159
174
  emptyOutDir: true,
package/bin/copySrc.js CHANGED
@@ -5,6 +5,7 @@ const importMap = require("../lib/importMap");
5
5
  const usage = require("../lib/usage");
6
6
  const splitJsBarrels = require("../lib/jsBarrels");
7
7
  const resolveAliases = require("../lib/alias");
8
+ const env = require("../lib/env");
8
9
 
9
10
  const cwd = process.cwd();
10
11
  const projectRoot = cwd.replace(/\/module$/, "");
@@ -37,6 +38,11 @@ function injectIndexHtml(indexHtmlPath) {
37
38
  process.env.NODE_ENV === "production"
38
39
  ? ""
39
40
  : `<script>globalThis.__OLUM_DEV__ = true;</script>\n`;
41
+
42
+ indexHtmlContent = indexHtmlContent.replace(
43
+ /<head[^>]*>/i,
44
+ (tag) => `${tag}\n${env.scriptTag()}`,
45
+ );
40
46
  indexHtmlContent = indexHtmlContent.replace(
41
47
  /<\/body>/,
42
48
  `\n<div id="olum-app"></div>\n${devFlagTag}${importMapTag}<script defer type="module" src="../src/main.js"></script>\n${devtoolScriptContent}</body>`,
package/bin/dev.js CHANGED
@@ -50,7 +50,7 @@ process.on("exit", () => read() === me && fs.rmSync(lockFile, { force: true }));
50
50
  process.on(signal, () => process.exit(0)),
51
51
  );
52
52
 
53
- serve(entryPoint).then(({ server, wsPort, PORT, log, setWsPort }) => {
53
+ serve(entryPoint).then(({ server, PORT, log }) => {
54
54
  const bootAt = Date.now();
55
55
  copySrc()
56
56
  .then(() => {
@@ -70,17 +70,14 @@ serve(entryPoint).then(({ server, wsPort, PORT, log, setWsPort }) => {
70
70
  );
71
71
  require("../lib/compiler");
72
72
 
73
- (function startWs(port) {
74
- const wss = new WebSocket.Server({ server });
75
- sockets = wss.clients;
76
- wss.on("listening", () => setWsPort(port));
77
- wss.on("error", (e) => {
78
- if (e.code === "EADDRINUSE") startWs(port + 1);
79
- });
80
- wss.on("connection", (ws) =>
81
- ws.send(JSON.stringify({ msg: "connected" })),
82
- );
83
- })(wsPort);
73
+ const wss = new WebSocket.Server({ server });
74
+ sockets = wss.clients;
75
+ wss.on("error", (e) => {
76
+ if (e.code !== "EADDRINUSE") console.error(e);
77
+ });
78
+ wss.on("connection", (ws) =>
79
+ ws.send(JSON.stringify({ msg: "connected" })),
80
+ );
84
81
  });
85
82
  })
86
83
  .catch(console.error);
package/bin/server.js CHANGED
@@ -6,11 +6,9 @@ const { parseDOM } = require("../lib/dom");
6
6
  const colors = require("../lib/colors");
7
7
  const mimes = require("./mimes.json");
8
8
  const sitemapPath = path.resolve(__dirname, "../src/sitemap.js");
9
- let wsPort = 8090;
10
9
 
11
10
  function handleWsFile() {
12
11
  let file = fs.readFileSync(path.resolve(__dirname, "./ws.js")).toString();
13
-
14
12
  file = "<script>" + file + "</script>";
15
13
  return file;
16
14
  }
@@ -159,16 +157,7 @@ function serve(entry, port, mode = "development") {
159
157
  }
160
158
  const log = colors("cyan", "Serving ") + colors("green", "port " + PORT);
161
159
 
162
- const setWsPort = (port) => {
163
- wsPort = port;
164
- };
165
- resolve({
166
- server: server,
167
- wsPort: wsPort,
168
- PORT: PORT,
169
- log: log,
170
- setWsPort: setWsPort,
171
- });
160
+ resolve({ server: server, PORT: PORT, log: log });
172
161
  });
173
162
  }
174
163
 
package/lib/changes.txt CHANGED
@@ -1 +0,0 @@
1
- change /home/eissapk/olum/template-compiler/src/match/[slug]/page.html
package/lib/env.js ADDED
@@ -0,0 +1,48 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const projectRoot = process.cwd().replace(/\/module$/, "");
5
+
6
+ function files() {
7
+ const mode =
8
+ process.env.NODE_ENV === "production" ? "production" : "development";
9
+ return [".env", `.env.${mode}`].map((name) => path.join(projectRoot, name));
10
+ }
11
+
12
+ function parse(src) {
13
+ const vars = {};
14
+ src.split(/\r?\n/).forEach((line) => {
15
+ const m = line.match(/^\s*(?:export\s+)?([\w.-]+)\s*=\s*(.*)?\s*$/);
16
+ if (!m) return;
17
+ let value = (m[2] || "").trim();
18
+ const quote = value[0];
19
+ if (
20
+ (quote === '"' || quote === "'" || quote === "`") &&
21
+ value.lastIndexOf(quote) > 0
22
+ ) {
23
+ value = value.slice(1, value.lastIndexOf(quote));
24
+ if (quote === '"') value = value.replace(/\\n/g, "\n");
25
+ } else {
26
+ value = value.replace(/\s+#.*$/, "");
27
+ }
28
+ vars[m[1]] = value;
29
+ });
30
+ return vars;
31
+ }
32
+
33
+ function load() {
34
+ return files().reduce(
35
+ (vars, file) =>
36
+ fs.existsSync(file)
37
+ ? Object.assign(vars, parse(fs.readFileSync(file, "utf8")))
38
+ : vars,
39
+ {},
40
+ );
41
+ }
42
+
43
+ function scriptTag() {
44
+ const json = JSON.stringify(load()).replace(/</g, "\\u003c");
45
+ return `<script>window.process = window.process || {}; process.env = Object.assign(process.env || {}, ${json});</script>`;
46
+ }
47
+
48
+ module.exports = { load, parse, scriptTag, files };
package/lib/websocket.js CHANGED
@@ -290,6 +290,8 @@ class WebSocketServer extends EventEmitter {
290
290
  }
291
291
 
292
292
  handleUpgrade(req, socket, head, callback) {
293
+ if (socket.__olumUpgraded) return;
294
+ socket.__olumUpgraded = true;
293
295
  socket.on("error", () => socket.destroy());
294
296
 
295
297
  const key = req.headers["sec-websocket-key"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "2.1.1",
3
+ "version": "2.1.4",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {