@rulecad/cad 0.7.97 → 0.8.0

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/lib/plates.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import { bounds, check as printCheck } from '@rulecad/printcheck';
7
- import { locate, build } from './design.mjs';
7
+ import { locateIn, build } from './design.mjs';
8
8
  import { paths, printerOf } from './workspace.mjs';
9
9
  import { peekRuleSet } from './rules.mjs';
10
10
  import { CadError } from './errors.mjs';
@@ -39,7 +39,7 @@ async function plateParts(s) {
39
39
  const it = o.fitting ? items.get(o.id) : null;
40
40
  if (o.fitting && !it?.fitting) continue;
41
41
  const fitting = it ? { ...it.fitting, pose: 'print' } : null;
42
- const b = fitting ? (await fittingBuilt({ ...it, fitting }, o.id, framesContext(), plasticOf(s.project))).b : await build({ ...locate(`${s.project}/${o.objName}`), ...(o.variant ? { variant: o.variant } : {}) }, o.set || {});
42
+ const b = fitting ? (await fittingBuilt({ ...it, fitting }, o.id, framesContext(), plasticOf(s.project))).b : await build({ ...locateIn(s.project, o.objName), ...(o.variant ? { variant: o.variant } : {}) }, o.set || {});
43
43
  const tris = b.parts.flatMap((p) => p.triangles), { lo, hi } = bounds(tris);
44
44
  const fil = [...new Set(b.parts.filter((p) => p.role !== 'support').map((p) => p.filament || 'base'))].sort().join('+') || 'base';
45
45
  out.push({ id: o.id.replace(/\./g, '_'), source: o.id, object: o.objName, ...(fitting ? { fitting } : {}), variant: o.variant, set: o.set || {}, filament: fil, material: own, hash: b.hash, lo, size: [hi[0] - lo[0], hi[1] - lo[1]], height: hi[2] - lo[2] });
package/lib/rules.mjs CHANGED
@@ -1,27 +1,51 @@
1
1
  // Rules from files: the variables and expressions of @rulecad/variables, with rule sets read from the workspace's rules/
2
2
  // (then the tool's) by name. Everything but loading is in @rulecad/variables, which needs no files and runs anywhere.
3
+ import fs from 'node:fs';
3
4
  import path from 'node:path';
4
5
  import { host, readJson } from './host.mjs';
5
6
  import { RULE_DIRS, WS } from './workspace.mjs';
7
+ import { plainName } from './names.mjs';
6
8
  import { resolve as resolveWith } from '@rulecad/variables';
7
9
 
8
10
  export { ANCHORS, isName, options, checkName, evaluate, fmt } from '@rulecad/variables';
9
11
 
10
12
  // dir: one folder (a release's own rules), else the workspace's rules, then the tool's. A rule set the tool provides
11
13
  // is copied into the workspace the first time it's used: the workspace keeps every rule its designs depend on (so a
12
- // release can record them in git), and your own measurements are edits to your copy.
14
+ // release can record them in git), and your own measurements are edits to your copy. The name is joined into both
15
+ // paths, so it must be plain (lib/names.mjs): a name with ../ would read a file from elsewhere and write its copy
16
+ // outside the workspace.
13
17
  export function loadRuleSet(name, dir) {
18
+ plainName(name, 'rule set name');
14
19
  const file = (dir ? [dir] : RULE_DIRS).map((d) => path.join(d, `${name}.json`)).find((f) => host.exists(f));
15
20
  if (!file) throw new Error(`no rule set "${name}" (rules/${name}.json)`);
16
21
  const own = path.join(WS, 'rules', `${name}.json`);
17
22
  if (!dir && file !== own) {
23
+ insideWorkspace(own);
18
24
  host.writeText(own, host.readText(file));
19
25
  console.error(`copied the ${name} rule set into rules/${name}.json: yours to keep and edit`);
20
26
  }
21
27
  return readJson(own);
22
28
  }
29
+ /**
30
+ * `file` (a rule set about to be written into the workspace's rules/) if no folder or file on its way down from the
31
+ * workspace is a link, else an error naming the link. A workspace can come from anyone, and git can carry a link: a
32
+ * rules/ folder that links to a folder elsewhere, or a rules/<name>.json that links to a file not yet made, would have
33
+ * the copy written outside the workspace.
34
+ * @param {string} file
35
+ * @returns {string}
36
+ */
37
+ export function insideWorkspace(file) {
38
+ if (host.name !== 'node') return file; // (a workspace in memory has no links)
39
+ const top = path.resolve(WS); // (the workspace's own folder may be reached by a link: only what is inside it counts)
40
+ for (let p = path.resolve(file); p.startsWith(top + path.sep); p = path.dirname(p)) {
41
+ let link = false; try { link = fs.lstatSync(p).isSymbolicLink(); } catch {} // (not there yet: nothing to follow)
42
+ if (link) throw new Error(`${path.relative(WS, p)} is a link to somewhere else, so nothing was written to ${path.relative(WS, file)}: it could land outside the workspace. Make ${path.relative(WS, p)} a folder or file of the workspace's own`);
43
+ }
44
+ return file;
45
+ }
23
46
  // A rule set read as it is, the workspace's if it has one: for figures a check only reads, leaving the workspace alone
24
47
  export function peekRuleSet(name) {
48
+ plainName(name, 'rule set name');
25
49
  const file = RULE_DIRS.map((d) => path.join(d, `${name}.json`)).find((f) => host.exists(f));
26
50
  if (!file) throw new Error(`no rule set "${name}" (rules/${name}.json)`);
27
51
  return readJson(file);
@@ -1,35 +1,119 @@
1
1
  // The sandbox's import hook: code in the design's project may import @jscad/modeling, @rulecad/shapes, @rulecad/flexures, @rulecad/gears, @rulecad/motors, @rulecad/frames, @rulecad/fixings and files of
2
2
  // its own project, nothing else (no node: modules: no files, network or processes). The tool's own modules are free.
3
+ // An allowed package is named plainly and must lead inside that package: '@jscad/modeling/../../graceful-fs' would
4
+ // otherwise climb out of it to any file of the workspace, and a file outside the project isn't held to these rules.
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
3
7
  import { builtinModules } from 'node:module';
8
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
9
 
5
- let project = '';
6
- export async function initialize(data) { project = data?.project || ''; }
7
-
10
+ // (Not @rulecad/pcb: a board design reaches the board engine as v.pcb, which the runner loads as the tool's own
11
+ // module. The engine imports Node's modules, which a package a design may import may not, and the permission model
12
+ // holds it to reads only.)
8
13
  const ALLOWED = ['@jscad/modeling', '@rulecad/shapes', '@rulecad/flexures', '@rulecad/gears', '@rulecad/motors', '@rulecad/frames', '@rulecad/fixings'];
14
+
15
+ // Each allowed package's real folder, as the tool itself finds it (from its entry up to the package.json of that
16
+ // name: exports may hide that file), found once; null where the tool can't find the package
17
+ function home(name) {
18
+ try {
19
+ for (let d = path.dirname(fileURLToPath(import.meta.resolve(name))); path.dirname(d) !== d; d = path.dirname(d)) {
20
+ const pj = path.join(d, 'package.json');
21
+ if (fs.existsSync(pj) && JSON.parse(fs.readFileSync(pj, 'utf8')).name === name) return pathToFileURL(fs.realpathSync(d) + path.sep).href;
22
+ }
23
+ } catch { /* not where the tool can find it */ }
24
+ return null;
25
+ }
26
+
27
+ // What a file of each package may import by name: the allowed packages and what its package.json says it depends on
28
+ function needs(url) {
29
+ try {
30
+ const j = JSON.parse(fs.readFileSync(new URL('package.json', url), 'utf8'));
31
+ return [...ALLOWED, ...['dependencies', 'peerDependencies', 'optionalDependencies'].flatMap((k) => Object.keys(j[k] || {}))];
32
+ } catch { return ALLOWED; }
33
+ }
34
+
35
+ /**
36
+ * Each allowed package's real folder (a file: URL ending in a slash), or null where the tool can't find it. Found in
37
+ * the tool's own thread: older Node runs these hooks in a worker, where import.meta.resolve can't find packages, so
38
+ * the preload works them out and hands them over.
39
+ * @returns {Record<string, string | null>}
40
+ */
41
+ export const homesOf = () => Object.fromEntries(ALLOWED.map((a) => [a, home(a)]));
42
+
43
+ let project = '', homes = {}, deps = {};
44
+ /**
45
+ * Set the hooks up: the design's project (a file: URL ending in a slash) and, from the preload, the packages' folders.
46
+ * @param {{ project?: string, homes?: Record<string, string | null> }} [data]
47
+ */
48
+ export async function initialize(data) {
49
+ project = data?.project || '';
50
+ homes = data?.homes || homesOf();
51
+ deps = Object.fromEntries(ALLOWED.filter((a) => homes[a]).map((a) => [a, needs(homes[a])]));
52
+ }
53
+
9
54
  const deny = (spec, why) => Object.assign(new Error(`designs can't import "${spec}": ${why}`), { code: 'design.sandbox' });
10
55
 
11
56
  // The same check, for in-thread hooks (synchronous) and worker hooks (async)
12
57
  export function resolveHook(spec, context, next) {
13
58
  const fromDesign = check(spec, context), r = next(spec, context);
14
- return fromDesign ? after(spec, r) : r;
59
+ return fromDesign ? after(spec, r) : inPackage(spec, context, r);
15
60
  }
16
61
  export async function resolve(spec, context, next) {
17
62
  const fromDesign = check(spec, context), r = await next(spec, context);
18
- return fromDesign ? after(spec, r) : r;
63
+ return fromDesign ? after(spec, r) : inPackage(spec, context, r);
64
+ }
65
+ // A design may reach any file of an allowed package, and such a file isn't the design's, so it is free of the rules
66
+ // above: one that imports something the package doesn't depend on would hand that to the design. @jscad/modeling's
67
+ // own tests require('ava'), and an "ava" the workspace installs (a file: dependency, say) may do anything. So a file
68
+ // of an allowed package (not of a package kept in its node_modules) may import only the allowed packages, what its
69
+ // package.json depends on, and its own files.
70
+ const packageAt = (url) => ALLOWED.find((a) => homes[a] && url?.startsWith(homes[a]) && !url.slice(homes[a].length).split('/').some((s) => s.toLowerCase() === 'node_modules'));
71
+ // (before Node looks for a name, and after it finds a relative file)
72
+ function packageCheck(spec, context) {
73
+ const name = packageAt(context.parentURL);
74
+ if (name && !isRelative(spec) && (spec.startsWith('node:') || builtinModules.includes(spec) || !deps[name].some((d) => spec === d || spec.startsWith(`${d}/`)))) {
75
+ throw deny(spec, `${fileURLToPath(context.parentURL)} would import it, and its package ${name} doesn't depend on it (a design may use a package's own files, not the tools its tests use)`);
76
+ }
77
+ }
78
+ function inPackage(spec, context, r) {
79
+ const name = isRelative(spec) && packageAt(context.parentURL);
80
+ if (name && !r.url.startsWith(homes[name])) throw deny(spec, `${fileURLToPath(context.parentURL)} would reach outside its package, ${name}`);
81
+ return r;
19
82
  }
20
83
  const isRelative = (spec) => spec.startsWith('./') || spec.startsWith('../');
84
+ const packageOf = (spec) => ALLOWED.find((a) => spec === a || spec.startsWith(`${a}/`));
21
85
  // A design's own files are its project's. A path that leaves it is refused wherever it leads: into the workspace's
22
- // node_modules, say, where any package may be. (The allowed packages are named bare, and may live anywhere.)
86
+ // node_modules, say, where any package may be. An allowed package must lead into its own folder, the one the tool
87
+ // uses, or a copy in the project: not through a link out of the project to some other folder of the same name.
23
88
  const after = (spec, r) => {
24
- if (isRelative(spec) && !r.url.startsWith(project)) throw deny(spec, 'it is outside the project');
89
+ if (isRelative(spec)) {
90
+ if (!r.url.startsWith(project)) throw deny(spec, 'it is outside the project');
91
+ return r;
92
+ }
93
+ const name = packageOf(spec), inside = homes[name];
94
+ if (!r.url.startsWith(project) && !(inside && r.url.startsWith(inside))) {
95
+ const to = r.url.startsWith('file:') ? fileURLToPath(r.url) : r.url;
96
+ const own = inside ? ` (${fileURLToPath(inside)})` : '';
97
+ throw deny(spec, `it leads outside the package ${name}, to ${to}. A design may use only the copy rulecad itself uses${own} or one inside its project: if the workspace installs another copy, give it the version rulecad uses (npm ls ${name} lists the copies)`);
98
+ }
25
99
  return r;
26
100
  };
101
+ // A file inside a package is named plainly: no '.' or '..' among the folders, no backslash, no %-encoded letters, and
102
+ // never in the package's own node_modules (another package, which may read files: a nested graceful-fs, say). Windows
103
+ // drops a name's trailing dots and spaces and knows NODE_M~1 for node_modules, so those spellings are refused too.
104
+ const odd = (s) => { const t = s.replace(/[. ]+$/, '').toLowerCase(); return t === '' || t === 'node_modules' || s.includes('~'); };
105
+ const climbs = (spec, name) => /[\\%]/.test(spec) || (spec !== name && spec.slice(name.length + 1).split('/').some(odd));
27
106
  // Everything under the project is the design's code, a node_modules folder there included
28
107
  function check(spec, context) {
29
108
  const fromDesign = project && context.parentURL?.startsWith(project);
109
+ if (!fromDesign) packageCheck(spec, context);
30
110
  if (fromDesign) {
31
111
  if (spec.startsWith('node:') || builtinModules.includes(spec)) throw deny(spec, 'a design only makes shapes (no files, network or programs)');
32
- if (!isRelative(spec) && !ALLOWED.some((a) => spec === a || spec.startsWith(`${a}/`))) throw deny(spec, `only ${ALLOWED.join(', ')} and files in its project`);
112
+ if (!isRelative(spec)) {
113
+ const name = packageOf(spec);
114
+ if (!name) throw deny(spec, `only ${ALLOWED.join(', ')} and files in its project`);
115
+ if (climbs(spec, name)) throw deny(spec, `a file of ${name} is named by its path inside the package, with no "." or ".." folders, node_modules, backslashes, "%" or "~", and no folder whose name ends in a dot or a space`);
116
+ }
33
117
  }
34
118
  return fromDesign;
35
119
  }
@@ -1,10 +1,10 @@
1
1
  // Loaded first in the sandbox (node --import): the import hook that keeps designs to their own imports. In-thread
2
2
  // (module.registerHooks) where Node has it; older Node runs hooks in a worker, which the sandbox then allows.
3
3
  import * as mod from 'node:module';
4
- import { resolveHook, initialize } from './sandbox-hooks.mjs';
4
+ import { resolveHook, initialize, homesOf } from './sandbox-hooks.mjs';
5
5
 
6
6
  const project = process.env.CAD_SANDBOX_PROJECT;
7
7
  if (mod.registerHooks) {
8
8
  initialize({ project });
9
9
  mod.registerHooks({ resolve: resolveHook });
10
- } else mod.register('./sandbox-hooks.mjs', import.meta.url, { data: { project } });
10
+ } else mod.register('./sandbox-hooks.mjs', import.meta.url, { data: { project, homes: homesOf() } });
@@ -1,5 +1,8 @@
1
1
  // The sandbox's runner: reads { js, values, meta } on stdin, runs the design's main(values), and writes its parts'
2
2
  // faces (and the rules it read) as JSON on stdout. Started by sandbox.mjs, under Node's permission model.
3
+ // A board design (board set) gets v.pcb, the board engine, and what it hands back is built into Circuit JSON here:
4
+ // the reply carries that circuit (and the matrix, and a cloned board's source) in place of parts, and the tool makes
5
+ // the board's solid from it. Routes the autorouter found are read from the tool's route cache and handed back.
3
6
  import fs from 'node:fs';
4
7
  import path from 'node:path';
5
8
  import * as shapes from '@rulecad/shapes';
@@ -20,11 +23,20 @@ for (const k of ['getBuiltinModule', 'binding', '_linkedBinding', 'dlopen', 'kil
20
23
  }
21
24
  const chunks = [];
22
25
  for await (const c of process.stdin) chunks.push(c);
23
- const { js, values, meta, engine, optional, stages, bound } = JSON.parse(Buffer.concat(chunks).toString('utf8')), context = bound?.fixings;
26
+ const { js, values, meta, engine, optional, stages, bound, board } = JSON.parse(Buffer.concat(chunks).toString('utf8')), context = bound?.fixings;
24
27
  // A lamina's slow stages: read from the tool's cache (the workspace is readable), and what this run makes handed back
25
28
  // with the parts for the tool to write (this process can't)
26
29
  const kept = {}; // (what this run made of them)
27
30
  if (stages) flexures.laminaCache({ salt: stages.salt, get: (k) => { try { return fs.readFileSync(path.join(stages.dir, `${k}.json`), 'utf8'); } catch { return undefined; } }, put: (k, text) => { kept[k] = text; } });
31
+ // A board's engine: @rulecad/pcb, loaded only for a board design, its mount bound to the workspace's thread sets (as
32
+ // data, like v.fixings), and its routes kept as the stages are
33
+ const routes = {};
34
+ let pcb = null, mounted = false;
35
+ if (board) {
36
+ pcb = await import('@rulecad/pcb');
37
+ if (pcb.routeStore) pcb.routeStore({ get: (k) => { if (!board.routes) return undefined; try { return fs.readFileSync(path.join(board.routes, `${k}.json`), 'utf8'); } catch { return undefined; } }, put: (k, text) => { routes[k] = text; } });
38
+ }
39
+ const engineFor = () => ({ ...pcb, mount: (thread, x, y, o = {}) => { mounted = true; return pcb.mount(thread, x, y, { sets: context?.sets, ...o }); } });
28
40
  const stdout = process.stdout, done = (o) => stdout.write(JSON.stringify(o), () => exit(0));
29
41
  // stdout carries the result, so what a design prints (console.log, to see a value) goes to stderr, which the tool passes on
30
42
  console.log = console.info = console.debug = (...a) => console.error(...a);
@@ -32,10 +44,14 @@ try {
32
44
  const mod = await import(js);
33
45
  if (typeof mod.main !== 'function') throw Object.assign(new Error('the design has no exported main(v)'), { code: 'design.main' });
34
46
  const ops = await shapes.ops(engine || 'jscad'), df = designFixings({ ...(context || {}), ops }); // (v.fixings: bound to the project, as the build's own is)
35
- const { v, read } = watch(values, { shapes, flexures, gears, motors, frames: designFrames(bound?.frames), fixings: df.fixings, ops }, optional);
47
+ const { v, read } = watch(values, { shapes, flexures, gears, motors, frames: designFrames(bound?.frames), fixings: df.fixings, ops, ...(pcb ? { pcb: engineFor() } : {}) }, optional);
36
48
  const { shapes: made, mechanism } = unpack(await mod.main(v));
37
- const parts = named(made, meta).map(({ geometry, ...p }) => ({ ...p, solid: faces(geometry) }));
38
- done({ parts, read: [...read], ...(mechanism ? { mechanism } : {}), ...(df.used() ? { fixings: df.found() } : {}), ...(Object.keys(kept).length ? { stages: kept } : {}) });
49
+ const found = { read: [...read], ...(mechanism ? { mechanism } : {}), ...(df.used() ? { fixings: df.found() } : {}), ...(Object.keys(kept).length ? { stages: kept } : {}) };
50
+ if (pcb) { // a circuit board: its Circuit JSON, for the tool to make the board's solid and files from
51
+ const { board: b, matrix, clone } = made && made.board ? made : { board: made };
52
+ const circuit = await pcb.render(b);
53
+ done({ parts: [], ...found, board: { circuit, ...(matrix ? { matrix } : {}), ...(clone ? { source: clone } : {}) }, ...(mounted ? { mounted } : {}), ...(Object.keys(routes).length ? { routes } : {}) });
54
+ } else done({ parts: named(made, meta).map(({ geometry, ...p }) => ({ ...p, solid: faces(geometry) })), ...found });
39
55
  } catch (e) {
40
56
  const line = lineOf(e, js);
41
57
  done({ error: { message: e?.message || String(e), ...(line ? { line } : {}), ...(e?.name === 'SyntaxError' ? { syntax: true } : {}), code: e?.code && typeof e.code === 'string' && !/^ERR_/.test(e.code) ? e.code : e?.code === 'ERR_ACCESS_DENIED' ? 'design.sandbox' : 'design.run', ...(e?.code === 'ERR_ACCESS_DENIED' && e.resource ? { resource: e.resource } : {}) } });
package/lib/sandbox.mjs CHANGED
@@ -9,8 +9,12 @@
9
9
  // the permission model doesn't cover the network, so a design written to get round them might still reach it, and
10
10
  // read the workspace as it does. So: run only designs you trust, as with any code.
11
11
  // It gets its values as data and sends back its parts' faces. A workspace that trusts its designs sets
12
- // "sandbox": false in cad.config.json (or CAD_TRUST=1). Board designs (engine pcb) run in the tool's own process,
13
- // with the board engine.
12
+ // "sandbox": false in cad.config.json (or CAD_TRUST=1).
13
+ // Board designs (engine pcb) run here too, with the board engine: the sandbox may then also read @rulecad/pcb and what
14
+ // it loads (tscircuit's packages), the design gets v.pcb as it would in the tool's process (v.pcb.mount reads the
15
+ // workspace's thread sets, handed in as data), the runner builds the board's Circuit JSON, and the reply carries it
16
+ // (with the keyboard matrix and a cloned board's source) for the tool to check and make the board's solid and files
17
+ // from. The autorouter's results come back the same way as a lamina's stages, for the tool to keep.
14
18
  import fs from 'node:fs';
15
19
  import path from 'node:path';
16
20
  import { spawn } from 'node:child_process';
@@ -33,7 +37,7 @@ export const sandboxed = () => !!flag && process.env.CAD_TRUST !== '1' && !(conf
33
37
 
34
38
  // What the sandbox may read: the workspace, and the packages designs and the runner load (wherever npm put them), and
35
39
  // what those load in turn (@rulecad/frames sizes a beam's operations through @rulecad/fixings)
36
- function readable() {
40
+ function readable({ board = false, extra = [] } = {}) {
37
41
  const real = (p) => { try { return fs.realpathSync(p); } catch { return null; } };
38
42
  const pkgDir = (name, from) => { // the package's folder: from its entry up to its package.json (exports may hide that file)
39
43
  try { let d = path.dirname(nodeModule.createRequire(from).resolve(name)); while (!fs.existsSync(path.join(d, 'package.json')) && path.dirname(d) !== d) d = path.dirname(d); return d; } catch { return null; }
@@ -42,8 +46,40 @@ function readable() {
42
46
  // Every node_modules above the workspace and the tool (package lookups read their links), and where links lead
43
47
  const up = (dir) => { const out = []; for (let d = dir; ; d = path.dirname(d)) { out.push(path.join(d, 'node_modules')); if (path.dirname(d) === d) return out; } };
44
48
  const dirs = [WS, TOOL, ...[...up(WS), ...up(TOOL)].filter((d) => fs.existsSync(d)),
45
- ...['@jscad/modeling', '@rulecad/shapes', '@rulecad/flexures', '@rulecad/gears', '@rulecad/motors', '@rulecad/frames', '@rulecad/fixings', '@rulecad/rules/x1c.json', '@rulecad/fea', '@rulecad/variables', 'manifold-3d'].flatMap((n) => [pkgDir(n, fromWs), pkgDir(n, fromTool)])];
46
- return [...new Set(dirs.filter(Boolean).flatMap((d) => [d, real(d)]).filter(Boolean))];
49
+ ...['@jscad/modeling', '@rulecad/shapes', '@rulecad/flexures', '@rulecad/gears', '@rulecad/motors', '@rulecad/frames', '@rulecad/fixings', '@rulecad/rules/x1c.json', '@rulecad/fea', '@rulecad/variables', 'manifold-3d'].flatMap((n) => [pkgDir(n, fromWs), pkgDir(n, fromTool)]), ...extra];
50
+ const out = [...new Set(dirs.filter(Boolean).flatMap((d) => [d, real(d)]).filter(Boolean))];
51
+ // A board's engine loads tscircuit's packages and @rulecad's own (smooth, rules, fixings): what it depends on, and
52
+ // what they do in turn, wherever each really is. Most are in a node_modules listed above; a package linked in from
53
+ // elsewhere (a workspace of packages, as rulecad's own repository is) is added by its real folder.
54
+ if (board) out.push(...(engineDirs ||= engineFolders(out, real, pkgDir, fromTool))); // (found once a run: the packages don't move under it)
55
+ return out;
56
+ }
57
+ let engineDirs = null;
58
+ // A package's name as npm allows it: never a path ("/home/me/.ssh/key", "../..") that would lead the walk below anywhere
59
+ const PACKAGE_NAME = /^(@[a-z0-9][\w.~-]*\/)?[a-z0-9][\w.~-]*$/i;
60
+ // The real folders of @rulecad/pcb and every package it loads, but those inside a folder the sandbox already reads.
61
+ // The engine the runner loads is the tool's own (sandbox-run.mjs imports it from here), so the walk starts there, never
62
+ // at a copy in the workspace: a workspace's node_modules is the workspace's to write, and a package.json there naming
63
+ // "dependencies" that lead out of it (a link, a path) would have the sandbox read wherever they lead. Each dependency is
64
+ // a package name, and its folder one whose package.json has that name.
65
+ function engineFolders(out, real, pkgDir, from) {
66
+ const found = [], seen = new Set(), under = (d) => out.some((o) => d === o || d.startsWith(o + path.sep));
67
+ const named = (d, n) => { try { return JSON.parse(fs.readFileSync(path.join(d, 'package.json'), 'utf8')).name === n; } catch { return false; } };
68
+ // (the folder found, or the one above it of that name: by its entry, a package's dist/package.json may be found first,
69
+ // but never above the node_modules it is in)
70
+ const own = (d, n) => { for (; d && path.basename(d) !== 'node_modules' && path.dirname(d) !== d; d = path.dirname(d)) if (named(d, n)) return d; return null; };
71
+ const add = (d, n) => { d = d && own(d, n); if (!d || seen.has(d)) return; seen.add(d); if (!under(d)) found.push(d); walk(d); };
72
+ const find = (n, dir) => { // (findPackageJSON where Node has it: exports that hide a package's entry from require don't hide this)
73
+ const at = path.join(dir, 'package.json');
74
+ try { if (nodeModule.findPackageJSON) { const f = nodeModule.findPackageJSON(n, pathToFileURL(at)); if (f) return real(path.dirname(f)); } } catch { /* by its entry, below */ }
75
+ return real(pkgDir(n, at) || '');
76
+ };
77
+ function walk(dir) {
78
+ let j; try { j = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')); } catch { return; }
79
+ for (const n of Object.keys({ ...j.dependencies, ...j.optionalDependencies, ...j.peerDependencies })) if (PACKAGE_NAME.test(n)) add(find(n, dir), n);
80
+ }
81
+ add(real(pkgDir('@rulecad/pcb', from) || ''), '@rulecad/pcb');
82
+ return found;
47
83
  }
48
84
 
49
85
  // A read the permission model refused, said with what to do. Node names the first path it may not read; when that is
@@ -58,16 +94,123 @@ function refused(e) {
58
94
  : `the design's sandbox was refused ${res}: a design may read only its workspace and the packages it uses. Keep what it needs inside the workspace, ${trust}`;
59
95
  }
60
96
 
97
+ // The child's reply is untrusted input. The design shares the runner's process, so it can print anything on the
98
+ // stdout the reply is read from, and end the process before the runner prints the real one. So every field is checked
99
+ // before it is used (checkReply), and the only thing written from it is a stage of the cache: under a key of the form
100
+ // the stage cache makes (@rulecad/flexures cache.mjs: `${name}-${sha256 hex}`, a name such as "physics" or "flood
101
+ // probe"), as a file directly in the stages folder (stageFile). A reply that is not one the runner makes is refused
102
+ // whole, with nothing written.
103
+
104
+ /** The form of a stage's key, as the stage cache makes it: a stage's name, a dash and the 64 hex digits of a SHA-256. */
105
+ export const STAGE_KEY = /^[a-z][a-z0-9 _-]{0,39}-[0-9a-f]{64}$/;
106
+
107
+ /**
108
+ * The file a stage of the cache is kept in, or null when its key would put it anywhere but directly in `dir`.
109
+ * @param {string} dir the stages folder @param {unknown} key @returns {string | null}
110
+ */
111
+ export function stageFile(dir, key) {
112
+ if (typeof key !== 'string' || !key) return null;
113
+ const file = path.resolve(dir, `${key}.json`), rel = path.relative(path.resolve(dir), file);
114
+ return rel && !path.isAbsolute(rel) && !rel.split(/[\\/]/).includes('..') && path.basename(rel) === rel ? file : null;
115
+ }
116
+
117
+ const plain = (x) => x !== null && typeof x === 'object' && !Array.isArray(x) && Object.getPrototypeOf(x) === Object.prototype;
118
+ const point = (p) => Array.isArray(p) && p.length === 3 && p.every((n) => typeof n === 'number' && Number.isFinite(n));
119
+ const faceList = (x) => Array.isArray(x) && x.every((f) => Array.isArray(f) && f.every(point));
120
+ const PART = { name: 'string', role: 'string', label: 'string', filament: 'string', mirror: 'boolean' }, PART_FACES = ['solid', 'polygons', 'triangles'];
121
+ const REPLY = ['parts', 'read', 'mechanism', 'fixings', 'stages', 'board', 'mounted', 'routes'], ERROR = { message: 'string', code: 'string', line: 'number', syntax: 'boolean', resource: 'string' };
122
+ const fields = (o, kinds) => Object.entries(o).find(([k, x]) => !(k in kinds) || typeof x !== kinds[k]);
123
+
124
+ /** The form of a route's key, as @rulecad/pcb's route cache makes it: the 64 hex digits of a SHA-256. */
125
+ export const ROUTE_KEY = /^[0-9a-f]{64}$/;
126
+ // A key JSON.parse keeps as a plain field that Object.assign and the like would take as the object's prototype
127
+ const polluting = (x) => {
128
+ for (const stack = [x]; stack.length;) {
129
+ const o = stack.pop();
130
+ if (o === null || typeof o !== 'object') continue;
131
+ if (!Array.isArray(o) && Object.hasOwn(o, '__proto__')) return true;
132
+ for (const v of Array.isArray(o) ? o : Object.values(o)) if (v !== null && typeof v === 'object') stack.push(v);
133
+ }
134
+ return false;
135
+ };
136
+ // A board's reply: its Circuit JSON (a list of elements, each with its type), and the matrix and source the design gave
137
+ function checkBoard(b) {
138
+ if (!plain(b)) return 'its board is not an object';
139
+ const extra = Object.keys(b).find((k) => !['circuit', 'matrix', 'source'].includes(k));
140
+ if (extra) return `its board has a field "${extra}" the runner doesn't send`;
141
+ if (!Array.isArray(b.circuit) || !b.circuit.length || !b.circuit.every((e) => plain(e) && typeof e.type === 'string')) return 'its board\'s circuit is not a list of circuit elements';
142
+ if (b.matrix != null && !(plain(b.matrix) || Array.isArray(b.matrix))) return 'its board\'s matrix is not an object';
143
+ if (b.source != null && !plain(b.source)) return 'its board\'s source is not an object';
144
+ if (polluting(b)) return 'its board has a field named __proto__';
145
+ return null;
146
+ }
147
+
148
+ /**
149
+ * What is wrong with a reply from the sandbox's runner, in a few words, or null when it is one the runner makes:
150
+ * `{ parts, read, mechanism?, fixings?, stages? }`, a board design's `{ parts: [], read, board: { circuit, matrix?,
151
+ * source? }, mounted?, fixings?, routes? }`, or `{ error }`.
152
+ * @param {unknown} r the child's stdout, parsed @returns {string | null}
153
+ */
154
+ export function checkReply(r) {
155
+ if (!plain(r)) return 'it is not an object';
156
+ if ('error' in r) {
157
+ if (Object.keys(r).length !== 1 || !plain(r.error)) return 'its error is not one the runner makes';
158
+ const bad = fields(r.error, ERROR);
159
+ return bad ? `its error's ${bad[0]} is not one the runner makes` : typeof r.error.message !== 'string' ? 'its error has no message' : null;
160
+ }
161
+ const extra = Object.keys(r).find((k) => !REPLY.includes(k));
162
+ if (extra) return `it has a field "${extra}" the runner doesn't send`;
163
+ if (!Array.isArray(r.parts)) return 'it has no list of parts';
164
+ for (const p of r.parts) {
165
+ if (!plain(p)) return 'a part is not an object';
166
+ const bad = Object.entries(p).find(([k, x]) => !(PART_FACES.includes(k) ? faceList(x) : k in PART && typeof x === PART[k]));
167
+ if (bad) return `a part's ${bad[0]} is not one the runner makes`;
168
+ if (typeof p.name !== 'string' || PART_FACES.some((k) => !(k in p))) return 'a part has no name or no faces';
169
+ }
170
+ if (!Array.isArray(r.read) || !r.read.every((n) => typeof n === 'string')) return 'what it read is not a list of names';
171
+ if (r.mechanism != null && !plain(r.mechanism)) return 'its mechanism is not an object';
172
+ if (r.fixings != null && !(Array.isArray(r.fixings) && r.fixings.every(plain))) return 'its fixings are not a list of findings';
173
+ if (r.stages != null) {
174
+ if (!plain(r.stages)) return 'its stages are not an object';
175
+ const bad = Object.entries(r.stages).find(([k, text]) => !STAGE_KEY.test(k) || typeof text !== 'string');
176
+ if (bad) return STAGE_KEY.test(bad[0]) ? 'a stage is not text' : 'a stage\'s key is not one the stage cache makes';
177
+ }
178
+ if (r.board != null) { const bad = checkBoard(r.board); if (bad) return bad; if (r.parts.length) return 'a board\'s reply has parts of its own'; }
179
+ if (r.mounted != null && typeof r.mounted !== 'boolean') return 'its "mounted" is not true or false';
180
+ if (r.routes != null) {
181
+ if (r.board == null) return 'it has routes but no board';
182
+ if (!plain(r.routes)) return 'its routes are not an object';
183
+ const bad = Object.entries(r.routes).find(([k, text]) => !ROUTE_KEY.test(k) || typeof text !== 'string');
184
+ if (bad) return ROUTE_KEY.test(bad[0]) ? 'a route is not text' : 'a route\'s key is not one the route cache makes';
185
+ }
186
+ if (r.mechanism != null && polluting(r.mechanism)) return 'its mechanism has a field named __proto__';
187
+ return null;
188
+ }
189
+
190
+ /** Whether designs can be sandboxed here at all: Node has the permission model. */
191
+ export const canSandbox = () => !!flag;
192
+
61
193
  /**
62
- * Run a design's main(values) in the sandbox: { parts, read } as the build makes them.
63
- * @param {{ js: string }} d the design @param {object} values @param {object} meta the .json's parts @param {'jscad' | 'manifold'} [engine] v.ops's booleans
64
- * @param {string[]} [optional] names main may read that aren't among the values (the display's own inputs)
65
- * @param {{ salt: string, get: (k: string) => string | undefined, put: (k: string, text: string) => void } | null} [stages] where a lamina's slow stages are kept: the child reads them from the cache (it may read the workspace) and hands back what it made, which is written here
66
- * @param {{ frames?: object, fixings?: { sets?: object, printer?: object, material?: string | null } | null }} [bound] what the design's helpers are bound to: frames, the workspace's profile sets (lib/frames.mjs framesContext); fixings, what v.fixings is bound to (design.mjs fixingsContext), whose calls come back as fixings
194
+ * Run a design's main(values) in the sandbox: { parts, read, mechanism, fixings } as the build makes them, and for a
195
+ * board design (board set) its { board: { circuit, matrix?, source? }, mounted } too, parts empty: the tool makes the
196
+ * board's solid from its circuit.
197
+ * The design shares the runner's process and can print anything, so every field of the reply is checked as untrusted
198
+ * input (checkReply), and only stage and route files of the caches are written from it.
199
+ * @param {object} request
200
+ * @param {{ js: string }} request.d the design
201
+ * @param {object} request.values @param {object} request.meta the .json's parts
202
+ * @param {'jscad' | 'manifold'} [request.engine] v.ops's booleans
203
+ * @param {string[]} [request.optional] names main may read that aren't among the values (the display's own inputs)
204
+ * @param {{ salt: string, get: (k: string) => string | undefined, put: (k: string, text: string) => void } | null} [request.stages] where a lamina's slow stages are kept: the child reads them from the cache (it may read the workspace) and hands back what it made, which is written here
205
+ * @param {{ frames?: object, fixings?: { sets?: object, printer?: object, material?: string | null } | null }} [request.bound] what the design's helpers are bound to: frames, the workspace's profile sets (lib/frames.mjs framesContext); fixings, what v.fixings is bound to (design.mjs fixingsContext), whose calls come back as fixings. A board's v.pcb.mount reads fixings.sets too
206
+ * @param {{ routes?: { dir: string, put: (k: string, text: string) => void } | null } | null} [request.board] set for a board design (engine pcb): routes, where the autorouter's results are kept (the child reads the folder; what it routes is handed back and put here)
207
+ * @param {string[]} [request.read] more folders the sandbox may read (a copy of a workspace held in memory)
208
+ * @returns {Promise<{ parts: object[], read: Set<string>, mechanism: object | null, fixings: object[] | null, board?: { circuit: object[], matrix?: object, source?: object }, mounted?: boolean }>}
67
209
  */
68
- export function runSandboxed(d, values, meta, engine = 'jscad', optional = [], stages = null, bound = {}) {
210
+ export function runSandboxed({ d, values, meta, engine = 'jscad', optional = [], stages = null, bound = {}, board = null, read: more = [] }) {
69
211
  const here = path.dirname(fileURLToPath(import.meta.url));
70
- const args = [flag, ...readable().map((p) => `--allow-fs-read=${p}`), ...(inThread ? [] : ['--allow-worker']), '--import', pathToFileURL(path.join(here, 'sandbox-preload.mjs')).href, path.join(here, 'sandbox-run.mjs')];
212
+ const routes = board?.routes?.dir ? [path.resolve(board.routes.dir)] : []; // (a route cache the user put outside the workspace, RULECAD_ROUTE_CACHE: read there, or every build routes again)
213
+ const args = [flag, ...readable({ board: !!board, extra: [...more, ...routes] }).map((p) => `--allow-fs-read=${p}`), ...(inThread ? [] : ['--allow-worker']), '--import', pathToFileURL(path.join(here, 'sandbox-preload.mjs')).href, path.join(here, 'sandbox-run.mjs')];
71
214
  // (real paths: Node names an imported file by where it really is, so a workspace reached through a link still matches)
72
215
  const js = fs.realpathSync(d.js), project = pathToFileURL(path.dirname(path.dirname(js)) + path.sep).href, stagesDir = paths.cache('stages');
73
216
  // The child gets none of this process's environment but what Node needs to start: tokens and keys stay out of it
@@ -84,10 +227,15 @@ export function runSandboxed(d, values, meta, engine = 'jscad', optional = [], s
84
227
  return reject(located(new Error(`the design's sandbox stopped: ${Buffer.concat(err).toString('utf8').trim().split('\n').slice(-3).join(' ') || 'no output'}`), d.js, 'design.sandbox'));
85
228
  }
86
229
  if (err.length) process.stderr.write(Buffer.concat(err)); // what the design printed
230
+ const wrong = checkReply(r) || (!board && r.board != null ? 'it has a board, and the design is not one' : board && r.board == null && !r.error ? 'a board design\'s reply has no board' : null); // (every field is untrusted: see checkReply)
231
+ if (wrong) return reject(located(new Error(`the design's reply was not one rulecad makes (${wrong}), so none of it was used and nothing it sent was written. A design gives back its shapes from main(v); one that writes to the process's output itself or ends the process is refused`), d.js, 'design.sandbox'));
87
232
  if (r.error) return reject(located(Object.assign(new Error(refused(r.error)), { code: r.error.code, ...(r.error.line ? { line: r.error.line } : {}), ...(r.error.syntax ? { name: 'SyntaxError' } : {}) }), d.js, r.error.code || 'design.run'));
88
233
  if (stages) for (const [k, text] of Object.entries(r.stages || {})) stages.put(k, text);
89
- resolve({ parts: r.parts.map(({ solid, ...p }) => ({ ...p, geometry: fromFaces(solid) })), read: new Set(r.read), mechanism: r.mechanism || null, fixings: r.fixings || null });
234
+ if (board?.routes) for (const [k, text] of Object.entries(r.routes || {})) board.routes.put(k, text);
235
+ resolve({ parts: r.parts.map(({ solid, ...p }) => ({ ...p, geometry: fromFaces(solid) })), read: new Set(r.read), mechanism: r.mechanism || null, fixings: r.fixings || null,
236
+ ...(board ? { board: r.board, mounted: r.mounted === true } : {}) });
90
237
  });
91
- child.stdin.end(JSON.stringify({ js: `${pathToFileURL(js).href}?t=${fs.statSync(js).mtimeMs}`, values, meta, engine, optional, ...(stages ? { stages: { dir: stagesDir, salt: stages.salt } } : {}), bound }));
238
+ child.stdin.end(JSON.stringify({ js: `${pathToFileURL(js).href}?t=${fs.statSync(js).mtimeMs}`, values, meta, engine, optional, ...(stages ? { stages: { dir: stagesDir, salt: stages.salt } } : {}), bound,
239
+ ...(board ? { board: { ...(board.routes ? { routes: path.resolve(board.routes.dir) } : {}) } } : {}) }));
92
240
  });
93
241
  }
package/lib/schema.mjs CHANGED
@@ -37,7 +37,8 @@ export function validate(value, s, root = s, at = '') {
37
37
  if (!types.some((t) => fits(value, t))) return [{ path: here, message: `should be ${types.join(' or ')}, not ${typeOf(value)}` }];
38
38
  }
39
39
  if (s.enum && !s.enum.includes(value)) out.push({ path: here, message: `should be one of ${s.enum.map((x) => JSON.stringify(x)).join(', ')} (got ${JSON.stringify(value)})` });
40
- if (s.pattern && typeof value === 'string' && !new RegExp(s.pattern).test(value)) out.push({ path: here, message: `"${value}" isn't in the expected form (${s.pattern})` });
40
+ // (a pattern with a description says what it wants in words; one without, the pattern itself)
41
+ if (s.pattern && typeof value === 'string' && !new RegExp(s.pattern).test(value)) out.push({ path: here, message: `"${value}" isn't in the expected form: ${s.description || s.pattern}` });
41
42
  if (typeOf(value) === 'object') {
42
43
  for (const k of s.required || []) if (!(k in value)) out.push({ path: here, message: `needs "${k}"` });
43
44
  const props = s.properties || {};
package/lib/targets.mjs CHANGED
@@ -1,22 +1,40 @@
1
- // Targets: optional extras the command hands work to, named in cad.config.json's "targets". A name is one of lib/targets/
2
- // (gist) or a module path relative to the workspace, so anyone can add their own (a smart mirror, a slicer, a printer).
1
+ // Targets: optional extras the command hands work to, named in cad.config.json's "targets". A name is either exactly one
2
+ // of the kit's own (OWN_TARGETS in workspace.mjs: today only "gist"), or a module path inside the workspace, so anyone
3
+ // can add their own (a smart mirror, a slicer, a printer). Every name but the kit's own is the workspace's code: it runs
4
+ // in the tool's process, so only once the workspace is trusted (cad trust), and never from outside the workspace. No
5
+ // path is ever made from a name to find one of the kit's own.
3
6
  // show: export async function show({ title, ttl, mesh, card }) puts a model somewhere to look at.
4
7
  // mesh: { polygons } (one solid) or { shapes, place } (each shape once, then a 3 × 4 transform per copy);
5
8
  // card: { title, items } (short lines) to go with it
6
9
  // shorten: export async function shorten(data, { desc }) stores a model link's data and returns an ID for #s=<id>
7
- import fs from 'node:fs';
8
10
  import path from 'node:path';
9
11
  import { pathToFileURL } from 'node:url';
10
- import { WS, config, needTrust } from './workspace.mjs';
12
+ import { WS, config, needTrust, isOwnTarget, OWN_TARGETS } from './workspace.mjs';
11
13
 
14
+ /** Whether cad.config.json names a target of this kind ("show", "shorten"). */
12
15
  export const hasTarget = (kind) => !!config.targets?.[kind];
13
16
 
17
+ /**
18
+ * The function a target of this kind exports, loaded: one of the kit's own by its exact name, else the workspace's own
19
+ * module, once the workspace is trusted and only from inside it.
20
+ * @param {string} kind "show" or "shorten"
21
+ * @returns {Promise<Function>}
22
+ */
14
23
  export async function target(kind) {
15
24
  const name = config.targets?.[kind];
16
25
  if (!name) throw new Error(`no "${kind}" target: name one in cad.config.json ("targets": { "${kind}": … })`);
17
- const own = new URL(`./targets/${name}.mjs`, import.meta.url);
18
- if (!fs.existsSync(own)) needTrust(); // (the workspace's own code, run in the tool's process: only once it is trusted)
19
- const mod = await import(fs.existsSync(own) ? own : pathToFileURL(path.resolve(WS, name)).href);
26
+ let href;
27
+ if (isOwnTarget(name)) href = OWN_TARGETS[name];
28
+ else {
29
+ needTrust(); // (the workspace's own code, run in the tool's process: only once it is trusted)
30
+ if (typeof name !== 'string') throw new Error(`the ${kind} target in cad.config.json should be the name of a module file, not ${JSON.stringify(name)}`);
31
+ const file = path.resolve(WS, name), rel = path.relative(WS, file);
32
+ if (!rel || rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) {
33
+ throw Object.assign(new Error(`the ${kind} target ${name} (cad.config.json) is outside this workspace (${WS}), so it isn't run. Put the module in the workspace's folder and name it from there`), { code: 'workspace.outside' });
34
+ }
35
+ href = pathToFileURL(file).href;
36
+ }
37
+ const mod = await import(href);
20
38
  if (typeof mod[kind] !== 'function') throw new Error(`target ${name} has no ${kind}()`);
21
39
  return mod[kind];
22
40
  }
package/lib/versions.mjs CHANGED
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
11
11
  import crypto from 'node:crypto';
12
12
  import { resolve, loadRuleSet } from './rules.mjs';
13
13
  import { WS, paths } from './workspace.mjs';
14
+ import { plainName, isPlainName } from './names.mjs';
14
15
  import { readLayout, hasLayout } from './layout.mjs';
15
16
  import { newer } from '@rulecad/versions';
16
17
 
@@ -57,10 +58,11 @@ export function materialise(d, version) {
57
58
  const js = path.join(base, `${d.name}.js`), json = path.join(base, `${d.name}.json`);
58
59
  fs.writeFileSync(js, show(rel(d.js)));
59
60
  fs.writeFileSync(json, JSON.stringify(object, null, 2));
60
- for (const u of (object.uses || []).filter((x) => !x.includes('/'))) fs.writeFileSync(path.join(base, 'rules', `${u}.json`), show(`rules/${u}.json`)); // objects it reads are released on their own
61
+ // (names from the release's own file, each written as a file here: plain names only, never ../)
62
+ for (const u of (object.uses || []).filter((x) => !x.includes('/'))) fs.writeFileSync(path.join(base, 'rules', `${plainName(u, 'rule set name', `${tag}'s ${d.name}.json, in its "uses"`)}.json`), show(`rules/${u}.json`)); // objects it reads are released on their own
61
63
  // The layouts it could pick, as they were then (only files that existed in that release)
62
64
  fs.mkdirSync(path.join(base, 'layouts'), { recursive: true });
63
- for (const v of Object.values(object.variables || {})) if (v.type === 'layout') for (const n of v.choice || [v.value]) {
65
+ for (const v of Object.values(object.variables || {})) if (v.type === 'layout') for (const n of (v.choice || [v.value]).filter(isPlainName)) { // (another name is refused where the layout is read)
64
66
  try { fs.writeFileSync(path.join(base, 'layouts', `${n}.json`), show(`projects/${d.project}/layouts/${n}.json`)); } catch {} // a built-in (grid)
65
67
  }
66
68
  return { ...d, js, json, rulesDir: path.join(base, 'rules'), layoutsDir: path.join(base, 'layouts'), version, tag };
@@ -84,7 +86,7 @@ const engineLibs = () => ENGINE_LIBS.map((n) => `${n}@${packageVersion(n, import
84
86
  const engineHash = (code) => crypto.createHash('sha256').update(`${code.trimEnd()}\n${engineLibs()}`).digest('hex').slice(0, 16);
85
87
  // The board engine's code: @rulecad/pcb's modules, and @rulecad/smooth's, which a board's build runs too (smoothing its
86
88
  // tracks, finishing them): a change to either is a change to what a board builds, so it must miss the cache
87
- const sources = (dir) => fs.readdirSync(dir).filter((f) => f.endsWith('.mjs') && f !== 'test.mjs').sort().map((f) => fs.readFileSync(path.join(dir, f), 'utf8')).join('\n');
89
+ const sources = (dir) => fs.readdirSync(dir).filter((f) => f.endsWith('.mjs') && f !== 'test.mjs' && !f.startsWith('.')).sort().map((f) => fs.readFileSync(path.join(dir, f), 'utf8')).join('\n');
88
90
  export const engineId = () => {
89
91
  const pcb = import.meta.resolve('@rulecad/pcb'), dir = path.dirname(fileURLToPath(pcb));
90
92
  const smooth = path.dirname(createRequire(pcb).resolve('@rulecad/smooth'));