Skip to content

Commit

Permalink
fix(expose): update expose switch logic
Browse files Browse the repository at this point in the history
- remove support for obsolete (& broken) snowpack setup
- add support for Vite's env var handling
  • Loading branch information
postspectacular committed Oct 4, 2022
1 parent 781470d commit 9a98c3e
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions packages/expose/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// FIXME https://github.com/snowpackjs/snowpack/issues/3621#issuecomment-907731004
// FIXME https://github.com/snowpackjs/snowpack/issues/3768
/* imports meta.hot method */

declare const __SNOWPACK_ENV__: any;

/**
* Exposes given `value` as `id` in global scope, iff `always = true`
* (default: false) or if `process.env.NODE_ENV != "production"` or if the
* `UMBRELLA_GLOBALS` env var is set to 1.
* Exposes given `value` as `id` in global scope, iff `always = true` (default:
* false) or if `process.env.NODE_ENV != "production"` or if the
* `UMBRELLA_GLOBALS` or `VITE_UMBRELLA_GLOBALS` env var is set to 1.
*
* @param id -
* @param value -
Expand All @@ -23,16 +17,13 @@ export const exposeGlobal = (id: string, value: any, always = false) => {
if (
glob &&
(always ||
(() =>
typeof process !== "undefined" &&
typeof process.env !== "undefined"
? process.env.NODE_ENV !== "production" ||
!!process.env.UMBRELLA_GLOBALS
: typeof __SNOWPACK_ENV__ !== "undefined"
? __SNOWPACK_ENV__.MODE !== "production" ||
!!__SNOWPACK_ENV__.UMBRELLA_GLOBALS ||
!!__SNOWPACK_ENV__.SNOWPACK_PUBLIC_UMBRELLA_GLOBALS
: true)())
(typeof process !== "undefined"
? process.env.NODE_ENV !== "production" ||
!!process.env.UMBRELLA_GLOBALS
: (<any>import.meta).env
? (<any>import.meta).env.MODE !== "production" ||
!!(<any>import.meta).env.VITE_UMBRELLA_GLOBALS
: true))
) {
glob[id] = value;
}
Expand Down

0 comments on commit 9a98c3e

Please sign in to comment.