Skip to content

Commit 3a27f62

Browse files
brc-ddbluwysapphi-red
authored
chore(deps)!: update postcss-load-config to v6 (#15235)
Co-authored-by: bluwy <[email protected]> Co-authored-by: sapphi-red <[email protected]>
1 parent 0c497d9 commit 3a27f62

File tree

10 files changed

+145
-179
lines changed

10 files changed

+145
-179
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
hoist-pattern[]=ts-node # package/vite: postcss-load-config
21
hoist-pattern[]=postcss # package/vite
32
hoist-pattern[]=pug # playground/tailwind: @vue/compiler-sfc
43
shell-emulator=true

docs/guide/migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ From Vite 6, even when `json.stringify: true` is set, `json.namedExports` is not
2020

2121
Vite 6 also introduces a new default value for `json.stringify` which is `'auto'`, which will only stringify large JSON files. To disable this behavior, set `json.stringify: false`.
2222

23+
### postcss-load-config
24+
25+
[`postcss-load-config`](https://npmjs.com/package/postcss-load-config) has been updated to v6 from v4. [`tsx`](https://www.npmjs.com/package/tsx) or [`jiti`](https://www.npmjs.com/package/jiti) is now required to load TypeScript postcss config files instead of [`ts-node`](https://www.npmjs.com/package/ts-node). Also [`yaml`](https://www.npmjs.com/package/yaml) is now required to load YAML postcss config files.
26+
2327
### Sass now uses modern API by default
2428

2529
In Vite 5, the legacy API was used by default for Sass. Vite 5.4 added support for the modern API.

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export default tseslint.config(
203203
'playground/**/*dep*/**',
204204
'playground/resolve/browser-module-field2/index.web.js',
205205
'playground/resolve/browser-field/**',
206-
'playground/tailwind/**', // blocked by https://github.com/postcss/postcss-load-config/issues/239
207206
],
208207
rules: {
209208
'import-x/no-commonjs': 'error',

packages/vite/LICENSE.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,24 +2518,3 @@ Repository: git+https://github.com/websockets/ws.git
25182518
> COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25192519
> IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25202520
> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2521-
2522-
---------------------------------------
2523-
2524-
## yaml
2525-
License: ISC
2526-
By: Eemeli Aro
2527-
Repository: github:eemeli/yaml
2528-
2529-
> Copyright Eemeli Aro <[email protected]>
2530-
>
2531-
> Permission to use, copy, modify, and/or distribute this software for any purpose
2532-
> with or without fee is hereby granted, provided that the above copyright notice
2533-
> and this permission notice appear in all copies.
2534-
>
2535-
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2536-
> REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
2537-
> FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2538-
> INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
2539-
> OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2540-
> TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
2541-
> THIS SOFTWARE.

packages/vite/package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"picocolors": "^1.1.1",
137137
"picomatch": "^4.0.2",
138138
"postcss-import": "^16.1.0",
139-
"postcss-load-config": "^4.0.2",
139+
"postcss-load-config": "^6.0.1",
140140
"postcss-modules": "^6.0.0",
141141
"resolve.exports": "^2.0.2",
142142
"rollup-plugin-dts": "^6.1.1",
@@ -157,18 +157,24 @@
157157
},
158158
"peerDependencies": {
159159
"@types/node": "^18.0.0 || >=20.0.0",
160+
"jiti": ">=1.21.0",
160161
"less": "*",
161162
"lightningcss": "^1.21.0",
162163
"sass": "*",
163164
"sass-embedded": "*",
164165
"stylus": "*",
165166
"sugarss": "*",
166-
"terser": "^5.16.0"
167+
"terser": "^5.16.0",
168+
"tsx": "^4.8.1",
169+
"yaml": "^2.4.2"
167170
},
168171
"peerDependenciesMeta": {
169172
"@types/node": {
170173
"optional": true
171174
},
175+
"jiti": {
176+
"optional": true
177+
},
172178
"sass": {
173179
"optional": true
174180
},
@@ -189,6 +195,12 @@
189195
},
190196
"terser": {
191197
"optional": true
198+
},
199+
"tsx": {
200+
"optional": true
201+
},
202+
"yaml": {
203+
"optional": true
192204
}
193205
}
194206
}

packages/vite/rollup.config.ts

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const nodeConfig = defineConfig({
9999
'fsevents',
100100
'lightningcss',
101101
'rollup/parseAst',
102+
// postcss-load-config
103+
'yaml',
104+
'jiti',
105+
/^tsx(\/|$)/,
102106
...Object.keys(pkg.dependencies),
103107
],
104108
plugins: [
@@ -107,35 +111,50 @@ const nodeConfig = defineConfig({
107111
// Shim them with eval() so rollup can skip these calls.
108112
shimDepsPlugin({
109113
// chokidar -> fsevents
110-
'fsevents-handler.js': {
111-
src: `require('fsevents')`,
112-
replacement: `__require('fsevents')`,
113-
},
114+
'fsevents-handler.js': [
115+
{
116+
src: `require('fsevents')`,
117+
replacement: `__require('fsevents')`,
118+
},
119+
],
114120
// postcss-import -> sugarss
115-
'process-content.js': {
116-
src: 'require("sugarss")',
117-
replacement: `__require('sugarss')`,
118-
},
119-
'lilconfig/src/index.js': {
120-
pattern: /: require;/g,
121-
replacement: `: __require;`,
122-
},
123-
// postcss-load-config calls require after register ts-node
124-
'postcss-load-config/src/index.js': {
125-
pattern: /require(?=\((configFile|'ts-node')\))/g,
126-
replacement: `__require`,
127-
},
121+
'process-content.js': [
122+
{
123+
src: 'require("sugarss")',
124+
replacement: `__require('sugarss')`,
125+
},
126+
],
127+
'lilconfig/src/index.js': [
128+
{
129+
pattern: /: require;/g,
130+
replacement: ': __require;',
131+
},
132+
],
133+
'postcss-load-config/src/req.js': [
134+
{
135+
src: "const { pathToFileURL } = require('node:url')",
136+
replacement: `const { fileURLToPath, pathToFileURL } = require('node:url')`,
137+
},
138+
{
139+
src: '__filename',
140+
replacement: 'fileURLToPath(import.meta.url)',
141+
},
142+
],
128143
// postcss-import uses the `resolve` dep if the `resolve` option is not passed.
129144
// However, we always pass the `resolve` option. Remove this import to avoid
130145
// bundling the `resolve` dep.
131-
'postcss-import/index.js': {
132-
src: 'const resolveId = require("./lib/resolve-id")',
133-
replacement: 'const resolveId = (id) => id',
134-
},
135-
'postcss-import/lib/parse-styles.js': {
136-
src: 'const resolveId = require("./resolve-id")',
137-
replacement: 'const resolveId = (id) => id',
138-
},
146+
'postcss-import/index.js': [
147+
{
148+
src: 'const resolveId = require("./lib/resolve-id")',
149+
replacement: 'const resolveId = (id) => id',
150+
},
151+
],
152+
'postcss-import/lib/parse-styles.js': [
153+
{
154+
src: 'const resolveId = require("./resolve-id")',
155+
replacement: 'const resolveId = (id) => id',
156+
},
157+
],
139158
}),
140159
...createSharedNodePlugins({}),
141160
licensePlugin(
@@ -199,46 +218,53 @@ interface ShimOptions {
199218
pattern?: RegExp
200219
}
201220

202-
function shimDepsPlugin(deps: Record<string, ShimOptions>): Plugin {
221+
function shimDepsPlugin(deps: Record<string, ShimOptions[]>): Plugin {
203222
const transformed: Record<string, boolean> = {}
204223

205224
return {
206225
name: 'shim-deps',
207226
transform(code, id) {
208227
for (const file in deps) {
209228
if (id.replace(/\\/g, '/').endsWith(file)) {
210-
const { src, replacement, pattern } = deps[file]
229+
for (const { src, replacement, pattern } of deps[file]) {
230+
const magicString = new MagicString(code)
211231

212-
const magicString = new MagicString(code)
213-
if (src) {
214-
const pos = code.indexOf(src)
215-
if (pos < 0) {
216-
this.error(
217-
`Could not find expected src "${src}" in file "${file}"`,
218-
)
219-
}
220-
transformed[file] = true
221-
magicString.overwrite(pos, pos + src.length, replacement)
222-
console.log(`shimmed: ${file}`)
223-
}
224-
225-
if (pattern) {
226-
let match
227-
while ((match = pattern.exec(code))) {
232+
if (src) {
233+
const pos = code.indexOf(src)
234+
if (pos < 0) {
235+
this.error(
236+
`Could not find expected src "${src}" in file "${file}"`,
237+
)
238+
}
228239
transformed[file] = true
229-
const start = match.index
230-
const end = start + match[0].length
231-
magicString.overwrite(start, end, replacement)
240+
magicString.overwrite(pos, pos + src.length, replacement)
232241
}
233-
if (!transformed[file]) {
234-
this.error(
235-
`Could not find expected pattern "${pattern}" in file "${file}"`,
236-
)
242+
243+
if (pattern) {
244+
let match
245+
while ((match = pattern.exec(code))) {
246+
transformed[file] = true
247+
const start = match.index
248+
const end = start + match[0].length
249+
let _replacement = replacement
250+
for (let i = 1; i <= match.length; i++) {
251+
_replacement = _replacement.replace(`$${i}`, match[i] || '')
252+
}
253+
magicString.overwrite(start, end, _replacement)
254+
}
255+
if (!transformed[file]) {
256+
this.error(
257+
`Could not find expected pattern "${pattern}" in file "${file}"`,
258+
)
259+
}
237260
}
238-
console.log(`shimmed: ${file}`)
261+
262+
code = magicString.toString()
239263
}
240264

241-
return magicString.toString()
265+
console.log(`shimmed: ${file}`)
266+
267+
return code
242268
}
243269
}
244270
},

playground/tailwind/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@vitejs/test-tailwind",
33
"private": true,
44
"version": "0.0.0",
5+
"type": "module",
56
"scripts": {
67
"dev": "vite",
78
"build": "vite build",
@@ -15,6 +16,6 @@
1516
"vue-router": "^4.4.5"
1617
},
1718
"devDependencies": {
18-
"ts-node": "^10.9.2"
19+
"tsx": "^4.11.0"
1920
}
2021
}

playground/tailwind/postcss.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// postcss.config.ts
2-
module.exports = {
2+
import { fileURLToPath } from 'node:url'
3+
4+
export default {
35
plugins: {
4-
tailwindcss: { config: __dirname + '/tailwind.config.js' },
6+
tailwindcss: {
7+
config: fileURLToPath(new URL('./tailwind.config.ts', import.meta.url)),
8+
},
59
autoprefixer: {},
610
},
711
}

playground/tailwind/tailwind.config.js renamed to playground/tailwind/tailwind.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/** @type {import('tailwindcss').Config} */
1+
import type { Config } from 'tailwindcss'
22

3-
module.exports = {
3+
export default {
44
content: [
55
// Before editing this section, make sure no paths are matching with `/src/main.js`
66
// Look https://github.com/vitejs/vite/pull/6959 for more details
@@ -14,4 +14,4 @@ module.exports = {
1414
extend: {},
1515
},
1616
plugins: [],
17-
}
17+
} satisfies Config

0 commit comments

Comments
 (0)