@wix/origami-site 0.1.1 → 0.1.2

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": "0.1.1",
3
+ "version": "0.1.2",
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": [
@@ -14,7 +14,9 @@
14
14
  "devDependencies": {
15
15
  "@types/node": "^22.0.0",
16
16
  "typescript": "^6.0.3",
17
- "vite": "^8"
17
+ "vite": "^8",
18
+ "@vitejs/plugin-react": "^5.2.0",
19
+ "postcss": "^8.5.3"
18
20
  },
19
21
  "publishUnscoped": false,
20
22
  "publishConfig": {
@@ -44,6 +46,7 @@
44
46
  "react-dom": "^18.3.1",
45
47
  "@wix/builder-error-pages": "^1.1.6",
46
48
  "@wix/builder-piler-components": "^1.6.7",
49
+ "@wix/origami-transforms": "0.1.2",
47
50
  "@babel/parser": "^7.25.0"
48
51
  },
49
52
  "exports": {
@@ -59,14 +62,20 @@
59
62
  "types": "./src/popups/index.d.ts",
60
63
  "default": "./src/popups/index.js"
61
64
  },
62
- "./vite-plugins": {
63
- "types": "./src/vite-plugins/index.d.ts",
64
- "default": "./src/vite-plugins/index.js"
65
+ "./build": {
66
+ "types": "./src/build/index.d.ts",
67
+ "default": "./src/build/index.js"
65
68
  },
66
69
  "./types": {
67
70
  "types": "./src/types/index.d.ts"
68
71
  },
69
- "./default-error-404": "./src/default-error-404.jsx"
72
+ "./default-error-404": {
73
+ "types": "./src/default-error-404.d.ts",
74
+ "default": "./src/default-error-404.jsx"
75
+ }
76
+ },
77
+ "peerDependencies": {
78
+ "vite": "^8"
70
79
  },
71
- "falconPackageHash": "236041398ac8f5cb5996fd571ab7dbe9f17287f25c51e01599157dc7"
80
+ "falconPackageHash": "c7e37593d4cdf506898d4bc2680d2948adb3027e23c106ffad08d458"
72
81
  }
@@ -0,0 +1,18 @@
1
+ import { existsSync, statSync } from 'node:fs'
2
+ import { dirname, resolve, sep } from 'node:path'
3
+
4
+ /** @param {string} root
5
+ * @returns {import('vite').Plugin} */
6
+ export const globalImports = root => ({
7
+ name: 'origami:global-imports',
8
+ enforce: /** @type {const} */ ('pre'),
9
+ resolveId(source, importer) {
10
+ if (!importer || source === './' || !(source.startsWith('./') || source.startsWith('../'))) return undefined
11
+ const folder = resolve(dirname(importer.split('?', 1)[0]), source)
12
+ if (!folder.startsWith(`${resolve(root, 'src/global')}${sep}`)) return undefined
13
+ const entry = resolve(folder, '_generated/index.jsx')
14
+ if (existsSync(folder) && statSync(folder).isDirectory() && existsSync(entry) && statSync(entry).isFile())
15
+ return entry
16
+ return undefined
17
+ },
18
+ })
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'vite'
2
+ import type { OrigamiSite } from '../server/index.js'
3
+
4
+ export type OrigamiVitePluginsOptions = {
5
+ /** The site package folder, containing src/pages/, src/global/, and src/site/ glue. */
6
+ root: string
7
+ /** Shared with the adapter; the plugins do not scan or own the site tree. */
8
+ siteTree: Pick<OrigamiSite, 'table' | 'onTableChange'>
9
+ }
10
+ export function origamiVitePlugins(options: OrigamiVitePluginsOptions): Plugin[]
@@ -0,0 +1,15 @@
1
+ import { transforms } from './transforms.js'
2
+ import { globalImports } from './globalImports.js'
3
+ import { pageList } from './pageList.js'
4
+ import { sharedPackages } from './sharedPackages.js'
5
+
6
+ /** @param {import('./index.js').OrigamiVitePluginsOptions} options
7
+ * @returns {import('vite').Plugin[]} */
8
+ export function origamiVitePlugins({ root, siteTree }) {
9
+ return [
10
+ globalImports(root),
11
+ pageList(siteTree),
12
+ ...transforms({ root }),
13
+ sharedPackages(),
14
+ ]
15
+ }
@@ -0,0 +1,37 @@
1
+ const publicId = 'virtual:origami-site'
2
+ const resolvedId = `\0${publicId}`
3
+
4
+ /** @param {import('@wix/origami-types').SiteRouteTable} table */
5
+ function moduleSource(table) {
6
+ // itemPath is relative to src/ and already includes the pages/ prefix.
7
+ const entries = [...table.pages, table.notFound].map(page => {
8
+ const entry = page.itemPath
9
+ ? `/src/${page.itemPath}/_generated/index.jsx`
10
+ : '@wix/origami-site/default-error-404'
11
+ return ` [${JSON.stringify(page.key)}]: () => import(${JSON.stringify(entry)})`
12
+ })
13
+ return `export const pages = {\n${entries.join(',\n')}\n};\nexport const popups = {};\nexport const seoUriByPageId = {};\n`
14
+ }
15
+
16
+ /** @param {import('./index.js').OrigamiVitePluginsOptions['siteTree']} siteTree
17
+ * @returns {import('vite').Plugin} */
18
+ export function pageList(siteTree) {
19
+ /** @type {(() => void) | undefined} */
20
+ let unsubscribe
21
+ return {
22
+ name: 'origami:page-list',
23
+ resolveId(id) { if (id === publicId) return resolvedId },
24
+ async load(id) { if (id === resolvedId) return moduleSource(await siteTree.table()) },
25
+ configureServer(server) {
26
+ unsubscribe?.()
27
+ unsubscribe = siteTree.onTableChange(() => {
28
+ for (const environment of Object.values(server.environments)) {
29
+ const module = environment.moduleGraph.getModuleById(resolvedId)
30
+ if (module) environment.moduleGraph.invalidateModule(module)
31
+ }
32
+ server.ws.send({ type: 'full-reload', path: '*' })
33
+ })
34
+ },
35
+ closeBundle() { unsubscribe?.(); unsubscribe = undefined },
36
+ }
37
+ }
@@ -0,0 +1,14 @@
1
+ /** @returns {import('vite').Plugin} */
2
+ export function sharedPackages() {
3
+ return {
4
+ name: 'origami:shared-packages',
5
+ config: () => ({ resolve: { dedupe: [
6
+ 'react',
7
+ 'react-dom',
8
+ '@wix/services-manager-react',
9
+ '@wix/sdk-react-context',
10
+ '@preact/signals-react',
11
+ '@preact/signals-core',
12
+ ] } }),
13
+ }
14
+ }
@@ -0,0 +1,27 @@
1
+ import { resolve } from 'node:path'
2
+ import { createTransformPipeline } from '@wix/origami-transforms'
3
+
4
+ /** @param {{ root: string }} options
5
+ * @returns {import('vite').Plugin[]} */
6
+ export function transforms({ root }) {
7
+ const pipeline = createTransformPipeline({ layout: { root: resolve(root) } })
8
+ return [
9
+ {
10
+ name: 'origami:jsx-checks',
11
+ enforce: 'pre',
12
+ config(_, { command }) { pipeline.setCommand(command) },
13
+ transform(code, id, options) {
14
+ if (pipeline.appliesTo(id, { ssr: options?.ssr })) return pipeline.transformJsx(code, id, { ssr: options?.ssr })
15
+ },
16
+ },
17
+ {
18
+ name: 'origami:css-transforms',
19
+ config: () => ({ css: { postcss: { plugins: [pipeline.postcssPlugin] } } }),
20
+ handleHotUpdate({ file, server }) {
21
+ if (pipeline.failedStylesheetDependsOn(resolve(file))) {
22
+ server.ws.send({ type: 'full-reload', path: '*' })
23
+ }
24
+ },
25
+ },
26
+ ]
27
+ }
@@ -0,0 +1,4 @@
1
+ import type { ComponentType } from 'react'
2
+
3
+ declare const DefaultError404: ComponentType
4
+ export default DefaultError404
@@ -1,9 +1,4 @@
1
- import React from 'react'
2
- import { createRoot } from 'react-dom/client'
3
1
  import { DefaultError404 } from '@wix/builder-error-pages'
4
- import { PilerPage } from '@wix/builder-piler-components'
5
2
  import '@wix/builder-error-pages/style.css'
6
3
 
7
- createRoot(document.getElementById('root')).render(
8
- React.createElement(React.StrictMode, null, React.createElement(PilerPage, { Page: DefaultError404 }))
9
- )
4
+ export default DefaultError404
@@ -1,2 +0,0 @@
1
- import type { Plugin } from 'vite'
2
- export function origamiVitePlugins(options: { root: string }): Plugin[]
@@ -1 +0,0 @@
1
- export {}