@wix/validation-infra 0.0.0-stage → 0.5.1

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 (152) hide show
  1. package/README.md +192 -2
  2. package/dist/constants.d.ts +29 -0
  3. package/dist/constants.js +45 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.js +13 -0
  6. package/dist/package-readers/constants.d.ts +6 -0
  7. package/dist/package-readers/constants.js +6 -0
  8. package/dist/package-readers/index.d.ts +1 -0
  9. package/dist/package-readers/index.js +1 -0
  10. package/dist/package-readers/read-from-files.d.ts +6 -0
  11. package/dist/package-readers/read-from-files.js +76 -0
  12. package/dist/package-readers/types.d.ts +7 -0
  13. package/dist/package-readers/types.js +1 -0
  14. package/dist/package-readers/utils.d.ts +4 -0
  15. package/dist/package-readers/utils.js +15 -0
  16. package/dist/page-model/build-page-model.d.ts +3 -0
  17. package/dist/page-model/build-page-model.js +12 -0
  18. package/dist/page-model/connect-css.d.ts +3 -0
  19. package/dist/page-model/connect-css.js +43 -0
  20. package/dist/page-model/constants.d.ts +17 -0
  21. package/dist/page-model/constants.js +17 -0
  22. package/dist/page-model/css-selectors.d.ts +2 -0
  23. package/dist/page-model/css-selectors.js +7 -0
  24. package/dist/page-model/index.d.ts +4 -0
  25. package/dist/page-model/index.js +4 -0
  26. package/dist/page-model/pages.d.ts +2 -0
  27. package/dist/page-model/pages.js +18 -0
  28. package/dist/page-model/read-css.d.ts +4 -0
  29. package/dist/page-model/read-css.js +98 -0
  30. package/dist/page-model/read-structure.d.ts +3 -0
  31. package/dist/page-model/read-structure.js +59 -0
  32. package/dist/page-model/read-theme.d.ts +6 -0
  33. package/dist/page-model/read-theme.js +14 -0
  34. package/dist/page-model/types.d.ts +92 -0
  35. package/dist/page-model/types.js +1 -0
  36. package/dist/page-model/utils.d.ts +16 -0
  37. package/dist/page-model/utils.js +29 -0
  38. package/dist/project-model/index.d.ts +5 -0
  39. package/dist/project-model/index.js +5 -0
  40. package/dist/project-model/menu-files.d.ts +4 -0
  41. package/dist/project-model/menu-files.js +14 -0
  42. package/dist/project-model/package-json.d.ts +5 -0
  43. package/dist/project-model/package-json.js +27 -0
  44. package/dist/project-model/popups.d.ts +4 -0
  45. package/dist/project-model/popups.js +12 -0
  46. package/dist/project-model/project-model.d.ts +4 -0
  47. package/dist/project-model/project-model.js +14 -0
  48. package/dist/project-model/types.d.ts +20 -0
  49. package/dist/project-model/types.js +2 -0
  50. package/dist/rules/index.d.ts +4 -0
  51. package/dist/rules/index.js +5 -0
  52. package/dist/rules/project/define-project-rule.d.ts +5 -0
  53. package/dist/rules/project/define-project-rule.js +4 -0
  54. package/dist/rules/project/index.d.ts +2 -0
  55. package/dist/rules/project/index.js +2 -0
  56. package/dist/rules/project/types.d.ts +16 -0
  57. package/dist/rules/project/types.js +1 -0
  58. package/dist/rules/site-app/define-rule.d.ts +5 -0
  59. package/dist/rules/site-app/define-rule.js +4 -0
  60. package/dist/rules/site-app/index.d.ts +2 -0
  61. package/dist/rules/site-app/index.js +1 -0
  62. package/dist/rules/site-app/types.d.ts +26 -0
  63. package/dist/rules/site-app/types.js +1 -0
  64. package/dist/rules/site-code/define-site-code-rule.d.ts +5 -0
  65. package/dist/rules/site-code/define-site-code-rule.js +4 -0
  66. package/dist/rules/site-code/index.d.ts +2 -0
  67. package/dist/rules/site-code/index.js +2 -0
  68. package/dist/rules/site-code/types.d.ts +11 -0
  69. package/dist/rules/site-code/types.js +1 -0
  70. package/dist/rules/types.d.ts +13 -0
  71. package/dist/rules/types.js +3 -0
  72. package/dist/rules-adapter/eslint/index.d.ts +1 -0
  73. package/dist/rules-adapter/eslint/index.js +1 -0
  74. package/dist/rules-adapter/eslint/types.d.ts +5 -0
  75. package/dist/rules-adapter/eslint/types.js +1 -0
  76. package/dist/rules-adapter/index.d.ts +2 -0
  77. package/dist/rules-adapter/index.js +2 -0
  78. package/dist/rules-adapter/types.d.ts +16 -0
  79. package/dist/rules-adapter/types.js +1 -0
  80. package/dist/rules-adapter/utils.d.ts +7 -0
  81. package/dist/rules-adapter/utils.js +20 -0
  82. package/dist/rules-api/component-catalog.d.ts +8 -0
  83. package/dist/rules-api/component-catalog.js +28 -0
  84. package/dist/rules-api/constants.d.ts +7 -0
  85. package/dist/rules-api/constants.js +7 -0
  86. package/dist/rules-api/index.d.ts +18 -0
  87. package/dist/rules-api/index.js +14 -0
  88. package/dist/rules-api/report.d.ts +8 -0
  89. package/dist/rules-api/report.js +13 -0
  90. package/dist/rules-api/rules-api.d.ts +13 -0
  91. package/dist/rules-api/rules-api.js +139 -0
  92. package/dist/rules-api/types.d.ts +141 -0
  93. package/dist/rules-api/types.js +1 -0
  94. package/dist/rules-api/utils.d.ts +14 -0
  95. package/dist/rules-api/utils.js +27 -0
  96. package/dist/shared/constants.d.ts +188 -0
  97. package/dist/shared/constants.js +242 -0
  98. package/dist/shared/css-variables.d.ts +9 -0
  99. package/dist/shared/css-variables.js +38 -0
  100. package/dist/shared/css.d.ts +78 -0
  101. package/dist/shared/css.js +426 -0
  102. package/dist/shared/element-match.d.ts +16 -0
  103. package/dist/shared/element-match.js +72 -0
  104. package/dist/shared/font-weights.d.ts +2 -0
  105. package/dist/shared/font-weights.js +551 -0
  106. package/dist/shared/index.d.ts +16 -0
  107. package/dist/shared/index.js +15 -0
  108. package/dist/shared/interactions-config.d.ts +15 -0
  109. package/dist/shared/interactions-config.js +120 -0
  110. package/dist/shared/links.d.ts +21 -0
  111. package/dist/shared/links.js +93 -0
  112. package/dist/shared/posix-path.d.ts +8 -0
  113. package/dist/shared/posix-path.js +27 -0
  114. package/dist/shared/site-files-tree-mapping.d.ts +40 -0
  115. package/dist/shared/site-files-tree-mapping.js +41 -0
  116. package/dist/shared/site-folders.d.ts +3 -0
  117. package/dist/shared/site-folders.js +17 -0
  118. package/dist/shared/site-media.d.ts +3 -0
  119. package/dist/shared/site-media.js +11 -0
  120. package/dist/shared/syntax-tree.d.ts +4 -0
  121. package/dist/shared/syntax-tree.js +30 -0
  122. package/dist/shared/transformation-values.d.ts +22 -0
  123. package/dist/shared/transformation-values.js +74 -0
  124. package/dist/shared/types.d.ts +477 -0
  125. package/dist/shared/types.js +1 -0
  126. package/dist/shared/utils.d.ts +155 -0
  127. package/dist/shared/utils.js +553 -0
  128. package/dist/shared/wrapper-contract.d.ts +31 -0
  129. package/dist/shared/wrapper-contract.js +157 -0
  130. package/dist/shared/wrapper-image-props.d.ts +3 -0
  131. package/dist/shared/wrapper-image-props.js +75 -0
  132. package/dist/site-code-model/constants.d.ts +107 -0
  133. package/dist/site-code-model/constants.js +102 -0
  134. package/dist/site-code-model/index.d.ts +3 -0
  135. package/dist/site-code-model/index.js +4 -0
  136. package/dist/site-code-model/manifest-values.d.ts +15 -0
  137. package/dist/site-code-model/manifest-values.js +88 -0
  138. package/dist/site-code-model/read-module.d.ts +4 -0
  139. package/dist/site-code-model/read-module.js +267 -0
  140. package/dist/site-code-model/read-site-code-model.d.ts +9 -0
  141. package/dist/site-code-model/read-site-code-model.js +42 -0
  142. package/dist/site-code-model/source-locations.d.ts +5 -0
  143. package/dist/site-code-model/source-locations.js +95 -0
  144. package/dist/site-code-model/types.d.ts +102 -0
  145. package/dist/site-code-model/types.js +1 -0
  146. package/dist/testing.d.ts +24 -0
  147. package/dist/testing.js +61 -0
  148. package/dist/types.d.ts +95 -0
  149. package/dist/types.js +1 -0
  150. package/dist/validate.d.ts +7 -0
  151. package/dist/validate.js +180 -0
  152. package/package.json +59 -3
@@ -0,0 +1,157 @@
1
+ // A wrapper's allowed CSS overrides, from its component-contract.json (component-wrapper-server erc/componentContract.ts), or, for a wrapper
2
+ // installed before it shipped one, from its defaults.css: the comment after "Allowed CSS overrides" (erc/defaultsCss.ts). The first block is
3
+ // the component's own; a state block (`.label.button__label--hover`, a native state's `.label:hover`) counts as its element's (`.label`).
4
+ // A component-contract.json also lists its elements' custom enums (revision 23) and typed vars (revision 25); a nested component's root ones
5
+ // come from its own type's contract (`refElements` names it).
6
+ import { ALLOWED_MARKER, COMPONENT_CONTRACT_JSON, CONTRACT_BLOCK, CONTRACT_PROPERTY, ELEMENT_SELECTOR, NESTED_COMPONENT, NO_CONTRACT_VARS, WRAPPERS_SCOPE } from "./constants.js";
7
+ import { basename } from "./posix-path.js";
8
+ import { getSelectorSegments, splitAtCombinators } from "./css.js";
9
+ import { chainOf, namesOf, nearestElement } from "./element-match.js";
10
+ /** A block's key: its compounds and combinators, one space apart, the last compound's state classes taken off ('.label.button__label--hover'
11
+ * → '.label', '.wrapper>.label:hover' → '.wrapper > .label'); null when the last has no class or type. */
12
+ export function blockKey(segments) {
13
+ const compounds = segments.flatMap((segment) => (getSelectorSegments(segment) ?? []).flatMap(splitAtCombinators).map((part) => part.trim()).filter(Boolean));
14
+ const element = ELEMENT_SELECTOR.exec(compounds.at(-1) ?? '')?.[0];
15
+ return element === undefined ? null : [...compounds.slice(0, -1), element].join(' ');
16
+ }
17
+ /** A reader of the wrappers' contracts, each resolved once per source and structure file and parsed once per file: the contract found as
18
+ * the site's node finds `<source>/component-contract.json`, else `<source>/css`, from the structure file; null when the package has neither.
19
+ * A system component has only the JSON (`@wix/origami-system-components/InternalContainer/component-contract.json`), which messages then name. */
20
+ export function createContractReader(readPackageFile) {
21
+ const contracts = new Map();
22
+ const requests = new Map();
23
+ const resolve = (source, fromFile) => {
24
+ const css = readPackageFile(`${source}/css`, fromFile);
25
+ const json = readPackageFile(`${source}/${COMPONENT_CONTRACT_JSON}`, fromFile);
26
+ const read = json ?? css;
27
+ if (read === null)
28
+ return null;
29
+ const packagePath = `${source}/${css === null ? COMPONENT_CONTRACT_JSON : basename(css.file)}`;
30
+ if (!contracts.has(read.file)) {
31
+ // None while it's read, so a type nested in itself gives no vars.
32
+ contracts.set(read.file, null);
33
+ contracts.set(read.file, json ? readJsonContract(json, packagePath, source, (type) => getNestedRootVars(type, fromFile)) : readContract(read, packagePath));
34
+ }
35
+ return contracts.get(read.file);
36
+ };
37
+ const read = (source, fromFile) => {
38
+ const request = `${fromFile}\n${source}`;
39
+ if (!requests.has(request))
40
+ requests.set(request, resolve(source, fromFile));
41
+ return requests.get(request);
42
+ };
43
+ /** A nested component's root vars, from its type's own contract (`wixEditorElements.Button` → `@origami-wrappers/wixEditorElements/button`,
44
+ * as the site's build imports it, origami-transforms wrapperImport); none for a type without one. */
45
+ const getNestedRootVars = (type, fromFile) => {
46
+ const [module, symbol, ...more] = type.split('.');
47
+ const contract = module && symbol && !more.length ? read(`${WRAPPERS_SCOPE}/${module}/${symbol.toLowerCase()}`, fromFile) : null;
48
+ if (!contract)
49
+ return NO_CONTRACT_VARS;
50
+ const isRoot = isBlockVar(contract, contract.root);
51
+ return { customEnums: contract.customEnums.filter(isRoot), customPropertyTypes: contract.customPropertyTypes.filter(isRoot) };
52
+ };
53
+ return read;
54
+ }
55
+ /** Whether a var is one of a block's own (the root's, or a part's: '.label'), not a nested component's. */
56
+ export const isBlockVar = ({ root }, block) => ({ nested, inline }) => !nested && (inline === undefined ? block === root : blockKey([inline]) === block);
57
+ /** A part's element and classes as written, its other states left out: `.button.hamburger-close-button`. */
58
+ export const getWrittenPart = ({ base, states }) => [base ?? '', ...states.filter((state) => state.startsWith('.'))].join('');
59
+ /** The nested component's selector a part is, as written, with or without more classes after it: the longest it matches; undefined for none.
60
+ * @deprecated Use getNestedElement, which finds it as the build does. */
61
+ export function getNestedSelector(part, nested) {
62
+ const written = getWrittenPart(part);
63
+ return nested.filter((selector) => written === selector || written.startsWith(`${selector}.`)).sort((a, b) => b.length - a.length)[0];
64
+ }
65
+ /** A rule's parts as the build reads a selector: each compound's names (namesOf), a part with a combinator in it (`.button.more-button >
66
+ * .label`, as readSegment keeps it) split at the combinator; `sibling` for one after a `+` or `~`. */
67
+ const getPartCompounds = (parts) => parts.flatMap(({ base, states, unread }) => chainOf(`${base ?? ''}${states.join('')}${unread}`).map(({ combinator, compound }) => ({ names: namesOf(compound), sibling: /[+~]/.test(combinator) })));
68
+ /** The nested component a rule's parts (after the component's own) name, as the build resolves an enum's element (origami-transforms
69
+ * element-match, element-match.ts): its classes in any order, with more classes; the one matched nearest the end wins, the more specific on a
70
+ * tie. `last` when it's the last compound (not when the rule styles one of its parts); undefined for none, or one a `+` or `~` goes past (its
71
+ * sibling isn't its part, and DMS's converter matches the contract's combinators). Ported from origami-lint at 76488285. */
72
+ export function getNestedElement(parts, nested) {
73
+ const compounds = getPartCompounds(parts);
74
+ const found = nearestElement(nested, compounds.map(({ names }) => names));
75
+ if (found === undefined || compounds.slice(found.end + 1).some(({ sibling }) => sibling))
76
+ return undefined;
77
+ return { selector: found.selector, last: found.end === compounds.length - 1 };
78
+ }
79
+ /** The JSON's elements as the blocks defaults.css writes for them: an element's block, and one per state (`.label:hover`,
80
+ * `.label.button__label--selected`), so both files give the same contract; and its vars, each ref element's from `nestedVars`. */
81
+ function readJsonContract({ text }, packagePath, source, nestedVars) {
82
+ const { root, elements, refElements } = JSON.parse(text);
83
+ const entries = Object.entries(elements).flatMap(([selector, { properties, customProperties, states }]) => [
84
+ { selector, properties: [...properties, ...customProperties] },
85
+ ...states.map((state) => ({ selector: 'pseudoClass' in state ? `${selector}:${state.pseudoClass}` : `${selector}.${state.class}`, properties: [] })),
86
+ ]);
87
+ const varsFile = `${source}/${COMPONENT_CONTRACT_JSON}`;
88
+ /** Each element's vars of one kind, then each ref element's root ones, under its selector. */
89
+ const readVars = (own, pick) => [
90
+ ...Object.entries(elements).flatMap(([selector, element]) => own(element).map(([key, value]) => ({ ...value, key, inline: selector === root ? undefined : selector, nested: false, file: varsFile }))),
91
+ ...Object.entries(refElements).flatMap(([selector, type]) => pick(nestedVars(type)).map((item) => ({ ...item, inline: selector, nested: true }))),
92
+ ];
93
+ const vars = {
94
+ customEnums: readVars((element) => Object.entries(element.customEnums ?? {}).map(([key, options]) => [key, { options }]), (nested) => nested.customEnums),
95
+ customPropertyTypes: readVars((element) => Object.entries(element.customPropertyTypes ?? {}).map(([key, type]) => [key, { type }]), (nested) => nested.customPropertyTypes),
96
+ };
97
+ const contract = toContract(packagePath, root, entries, Object.keys(refElements), vars);
98
+ return contract && { ...contract, declaresNativeStates: true };
99
+ }
100
+ /** The blocks after the marker; the first is the component's own. */
101
+ function readContract({ text }, packagePath) {
102
+ const at = text.indexOf(ALLOWED_MARKER);
103
+ if (at === -1)
104
+ return null;
105
+ const entries = [...text.slice(at).matchAll(CONTRACT_BLOCK)].map(([, selector, body]) => ({ selector: selector, properties: [...body.matchAll(CONTRACT_PROPERTY)].map(([, property]) => property) }));
106
+ const nested = [...text.slice(at).matchAll(NESTED_COMPONENT)].map(([, selector]) => selector);
107
+ return toContract(packagePath, entries[0]?.selector, entries, nested);
108
+ }
109
+ /** The contract of these blocks: each block's properties join its key's (blockKey), so a state block's join its element's; null when the
110
+ * root has no key. */
111
+ function toContract(file, rootSelector, entries, nested, vars = NO_CONTRACT_VARS) {
112
+ const own = rootSelector === undefined ? null : blockKey([rootSelector]);
113
+ if (!own)
114
+ return null;
115
+ const blocks = new Map();
116
+ const stateClasses = new Map();
117
+ const statePseudoClasses = new Map();
118
+ for (const { selector, properties } of entries) {
119
+ const key = blockKey([selector]);
120
+ if (key === null)
121
+ continue;
122
+ blocks.set(key, new Set([...(blocks.get(key) ?? []), ...properties]));
123
+ addStateClasses(selector, stateClasses, statePseudoClasses);
124
+ }
125
+ return { file, root: own, blocks, nested, stateClasses, statePseudoClasses, declaresNativeStates: statePseudoClasses.size > 0, ...vars };
126
+ }
127
+ /** A block's state classes and pseudo-classes, by its last compound's element (splitCompound): `.label.button__label--hover` → '.label':
128
+ * 'button__label--hover'; `.label:hover` → '.label': 'hover'. */
129
+ function addStateClasses(selector, stateClasses, statePseudoClasses) {
130
+ const compound = (getSelectorSegments(selector) ?? []).flatMap(splitAtCombinators).at(-1)?.trim() ?? '';
131
+ const { element, states } = splitCompound(compound);
132
+ if (!element)
133
+ return;
134
+ const add = (byElement, names) => {
135
+ if (!names.length)
136
+ return;
137
+ const listed = byElement.get(element) ?? new Set();
138
+ for (const name of names)
139
+ listed.add(name);
140
+ byElement.set(element, listed);
141
+ };
142
+ add(stateClasses, states);
143
+ add(statePseudoClasses, [...compound.matchAll(/(?<!:):([\w-]+)/g)].map(([, name]) => name));
144
+ }
145
+ /** A compound's element and the state classes after it, its pseudo-classes and attributes left out, as defaults.css writes a state
146
+ * (a functional state's `${selector}.${className}`, erc/defaultsCss.ts): the element is its type and first class, the rest are states: `.label.button__label--hover`
147
+ * → '.label', ['button__label--hover']; `.button.selected` → '.button', ['selected']; a type's class with `--` is a state too: `a.button--hover`
148
+ * → 'a', ['button--hover']. */
149
+ export function splitCompound(compound) {
150
+ const attribute = compound.startsWith('[') ? ELEMENT_SELECTOR.exec(compound)?.[0] : undefined;
151
+ const plain = (attribute ? compound.slice(attribute.length) : compound).replace(/\[[^\]]*\]/g, '').replace(/::?[\w-]+(\([^)]*\))?/g, '');
152
+ if (attribute)
153
+ return { element: attribute, states: plain.split('.').filter(Boolean) };
154
+ const [type = '', ...classes] = plain.split('.');
155
+ const ownClasses = classes.length && (!type || !classes[0].includes('--')) ? 1 : 0;
156
+ return { element: [type, ...classes.slice(0, ownClasses)].join('.'), states: classes.slice(ownClasses) };
157
+ }
@@ -0,0 +1,3 @@
1
+ import type { ImagePath } from './types.ts';
2
+ /** Image locations declared by defineComponent, including arrays, nested objects, videos and legacy inlined Images. */
3
+ export declare function readImagePaths(text: string): ImagePath[];
@@ -0,0 +1,75 @@
1
+ // The static part of origami-transforms/wrapperImagePaths.js, using the parser already installed here.
2
+ import { parse } from '@typescript-eslint/parser';
3
+ import { DEFINITION_GROUPS } from "./constants.js";
4
+ import { getProperties, getProperty, getKey } from "./utils.js";
5
+ import { walk } from "./syntax-tree.js";
6
+ /** Image locations declared by defineComponent, including arrays, nested objects, videos and legacy inlined Images. */
7
+ export function readImagePaths(text) {
8
+ const paths = [];
9
+ let program;
10
+ try {
11
+ program = parse(text, { sourceType: 'module', ecmaFeatures: { jsx: true } });
12
+ }
13
+ catch {
14
+ return paths;
15
+ }
16
+ walk(program, [], node => {
17
+ if (node.type !== 'CallExpression')
18
+ return;
19
+ const call = node;
20
+ if (call.callee.type !== 'Identifier' || call.callee.name !== 'defineComponent')
21
+ return;
22
+ const [definition] = call.arguments;
23
+ if (definition?.type !== 'ObjectExpression')
24
+ return;
25
+ for (const [group, root] of DEFINITION_GROUPS) {
26
+ const entries = getProperty(definition, group)?.value;
27
+ if (entries?.type !== 'ObjectExpression')
28
+ continue;
29
+ for (const entry of getProperties(entries)) {
30
+ const key = getKey(entry);
31
+ if (key !== null)
32
+ paths.push(...imagePathsInProp(entry.value, [...root, key]));
33
+ }
34
+ }
35
+ });
36
+ return paths;
37
+ }
38
+ function imagePathsInProp(value, path) {
39
+ if (value.type !== 'CallExpression' || value.callee.type !== 'MemberExpression' || value.callee.property.type !== 'Identifier')
40
+ return [];
41
+ if (value.callee.property.name === 'image')
42
+ return [path];
43
+ if (value.callee.property.name === 'video')
44
+ return [[...path, 'poster']];
45
+ const [type] = value.typeArguments?.params ?? [];
46
+ return type ? imagePathsInType(type, path) : [];
47
+ }
48
+ function imagePathsInType(type, path) {
49
+ if (type.type === 'TSTypeReference' && type.typeName.type === 'Identifier') {
50
+ if (type.typeName.name === 'Image')
51
+ return [path];
52
+ if (type.typeName.name === 'Video')
53
+ return [[...path, 'poster']];
54
+ const [item] = type.typeName.name === 'Array' ? (type.typeArguments?.params ?? []) : [];
55
+ return item ? imagePathsInType(item, [...path, '[]']) : [];
56
+ }
57
+ if (type.type === 'TSArrayType')
58
+ return imagePathsInType(type.elementType, [...path, '[]']);
59
+ if (type.type === 'TSUnionType')
60
+ return type.types.flatMap(member => imagePathsInType(member, path));
61
+ if (type.type !== 'TSTypeLiteral')
62
+ return [];
63
+ const members = type.members.filter(member => member.type === 'TSPropertySignature');
64
+ const uri = members.find(member => memberName(member.key) === 'uri');
65
+ if (uri?.optional && members.some(member => memberName(member.key) === 'url'))
66
+ return [path];
67
+ return members.flatMap(member => {
68
+ const key = memberName(member.key);
69
+ const annotation = member.typeAnnotation?.typeAnnotation;
70
+ return key && annotation ? imagePathsInType(annotation, [...path, key]) : [];
71
+ });
72
+ }
73
+ function memberName(key) {
74
+ return key.type === 'Identifier' ? key.name : key.type === 'Literal' && typeof key.value === 'string' ? key.value : undefined;
75
+ }
@@ -0,0 +1,107 @@
1
+ import type { ExtensionKind } from './types.ts';
2
+ /** A value the model doesn't read: a call, a package's export, a function. A rule checks nothing about it. */
3
+ export declare const UNKNOWN: unique symbol;
4
+ /** The registration calls, `extensions.<method>({…})`, and the kind each registers. */
5
+ export declare const REGISTRATIONS: Readonly<Record<string, ExtensionKind>>;
6
+ /** The name the registry is exported under: `import { extensions } from '@wix/astro/builders'`. */
7
+ export declare const EXTENSION_REGISTRY = "extensions";
8
+ /** Packages that export the extensions registry, including older exported sites; 0.x sites register context providers
9
+ * and function libraries from the experimental entry. */
10
+ export declare const EXTENSION_REGISTRY_SOURCES: readonly string[];
11
+ /** The functions the Wix CLI's scaffold builds a manifest with, by the names their packages export, and those packages;
12
+ * the model does what each does, and only for an import of that name from that package. */
13
+ export declare const MANIFEST_FUNCTIONS: {
14
+ readonly deepmerge: {
15
+ readonly name: "deepmerge";
16
+ readonly source: "deepmerge-ts";
17
+ };
18
+ /** The deepmerge package's default export, which most apps' extensions import (`import merge from 'deepmerge'`). It
19
+ * merges two objects as deepmerge-ts does, arrays concatenated; a third argument is its options. */
20
+ readonly deepmergePackage: {
21
+ readonly name: "default";
22
+ readonly source: "deepmerge";
23
+ };
24
+ readonly withEditorElementDefaults: {
25
+ readonly name: "withEditorElementDefaults";
26
+ readonly source: "@wix/react-component-utils";
27
+ };
28
+ };
29
+ /** The editor element's keys withEditorElementDefaults reads (@wix/react-component-utils), and those fixAt reads a
30
+ * generated value's source by; the defaults' inner parts are ELEMENT_PROPS (shared/constants.ts), the same key a page
31
+ * writes them under. */
32
+ export declare const EDITOR_ELEMENT: {
33
+ readonly data: "data";
34
+ readonly defaultValue: "defaultValue";
35
+ readonly elements: "elements";
36
+ readonly inlineElement: "inlineElement";
37
+ readonly refElement: "refElement";
38
+ readonly selector: "selector";
39
+ readonly cssProperties: "cssProperties";
40
+ readonly cssCustomProperties: "cssCustomProperties";
41
+ };
42
+ /** The registration's key that names the extension: `type: 'companionApp.<Name>'`. */
43
+ export declare const TYPE_KEY = "type";
44
+ /** The syntax tree's node types the reader reads, by their ESTree names: compare a node's `type` with these, never with a string written out. */
45
+ export declare const NODE_TYPE: {
46
+ readonly ArrayExpression: "ArrayExpression";
47
+ readonly CallExpression: "CallExpression";
48
+ readonly ExportDefaultDeclaration: "ExportDefaultDeclaration";
49
+ readonly ExportAllDeclaration: "ExportAllDeclaration";
50
+ readonly ExportNamedDeclaration: "ExportNamedDeclaration";
51
+ readonly Identifier: "Identifier";
52
+ readonly ImportDeclaration: "ImportDeclaration";
53
+ readonly JSXAttribute: "JSXAttribute";
54
+ readonly JSXIdentifier: "JSXIdentifier";
55
+ readonly Literal: "Literal";
56
+ readonly MemberExpression: "MemberExpression";
57
+ readonly ObjectExpression: "ObjectExpression";
58
+ readonly ParenthesizedExpression: "ParenthesizedExpression";
59
+ readonly SpreadElement: "SpreadElement";
60
+ readonly TemplateElement: "TemplateElement";
61
+ readonly TemplateLiteral: "TemplateLiteral";
62
+ readonly TSAsExpression: "TSAsExpression";
63
+ readonly TSNonNullExpression: "TSNonNullExpression";
64
+ readonly TSSatisfiesExpression: "TSSatisfiesExpression";
65
+ readonly TSTypeAssertion: "TSTypeAssertion";
66
+ readonly UnaryExpression: "UnaryExpression";
67
+ readonly VariableDeclaration: "VariableDeclaration";
68
+ };
69
+ /** Wrappers that change a value's type, not the value: `x as T`, `x satisfies T`, `x!`, `<T>x`, `(x)`. */
70
+ export declare const TYPE_WRAPPERS: readonly string[];
71
+ /** The `typeof` of a literal the model reads. */
72
+ export declare const SCALAR_TYPES: readonly string[];
73
+ /** A property's kind when it holds a value (not a getter or a setter). */
74
+ export declare const VALUE_PROPERTY = "init";
75
+ /** The only declaration whose value the model reads: a let or a var may be assigned again. */
76
+ export declare const CONST_DECLARATION = "const";
77
+ /** `import type`, `export type`: a declaration or a specifier that holds no value. */
78
+ export declare const TYPE_ONLY = "type";
79
+ export declare const NEGATIVE = "-";
80
+ export declare const DEFAULT_EXPORT = "default";
81
+ /** The name a whole module is read under: `import * as`, `export *`. */
82
+ export declare const NAMESPACE_IMPORT = "*";
83
+ /** How a relative import's source starts: `./props`, `../shared`. Any other source is a package. */
84
+ export declare const RELATIVE_IMPORT = ".";
85
+ /** An import the build turns into a URL: `import componentUrl from './component.tsx?url'`. */
86
+ export declare const URL_IMPORT = "?url";
87
+ /** A file the reader reads as a module: JavaScript or TypeScript. Any other file an import resolves to (JSON, a CSS
88
+ * module, an image) is UNKNOWN. */
89
+ export declare const SOURCE_MODULE: RegExp;
90
+ /** What an import without its file's extension may mean, in the order companionRegistrations.js (@wix/origami-transforms)
91
+ * tries them after the path as written: an added extension, then a directory's entry. */
92
+ export declare const MODULE_EXTENSIONS: readonly string[];
93
+ /** The TypeScript sources an emitted JavaScript name may mean (`./props.js` → `props.ts`), tried before MODULE_EXTENSIONS. */
94
+ export declare const TYPESCRIPT_EXTENSIONS: Readonly<Record<string, readonly string[]>>;
95
+ /** The files a generated value may be written from, by the key above it (each a suffix beside the generated file), the
96
+ * scaffold's first; the value's source is the first one the site has. A JavaScript component's `data` is from its React file. */
97
+ export declare const GENERATED_FROM: Readonly<Record<string, readonly string[]>>;
98
+ /** The keys whose children the app names: a data field, an element, a CSS property. */
99
+ export declare const NAMED_CHILDREN: readonly string[];
100
+ /** The JSX attribute the generator reads an element's class, and so its selector, from. */
101
+ export declare const CLASS_NAME = "className";
102
+ /** The at-rule that registers a custom property, which the generator reads its type from first. */
103
+ export declare const PROPERTY_AT_RULE = "property";
104
+ /** The generator pads a selector shorter than this with `_` (ZeroConfig's padSelector, MINIMUM_SELECTOR_LENGTH): only a
105
+ * selector of this length can be padded. */
106
+ export declare const PADDED_SELECTOR_LENGTH = 4;
107
+ export declare const SELECTOR_PADDING: RegExp;
@@ -0,0 +1,102 @@
1
+ // What the static reader supports: the registration calls and manifest functions, the syntax it evaluates, how an
2
+ // import resolves, and where a generated value comes from.
3
+ import { COMPONENT_FILE_SUFFIXES, PROPS_FILE_SUFFIX, STYLES_FILE_SUFFIX } from "../shared/index.js";
4
+ /** A value the model doesn't read: a call, a package's export, a function. A rule checks nothing about it. */
5
+ export const UNKNOWN = Symbol('unknown');
6
+ // ── registrations and manifest functions ──
7
+ /** The registration calls, `extensions.<method>({…})`, and the kind each registers. */
8
+ export const REGISTRATIONS = { editorReactComponent: 'component', contextProvider: 'contextProvider', functionLibrary: 'functionLibrary' };
9
+ /** The name the registry is exported under: `import { extensions } from '@wix/astro/builders'`. */
10
+ export const EXTENSION_REGISTRY = 'extensions';
11
+ /** Packages that export the extensions registry, including older exported sites; 0.x sites register context providers
12
+ * and function libraries from the experimental entry. */
13
+ export const EXTENSION_REGISTRY_SOURCES = ['@wix/astro/builders', '@wix/custom-extensions', '@wix/custom-extensions/experimental'];
14
+ /** The functions the Wix CLI's scaffold builds a manifest with, by the names their packages export, and those packages;
15
+ * the model does what each does, and only for an import of that name from that package. */
16
+ export const MANIFEST_FUNCTIONS = {
17
+ deepmerge: { name: 'deepmerge', source: 'deepmerge-ts' },
18
+ /** The deepmerge package's default export, which most apps' extensions import (`import merge from 'deepmerge'`). It
19
+ * merges two objects as deepmerge-ts does, arrays concatenated; a third argument is its options. */
20
+ deepmergePackage: { name: 'default', source: 'deepmerge' },
21
+ withEditorElementDefaults: { name: 'withEditorElementDefaults', source: '@wix/react-component-utils' },
22
+ };
23
+ /** The editor element's keys withEditorElementDefaults reads (@wix/react-component-utils), and those fixAt reads a
24
+ * generated value's source by; the defaults' inner parts are ELEMENT_PROPS (shared/constants.ts), the same key a page
25
+ * writes them under. */
26
+ export const EDITOR_ELEMENT = {
27
+ data: 'data', defaultValue: 'defaultValue', elements: 'elements', inlineElement: 'inlineElement', refElement: 'refElement',
28
+ selector: 'selector', cssProperties: 'cssProperties', cssCustomProperties: 'cssCustomProperties',
29
+ };
30
+ /** The registration's key that names the extension: `type: 'companionApp.<Name>'`. */
31
+ export const TYPE_KEY = 'type';
32
+ // ── the syntax the reader evaluates ──
33
+ /** The syntax tree's node types the reader reads, by their ESTree names: compare a node's `type` with these, never with a string written out. */
34
+ export const NODE_TYPE = {
35
+ ArrayExpression: 'ArrayExpression',
36
+ CallExpression: 'CallExpression',
37
+ ExportDefaultDeclaration: 'ExportDefaultDeclaration',
38
+ ExportAllDeclaration: 'ExportAllDeclaration',
39
+ ExportNamedDeclaration: 'ExportNamedDeclaration',
40
+ Identifier: 'Identifier',
41
+ ImportDeclaration: 'ImportDeclaration',
42
+ JSXAttribute: 'JSXAttribute',
43
+ JSXIdentifier: 'JSXIdentifier',
44
+ Literal: 'Literal',
45
+ MemberExpression: 'MemberExpression',
46
+ ObjectExpression: 'ObjectExpression',
47
+ ParenthesizedExpression: 'ParenthesizedExpression',
48
+ SpreadElement: 'SpreadElement',
49
+ TemplateElement: 'TemplateElement',
50
+ TemplateLiteral: 'TemplateLiteral',
51
+ TSAsExpression: 'TSAsExpression',
52
+ TSNonNullExpression: 'TSNonNullExpression',
53
+ TSSatisfiesExpression: 'TSSatisfiesExpression',
54
+ TSTypeAssertion: 'TSTypeAssertion',
55
+ UnaryExpression: 'UnaryExpression',
56
+ VariableDeclaration: 'VariableDeclaration',
57
+ };
58
+ /** Wrappers that change a value's type, not the value: `x as T`, `x satisfies T`, `x!`, `<T>x`, `(x)`. */
59
+ export const TYPE_WRAPPERS = [NODE_TYPE.TSAsExpression, NODE_TYPE.TSSatisfiesExpression, NODE_TYPE.TSNonNullExpression, NODE_TYPE.TSTypeAssertion, NODE_TYPE.ParenthesizedExpression];
60
+ /** The `typeof` of a literal the model reads. */
61
+ export const SCALAR_TYPES = ['string', 'number', 'boolean'];
62
+ /** A property's kind when it holds a value (not a getter or a setter). */
63
+ export const VALUE_PROPERTY = 'init';
64
+ /** The only declaration whose value the model reads: a let or a var may be assigned again. */
65
+ export const CONST_DECLARATION = 'const';
66
+ /** `import type`, `export type`: a declaration or a specifier that holds no value. */
67
+ export const TYPE_ONLY = 'type';
68
+ export const NEGATIVE = '-';
69
+ // ── imports and exports ──
70
+ export const DEFAULT_EXPORT = 'default';
71
+ /** The name a whole module is read under: `import * as`, `export *`. */
72
+ export const NAMESPACE_IMPORT = '*';
73
+ /** How a relative import's source starts: `./props`, `../shared`. Any other source is a package. */
74
+ export const RELATIVE_IMPORT = '.';
75
+ /** An import the build turns into a URL: `import componentUrl from './component.tsx?url'`. */
76
+ export const URL_IMPORT = '?url';
77
+ /** A file the reader reads as a module: JavaScript or TypeScript. Any other file an import resolves to (JSON, a CSS
78
+ * module, an image) is UNKNOWN. */
79
+ export const SOURCE_MODULE = /\.[cm]?[jt]sx?$/;
80
+ /** What an import without its file's extension may mean, in the order companionRegistrations.js (@wix/origami-transforms)
81
+ * tries them after the path as written: an added extension, then a directory's entry. */
82
+ export const MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '/index.ts', '/index.tsx', '/index.js'];
83
+ /** The TypeScript sources an emitted JavaScript name may mean (`./props.js` → `props.ts`), tried before MODULE_EXTENSIONS. */
84
+ export const TYPESCRIPT_EXTENSIONS = { '.js': ['.ts', '.tsx'], '.mjs': ['.mts'], '.cjs': ['.cts'] };
85
+ // ── a generated value's source (source-locations.ts) ──
86
+ const { data, elements, selector, cssProperties, cssCustomProperties } = EDITOR_ELEMENT;
87
+ /** The files a generated value may be written from, by the key above it (each a suffix beside the generated file), the
88
+ * scaffold's first; the value's source is the first one the site has. A JavaScript component's `data` is from its React file. */
89
+ export const GENERATED_FROM = {
90
+ [data]: [PROPS_FILE_SUFFIX, ...COMPONENT_FILE_SUFFIXES], [cssProperties]: [STYLES_FILE_SUFFIX], [cssCustomProperties]: [STYLES_FILE_SUFFIX],
91
+ [selector]: COMPONENT_FILE_SUFFIXES, [elements]: COMPONENT_FILE_SUFFIXES,
92
+ };
93
+ /** The keys whose children the app names: a data field, an element, a CSS property. */
94
+ export const NAMED_CHILDREN = [data, elements, cssProperties, cssCustomProperties];
95
+ /** The JSX attribute the generator reads an element's class, and so its selector, from. */
96
+ export const CLASS_NAME = 'className';
97
+ /** The at-rule that registers a custom property, which the generator reads its type from first. */
98
+ export const PROPERTY_AT_RULE = 'property';
99
+ /** The generator pads a selector shorter than this with `_` (ZeroConfig's padSelector, MINIMUM_SELECTOR_LENGTH): only a
100
+ * selector of this length can be padded. */
101
+ export const PADDED_SELECTOR_LENGTH = 4;
102
+ export const SELECTOR_PADDING = /_+$/;
@@ -0,0 +1,3 @@
1
+ export { UNKNOWN } from './constants.ts';
2
+ export { createExtensionReader, isExtensionFile, readSiteCodeModel } from './read-site-code-model.ts';
3
+ export type { Extension, ExtensionKind, Manifest, ManifestValue, SiteCodeModel, SourceLocation } from './types.ts';
@@ -0,0 +1,4 @@
1
+ // The site-code model, beside the project model (part 2): what a rule sees of packages/site-code, each extension's manifest and
2
+ // where its values are written.
3
+ export { UNKNOWN } from "./constants.js";
4
+ export { createExtensionReader, isExtensionFile, readSiteCodeModel } from "./read-site-code-model.js";
@@ -0,0 +1,15 @@
1
+ import type { LocatedManifestObject, LocatedManifestValue, ManifestValue, SourceLocation } from './types.ts';
2
+ export declare const unknownAt: (place: SourceLocation) => LocatedManifestValue;
3
+ export declare const isObject: (placed: LocatedManifestValue | undefined) => placed is LocatedManifestObject;
4
+ /** The value without its places: what a rule reads. */
5
+ export declare function toManifestValue({ value }: LocatedManifestValue): ManifestValue;
6
+ /** An object's value at a key, or an array's at an index; undefined when there's none. */
7
+ export declare function childOf({ value }: LocatedManifestValue, key: string): LocatedManifestValue | undefined;
8
+ /** The value at a dotted path; a path that isn't there gives the nearest value above it. */
9
+ export declare function getNearestValue(placed: LocatedManifestValue, path: string): LocatedManifestValue;
10
+ /** deepmerge-ts: objects joined key by key, arrays concatenated, otherwise the later value. UNKNOWN on either side is UNKNOWN. */
11
+ export declare function deepmerge(a: LocatedManifestValue, b: LocatedManifestValue): LocatedManifestValue;
12
+ /** @wix/react-component-utils' withEditorElementDefaults: each default fills its `data` field's defaultValue, and
13
+ * `elementProps.<name>` does the same inside that element's inlineElement or refElement. Unknown defaults may fill any
14
+ * field: each field without a defaultValue gets an UNKNOWN one. */
15
+ export declare function withEditorElementDefaults(element: LocatedManifestValue, defaults: LocatedManifestValue): LocatedManifestValue;
@@ -0,0 +1,88 @@
1
+ // Manifest values with their places: reading them out, a path's value and place, and the two merges the Wix CLI's scaffold builds a manifest with.
2
+ import { ELEMENT_PROPS } from "../shared/index.js";
3
+ import { EDITOR_ELEMENT, UNKNOWN } from "./constants.js";
4
+ const { data, defaultValue, elements, inlineElement, refElement } = EDITOR_ELEMENT;
5
+ export const unknownAt = (place) => ({ place, value: UNKNOWN });
6
+ export const isObject = (placed) => placed?.value instanceof Map;
7
+ /** The value without its places: what a rule reads. */
8
+ export function toManifestValue({ value }) {
9
+ if (value instanceof Map)
10
+ return Object.fromEntries([...value].map(([key, child]) => [key, toManifestValue(child)]));
11
+ return Array.isArray(value) ? value.map(toManifestValue) : value;
12
+ }
13
+ /** An object's value at a key, or an array's at an index; undefined when there's none. */
14
+ export function childOf({ value }, key) {
15
+ if (value instanceof Map)
16
+ return value.get(key);
17
+ return Array.isArray(value) ? value[Number(key)] : undefined;
18
+ }
19
+ /** The value at a dotted path; a path that isn't there gives the nearest value above it. */
20
+ export function getNearestValue(placed, path) {
21
+ let current = placed;
22
+ for (const key of path.split('.')) {
23
+ const next = childOf(current, key);
24
+ if (!next)
25
+ break;
26
+ current = next;
27
+ }
28
+ return current;
29
+ }
30
+ /** deepmerge-ts: objects joined key by key, arrays concatenated, otherwise the later value. UNKNOWN on either side is UNKNOWN. */
31
+ export function deepmerge(a, b) {
32
+ if (a.value === UNKNOWN || b.value === UNKNOWN)
33
+ return unknownAt(a.place);
34
+ if (isObject(a) && isObject(b)) {
35
+ const value = new Map(a.value);
36
+ for (const [key, child] of b.value)
37
+ value.set(key, value.has(key) ? deepmerge(value.get(key), child) : child);
38
+ return { place: a.place, value };
39
+ }
40
+ if (Array.isArray(a.value) && Array.isArray(b.value))
41
+ return { place: a.place, value: [...a.value, ...b.value] };
42
+ return b;
43
+ }
44
+ /** @wix/react-component-utils' withEditorElementDefaults: each default fills its `data` field's defaultValue, and
45
+ * `elementProps.<name>` does the same inside that element's inlineElement or refElement. Unknown defaults may fill any
46
+ * field: each field without a defaultValue gets an UNKNOWN one. */
47
+ export function withEditorElementDefaults(element, defaults) {
48
+ if (!isObject(element))
49
+ return element;
50
+ const filled = updateChild(element, data, (fields) => fillDefaults(fields, defaults));
51
+ const props = defaultOf(defaults, ELEMENT_PROPS);
52
+ return props ? updateChild(filled, elements, (named) => applyElementProps(named, props)) : filled;
53
+ }
54
+ /** A field without a defaultValue takes its default; `elementProps` is not a field. */
55
+ function fillDefaults(fields, defaults) {
56
+ const value = new Map(fields.value);
57
+ for (const [key, field] of fields.value) {
58
+ const fallback = key === ELEMENT_PROPS ? undefined : defaultOf(defaults, key);
59
+ if (fallback && isObject(field) && !hasDefault(field))
60
+ value.set(key, { place: field.place, value: new Map(field.value).set(defaultValue, fallback) });
61
+ }
62
+ return { place: fields.place, value };
63
+ }
64
+ function applyElementProps(named, props) {
65
+ let result = named;
66
+ for (const name of named.value.keys()) {
67
+ const elementDefaults = defaultOf(props, name);
68
+ if (!elementDefaults)
69
+ continue;
70
+ result = updateChild(result, name, (element) => {
71
+ const inner = [inlineElement, refElement].find((key) => isObject(element.value.get(key)));
72
+ return inner ? updateChild(element, inner, (child) => withEditorElementDefaults(child, elementDefaults)) : element;
73
+ });
74
+ }
75
+ return result;
76
+ }
77
+ /** The default at key; UNKNOWN when the defaults aren't read, as they may hold any key. */
78
+ function defaultOf(defaults, key) {
79
+ if (defaults.value === UNKNOWN)
80
+ return unknownAt(defaults.place);
81
+ return isObject(defaults) ? defaults.value.get(key) : undefined;
82
+ }
83
+ const hasDefault = (field) => (field.value.get(defaultValue)?.value ?? null) !== null;
84
+ /** The object with its child at key replaced by update(child); as it is when that child isn't an object. */
85
+ function updateChild(object, key, update) {
86
+ const child = object.value.get(key);
87
+ return isObject(child) ? { place: object.place, value: new Map(object.value).set(key, update(child)) } : object;
88
+ }
@@ -0,0 +1,4 @@
1
+ import { type ReadFile } from '../shared/index.ts';
2
+ import type { ParsedModule, ReadImport } from './types.ts';
3
+ /** Throws for a file that doesn't parse, naming it. */
4
+ export declare function readModule(file: string, text: string, readImport: ReadImport, readFile: ReadFile): ParsedModule;