Skip to content

Migrate code to ESM modules#683

Merged
ggrossetie merged 13 commits into
asciidoctor:mainfrom
ggrossetie:esm-code
Apr 29, 2026
Merged

Migrate code to ESM modules#683
ggrossetie merged 13 commits into
asciidoctor:mainfrom
ggrossetie:esm-code

Conversation

@ggrossetie

Copy link
Copy Markdown
Member

Replace global-based scripts with ES modules: split the codebase into
focused modules (constants, converter, dom, fetch, page, settings, theme),
add a dynamic-import bootstrap content script, and update vendor files
and manifest accordingly.

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

ggrossetie and others added 2 commits April 29, 2026 09:06
Replace global-based scripts with ES modules: split the codebase into
focused modules (constants, converter, dom, fetch, page, settings, theme),
add a dynamic-import bootstrap content script, and update vendor files
and manifest accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add an HTTP server (tasks/server.js) for ESM imports to work over http://
instead of file://. Load modules dynamically in beforeEach via
page.evaluate() and expose them as window globals. Update test-page.html
to load vendor scripts as classic scripts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ggrossetie ggrossetie force-pushed the esm-code branch 2 times, most recently from f67a8b0 to 914cf0b Compare April 29, 2026 07:06
ggrossetie and others added 11 commits April 29, 2026 09:09
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace dynamic import() with static ESM import in contentScript.js
  (dynamic import never resolved in Firefox due to transitive imports)
- Remove Firefox-specific local fetch+convert code from main.js;
  both browsers now send fetch-convert to the background script
- Fix isExtensionEnabled() to return true by default on fresh install

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add esbuild to bundle contentScript.js into an IIFE (content-bundle.js)
  so it loads as a classic script without requiring "type: module",
  which would break vendor scripts in the same content_scripts entry
- Both Chrome and Firefox now use content-bundle.js
- Add scripting permission for scripting.insertCSS API
- Add downloadFonts() build step: downloads Google Fonts woff2 files
  locally and generates app/css/asciidoctor-fonts.css
- Add fonts/asciidoctor/* to web_accessible_resources

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace <link> element injection with sendMessage({ action: 'insert-css' })
  calls to the background; scripting.insertCSS() is not subject to page CSP
- Background resolves @import rules by fetching and inlining them,
  and rewrites all relative url() references to absolute extension URLs
  before injecting, fixing broken font paths on sandboxed pages
- Fix Firefox Promise rejection when no content script listener exists
- Fix enable/disable state inversion in background script

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the Google Fonts @import in asciidoctor.css with a reference to
a locally generated asciidoctor-fonts.css containing @font-face rules
pointing to bundled woff2 files. Fonts load entirely from the extension,
with no external network requests, and work even on pages with strict CSP.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…igin

scripting.insertCSS with css: gives the stylesheet a null principal in
Firefox, which blocks loading moz-extension:// font URLs even when listed
in web_accessible_resources.

Using files: mode gives the stylesheet the extension's own origin, which
allows @font-face rules to load font files directly from moz-extension://.
Chrome keeps the inline css: approach (rewritten absolute URLs) because its
files: mode incorrectly resolves url() relative to the page, not the file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ggrossetie ggrossetie merged commit 38ee00c into asciidoctor:main Apr 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant