@bakery-framework/plugin-vue 2.2.0 → 2.2.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/plugin-vue",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Bakery vue plugin.",
5
5
  "keywords": [
6
6
  "bakery",
@@ -43,7 +43,7 @@
43
43
  "vue": "^3.5.38"
44
44
  },
45
45
  "dependencies": {
46
- "@bakery-framework/core": "^2.2.0"
46
+ "@bakery-framework/core": "^2.2.2"
47
47
  },
48
48
  "engines": {
49
49
  "bun": ">=1.4.0"
package/src/compile.ts CHANGED
@@ -138,15 +138,14 @@ export async function compileScriptBlock(
138
138
  }
139
139
  }
140
140
 
141
- if (descriptor.script && descriptor.scriptSetup) {
142
- const scriptLang = descriptor.script.lang || descriptor.script.attrs?.lang
143
- if (scriptLang === 'ts') {
144
- // If the script block is TypeScript, we need to compile it first before passing it to the Vue compiler
145
- const compiledScript = await compileText(descriptor.script.content)
146
- descriptor.script.content = compiledScript
147
- }
148
- }
149
-
141
+ // The blocks go to Vue as written, TypeScript included: `compileScript`
142
+ // reads TypeScript, and `compileText` below takes the types out of what it
143
+ // returns. A plain `<script lang="ts">` beside `<script setup>` used to be
144
+ // transpiled first and written back into `descriptor.script.content`, but
145
+ // Vue edits the whole file by the block's original offsets, so a rewritten
146
+ // block put its edits in the wrong places: an `export default` of options
147
+ // came out as `returnconst __default__ = MIT)` over the lines around it,
148
+ // and the module failed to parse.
150
149
  const { compileScript } = await loadCompiler()
151
150
  const result = compileScript(descriptor, {
152
151
  id,
package/src/handler.ts CHANGED
@@ -32,7 +32,7 @@ import {
32
32
  parseVue,
33
33
  vueBuildVariant,
34
34
  } from './compile'
35
- import { VUE_HTML_SHELL } from './shell'
35
+ import { declaresViewport, VIEWPORT_META, VUE_HTML_SHELL } from './shell'
36
36
  import type { ParsedCacheEntry, VueMeta } from './types'
37
37
  import {
38
38
  cacheDir,
@@ -351,11 +351,17 @@ export async function componentScript(options: {
351
351
  code = code.replace(RX_SERVER_DATA_TOKEN, () => serverData)
352
352
  }
353
353
 
354
+ // One element per component, holding every block, joined as `componentCss`
355
+ // joins them for a page. The element is per component so a module evaluated
356
+ // again replaces its styles rather than stacking a second copy; writing each
357
+ // block into it in turn, as this did, kept only the last block.
354
358
  if (!isRootScript) {
355
- for (const style of compiled.styles) {
356
- if (style.code) {
357
- code += `;\n(function(){var k='__vu_css_${id}';var s=document.getElementById(k)||(function(){var el=document.createElement('style');el.id=k;document.head.appendChild(el);return el})();s.textContent=${JSON.stringify(style.code)}})()`
358
- }
359
+ const css = compiled.styles
360
+ .map(style => style.code)
361
+ .filter(Boolean)
362
+ .join('\n\n')
363
+ if (css) {
364
+ code += `;\n(function(){var k='__vu_css_${id}';var s=document.getElementById(k)||(function(){var el=document.createElement('style');el.id=k;document.head.appendChild(el);return el})();s.textContent=${JSON.stringify(css)}})()`
359
365
  }
360
366
  }
361
367
 
@@ -703,6 +709,12 @@ export class VueHandler extends DynamicHandler {
703
709
  () => serverDecl + moduleDecl + routeDecl,
704
710
  )
705
711
 
712
+ // An app's own viewport, through `head`, would lose to the shell's: see
713
+ // `declaresViewport`.
714
+ if (declaresViewport(Bakery.config.head)) {
715
+ hydrated = hydrated.replace(VIEWPORT_META, '')
716
+ }
717
+
706
718
  // Static markup, injected verbatim. See parseSkeleton for why it is
707
719
  // never rendered. mount() replaces the container children, so it
708
720
  // disappears the moment the real component is up.
package/src/shell.ts CHANGED
@@ -1,9 +1,30 @@
1
+ /**
2
+ * The page's default viewport. Without one a phone lays the page out 980 px
3
+ * wide and no `max-width` media query applies (measured in Chrome under 390 px
4
+ * emulation: `innerWidth` 980, and 390 with this tag).
5
+ */
6
+ export const VIEWPORT_META =
7
+ '<meta name="viewport" content="width=device-width, initial-scale=1">'
8
+
9
+ /**
10
+ * Whether `head` markup declares a viewport of its own.
11
+ *
12
+ * The host's `head` is spliced in right after `<head>`, ahead of the shell's
13
+ * own tags, and of two viewport metas Chrome honors the later one (measured:
14
+ * `width=600` after `device-width` reads 600, before it 390). So the default
15
+ * above would override an app's own, and the handler drops it instead.
16
+ */
17
+ export function declaresViewport(head: string | undefined): boolean {
18
+ return !!head && /<meta\b[^>]*\sname\s*=\s*["']?viewport\b/i.test(head)
19
+ }
20
+
1
21
  export const VUE_HTML_SHELL = `
2
22
  <!DOCTYPE html>
3
23
  <html lang="en">
4
24
 
5
25
  <head>
6
26
  <meta charset="UTF-8">
27
+ ${VIEWPORT_META}
7
28
  <title>Vue App</title>
8
29
  /*__SERVER_VARIABLES__*/
9
30
  </head>