Skip to content

Commit 4750980

Browse files
enhance(frontend): update vite to v8 再 (#17289)
* Revert "Revert "deps: Update vite to v8" (#17283)" This reverts commit a18c909. * fix(frontend): popupのりアクティビティがチャンクをまたいで切れる事がある問題を修正 * update vite/rolldown
1 parent 92e0e8e commit 4750980

21 files changed

Lines changed: 1454 additions & 633 deletions

packages/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,6 @@
228228
"pid-port": "2.1.0",
229229
"simple-oauth2": "5.1.0",
230230
"supertest": "7.2.2",
231-
"vite": "7.3.1"
231+
"vite": "8.0.7"
232232
}
233233
}

packages/frontend-builder/locale-inliner/collect-modifications.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*/
55

6-
import { parseAst } from 'vite';
6+
import { parseAst } from 'rolldown/parseAst';
77
import * as estreeWalker from 'estree-walker';
88
import { assertNever, assertType } from '../utils.js';
9-
import type { AstNode, ProgramNode } from 'rollup';
9+
import type { ESTree as RolldownESTree } from 'rolldown/utils';
10+
import type { AstNode } from 'rollup';
1011
import type * as estree from 'estree';
1112
import type { LocaleInliner, TextModification } from '../locale-inliner.js';
1213
import type { Logger } from '../logger.js';
@@ -17,7 +18,7 @@ interface WalkerContext {
1718
}
1819

1920
export function collectModifications(sourceCode: string, fileName: string, fileLogger: Logger, inliner: LocaleInliner): TextModification[] {
20-
let programNode: ProgramNode;
21+
let programNode: RolldownESTree.Program;
2122
try {
2223
programNode = parseAst(sourceCode);
2324
} catch (err) {
@@ -35,7 +36,8 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
3536
// 1) replace all `scripts/` path literals with locale code
3637
// 2) replace all `localStorage.getItem("lang")` with `localeName` variable
3738
// 3) replace all `await window.fetch(`/assets/locales/${d}.${x}.json`).then(u=>u.json())` with `localeJson` variable
38-
estreeWalker.walk(programNode, {
39+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40+
(estreeWalker.walk as any)(programNode, {
3941
enter(this: WalkerContext, node: Node) {
4042
assertType<AstNode>(node);
4143

@@ -118,8 +120,9 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
118120
// Check if the identifier is already declared in the file.
119121
// If it is, we may overwrite it and cause issues so we skip inlining
120122
let isSupported = true;
121-
estreeWalker.walk(programNode, {
122-
enter(node) {
123+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
124+
(estreeWalker.walk as any)(programNode, {
125+
enter(node: Node) {
123126
if (node.type === 'VariableDeclaration') {
124127
assertType<estree.VariableDeclaration>(node);
125128
for (const id of node.declarations.flatMap(x => declsOfPattern(x.id))) {
@@ -145,8 +148,9 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
145148

146149
const toSkip = new Set();
147150
toSkip.add(i18nImport);
148-
estreeWalker.walk(programNode, {
149-
enter(this: WalkerContext, node, parent, property) {
151+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152+
(estreeWalker.walk as any)(programNode, {
153+
enter(this: WalkerContext, node: Node, parent: Node | null, property: string | number | symbol | null | undefined) {
150154
assertType<AstNode>(node);
151155
assertType<AstNode>(parent);
152156
if (toSkip.has(node)) {
@@ -379,7 +383,7 @@ type SpecifierResult =
379383
| { type: 'specifier', localI18nIdentifier: string, importNode: estree.ImportDeclaration & AstNode }
380384
;
381385

382-
function findImportSpecifier(programNode: ProgramNode, i18nFileName: string, i18nSymbol: string): SpecifierResult {
386+
function findImportSpecifier(programNode: RolldownESTree.Program, i18nFileName: string, i18nSymbol: string): SpecifierResult {
383387
const imports = programNode.body.filter(x => x.type === 'ImportDeclaration');
384388
const importNode = imports.find(x => x.source.value === `./${i18nFileName}`) as estree.ImportDeclaration | undefined;
385389
if (!importNode) return { type: 'no-import' };

packages/frontend-builder/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
"rollup": "4.60.0"
1818
},
1919
"dependencies": {
20-
"i18n": "workspace:*",
2120
"estree-walker": "3.0.3",
21+
"i18n": "workspace:*",
2222
"magic-string": "0.30.21",
23-
"vite": "7.3.1"
23+
"rolldown": "1.0.0-rc.13",
24+
"vite": "8.0.7"
2425
}
2526
}

packages/frontend-builder/rollup-plugin-remove-unref-i18n.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55

66
import * as estreeWalker from 'estree-walker';
7-
import MagicString from 'magic-string';
7+
import { RolldownMagicString } from 'rolldown';
88
import { assertType } from './utils.js';
9+
import type { ESTree } from 'rolldown/utils';
910
import type { Plugin } from 'vite';
10-
import type { CallExpression, Expression, Program } from 'estree';
11-
import type { AstNode } from 'rollup';
11+
import type { CallExpression, Expression } from 'estree';
1212

1313
// This plugin transforms `unref(i18n)` to `i18n` in the code, which is useful for removing unnecessary unref calls
1414
// and helps locale inliner runs after vite build to inline the locale data into the final build.
@@ -23,31 +23,30 @@ export function pluginRemoveUnrefI18n(
2323
} = {}): Plugin {
2424
return {
2525
name: 'UnwindCssModuleClassName',
26-
renderChunk(code) {
26+
renderChunk(code, _chunk, _options, meta) {
2727
if (!code.includes('unref(i18n)')) return null;
28-
const ast = this.parse(code) as Program;
29-
const magicString = new MagicString(code);
30-
estreeWalker.walk(ast, {
31-
enter(node) {
28+
const ast = this.parse(code);
29+
const magicString = meta.magicString ?? new RolldownMagicString(code);
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31+
(estreeWalker.walk as any)(ast, {
32+
enter(node: ESTree.Node) {
3233
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'unref'
3334
&& node.arguments.length === 1) {
3435
// calls to unref with single argument
3536
const arg = node.arguments[0];
3637
if (arg.type === 'Identifier' && arg.name === i18nSymbolName) {
3738
// this is unref(i18n) so replace it with i18n
3839
// to replace, remove the 'unref(' and the trailing ')'
39-
assertType<CallExpression & AstNode>(node);
40-
assertType<Expression & AstNode>(arg);
40+
assertType<CallExpression>(node);
41+
assertType<Expression>(arg);
4142
magicString.remove(node.start, arg.start);
4243
magicString.remove(arg.end, node.end);
4344
}
4445
}
4546
},
4647
});
47-
return {
48-
code: magicString.toString(),
49-
map: magicString.generateMap({ hires: true }),
50-
};
48+
49+
return magicString;
5150
},
5251
};
5352
}

packages/frontend-embed/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import url from 'node:url';
33
import path from 'node:path';
44
import { execa } from 'execa';
55
import locales from 'i18n';
6-
import { LocaleInliner } from '../frontend-builder/locale-inliner.js'
6+
import { LocaleInliner } from '../frontend-builder/locale-inliner.js';
77
import { createLogger } from '../frontend-builder/logger';
88

99
// requires node 21 or later

packages/frontend-embed/vite.json5.ts renamed to packages/frontend-embed/lib/vite-plugin-json5.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Original: https://github.com/rollup/plugins/tree/8835dd2aed92f408d7dc72d7cc25a9728e16face/packages/json
1+
/*
2+
* SPDX-FileCopyrightText: syuilo and misskey-project
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
25

36
import JSON5 from 'json5';
4-
import { Plugin } from 'rollup';
7+
import { Plugin } from 'vite';
58
import { createFilter, dataToEsm } from '@rollup/pluginutils';
69
import { RollupJsonOptions } from '@rollup/plugin-json';
710

packages/frontend-embed/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dependencies": {
1313
"@discordapp/twemoji": "16.0.1",
1414
"@rollup/plugin-json": "6.1.0",
15-
"@rollup/plugin-replace": "6.0.3",
1615
"@rollup/pluginutils": "5.3.0",
1716
"@twemoji/parser": "16.0.0",
1817
"@vitejs/plugin-vue": "6.0.5",
@@ -26,11 +25,9 @@
2625
"misskey-js": "workspace:*",
2726
"punycode.js": "2.3.1",
2827
"rollup": "4.60.0",
29-
"sass": "1.98.0",
3028
"shiki": "3.23.0",
3129
"tinycolor2": "1.6.0",
3230
"uuid": "13.0.0",
33-
"vite": "7.3.1",
3431
"vue": "3.5.30"
3532
},
3633
"devDependencies": {
@@ -45,7 +42,7 @@
4542
"@types/ws": "8.18.1",
4643
"@typescript-eslint/eslint-plugin": "8.57.2",
4744
"@typescript-eslint/parser": "8.57.2",
48-
"@vitest/coverage-v8": "4.1.1",
45+
"@vitest/coverage-v8": "4.1.2",
4946
"@vue/runtime-core": "3.5.30",
5047
"acorn": "8.16.0",
5148
"cross-env": "10.1.0",
@@ -57,8 +54,10 @@
5754
"msw": "2.12.14",
5855
"nodemon": "3.1.14",
5956
"prettier": "3.8.1",
57+
"sass-embedded": "1.98.0",
6058
"start-server-and-test": "2.1.5",
6159
"tsx": "4.21.0",
60+
"vite": "8.0.7",
6261
"vite-plugin-turbosnap": "1.0.3",
6362
"vue-component-type-helpers": "3.2.6",
6463
"vue-eslint-parser": "10.4.0",

packages/frontend-embed/vite.config.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { promises as fsp } from 'fs';
77
import locales from 'i18n';
88
import meta from '../../package.json';
99
import packageInfo from './package.json' with { type: 'json' };
10-
import pluginJson5 from './vite.json5.js';
10+
import pluginJson5 from './lib/vite-plugin-json5.js';
1111
import { pluginRemoveUnrefI18n } from '../frontend-builder/rollup-plugin-remove-unref-i18n';
1212

13-
const url = process.env.NODE_ENV === 'development' ? yaml.load(await fsp.readFile('../../.config/default.yml', 'utf-8')).url : null;
13+
const url = process.env.NODE_ENV === 'development' ? (yaml.load(await fsp.readFile('../../.config/default.yml', 'utf-8')) as any).url : null;
1414
const host = url ? (new URL(url)).hostname : undefined;
1515

1616
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];
@@ -113,11 +113,6 @@ export function getConfig(): UserConfig {
113113
}
114114
},
115115
},
116-
preprocessorOptions: {
117-
scss: {
118-
api: 'modern-compiler',
119-
},
120-
},
121116
},
122117

123118
define: {
@@ -137,18 +132,26 @@ export function getConfig(): UserConfig {
137132
'safari16',
138133
],
139134
manifest: 'manifest.json',
140-
rollupOptions: {
135+
rolldownOptions: {
136+
experimental: {
137+
nativeMagicString: true,
138+
},
141139
input: {
142140
i18n: './src/i18n.ts',
143141
entry: './src/boot.ts',
144142
},
145143
external: externalPackages.map(p => p.match),
146144
preserveEntrySignatures: 'allow-extension',
147145
output: {
148-
manualChunks: {
149-
vue: ['vue'],
150-
// dependencies of i18n.ts
151-
'config': ['@@/js/config.js'],
146+
codeSplitting: {
147+
groups: [{
148+
name: 'vue',
149+
test: /node_modules[\\/]vue/,
150+
}, {
151+
// dependencies of i18n.ts
152+
name: 'config',
153+
test: /@@[\\/]js[\\/]config\.js/,
154+
}],
152155
},
153156
entryFileNames: `scripts/${localesHash}-[hash:8].js`,
154157
chunkFileNames: `scripts/${localesHash}-[hash:8].js`,

0 commit comments

Comments
 (0)