Skip to content

Commit d615bcd

Browse files
authored
build: use JSON import attributes instead of readFIleSync in rolldown configs (#23251)
1 parent 74a25c3 commit d615bcd

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

‎packages/vite/rolldown.config.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import { readFileSync, writeFileSync } from 'node:fs'
1+
import { writeFileSync } from 'node:fs'
22
import path from 'node:path'
33
import MagicString from 'magic-string'
44
import type { Plugin } from 'rolldown'
55
import { defineConfig } from 'rolldown'
66
import { ImportType, init, parse } from 'es-module-lexer'
77
import licensePlugin from './rollupLicensePlugin'
8+
import pkg from './package.json' with { type: 'json' }
89

910
// eslint-disable-next-line n/no-unsupported-features/node-builtins
1011
const dirname = import.meta.dirname
11-
const pkg = JSON.parse(
12-
readFileSync(new URL('./package.json', import.meta.url)).toString(),
13-
)
12+
1413
const disableSourceMap = !!process.env.DEBUG_DISABLE_SOURCE_MAP
1514

1615
const envConfig = defineConfig({

‎packages/vite/rolldown.dts.config.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { readFileSync } from 'node:fs'
21
import { builtinModules } from 'node:module'
32
import { defineConfig } from 'rolldown'
43
import type {
@@ -13,16 +12,13 @@ import { dts } from 'rolldown-plugin-dts'
1312
import { parse as parseWithBabel } from '@babel/parser'
1413
import { walk } from 'estree-walker'
1514
import MagicString from 'magic-string'
15+
import pkg from './package.json' with { type: 'json' }
1616

1717
type Directive = ESTree.Directive
1818
type ModuleExportName = ESTree.ModuleExportName
1919
type Program = ESTree.Program
2020
type Statement = ESTree.Statement
2121

22-
const pkg = JSON.parse(
23-
readFileSync(new URL('./package.json', import.meta.url)).toString(),
24-
)
25-
2622
const external = [
2723
/^node:*/,
2824
/^vite\//,

0 commit comments

Comments
 (0)