@weborigami/origami 0.6.6 → 0.6.8
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 +5 -2
- package/main.js +1 -1
- package/package.json +3 -3
- package/src/cli/cli.js +2 -7
- package/src/dev/OriCommandTransform.js +1 -1
- package/src/dev/help.yaml +1 -1
- package/src/dev/watch.js +1 -1
- package/src/origami/fetch.js +4 -2
- package/src/origami/image/format.js +9 -3
- package/src/origami/image/resize.js +9 -3
- package/src/origami/ori.js +1 -12
- package/src/origami/origami.js +11 -11
- package/src/server/constructResponse.js +3 -0
- package/src/initializeBuiltins.js +0 -23
package/index.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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,6 +1,6 @@
|
|
|
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";
|
|
3
|
-
export { default as initializeBuiltins } from "./src/initializeBuiltins.js";
|
|
4
4
|
export * as Origami from "./src/origami/origami.js";
|
|
5
5
|
export { default as origamiHighlightDefinition } from "./src/origami/origamiHighlightDefinition.js";
|
|
6
6
|
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.
|
|
3
|
+
"version": "0.6.8",
|
|
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.
|
|
20
|
+
"@weborigami/async-tree": "0.6.8",
|
|
21
21
|
"@weborigami/json-feed-to-rss": "1.0.1",
|
|
22
|
-
"@weborigami/language": "0.6.
|
|
22
|
+
"@weborigami/language": "0.6.8",
|
|
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
|
@@ -5,7 +5,6 @@ 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";
|
|
8
|
-
import initializeBuiltins from "../initializeBuiltins.js";
|
|
9
8
|
import ori from "../origami/ori.js";
|
|
10
9
|
|
|
11
10
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
@@ -13,10 +12,6 @@ const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
|
13
12
|
async function main(...args) {
|
|
14
13
|
const expression = args.join(" ");
|
|
15
14
|
|
|
16
|
-
// Need to initialize builtins before calling projectRoot, which instantiates
|
|
17
|
-
// an OrigamiFileMap object that handles extensions, which requires builtins.
|
|
18
|
-
initializeBuiltins();
|
|
19
|
-
|
|
20
15
|
// Find the project root.
|
|
21
16
|
const currentDirectory = process.cwd();
|
|
22
17
|
const projectRoot = await projectRootFromPath(currentDirectory);
|
|
@@ -39,8 +34,8 @@ async function main(...args) {
|
|
|
39
34
|
result instanceof ArrayBuffer
|
|
40
35
|
? new Uint8Array(result)
|
|
41
36
|
: typeof result === "string" || result instanceof TypedArray
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
? result
|
|
38
|
+
: String(result);
|
|
44
39
|
await stdout.write(output);
|
|
45
40
|
|
|
46
41
|
// If stdout points to the console, and the result didn't end in a newline,
|
|
@@ -28,7 +28,7 @@ export default function OriCommandTransform(Base) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Key is an Origami command; invoke it.
|
|
31
|
-
const globals = await projectGlobals();
|
|
31
|
+
const globals = await projectGlobals(/** @type {any} */ (this));
|
|
32
32
|
const commandName = trailingSlash.remove(key.slice(1).trim());
|
|
33
33
|
|
|
34
34
|
// Look for command as a global or Dev command
|
package/src/dev/help.yaml
CHANGED
package/src/dev/watch.js
CHANGED
|
@@ -16,7 +16,7 @@ export default async function watch(maplike, fn) {
|
|
|
16
16
|
const container = await getTreeArgument(maplike, "watch");
|
|
17
17
|
|
|
18
18
|
// Watch the indicated tree.
|
|
19
|
-
|
|
19
|
+
/** @type {any} */ (container).watch?.();
|
|
20
20
|
|
|
21
21
|
if (fn === undefined) {
|
|
22
22
|
return container;
|
package/src/origami/fetch.js
CHANGED
|
@@ -4,7 +4,7 @@ import { handleExtension } from "@weborigami/language";
|
|
|
4
4
|
* Extend the JavaScript `fetch` function to implicity return an ArrayBuffer
|
|
5
5
|
* with an unpack() method if the resource has a known file extension.
|
|
6
6
|
*/
|
|
7
|
-
export default async function fetchBuiltin(resource, options) {
|
|
7
|
+
export default async function fetchBuiltin(resource, options, state) {
|
|
8
8
|
const response = await fetch(resource, options);
|
|
9
9
|
if (!response.ok) {
|
|
10
10
|
return undefined;
|
|
@@ -14,5 +14,7 @@ export default async function fetchBuiltin(resource, options) {
|
|
|
14
14
|
|
|
15
15
|
const url = new URL(resource);
|
|
16
16
|
const key = url.pathname;
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
return handleExtension(value, key, state.container);
|
|
18
19
|
}
|
|
20
|
+
fetchBuiltin.needsState = true;
|
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
}
|
package/src/origami/ori.js
CHANGED
|
@@ -30,7 +30,7 @@ export default async function ori(expression, options = {}) {
|
|
|
30
30
|
|
|
31
31
|
// Add Dev builtins as top-level globals
|
|
32
32
|
const globals = {
|
|
33
|
-
...(await projectGlobals()),
|
|
33
|
+
...(await projectGlobals(parent)),
|
|
34
34
|
...dev,
|
|
35
35
|
};
|
|
36
36
|
|
|
@@ -47,17 +47,6 @@ export default async function ori(expression, options = {}) {
|
|
|
47
47
|
// Execute
|
|
48
48
|
let result = await fn();
|
|
49
49
|
|
|
50
|
-
// if (result === undefined) {
|
|
51
|
-
// // Was the code a path traversal?
|
|
52
|
-
// const wasTraversal =
|
|
53
|
-
// fn.code[0] === ops.unpack ||
|
|
54
|
-
// (fn.code[0] instanceof Array && fn.code[0][0] === ops.scope);
|
|
55
|
-
// if (wasTraversal) {
|
|
56
|
-
// // Yes, probably an error
|
|
57
|
-
// console.warn(`ori: warning: undefined ${highlightError(expression)}`);
|
|
58
|
-
// }
|
|
59
|
-
// }
|
|
60
|
-
|
|
61
50
|
// If result was a function, execute it.
|
|
62
51
|
if (typeof result === "function") {
|
|
63
52
|
result = await result();
|
package/src/origami/origami.js
CHANGED
|
@@ -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 "
|
|
4
|
-
// export { default as htmlDom } from "
|
|
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";
|
|
@@ -28,9 +23,14 @@ 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";
|
|
30
25
|
export { default as projectRoot } from "./projectRoot.js";
|
|
26
|
+
export { default as redirect } from "./redirect.js";
|
|
31
27
|
export { default as repeat } from "./repeat.js";
|
|
28
|
+
export { default as rss } from "./rss.js";
|
|
32
29
|
export { default as shell } from "./shell.js";
|
|
30
|
+
export { default as sitemap } from "./sitemap.js";
|
|
33
31
|
export { default as slash } from "./slash.js";
|
|
32
|
+
export { default as slug } from "./slug.js";
|
|
33
|
+
export { default as static } from "./static.js";
|
|
34
34
|
export { default as string } from "./string.js";
|
|
35
35
|
export { default as tsv } from "./tsv.js";
|
|
36
36
|
export { default as unpack } from "./unpack.js";
|
|
@@ -122,6 +122,9 @@ function maybeHtml(text) {
|
|
|
122
122
|
if (text.startsWith("<!DOCTYPE html>")) {
|
|
123
123
|
return true;
|
|
124
124
|
}
|
|
125
|
+
if (text.startsWith("<!--")) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
125
128
|
// Check if the text starts with an HTML tag.
|
|
126
129
|
// - start with possible whitespace
|
|
127
130
|
// - followed by '<'
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { builtins } from "@weborigami/language";
|
|
2
|
-
import * as dev from "./dev/dev.js";
|
|
3
|
-
import help from "./dev/help.js";
|
|
4
|
-
import * as origami from "./origami/origami.js";
|
|
5
|
-
|
|
6
|
-
let initialized = false;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Pass the Origami builtins to the compiler.
|
|
10
|
-
*/
|
|
11
|
-
export default function initializeBuiltins() {
|
|
12
|
-
if (!initialized) {
|
|
13
|
-
const origamiBuiltins = {
|
|
14
|
-
Dev: dev,
|
|
15
|
-
Origami: origami,
|
|
16
|
-
"help:": help,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
Object.assign(builtins, origamiBuiltins);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
initialized = true;
|
|
23
|
-
}
|