Skip to content

Commit a5a75bd

Browse files
authored
refactor: use JSON import attributes instead of createRequire in config (#5380)
1 parent 4ffcdae commit a5a75bd

10 files changed

Lines changed: 19 additions & 45 deletions

File tree

docs/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { createRequire } from 'node:module'
21
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
3-
4-
const require = createRequire(import.meta.url)
5-
const pkg = require('vitepress/package.json')
2+
import { version } from 'vitepress/package.json' with { type: 'json' }
63

74
export default defineAdditionalConfig({
85
description: 'Vite & Vue powered static site generator.',
@@ -40,7 +37,7 @@ function nav(): DefaultTheme.NavItem[] {
4037
activeMatch: '/reference/'
4138
},
4239
{
43-
text: pkg.version,
40+
text: version,
4441
items: [
4542
{
4643
text: '1.6.4',

docs/es/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -92,7 +89,7 @@ function nav(): DefaultTheme.NavItem[] {
9289
activeMatch: '/es/reference/'
9390
},
9491
{
95-
text: pkg.version,
92+
text: version,
9693
items: [
9794
{
9895
text: '1.6.4',

docs/fa/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -100,7 +97,7 @@ function nav(): DefaultTheme.NavItem[] {
10097
activeMatch: '/reference/'
10198
},
10299
{
103-
text: pkg.version,
100+
text: version,
104101
items: [
105102
{
106103
text: '1.6.4',

docs/ja/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -63,7 +60,7 @@ function nav(): DefaultTheme.NavItem[] {
6360
activeMatch: '/reference/'
6461
},
6562
{
66-
text: pkg.version,
63+
text: version,
6764
items: [
6865
{
6966
text: '1.6.4',

docs/ko/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -92,7 +89,7 @@ function nav(): DefaultTheme.NavItem[] {
9289
activeMatch: '/ko/reference/'
9390
},
9491
{
95-
text: pkg.version,
92+
text: version,
9693
items: [
9794
{
9895
text: '1.6.4',

docs/pt/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -92,7 +89,7 @@ function nav(): DefaultTheme.NavItem[] {
9289
activeMatch: '/pt/reference/'
9390
},
9491
{
95-
text: pkg.version,
92+
text: version,
9693
items: [
9794
{
9895
text: '1.6.4',

docs/ru/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -90,7 +87,7 @@ function nav(): DefaultTheme.NavItem[] {
9087
activeMatch: '/ru/reference/'
9188
},
9289
{
93-
text: pkg.version,
90+
text: version,
9491
items: [
9592
{
9693
text: '1.6.4',

docs/zh/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { createRequire } from 'node:module'
21
import {
32
defineAdditionalConfig,
43
type DefaultTheme,
54
type MarkdownLocaleOptions
65
} from 'vitepress'
7-
8-
const require = createRequire(import.meta.url)
9-
const pkg = require('vitepress/package.json')
6+
import { version } from 'vitepress/package.json' with { type: 'json' }
107

118
export const markdown: MarkdownLocaleOptions = {
129
container: {
@@ -92,7 +89,7 @@ function nav(): DefaultTheme.NavItem[] {
9289
activeMatch: '/zh/reference/'
9390
},
9491
{
95-
text: pkg.version,
92+
text: version,
9693
items: [
9794
{
9895
text: '1.6.4',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"build": "pnpm build:prepare && pnpm build:client && pnpm build:node && node scripts/genWebTypes.ts",
6363
"build:prepare": "pnpm clean && node scripts/copyShared.ts",
6464
"build:client": "vue-tsc --noEmit -p src/client && tsc -p src/client && node scripts/copyClient.ts",
65-
"build:node": "tsc -p src/node --noEmit && rollup --config rollup.config.ts --configPlugin esbuild",
65+
"build:node": "tsc -p src/node --noEmit && rollup --config rollup.config.ts",
6666
"test": "pnpm --aggregate-output --reporter=append-only '/^test:(types|unit|e2e|init)$/'",
6767
"test:types": "tsc -p __tests__/unit && tsc -p __tests__/e2e && tsc -p __tests__/init && vue-tsc -p docs",
6868
"test:unit": "vitest run -r __tests__/unit",

rollup.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import json from '@rollup/plugin-json'
44
import { nodeResolve } from '@rollup/plugin-node-resolve'
55
import replace from '@rollup/plugin-replace'
66
import { rm } from 'node:fs/promises'
7-
import { builtinModules, createRequire } from 'node:module'
7+
import { builtinModules } from 'node:module'
88
import { fileURLToPath } from 'node:url'
99
import { type RollupOptions, defineConfig } from 'rollup'
1010
import dts from 'rollup-plugin-dts'
1111
import esbuild from 'rollup-plugin-esbuild'
12-
13-
const require = createRequire(import.meta.url)
14-
const pkg = require('./package.json')
12+
import pkg from './package.json' with { type: 'json' }
1513

1614
const DEV = !!process.env.DEV
1715
const PROD = !DEV

0 commit comments

Comments
 (0)