davidwarrington / liquid-schema-plugin

Build reusable section schemas using Javascript
42 stars 4 forks source link

`Syntax Error in 'schema' - Valid syntax: schema` #16

Open tomaszs opened 2 years ago

tomaszs commented 2 years ago

My webpack config looks like this:

new LiquidSchemaPlugin({
      from: {
          liquid: './src/sections',
          schema: './src/schema'
      },
      to: './dist/sections'
    }),

Inside schema folder I have put mycode.js file that looks like this:

module.exports = (filename, content) => {
  return content;
}

And i use it in a section located in sections folder that way:

{% schema 'mycode' %}

But I get error:

Syntax Error in 'schema' - Valid syntax: schema

And:

>>> ERR :: deployment failed undefined 1 null [development] Errors encountered: 
    [development] (sections/mysection.liquid) Liquid syntax error (line 39): Syntax Error in 'schema' - Valid syntax: schema
finished command with errors

I have tried adding to mysection this:

{% comment %}theme-check-disable ValidSchema,SyntaxError{% endcomment %}

And to my package.json file this:

theme-check --exclude-category liquid

But it does not work. How to make it work?

davidwarrington commented 2 years ago

Please could you share what the schema looks like in your dist/sections/mysection.liquid file?

If the schema in your section file is literally just {% schema 'mycode' %} the content variable in your mycode.js is probably null.

tomaszs commented 2 years ago

Hello David,

It is whole schema, so there is schema tag like the one I wrote, than there is a valid JSON (validated and working) and then there is schema closing tag, something like this

{% schema 'mycode' %}
{
  "name": "Slideshow",
  "tag": "section",
  "class": "slideshow",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Slideshow"
    }
  ],
  "blocks": [
     {
       "name": "Slide",
       "type": "slide",
       "settings": [
         {
           "type": "image_picker",
           "id": "image",
           "label": "Image"
         }
       ]
     }
   ]
}
{% endschema %}

When I remove mycode from the schema tag, everything works. It looks like the notation is not validated as a proper schema or something

davidwarrington commented 2 years ago

Hi @tomaszs, sorry for taking so long to get back to you.

Just to confirm, is the code block above from ./dist/sections/mysection.liquid or ./src/sections/mysection.liquid?

If it's the former it would seem my plugin isn't building your files properly but I've not been able to reproduce the issue. Would you be able to share a repo with the bare minimum required to replicate this issue?

As for your Theme Check error, it looks like Theme Check doesn't allow you to disable ValidSchema or SyntaxError rules with theme-check-disable comments. Depending on the other tools in your build this might be pointless, but you could perhaps try running Theme Check in your ./dist folder instead of ./src?

tomaszs commented 2 years ago

Hello David,

It i from src file sorry. Missed that you wanted it from dist. Yeah. It seems like Theme Check. They should add a rule that handles your plugin