Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #2062 #2063

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
},
};
}

17 changes: 15 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,22 @@ 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);
}

if let Callee::Expr(expr) = &mut call_expr.callee {
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
Loading