asciidoctor / asciidoctor-kroki

Asciidoctor.js extension to convert diagrams to images using Kroki!
https://kroki.io/
MIT License
146 stars 47 forks source link

Antora integration - Error "Opal is not defined" #389

Closed AndreVirtimo closed 1 year ago

AndreVirtimo commented 1 year ago

I have an existing Antora (3.0.1) Project and added this extension by:

npm i asciidoctor-kroki

and add the extension to my playbook:

antora:
  extensions:
    - require: '@antora/lunr-extension'
    - asciidoctor-kroki

When I run antora I get an error:

bpc-docs git:(support/3.5.x) ✗ antora --fetch antora-playbook-local.yml --stacktrace
ReferenceError: Opal is not defined
    at register (/Users/andre/Workspace/bpc-docs/node_modules/asciidoctor-kroki/src/asciidoctor-kroki.js:220:20)
    at /Users/andre/Workspace/bpc-docs/node_modules/@antora/site-generator/lib/generator-context.js:149:37
    at Array.forEach (<anonymous>)
    at GeneratorContext._registerExtensions (/Users/andre/Workspace/bpc-docs/node_modules/@antora/site-generator/lib/generator-context.js:142:18)
    at GeneratorContext._init (/Users/andre/Workspace/bpc-docs/node_modules/@antora/site-generator/lib/generator-context.js:131:10)
    at Function.start (/Users/andre/Workspace/bpc-docs/node_modules/@antora/site-generator/lib/generator-context.js:114:34)
    at generateSite (/Users/andre/Workspace/bpc-docs/node_modules/@antora/site-generator/lib/generate-site.js:10:51)
    at Command.<anonymous> (/usr/local/lib/node_modules/@antora/cli/lib/cli.js:76:20)
    at Command.listener [as _actionHandler] (/usr/local/lib/node_modules/@antora/cli/node_modules/commander/index.js:426:31)
    at Command._parseCommand (/usr/local/lib/node_modules/@antora/cli/node_modules/commander/index.js:1002:14)
ggrossetie commented 1 year ago

@mojavelinux I believe the reason is that Asciidoctor.js is not yet loaded. I think we need to defer this call right? Is it bad to call LoggerManager.getLogger() every time the block or inline block macro is called?

mojavelinux commented 1 year ago

The issue here is that you are trying to require an Asciidoctor extension as an Antora extension. These are not the same thing. The declaration in the playbook should be:

asciidoc:
  extensions:
  - asciidoctor-kroki

I'm considering updating Antora to detect the misplaced registration and warn about it.

ggrossetie commented 1 year ago

I completely missed that 🙈 I was mislead by the error message. Thanks for your analysis Dan.

AndreVirtimo commented 1 year ago

Thank you. I missed that because I already had an antora extension in place, so I added this one.

Now it's working:

antora:
  extensions:
    - require: '@antora/lunr-extension'
asciidoc:
  extensions:
    - asciidoctor-kroki