@weborigami/origami 0.6.5 → 0.6.7

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/index.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
- * Tree Origami is a JavaScript project, but we use TypeScript as an internal
3
- * tool to confirm our code is type safe.
2
+ * Origami is a JavaScript project, but we use TypeScript as an internal tool to
3
+ * confirm our code is type safe.
4
4
  */
5
5
 
6
+ // Re-export all exports from main.js
7
+ export * from "./main.js";
8
+
6
9
  /**
7
10
  * A class constructor is an object with a `new` method that returns an
8
11
  * instance of the indicated type.
package/main.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export { default as documentObject } from "./src/common/documentObject.js";
2
+ export * from "./src/common/serialize.js";
2
3
  export * as Dev from "./src/dev/dev.js";
4
+ export { default as initializeBuiltins } from "./src/initializeBuiltins.js";
3
5
  export * as Origami from "./src/origami/origami.js";
4
6
  export { default as origamiHighlightDefinition } from "./src/origami/origamiHighlightDefinition.js";
5
7
  export { default as constructResponse } from "./src/server/constructResponse.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "typescript": "5.9.3"
18
18
  },
19
19
  "dependencies": {
20
- "@weborigami/async-tree": "0.6.5",
20
+ "@weborigami/async-tree": "0.6.7",
21
21
  "@weborigami/json-feed-to-rss": "1.0.1",
22
- "@weborigami/language": "0.6.5",
22
+ "@weborigami/language": "0.6.7",
23
23
  "css-tree": "3.1.0",
24
24
  "graphviz-wasm": "3.0.2",
25
25
  "highlight.js": "11.11.1",
package/src/cli/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Tree } from "@weborigami/async-tree";
4
- import { formatError, projectRoot } from "@weborigami/language";
4
+ import { formatError, projectRootFromPath } from "@weborigami/language";
5
5
  import path from "node:path";
6
6
  import process, { stdout } from "node:process";
7
7
  import help from "../dev/help.js";
@@ -18,7 +18,8 @@ async function main(...args) {
18
18
  initializeBuiltins();
19
19
 
20
20
  // Find the project root.
21
- const projectTree = await projectRoot();
21
+ const currentDirectory = process.cwd();
22
+ const projectRoot = await projectRootFromPath(currentDirectory);
22
23
 
23
24
  // If no arguments were passed, show usage.
24
25
  if (!expression) {
@@ -28,9 +29,8 @@ async function main(...args) {
28
29
  }
29
30
 
30
31
  // Traverse from the project root to the current directory.
31
- const currentDirectory = process.cwd();
32
- const relative = path.relative(projectTree.path, currentDirectory);
33
- const parent = await Tree.traversePath(projectTree, relative);
32
+ const relative = path.relative(projectRoot.path, currentDirectory);
33
+ const parent = await Tree.traversePath(projectRoot, relative);
34
34
 
35
35
  const result = await ori(expression, { parent });
36
36
 
@@ -9,7 +9,13 @@ import sharp from "sharp";
9
9
  * @param {any} options
10
10
  */
11
11
  export default async function imageFormat(input, format, options) {
12
- return input instanceof Uint8Array || input instanceof ArrayBuffer
13
- ? sharp(input).toFormat(format, options).toBuffer()
14
- : undefined;
12
+ if (!(input instanceof Uint8Array || input instanceof ArrayBuffer)) {
13
+ return undefined;
14
+ }
15
+
16
+ const data = await sharp(input).toFormat(format, options).toBuffer();
17
+
18
+ // Sharp WASM library returns what appears to be a SharedArrayBuffer, which is
19
+ // not accepted in some contexts, so we convert it to a regular Uint8Array.
20
+ return new Uint8Array(data);
15
21
  }
@@ -7,7 +7,13 @@ import sharp from "sharp";
7
7
  * @param {import("sharp").ResizeOptions} options
8
8
  */
9
9
  export default async function resize(input, options) {
10
- return input instanceof Uint8Array || input instanceof ArrayBuffer
11
- ? sharp(input).rotate().resize(options).toBuffer()
12
- : undefined;
10
+ if (!(input instanceof Uint8Array || input instanceof ArrayBuffer)) {
11
+ return undefined;
12
+ }
13
+
14
+ const data = await sharp(input).rotate().resize(options).toBuffer();
15
+
16
+ // Sharp WASM library returns what appears to be a SharedArrayBuffer, which is
17
+ // not accepted in some contexts, so we convert it to a regular Uint8Array.
18
+ return new Uint8Array(data);
13
19
  }
@@ -4,8 +4,7 @@ import {
4
4
  isStringlike,
5
5
  toString,
6
6
  } from "@weborigami/async-tree";
7
- import { compile } from "@weborigami/language";
8
- import projectGlobals from "@weborigami/language/src/project/projectGlobals.js";
7
+ import { compile, projectGlobals } from "@weborigami/language";
9
8
  import { toYaml } from "../common/serialize.js";
10
9
  import * as dev from "../dev/dev.js";
11
10
 
@@ -1,16 +1,7 @@
1
1
  export { extension } from "@weborigami/async-tree";
2
2
  export { default as help } from "../dev/help.js"; // Alias
3
- export { default as document } from "../origami/document.js";
4
- // export { default as htmlDom } from "../origami/htmlDom.js";
5
- export { default as indexPage } from "../origami/indexPage.js";
6
- export { default as inline } from "../origami/inline.js";
7
- export { default as jsonKeys } from "../origami/jsonKeys.js";
8
- export { default as mdHtml } from "../origami/mdHtml.js";
9
- export { default as redirect } from "../origami/redirect.js";
10
- export { default as rss } from "../origami/rss.js";
11
- export { default as sitemap } from "../origami/sitemap.js";
12
- export { default as slug } from "../origami/slug.js";
13
- export { default as static } from "../origami/static.js";
3
+ export { default as document } from "./document.js";
4
+ // export { default as htmlDom } from "./htmlDom.js";
14
5
  export { default as basename } from "./basename.js";
15
6
  export { default as csv } from "./csv.js";
16
7
  export { default as fetch } from "./fetch.js";
@@ -18,8 +9,12 @@ export { default as htmlEscape } from "./htmlEscape.js";
18
9
  export { default as format } from "./image/format.js";
19
10
  export * as image from "./image/image.js";
20
11
  export { default as resize } from "./image/resize.js";
12
+ export { default as indexPage } from "./indexPage.js";
13
+ export { default as inline } from "./inline.js";
21
14
  export { default as json } from "./json.js";
15
+ export { default as jsonKeys } from "./jsonKeys.js";
22
16
  export { default as jsonParse } from "./jsonParse.js";
17
+ export { default as mdHtml } from "./mdHtml.js";
23
18
  export { default as mdOutline } from "./mdOutline.js";
24
19
  export { default as naturalOrder } from "./naturalOrder.js";
25
20
  export { default as once } from "./once.js";
@@ -27,9 +22,15 @@ export { default as ori } from "./ori.js";
27
22
  export { default as pack } from "./pack.js";
28
23
  export { default as post } from "./post.js";
29
24
  export { default as project } from "./project.js";
25
+ export { default as projectRoot } from "./projectRoot.js";
26
+ export { default as redirect } from "./redirect.js";
30
27
  export { default as repeat } from "./repeat.js";
28
+ export { default as rss } from "./rss.js";
31
29
  export { default as shell } from "./shell.js";
30
+ export { default as sitemap } from "./sitemap.js";
32
31
  export { default as slash } from "./slash.js";
32
+ export { default as slug } from "./slug.js";
33
+ export { default as static } from "./static.js";
33
34
  export { default as string } from "./string.js";
34
35
  export { default as tsv } from "./tsv.js";
35
36
  export { default as unpack } from "./unpack.js";
@@ -1,3 +1,6 @@
1
1
  import { projectRoot } from "@weborigami/language";
2
2
 
3
- export default projectRoot;
3
+ export default async function project() {
4
+ console.warn("Origami.project has been renamed to Origami.projectRoot");
5
+ return projectRoot();
6
+ }
@@ -0,0 +1,3 @@
1
+ import { projectRoot } from "@weborigami/language";
2
+
3
+ export default projectRoot;
@@ -28,7 +28,7 @@ export default async function constructResponse(request, resource) {
28
28
  }
29
29
 
30
30
  // Determine media type, what data we'll send, and encoding.
31
- const url = new URL(request.url ?? "", `https://${request.headers.host}`);
31
+ const url = new URL(request?.url ?? "", `https://${request?.headers.host}`);
32
32
 
33
33
  if (!url.pathname.endsWith("/") && Tree.isMaplike(resource)) {
34
34
  // Maplike resource: redirect to its index page.
@@ -89,6 +89,7 @@ export default async function constructResponse(request, resource) {
89
89
  const text = toString(resource);
90
90
  if (text) {
91
91
  mediaType = maybeHtml(text) ? "text/html" : "text/plain";
92
+ mediaType += "; charset=utf-8";
92
93
  body = text;
93
94
  }
94
95
  } else if (mediaType && SiteMap.mediaTypeIsText(mediaType)) {
@@ -121,13 +122,16 @@ function maybeHtml(text) {
121
122
  if (text.startsWith("<!DOCTYPE html>")) {
122
123
  return true;
123
124
  }
125
+ if (text.startsWith("<!--")) {
126
+ return true;
127
+ }
124
128
  // Check if the text starts with an HTML tag.
125
129
  // - start with possible whitespace
126
130
  // - followed by '<'
127
131
  // - followed by a letter
128
- // - followed by letters, digits, hyphens, underscores, colons, or periods
132
+ // - followed maybe by letters, digits, hyphens, underscores, colons, or periods
129
133
  // - followed by '>', or
130
134
  // - followed by whitespace, anything that's not '>', then a '>'
131
- const tagRegex = /^\s*<[a-zA-Z][a-zA-Z0-9-_:\.]+(>|[\s]+[^>]*>)/;
135
+ const tagRegex = /^\s*<[a-zA-Z][a-zA-Z0-9-_:\.]*(>|[\s]+[^>]*>)/;
132
136
  return tagRegex.test(text);
133
137
  }
@@ -80,7 +80,7 @@ export async function handleRequest(request, response, map) {
80
80
  }
81
81
  }
82
82
 
83
- function keysFromUrl(url) {
83
+ export function keysFromUrl(url) {
84
84
  const encodedKeys = keysFromPath(url.pathname);
85
85
  const keys = encodedKeys.map((key) => decodeURIComponent(key));
86
86
 
@@ -119,7 +119,7 @@ export function requestListener(maplike) {
119
119
  * Construct a page in response in the given error, and also show the error in
120
120
  * the console.
121
121
  */
122
- function respondWithError(response, error) {
122
+ export function respondWithError(response, error) {
123
123
  let message = formatError(error);
124
124
  // Remove ANSI escape codes from the message.
125
125
  message = message.replace(/\x1b\[[0-9;]*m/g, "");
@@ -138,7 +138,7 @@ ${message}
138
138
  </body>
139
139
  </html>
140
140
  `;
141
- response.writeHead(404, { "Content-Type": "text/html" });
141
+ response.writeHead(500, { "Content-Type": "text/html" });
142
142
  response.end(html, "utf-8");
143
143
  console.error(message);
144
144
  }