@wix/origami-site 0.1.11 → 0.1.12

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.11",
3
+ "version": "0.1.12",
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": [
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@wix/origami-types": "1.3.0",
46
+ "@wix/origami-types": "1.4.0",
47
47
  "react": "^18.3.1",
48
48
  "react-dom": "^18.3.1",
49
49
  "@wix/builder-error-pages": "^1.1.6",
@@ -79,5 +79,5 @@
79
79
  "peerDependencies": {
80
80
  "vite": "^8"
81
81
  },
82
- "falconPackageHash": "24c3e9be28422eca894ae970057d12bb43ca7f2b2231d6a51421ada9"
82
+ "falconPackageHash": "a080aee82c31bea3d382a432f657bcad446c30c80db3c94acb7b8f0c"
83
83
  }
@@ -2,10 +2,9 @@
2
2
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
3
3
  import { basename, resolve } from 'node:path'
4
4
  import { parse } from '@babel/parser'
5
+ import { findItems, pageUrl } from '@wix/origami-types'
5
6
  import { SiteTreeError } from '../requests/errors.js'
6
7
 
7
-
8
-
9
8
  /** @type {Map<string, { mtimeMs: number, metadata: { title?: string, pageId?: string } }>} */
10
9
  const metadataCache = new Map()
11
10
 
@@ -63,43 +62,31 @@ export const siteRoot = root => {
63
62
 
64
63
  /** @param {string} root @returns {Promise<import('@wix/origami-types').SiteRouteTable>} */
65
64
  export const readSiteTree = async root => {
66
- const pagesDir = resolve(siteRoot(root), 'src/pages')
65
+ const src = resolve(siteRoot(root), 'src')
67
66
  /** @type {import('@wix/origami-types').PageRoute[]} */
68
67
  const pages = []
69
68
  /** @type {import('@wix/origami-types').SiteNotFoundRoute} */
70
69
  let notFound = { key: '@wix/origami-site/default-error-404', title: 'Page not found' }
71
- const walk = (folder, itemPath) => {
72
- const entries = readdirSync(folder, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))
70
+ const pathsByUrl = new Map()
71
+ const { items, routers } = existsSync(resolve(src, 'pages'))
72
+ ? findItems(path => readdirSync(resolve(src, path), { withFileTypes: true }), 'pages')
73
+ : { items: [], routers: [] }
74
+ if (routers.length) throw new SiteTreeError('NOT_SUPPORTED_YET', [`src/${routers[0]}`], 'Router pages are not supported yet.')
75
+ for (const itemPath of items) {
73
76
  const path = `src/${itemPath}`
74
- const isItem = entries.some(entry => entry.isFile() && entry.name === 'version')
75
- if (isItem) {
76
- const metadata = pageMetadata(folder)
77
- if (itemPath === 'pages/error404') notFound = { key: itemPath, itemPath, title: metadata.title }
78
- else {
79
- const url = '/' + itemPath.split('/').slice(1).filter(segment => !/^\([^()]+\)$/.test(segment)).join('/')
80
- pages.push({ key: itemPath, url, itemPath, ...metadata, access: [] })
81
- }
77
+ const metadata = pageMetadata(resolve(src, itemPath))
78
+ if (itemPath === 'pages/error404') notFound = { key: itemPath, itemPath, title: metadata.title }
79
+ else {
80
+ const url = pageUrl(itemPath)
81
+ const previous = pathsByUrl.get(url)
82
+ if (previous) throw new SiteTreeError('DUPLICATE_URL', [previous, path], `Both pages serve "${url}".`)
83
+ pathsByUrl.set(url, path)
84
+ pages.push({ key: itemPath, url, itemPath, ...metadata, access: [] })
82
85
  }
83
- const children = entries.filter(entry => entry.isDirectory() && !entry.name.startsWith('.') &&
84
- !['_generated', 'node_modules', 'servicesConfigs'].includes(entry.name))
85
- .filter(child => walk(resolve(folder, child.name), `${itemPath}/${child.name}`))
86
- if (!isItem && !children.length) return false
87
- if (/^\[.*\]$/.test(basename(folder)))
88
- throw new SiteTreeError('NOT_SUPPORTED_YET', [path], 'Router pages are not supported yet.')
89
- if (entries.some(entry => entry.name === 'route.json'))
90
- throw new SiteTreeError('NOT_SUPPORTED_YET', [`${path}/route.json`], 'Router pages are not supported yet.')
91
- if (itemPath === 'pages/error404' && children.length)
92
- throw new SiteTreeError('NOT_FOUND_HAS_CHILDREN', [path, ...children.map(child => `${path}/${child.name}`)],
93
- 'The not-found page cannot have children.')
94
- return true
95
- }
96
- if (existsSync(pagesDir)) walk(pagesDir, 'pages')
97
- const pathsByUrl = new Map()
98
- for (const page of pages) {
99
- const path = `src/${page.itemPath}`
100
- const previous = pathsByUrl.get(page.url)
101
- if (previous) throw new SiteTreeError('DUPLICATE_URL', [previous, path], `Both pages serve "${page.url}".`)
102
- pathsByUrl.set(page.url, path)
103
86
  }
87
+ const notFoundChildren = pages.filter(page => page.itemPath.startsWith('pages/error404/'))
88
+ if (notFoundChildren.length)
89
+ throw new SiteTreeError('NOT_FOUND_HAS_CHILDREN', ['src/pages/error404', ...notFoundChildren.map(page => `src/${page.itemPath}`)],
90
+ 'The not-found page cannot have children.')
104
91
  return { version: 2, pages, routers: [], notFound, popups: [] }
105
92
  }