@shiqianjiang/ceru-plugin-issuer 0.2.2 → 0.2.3

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 (2) hide show
  1. package/dist/index.js +48 -7
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -128,6 +128,7 @@ export const MANIFEST_SCHEMA = object({
128
128
  author: string,
129
129
  publisher: string,
130
130
  license: string,
131
+ homepage: string,
131
132
  config: { type: 'object', additionalProperties: true },
132
133
  engines: object({
133
134
  hostApi: string,
@@ -258,6 +259,7 @@ export const MANIFEST_SCHEMA = object({
258
259
  id,
259
260
  name: string,
260
261
  protocols: strings,
262
+ qualities: strings,
261
263
  connectionMode: { enum: ['none', 'single', 'multiple'] },
262
264
  icon: {
263
265
  oneOf: [
@@ -609,6 +611,35 @@ function inspectBody(body, manifest) {
609
611
  let registry;
610
612
  const preamble = [];
611
613
  const functions = new Map();
614
+ const bindings = new Map();
615
+ const selfContained = new Set();
616
+ const staticOrReference = (node, depth = 0) => {
617
+ ensure(depth <= 64, 'Static export nesting exceeds 64');
618
+ if (node.type === 'Identifier' || node.type === 'Literal')
619
+ return;
620
+ if (node.type === 'UnaryExpression' &&
621
+ node.operator === '-' &&
622
+ node.argument.type === 'Literal')
623
+ return;
624
+ if (node.type === 'ArrayExpression') {
625
+ for (const item of node.elements) {
626
+ ensure(item, 'Array holes are forbidden');
627
+ staticOrReference(item, depth + 1);
628
+ }
629
+ return;
630
+ }
631
+ for (const [, child] of astObject(node))
632
+ staticOrReference(child, depth + 1);
633
+ };
634
+ const resolveBinding = (node) => {
635
+ const seen = new Set();
636
+ while (node?.type === 'Identifier' && bindings.has(node.name)) {
637
+ ensure(!seen.has(node.name), 'Circular top-level binding: ' + node.name);
638
+ seen.add(node.name);
639
+ node = bindings.get(node.name);
640
+ }
641
+ return node;
642
+ };
612
643
  let sourceFormat = 'exports-v2';
613
644
  if (tree.body.length === 1 &&
614
645
  tree.body[0].type === 'ExpressionStatement' &&
@@ -645,9 +676,15 @@ function inspectBody(body, manifest) {
645
676
  const isStatic = init && ['Literal', 'ObjectExpression', 'ArrayExpression'].includes(init.type);
646
677
  ensure(isFunction || isRequire || isStatic, 'Top-level variables must be static data, functions, or require() imports');
647
678
  if (isStatic)
648
- astJson(init);
649
- if (declaration.id.type === 'Identifier' && isFunction)
650
- functions.set(declaration.id.name, init);
679
+ staticOrReference(init);
680
+ if (declaration.id.type === 'Identifier') {
681
+ bindings.set(declaration.id.name, init);
682
+ if (isFunction) {
683
+ functions.set(declaration.id.name, init);
684
+ if (body.slice(declaration.id.end, init.start).includes('@ceru-self-contained'))
685
+ selfContained.add(declaration.id.name);
686
+ }
687
+ }
651
688
  }
652
689
  preamble.push(body.slice(statement.start, statement.end));
653
690
  continue;
@@ -675,21 +712,24 @@ function inspectBody(body, manifest) {
675
712
  value: node,
676
713
  });
677
714
  if (exported.has('modules'))
678
- for (const [key, node] of astObject(exported.get('modules')))
715
+ for (const [key, node] of astObject(resolveBinding(exported.get('modules'))))
679
716
  addModule(key, node);
680
717
  if (exported.has('activate')) {
681
718
  ensure(manifest.modules.logic, 'activate requires modules.logic');
682
719
  addModule(manifest.modules.logic.entry, exported.get('activate'));
683
720
  }
684
721
  if (exported.has('surfaces'))
685
- for (const [id, node] of astObject(exported.get('surfaces'))) {
722
+ for (const [id, node] of astObject(resolveBinding(exported.get('surfaces')))) {
686
723
  const surface = manifest.modules.surfaces?.find((item) => item.id === id && item.kind === 'web');
687
724
  ensure(surface, 'Unknown visible surface: ' + id);
688
725
  addModule(surface.entry, node);
689
726
  }
690
727
  registry = new Map([
691
728
  ['modules', { type: 'ObjectExpression', properties }],
692
- ['resources', exported.get('resources') ?? { type: 'ObjectExpression', properties: [] }],
729
+ [
730
+ 'resources',
731
+ resolveBinding(exported.get('resources')) ?? { type: 'ObjectExpression', properties: [] },
732
+ ],
693
733
  ]);
694
734
  }
695
735
  const modules = Object.create(null);
@@ -701,7 +741,8 @@ function inspectBody(body, manifest) {
701
741
  !node.generator &&
702
742
  node.params.length <= 1 &&
703
743
  (!node.params.length || node.params[0].type === 'Identifier'), 'Module must be a function with one context parameter');
704
- modules[key] = preamble.length
744
+ const generatedEntry = exportedNode.type === 'Identifier' && selfContained.has(exportedNode.name);
745
+ modules[key] = preamble.length && !generatedEntry
705
746
  ? 'async function(ctx) {\n' +
706
747
  preamble.join('\n') +
707
748
  '\nreturn (' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiqianjiang/ceru-plugin-issuer",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Static verification, Ed25519 signing and cached personalized issuance of Ceru single-JS plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "node": ">=22.12.0"
24
24
  },
25
25
  "dependencies": {
26
- "@shiqianjiang/ceru-plugin-sdk": "0.2.2",
26
+ "@shiqianjiang/ceru-plugin-sdk": "0.2.3",
27
27
  "acorn": "^8.18.0",
28
28
  "ajv": "^8.20.0"
29
29
  },