@wix/origami-site 0.1.14 → 0.1.16
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.
|
|
3
|
+
"version": "0.1.16",
|
|
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": [
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"optional": true
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
|
-
"falconPackageHash": "
|
|
94
|
+
"falconPackageHash": "98246cb0560035c80b813a0c4d4937ea7d4530365e6eab3d5f7226a4"
|
|
95
95
|
}
|
package/src/server/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type SiteOptions = {
|
|
|
8
8
|
root: string // the site package folder
|
|
9
9
|
mode: 'dev' | 'prod'
|
|
10
10
|
table?: SiteRouteTable // prod: the table from the build. dev: omitted, the core scans.
|
|
11
|
-
wix: { clientId: string; siteId: string } // from VITE_WIX_CLIENT_ID /
|
|
11
|
+
wix: { clientId: string; siteId: string } // from VITE_WIX_CLIENT_ID / VITE_WIX_METASITE_ID
|
|
12
12
|
tokens?: TokenProvider // default: rejects until router support (stage 2)
|
|
13
13
|
access?: AccessSource // default: noAccessRules (4)
|
|
14
14
|
accessHandlers?: AccessHandler[] // default: []
|
|
@@ -80,3 +80,7 @@ export function getAccessToken(): Promise<string>
|
|
|
80
80
|
export function serializePageData(data: PageData): string
|
|
81
81
|
/** The core's plain HTML error page: logs the stack, shows the message in dev only, `cache-control: no-store`. */
|
|
82
82
|
export function errorResponse(error: unknown, options: { status?: 500 | 503; mode: 'dev' | 'prod'; logger?: Logger }): Response
|
|
83
|
+
/** `yarn build`: writes `<serverOutDir>/origami-routes.json`, atomically. */
|
|
84
|
+
export function writeBuiltTable(serverOutDir: string, table: SiteRouteTable): Promise<void>
|
|
85
|
+
/** `yarn start`: reads it back; throws on a missing file, an unknown format or another core major. */
|
|
86
|
+
export function readBuiltTable(serverOutDir: string): Promise<SiteRouteTable>
|
package/src/server/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { readSiteTree } from './site-tree/readSiteTree.js'
|
|
2
|
+
export { writeBuiltTable, readBuiltTable } from './site-tree/builtTable.js'
|
|
2
3
|
export { SiteTreeError } from './requests/errors.js'
|
|
3
4
|
export { createSite, noAccessRules } from './requests/createSite.js'
|
|
4
5
|
export { runInRequestContext, getRequestContext, getAccessToken } from './requests/context.js'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
const FILE = 'origami-routes.json'
|
|
5
|
+
const FORMAT = 1
|
|
6
|
+
const corePackage = JSON.parse(await readFile(new URL('../../../package.json', import.meta.url), 'utf8'))
|
|
7
|
+
const breakingPart = version => {
|
|
8
|
+
const [first, second] = String(version).split('.')
|
|
9
|
+
return first === '0' ? `0.${second}` : first
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Writes the route table `yarn build` used, beside (never inside) the public client folder.
|
|
13
|
+
* @param {string} serverOutDir @param {import('@wix/origami-types').SiteRouteTable} table */
|
|
14
|
+
export async function writeBuiltTable(serverOutDir, table) {
|
|
15
|
+
await mkdir(serverOutDir, { recursive: true })
|
|
16
|
+
const path = join(serverOutDir, FILE)
|
|
17
|
+
// Temp file plus rename: a crashed build never leaves half a table.
|
|
18
|
+
const temporary = `${path}.${process.pid}.tmp`
|
|
19
|
+
await writeFile(temporary, `${JSON.stringify({ format: FORMAT, core: corePackage.version, table }, null, 2)}\n`)
|
|
20
|
+
await rename(temporary, path)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @param {string} serverOutDir @returns {Promise<import('@wix/origami-types').SiteRouteTable>} */
|
|
24
|
+
export async function readBuiltTable(serverOutDir) {
|
|
25
|
+
const path = join(serverOutDir, FILE)
|
|
26
|
+
let file
|
|
27
|
+
try { file = JSON.parse(await readFile(path, 'utf8')) } catch (error) {
|
|
28
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') throw new Error(`No route table at ${path}: run yarn build first.`)
|
|
29
|
+
throw new Error(`The route table at ${path} is not valid JSON: run yarn build again.`, { cause: error })
|
|
30
|
+
}
|
|
31
|
+
if (file?.format !== FORMAT || file.table?.version !== 2) throw new Error(`The route table at ${path} has an unknown format: run yarn build again.`)
|
|
32
|
+
// While 0.x, a minor is breaking, as ^ ranges treat it.
|
|
33
|
+
if (breakingPart(file.core) !== breakingPart(corePackage.version))
|
|
34
|
+
throw new Error(`The route table at ${path} was built by @wix/origami-site ${file.core}, this is ${corePackage.version}: rebuild after upgrading.`)
|
|
35
|
+
return file.table
|
|
36
|
+
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** What each adapter package exports as
|
|
1
|
+
/** What each adapter package exports as the default export of its `./adapter` entry. */
|
|
2
2
|
export interface OrigamiAdapter {
|
|
3
3
|
name: string // '@wix/origami-site-astro'
|
|
4
4
|
version: string // its package version
|
|
@@ -12,11 +12,11 @@ export interface OrigamiAdapter {
|
|
|
12
12
|
export type ProjectContext = {
|
|
13
13
|
siteName: string
|
|
14
14
|
coreVersion: string // the @wix/origami-site range to depend on
|
|
15
|
-
nodeVersion: string // '
|
|
15
|
+
nodeVersion: string // '24'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export type ProjectFiles = {
|
|
19
|
-
files: Record<string /* path relative to the site package */, string /* contents */> // e.g. astro.config.mjs
|
|
19
|
+
files: Record<string /* path relative to the site package */, string /* contents */> // e.g. astro.config.mjs
|
|
20
20
|
packageJson: {
|
|
21
21
|
scripts: { dev: string; build: string; start: string } & Record<string, string>
|
|
22
22
|
dependencies: Record<string, string>
|
|
@@ -35,7 +35,7 @@ export interface ConformanceDriver {
|
|
|
35
35
|
start(root: string, env: SiteEnv): Promise<RunningSite>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export type SiteEnv = Record<string, string> // VITE_WIX_CLIENT_ID,
|
|
38
|
+
export type SiteEnv = Record<string, string> // VITE_WIX_CLIENT_ID, VITE_WIX_METASITE_ID, ORIGAMI_WIX_API_BASE (tests), PORT
|
|
39
39
|
export type RunningSite = { url: URL; logs(): string; restarts(): number; stop(): Promise<void> }
|
|
40
40
|
export type BuildResult = { ok: true; output: string } | { ok: false; output: string }
|
|
41
41
|
|