{"_id":"@backpackjs/netlify-inject-build-env-vars","_rev":"71-e7759e28ec6e9b580bce913d31e067f3","time":{"created":"2022-10-05T20:48:42.334Z","0.0.2":"2021-05-21T15:09:59.846Z","modified":"2023-08-11T21:54:37.708Z","0.0.3":"2021-06-03T07:05:39.472Z","0.0.4":"2021-06-03T07:29:26.225Z","0.0.5":"2021-06-04T21:18:31.150Z","0.0.6":"2021-06-04T22:12:57.218Z","0.0.7":"2021-06-07T20:52:26.970Z","0.0.8":"2021-06-07T22:03:45.793Z","0.0.9":"2021-06-08T00:29:07.136Z","0.0.10":"2021-06-08T00:53:50.069Z","0.0.11":"2021-06-08T23:35:11.074Z","0.0.12":"2021-06-09T03:14:29.431Z","0.0.13":"2021-06-09T03:31:50.423Z","0.0.14":"2021-06-10T08:43:46.715Z","0.0.15":"2021-06-14T22:50:34.308Z","0.0.16":"2021-06-14T23:59:25.232Z","0.0.22":"2021-06-15T19:58:06.110Z","0.0.23":"2021-06-17T19:51:28.105Z","0.0.24":"2021-06-18T00:43:12.736Z","0.0.25":"2021-07-26T23:46:30.523Z","0.0.100":"2021-08-04T23:04:02.689Z","0.0.101":"2021-08-05T02:55:55.085Z","0.0.102":"2021-08-05T18:05:04.704Z","0.0.103":"2021-08-05T18:13:27.022Z","0.0.104":"2021-08-06T00:43:05.869Z","0.0.105":"2021-08-07T14:19:39.092Z","0.0.106":"2021-08-10T10:48:56.109Z","0.0.107":"2021-08-13T10:38:35.636Z","0.0.108":"2021-08-14T10:50:06.995Z","0.0.109":"2021-08-16T15:52:42.931Z","0.0.110":"2021-09-01T19:57:38.586Z","0.0.111":"2021-09-09T11:54:43.521Z","0.0.112":"2021-09-09T12:18:32.506Z","0.0.113":"2021-09-14T22:43:17.545Z","0.1.0":"2021-10-15T00:11:10.452Z","0.1.1":"2021-10-28T23:53:23.580Z","0.1.2":"2021-11-05T22:52:45.457Z","0.1.3":"2022-02-16T03:02:41.733Z","0.1.4":"2022-02-17T03:42:04.217Z","0.1.5":"2022-02-24T00:17:31.956Z","0.1.6":"2022-03-04T22:13:54.010Z","0.1.7":"2022-03-07T22:03:19.393Z","0.1.8":"2022-03-07T23:13:10.995Z","0.1.9":"2022-03-08T00:16:36.412Z","0.1.10":"2022-03-08T18:54:34.946Z","0.1.11":"2022-03-08T19:09:39.942Z","0.1.12":"2022-03-08T19:57:38.530Z","0.2.0":"2022-03-17T01:25:55.745Z","1.0.0":"2022-03-17T04:09:30.434Z","1.1.0":"2022-03-21T09:49:57.201Z","1.1.1":"2022-05-18T22:58:36.602Z","1.1.2":"2022-05-19T23:10:28.083Z","1.1.2-bundle-perf-test.0":"2022-05-20T02:19:10.704Z","1.2.1":"2022-05-24T00:31:11.667Z","1.2.3":"2022-10-05T20:48:42.505Z"},"name":"@backpackjs/netlify-inject-build-env-vars","dist-tags":{"latest":"1.2.3"},"versions":{"1.2.3":{"name":"@backpackjs/netlify-inject-build-env-vars","version":"1.2.3","author":{"name":"@packdigital"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/packdigital/backpackjs-monorepo.git"},"main":"build/index.js","types":"build/index.d.ts","engines":{"node":">=14"},"scripts":{"start":"yarn dev","lint":"eslint src --ext .js,.ts","clean":"rimraf build","compile":"tsc -p tsconfig.json","bundle":"node ../../shared/build-script.js","build":"yarn clean && yarn compile && yarn bundle --minify","dev":"yarn compile && yarn bundle --watch --sourcemap"},"dependencies":{"@backpackjs/constants":"^1.2.4","dotenv":"^8.2.0","node-recursive-directory":"^1.2.0","promise-fs":"^2.1.1","replace-in-file":"^6.2.0"},"gitHead":"5751b07c13b807e6254845c8241648924f8f0bf6","description":"A netlify plugin that injects any build time env vars into all or any specific subset of a nextjs project lambda functions. The env vars replacing/inlining supports both a project build time env vars or netlify own build time env vars.","bugs":{"url":"https://github.com/packdigital/backpackjs-monorepo/issues"},"homepage":"https://github.com/packdigital/backpackjs-monorepo#readme","_id":"@backpackjs/netlify-inject-build-env-vars@1.2.3","_nodeVersion":"16.17.0","_npmVersion":"lerna/4.0.0/node@v16.17.0+arm64 (darwin)","dist":{"integrity":"sha512-yI4Jv2wMno3RMQkT+G2Ofj13iFtf3aT0WuO9bi5FVJQZ43UBe5++NfnBCePR9yZe3tC5w12vwwE04esp0N7l0g==","shasum":"a34def2a2e20274657a01913a2ea66fefb1e3b2c","tarball":"https://registry.npmjs.org/@backpackjs/netlify-inject-build-env-vars/-/netlify-inject-build-env-vars-1.2.3.tgz","fileCount":5,"unpackedSize":11071,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEWxkIYXjKgRerYamNBBjXhYi29pmVdP12v2stMVlxUdAiEA41IUT4Wp1LyTndTIK+BAjkM8PBk0UktIpQEvacr2R/g="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjPe2qACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpGBQ//Yk6M5oUCd2agXYgttGZNaoVFQmYHQv8TOLSxf8sPnSQqEnm5\r\n401lJyPKaBHm7Bz6IS9y/BOaaCUfKCjKJnyQExRSnbkG649H8AK0Asp5m9wz\r\nwAF+gJxK/0c3aDul+HzqlYzK3q37YIgk9Conk8Qz7kp54GlWGMHqA/OotvIW\r\neD4UrcDDvK/MpA8cEgwjMzj2dtCxwPFol3c09uoby3hsjtc94AEv3D6KDBlW\r\nVCeCys1B+OwFsiP/kwm2UxnVC1uqJmOv708hh9yygDyrR7Z2OYxyEYye95lF\r\nYqyYyd+my3W98qf7gtIXfRzBcg93dusnJXaSRWsGfKbfHjuzTNMuCbOevNwv\r\nL3RHSpmCn93gc4PuqmzlFLhMgz8LyDXwvV7cSpoCee9y3Uti8hO2yEbxZzpO\r\n+fKFfeFDfkTqpwoxNoKndHYRYvvLDYWurDACjH8gvV9O45+/17sdIlLZA4X+\r\n06L1qrUcLzw3w3IbPDFagfjVVdMLIfwA5BpRXyQk6RxxUN/lczyq3fF7iwUQ\r\nnKgQ+7WF/2kK0nUZ+qysWwumwVc01iDyJdJWvvLWwm/pk8oBwgfX3RABkBzn\r\n3NNo9GnvmFYlLJo5BGFPUPwpO7eZY55/ayFaXeUrVFgl8t55bb09QqYddGmf\r\nCwE/fohwd1HrVqpinBrVrl3DhfV2K4PxMEM=\r\n=91YG\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"tshamz","email":"tyler@packdigital.com"},"directories":{},"maintainers":[{"name":"eli-nessa","email":"eli@nessalab.com"},{"name":"jonathan-monroe","email":"jonathan.monroe@pyyne.com"},{"name":"thiagovilla","email":"thiagovilla89@gmail.com"},{"name":"jasonredick","email":"jason.redick@me.com"},{"name":"sg-packdigital","email":"shymmy.garcia@packdigital.com"},{"name":"corycummings","email":"cory@packdigital.com"},{"name":"aaronescalona","email":"aaron.escalona@packdigital.com"},{"name":"tshamz","email":"tyler@packdigital.com"},{"name":"jeremyagabriel","email":"jeremyagabriel@gmail.com"},{"name":"anguy95","email":"anguy95@gmail.com"},{"name":"andee.isaacs","email":"andee.isaacs@packdigital.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/netlify-inject-build-env-vars_1.2.3_1665002922335_0.2539903672824082"},"_hasShrinkwrap":false}},"maintainers":[{"email":"eli@nessalab.com","name":"eli-nessa"},{"email":"thiagovilla89@gmail.com","name":"thiagovilla"},{"email":"jason.redick@me.com","name":"jasonredick"},{"email":"shymmy.garcia@packdigital.com","name":"sg-packdigital"},{"email":"cory@packdigital.com","name":"corycummings"},{"email":"aaron.escalona@packdigital.com","name":"aaronescalona"},{"email":"tyler@packdigital.com","name":"tshamz"},{"email":"jeremyagabriel@gmail.com","name":"jeremyagabriel"},{"email":"anguy95@gmail.com","name":"anguy95"}],"description":"A netlify plugin that injects any build time env vars into all or any specific subset of a nextjs project lambda functions. The env vars replacing/inlining supports both a project build time env vars or netlify own build time env vars.","homepage":"https://github.com/packdigital/backpackjs-monorepo#readme","repository":{"type":"git","url":"git+https://github.com/packdigital/backpackjs-monorepo.git"},"author":{"name":"@packdigital"},"bugs":{"url":"https://github.com/packdigital/backpackjs-monorepo/issues"},"license":"MIT","readme":"# netlify-inject-build-env-vars\n\nA netlify plugin that injects any build time env vars into all or any specific subset of a nextjs project lambda functions. The env vars replacing/inlining supports both a project build time env vars or netlify own build time env vars.\n\n## Example\n`my-function.js`\n```js\n  if (process.env.BRANCH === 'main') {\n    ...\n  }\n```\n\nwill be transformed to...\n`my-function.js`\n```js\n  if('main' === 'main) {...}\n```\n\n---\nNetlify en vars include:\n- [config](https://docs.netlify.com/configure-builds/environment-variables/)\n- [context](https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables)\n- [build-metadata](https://docs.netlify.com/configure-builds/environment-variables/#build-metadata)\n- [git-metadata](https://docs.netlify.com/configure-builds/environment-variables/#git-metadata)\n- [deploy-metadata](https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata) env vars\n\n---\n\nThis project started as a fork of `netlify-plugin-inline-functions-env`. So, credits to Ben\n\n----\n## netlify-plugin-inline-functions-env [Readme]\n[![npm version](https://badge.fury.io/js/netlify-plugin-inline-functions-env.svg)](https://badge.fury.io/js/netlify-plugin-inline-functions-env)\n\n[![test status](https://github.com/bencao/netlify-plugin-inline-functions-env/workflows/UnitTest/badge.svg)](https://github.com/bencao/netlify-plugin-inline-functions-env/actions)\n\nInline process.env.X in netlify functions with netlify build time environment variables.\n\n## Why\n\nWhen we talk about environment variable values for a netlify function, it is important to understand that there're two possible context.\n\n**Build time**\n\nThis is when netlify builds your site. The following environment variables would be available at build time:\n\n- Environment Variables you set at Netlify UI\n- [Readonly Environment Variables](https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables) set by Netlify including build/git metadata\n- [Deploy Context Environment Variables](https://docs.netlify.com/configure-builds/file-based-configuration/#deploy-contexts) you set in `netlify.toml` within `[context.xxx.environment]` section\n- Environment Variables set by other Netlify build plugins such as [contextual env plugin](https://github.com/cball/netlify-plugin-contextual-env#readme)\n\n**Runtime**\n\nThis is when your function code is evaluated when a request was received. The following environment variables would be available at runtime:\n\n- Environment Variables you set at Netlify UI\n\n**Problem**\n\nYou may have noticed that the available environment variables at Runtime is only a subset of that in build time.\n\nThat is a common source of confusion for many people, see discussions over [here](https://community.netlify.com/t/support-guide-using-environment-variables-on-netlify-correctly/267).\n\nThis plugin was built to mitigate this issue by inlining the build time environment variable values as part of your code, so that you can consider build time environment variables magically become available for runtime!\n\nWith the original function source file\n\n```\nfunction handler(event, context) {\n  return {\n    statusCode: 200,\n    body: JSON.stringify({\n      CONTEXT: process.env.CONTEXT\n    })\n  };\n};\n\nmodule.exports = { handler };\n```\n\nThe plugin will produce the inlined function source file\n\n```\nfunction handler(event, context) {\n  return {\n    statusCode: 200,\n    body: JSON.stringify({\n      CONTEXT: \"deploy-preview\"    <---------- replaced with build time env var values\n    })\n  };\n};\n\nmodule.exports = { handler };\n```\n\n**Caveats**\n\nThe plugin wouldn't replace more dynamic code like the following ones\n\n```\nconsole.log(process.env);          <-------- no concrete values, won't be replaced with an object\n\nfunction getKey(key) {\n  return process.env[key];         <-------- rely on runtime value so won't be replaced\n}\n```\n\nSo you may have to intentionlly convert the above code into something like `process.env.X` so it will be inlined.\n\n## Install\n\nTo install, add the following lines to your `netlify.toml` file:\n\n```toml\n[[plugins]]\npackage = \"netlify-plugin-inline-functions-env\"\n```\n\n## More Options\n\n### Debugging\n\nYou can turn on verbose for debugging purpose by providing plugin inputs.\n\n```toml\n[[plugins]]\npackage = \"netlify-plugin-inline-functions-env\"\n  [plugins.inputs]\n  verbose = \"true\"\n```\n\n> Be careful with verbose mode, as it will print the files with the replaced env variables\n\n### Configuring build event\n\nIf you are using TypeScript, or processing your code in other ways you may want to choose `onBuild`\n\n```toml\n[[plugins]]\npackage = \"netlify-plugin-inline-functions-env\"\n  [plugins.inputs]\n  buildEvent = \"onBuild\"\n```\n\nDefault value is `onPreBuild`. It's also been tested to work with `onBuild`\nThe values for buildEvent can be found [here](https://docs.netlify.com/configure-builds/build-plugins/create-plugins/#plug-in-to-build-events)\n\n### Conditional Transformation\n\nIf you are using libraries such as [dotenv-defaults](https://github.com/mrsteele/dotenv-defaults), you may want to limit or skip the transformation for certain environment variables.\n\n```toml\n[[plugins]]\npackage = \"netlify-plugin-inline-functions-env\"\n  [plugins.inputs]\n  exclude = [\"DO_NOT_TRANSFORM_ME\", \"DO_NOT_TRANSFORM_ME_2\"]\n```\n\n```toml\n[[plugins]]\npackage = \"netlify-plugin-inline-functions-env\"\n  [plugins.inputs]\n  include = [\"ONLY_TRANSFORM_ME\", \"ONLY_TRANSFORM_ME_2\"]\n```\n\n## Gotchas\n\n1. The `[[plugins]]` line is required for each plugin, even if you have other plugins in your `netlify.toml` file already.\n\n2. This plugin only replaces variables in the functions directory. Files outside the directory won't be modified.\n\n3. Also please add `netlify-plugin-inline-functions-env` to your dev dependencies by `yarn install --dev netlify-plugin-inline-functions-env` or `npm install --save-dev netlify-plugin-inline-functions-env`.\n","readmeFilename":"README.md"}