@wix/origami-site 1.0.20 → 1.0.22
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.
|
|
3
|
+
"version": "1.0.22",
|
|
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": [
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"@wix/origami-types": "1.4.2",
|
|
50
50
|
"@wix/builder-error-pages": "^1.1.6",
|
|
51
51
|
"@wix/builder-piler-components": "^1.6.7",
|
|
52
|
-
"@wix/origami-transforms": "0.1.
|
|
52
|
+
"@wix/origami-transforms": "0.1.33",
|
|
53
53
|
"@babel/parser": "^7.25.0",
|
|
54
54
|
"@wix/system-core-components": "^1.3.10",
|
|
55
55
|
"@wix/origami-services": "1.2.4",
|
|
56
56
|
"@wix/services-manager-react": "^1.0.8",
|
|
57
|
-
"@wix/origami-bi": "0.
|
|
57
|
+
"@wix/origami-bi": "0.12.0"
|
|
58
58
|
},
|
|
59
59
|
"exports": {
|
|
60
60
|
"./server": {
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"optional": true
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
-
"falconPackageHash": "
|
|
98
|
+
"falconPackageHash": "d785d6b5dfd0903aa383f497eb21d2f7a0e21e126e74cd734b4c7752"
|
|
99
99
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import {
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
3
|
import {
|
|
4
4
|
companionExports,
|
|
5
5
|
companionModules,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isExtensionFile,
|
|
9
9
|
readCompanionRegistrationsIn,
|
|
10
10
|
} from '@wix/origami-transforms/companion-registrations'
|
|
11
|
+
import { relativePath } from './relativePath.js'
|
|
11
12
|
|
|
12
13
|
// Companion app components and context providers skip the component wrapper server, so they arrive without its
|
|
13
14
|
// wrapping. Each `@site/site-code/<Name>` import resolves to a module that wraps the client entry registered as
|
|
@@ -96,9 +97,6 @@ const exportedName = companionImport => {
|
|
|
96
97
|
return /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name)
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
/** @param {string} from @param {string} to */
|
|
100
|
-
const relativePath = (from, to) => relative(from, to).split(sep).join('/')
|
|
101
|
-
|
|
102
100
|
/**
|
|
103
101
|
* Writes site-code's `package.json` `exports`, as the export does, so a component, context or library added, renamed
|
|
104
102
|
* or removed after the export type-checks with no manual entry. Entries no page imports as `@site/site-code/<Name>`,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { basename, dirname, resolve } from 'node:path'
|
|
3
|
+
import { parse } from '@babel/parser'
|
|
4
|
+
import { wrapperSideEffectImports } from '@wix/origami-transforms/wrapper-side-effects'
|
|
5
|
+
import { relativePath } from './relativePath.js'
|
|
6
|
+
|
|
7
|
+
// 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.
|
|
13
|
+
const STRUCTURE = 'structure.jsx'
|
|
14
|
+
const CATALOG = 'site-component-catalog.json'
|
|
15
|
+
// The bare imports the file starts with, as the export writes them.
|
|
16
|
+
const LEADING_IMPORTS = /^(?:import (['"])[^'"\r\n]*\1;?\r?\n)*/
|
|
17
|
+
// The `_generated/index.jsx` line that names the item's module.
|
|
18
|
+
const ENTRY_EXPORT = /export \{ default \} from '\.\/([^'/]+\.jsx)'/
|
|
19
|
+
|
|
20
|
+
/** @param {string} root the site app folder */
|
|
21
|
+
export const generatedImports = root => {
|
|
22
|
+
/** @param {string} structurePath @param {(message: string) => void} report */
|
|
23
|
+
const sync = (structurePath, report) => {
|
|
24
|
+
const catalogPath = resolve(root, CATALOG)
|
|
25
|
+
const generatedFolder = resolve(dirname(structurePath), '_generated')
|
|
26
|
+
const entryPath = resolve(generatedFolder, 'index.jsx')
|
|
27
|
+
// A site exported before the catalog, or a structure that isn't an exported item, has nothing to rewrite.
|
|
28
|
+
if (!existsSync(catalogPath) || !existsSync(entryPath)) return
|
|
29
|
+
try {
|
|
30
|
+
const name = ENTRY_EXPORT.exec(readFileSync(entryPath, 'utf8'))?.[1]
|
|
31
|
+
const modulePath = name && resolve(generatedFolder, name)
|
|
32
|
+
if (!modulePath || !existsSync(modulePath)) return report(`${relativePath(root, entryPath)} names no module to import the structure's wrappers in`)
|
|
33
|
+
const sources = parse(readFileSync(structurePath, 'utf8'), { sourceType: 'module', plugins: ['jsx'] })
|
|
34
|
+
.program.body.flatMap(statement => (statement.type === 'ImportDeclaration' ? [statement.source.value] : []))
|
|
35
|
+
const imports = wrapperSideEffectImports(sources, JSON.parse(readFileSync(catalogPath, 'utf8')), relativePath(root, generatedFolder))
|
|
36
|
+
const current = readFileSync(modulePath, 'utf8')
|
|
37
|
+
const next = imports.map(path => `import '${path}'\n`).join('') + current.replace(LEADING_IMPORTS, '')
|
|
38
|
+
if (next !== current) writeFileSync(modulePath, next)
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// A structure mid-edit doesn't parse; the import of it reports that, and the server keeps running.
|
|
41
|
+
report(`${relativePath(root, structurePath)}: ${error instanceof Error ? error.message : String(error)}`)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name: 'origami-generated-imports',
|
|
46
|
+
/** @this {import('vite').Rollup.PluginContext} */
|
|
47
|
+
buildStart() {
|
|
48
|
+
for (const structurePath of findStructures(resolve(root, 'src'))) sync(structurePath, message => this.warn(message))
|
|
49
|
+
},
|
|
50
|
+
/** @param {import('vite').ViteDevServer} server */
|
|
51
|
+
configureServer: server => {
|
|
52
|
+
/** @param {string} file */
|
|
53
|
+
const onFile = file => basename(file) === STRUCTURE && sync(file, message => server.config.logger.warn(message))
|
|
54
|
+
for (const event of ['add', 'change']) server.watcher.on(event, onFile)
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Every page's and global component's `structure.jsx` under the site's `src`.
|
|
61
|
+
* @param {string} folder
|
|
62
|
+
* @returns {string[]}
|
|
63
|
+
*/
|
|
64
|
+
const findStructures = folder => {
|
|
65
|
+
if (!existsSync(folder)) return []
|
|
66
|
+
return readdirSync(folder, { withFileTypes: true }).flatMap(entry => {
|
|
67
|
+
if (entry.isDirectory()) return entry.name === '_generated' || entry.name === 'node_modules' ? [] : findStructures(resolve(folder, entry.name))
|
|
68
|
+
return entry.name === STRUCTURE ? [resolve(folder, entry.name)] : []
|
|
69
|
+
})
|
|
70
|
+
}
|
package/src/build/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { transforms } from './transforms.js'
|
|
2
2
|
import { companionComponents } from './companionComponents.js'
|
|
3
|
+
import { generatedImports } from './generatedImports.js'
|
|
3
4
|
import { globalImports } from './globalImports.js'
|
|
4
5
|
import { pageList } from './pageList.js'
|
|
5
6
|
import { sharedPackages } from './sharedPackages.js'
|
|
@@ -17,6 +18,7 @@ export function origamiVitePlugins({ root, siteTree }) {
|
|
|
17
18
|
...transforms({ root }),
|
|
18
19
|
servicesConfigsReload(root),
|
|
19
20
|
companionComponents(root),
|
|
21
|
+
generatedImports(root),
|
|
20
22
|
sharedPackages(),
|
|
21
23
|
wrapperAliases(root),
|
|
22
24
|
browserEnv(),
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { relative, sep } from 'node:path'
|
|
2
|
+
|
|
3
|
+
/** `to` relative to `from`, with `/` separators, as imports and `package.json` `exports` write it.
|
|
4
|
+
* @param {string} from @param {string} to */
|
|
5
|
+
export const relativePath = (from, to) => relative(from, to).split(sep).join('/')
|