1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-05 04:15:55 +02:00

Revert "deps: Update vite to v8" (#17283)

Revert "deps: Update vite to v8 (#17238)"

This reverts commit e601fcb729.
This commit is contained in:
かっこかり
2026-04-06 20:15:57 +09:00
committed by GitHub
parent 0b7b59f1e2
commit a18c909ba3
16 changed files with 735 additions and 1553 deletions

View File

@@ -4,11 +4,11 @@
*/
import * as estreeWalker from 'estree-walker';
import { RolldownMagicString } from 'rolldown';
import MagicString from 'magic-string';
import { assertType } from './utils.js';
import type { ESTree } from 'rolldown/utils';
import type { Plugin } from 'vite';
import type { CallExpression, Expression } from 'estree';
import type { CallExpression, Expression, Program } from 'estree';
import type { AstNode } from 'rollup';
// This plugin transforms `unref(i18n)` to `i18n` in the code, which is useful for removing unnecessary unref calls
// and helps locale inliner runs after vite build to inline the locale data into the final build.
@@ -23,13 +23,12 @@ export function pluginRemoveUnrefI18n(
} = {}): Plugin {
return {
name: 'UnwindCssModuleClassName',
renderChunk(code, _chunk, _options, meta) {
renderChunk(code) {
if (!code.includes('unref(i18n)')) return null;
const ast = this.parse(code);
const magicString = meta.magicString ?? new RolldownMagicString(code);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(estreeWalker.walk as any)(ast, {
enter(node: ESTree.Node) {
const ast = this.parse(code) as Program;
const magicString = new MagicString(code);
estreeWalker.walk(ast, {
enter(node) {
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'unref'
&& node.arguments.length === 1) {
// calls to unref with single argument
@@ -37,16 +36,18 @@ export function pluginRemoveUnrefI18n(
if (arg.type === 'Identifier' && arg.name === i18nSymbolName) {
// this is unref(i18n) so replace it with i18n
// to replace, remove the 'unref(' and the trailing ')'
assertType<CallExpression>(node);
assertType<Expression>(arg);
assertType<CallExpression & AstNode>(node);
assertType<Expression & AstNode>(arg);
magicString.remove(node.start, arg.start);
magicString.remove(arg.end, node.end);
}
}
},
});
return magicString;
return {
code: magicString.toString(),
map: magicString.generateMap({ hires: true }),
};
},
};
}