one
Version:
One is a React framework for web, iOS, and Android apps.
28 lines (25 loc) • 792 B
JavaScript
import * as t from "@babel/types";
const GUARD_SPECIFIERS = [
"server-only",
"client-only",
"native-only",
"web-only"
];
const ALLOWED_IN_NATIVE = ["native-only"];
function environmentGuardBabelPlugin(_) {
return {
name: "one-environment-guard",
visitor: { ImportDeclaration(path) {
const source = path.node.source.value;
if (!GUARD_SPECIFIERS.includes(source)) return;
if (ALLOWED_IN_NATIVE.includes(source)) {
path.remove();
} else {
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.mjs.map