Refactor Server Paradigm.
This commit is contained in:
+68
-24
@@ -1,31 +1,75 @@
|
||||
import { log } from "../../../utils/log";
|
||||
const BunSkipNonBrowserPlugin = {
|
||||
name: "skip-non-browser",
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^(bun:|node:)/ }, (args) => {
|
||||
return { path: args.path, external: true };
|
||||
const skipFilter = /^(bun:|node:|fs$|path$|os$|crypto$|net$|events$|util$|tls$|url$|process$)/;
|
||||
// const skipped_modules = new Set<string>();
|
||||
build.onResolve({ filter: skipFilter }, (args) => {
|
||||
global.SKIPPED_BROWSER_MODULES.add(args.path);
|
||||
return {
|
||||
path: args.path,
|
||||
namespace: "skipped",
|
||||
// external: true,
|
||||
};
|
||||
});
|
||||
build.onResolve({ filter: /^[^./]/ }, (args) => {
|
||||
// If it's a built-in like 'fs' or 'path', skip it immediately
|
||||
const excludes = [
|
||||
"fs",
|
||||
"path",
|
||||
"os",
|
||||
"crypto",
|
||||
"net",
|
||||
"events",
|
||||
"util",
|
||||
];
|
||||
if (excludes.includes(args.path) || args.path.startsWith("node:")) {
|
||||
return { path: args.path, external: true };
|
||||
}
|
||||
try {
|
||||
Bun.resolveSync(args.path, args.importer || process.cwd());
|
||||
return null;
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`[Skip] Mark as external: ${args.path}`);
|
||||
return { path: args.path, external: true };
|
||||
}
|
||||
// build.onEnd(() => {
|
||||
// log.warn(`global.SKIPPED_BROWSER_MODULES`, [
|
||||
// ...global.SKIPPED_BROWSER_MODULES,
|
||||
// ]);
|
||||
// });
|
||||
// build.onResolve({ filter: /^[^./]/ }, (args) => {
|
||||
// // If it's a built-in like 'fs' or 'path', skip it immediately
|
||||
// const excludes = [
|
||||
// "fs",
|
||||
// "path",
|
||||
// "os",
|
||||
// "crypto",
|
||||
// "net",
|
||||
// "events",
|
||||
// "util",
|
||||
// "tls",
|
||||
// ];
|
||||
// if (excludes.includes(args.path) || args.path.startsWith("node:")) {
|
||||
// return {
|
||||
// path: args.path,
|
||||
// // namespace: "skipped",
|
||||
// external: true,
|
||||
// };
|
||||
// }
|
||||
// try {
|
||||
// Bun.resolveSync(args.path, args.importer || process.cwd());
|
||||
// return null;
|
||||
// } catch (e) {
|
||||
// console.warn(`[Skip] Mark as external: ${args.path}`);
|
||||
// return {
|
||||
// path: args.path,
|
||||
// // namespace: "skipped",
|
||||
// external: true,
|
||||
// };
|
||||
// }
|
||||
// });
|
||||
build.onLoad({ filter: /.*/, namespace: "skipped" }, (args) => {
|
||||
return {
|
||||
contents: `
|
||||
const proxy = new Proxy(() => proxy, {
|
||||
get: () => proxy,
|
||||
construct: () => proxy,
|
||||
});
|
||||
|
||||
export const Database = proxy;
|
||||
export const join = proxy;
|
||||
export const fileURLToPath = proxy;
|
||||
export const arch = proxy;
|
||||
export const platform = proxy;
|
||||
export const statSync = proxy;
|
||||
|
||||
export const $H = proxy;
|
||||
export const _ = proxy;
|
||||
|
||||
export default proxy;
|
||||
`,
|
||||
loader: "js",
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user