Skip to content

Commit e030beb

Browse files
author
Ernest
committed
feat: separate packages
1 parent b728991 commit e030beb

File tree

320 files changed

+497
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+497
-612
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ jobs:
3232
- name: Install deps
3333
run: pnpm i
3434

35-
- name: Test @import-meta-env/vite
36-
run: pnpm run test --parallel --stream --filter @import-meta-env/vite
35+
- name: Test
36+
run: pnpm run test --parallel --stream --filter @import-meta-env/*
3737

38-
- name: Build @import-meta-env/vite
39-
run: pnpm run build --parallel --stream --filter @import-meta-env/vite
40-
41-
- name: Build @import-meta-env/babel
42-
run: pnpm run build --parallel --stream --filter @import-meta-env/babel
38+
- name: Build
39+
run: pnpm run build --parallel --stream --filter @import-meta-env/*
4340

4441
- name: Install binary
4542
run: pnpm i
@@ -49,21 +46,18 @@ jobs:
4946
pnpm \
5047
--parallel \
5148
--stream \
52-
--filter \!html \
53-
--filter \!@import-meta-env/vite \
54-
--filter \!@import-meta-env/babel \
55-
--filter \!vue-ts \
56-
--filter \!vue-jsx \
49+
--filter *-example \
50+
--filter \!vite-html-example \
51+
--filter \!vite-vue-* \
5752
exec sh test.sh
5853
59-
- name: Build&Test examples/vue-*
54+
- name: Build&Test examples/vite-vue-*
6055
if: ${{ matrix.node_version >= '14' }}
6156
run: |
6257
pnpm \
6358
--parallel \
6459
--stream \
65-
--filter vue-ts \
66-
--filter vue-jsx \
60+
--filter vite-vue* \
6761
exec sh test.sh
6862
6963
compatibility:
@@ -80,6 +74,7 @@ jobs:
8074
- os: windows-latest
8175
node_version: lts/*
8276
dotenv_version: latest
77+
fail-fast: false
8378
name: "compatibility: ${{ matrix.os }}, dotenv@${{ matrix.dotenv_version }}, node@${{ matrix.node_version }}"
8479
steps:
8580
- name: Checkout
@@ -96,24 +91,23 @@ jobs:
9691
node-version: ${{ matrix.node_version }}
9792
cache: "pnpm"
9893

99-
- name: Install deps
94+
- name: Install package
10095
run: |
10196
pnpm i
102-
pnpm --parallel --stream --filter @import-meta-env/vite exec pnpm rm dotenv
103-
pnpm i -W -D dotenv@${{ matrix.dotenv_version }}
97+
pnpm --parallel --stream --filter @import-meta-env/* exec pnpm rm dotenv
98+
pnpm --parallel --stream --filter @import-meta-env/* exec pnpm i --save-peer dotenv@${{ matrix.dotenv_version }}
10499
105-
- name: Test @import-meta-env/vite
106-
run: pnpm run test --parallel --stream --filter @import-meta-env/vite
100+
- name: Test package
101+
run: pnpm run test --parallel --stream --filter @import-meta-env/*
107102

108-
- name: Build @import-meta-env/vite
109-
run: pnpm run build --parallel --stream --filter @import-meta-env/vite
103+
- name: Build package
104+
run: pnpm run build --parallel --stream --filter @import-meta-env/*
110105

111106
- name: Install binary
112-
run: pnpm i
107+
run: pnpm i --no-frozen-lockfile
113108

114109
- name: Test example
115-
run: |
116-
pnpm run test --parallel --stream --filter html
110+
run: pnpm run test --parallel --stream --filter vite-html-example
117111

118112
lint:
119113
runs-on: ubuntu-latest

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ dist
44
__dist__
55
pnpm-lock.yaml
66

7-
packages/vite/examples/config-build-out-dir/custom-out-dir
7+
packages/examples/vite-config-build-out-dir-example/custom-out-dir

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
| Package | Version (click for changelogs) | Description |
1313
| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14+
| [@import-meta-env/cli](./packages/cli#readme) | [![@import-meta-env/cli version](https://img.shields.io/npm/v/@import-meta-env/cli.svg)](./packages/cli/CHANGELOG.md) | A binary package is used to inject environment variables into those placeholders. |
1415
| [@import-meta-env/vite](./packages/vite#readme) | [![@import-meta-env/vite version](https://img.shields.io/npm/v/@import-meta-env/vite.svg)](./packages/vite/CHANGELOG.md) | Inject environment variables into the `import.meta.env` object **_after_** building the application instead of statically replacing it during production. |
1516
| [@import-meta-env/babel](./packages/babel#readme) | [![@import-meta-env/babel version](https://img.shields.io/npm/v/@import-meta-env/babel.svg)](./packages/babel/CHANGELOG.md) | Provide an approximation of some of [@import-meta-env/vite](https://github.com/iendeavor/import-meta-env/tree/develop/packages/vite) specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner. |
1617

packages/babel/examples/mocha/babel.config.js renamed to babel.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ module.exports = {
33
["@babel/preset-env", { targets: { node: "current" } }],
44
"@babel/preset-typescript",
55
],
6-
plugins: ["module:@import-meta-env/babel"],
76
};

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"prettier": "^2.5.1"
4+
"@babel/core": "^7.17.5",
5+
"@babel/preset-env": "^7.16.11",
6+
"@babel/preset-typescript": "^7.16.7",
7+
"@types/jest": "^27.4.0",
8+
"@types/node": "^17.0.8",
9+
"@types/tmp": "^0.2.3",
10+
"babel-jest": "^27.5.1",
11+
"esbuild": "^0.14.23",
12+
"jest": "^27.5.1",
13+
"picocolors": "^1.0.0",
14+
"prettier": "^2.5.1",
15+
"rimraf": "^3.0.2",
16+
"standard-version": "^9.3.2",
17+
"tmp": "^0.2.1",
18+
"typescript": "^4.5.4"
519
}
620
}

packages/babel/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Ernest
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/babel/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
[![NPM version](https://img.shields.io/npm/v/@import-meta-env/babel.svg)](https://www.npmjs.com/package/@import-meta-env/babel)
55
[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
66

7-
This plugin is intended to provide an approximation of some of [@import-meta-env/vite](https://github.com/iendeavor/import-meta-env/tree/develop/packages/vite) specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner.
7+
This plugin is intended to provide an approximation of some of [import-meta-env](https://github.com/iendeavor/import-meta-env) specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner.
88

99
⚠ The functionality within these transformations should not be relied upon in production.
1010

11+
<br>
12+
13+
This project use [SemVer](https://semver.org/) for versioning. For the versions available, see the tags on this repository.
14+
1115
## 🚀 Quick Start
1216

1317
Install and register the plugin:
1418

1519
```sh
16-
$ npm i dotenv @import-meta-env/babel
20+
$ npm i @import-meta-env/babel
1721
```
1822

1923
```js
@@ -23,20 +27,25 @@ module.exports = {
2327
};
2428
```
2529

26-
Adjust the test script in your package.json:
30+
Adjust scripts in your package.json or elsewhere:
2731

2832
```json
2933
{
3034
"scripts": {
3135
// If you have a `.env` file:
32-
"test": "your-test-script",
36+
"foo": "foo",
3337
// If you don't have a `.env` file:
34-
"test": "cross-env S3_BUCKET=YOURS3BUCKET your-test-script"
38+
"foo": "cross-env S3_BUCKET=YOURS3BUCKET foo"
3539
}
3640
}
3741
```
3842

3943
See also:
4044

4145
- [examples](./examples)
46+
- [@import-meta-env/cli](https://github.com/iendeavor/import-meta-env/tree/main/packages/cli) - A binary package is used to inject environment variables into those placeholders.
4247
- [@import-meta-env/vite](https://github.com/iendeavor/import-meta-env/tree/main/packages/vite) - Inject environment variables into the import.meta.env object after building the application instead of statically replacing it during production.
48+
49+
## 📝 License
50+
51+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details

packages/babel/package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"scripts": {
1212
"build": "rimraf dist bin && pnpm build-bundle",
1313
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:vite --external:dotenv --outfile=dist/index.js",
14-
"release": "standard-version -t babel --releaseCommitMessageFormat 'chore(release): @import-meta-env/babel@{{currentTag}}' --path . && pnpm build"
14+
"release": "standard-version -t babel --releaseCommitMessageFormat 'chore(release): @import-meta-env/babel@{{currentTag}}' --path . && pnpm build",
15+
"test": "echo \"no test\""
1516
},
1617
"repository": {
1718
"type": "git",
@@ -23,16 +24,12 @@
2324
},
2425
"homepage": "https://github.com/iendeavor/import-meta-env/tree/main/packages/babel#readme",
2526
"devDependencies": {
26-
"@babel/core": "^7.17.5",
27-
"dotenv": "^11.0.0 || ^12.0.4 || ^13.0.1 || ^14.3.2 || ^15.0.1 || ^16.0.0",
28-
"esbuild": "^0.14.11",
29-
"rimraf": "^3.0.2",
30-
"standard-version": "^9.3.2",
31-
"typescript": "^4.5.4",
32-
"vite": "^2.7.13"
27+
"dotenv": "^11.0.0 || ^12.0.4 || ^13.0.1 || ^14.3.2 || ^15.0.1 || ^16.0.0"
3328
},
3429
"peerDependencies": {
35-
"dotenv": "^11.0.0 || ^12.0.4 || ^13.0.1 || ^14.3.2 || ^15.0.1 || ^16.0.0",
36-
"vite": "^2.7.13"
30+
"dotenv": "^11.0.0 || ^12.0.4 || ^13.0.1 || ^14.3.2 || ^15.0.1 || ^16.0.0"
31+
},
32+
"dependencies": {
33+
"picocolors": "^1.0.0"
3734
}
3835
}

packages/babel/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type babelCore from "@babel/core";
2-
import { resolve } from "../../vite/src/env";
3-
import { envFilePath, envExampleFilePath } from "../../vite/src/shared";
2+
import { resolve, envFilePath, envExampleFilePath } from "../../shared";
43

54
export default function importMetaEnvBabelPlugin({
65
template,

packages/babel/tsconfig.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
{
22
"include": ["src"],
3-
"exclude": ["**/*.test.ts"],
4-
"compilerOptions": {
5-
"outDir": "dist",
6-
"target": "esnext",
7-
"module": "commonjs",
8-
"moduleResolution": "node",
9-
"strict": true,
10-
"declaration": true,
11-
"sourceMap": true,
12-
"noImplicitOverride": true,
13-
"noUnusedLocals": true,
14-
"esModuleInterop": true,
15-
"resolveJsonModule": true,
16-
"baseUrl": "."
17-
}
3+
"extends": "../../tsconfig.json"
184
}

packages/cli/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Ernest
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/cli/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# @import-meta-env/cli
2+
3+
[![CI](https://github.com/iendeavor/import-meta-env/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/iendeavor/import-meta-env/actions/workflows/ci.yml)
4+
[![NPM version](https://img.shields.io/npm/v/@import-meta-env/cli.svg)](https://www.npmjs.com/package/@import-meta-env/cli)
5+
[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6+
7+
[Our plugin](https://github.com/iendeavor/import-meta-env#packages) generates chunks with placeholders during production, which allow us to statically replace environment variables **_after_** building the application, and this binary package is used to inject environment variables into these placeholders.
8+
9+
<br>
10+
11+
This project use [SemVer](https://semver.org/) for versioning. For the versions available, see the tags on this repository.
12+
13+
## 🚀 Quick Start
14+
15+
Install package:
16+
17+
```sh
18+
$ npm i @import-meta-env/cli
19+
```
20+
21+
You can now execute `import-meta-env` binary to inject environment variables.
22+
23+
```sh
24+
$ npx import-meta-env
25+
```
26+
27+
Tip: to deploy container with docker or others, you can use [pkg](https://github.com/vercel/pkg) to create a standalone executable.
28+
29+
For example, you can pack the alpine version like this:
30+
31+
```sh
32+
$ npm i -g pkg
33+
$ npx pkg ./node_modules/@import-meta-env/cli/bin/import-meta-env.js -t node16-alpine
34+
```
35+
36+
See also:
37+
38+
- [examples](https://github.com/iendeavor/import-meta-env/tree/main/packages/examples)
39+
- [@import-meta-env/babel](https://github.com/iendeavor/import-meta-env/tree/main/packages/babel) - Provide an approximation of this plugin's specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner.
40+
- [@import-meta-env/vite](https://github.com/iendeavor/import-meta-env/tree/main/packages/vite) - Inject environment variables into the import.meta.env object after building the application instead of statically replacing it during production.
41+
42+
## 📖 API
43+
44+
```sh
45+
$ npx import-meta-env --help
46+
Usage: import-meta-env [options]
47+
48+
Inject environment variables from the system or `.env` file.
49+
50+
Options:
51+
-V, --version output the version number
52+
-e, --env <path> The .env file path to load (default: ".env")
53+
-x, --example <path> The .env example file path to load (default: ".env.example")
54+
-o, --output <path...> The output file paths to inject in-place (default: "dist/assets/import-meta-env*")
55+
-h, --help display help for command
56+
```
57+
58+
Since we may switch to different environment variables multiple times, this executable also creates `*.bak` files to restore.
59+
60+
## 📝 License
61+
62+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details

packages/cli/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("../../babel.config");

packages/cli/package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@import-meta-env/cli",
3+
"version": "0.1.0",
4+
"description": "Load environment variables into import.meta.env object",
5+
"license": "MIT",
6+
"author": "Ernest",
7+
"keywords": [
8+
"twelve-factor",
9+
"dotenv"
10+
],
11+
"bin": {
12+
"import-meta-env": "bin/import-meta-env.js"
13+
},
14+
"files": [
15+
"bin"
16+
],
17+
"scripts": {
18+
"build": "rimraf bin && pnpm build-cli",
19+
"build-cli": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:dotenv --outfile=bin/import-meta-env.js",
20+
"release": "standard-version -t cli --releaseCommitMessageFormat 'chore(release): @import-meta-env/cli@{{currentTag}}' --path . && pnpm build",
21+
"test": "jest src/__tests__"
22+
},
23+
"engines": {
24+
"node": "^12.20.0 || >= 14"
25+
},
26+
"repository": {
27+
"type": "git",
28+
"url": "git+https://github.com/iendeavor/import-meta-env.git",
29+
"directory": "packages/cli"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/iendeavor/import-meta-env/issues"
33+
},
34+
"homepage": "https://github.com/iendeavor/import-meta-env/tree/main/packages/cli#readme",
35+
"devDependencies": {
36+
"@types/glob": "^7.2.0",
37+
"dotenv": "^11.0.0 || ^12.0.4 || ^13.0.1 || ^14.3.2 || ^15.0.1 || ^16.0.0"
38+
},
39+
"peerDependencies": {
40+
"dotenv": "^11.0.0 || ^12.0.4 || ^13.0.1 || ^14.3.2 || ^15.0.1 || ^16.0.0"
41+
},
42+
"dependencies": {
43+
"commander": "^9.0.0",
44+
"glob": "^7.2.0",
45+
"picocolors": "^1.0.0"
46+
}
47+
}

0 commit comments

Comments
 (0)