Skip to content

Commit

Permalink
fix: nx #40 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangHongEn authored Aug 29, 2024
1 parent d3487be commit 661e052
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"format": "pretty-quick",
"dev": "microbundle watch",
"build": "rimraf lib && microbundle --no-sourcemap --compress=false",
"dev-rust-vite": "pnpm -filter 'examples-rust-vite*' run dev",
"dev-vite-vite": "pnpm -filter 'examples-vite-vite*' run dev",
"preview-vite-vite": "pnpm -filter 'examples-vite-vite*' run preview"
"dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
"dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
"preview-vv": "pnpm -filter 'examples-vite-vite*' run preview"
},
"repository": {
"type": "git",
Expand Down
22 changes: 17 additions & 5 deletions src/utils/VirtualModule.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { mkdirSync, writeFile, writeFileSync } from "fs";
import { resolve } from "pathe";
import { existsSync, mkdirSync, writeFile, writeFileSync } from "fs";
import { dirname, join, parse, resolve } from "pathe";
import { packageNameEncode } from "../utils/packageNameUtils";

const nodeModulesDir = resolve("./node_modules")
const nodeModulesDir = function findNodeModulesDir(startDir = process.cwd()) {
let currentDir = startDir;

while (currentDir !== parse(currentDir).root) {
const nodeModulesPath = join(currentDir, 'node_modules');
if (existsSync(nodeModulesPath)) {
return nodeModulesPath;
}
currentDir = dirname(currentDir);
}

return "";
}()
export const virtualPackageName = "__mf__virtual"
try {
if (!existsSync(resolve(nodeModulesDir, virtualPackageName))) {
mkdirSync(resolve(nodeModulesDir, virtualPackageName))
} catch (e) { }
}
writeFileSync(resolve(nodeModulesDir, virtualPackageName, "empty.js"), "")
writeFileSync(resolve(nodeModulesDir, virtualPackageName, "package.json"), JSON.stringify({
name: virtualPackageName,
Expand Down

0 comments on commit 661e052

Please sign in to comment.