Skip to content

Commit

Permalink
fix: #2062
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Jan 14, 2025
1 parent 92c2a72 commit 6f0eef4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 74 deletions.
74 changes: 2 additions & 72 deletions examples/refactor-react/farm.config.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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")
},
};
}

20 changes: 18 additions & 2 deletions rust-plugins/replace-dirname/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6f0eef4

Please sign in to comment.