kawapress 0.4.0 → 0.4.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,7 +1,7 @@
1
1
  {
2
2
  "name": "kawapress",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "description": "A Vue-centric static site generator",
6
6
  "license": "MIT",
7
7
  "homepage": "https://kawapress.dev/",
@@ -84,6 +84,6 @@
84
84
  "tinyglobby": "^0.2.17",
85
85
  "vite": "^8.2.2",
86
86
  "vue": "^3.5.41",
87
- "@kawapress/preset-nagi": "^0.4.0"
87
+ "@kawapress/preset-nagi": "^0.4.2"
88
88
  }
89
89
  }
@@ -81,6 +81,11 @@ export function createBaseViteConfig(
81
81
  // `index.html` to scan, so every dependency would be discovered after the
82
82
  // first page request and force a full reload. See useRuntimeDependencies().
83
83
  optimizeDeps: {
84
+ // The browser entry reaches KawaPress through relative imports. A
85
+ // pre-bundled copy of `kawapress/client` would bring a second router and
86
+ // site injection key, and every component importing it from a site or a
87
+ // plugin would fail to find the app.
88
+ exclude: [KAWAPRESS_PACKAGE_NAME],
84
89
  include: [
85
90
  VUE_DEPENDENCY,
86
91
  ...runtimeDependencySpecifiers(
@@ -2,3 +2,11 @@ import { fileURLToPath } from 'node:url'
2
2
 
3
3
  export const entryServerPath = fileURLToPath(new URL('../../client/entries/entry-server.ts', import.meta.url))
4
4
  export const entryClientPath = fileURLToPath(new URL('../../client/entries/entry-client.ts', import.meta.url))
5
+
6
+ /**
7
+ * Output directory and file name of the built server entry. The `.mjs`
8
+ * extension keeps it an ES module whatever the `type` of the site's
9
+ * `package.json` is.
10
+ */
11
+ export const SERVER_OUT_DIR = 'dist/.server'
12
+ export const SERVER_ENTRY_FILE = 'entry-server.mjs'
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from 'vite'
2
- import { readFile } from 'node:fs/promises'
2
+ import { readFile, realpath } from 'node:fs/promises'
3
3
  import { findPackageJSON } from 'node:module'
4
4
  import { dirname, join } from 'node:path'
5
5
  import process from 'node:process'
@@ -83,7 +83,7 @@ async function resolvePluginPackages(
83
83
  const searchRoots = [root]
84
84
  const corePackagePath = findPluginPackage('kawapress', searchRoots)
85
85
  if (corePackagePath) {
86
- searchRoots.push(dirname(corePackagePath))
86
+ searchRoots.push(await packageDirectory(corePackagePath))
87
87
  }
88
88
  let foundPackage = true
89
89
 
@@ -104,7 +104,7 @@ async function resolvePluginPackages(
104
104
  packagePath,
105
105
  exports: packageJson.exports,
106
106
  })
107
- searchRoots.push(dirname(packagePath))
107
+ searchRoots.push(await packageDirectory(packagePath))
108
108
  unresolved.delete(pluginName)
109
109
  foundPackage = true
110
110
  }
@@ -113,6 +113,15 @@ async function resolvePluginPackages(
113
113
  return packages
114
114
  }
115
115
 
116
+ /**
117
+ * Directory a package really lives in. pnpm links a dependency into the site's
118
+ * `node_modules`, and only the real directory has the package's own
119
+ * dependencies next to it, such as the preset a plugin package belongs to.
120
+ */
121
+ async function packageDirectory(packagePath: string): Promise<string> {
122
+ return dirname(await realpath(packagePath))
123
+ }
124
+
116
125
  function findPluginPackage(
117
126
  pluginName: string,
118
127
  searchRoots: string[],
@@ -9,7 +9,7 @@ import {
9
9
  createBaseViteConfig,
10
10
  createSitePageLoader,
11
11
  } from '../generator/vite/config'
12
- import { entryClientPath, entryServerPath } from '../generator/vite/entries'
12
+ import { entryClientPath, entryServerPath, SERVER_ENTRY_FILE, SERVER_OUT_DIR } from '../generator/vite/entries'
13
13
  import { createPageInputs } from '../generator/vite/page-inputs'
14
14
  import {
15
15
  createBuildArtifactEmitter,
@@ -68,8 +68,11 @@ export async function buildSite(root: string) {
68
68
  ssr: {
69
69
  consumer: 'server',
70
70
  build: {
71
- outDir: 'dist/.server',
72
- rollupOptions: { input: entryServerPath },
71
+ outDir: SERVER_OUT_DIR,
72
+ rolldownOptions: {
73
+ input: entryServerPath,
74
+ output: { entryFileNames: SERVER_ENTRY_FILE },
75
+ },
73
76
  },
74
77
  },
75
78
  },
@@ -13,6 +13,7 @@ import { NOT_FOUND_ROUTE_PATH } from '../core/not-found'
13
13
  import { findUnconsumedOutletItems, formatUnconsumedOutletWarnings } from '../core/outlet'
14
14
  import { pageChunkFileName, pageChunkHash } from '../core/page-chunk'
15
15
  import { pageTableFileName } from '../core/page-manifest'
16
+ import { SERVER_ENTRY_FILE, SERVER_OUT_DIR } from '../generator/vite/entries'
16
17
  import { collectPageAssets, collectPageChunk } from './page-assets'
17
18
  import { renderHtmlTemplate } from './template'
18
19
 
@@ -34,7 +35,8 @@ interface ServerBundle {
34
35
 
35
36
  export async function prerenderPages(root: string): Promise<void> {
36
37
  const distDir = join(root, 'dist')
37
- const serverEntry = join(distDir, '.server/entry-server.js')
38
+ const serverDir = join(root, SERVER_OUT_DIR)
39
+ const serverEntry = join(serverDir, SERVER_ENTRY_FILE)
38
40
  const { render, getOutletRegistry, pages, pageModules, site } = await import(
39
41
  pathToFileURL(serverEntry).href,
40
42
  ) as ServerBundle
@@ -83,7 +85,7 @@ export async function prerenderPages(root: string): Promise<void> {
83
85
  reportUnconsumedOutlets(getOutletRegistry(), renderedOutlets)
84
86
  consola.success(`KawaPress: prerendered ${paths.length} pages`)
85
87
 
86
- await rm(join(distDir, '.server'), { recursive: true })
88
+ await rm(serverDir, { recursive: true })
87
89
  await rm(join(distDir, '.vite'), { recursive: true })
88
90
  }
89
91