diff --git a/Cargo.lock b/Cargo.lock index 57e157004..a9eda403b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1616,20 +1616,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "farm_plugin_replace_dirname" -version = "0.0.0" -dependencies = [ - "farmfe_core", - "farmfe_macro_plugin", - "farmfe_toolkit", - "farmfe_toolkit_plugin_types", - "regex", - "serde", - "serde_json", - "url", -] - [[package]] name = "farmfe_compiler" version = "0.0.11" @@ -1840,6 +1826,20 @@ dependencies = [ "serde", ] +[[package]] +name = "farmfe_plugin_replace_dirname" +version = "0.0.0" +dependencies = [ + "farmfe_core", + "farmfe_macro_plugin", + "farmfe_toolkit", + "farmfe_toolkit_plugin_types", + "regex", + "serde", + "serde_json", + "url", +] + [[package]] name = "farmfe_plugin_resolve" version = "0.0.11" diff --git a/examples/refactor-react/farm.config.ts b/examples/refactor-react/farm.config.ts index 23d29be62..5a89f2b10 100644 --- a/examples/refactor-react/farm.config.ts +++ b/examples/refactor-react/farm.config.ts @@ -2,6 +2,9 @@ import { defineConfig } from "@farmfe/core"; import react from "@farmfe/plugin-react"; import path from "path"; + +console.log(__dirname); + export default defineConfig({ plugins: [ react(), diff --git a/packages/core/package.json b/packages/core/package.json index 1e51e13af..fe22dbfa8 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -94,7 +94,7 @@ "dotenv-expand": "^11.0.6", "execa": "8.0.0", "farm-browserslist-generator": "^1.0.5", - "farm-plugin-replace-dirname": "0.2.1", + "@farmfe/plugin-replace-dirname": "workspace:*", "fast-glob": "^3.3.2", "fs-extra": "^11.1.1", "is-plain-object": "^5.0.0", diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index bd0fb18ab..f78b93be4 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -665,15 +665,14 @@ export async function readConfigFile( mode }); - // const replaceDirnamePlugin = await import('farm-plugin-replace-dirname').then( - // (mod) => mod.default - // ); + const replaceDirnamePlugin = await import( + '@farmfe/plugin-replace-dirname' + ).then((mod) => mod.default); const compiler = new Compiler({ compilation: normalizedConfig, jsPlugins: [], - // rustPlugins: [[replaceDirnamePlugin, '{}']] - rustPlugins: [] + rustPlugins: [[replaceDirnamePlugin, '{}']] }); const FARM_PROFILE = process.env.FARM_PROFILE; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 809ca0761..70a4168aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2610,6 +2610,9 @@ importers: packages/core: dependencies: + '@farmfe/plugin-replace-dirname': + specifier: workspace:* + version: link:../../rust-plugins/replace-dirname '@farmfe/runtime': specifier: workspace:1.0.0-nightly-20241023020505 version: link:../runtime @@ -2655,9 +2658,6 @@ importers: farm-browserslist-generator: specifier: ^1.0.5 version: 1.0.5 - farm-plugin-replace-dirname: - specifier: 0.2.1 - version: 0.2.1 fast-glob: specifier: ^3.3.2 version: 3.3.2 @@ -12280,63 +12280,6 @@ packages: farm-plugin-remove-console@0.1.8: resolution: {integrity: sha512-t/QH2N97w2/VM4tj/hmnceU/95yYeORR5BnlWP91PherULRFhTVctECcC0JI33Psvyk06uSW4BuKgBPtktM5+w==} - farm-plugin-replace-dirname-darwin-arm64@0.2.1: - resolution: {integrity: sha512-9FThv/qoFuj3cJjv9P6YnXbBwPQ5TwGjnr50ejXdZn13Ehz0+7w7EscbRsZHNvT7p24p6i0Y9NUSallcWc2syw==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] - - farm-plugin-replace-dirname-darwin-x64@0.2.1: - resolution: {integrity: sha512-Msqrh8mAPBbEpANpa0z9uQBr1/MO+PaHgBxym/aNs1vpxB4KAs6JQWYKtO+Ob7JzFyV6d9lIRhpnpxzxTqSIfA==} - engines: {node: '>= 10'} - cpu: [x64] - os: [darwin] - - farm-plugin-replace-dirname-linux-arm64-gnu@0.2.1: - resolution: {integrity: sha512-ZKuxGu9G01CW521uTQHh+IP8pcT/NolGQfcQuEmBpD8epJ8per8Ps52fS05u5TGniaOg+ySZpt7HxbX+++k1YQ==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - - farm-plugin-replace-dirname-linux-arm64-musl@0.2.1: - resolution: {integrity: sha512-m3gH8ggczbRYTHZSNp3LjIQIcqhvDO4O78bxXc8O1ozKD8M47/YfQLyQV06M7H4rZ8s6XV3Bb1kAcRAASp3M5A==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - - farm-plugin-replace-dirname-linux-x64-gnu@0.2.1: - resolution: {integrity: sha512-MehKkoM2RFw3sCnEu9nCbXKjxtC3hfTad0h/dC+Z8iEBcLEReVLoNzHWWUa6BxkxqDtB82/BWO/ObSUj/VUnwQ==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - - farm-plugin-replace-dirname-linux-x64-musl@0.2.1: - resolution: {integrity: sha512-o1qPZi16N/sHOteZYJVv6UmZFK3QKpVQrywk/4spJI0mPH9A9Y+G6iBE2Tqjb3d+1Hb6phr++EBJHZ2x1ajtGQ==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - - farm-plugin-replace-dirname-win32-arm64-msvc@0.2.1: - resolution: {integrity: sha512-Xn/wYFkgb7SsTlSaefFtvxNbXEVdvZB854b/rBZu47+MRQpSnBIPwnTGcqo8eNTMjtnY4beGGtcd78iqMVAHFQ==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [win32] - - farm-plugin-replace-dirname-win32-ia32-msvc@0.2.1: - resolution: {integrity: sha512-YtIu5CS/BSgbQZb1qjaBg0cEKvB4vCIbBxNn64H468zwliPbE93SAIyiwu6cL3la59cjBP4sEbz4ZAWyY9GoMQ==} - engines: {node: '>= 10'} - cpu: [ia32] - os: [win32] - - farm-plugin-replace-dirname-win32-x64-msvc@0.2.1: - resolution: {integrity: sha512-KUAf4rcv3Nz+CpGs4zr+ZRu4hWRp7SHQBgpX+mb0hhMjRvn+LoWm2qCL2q9Gp3jsTDVmzjPbyZxp/9UJKx13lQ==} - engines: {node: '>= 10'} - cpu: [x64] - os: [win32] - - farm-plugin-replace-dirname@0.2.1: - resolution: {integrity: sha512-aJ4euQzxoq0sVu4AwXrNQflHJrSZdrdApGEyVRtN6KiCop3CHXnTg9ydlyCNXN2unQB283aNjojvCd5E/32KgA==} - farmup@0.1.4: resolution: {integrity: sha512-zOr66ynrL9F3WmfuhkwQ73wg1IBBdDAEAJBw3MuOfKRdpKzqyn2T5dVBvVqE4YAIF7GnDyBrw1f/V2Z94+9WNw==} hasBin: true @@ -34717,49 +34660,6 @@ snapshots: farm-plugin-remove-console-win32-ia32-msvc: 0.1.8 farm-plugin-remove-console-win32-x64-msvc: 0.1.8 - farm-plugin-replace-dirname-darwin-arm64@0.2.1: - optional: true - - farm-plugin-replace-dirname-darwin-x64@0.2.1: - optional: true - - farm-plugin-replace-dirname-linux-arm64-gnu@0.2.1: - optional: true - - farm-plugin-replace-dirname-linux-arm64-musl@0.2.1: - optional: true - - farm-plugin-replace-dirname-linux-x64-gnu@0.2.1: - optional: true - - farm-plugin-replace-dirname-linux-x64-musl@0.2.1: - optional: true - - farm-plugin-replace-dirname-win32-arm64-msvc@0.2.1: - optional: true - - farm-plugin-replace-dirname-win32-ia32-msvc@0.2.1: - optional: true - - farm-plugin-replace-dirname-win32-x64-msvc@0.2.1: - optional: true - - farm-plugin-replace-dirname@0.2.1: - dependencies: - '@changesets/cli': 2.27.2 - '@farmfe/utils': 0.0.1 - cac: 6.7.14 - optionalDependencies: - farm-plugin-replace-dirname-darwin-arm64: 0.2.1 - farm-plugin-replace-dirname-darwin-x64: 0.2.1 - farm-plugin-replace-dirname-linux-arm64-gnu: 0.2.1 - farm-plugin-replace-dirname-linux-arm64-musl: 0.2.1 - farm-plugin-replace-dirname-linux-x64-gnu: 0.2.1 - farm-plugin-replace-dirname-linux-x64-musl: 0.2.1 - farm-plugin-replace-dirname-win32-arm64-msvc: 0.2.1 - farm-plugin-replace-dirname-win32-ia32-msvc: 0.2.1 - farm-plugin-replace-dirname-win32-x64-msvc: 0.2.1 - farmup@0.1.4: dependencies: '@farmfe/core': link:packages/core diff --git a/rust-plugins/replace-dirname/Cargo.toml b/rust-plugins/replace-dirname/Cargo.toml index bead3ecfe..263af8932 100644 --- a/rust-plugins/replace-dirname/Cargo.toml +++ b/rust-plugins/replace-dirname/Cargo.toml @@ -1,6 +1,6 @@ [package] edition = "2021" -name = "farm_plugin_replace_dirname" +name = "farmfe_plugin_replace_dirname" version = "0.0.0" [lib] diff --git a/rust-plugins/replace-dirname/func.js b/rust-plugins/replace-dirname/func.js deleted file mode 100644 index ebd41be5b..000000000 --- a/rust-plugins/replace-dirname/func.js +++ /dev/null @@ -1,3 +0,0 @@ -import binPath from "./index.js"; - -export default (options)=>[binPath,options]; diff --git a/rust-plugins/replace-dirname/index.d.ts b/rust-plugins/replace-dirname/index.d.ts index 8cf7cf2ef..299c09ef0 100755 --- a/rust-plugins/replace-dirname/index.d.ts +++ b/rust-plugins/replace-dirname/index.d.ts @@ -1,9 +1,13 @@ -export interface SassOptions { +export interface IOptions { /** - * Add extra content to the head of each sass file, such as an @import '@/styles/variables.scss'; statement. + * The path to the root of the project */ - additionalData?: string; + include?: string[]; + /** + * exclude the path from the project + */ + exclude?: string[]; } -declare const binPath: (options?: SassOptions) => [string, typeof options]; +const binPath: string; export default binPath; diff --git a/rust-plugins/replace-dirname/index.js b/rust-plugins/replace-dirname/index.js index 46eef5702..46ca68e7b 100755 --- a/rust-plugins/replace-dirname/index.js +++ b/rust-plugins/replace-dirname/index.js @@ -1,7 +1,7 @@ -import { existsSync, readFileSync } from 'fs'; -import { createRequire } from 'module'; -import { dirname, join } from 'path'; -import { fileURLToPath } from 'url'; +import { existsSync, readFileSync } from "fs"; +import { createRequire } from "module"; +import { dirname, join } from "path"; +import { fileURLToPath } from "url"; const { platform, arch } = process; const currentDir = dirname(fileURLToPath(import.meta.url)); @@ -12,9 +12,9 @@ const require = createRequire(import.meta.url); function isMusl() { // For Node 10 - if (!process.report || typeof process.report.getReport !== 'function') { + if (!process.report || typeof process.report.getReport !== "function") { try { - return readFileSync('/usr/bin/ldd', 'utf8').includes('musl'); + return readFileSync("/usr/bin/ldd", "utf8").includes("musl"); } catch (e) { return true; } @@ -25,29 +25,35 @@ function isMusl() { } switch (platform) { - case 'win32': + case "win32": switch (arch) { - case 'x64': - if (existsSync(join(currentDir, './npm/win32-x64-msvc/index.farm'))) { - binPath = join(currentDir, './npm/win32-x64-msvc/index.farm'); + case "x64": + if (existsSync(join(currentDir, "./npm/win32-x64-msvc/index.farm"))) { + binPath = join(currentDir, "./npm/win32-x64-msvc/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-win32-x64-msvc'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-win32-x64-msvc", + ); } break; - case 'ia32': - if (existsSync(join(currentDir, './npm/win32-ia32-msvc/index.farm'))) { - binPath = join(currentDir, './npm/win32-ia32-msvc/index.farm'); + case "ia32": + if (existsSync(join(currentDir, "./npm/win32-ia32-msvc/index.farm"))) { + binPath = join(currentDir, "./npm/win32-ia32-msvc/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-win32-ia32-msvc'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-win32-ia32-msvc", + ); } break; - case 'arm64': - if (existsSync(join(currentDir, './npm/win32-arm64-msvc/index.farm'))) { - binPath = join(currentDir, './npm/win32-arm64-msvc/index.farm'); + case "arm64": + if (existsSync(join(currentDir, "./npm/win32-arm64-msvc/index.farm"))) { + binPath = join(currentDir, "./npm/win32-arm64-msvc/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-win32-arm64-msvc'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-win32-arm64-msvc", + ); } break; @@ -55,61 +61,73 @@ switch (platform) { throw new Error(`Unsupported architecture on Windows: ${arch}`); } break; - case 'darwin': + case "darwin": switch (arch) { - case 'x64': - if (existsSync(join(currentDir, './npm/darwin-x64/index.farm'))) { - binPath = join(currentDir, './npm/darwin-x64/index.farm'); + case "x64": + if (existsSync(join(currentDir, "./npm/darwin-x64/index.farm"))) { + binPath = join(currentDir, "./npm/darwin-x64/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-darwin-x64'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-darwin-x64", + ); } break; - case 'arm64': - if (existsSync(join(currentDir, './npm/darwin-arm64/index.farm'))) { - binPath = join(currentDir, './npm/darwin-arm64/index.farm'); + case "arm64": + if (existsSync(join(currentDir, "./npm/darwin-arm64/index.farm"))) { + binPath = join(currentDir, "./npm/darwin-arm64/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-darwin-arm64'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-darwin-arm64", + ); } break; default: throw new Error(`Unsupported architecture on macOS: ${arch}`); } break; - case 'linux': + case "linux": switch (arch) { - case 'x64': + case "x64": if (isMusl()) { - if (existsSync(join(currentDir, './npm/linux-x64-musl/index.farm'))) { - binPath = join(currentDir, './npm/linux-x64-musl/index.farm'); + if (existsSync(join(currentDir, "./npm/linux-x64-musl/index.farm"))) { + binPath = join(currentDir, "./npm/linux-x64-musl/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-linux-x64-musl'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-linux-x64-musl", + ); } } else { - if (existsSync(join(currentDir, './npm/linux-x64-gnu/index.farm'))) { - binPath = join(currentDir, './npm/linux-x64-gnu/index.farm'); + if (existsSync(join(currentDir, "./npm/linux-x64-gnu/index.farm"))) { + binPath = join(currentDir, "./npm/linux-x64-gnu/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-linux-x64-gnu'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-linux-x64-gnu", + ); } } break; - case 'arm64': + case "arm64": if (isMusl()) { if ( - existsSync(join(currentDir, './npm/linux-arm64-musl/index.farm')) + existsSync(join(currentDir, "./npm/linux-arm64-musl/index.farm")) ) { - binPath = join(currentDir, './npm/linux-arm64-musl/index.farm'); + binPath = join(currentDir, "./npm/linux-arm64-musl/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-linux-arm64-musl'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-linux-arm64-musl", + ); } } else { if ( - existsSync(join(currentDir, './npm/linux-arm64-gnu/index.farm')) + existsSync(join(currentDir, "./npm/linux-arm64-gnu/index.farm")) ) { - binPath = join(currentDir, './npm/linux-arm64-gnu/index.farm'); + binPath = join(currentDir, "./npm/linux-arm64-gnu/index.farm"); } else { - binPath = require.resolve('@farmfe/plugin-sass-linux-arm64-gnu'); + binPath = require.resolve( + "@farmfe/plugin-replace-dirname-linux-arm64-gnu", + ); } } break; diff --git a/rust-plugins/replace-dirname/package.json b/rust-plugins/replace-dirname/package.json index 131ae688a..99756825a 100755 --- a/rust-plugins/replace-dirname/package.json +++ b/rust-plugins/replace-dirname/package.json @@ -26,7 +26,7 @@ }, "exports": { ".": { - "import": "./func.js", + "import": "./index.js", "types": "./index.d.ts", "default": "./index.js" },