@wix/origami-site-runtime 1.0.3 → 1.0.4
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-runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Vite development and build helpers for wix-import static sites",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"./default-error-404": "./src/default-error-404.jsx"
|
|
65
65
|
},
|
|
66
66
|
"type": "module",
|
|
67
|
-
"falconPackageHash": "
|
|
67
|
+
"falconPackageHash": "14925f95729c0077ece00a2bb4ba11d8be4a53aa16e14d1a5eaa5fdc"
|
|
68
68
|
}
|
package/src/jsxPlugins/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// `order`. A descriptor needs a `name`, an `order`, and `transform(program, context)`, where
|
|
3
3
|
// `program` is the Babel Program path for the module; see `../transform/types.js`.
|
|
4
4
|
|
|
5
|
+
import { mediaValidationPlugin } from './mediaValidation/index.js'
|
|
5
6
|
import { origamiCompatibilityPlugin } from './origamiCompatibility/index.js'
|
|
6
7
|
import { layoutValidationPlugin } from './validation/index.js'
|
|
7
8
|
|
|
8
9
|
/** @type {readonly import('../transform/types.js').JsxTransformPlugin[]} */
|
|
9
|
-
export const jsxPlugins = Object.freeze([layoutValidationPlugin, origamiCompatibilityPlugin])
|
|
10
|
+
export const jsxPlugins = Object.freeze([layoutValidationPlugin, mediaValidationPlugin, origamiCompatibilityPlugin])
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Fails the build on an Image whose `uri` is not a Wix media ID, such as a web URL or a local file.
|
|
2
|
+
// The Wix import accepts such a `uri` but the image is broken on the site; `origami upload-media`
|
|
3
|
+
// uploads it and points the Image at the uploaded file. `yarn dev` only warns, so the page still
|
|
4
|
+
// previews. Like the layout rules, Image is identified by its JSX tag name, and a computed `uri` is
|
|
5
|
+
// not checked.
|
|
6
|
+
|
|
7
|
+
import { basename } from 'node:path'
|
|
8
|
+
import { LayoutError } from '../../transform/layoutError.js'
|
|
9
|
+
|
|
10
|
+
const STRUCTURE_FILES = new Set(['structure.tsx', 'structure.jsx'])
|
|
11
|
+
|
|
12
|
+
// `117a96_1cff23187eeb4050a2a691bcdcad6502~mv2.jpg`: an account prefix, an underscore and a file name.
|
|
13
|
+
const WIX_MEDIA_ID = /^[A-Za-z0-9]+_[A-Za-z0-9_~.-]+\.[A-Za-z0-9]+$/
|
|
14
|
+
|
|
15
|
+
/** @type {import('../../transform/types.js').JsxTransformPlugin} */
|
|
16
|
+
export const mediaValidationPlugin = {
|
|
17
|
+
name: 'wix-import-media-validation',
|
|
18
|
+
// Alongside the layout rules: before anything rewrites the tree.
|
|
19
|
+
order: -100,
|
|
20
|
+
appliesTo: context => STRUCTURE_FILES.has(basename(context.filePath)),
|
|
21
|
+
|
|
22
|
+
transform: (program, context) => {
|
|
23
|
+
const file = context.relativePath ?? context.filePath
|
|
24
|
+
const violations = []
|
|
25
|
+
let first
|
|
26
|
+
program.traverse({
|
|
27
|
+
JSXOpeningElement({ node }) {
|
|
28
|
+
if (node.name.type !== 'JSXIdentifier' || node.name.name !== 'Image') return
|
|
29
|
+
const attributes = node.attributes.filter(attribute => attribute.type === 'JSXAttribute')
|
|
30
|
+
const image = attributes.find(attribute => attribute.name.name === 'image')?.value?.expression
|
|
31
|
+
const uri = image?.type === 'ObjectExpression' &&
|
|
32
|
+
image.properties.find(property => property.key?.name === 'uri' || property.key?.value === 'uri')
|
|
33
|
+
if (uri?.value.type !== 'StringLiteral' || WIX_MEDIA_ID.test(uri.value.value)) return
|
|
34
|
+
const id = attributes.find(attribute => attribute.name.name === 'id')?.value?.value
|
|
35
|
+
const line = uri.loc?.start.line
|
|
36
|
+
violations.push(
|
|
37
|
+
`${file}${line ? `:${line}` : ''} <Image${id ? ` id="${id}"` : ''}> image.uri "${uri.value.value}" is not a Wix media ID. Run \`origami upload-media\` to upload it.`
|
|
38
|
+
)
|
|
39
|
+
first ??= { file: context.filePath, line, column: uri.loc?.start.column }
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
if (violations.length === 0) return
|
|
43
|
+
if (context.command === 'serve') {
|
|
44
|
+
for (const violation of violations) console.warn(`[origami] ${violation}`)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
throw new LayoutError(violations, first)
|
|
48
|
+
},
|
|
49
|
+
}
|