Skip to content

[IMP] owl: expose the template compiler - #2076

Open
ged-odoo wants to merge 1 commit into
masterfrom
master-expose-compiler-ged
Open

ged-odoo wants to merge 1 commit into
masterfrom
master-expose-compiler-ged

Conversation

@ged-odoo

Copy link
Copy Markdown
Contributor

Before this PR, the template compiler cannot be used outside the owl repository: @odoo/owl does not export compile, the compile_owl_templates command of Owl 2 is gone (its script stayed in tools/, unpublished), and owl-compiler is not published. So templates cannot be precompiled.

This PR:

  • exports compile from @odoo/owl (for browsers);
  • brings back the compile_owl_templates command (bin of @odoo/owl), with the standalone compiler shipped as dist/compile_templates.mjs, copied from owl-compiler by the build;
  • exports compile from dist/compile_templates.mjs too, for node: that bundle sets up jsdom itself, and only contains the compiler;
  • makes jsdom an optional peer dependency (Owl 2 made it a dependency of every install). Without it, the command says to install it;
  • updates the "Precompiling templates" page.

Usage:

npm install @odoo/owl
npm install --save-dev jsdom
npx compile_owl_templates path/to/templates -o templates.js
import { compile } from "@odoo/owl"; // browser
import { compile } from "@odoo/owl/dist/compile_templates.mjs"; // node

Notes:

  • Why not compile from @odoo/owl in node: setting up a partial DOM (as the standalone bundle does) is not enough there, as the runtime part of the bundle then expects a full one (DOMTokenList, ...).
  • Checked with the packed tarball installed in an empty project: without jsdom the command exits with the install hint; with jsdom it compiles templates, and compile imports from dist/compile_templates.mjs in node. The repo's npm run compile_templates (used by the devtools build) still works.
  • A smoke test checks that compile is exported and that its result can be used as a template. All tests, type tests, lint and the formatting check pass.
  • No new npm package: @odoo/owl-compiler and @odoo/owl-core stay unpublished. Publishing owl-core on its own would make its whole export list, including the reactivity internals, a public API.

Before this commit, the template compiler cannot be used outside the owl
repository: @odoo/owl does not export `compile`, the compile_owl_templates
command of Owl 2 is gone (its script stayed in tools/, unpublished), and
owl-compiler is not published. So templates cannot be precompiled.

This commit exports `compile` from @odoo/owl, and brings back the
compile_owl_templates command with the standalone compiler
(dist/compile_templates.mjs, which also exports `compile` for node).
jsdom, which they need in node, is an optional peer dependency.

This branch has not been deployed

No deployments
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