From 6f0eef4c3b86b127b983e5e22265e75855e6238c Mon Sep 17 00:00:00 2001 From: erkelost <1256029807@qq.com> Date: Tue, 14 Jan 2025 11:25:03 +0800 Subject: [PATCH] fix: #2062 --- examples/refactor-react/farm.config.ts | 74 +------------------------ rust-plugins/replace-dirname/src/lib.rs | 20 ++++++- 2 files changed, 20 insertions(+), 74 deletions(-) diff --git a/examples/refactor-react/farm.config.ts b/examples/refactor-react/farm.config.ts index 01edc50ca8..d4290a6c7f 100644 --- a/examples/refactor-react/farm.config.ts +++ b/examples/refactor-react/farm.config.ts @@ -1,52 +1,11 @@ import { defineConfig, loadEnv } from "@farmfe/core"; - +import path from 'node:path' import react from "@farmfe/plugin-react"; -import path from "path"; +console.log(path.resolve(__dirname, 'src/CustomResolved.vue').replaceAll('\\', '/')); -function custom() { - return { - name: "farm-test-plugin-name", - buildStart: { - executor() { - // console.log("buildStart"); - } - }, - config(config) { - config.plugins.push({ - name: "test-add-plugin" - }) - return config - }, - resolve: { - filters: { - importers: ['^.*$'], - sources: ['.*'], - }, - executor(param) { - } - }, - transform: { - filters: { - moduleTypes: ['js'], - }, - async executor(param, ctx) { - // console.log(param, "transform"); - } - }, - // renderStart: { - // async executor() { - // // update my plugin status - // // console.log(1231231); - // } - // } - } -} export default defineConfig({ plugins: [ react(), - // myCustomPlugin(), - // compilerPlugin(), - custom() ], compilation: { input: { @@ -55,37 +14,8 @@ export default defineConfig({ about: path.resolve(__dirname, 'about.html'), }, progress: false, - // persistentCache: false, - // persistentCache: { - // cacheDir: "node_modules/.adny", - // }, output: { publicPath: "/aaa/", }, }, - server: { - port: 4855, - appType: "mpa", - }, }); - -function myCustomPlugin() { - return { - name: "custom", - updateModules: { - executor(data: any) { - console.log(data); - }, - }, - }; -} - -function compilerPlugin() { - return { - name: "compiler", - configureCompiler(compiler: any) { - // console.log(compiler, "compiler") - }, - }; -} - diff --git a/rust-plugins/replace-dirname/src/lib.rs b/rust-plugins/replace-dirname/src/lib.rs index 0f3a2fa652..06a01e48b9 100644 --- a/rust-plugins/replace-dirname/src/lib.rs +++ b/rust-plugins/replace-dirname/src/lib.rs @@ -7,7 +7,7 @@ use farmfe_core::{ error::CompilationError, plugin::{Plugin, PluginProcessModuleHookParam}, swc_common::DUMMY_SP, - swc_ecma_ast::{self, Expr, Lit, MemberExpr, MemberProp, Module, Str}, + swc_ecma_ast::{self, Callee, Expr, Lit, MemberExpr, MemberProp, MetaPropKind, Module, Str}, }; use std::{env, path::Path, sync::Arc}; use url::Url; @@ -100,9 +100,25 @@ pub fn replace_dirname_with_ast(ast: &mut Module, dir_path: &str, file_path: &st } _ => {} }, + + Expr::Call(call_expr) => { + for arg in &mut call_expr.args { + self.visit_mut_expr(&mut arg.expr); + } + + match &mut call_expr.callee { + Callee::Expr(expr) => { + self.visit_mut_expr(expr); + } + _ => {} + } + } + Expr::Member(MemberExpr { obj, prop, .. }) => { + // #2062 + self.visit_mut_expr(obj); if let Expr::MetaProp(meta_prop) = &**obj { - if meta_prop.kind == swc_ecma_ast::MetaPropKind::ImportMeta { + if meta_prop.kind == MetaPropKind::ImportMeta { if let MemberProp::Ident(ident) = &prop { if ident.sym == "url" { if let Ok(file_path) = Url::from_file_path(self.file_path) {