metaowl 0.2.13 → 0.2.14

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.
@@ -11,10 +11,19 @@ import { loadFile } from '@odoo/owl'
11
11
  * Returns null if not available (dev mode without inline plugin or legacy setup).
12
12
  */
13
13
  async function getInlinedTemplates() {
14
+ // Skip in test environment (Vitest doesn't have the same import.meta behavior)
15
+ // Also skip if we're not in a browser environment
16
+ if (typeof window === 'undefined' && typeof globalThis.importMeta === 'undefined') {
17
+ return null
18
+ }
19
+
14
20
  try {
15
21
  // In production (build), templates are inlined via Vite plugin
16
- const { TEMPLATES } = await import('/src/templates.js')
17
- return TEMPLATES
22
+ // Use dynamic import with a path that Vite can resolve at runtime
23
+ // The templates.js is generated in the output directory
24
+ // Using eval to prevent Vite's static analysis from failing
25
+ const templatesModule = await new Function('return import("/templates.js")')()
26
+ return templatesModule.TEMPLATES
18
27
  } catch (e) {
19
28
  // In development or legacy setup, templates are loaded at runtime
20
29
  return null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metaowl",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Lightweight meta-framework for Odoo OWL — file-based routing, app mounting, Fetch helper, Cache, Meta tags, SSG generator, and a Vite plugin.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/vite/plugin.js CHANGED
@@ -220,10 +220,11 @@ export async function metaowlPlugin(options = {}) {
220
220
  const projectRoot = process.cwd()
221
221
 
222
222
  // Collect and inline all XML templates into a single JS file
223
+ // Use already collected XML arrays to avoid duplicate glob operations
223
224
  const xmlFiles = [
224
- ...globSync(`${root}/${layoutsDir}/**/*.xml`),
225
- ...globSync(`${root}/${pagesDir}/**/*.xml`),
226
- ...globSync(`${root}/${componentsDir}/**/*.xml`)
225
+ ...layoutXml,
226
+ ...pageXml,
227
+ ...componentXml
227
228
  ]
228
229
 
229
230
  let templates = '<templates>'
@@ -236,20 +237,22 @@ export async function metaowlPlugin(options = {}) {
236
237
  }
237
238
  templates += '</templates>'
238
239
 
239
- // Escape for JavaScript string
240
- const escaped = templates
241
- .replace(/\\/g, '\\\\')
242
- .replace(/'/g, "\\'")
243
- .replace(/\n/g, '\\n')
244
- .replace(/\r/g, '')
240
+ // Escape for JavaScript string using JSON encoding for safety
241
+ const escaped = JSON.stringify(templates).slice(1, -1)
245
242
 
246
- // Write templates.js
243
+ // Write templates.js to the output root (accessible as /templates.js)
247
244
  const templatesJs = `export const TEMPLATES = '${escaped}';\n`
248
- const templatesDir = resolve(_outDirResolved, root)
245
+ const templatesDir = _outDirResolved
249
246
  mkdirSync(templatesDir, { recursive: true })
250
247
  writeFileSync(resolve(templatesDir, 'templates.js'), templatesJs)
251
248
 
252
249
  console.log(`[metaowl] Inlined ${xmlFiles.length} XML templates into templates.js`)
250
+
251
+ // Restore: Copy assets/images (referenced via absolute URLs in XML)
252
+ const srcImages = resolve(projectRoot, root, 'assets', 'images')
253
+ if (existsSync(srcImages)) {
254
+ cpSync(srcImages, resolve(_outDirResolved, 'assets', 'images'), { recursive: true })
255
+ }
253
256
  }
254
257
  }
255
258
  ]