Skip to content

Commit

Permalink
feat: upgrade jiti to fully esm for vite
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Sep 30, 2024
1 parent 1db600b commit 2508e45
Show file tree
Hide file tree
Showing 15 changed files with 1,372 additions and 1,065 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"typedoc": "^0.26.7",
"typedoc-plugin-markdown": "^4.2.7",
"typedoc-plugin-markdown": "^4.2.8",
"typedoc-vitepress-theme": "^1.0.1",
"vitepress": "^1.3.4"
}
Expand Down
2 changes: 1 addition & 1 deletion demo/custom/valaxy-theme-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"types": "types/index.d.ts",
"dependencies": {
"@iconify-json/ant-design": "^1.2.1",
"@iconify-json/simple-icons": "^1.2.3"
"@iconify-json/simple-icons": "^1.2.4"
}
}
2 changes: 1 addition & 1 deletion demo/yun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"valaxy": "workspace:*",
"valaxy-addon-algolia": "workspace:*",
"valaxy-addon-artalk": "^0.1.0",
"valaxy-addon-artalk": "^0.1.1",
"valaxy-addon-bangumi": "workspace:*",
"valaxy-addon-components": "workspace:*",
"valaxy-addon-lightgallery": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
},
"devDependencies": {
"@iconify-json/carbon": "^1.2.1",
"@iconify-json/simple-icons": "^1.2.3",
"@iconify-json/simple-icons": "^1.2.4",
"nodemon": "^3.1.7",
"vite": "^5.4.7",
"vite": "^5.4.8",
"vitepress": "1.1.4"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@
"@types/markdown-it-attrs": "^4.1.3",
"@types/markdown-it-container": "^2.0.10",
"@types/markdown-it-emoji": "^3.0.1",
"@types/node": "^22.5.5",
"@types/node": "^22.7.4",
"@types/prompts": "^2.4.9",
"@types/resolve": "^1.20.6",
"bumpp": "^9.5.2",
"bumpp": "^9.6.1",
"cross-env": "^7.0.3",
"decap-cms-app": "^3.3.3",
"eslint": "^9.11.0",
"eslint": "^9.11.1",
"https-localhost": "^4.7.1",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"release": "bumpp && npm publish"
},
"dependencies": {
"@rollup/pluginutils": "^5.1.0",
"@rollup/pluginutils": "^5.1.2",
"axios": "^1.7.7",
"body-parser": "^1.20.3",
"http-proxy-middleware": "^3.0.2",
Expand All @@ -46,6 +46,6 @@
"typescript": "^5.6.2",
"unbuild": "^2.0.0",
"unplugin-vue-router": "^0.10.8",
"vite": "^5.4.7"
"vite": "^5.4.8"
}
}
4 changes: 2 additions & 2 deletions packages/valaxy-addon-algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"valaxy": "latest"
},
"dependencies": {
"@docsearch/css": "^3.6.1",
"@docsearch/js": "^3.6.1"
"@docsearch/css": "^3.6.2",
"@docsearch/js": "^3.6.2"
}
}
4 changes: 2 additions & 2 deletions packages/valaxy-theme-press/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"main": "node/index.ts",
"types": "types/index.d.ts",
"dependencies": {
"@docsearch/css": "^3.6.1",
"@docsearch/js": "^3.6.1"
"@docsearch/css": "^3.6.2",
"@docsearch/js": "^3.6.2"
},
"devDependencies": {
"valaxy": "workspace:*"
Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy-theme-yun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@explosions/fireworks": "^0.0.2",
"@iconify-json/ant-design": "^1.2.1",
"@iconify-json/simple-icons": "^1.2.3",
"@iconify-json/simple-icons": "^1.2.4",
"animejs": "^3.2.2"
},
"devDependencies": {
Expand Down
15 changes: 8 additions & 7 deletions packages/valaxy/node/config/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import fs from 'fs-extra'

// https://github.com/unjs/c12
Expand All @@ -8,11 +7,17 @@ import fs from 'fs-extra'
// use jiti directly is 0.0006s 0.6ms
// write in valaxy directly can be fastest and solve cjs esm in vite

import jiti from 'jiti'
import { createJiti } from 'jiti'
import { resolve } from 'pathe'
import consola from 'consola'
import type { ResolvedValaxyOptions } from '../options'

const jiti = createJiti(import.meta.url, {
interopDefault: true,
// for hmr
moduleCache: false,
})

export interface LoadConfigFromFileOptions {
cwd?: string
valaxyOptions?: ResolvedValaxyOptions
Expand All @@ -37,11 +42,7 @@ export async function loadConfig<T extends UserInputConfig = UserInputConfig>(op

if (await fs.exists(filePath)) {
try {
data = jiti(fileURLToPath(import.meta.url), {
interopDefault: true,
requireCache: false,
esmResolve: true,
})(filePath)
data = (await jiti.import(filePath)) as T
}
catch (e) {
consola.error(`Failed to load config file: ${filePath}`)
Expand Down
9 changes: 4 additions & 5 deletions packages/valaxy/node/plugins/setupNode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// ref slidev
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import fs from 'fs-extra'
import { isObject } from '@antfu/utils'
import jiti from 'jiti'
import { createJiti } from 'jiti'

const jiti = createJiti(import.meta.url)

function deepMerge(a: any, b: any, rootPath = '') {
a = { ...a }
Expand All @@ -23,9 +24,7 @@ export async function loadSetups<T, R extends object>(roots: string[], name: str
for (const root of roots) {
const path = resolve(root, 'setup', name)
if (fs.existsSync(path)) {
const { default: setup } = jiti(fileURLToPath(import.meta.url), {
esmResolve: true,
})(path)
const { default: setup } = (await jiti.import(path)) as { default: (arg: T) => R }
const result = await setup(arg)
if (result !== null) {
returns = merge
Expand Down
20 changes: 8 additions & 12 deletions packages/valaxy/node/plugins/unocss.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { resolve } from 'node:path'
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import fs from 'fs-extra'
import type { VitePluginConfig as UnoCSSConfig, VitePluginConfig } from 'unocss/vite'
import jiti from 'jiti'
import { createJiti } from 'jiti'
import defu from 'defu'

import type {
Expand All @@ -19,6 +18,8 @@ import {
import type { ResolvedValaxyOptions } from '../options'
import { loadSetups } from './setupNode'

const jiti = createJiti(import.meta.url)

export async function createSafelist(options: ResolvedValaxyOptions) {
const { config } = options
const safeIcons: string[] = [
Expand Down Expand Up @@ -139,22 +140,17 @@ export async function createUnocssPlugin(options: ResolvedValaxyOptions) {

const configDeps: string[] = []

configFiles.forEach((configFile) => {
if (existsSync(configFile)) {
let uConfig: UnoCSSConfig | { default: UnoCSSConfig } = jiti(
fileURLToPath(import.meta.url),
{
esmResolve: true,
},
)(configFile) as UnoCSSConfig | { default: UnoCSSConfig }
for (const configFile of configFiles) {
if (await fs.exists(configFile)) {
let uConfig = (await jiti.import(configFile)) as UnoCSSConfig | { default: UnoCSSConfig }
if ('default' in uConfig)
uConfig = uConfig.default

config = defu(config, uConfig)

configDeps.push(configFile)
}
})
}

config = await loadSetups(roots, 'unocss.ts', {}, config, true)

Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy/node/utils/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function readAddonModule(name: string, options: ReadAddonModuleOpti
const root = getAddonRoot(name, options.cwd || process.cwd())

const packageJSONPath = resolve(root, './package.json')
if (!fs.existsSync(packageJSONPath)) {
if (!await fs.exists(packageJSONPath)) {
logger.error(`No addon named ${name} found`)
return
}
Expand Down
26 changes: 13 additions & 13 deletions packages/valaxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@
"@intlify/unplugin-vue-i18n": "4",
"@types/katex": "^0.16.7",
"@types/luxon": "^3.4.2",
"@unhead/addons": "^1.11.6",
"@unhead/schema-org": "^1.11.6",
"@unhead/vue": "^1.11.6",
"@unhead/addons": "^1.11.7",
"@unhead/schema-org": "^1.11.7",
"@unhead/vue": "^1.11.7",
"@valaxyjs/devtools": "workspace:*",
"@valaxyjs/utils": "workspace:*",
"@vitejs/plugin-vue": "^5.1.4",
"@vue/devtools-api": "^7.4.5",
"@vue/devtools-api": "^7.4.6",
"@vueuse/core": "^11.1.0",
"@vueuse/integrations": "^11.1.0",
"consola": "^3.2.3",
"critters": "^0.0.24",
"cross-spawn": "^7.0.3",
"css-i18n": "^0.0.5",
"date-fns": "^4.1.0",
"date-fns-tz": "^3.1.3",
"date-fns-tz": "^3.2.0",
"debug": "^4.3.7",
"defu": "^6.1.4",
"ejs": "^3.1.10",
Expand All @@ -97,7 +97,7 @@
"hookable": "^5.5.3",
"html-to-text": "^9.0.5",
"is-installed-globally": "^1.0.0",
"jiti": "^1.21.6",
"jiti": "^2.0.0",
"js-base64": "^3.7.7",
"js-yaml": "^4.1.0",
"katex": "^0.16.11",
Expand All @@ -121,21 +121,21 @@
"pathe": "^1.1.2",
"pinia": "^2.2.2",
"qrcode": "^1.5.4",
"sass": "^1.79.3",
"shiki": "^1.18.0",
"sass": "^1.79.4",
"shiki": "^1.21.0",
"star-markdown-css": "^0.5.2",
"unocss": "^0.62.4",
"unocss": "^0.63.1",
"unplugin-vue-components": "^0.27.4",
"unplugin-vue-markdown": "^0.26.2",
"unplugin-vue-router": "^0.10.8",
"vanilla-lazyload": "^19.1.3",
"vite": "^5.4.7",
"vite-plugin-vue-devtools": "^7.4.5",
"vite": "^5.4.8",
"vite-plugin-vue-devtools": "^7.4.6",
"vite-plugin-vue-layouts": "0.11.0",
"vite-ssg": "0.23.7",
"vite-ssg-sitemap": "0.6.1",
"vue": "^3.5.7",
"vue-i18n": "^10.0.1",
"vue": "^3.5.10",
"vue-i18n": "^10.0.3",
"vue-router": "^4.4.5",
"yargs": "^17.7.2"
},
Expand Down
Loading

0 comments on commit 2508e45

Please sign in to comment.