8000 refactor: renderer and root component injections · romhml/compodium@5deb0e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5deb0e4

Browse files
committed
refactor: renderer and root component injections
1 parent 7546ee1 commit 5deb0e4

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎packages/core/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@vueuse/core": "^13.1.0",
4848
"chokidar": "^4.0.3",
4949
"hookable": "^5.5.3",
50+
"mlly": "^1.7.4",
5051
"pathe": "^2.0.3",
5152
"scule": "^1.3.0",
5253
"sirv": "^3.0.1",

‎packages/core/src/plugins/devtools.ts‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import sirv from 'sirv'
33
import type { PluginConfig } from '../types'
44
import { resolve, dirname } from 'pathe'
55
import { fileURLToPath } from 'node:url'
6-
import { existsSync, readFileSync } from 'node:fs'
6+
import { existsSync } from 'node:fs'
77
import { joinURL } from 'ufo'
8+
import { resolvePathSync } from 'mlly'
89

910
export function devtoolsPlugin(config: PluginConfig): VitePlugin {
1011
const userPreview = resolve(joinURL(config.rootDir, config.dir, 'preview.vue'))
@@ -39,16 +40,7 @@ export function devtoolsPlugin(config: PluginConfig): VitePlugin {
3940
if (existsSync(userPreview)) {
4041
return userPreview
4142
}
42-
return '\0virtual:compodium:preview'
43-
}
44-
},
45-
46-
load(id) {
47-
if (id === '\0virtual:compodium:preview') {
48-
if (existsSync(userPreview)) {
49-
return readFileSync(userPreview, 'utf-8')
50-
}
51-
return `export { default } from '@compodium/core/runtime/preview.vue'`
43+
return resolvePathSync('../runtime/preview.vue', { extensions: ['.vue'], url: import.meta.url })
5244
}
5345
}
5446
}

‎packages/vue/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@vue/devtools-kit": "^7.7.6",
4040
"consola": "^3.4.2",
4141
"defu": "^6.1.4",
42+
"mlly": "^1.7.4",
4243
"pathe": "^2.0.3",
4344
"unplugin": "^2.3.4"
4445
}

‎packages/vue/src/plugins/renderer.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { VitePlugin } from 'unplugin'
22
import type { PluginOptions } from '@compodium/core'
33
import { readFileSync, existsSync } from 'node:fs'
44
import { dirname, resolve } from 'node:path'
5+
import { resolvePathSync } from 'mlly'
56

67
export function rendererPlugin(options: PluginOptions): VitePlugin {
78
return {
@@ -49,12 +50,12 @@ export function rendererPlugin(options: PluginOptions): VitePlugin {
4950
).replace(
5051
/\.mount\([^)]*\)/,
5152
'.mount("#compodium")'
52-
).replace(/(from|import)\s+(['"])([./])/g, (match, keyword, quote, path) => {
53-
// Resolve the relative import based on the main directory
53+
).replace(/(from|import)\s+(['"])([./])/g, (_match, keyword, quote, path) => {
54+
// Resolve the relative import based on the main directory
5455
return `${keyword} ${quote}${resolve(mainDir, path)}/`
5556
})
5657

57-
return `import CompodiumRoot from '${import.meta.resolve('@compodium/core/runtime/root.vue')}';\n${mainContent}`
58+
return `import CompodiumRoot from '${resolvePathSync('./runtime/root.vue', { extensions: ['.vue'], url: import.meta.resolve('@compodium/core') })}';\n${mainContent}`
5859
}
5960
}
6061
}

‎pnpm-lock.yaml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0