@wix/origami-site 1.0.13 → 1.0.14

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.13",
3
+ "version": "1.0.14",
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
  "@wix/origami-types": "1.4.2",
49
49
  "@wix/builder-error-pages": "^1.1.6",
50
50
  "@wix/builder-piler-components": "^1.6.7",
51
- "@wix/origami-transforms": "0.1.24",
51
+ "@wix/origami-transforms": "0.1.25",
52
52
  "@babel/parser": "^7.25.0",
53
53
  "@wix/system-core-components": "^1.3.10",
54
54
  "@wix/origami-services": "1.2.4",
@@ -93,5 +93,5 @@
93
93
  "optional": true
94
94
  }
95
95
  },
96
- "falconPackageHash": "7476a05fa90caef655a64a8fa35681677a2f8aa390f6e97c03552d57"
96
+ "falconPackageHash": "6c67a026beecadeb574da81d4e507819638b8213bc9559ebabeb4fd2"
97
97
  }
@@ -11,10 +11,14 @@ import {
11
11
 
12
12
  // Companion app components and context providers skip the component wrapper server, so they arrive without its
13
13
  // wrapping. Each `@site/site-code/<Name>` import resolves to a module that wraps the client entry registered as
14
- // `companionApp.<Name>` the way the server wraps its components and providers, without the presets. TypeScript doesn't run this plugin: it resolves the same import through
15
- // site-code's `package.json` `exports`, which this plugin keeps in step with the registrations.
14
+ // `companionApp.<Name>` the way the server wraps its components and providers, without the presets. A function
15
+ // library's module re-exports its client entry, unwrapped, as the server's library wrapper does.
16
+ // TypeScript doesn't run this plugin: it resolves the same import through site-code's `package.json` `exports`, which
17
+ // this plugin keeps in step with the registrations.
16
18
  const IMPORT = /^@site\/site-code\/([A-Za-z_$][\w$]*)$/
17
19
  const PREFIX = '\0origami-companion:'
20
+ // The `exports` entry of an `@site/site-code/<Name>` import.
21
+ const COMPANION_EXPORT = /^\.\/[A-Za-z_$][\w$]*$/
18
22
 
19
23
  /** @param {string} siteRoot */
20
24
  export const companionComponents = siteRoot => {
@@ -68,6 +72,7 @@ export const companionComponents = siteRoot => {
68
72
  // The wrapper comes from the registration file, so editing it reloads the module.
69
73
  this.addWatchFile(module.registration.path)
70
74
  const from = JSON.stringify(entry(module.registration))
75
+ if (module.registration.kind === 'functionLibrary') return `export * from ${from}`
71
76
  const exported = exportedName(module.import)
72
77
  const wrapped =
73
78
  module.registration.kind === 'component' ? 'withInteractions(withOrigami(Raw))' : 'withOrigami(Raw)'
@@ -95,14 +100,19 @@ const exportedName = companionImport => {
95
100
  const relativePath = (from, to) => relative(from, to).split(sep).join('/')
96
101
 
97
102
  /**
98
- * Writes site-code's `package.json` `exports`, as the export does, so a component or context added, renamed or
99
- * removed after the export type-checks with no manual entry. import-site uploads the stored `exports`, not these.
100
- * @param {string} appRoot @param {Record<string, string>} exports
103
+ * Writes site-code's `package.json` `exports`, as the export does, so a component, context or library added, renamed
104
+ * or removed after the export type-checks with no manual entry. Entries no page imports as `@site/site-code/<Name>`,
105
+ * such as `.`, are kept. import-site uploads the stored `exports`, not these.
106
+ * @param {string} appRoot @param {Record<string, string>} registered
101
107
  */
102
- const writeExports = (appRoot, exports) => {
108
+ const writeExports = (appRoot, registered) => {
103
109
  const packagePath = resolve(appRoot, 'package.json')
104
110
  if (!existsSync(packagePath)) return
105
111
  const packageJson = JSON.parse(readFileSync(packagePath, 'utf8'))
112
+ // A string `exports` is the package's `.` entry.
113
+ const current = typeof packageJson.exports === 'string' ? { '.': packageJson.exports } : (packageJson.exports ?? {})
114
+ const others = Object.entries(current).filter(([key]) => !COMPANION_EXPORT.test(key))
115
+ const exports = { ...Object.fromEntries(others), ...registered }
106
116
  if (JSON.stringify(exports) === JSON.stringify(packageJson.exports)) return
107
117
  writeFileSync(packagePath, `${JSON.stringify({ ...packageJson, exports }, null, 2)}\n`)
108
118
  }