@weborigami/language 0.6.6 → 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,5 +1,11 @@
1
+ /**
2
+ * Origami is a JavaScript project, but we use TypeScript as an internal tool to
3
+ * confirm our code is type safe.
4
+ */
5
+
1
6
  import { SyncOrAsyncMap, UnpackFunction } from "@weborigami/async-tree";
2
7
 
8
+ // Re-export all exports from main.js
3
9
  export * from "./main.js";
4
10
 
5
11
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/language",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Web Origami expression language compiler and runtime",
5
5
  "type": "module",
6
6
  "main": "./main.js",
@@ -11,7 +11,7 @@
11
11
  "typescript": "5.9.3"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/async-tree": "0.6.6",
14
+ "@weborigami/async-tree": "0.6.7",
15
15
  "exif-parser": "0.1.12",
16
16
  "watcher": "2.3.1",
17
17
  "yaml": "2.8.1"
@@ -29,30 +29,40 @@ export default async function projectRootFromPath(dirname = process.cwd()) {
29
29
  let root;
30
30
  let value;
31
31
  // Use a plain FileMap to avoid loading extension handlers
32
- const currentTree = new FileMap(dirname);
33
- // Try looking for config file
34
- value = await currentTree.get(configFileName);
35
- if (value) {
36
- // Found config file
37
- root = new OrigamiFileMap(currentTree.path);
38
- } else {
32
+ let currentFolder = new FileMap(dirname);
33
+ while (currentFolder) {
34
+ // Try looking for config file
35
+ value = await currentFolder.get(configFileName);
36
+ if (value) {
37
+ // Found config file
38
+ root = new OrigamiFileMap(currentFolder.path);
39
+ break;
40
+ }
41
+
39
42
  // Try looking for package.json
40
- value = await currentTree.get(packageFileName);
43
+ value = await currentFolder.get(packageFileName);
41
44
  if (value) {
42
45
  // Found package.json
43
- root = new OrigamiFileMap(currentTree.path);
46
+ root = new OrigamiFileMap(currentFolder.path);
47
+ break;
48
+ }
49
+
50
+ // Move up a folder and try again
51
+ const parentPath = path.dirname(currentFolder.path);
52
+ if (parentPath !== currentFolder.path) {
53
+ currentFolder = new FileMap(parentPath);
44
54
  } else {
45
- // Move up a folder and try again
46
- const parentPath = path.dirname(dirname);
47
- if (parentPath !== dirname) {
48
- root = await projectRootFromPath(parentPath);
49
- } else {
50
- // At filesystem root, use current working directory
51
- root = new OrigamiFileMap(process.cwd());
52
- }
55
+ // At filesystem root; not found
56
+ root = null;
57
+ break;
53
58
  }
54
59
  }
55
60
 
61
+ if (!root) {
62
+ // Default to using the provided folder as the project root
63
+ root = new OrigamiFileMap(dirname);
64
+ }
65
+
56
66
  mapPathToRoot.set(dirname, root);
57
67
  return root;
58
68
  }
@@ -1,25 +1,28 @@
1
1
  import os from "node:os";
2
2
  import path from "node:path";
3
- import process from "node:process";
4
3
  import OrigamiFileMap from "../runtime/OrigamiFileMap.js";
5
4
 
6
5
  /**
7
6
  *
8
- * @param {string[]} keys
7
+ * @param {any[]} args
9
8
  */
10
- export default async function files(...keys) {
9
+ export default async function files(...args) {
10
+ const state = args.pop(); // Remaining args are the path
11
+
11
12
  // If path begins with `~`, treat it relative to the home directory.
12
- // Otherwise, treat it relative to the current working directory.
13
- let relativePath = keys.join(path.sep);
13
+ // Otherwise, treat it relative to the current container.
14
+ let relativePath = args.join(path.sep);
14
15
  let basePath;
15
16
  if (relativePath.startsWith("~")) {
16
17
  basePath = os.homedir();
17
18
  relativePath = relativePath.slice(2);
18
19
  } else {
19
- basePath = process.cwd();
20
+ const { container } = state;
21
+ basePath = container.path;
20
22
  }
21
23
  const resolved = path.resolve(basePath, relativePath);
22
24
 
23
25
  const result = new OrigamiFileMap(resolved);
24
26
  return result;
25
27
  }
28
+ files.needsState = true;
@@ -138,6 +138,9 @@ function defineProperty(object, propertyInfo, state, map) {
138
138
  * Return a normalized version of the property key for use in the keys() method.
139
139
  * Among other things, this adds trailing slashes to keys that correspond to
140
140
  * maplike values.
141
+ *
142
+ * @param {any} propertyInfo
143
+ * @param {object|null} [object]
141
144
  */
142
145
  export function normalizeKey(propertyInfo, object = null) {
143
146
  const { key, value, valueType } = propertyInfo;
@@ -33,8 +33,8 @@ describe("projectRootFromPath", () => {
33
33
  assert.equal(resultPath, fileURLToPath(projectUrl));
34
34
  });
35
35
 
36
- test("defaults to current working directory", async () => {
36
+ test("defaults to supplied directory", async () => {
37
37
  const root = await projectRootFromPath("/");
38
- assert.equal(root.path, process.cwd());
38
+ assert.equal(root.path, "/");
39
39
  });
40
40
  });