@wix/origami-site 1.0.33 → 1.0.34

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-site",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "Runs an exported Wix origami site: file-based routing, Wix dynamic pages, popups and build checks. Use with @wix/origami-site-astro or @wix/origami-site-express.",
5
5
  "type": "module",
6
6
  "files": [
@@ -48,7 +48,7 @@
48
48
  "dependencies": {
49
49
  "@wix/origami-types": "1.4.2",
50
50
  "@wix/builder-error-pages": "^1.1.6",
51
- "@wix/origami-transforms": "0.1.41",
51
+ "@wix/origami-transforms": "0.1.42",
52
52
  "@babel/parser": "^7.25.0",
53
53
  "@wix/origami-services": "1.2.7",
54
54
  "@wix/services-manager-react": "^1.0.8",
@@ -93,5 +93,5 @@
93
93
  "optional": true
94
94
  }
95
95
  },
96
- "falconPackageHash": "1e8540ed77ce8d80902fbaeb25b072f5bd1337f1b46d49f6c473949f"
96
+ "falconPackageHash": "600e3e3a0522b524c52f09ddee18178e95c07b24e4cfb2fc123e4d5b"
97
97
  }
@@ -1,15 +1,20 @@
1
1
  import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
2
3
  import { basename, dirname, resolve } from 'node:path'
3
4
  import { parse } from '@babel/parser'
5
+ import { wrapperPackageName } from '@wix/origami-transforms/wrapper-import'
4
6
  import { wrapperSideEffectImports } from '@wix/origami-transforms/wrapper-side-effects'
5
7
  import { relativePath } from './relativePath.js'
8
+ import { readWrapperPackageJson } from './wrapperAliases.js'
6
9
 
7
10
  // An item's `_generated/<Name>.jsx` starts with the side-effect imports of the wrappers its structure imports: each
8
- // component's defaults sheet, and the viewer services a companion app provider needs. The export writes them for the
9
- // structure it exports, so a component type or a provider added to `structure.jsx` by hand afterwards renders without
10
- // its styles, or fails with "Service … is not provided". This plugin rewrites those lines on disk, by the export's
11
- // rule, when the server or the build starts and when a structure is added or changed, so the code that runs is the
12
- // code in the file. It never writes a structure, so its own writes don't trigger it again.
11
+ // component's defaults sheet and its ref element types', and the viewer services a companion app provider needs. The
12
+ // export writes them for the structure it exports, so a component type or a provider added to `structure.jsx` by hand
13
+ // afterwards renders without its styles, or fails with "Service … is not provided". This plugin rewrites those lines on
14
+ // disk, by the export's rule, when the server or the build starts and when a structure is added or changed, so the code
15
+ // that runs is the code in the file. It never writes a structure, so its own writes don't trigger it again. A ref
16
+ // element type's sheet comes off the installed wrapper packages (`collectRefElements`), so the export, which runs before
17
+ // they are installed, writes none, and this adds them.
13
18
  const STRUCTURE = 'structure.jsx'
14
19
  const CATALOG = 'site-component-catalog.json'
15
20
  // The bare imports the file starts with, as the export writes them.
@@ -17,6 +22,24 @@ const LEADING_IMPORTS = /^(?:import (['"])[^'"\r\n]*\1;?\r?\n)*/
17
22
  // The `_generated/index.jsx` line that names the item's module.
18
23
  const ENTRY_EXPORT = /export \{ default \} from '\.\/([^'/]+\.jsx)'/
19
24
 
25
+ /**
26
+ * Each wrapper component's ref element types, by its type, off the `origami.refElements` of the catalog modules'
27
+ * installed wrapper packages. A package from before them, or not installed yet, has none.
28
+ * @param {string} root the site app folder
29
+ * @param {object} catalog
30
+ * @returns {Record<string, string[]>}
31
+ */
32
+ const collectRefElements = (root, catalog) => {
33
+ const require = createRequire(resolve(root, 'package.json'))
34
+ return Object.fromEntries(
35
+ Object.keys(catalog).flatMap(module =>
36
+ Object.entries(readWrapperPackageJson(require, wrapperPackageName(module))?.origami?.refElements ?? {}).map(
37
+ ([symbol, types]) => [`${module}.${symbol}`, types]
38
+ )
39
+ )
40
+ )
41
+ }
42
+
20
43
  /** @param {string} root the site app folder */
21
44
  export const generatedImports = root => {
22
45
  /** @param {string} structurePath @param {(message: string) => void} report */
@@ -32,7 +55,8 @@ export const generatedImports = root => {
32
55
  if (!modulePath || !existsSync(modulePath)) return report(`${relativePath(root, entryPath)} names no module to import the structure's wrappers in`)
33
56
  const sources = parse(readFileSync(structurePath, 'utf8'), { sourceType: 'module', plugins: ['jsx'] })
34
57
  .program.body.flatMap(statement => (statement.type === 'ImportDeclaration' ? [statement.source.value] : []))
35
- const imports = wrapperSideEffectImports(sources, JSON.parse(readFileSync(catalogPath, 'utf8')), relativePath(root, generatedFolder))
58
+ const catalog = JSON.parse(readFileSync(catalogPath, 'utf8'))
59
+ const imports = wrapperSideEffectImports(sources, catalog, relativePath(root, generatedFolder), collectRefElements(root, catalog))
36
60
  const current = readFileSync(modulePath, 'utf8')
37
61
  const next = imports.map(path => `import '${path}'\n`).join('') + current.replace(LEADING_IMPORTS, '')
38
62
  if (next !== current) writeFileSync(modulePath, next)
@@ -22,7 +22,7 @@ const readJson = path => JSON.parse(readFileSync(path, 'utf8'))
22
22
  * @param {NodeJS.Require} require
23
23
  * @param {string} name
24
24
  */
25
- const readWrapperPackageJson = (require, name) => {
25
+ export const readWrapperPackageJson = (require, name) => {
26
26
  try {
27
27
  return readJson(require.resolve(`${name}/package.json`))
28
28
  } catch (error) {