@wix/origami-transforms 0.1.31 → 0.1.33

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,3 +5,4 @@ export function wrapperImport({ module, symbol }: {
5
5
  readonly module: string;
6
6
  readonly symbol: string;
7
7
  }): string;
8
+ export function moduleFromWrapperEntry(specifier: string): string | undefined;
@@ -0,0 +1,25 @@
1
+ /** The module of the site's own (companion) app. Its providers' viewer services come with the export; other apps' come
2
+ * with the site's services. */
3
+ export const COMPANION_APP: "companionApp";
4
+ /** Where an export puts the viewer services the companion app's wrapped context providers need, relative to the site
5
+ * app: each service's bundle and the module that registers it, `<package name>/bundle.js` and `<package name>/index.js`. */
6
+ export const VIEWER_SERVICES_FOLDER: "src/site/_generated/viewer-services";
7
+ export function viewerServiceImport(generatedFolder: string, packageName: string): string;
8
+ export function wrapperSideEffectImports(sources: Iterable<string>, catalog: WrapperCatalog, generatedFolder: string): string[];
9
+ /**
10
+ * the site's component catalog (`site-component-catalog.json`), by module
11
+ */
12
+ export type WrapperCatalog = {
13
+ readonly [module: string]: {
14
+ readonly entries: {
15
+ readonly components?: {
16
+ readonly [name: string]: unknown;
17
+ };
18
+ readonly contextProviders?: {
19
+ readonly [name: string]: {
20
+ readonly services?: readonly string[];
21
+ };
22
+ };
23
+ };
24
+ };
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-transforms",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "Babel and PostCSS checks and transforms for Wix origami page files.",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -23,7 +23,7 @@
23
23
  "@wix/origami-system-components": "1.10.6",
24
24
  "postcss": "^8.5.3",
25
25
  "postcss-custom-media": "^12.0.1",
26
- "@wix/origami-bi": "0.11.0"
26
+ "@wix/origami-bi": "0.12.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^22.0.0",
@@ -64,6 +64,10 @@
64
64
  "types": "./dist/wrapperImport.d.ts",
65
65
  "default": "./src/wrapperImport.js"
66
66
  },
67
+ "./wrapper-side-effects": {
68
+ "types": "./dist/wrapperSideEffects.d.ts",
69
+ "default": "./src/wrapperSideEffects.js"
70
+ },
67
71
  "./companion-registrations": {
68
72
  "types": "./dist/companionRegistrations.d.ts",
69
73
  "default": "./src/companionRegistrations.js"
@@ -71,5 +75,5 @@
71
75
  },
72
76
  "type": "module",
73
77
  "types": "./dist/index.d.ts",
74
- "falconPackageHash": "eea52f454e6f8d604431d5d69e6ce0bae25496f2528518f4dbdb43dd"
78
+ "falconPackageHash": "543337a557c7e9b34bf34978fb0fcde189ab7ccc51c0ee4a8e805448"
75
79
  }
@@ -19,3 +19,13 @@ export const wrapperPackageName = module => `${WRAPPERS_SCOPE}/${module}`
19
19
  * @param {{ readonly module: string, readonly symbol: string }} component
20
20
  */
21
21
  export const wrapperImport = ({ module, symbol }) => `${wrapperPackageName(module)}/${symbol.toLowerCase()}`
22
+
23
+ // The package name keeps the module as is; the symbol comes back from the import specifier.
24
+ const WRAPPER_PACKAGE_IMPORT = new RegExp(`^${WRAPPERS_SCOPE}/([^/]+)/[^/]+$`)
25
+
26
+ /**
27
+ * The module whose wrapper a structure imports, or undefined when the import is not a wrapper entry.
28
+ * @param {string} specifier
29
+ * @returns {string | undefined}
30
+ */
31
+ export const moduleFromWrapperEntry = specifier => WRAPPER_PACKAGE_IMPORT.exec(specifier)?.[1]
@@ -0,0 +1,60 @@
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 provider needs. The export
3
+ // writes these lines, and `yarn dev` and `yarn build` rewrite them when the structure changes, so both follow one rule.
4
+ // Kept free of dependencies, like `wrapperImport.js`, so the generator's bundle doesn't take the transforms with it.
5
+ import { posix } from 'node:path'
6
+ import { moduleFromWrapperEntry, wrapperImport } from './wrapperImport.js'
7
+
8
+ /** The module of the site's own (companion) app. Its providers' viewer services come with the export; other apps' come
9
+ * with the site's services. */
10
+ export const COMPANION_APP = 'companionApp'
11
+
12
+ /** Where an export puts the viewer services the companion app's wrapped context providers need, relative to the site
13
+ * app: each service's bundle and the module that registers it, `<package name>/bundle.js` and `<package name>/index.js`. */
14
+ export const VIEWER_SERVICES_FOLDER = 'src/site/_generated/viewer-services'
15
+
16
+ /**
17
+ * @typedef {{ readonly [module: string]: { readonly entries: {
18
+ * readonly components?: { readonly [name: string]: unknown },
19
+ * readonly contextProviders?: { readonly [name: string]: { readonly services?: readonly string[] } },
20
+ * } } }} WrapperCatalog the site's component catalog (`site-component-catalog.json`), by module
21
+ */
22
+
23
+ /**
24
+ * The module that registers a viewer service, as an item's `_generated` folder imports it.
25
+ * @param {string} generatedFolder the item's `_generated` folder, relative to the site app
26
+ * @param {string} packageName
27
+ */
28
+ export const viewerServiceImport = (generatedFolder, packageName) => {
29
+ const path = posix.relative(generatedFolder, `${VIEWER_SERVICES_FOLDER}/${packageName}/index.js`)
30
+ return path.startsWith('.') ? path : `./${path}`
31
+ }
32
+
33
+ /**
34
+ * 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 viewer service registrations. A folder is the
36
+ * catalog symbol whose `wrapperImport` it is; a function library's folder, or one the catalog doesn't have, brings
37
+ * nothing.
38
+ * @param {Iterable<string>} sources the structure's import sources
39
+ * @param {WrapperCatalog} catalog
40
+ * @param {string} generatedFolder the item's `_generated` folder, relative to the site app
41
+ * @returns {string[]}
42
+ */
43
+ export const wrapperSideEffectImports = (sources, catalog, generatedFolder) => {
44
+ /** @type {Set<string>} */
45
+ const imports = new Set()
46
+ for (const source of sources) {
47
+ const module = moduleFromWrapperEntry(source)
48
+ if (!module) continue
49
+ const { components = {}, contextProviders = {} } = catalog[module]?.entries ?? {}
50
+ /** @param {string} name */
51
+ const isFolder = name => wrapperImport({ module, symbol: name }) === source
52
+ if (Object.keys(components).some(isFolder)) imports.add(`${source}/css`)
53
+ if (module !== COMPANION_APP) continue
54
+ const provider = Object.keys(contextProviders).find(isFolder)
55
+ for (const service of (provider && contextProviders[provider].services) ?? []) {
56
+ imports.add(viewerServiceImport(generatedFolder, service))
57
+ }
58
+ }
59
+ return [...imports]
60
+ }