UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

30 lines (29 loc) 850 B
import * as t from "@babel/types"; const 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) { const 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.js.map