Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codaline-io/parcel-optimizer-replace-envs

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codaline-io/parcel-optimizer-replace-envs - npm Package Compare versions

Comparing version 0.0.1-beta.3 to 0.0.1

2

lib/ReplaceEnvsOptimizer.js

@@ -1,2 +0,2 @@

var e,r,n,o,s,{resolve:p}=require("path"),{Optimizer:c}=require("@parcel/plugin"),{config:t}=require("dotenv");e=module.exports,Object.defineProperty(e,"__esModule",{value:!0,configurable:!0}),r=module.exports,n="default",o=()=>a,Object.defineProperty(r,n,{get:o,set:s,enumerable:!0,configurable:!0});"production"===process.env.NODE_ENV||t({path:process.env.DOTENV_FILE?process.env.DOTENV_FILE:p(process.cwd(),"./.env")});var a=new c({optimize:async({contents:e,map:r})=>(Object.keys(process.env).forEach((r=>{e.indexOf(r)>-1&&(e=(e=e.replace(new RegExp(`process.env.${r}`,"g"),`"${process.env[r]}"`)).replace(new RegExp(`process.env[${r}]`,"g"),`"${process.env[r]}"`))})),{contents:e,map:r})});
var e,r,s,o,n,{resolve:p}=require("path"),{Optimizer:c}=require("@parcel/plugin"),{config:t}=require("dotenv");e=module.exports,Object.defineProperty(e,"__esModule",{value:!0,configurable:!0}),r=module.exports,s="default",o=()=>a,Object.defineProperty(r,s,{get:o,set:n,enumerable:!0,configurable:!0});"production"===process.env.NODE_ENV||t({path:process.env.DOTENV_FILE?process.env.DOTENV_FILE:p(process.cwd(),"./.env")});var a=new c({optimize:async({contents:e,map:r})=>(Object.keys(process.env).forEach((r=>{const s=new RegExp(`process.env.${r}(?!(\\s*=|_|-|\\w|\\d))`,"g"),o=new RegExp(`process.env[${r}](?!(\\s*=|_|-|\\w|\\d))`,"g");(s.test(e)||o.test(e))&&(e=(e=e.replace(s,`"${process.env[r]}"$1`)).replace(o,`"${process.env[r]}"$1`))})),{contents:e,map:r})});
//# sourceMappingURL=ReplaceEnvsOptimizer.js.map
{
"name": "@codaline-io/parcel-optimizer-replace-envs",
"version": "0.0.1-beta.3",
"version": "0.0.1",
"scripts": {

@@ -5,0 +5,0 @@ "build": "parcel build ReplaceEnvsOptimizer.ts --no-cache --dist-dir lib"

@@ -5,1 +5,5 @@ ### Parcel v2 Optimizer to replace `process.env`s

- replaces occurences of `process.env.X` with the value
### How it works
- somehow hacky, because as an optimizer it just uses a dumb regex to replace all `process.env` with its values

@@ -15,7 +15,9 @@ import { resolve } from 'path'

Object.keys(process.env).forEach((ENV_KEY) => {
const containsEnv = contents.indexOf(ENV_KEY) > -1
const namedRegex = new RegExp(`process.env.${ENV_KEY}(?!(\\s*=|_|-|\\w|\\d))`, 'g')
const unnamedRegex = new RegExp(`process.env[${ENV_KEY}](?!(\\s*=|_|-|\\w|\\d))`, 'g')
const containsEnv = namedRegex.test(contents) || unnamedRegex.test(contents)
if (containsEnv) {
contents = contents.replace(new RegExp(`process.env.${ENV_KEY}`, 'g'), `"${process.env[ENV_KEY]}"`)
contents = contents.replace(new RegExp(`process.env[${ENV_KEY}]`, 'g'), `"${process.env[ENV_KEY]}"`)
contents = contents.replace(namedRegex, `"${process.env[ENV_KEY]}"$1`)
contents = contents.replace(unnamedRegex, `"${process.env[ENV_KEY]}"$1`)
}

@@ -22,0 +24,0 @@ })

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc