@wix/origami-site-runtime 1.0.3 → 1.0.5

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",
3
+ "version": "1.0.5",
4
4
  "description": "Vite development and build helpers for wix-import static sites",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "@babel/types": "^7.25.2",
20
20
  "@wix/builder-error-pages": "^1.1.6",
21
21
  "@wix/builder-piler-components": "^1.6.7",
22
- "@wix/origami-runtime": "0.9.0",
22
+ "@wix/origami-runtime": "0.10.0",
23
23
  "postcss": "^8.5.3",
24
24
  "postcss-custom-media": "^12.0.1",
25
25
  "react": "^18.3.1",
@@ -64,5 +64,5 @@
64
64
  "./default-error-404": "./src/default-error-404.jsx"
65
65
  },
66
66
  "type": "module",
67
- "falconPackageHash": "85b492ce3a05b09e7ef072ed40132bd25eb8316f3c6e7549596f550d"
67
+ "falconPackageHash": "203443429f6ecbdef5a36d850631bd595d5680e2a7b26e65f97fbe5a"
68
68
  }
@@ -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
+ }