@weborigami/origami 0.3.3 → 0.3.4-jse.5

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.
Files changed (59) hide show
  1. package/main.js +1 -3
  2. package/package.json +4 -4
  3. package/src/BuiltinsTree.js +18 -0
  4. package/src/builtinsJse.js +67 -0
  5. package/src/builtinsShell.js +52 -0
  6. package/src/cli/getConfig.js +10 -0
  7. package/src/common/documentObject.js +8 -2
  8. package/src/common/fetchAndHandleExtension.js +3 -2
  9. package/src/common/utilities.js +2 -2
  10. package/src/dev/ExplorableSiteTransform.js +2 -2
  11. package/src/dev/crawler/crawlResources.js +1 -1
  12. package/src/dev/crawler/pathsInHtml.js +2 -0
  13. package/src/dev/explore.js +3 -8
  14. package/src/dev/explore.js.inline +2 -2
  15. package/src/dev/explore.ori +6 -6
  16. package/src/handlers/css.handler.js +2 -2
  17. package/src/handlers/handlerBuiltins.js +26 -0
  18. package/src/handlers/handlers.js +36 -40
  19. package/src/handlers/htm.handler.js +1 -1
  20. package/src/handlers/html.handler.js +2 -2
  21. package/src/handlers/jpg.handler.js +1 -1
  22. package/src/handlers/js.handler.js +1 -1
  23. package/src/handlers/jse.handler.js +17 -0
  24. package/src/handlers/jsedocument.handler.js +17 -0
  25. package/src/handlers/md.handler.js +2 -2
  26. package/src/handlers/mjs.handler.js +1 -1
  27. package/src/handlers/ori.handler.js +15 -5
  28. package/src/handlers/oridocument.handler.js +15 -2
  29. package/src/{common → handlers}/processUnpackedContent.js +1 -3
  30. package/src/handlers/ts.handler.js +1 -1
  31. package/src/handlers/txt.handler.js +9 -1
  32. package/src/handlers/wasm.handler.js +1 -1
  33. package/src/handlers/yaml.handler.js +1 -1
  34. package/src/handlers/yml.handler.js +1 -1
  35. package/src/help/help.yaml +1 -11
  36. package/src/origami/config.js +2 -4
  37. package/src/origami/ori.js +17 -4
  38. package/src/origami/origami.js +0 -5
  39. package/src/origami/project.js +66 -56
  40. package/src/origami/regexMatch.js +4 -0
  41. package/src/protocols/files.js +2 -1
  42. package/src/protocols/inherited.js +6 -3
  43. package/src/protocols/new.js +4 -0
  44. package/src/protocols/node.js +13 -0
  45. package/src/protocols/scope.js +3 -3
  46. package/src/site/{index.js → indexPage.js} +1 -1
  47. package/src/site/site.js +1 -1
  48. package/src/site/sitemap.js +3 -4
  49. package/src/site/static.js +1 -1
  50. package/src/text/inline.js +19 -14
  51. package/src/text/mdHtml.js +2 -1
  52. package/src/tree/map.js +1 -1
  53. package/src/builtins.js +0 -58
  54. package/src/builtinsTree.js +0 -36
  55. package/src/calc/calc.js +0 -81
  56. package/src/handlers/handlerExports.js +0 -16
  57. package/src/internal.js +0 -24
  58. package/src/js.js +0 -38
  59. package/src/node.js +0 -22
package/main.js CHANGED
@@ -1,11 +1,9 @@
1
- export * from "./src/calc/calc.js";
2
1
  export { default as documentObject } from "./src/common/documentObject.js";
3
2
  export { toString } from "./src/common/utilities.js";
4
3
  export * from "./src/dev/dev.js";
5
- export * from "./src/handlers/handlerExports.js";
4
+ export { default as handlerBuiltins } from "./src/handlers/handlerBuiltins.js";
6
5
  export * from "./src/handlers/handlers.js";
7
6
  export * from "./src/image/image.js";
8
- export { builtinsTree } from "./src/internal.js";
9
7
  export * from "./src/origami/origami.js";
10
8
  export { default as packageBuiltin } from "./src/protocols/package.js";
11
9
  export * from "./src/server/server.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.3.3",
3
+ "version": "0.3.4-jse.5",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,10 +17,10 @@
17
17
  "typescript": "5.8.2"
18
18
  },
19
19
  "dependencies": {
20
- "@weborigami/async-tree": "0.3.3",
20
+ "@weborigami/async-tree": "0.3.4-jse.5",
21
21
  "@weborigami/json-feed-to-rss": "1.0.0",
22
- "@weborigami/language": "0.3.3",
23
- "@weborigami/types": "0.3.3",
22
+ "@weborigami/language": "0.3.4-jse.5",
23
+ "@weborigami/types": "0.3.4-jse.5",
24
24
  "css-tree": "3.1.0",
25
25
  "exif-parser": "0.1.12",
26
26
  "graphviz-wasm": "3.0.2",
@@ -0,0 +1,18 @@
1
+ import { trailingSlash } from "@weborigami/async-tree";
2
+
3
+ // We create our own tree instead of using ObjectTree, since that binds the
4
+ // functions would be bound to the object. We want to leave them unbound.
5
+ export default class BuiltinsTree {
6
+ constructor(object) {
7
+ this.object = object;
8
+ }
9
+
10
+ async get(key) {
11
+ const normalizedKey = trailingSlash.remove(key);
12
+ return this.object[normalizedKey];
13
+ }
14
+
15
+ async keys() {
16
+ return Object.keys(this.object);
17
+ }
18
+ }
@@ -0,0 +1,67 @@
1
+ import { text as treeText } from "@weborigami/async-tree";
2
+ import { jsGlobals } from "@weborigami/language";
3
+ import * as dev from "./dev/dev.js";
4
+ import handlerBuiltins from "./handlers/handlerBuiltins.js";
5
+ import help from "./help/help.js";
6
+ import * as image from "./image/image.js";
7
+ import * as origami from "./origami/origami.js";
8
+ import explore from "./protocols/explore.js";
9
+ import files from "./protocols/files.js";
10
+ import http from "./protocols/http.js";
11
+ import https from "./protocols/https.js";
12
+ import httpstree from "./protocols/httpstree.js";
13
+ import httptree from "./protocols/httptree.js";
14
+ import inherited from "./protocols/inherited.js";
15
+ import node from "./protocols/node.js";
16
+ import packageNamespace from "./protocols/package.js";
17
+ import scope from "./protocols/scope.js";
18
+ import * as site from "./site/site.js";
19
+ import * as text from "./text/text.js";
20
+ import * as tree from "./tree/tree.js";
21
+
22
+ let builtins;
23
+
24
+ export default function builtinsJse() {
25
+ if (!builtins) {
26
+ const Tree = {
27
+ ...tree,
28
+ indent: text.indent,
29
+ json: origami.json,
30
+ text: treeText,
31
+ };
32
+
33
+ const Origami = {
34
+ ...dev,
35
+ files,
36
+ image,
37
+ ...origami,
38
+ ...site,
39
+ ...text,
40
+ };
41
+
42
+ /** @type {any} */
43
+ builtins = {
44
+ ...jsGlobals,
45
+
46
+ "explore:": explore,
47
+ "files:": files,
48
+ "help:": help,
49
+ "http:": http,
50
+ "https:": https,
51
+ "httpstree:": httpstree,
52
+ "httptree:": httptree,
53
+ "inherited:": inherited,
54
+ "node:": node,
55
+ "package:": packageNamespace,
56
+ "scope:": scope,
57
+
58
+ Tree,
59
+ Origami,
60
+
61
+ // Handlers need to be exposed at top level
62
+ ...handlerBuiltins(),
63
+ };
64
+ }
65
+
66
+ return builtins;
67
+ }
@@ -0,0 +1,52 @@
1
+ import { jsGlobals } from "@weborigami/language";
2
+ import builtinsJse from "./builtinsJse.js";
3
+ import * as dev from "./dev/dev.js";
4
+ import * as image from "./image/image.js";
5
+ import * as origami from "./origami/origami.js";
6
+ import instantiate from "./protocols/new.js";
7
+ import scope from "./protocols/scope.js";
8
+ import * as site from "./site/site.js";
9
+ import * as text from "./text/text.js";
10
+ import * as tree from "./tree/tree.js";
11
+
12
+ let builtins;
13
+
14
+ export default function builtinsShell() {
15
+ if (!builtins) {
16
+ builtins = {
17
+ // All JSE builtins
18
+ ...builtinsJse(),
19
+
20
+ // Old protocols to be deprecated
21
+ "dev:": dev,
22
+ "image:": image,
23
+ "js:": jsGlobals,
24
+ "new:": instantiate,
25
+ "origami:": origami,
26
+ "scope:": scope,
27
+ "site:": adjustReservedWords(site),
28
+ "text:": text,
29
+ "tree:": tree,
30
+
31
+ // For backward compat, include all methods at the top level
32
+ ...dev,
33
+ ...image,
34
+ ...origami,
35
+ ...adjustReservedWords(site),
36
+ ...text,
37
+ ...tree,
38
+ };
39
+ }
40
+
41
+ return builtins;
42
+ }
43
+
44
+ // Handle cases where a builtin name conflicts with a JS reserved word
45
+ function adjustReservedWords(obj) {
46
+ const result = {};
47
+ for (const [key, value] of Object.entries(obj)) {
48
+ const name = value.key ?? key;
49
+ result[name] = value;
50
+ }
51
+ return result;
52
+ }
@@ -0,0 +1,10 @@
1
+ import { Tree } from "@weborigami/async-tree";
2
+
3
+ // Return the config for the given tree
4
+ export default function getConfig(tree) {
5
+ if (!tree) {
6
+ return null;
7
+ }
8
+ const root = Tree.root(tree);
9
+ return root.config;
10
+ }
@@ -1,5 +1,4 @@
1
1
  import { isPlainObject, isUnpackable, toString } from "@weborigami/async-tree";
2
- // import txtHandler from "../builtins/txt.handler.js";
3
2
 
4
3
  /**
5
4
  * In Origami, a text document object is any object with a `@text` property and
@@ -22,7 +21,7 @@ export default async function documentObject(input, data) {
22
21
  }
23
22
 
24
23
  if (isPlainObject(input)) {
25
- text = input["@text"];
24
+ text = input["@text"] ?? input._body;
26
25
  inputData = input;
27
26
  } else {
28
27
  text = toString(input);
@@ -37,6 +36,13 @@ export default async function documentObject(input, data) {
37
36
  // };
38
37
  // const result = Object.create(base);
39
38
  const result = {};
39
+ // TODO: Deprecate @text
40
40
  Object.assign(result, inputData, data, { "@text": text });
41
+ Object.defineProperty(result, "_body", {
42
+ configurable: true,
43
+ value: text,
44
+ enumerable: false, // TODO: Make enumerable
45
+ writable: true,
46
+ });
41
47
  return result;
42
48
  }
@@ -1,4 +1,4 @@
1
- import { handleExtension } from "@weborigami/language";
1
+ import { getHandlers, handleExtension } from "@weborigami/language";
2
2
 
3
3
  /**
4
4
  * Fetch the resource at the given href.
@@ -19,7 +19,8 @@ export default async function fetchAndHandleExtension(href) {
19
19
  const url = new URL(href);
20
20
  const filename = url.pathname.split("/").pop();
21
21
  if (this && filename) {
22
- buffer = await handleExtension(this, buffer, filename);
22
+ const handlers = getHandlers(this);
23
+ buffer = await handleExtension(this, buffer, filename, handlers);
23
24
  }
24
25
 
25
26
  return buffer;
@@ -94,8 +94,8 @@ export function toFunction(obj) {
94
94
  * @returns {string|null}
95
95
  */
96
96
  export function toString(object) {
97
- if (isPlainObject(object) && "@text" in object) {
98
- object = object["@text"];
97
+ if (isPlainObject(object) && ("@text" in object || "_body" in object)) {
98
+ object = object["@text"] ?? object._body;
99
99
  }
100
100
  return asyncTreeToString(object);
101
101
  }
@@ -1,6 +1,6 @@
1
1
  import { Tree, jsonKeys } from "@weborigami/async-tree";
2
2
  import { isTransformApplied, transformObject } from "../common/utilities.js";
3
- import index from "../site/index.js";
3
+ import indexPage from "../site/indexPage.js";
4
4
 
5
5
  /**
6
6
  * Wraps a tree (typically a SiteTree) to turn a standard site into an
@@ -32,7 +32,7 @@ export default function ExplorableSiteTransform(Base) {
32
32
  // The tree doesn't have the key; try the defaults.
33
33
  if (key === "index.html") {
34
34
  // This tree is both the function call target and the parameter.
35
- value = await index.call(this, this);
35
+ value = await indexPage.call(this, this);
36
36
  } else if (key === ".keys.json") {
37
37
  value = await jsonKeys.stringify(this);
38
38
  }
@@ -130,7 +130,7 @@ async function processPath(tree, path, baseUrl) {
130
130
 
131
131
  // Traverse tree to get value.
132
132
  let value;
133
- let normalizedKeys;
133
+ let normalizedKeys = [];
134
134
  let normalizedPath;
135
135
  try {
136
136
  value = await Tree.traverse(tree, ...keys);
@@ -5,7 +5,9 @@ import { addHref } from "./utilities.js";
5
5
 
6
6
  export default function pathsInHtml(html) {
7
7
  const paths = {
8
+ /** @type {string[]} */
8
9
  crawlablePaths: [],
10
+ /** @type {string[]} */
9
11
  resourcePaths: [],
10
12
  };
11
13
 
@@ -5,7 +5,7 @@ import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
7
7
  import { getDescriptor } from "../common/utilities.js";
8
- import { builtinsTree } from "../internal.js";
8
+ import oriHandler from "../handlers/ori.handler.js";
9
9
  import debug from "./debug.js";
10
10
 
11
11
  let templatePromise;
@@ -44,7 +44,7 @@ export default async function explore(...keys) {
44
44
  const data = await getScopeData(scope(tree));
45
45
  templatePromise ??= loadTemplate();
46
46
  const template = await templatePromise;
47
- const text = await template(data);
47
+ const text = await template.call(this, data);
48
48
 
49
49
  result = new String(text);
50
50
  result.unpack = () => debug.call(tree, tree);
@@ -57,10 +57,6 @@ async function getScopeData(scope) {
57
57
  const trees = scope.trees ?? [scope];
58
58
  const data = [];
59
59
  for (const tree of trees) {
60
- if (tree.parent === undefined) {
61
- // Skip builtins.
62
- continue;
63
- }
64
60
  const name = getDescriptor(tree);
65
61
  const treeKeys = Array.from(await tree.keys());
66
62
  // Skip system-ish files that start with a period.
@@ -73,8 +69,7 @@ async function getScopeData(scope) {
73
69
  async function loadTemplate() {
74
70
  const folderPath = path.resolve(fileURLToPath(import.meta.url), "..");
75
71
  const folder = new OrigamiFiles(folderPath);
76
- folder.parent = builtinsTree;
77
72
  const templateFile = await folder.get("explore.ori");
78
- const template = await templateFile.unpack();
73
+ const template = await oriHandler.unpack(templateFile, { parent: folder });
79
74
  return template;
80
75
  }
@@ -3,7 +3,7 @@ let frame;
3
3
 
4
4
  const modes = {
5
5
  Content: "",
6
- Index: "!index",
6
+ Index: "!indexPage",
7
7
  YAML: "!yaml",
8
8
  SVG: "!svg",
9
9
  };
@@ -15,7 +15,7 @@ function getPathFromHash() {
15
15
 
16
16
  function getModeFromLocation() {
17
17
  const href = document.location.href;
18
- const match = /[\/](?<command>\!(?:index|yaml|svg))$/.exec(href);
18
+ const match = /[\/](?<command>\!(?:indexPage|yaml|svg))$/.exec(href);
19
19
  const command = match?.groups?.command ?? "";
20
20
  const mode =
21
21
  Object.keys(modes).find((key) => modes[key] === command) ?? "Content";
@@ -4,8 +4,8 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1" />
6
6
  <title>Web Origami Explorer</title>
7
- <style>${ explore.css }</style>
8
- <script>${ explore.js.inline }</script>
7
+ <style>${ <explore.css> }</style>
8
+ <script>${ <explore.js.inline> }</script>
9
9
  </head>
10
10
  <body>
11
11
  <nav>
@@ -16,10 +16,10 @@
16
16
  <button id="buttonSVG">SVG</button>
17
17
  <button id="buttonYAML">YAML</button>
18
18
  </div>
19
- ${ map(scope, (scopeTree) => `
19
+ ${ Tree.map(scope, (scopeTree) => `
20
20
  <ul>
21
- <h2>${ scopeTree/name ?? "" }</h2>
22
- ${ map(scopeTree/keys, (key) => `
21
+ <h2>${ scopeTree.name ?? "" }</h2>
22
+ ${ Tree.map(scopeTree.keys, (key) => `
23
23
  <li>
24
24
  <a href="./!explore/${ key }" target="frame">${ key }</a>
25
25
  </li>
@@ -30,4 +30,4 @@
30
30
  <iframe id="frame" name="frame"></iframe>
31
31
  </body>
32
32
  </html>
33
- `
33
+ `
@@ -1,7 +1,7 @@
1
1
  // .css files use the .txt loader
2
- import fileTypeText from "./txt.handler.js";
2
+ import { txtHandler } from "./handlers.js";
3
3
 
4
4
  export default {
5
- ...fileTypeText,
5
+ ...txtHandler,
6
6
  mediaType: "text/css",
7
7
  };
@@ -0,0 +1,26 @@
1
+ import * as handlers from "./handlers.js";
2
+
3
+ export default function handlerBuiltins() {
4
+ return {
5
+ "css.handler": handlers.cssHandler,
6
+ "csv.handler": handlers.csvHandler,
7
+ "htm.handler": handlers.htmHandler,
8
+ "html.handler": handlers.htmlHandler,
9
+ "jpeg.handler": handlers.jpegHandler,
10
+ "jpg.handler": handlers.jpgHandler,
11
+ "js.handler": handlers.jsHandler,
12
+ "jse.handler": handlers.jseHandler,
13
+ "jsedocument.handler": handlers.jsedocumentHandler,
14
+ "json.handler": handlers.jsonHandler,
15
+ "md.handler": handlers.mdHandler,
16
+ "mjs.handler": handlers.mjsHandler,
17
+ "ori.handler": handlers.oriHandler,
18
+ "oridocument.handler": handlers.oridocumentHandler,
19
+ "ts.handler": handlers.tsHandler,
20
+ "txt.handler": handlers.txtHandler,
21
+ "wasm.handler": handlers.wasmHandler,
22
+ "xhtml.handler": handlers.xhtmlHandler,
23
+ "yaml.handler": handlers.yamlHandler,
24
+ "yml.handler": handlers.ymlHandler,
25
+ };
26
+ }
@@ -1,41 +1,37 @@
1
- import {
2
- jsHandler,
3
- oriHandler,
4
- oridocumentHandler,
5
- wasmHandler,
6
- yamlHandler,
7
- } from "../internal.js";
8
- import cssHandler from "./css.handler.js";
9
- import csvHandler from "./csv.handler.js";
10
- import htmHandler from "./htm.handler.js";
11
- import htmlHandler from "./html.handler.js";
12
- import jpegHandler from "./jpeg.handler.js";
13
- import jpgHandler from "./jpg.handler.js";
14
- import jsonHandler from "./json.handler.js";
15
- import mdHandler from "./md.handler.js";
16
- import mjsHandler from "./mjs.handler.js";
17
- import tsHandler from "./ts.handler.js";
18
- import txtHandler from "./txt.handler.js";
19
- import xhtmlHandler from "./xhtml.handler.js";
20
- import ymlHandler from "./yml.handler.js";
1
+ //
2
+ // This library includes a number of modules with circular dependencies. This
3
+ // module exists to explicitly set the loading order for those modules. To
4
+ // enforce use of this loading order, other modules should only load the modules
5
+ // below via this module.
6
+ //
7
+ // About this pattern:
8
+ // https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de
9
+ //
10
+ // Note: to avoid having VS Code auto-sort the imports, keep lines between them.
21
11
 
22
- export default {
23
- "css.handler": cssHandler,
24
- "csv.handler": csvHandler,
25
- "htm.handler": htmHandler,
26
- "html.handler": htmlHandler,
27
- "jpeg.handler": jpegHandler,
28
- "jpg.handler": jpgHandler,
29
- "js.handler": jsHandler,
30
- "json.handler": jsonHandler,
31
- "md.handler": mdHandler,
32
- "mjs.handler": mjsHandler,
33
- "ori.handler": oriHandler,
34
- "oridocument.handler": oridocumentHandler,
35
- "ts.handler": tsHandler,
36
- "txt.handler": txtHandler,
37
- "wasm.handler": wasmHandler,
38
- "xhtml.handler": xhtmlHandler,
39
- "yaml.handler": yamlHandler,
40
- "yml.handler": ymlHandler,
41
- };
12
+ export { default as jsHandler } from "./js.handler.js";
13
+ export { default as tsHandler } from "./ts.handler.js";
14
+
15
+ export { default as oriHandler } from "./ori.handler.js";
16
+
17
+ export { default as jseHandler } from "./jse.handler.js";
18
+
19
+ export { default as oridocumentHandler } from "./oridocument.handler.js";
20
+
21
+ export { default as jsedocumentHandler } from "./jsedocument.handler.js";
22
+
23
+ export { default as txtHandler } from "./txt.handler.js";
24
+
25
+ export { default as cssHandler } from "./css.handler.js";
26
+ export { default as csvHandler } from "./csv.handler.js";
27
+ export { default as htmHandler } from "./htm.handler.js";
28
+ export { default as htmlHandler } from "./html.handler.js";
29
+ export { default as jpegHandler } from "./jpeg.handler.js";
30
+ export { default as jpgHandler } from "./jpg.handler.js";
31
+ export { default as jsonHandler } from "./json.handler.js";
32
+ export { default as mdHandler } from "./md.handler.js";
33
+ export { default as mjsHandler } from "./mjs.handler.js";
34
+ export { default as wasmHandler } from "./wasm.handler.js";
35
+ export { default as xhtmlHandler } from "./xhtml.handler.js";
36
+ export { default as yamlHandler } from "./yaml.handler.js";
37
+ export { default as ymlHandler } from "./yml.handler.js";
@@ -1,2 +1,2 @@
1
1
  // .htm is a synonynm for .html
2
- export { default } from "./html.handler.js";
2
+ export { htmlHandler as default } from "./handlers.js";
@@ -1,7 +1,7 @@
1
1
  // .html files use the .txt loader
2
- import fileTypeText from "./txt.handler.js";
2
+ import { txtHandler } from "./handlers.js";
3
3
 
4
4
  export default {
5
- ...fileTypeText,
5
+ ...txtHandler,
6
6
  mediaType: "text/html",
7
7
  };
@@ -1,2 +1,2 @@
1
1
  // .jpg is a synonym for .jpeg
2
- export { default } from "./jpeg.handler.js";
2
+ export { jpegHandler as default } from "./handlers.js";
@@ -1,4 +1,4 @@
1
- import { processUnpackedContent } from "../internal.js";
1
+ import processUnpackedContent from "./processUnpackedContent.js";
2
2
 
3
3
  /**
4
4
  * A JavaScript file
@@ -0,0 +1,17 @@
1
+ import builtinsJse from "../builtinsJse.js";
2
+ import getParent from "./getParent.js";
3
+ import { oriHandler } from "./handlers.js";
4
+
5
+ export default {
6
+ ...oriHandler,
7
+
8
+ async unpack(packed, options = {}) {
9
+ const parent = getParent(packed, options);
10
+ return oriHandler.unpack(packed, {
11
+ ...options,
12
+ globals: builtinsJse(),
13
+ mode: "jse",
14
+ parent,
15
+ });
16
+ },
17
+ };
@@ -0,0 +1,17 @@
1
+ import builtinsJse from "../builtinsJse.js";
2
+ import getParent from "./getParent.js";
3
+ import { oridocumentHandler } from "./handlers.js";
4
+
5
+ export default {
6
+ ...oridocumentHandler,
7
+
8
+ async unpack(packed, options = {}) {
9
+ const parent = getParent(packed, options);
10
+ return oridocumentHandler.unpack(packed, {
11
+ ...options,
12
+ globals: builtinsJse(),
13
+ mode: "jse",
14
+ parent,
15
+ });
16
+ },
17
+ };
@@ -1,7 +1,7 @@
1
1
  // .md files use the .txt loader
2
- import fileTypeText from "./txt.handler.js";
2
+ import { txtHandler } from "./handlers.js";
3
3
 
4
4
  export default {
5
- ...fileTypeText,
5
+ ...txtHandler,
6
6
  mediaType: "text/markdown",
7
7
  };
@@ -1,2 +1,2 @@
1
1
  // .mjs is a synonynm for .js
2
- export { jsHandler as default } from "../internal.js";
2
+ export { jsHandler as default } from "./handlers.js";
@@ -1,7 +1,9 @@
1
1
  import { compile } from "@weborigami/language";
2
+ import builtinsShell from "../builtinsShell.js";
3
+ import getConfig from "../cli/getConfig.js";
2
4
  import * as utilities from "../common/utilities.js";
3
- import { builtinsTree, processUnpackedContent } from "../internal.js";
4
5
  import getParent from "./getParent.js";
6
+ import processUnpackedContent from "./processUnpackedContent.js";
5
7
 
6
8
  /**
7
9
  * An Origami expression file
@@ -34,10 +36,18 @@ export default {
34
36
 
35
37
  // Compile the source code as an Origami program and evaluate it.
36
38
  const compiler = options.compiler ?? compile.program;
37
- const fn = compiler(source);
38
- const target = parent ?? builtinsTree;
39
- let content = await fn.call(target);
40
39
 
41
- return processUnpackedContent(content, parent);
40
+ const config = getConfig(parent) ?? {};
41
+ const globals = {
42
+ ...(options.globals ?? builtinsShell()),
43
+ ...config,
44
+ };
45
+
46
+ const mode = options.mode ?? "shell";
47
+ const fn = compiler(source, { globals, mode });
48
+
49
+ let result = await fn.call(parent);
50
+
51
+ return processUnpackedContent(result, parent);
42
52
  },
43
53
  };
@@ -1,8 +1,9 @@
1
1
  import { extension, trailingSlash } from "@weborigami/async-tree";
2
2
  import { compile } from "@weborigami/language";
3
+ import builtinsShell from "../builtinsShell.js";
3
4
  import { toString } from "../common/utilities.js";
4
- import { processUnpackedContent } from "../internal.js";
5
5
  import getParent from "./getParent.js";
6
+ import processUnpackedContent from "./processUnpackedContent.js";
6
7
 
7
8
  /**
8
9
  * An Origami template document: a plain text file that contains Origami
@@ -35,7 +36,19 @@ export default {
35
36
  text,
36
37
  url,
37
38
  };
38
- const defineFn = compile.templateDocument(source);
39
+
40
+ let globals;
41
+ if (options.globals) {
42
+ globals = options.globals;
43
+ } else {
44
+ globals = builtinsShell();
45
+ }
46
+
47
+ const defineFn = compile.templateDocument(source, {
48
+ front: options.front,
49
+ globals,
50
+ mode: options.mode ?? "shell",
51
+ });
39
52
 
40
53
  // Invoke the definition to get back the template function
41
54
  const result = await defineFn.call(parent);
@@ -1,5 +1,4 @@
1
1
  import { symbols, Tree } from "@weborigami/async-tree";
2
- import { builtinsTree } from "../internal.js";
3
2
 
4
3
  /**
5
4
  * Perform any necessary post-processing on the unpacked content of a file. This
@@ -14,8 +13,7 @@ import { builtinsTree } from "../internal.js";
14
13
  export default function processUnpackedContent(content, parent) {
15
14
  if (typeof content === "function") {
16
15
  // Bind the function to the parent as the `this` context.
17
- const target = parent ?? builtinsTree;
18
- const result = content.bind(target);
16
+ const result = content.bind(parent);
19
17
  // Copy over any properties that were attached to the function
20
18
  Object.assign(result, content);
21
19
  return result;