@wix/origami-transforms 0.1.41 → 0.1.42
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.
|
@@ -5,7 +5,7 @@ export const COMPANION_APP: "companionApp";
|
|
|
5
5
|
* app: each service's bundle and the module that registers it, `<package name>/bundle.js` and `<package name>/index.js`. */
|
|
6
6
|
export const VIEWER_SERVICES_FOLDER: "src/site/_generated/viewer-services";
|
|
7
7
|
export function viewerServiceImport(generatedFolder: string, packageName: string): string;
|
|
8
|
-
export function wrapperSideEffectImports(sources: Iterable<string>, catalog: WrapperCatalog, generatedFolder: string): string[];
|
|
8
|
+
export function wrapperSideEffectImports(sources: Iterable<string>, catalog: WrapperCatalog, generatedFolder: string, refElements?: RefElements): string[];
|
|
9
9
|
/**
|
|
10
10
|
* the site's component catalog (`site-component-catalog.json`), by module
|
|
11
11
|
*/
|
|
@@ -23,3 +23,10 @@ export type WrapperCatalog = {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* each wrapper component's ref element types, by
|
|
28
|
+
* its type, as its wrapper package's `origami.refElements` lists them
|
|
29
|
+
*/
|
|
30
|
+
export type RefElements = {
|
|
31
|
+
readonly [type: string]: readonly string[];
|
|
32
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-transforms",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.42",
|
|
4
4
|
"description": "Babel and PostCSS checks and transforms for Wix origami page files.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
},
|
|
77
77
|
"type": "module",
|
|
78
78
|
"types": "./dist/index.d.ts",
|
|
79
|
-
"falconPackageHash": "
|
|
79
|
+
"falconPackageHash": "a93543b10c8156d2dd51f02d94e447a5aaf82374b5c26370c547c8ba"
|
|
80
80
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// What an item's `_generated` entry imports before its structure, for the wrappers the structure imports: each
|
|
2
|
-
// component's defaults sheet, and the registration of each viewer service a companion app
|
|
3
|
-
// writes these lines, and `yarn dev` and `yarn build` rewrite them when the structure
|
|
4
|
-
// Kept free of dependencies, like `wrapperImport.js`, so the generator's bundle
|
|
2
|
+
// component's defaults sheet and its ref element types', and the registration of each viewer service a companion app
|
|
3
|
+
// provider needs. The export writes these lines, and `yarn dev` and `yarn build` rewrite them when the structure
|
|
4
|
+
// changes, so both follow one rule. Kept free of dependencies, like `wrapperImport.js`, so the generator's bundle
|
|
5
|
+
// doesn't take the transforms with it.
|
|
5
6
|
import { posix } from 'node:path'
|
|
6
7
|
import { moduleFromWrapperEntry, wrapperImport } from './wrapperImport.js'
|
|
7
8
|
|
|
@@ -20,6 +21,11 @@ export const VIEWER_SERVICES_FOLDER = 'src/site/_generated/viewer-services'
|
|
|
20
21
|
* } } }} WrapperCatalog the site's component catalog (`site-component-catalog.json`), by module
|
|
21
22
|
*/
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {{ readonly [type: string]: readonly string[] }} RefElements each wrapper component's ref element types, by
|
|
26
|
+
* its type, as its wrapper package's `origami.refElements` lists them
|
|
27
|
+
*/
|
|
28
|
+
|
|
23
29
|
/**
|
|
24
30
|
* The module that registers a viewer service, as an item's `_generated` folder imports it.
|
|
25
31
|
* @param {string} generatedFolder the item's `_generated` folder, relative to the site app
|
|
@@ -30,26 +36,54 @@ export const viewerServiceImport = (generatedFolder, packageName) => {
|
|
|
30
36
|
return path.startsWith('.') ? path : `./${path}`
|
|
31
37
|
}
|
|
32
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The `/css` of a component and of its ref elements' types, which its raw component renders itself (FastGallery its
|
|
41
|
+
* ExpandedGallery) and no structure imports: each ref type's before the component's, at any depth, so a ref type's
|
|
42
|
+
* sheet never comes after the sheet of the component that styles it. A ref type the catalog doesn't have (its app isn't
|
|
43
|
+
* on the site) brings nothing.
|
|
44
|
+
* @param {WrapperCatalog} catalog
|
|
45
|
+
* @param {RefElements} refElements
|
|
46
|
+
* @param {string} module
|
|
47
|
+
* @param {string} symbol
|
|
48
|
+
* @param {Set<string>} imports where the imports go, in order
|
|
49
|
+
* @param {Set<string>} seen the types already walked, so a cycle ends
|
|
50
|
+
*/
|
|
51
|
+
const addComponentCss = (catalog, refElements, module, symbol, imports, seen) => {
|
|
52
|
+
const type = `${module}.${symbol}`
|
|
53
|
+
if (!catalog[module]?.entries.components?.[symbol] || seen.has(type)) return
|
|
54
|
+
seen.add(type)
|
|
55
|
+
for (const refType of refElements[type] ?? []) {
|
|
56
|
+
const separator = refType.indexOf('.')
|
|
57
|
+
if (separator > 0) addComponentCss(catalog, refElements, refType.slice(0, separator), refType.slice(separator + 1), imports, seen)
|
|
58
|
+
}
|
|
59
|
+
imports.add(`${wrapperImport({ module, symbol })}/css`)
|
|
60
|
+
}
|
|
61
|
+
|
|
33
62
|
/**
|
|
34
63
|
* The side-effect imports of the wrappers an item's structure imports from, once each, in the structure's order: a
|
|
35
|
-
* component folder's `<folder>/css`, and a companion app provider folder's
|
|
36
|
-
* catalog symbol whose `wrapperImport` it is; a function library's
|
|
37
|
-
* nothing.
|
|
64
|
+
* component folder's `<folder>/css`, after its ref types' (`addComponentCss`), and a companion app provider folder's
|
|
65
|
+
* viewer service registrations. A folder is the catalog symbol whose `wrapperImport` it is; a function library's
|
|
66
|
+
* folder, or one the catalog doesn't have, brings nothing.
|
|
38
67
|
* @param {Iterable<string>} sources the structure's import sources
|
|
39
68
|
* @param {WrapperCatalog} catalog
|
|
40
69
|
* @param {string} generatedFolder the item's `_generated` folder, relative to the site app
|
|
70
|
+
* @param {RefElements} [refElements] the ref element types off the installed wrapper packages; the export, which runs
|
|
71
|
+
* before they are installed, has none
|
|
41
72
|
* @returns {string[]}
|
|
42
73
|
*/
|
|
43
|
-
export const wrapperSideEffectImports = (sources, catalog, generatedFolder) => {
|
|
74
|
+
export const wrapperSideEffectImports = (sources, catalog, generatedFolder, refElements = {}) => {
|
|
44
75
|
/** @type {Set<string>} */
|
|
45
76
|
const imports = new Set()
|
|
77
|
+
/** @type {Set<string>} */
|
|
78
|
+
const seen = new Set()
|
|
46
79
|
for (const source of sources) {
|
|
47
80
|
const module = moduleFromWrapperEntry(source)
|
|
48
81
|
if (!module) continue
|
|
49
82
|
const { components = {}, contextProviders = {} } = catalog[module]?.entries ?? {}
|
|
50
83
|
/** @param {string} name */
|
|
51
84
|
const isFolder = name => wrapperImport({ module, symbol: name }) === source
|
|
52
|
-
|
|
85
|
+
const symbol = Object.keys(components).find(isFolder)
|
|
86
|
+
if (symbol) addComponentCss(catalog, refElements, module, symbol, imports, seen)
|
|
53
87
|
if (module !== COMPANION_APP) continue
|
|
54
88
|
const provider = Object.keys(contextProviders).find(isFolder)
|
|
55
89
|
for (const service of (provider && contextProviders[provider].services) ?? []) {
|