one
Version:
One is a new React Framework that makes Vite serve both native and web.
18 lines (17 loc) • 771 B
JavaScript
import * as t from "@babel/types";
var GUARD_SPECIFIERS = ["server-only", "client-only", "native-only", "web-only"],
ALLOWED_IN_NATIVE = ["native-only"];
function environmentGuardBabelPlugin(_) {
return {
name: "one-environment-guard",
visitor: {
ImportDeclaration(path) {
var source = path.node.source.value;
GUARD_SPECIFIERS.includes(source) && (ALLOWED_IN_NATIVE.includes(source) ? path.remove() : path.replaceWith(t.throwStatement(t.newExpression(t.identifier("Error"), [t.stringLiteral(`${source} cannot be imported in a native environment`)]))));
}
}
};
}
var environment_guard_default = environmentGuardBabelPlugin;
export { environment_guard_default as default };
//# sourceMappingURL=environment-guard.native.js.map