@jigging/jig 0.1.0-alpha.10 → 0.1.0-alpha.12

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.
@@ -1783,6 +1783,18 @@ function normalizeJig(input, canonical) {
1783
1783
  function defineBinding(input) {
1784
1784
  return normalizeBinding(input, false);
1785
1785
  }
1786
+ function flowRef(path) {
1787
+ return record({
1788
+ kind: "flow",
1789
+ path: normalizeProjectPath(path, "Flow reference")
1790
+ });
1791
+ }
1792
+ function bindingRef(id) {
1793
+ return record({
1794
+ kind: "binding",
1795
+ id: validateLocalName(id, "Binding reference")
1796
+ });
1797
+ }
1786
1798
  function normalizeBinding(input, canonical) {
1787
1799
  const captured = snapshotJsonObject(input, "Binding definition");
1788
1800
  assertClosedObject(captured, canonical ? ["kind", "package", "settings", "slots"] : ["package", "settings", "slots"], "Binding definition");
@@ -1794,7 +1806,12 @@ function normalizeBinding(input, canonical) {
1794
1806
  const packagePath = normalizeProjectPath(captured.package, "package");
1795
1807
  const settings = Object.hasOwn(captured, "settings") ? expectJsonObject(captured.settings, "settings") : emptyRecord();
1796
1808
  const slots = Object.hasOwn(captured, "slots") ? normalizeFlowSlots(captured.slots) : emptyRecord();
1797
- return record({ kind: "package", package: packagePath, settings, slots });
1809
+ return record({
1810
+ kind: "package",
1811
+ package: packagePath,
1812
+ settings,
1813
+ slots
1814
+ });
1798
1815
  }
1799
1816
  function normalizeFlowSlots(value) {
1800
1817
  const input = snapshotJsonObject(value, "slots");
@@ -1804,10 +1821,20 @@ function normalizeFlowSlots(value) {
1804
1821
  const output = Object.create(null);
1805
1822
  for (const name of Object.keys(input).sort(compareUtf8)) {
1806
1823
  validateLocalName(name, "slot name");
1807
- output[name] = normalizeProjectPath(input[name], `slot ${name}`);
1824
+ const target = parseRunTargetSelector(input[name], `slot ${name}`);
1825
+ output[name] = target.kind === "flow" ? `flow:${target.path}` : `binding:${target.id}`;
1808
1826
  }
1809
1827
  return Object.freeze(output);
1810
1828
  }
1829
+ function parseRunTargetSelector(value, label) {
1830
+ if (typeof value !== "string")
1831
+ throw new TypeError(`${label} must be a target selector`);
1832
+ if (value.startsWith("flow:"))
1833
+ return flowRef(normalizeProjectPath(value.slice(5), label));
1834
+ if (value.startsWith("binding:"))
1835
+ return bindingRef(validateLocalName(value.slice(8), label));
1836
+ throw new TypeError(`${label} must select flow:<path> or binding:<id>`);
1837
+ }
1811
1838
  function normalizeSource(value, field, canonical) {
1812
1839
  if (value === undefined)
1813
1840
  throw new TypeError(`${field} cannot be undefined`);
@@ -240,65 +240,67 @@ async function build(request) {
240
240
  target: "bun",
241
241
  write: false,
242
242
  sourcemap: "none",
243
- plugins: [{
244
- name: "jig-closed-author-module",
245
- setup(builder) {
246
- builder.onResolve({ filter: /^jig-author:bridge$/ }, (arguments_) => {
247
- if (arguments_.kind !== "entry-point-build" || arguments_.importer !== "") {
243
+ plugins: [
244
+ {
245
+ name: "jig-closed-author-module",
246
+ setup(builder) {
247
+ builder.onResolve({ filter: /^jig-author:bridge$/ }, (arguments_) => {
248
+ if (arguments_.kind !== "entry-point-build" || arguments_.importer !== "") {
249
+ throw deniedImport(arguments_.path);
250
+ }
251
+ return { path: arguments_.path, namespace: "jig-author" };
252
+ });
253
+ builder.onResolve({ filter: /^jig-author:entry$/ }, (arguments_) => {
254
+ if (arguments_.kind !== "import-statement" || arguments_.importer !== "jig-author:bridge") {
255
+ throw deniedImport(arguments_.path);
256
+ }
257
+ return { path: request.entryProjectPath, namespace: "jig-project" };
258
+ });
259
+ builder.onResolve({ filter: /^jig-author:/ }, (arguments_) => {
248
260
  throw deniedImport(arguments_.path);
249
- }
250
- return { path: arguments_.path, namespace: "jig-author" };
251
- });
252
- builder.onResolve({ filter: /^jig-author:entry$/ }, (arguments_) => {
253
- if (arguments_.kind !== "import-statement" || arguments_.importer !== "jig-author:bridge") {
261
+ });
262
+ builder.onLoad({ filter: /^jig-author:bridge$/, namespace: "jig-author" }, () => ({
263
+ loader: "ts",
264
+ contents: bridge
265
+ }));
266
+ builder.onResolve({ filter: /^@jigging\/jig$/ }, (arguments_) => {
267
+ if (arguments_.kind !== "import-statement" || !modules.has(arguments_.importer)) {
268
+ throw deniedImport(arguments_.path);
269
+ }
270
+ return { path: "sdk", namespace: "jig-sealed" };
271
+ });
272
+ builder.onLoad({ filter: /^sdk$/, namespace: "jig-sealed" }, () => ({
273
+ loader: "js",
274
+ contents: sdkSource
275
+ }));
276
+ builder.onResolve({ filter: /.*/, namespace: "jig-sealed" }, (arguments_) => {
254
277
  throw deniedImport(arguments_.path);
255
- }
256
- return { path: request.entryProjectPath, namespace: "jig-project" };
257
- });
258
- builder.onResolve({ filter: /^jig-author:/ }, (arguments_) => {
259
- throw deniedImport(arguments_.path);
260
- });
261
- builder.onLoad({ filter: /^jig-author:bridge$/, namespace: "jig-author" }, () => ({
262
- loader: "ts",
263
- contents: bridge
264
- }));
265
- builder.onResolve({ filter: /^@jigging\/jig$/ }, (arguments_) => {
266
- if (arguments_.kind !== "import-statement" || !modules.has(arguments_.importer)) {
278
+ });
279
+ builder.onResolve({ filter: /.*/ }, (arguments_) => {
280
+ if (arguments_.kind !== "import-statement") {
281
+ throw deniedImport(`${arguments_.path} (${arguments_.kind} from ${arguments_.importer})`);
282
+ }
283
+ if (!modules.has(arguments_.importer)) {
284
+ throw deniedImport(`${arguments_.path} (from ${arguments_.importer})`);
285
+ }
286
+ const target = edges.get(`${arguments_.importer}\x00${arguments_.path}`);
287
+ if (target === undefined || !modules.has(target)) {
288
+ throw deniedImport(`${arguments_.path} (from ${arguments_.importer})`);
289
+ }
290
+ return { path: target, namespace: "jig-project" };
291
+ });
292
+ builder.onLoad({ filter: /.*/, namespace: "jig-project" }, (arguments_) => {
293
+ const module = modules.get(arguments_.path);
294
+ if (module === undefined)
295
+ return;
296
+ return { loader: "ts", contents: module.source };
297
+ });
298
+ builder.onResolve({ filter: /.*/, namespace: "jig-author" }, (arguments_) => {
267
299
  throw deniedImport(arguments_.path);
268
- }
269
- return { path: "sdk", namespace: "jig-sealed" };
270
- });
271
- builder.onLoad({ filter: /^sdk$/, namespace: "jig-sealed" }, () => ({
272
- loader: "js",
273
- contents: sdkSource
274
- }));
275
- builder.onResolve({ filter: /.*/, namespace: "jig-sealed" }, (arguments_) => {
276
- throw deniedImport(arguments_.path);
277
- });
278
- builder.onResolve({ filter: /.*/ }, (arguments_) => {
279
- if (arguments_.kind !== "import-statement") {
280
- throw deniedImport(`${arguments_.path} (${arguments_.kind} from ${arguments_.importer})`);
281
- }
282
- if (!modules.has(arguments_.importer)) {
283
- throw deniedImport(`${arguments_.path} (from ${arguments_.importer})`);
284
- }
285
- const target = edges.get(`${arguments_.importer}\x00${arguments_.path}`);
286
- if (target === undefined || !modules.has(target)) {
287
- throw deniedImport(`${arguments_.path} (from ${arguments_.importer})`);
288
- }
289
- return { path: target, namespace: "jig-project" };
290
- });
291
- builder.onLoad({ filter: /.*/, namespace: "jig-project" }, (arguments_) => {
292
- const module = modules.get(arguments_.path);
293
- if (module === undefined)
294
- return;
295
- return { loader: "ts", contents: module.source };
296
- });
297
- builder.onResolve({ filter: /.*/, namespace: "jig-author" }, (arguments_) => {
298
- throw deniedImport(arguments_.path);
299
- });
300
+ });
301
+ }
300
302
  }
301
- }]
303
+ ]
302
304
  });
303
305
  } catch (error) {
304
306
  const message = boundedMessage(error);
@@ -417,7 +419,10 @@ function boundedMessage(error) {
417
419
  let message;
418
420
  try {
419
421
  if (error instanceof AggregateError) {
420
- message = [error.message, ...error.errors.map((item) => item instanceof Error ? item.message : String(item))].join(": ");
422
+ message = [
423
+ error.message,
424
+ ...error.errors.map((item) => item instanceof Error ? item.message : String(item))
425
+ ].join(": ");
421
426
  } else {
422
427
  message = error instanceof Error ? error.message : String(error);
423
428
  }