Sha256: 173f4ca8701faff405d7f7c26a9fbdb5b18a1119552a229032b51e576790bff9

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

import setup from './setup_plugin.js'

// Export environment variables as named exports only. You can also import from `env:ENV_VAR_NAME`,
// which will return the value of the environment variable as the default export. This allows you to
// safely import a variable regardless of its existence.
export default setup('env', () => {
  return [
    {
      type: 'onResolve',
      filter: /^env(:.+)?$/,
      callback({ path }) {
        return { path, namespace: 'env' }
      }
    },

    {
      type: 'onLoad',
      filter: /.*/,
      namespace: 'env',
      callback({ path }) {
        if (path.includes(':')) {
          return {
            loader: 'js',
            contents: `export default ${Deno.env.get(path.split(':')[1])}`
          }
        }

        const env = Deno.env.toObject()
        const contents = []

        for (const key in env) {
          if (Object.hasOwnProperty.call(env, key)) {
            contents.push(`export const ${key} = '${env[key]}'`)
          }
        }

        return {
          loader: 'js',
          contents: contents.join(';')
        }
      }
    }
  ]
})

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proscenium-0.4.0-arm64-darwin lib/proscenium/compilers/esbuild/env_plugin.js
proscenium-0.4.0-x86_64-darwin lib/proscenium/compilers/esbuild/env_plugin.js
proscenium-0.4.0-x86_64-linux lib/proscenium/compilers/esbuild/env_plugin.js