forked from mirrors/misskey
deps: Update vite to v8 (#17238)
* deps: Update vite to v8 * fix * migrate some plugins to rolldown-based * fix broken lockfile * wip * update rolldown * override rolldown version * perf * spdx * fix * update vite to 8.0.1 * chore: rewrite rollup-plugin-unwind-css-module-class-name with MagicString * format * swap type definitions * replace using MagicString * provided magicString * fix code style * fix * fix * fix * fix * fix --------- Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> * fix: lint fixes * swap sass with sass-embedded * fix lint * fix: インライン化されたVue SFC出力に対してCSS Module定義削除が効かないのを修正 * fix * fix: バックエンドのCSS読み込みの方法が悪いのを修正 * fix: 使用されないpreloadを削除 * fix lint [ci skip] * Apply suggestion from @syuilo * Add comment in pnpm-workspace.yaml [ci skip] * update vite/rolldown * remove magic-string --------- Co-authored-by: cm-ayf <cm.ayf2734@gmail.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { parseAst } from 'vite';
|
||||
import { parseAst } from 'rolldown/parseAst';
|
||||
import * as estreeWalker from 'estree-walker';
|
||||
import { assertNever, assertType } from '../utils.js';
|
||||
import type { AstNode, ProgramNode } from 'rollup';
|
||||
import type { ESTree as RolldownESTree } from 'rolldown/utils';
|
||||
import type { AstNode } from 'rollup';
|
||||
import type * as estree from 'estree';
|
||||
import type { LocaleInliner, TextModification } from '../locale-inliner.js';
|
||||
import type { Logger } from '../logger.js';
|
||||
@@ -17,7 +18,7 @@ interface WalkerContext {
|
||||
}
|
||||
|
||||
export function collectModifications(sourceCode: string, fileName: string, fileLogger: Logger, inliner: LocaleInliner): TextModification[] {
|
||||
let programNode: ProgramNode;
|
||||
let programNode: RolldownESTree.Program;
|
||||
try {
|
||||
programNode = parseAst(sourceCode);
|
||||
} catch (err) {
|
||||
@@ -35,7 +36,8 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
|
||||
// 1) replace all `scripts/` path literals with locale code
|
||||
// 2) replace all `localStorage.getItem("lang")` with `localeName` variable
|
||||
// 3) replace all `await window.fetch(`/assets/locales/${d}.${x}.json`).then(u=>u.json())` with `localeJson` variable
|
||||
estreeWalker.walk(programNode, {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(estreeWalker.walk as any)(programNode, {
|
||||
enter(this: WalkerContext, node: Node) {
|
||||
assertType<AstNode>(node);
|
||||
|
||||
@@ -118,8 +120,9 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
|
||||
// Check if the identifier is already declared in the file.
|
||||
// If it is, we may overwrite it and cause issues so we skip inlining
|
||||
let isSupported = true;
|
||||
estreeWalker.walk(programNode, {
|
||||
enter(node) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(estreeWalker.walk as any)(programNode, {
|
||||
enter(node: Node) {
|
||||
if (node.type === 'VariableDeclaration') {
|
||||
assertType<estree.VariableDeclaration>(node);
|
||||
for (const id of node.declarations.flatMap(x => declsOfPattern(x.id))) {
|
||||
@@ -145,8 +148,9 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
|
||||
|
||||
const toSkip = new Set();
|
||||
toSkip.add(i18nImport);
|
||||
estreeWalker.walk(programNode, {
|
||||
enter(this: WalkerContext, node, parent, property) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(estreeWalker.walk as any)(programNode, {
|
||||
enter(this: WalkerContext, node: Node, parent: Node | null, property: string | number | symbol | null | undefined) {
|
||||
assertType<AstNode>(node);
|
||||
assertType<AstNode>(parent);
|
||||
if (toSkip.has(node)) {
|
||||
@@ -379,7 +383,7 @@ type SpecifierResult =
|
||||
| { type: 'specifier', localI18nIdentifier: string, importNode: estree.ImportDeclaration & AstNode }
|
||||
;
|
||||
|
||||
function findImportSpecifier(programNode: ProgramNode, i18nFileName: string, i18nSymbol: string): SpecifierResult {
|
||||
function findImportSpecifier(programNode: RolldownESTree.Program, i18nFileName: string, i18nSymbol: string): SpecifierResult {
|
||||
const imports = programNode.body.filter(x => x.type === 'ImportDeclaration');
|
||||
const importNode = imports.find(x => x.source.value === `./${i18nFileName}`) as estree.ImportDeclaration | undefined;
|
||||
if (!importNode) return { type: 'no-import' };
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
"rollup": "4.60.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"i18n": "workspace:*",
|
||||
"estree-walker": "3.0.3",
|
||||
"i18n": "workspace:*",
|
||||
"magic-string": "0.30.21",
|
||||
"vite": "7.3.1"
|
||||
"rolldown": "1.0.0-rc.11",
|
||||
"vite": "8.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
*/
|
||||
|
||||
import * as estreeWalker from 'estree-walker';
|
||||
import MagicString from 'magic-string';
|
||||
import { RolldownMagicString } from 'rolldown';
|
||||
import { assertType } from './utils.js';
|
||||
import type { ESTree } from 'rolldown/utils';
|
||||
import type { Plugin } from 'vite';
|
||||
import type { CallExpression, Expression, Program } from 'estree';
|
||||
import type { AstNode } from 'rollup';
|
||||
import type { CallExpression, Expression } from 'estree';
|
||||
|
||||
// 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,12 +23,13 @@ export function pluginRemoveUnrefI18n(
|
||||
} = {}): Plugin {
|
||||
return {
|
||||
name: 'UnwindCssModuleClassName',
|
||||
renderChunk(code) {
|
||||
renderChunk(code, _chunk, _options, meta) {
|
||||
if (!code.includes('unref(i18n)')) return null;
|
||||
const ast = this.parse(code) as Program;
|
||||
const magicString = new MagicString(code);
|
||||
estreeWalker.walk(ast, {
|
||||
enter(node) {
|
||||
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) {
|
||||
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'unref'
|
||||
&& node.arguments.length === 1) {
|
||||
// calls to unref with single argument
|
||||
@@ -36,18 +37,16 @@ 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 & AstNode>(node);
|
||||
assertType<Expression & AstNode>(arg);
|
||||
assertType<CallExpression>(node);
|
||||
assertType<Expression>(arg);
|
||||
magicString.remove(node.start, arg.start);
|
||||
magicString.remove(arg.end, node.end);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
return {
|
||||
code: magicString.toString(),
|
||||
map: magicString.generateMap({ hires: true }),
|
||||
};
|
||||
|
||||
return magicString;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user