kireji 0.3.0 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kireji",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A web framework for stateful, entropy-perfect, multi-origin web applications. Currently in alpha. Expect breaking changes for version 0. Use with caution!",
5
5
  "files": [
6
6
  "src/",
package/src/build.js CHANGED
@@ -7,17 +7,18 @@ function ƒ(_, compressedSubjectOrigins) {
7
7
  Object.defineProperty(_, "$", { value: (f => x => f(x).toString().trim())(require("child_process").execSync) }),
8
8
  _.command = process.argv[2] || "help",
9
9
  _.local = _.command === "dev" ? "1" : "0",
10
- require.main === module && (
10
+ require.main === module ? (
11
11
  _.branch = _.$("git rev-parse --abbrev-ref HEAD").toString().trim(),
12
12
  _.gitSHA = _.$("git rev-parse HEAD").toString().trim(),
13
13
  _.version = (([M, m, p], c) => +_.local ? +M && c === "major" ? `${++M}.0.0` : c === "minor" || (!+M && c === "major") ? `${M}.${++m}.0` : `${M}.${m}.${++p}` : `${M}.${m}.${p}`)(_.$("git log -1 --pretty=%s").toString().match(/^\s*(\d+\.\d+\.\d+)/)[1].split("."), _.change),
14
14
  _.modified = _.$('git show -s --format=%ci HEAD').toString().trim(),
15
15
  _.ETag = `"${_.version}.${_.gitSHA.slice(0, 7)}${+_.local ? ("." + Math.random()).slice(2, 10) : ""}"`,
16
- _.name = __dirname.split(/[\\/]/).filter(Boolean).at(-4)
17
- ),
18
- "node"
16
+ _.name = __dirname.split(/[\\/]/).filter(Boolean).at(-4),
17
+ "node-main"
18
+ ) :
19
+ "node-module"
19
20
  ),
20
- production = _.branch === "main" && environment !== "node" && !(+_.local),
21
+ production = _.branch === "main" && (environment === "client" || environment === "worker") && !(+_.local),
21
22
  welcomeMessage = `
22
23
  ▌ ▘ ▘▘ ${_.name}
23
24
  k = ▙▘▌▛▘█▌ ▌▌ ${_.branch}
@@ -63,7 +64,7 @@ function ƒ(_, compressedSubjectOrigins) {
63
64
  }], "table")
64
65
  },
65
66
  logServerScope = (col1, col2, col3, callback) => {
66
- return logScope(0, `\n${("" + col1).padEnd(22, " ")} ${(environment === "node" ? Math.trunc(process.memoryUsage().rss / 1024 / 1024) + " MiB" : "--").padEnd(8, " ")} ${("" + col2).padStart(24, " ")} ${col3}`, log => callback((col1, col2, col3) => log(`${("" + col1).padEnd(20, " ")} ${(environment === "node" ? Math.trunc(process.memoryUsage().rss / 1024 / 1024) + " MiB" : "--").padEnd(8, " ")} ${("" + col2).padStart(24, " ")} ${col3}`)))
67
+ return logScope(0, `\n${("" + col1).padEnd(22, " ")} ${(environment.startsWith("node") ? Math.trunc(process.memoryUsage().rss / 1024 / 1024) + " MiB" : "--").padEnd(8, " ")} ${("" + col2).padStart(24, " ")} ${col3}`, log => callback((col1, col2, col3) => log(`${("" + col1).padEnd(20, " ")} ${(environment.startsWith("node") ? Math.trunc(process.memoryUsage().rss / 1024 / 1024) + " MiB" : "--").padEnd(8, " ")} ${("" + col2).padStart(24, " ")} ${col3}`)))
67
68
  }
68
69
 
69
70
  // String and Stringification Utilities
@@ -240,7 +241,7 @@ function ƒ(_, compressedSubjectOrigins) {
240
241
  subjectIndices = new Map(),
241
242
  subjectOrigins = new Map()
242
243
 
243
- if (environment === "node" && require.main === module) {
244
+ if (environment === "node-main") {
244
245
  subjectOrigins.set("", true)
245
246
 
246
247
  const
@@ -719,7 +720,7 @@ function ƒ(_, compressedSubjectOrigins) {
719
720
  return part
720
721
  },
721
722
  hydrateSubjectOrigins = () => {
722
- if (environment === "node") {
723
+ if (environment === "node-main") {
723
724
  const bits = allSubjects.map(([host, fn]) => +subjectOrigins.get(host + (fn ? "/" + fn : "")))
724
725
  const bitString = bits.join("")
725
726
  compressedSubjectOrigins = encodeSegment(BigInt("0b" + bitString))
package/src/part.html_.js CHANGED
@@ -50,8 +50,8 @@ const nonImageStyles = `<style id="user-css">${_["part.css"]}</style>` +
50
50
  `<style id="application-css">${application["part.css"]}</style>`
51
51
 
52
52
  const styles = nonImageStyles +
53
- `<style id="img-css">${environment === "node" ? "" : _["images.css"]}</style>` +
54
- (environment === "node" ? `<style id="early-img-css">${_.getImagesEarly(bodyHTML, nonImageStyles)}</style>` : "")
53
+ `<style id="img-css">${environment.startsWith("node") ? "" : _["images.css"]}</style>` +
54
+ (environment.startsWith("node") ? `<style id="early-img-css">${_.getImagesEarly(bodyHTML, nonImageStyles)}</style>` : "")
55
55
 
56
56
  const headHTML =
57
57
  `<head>${title}${meta}${links}${styles}</head>`
@@ -1,3 +1,3 @@
1
1
  Ecosystem Facets are subparts which undergo a special installation step, depending on the deployment environment.
2
2
 
3
- A facet can only be installed on a proper subset of the three environments (node server, service worker, and client). The ecosystem only accepts requests and user interaction after all applicable facets have been installed.
3
+ A facet can only be installed on a proper subset of the four environments (node main, node module, service worker, and client). The ecosystem only accepts requests and user interaction after all applicable facets have been installed.
@@ -1,5 +1,5 @@
1
1
  This server-only facet uses node-specific functionality to create an HTTP server on the designated port. It allows the ecosystem to server-render a snapshot of its GUI as a single HTML document with inlined CSS and JavaScript. This acts as a bootstrap which fetches and installs the ecosystem as a service worker and then hydrates the snapshot.
2
2
 
3
- When it is deployed as the main node module (and not imported by another module) it gathers information about other version deployments and can serve them by importing them as modules.
3
+ When the environment is "node-main" (and not "node-module"), it gathers information about other version deployments and can serve them by importing them as modules.
4
4
 
5
5
  It provides http-to-https redirects, ensures that the "www." subdomain is removed, redirects from canonical URLs, provides version information for the update manager, and redirects certain canonical paths (like "/") to the appropriate versioned and stateful counterpart.
@@ -1 +1,2 @@
1
- node
1
+ node-main
2
+ node-module
@@ -83,7 +83,7 @@ const
83
83
 
84
84
  module.exports = currentExports
85
85
 
86
- if (require.main !== module) {
86
+ if (environment === "node-module") {
87
87
  logScope(0, "Server Ready - Proxy Module")
88
88
  return
89
89
  }
package/src/type.d.ts CHANGED
@@ -135,10 +135,14 @@ class SourceMappedFile {
135
135
  getMap(): string
136
136
  }
137
137
  /** A string representing which of three known environments the framework is running on.
138
- * 1. "node"
138
+ * 1. "node-main"
139
139
  * - Unpacked in a clone of the project git repo in node.
140
140
  * - It's called by `npx kireji` in order to perform operations like pack the repo into a single client artifact and run as a backend to serve that artifact and to server-render HTML.
141
- * - It's state (when it runs as a server) is set by http requests at the designated port.
141
+ * - Its state (when it runs as a server) is set by http requests at the designated port.
142
+ * 2. "node-module"
143
+ * - Packed and archived, loaded in as a module via `require` by the main node module.
144
+ * - It acts as a proxy for a previous version of the project, when matching versioned URLs are fetched.
145
+ * - Its state is set by proxy requests passed through by the main node module.
142
146
  * 3. "worker"
143
147
  * - Packed and deployed as the browser's ServiceWorker.
144
148
  * - It's booted by the browser after a client registers it.
@@ -147,7 +151,7 @@ class SourceMappedFile {
147
151
  * - Packed and deployed as a front-end framework hydrating a browser tab.
148
152
  * - It's booted by a script tag added to the server- or worker-rendered html file.
149
153
  * - Its state is initially set by `location.href` (whatever is in the address bar) and then set by user interaction thereafter. */
150
- declare const environment: "node" | "worker" | "client"
154
+ declare const environment: "client" | "worker" | "node-main" | "node-module"
151
155
  /** True if the framework was built on the cloud from the main branch. */
152
156
  declare const production: boolean
153
157
  /** A unicode-safe replacement for btoa. */
package/src/validate.js CHANGED
@@ -1,4 +1,4 @@
1
- if (environment === "node" && require.main === module) {
1
+ if (environment === "node-main") {
2
2
  logScope(1, "Routing Test", log => {
3
3
  // logScope(3, "Uninitialized Model", log => log(serialize(_.model)))
4
4
  const testURL = `https://${_.defaultApplicationHost}/${_.version}/${_.landingHash}/`