Skip to content

Commit

Permalink
feat: migrate from VITE_ to PUBLIC_
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiderDan98 committed Jun 7, 2024
1 parent 1d2192d commit 6e9b1bb
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 122 deletions.
54 changes: 5 additions & 49 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
name: validate
on:
push:
branches:
- 'main'
- 'beta'
- 'alpha'
- '!all-contributors/**'
pull_request: {}
jobs:
main:
# ignore all-contributors PRs
if: ${{ !contains(github.head_ref, 'all-contributors') }}
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: ⬇️ Checkout repo
uses: actions/checkout@v2

- name: ⎔ Setup node
uses: actions/setup-node@v1
with:
node-version: 20

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false
env:
HUSKY_SKIP_INSTALL: true

- name: ▶️ Run validate script
run: npm run validate

- name: ⬆️ Upload coverage report
uses: codecov/codecov-action@v1
on:
release:
types: [published]

jobs:
release:
needs: main
runs-on: ubuntu-latest
if:
${{ github.repository == 'OpenSourceRaidGuild/babel-vite' &&
contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha', github.ref) &&
github.event_name == 'push' }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: ⬇️ Checkout repo
uses: actions/checkout@v2

Expand All @@ -74,4 +30,4 @@ jobs:
run: npx multi-semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions packages/babel-plugin-transform-vite-meta-env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const baseUrl = import.meta.env.BASE_URL;
const nodeEnv = import.meta.env.NODE_ENV;
const dev = import.meta.env.DEV;
const prod = import.meta.env.PROD;
const viteVar = import.meta.env.VITE_VAR;
const viteVar = import.meta.env.PUBLIC_VAR;
const other = import.meta.env.OTHER;
const env = import.meta.env;
```
Expand All @@ -45,17 +45,17 @@ const baseUrl = '/';
const nodeEnv = process.env.NODE_ENV || 'test';
const dev = process.env.NODE_ENV !== 'production';
const prod = process.env.NODE_ENV === 'production';
const viteVar = process.env.VITE_VAR;
const viteVar = process.env.PUBLIC_VAR;
const other = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
DEV: process.env.NODE_ENV !== 'production',
PROD: process.env.NODE_ENV === 'production'
}.OTHER;
const env = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
Expand Down
10 changes: 1 addition & 9 deletions packages/babel-plugin-transform-vite-meta-env/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "babel-plugin-transform-vite-meta-env",
"name": "@fond-of/babel-plugin-transform-vite-meta-env",
"version": "0.0.0-semantically-released",
"description": "babel plugin that emulates vite's import.meta.env functionality",
"main": "lib/index.js",
Expand All @@ -8,10 +8,6 @@
"lib",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/OpenSourceRaidGuild/babel-vite.git"
},
"keywords": [
"babel",
"vite",
Expand All @@ -22,10 +18,6 @@
],
"author": "Michael Peyper <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenSourceRaidGuild/babel-vite/issues"
},
"homepage": "https://github.com/OpenSourceRaidGuild/babel-vite#readme",
"scripts": {
"build": "kcd-scripts build --out-dir lib",
"test": "kcd-scripts test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const x = import.meta.env.OTHER
↓ ↓ ↓ ↓ ↓ ↓
const x = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
Expand Down Expand Up @@ -106,13 +106,13 @@ const x = process.env.NODE_ENV === 'production'
`;

exports[`vite-meta-env replace VITE_* variables: replace VITE_* variables 1`] = `
exports[`vite-meta-env replace PUBLIC_* variables: replace PUBLIC_* variables 1`] = `
const x = import.meta.env.VITE_VAR
const x = import.meta.env.PUBLIC_VAR
↓ ↓ ↓ ↓ ↓ ↓
const x = process.env.VITE_VAR
const x = process.env.PUBLIC_VAR
`;
Expand All @@ -124,7 +124,7 @@ const env = import.meta.env
↓ ↓ ↓ ↓ ↓ ↓
const env = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
Expand All @@ -137,13 +137,13 @@ const env = {

exports[`vite-meta-env replace key access: replace key access 1`] = `
const key = "VITE_VAR"; const x = import.meta.env[key]
const key = "PUBLIC_VAR"; const x = import.meta.env[key]
↓ ↓ ↓ ↓ ↓ ↓
const key = 'VITE_VAR'
const key = 'PUBLIC_VAR'
const x = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
Expand All @@ -156,18 +156,18 @@ const x = {

exports[`vite-meta-env replace string access: replace string access 1`] = `
const x = import.meta.env["VITE_VAR"]
const x = import.meta.env["PUBLIC_VAR"]
↓ ↓ ↓ ↓ ↓ ↓
const x = {
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
DEV: process.env.NODE_ENV !== 'production',
PROD: process.env.NODE_ENV === 'production'
}['VITE_VAR']
}['PUBLIC_VAR']
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pluginTester({
'replace NODE_ENV': 'const x = import.meta.env.NODE_ENV',
'replace DEV': 'const x = import.meta.env.DEV',
'replace PROD': 'const x = import.meta.env.PROD',
'replace VITE_* variables': 'const x = import.meta.env.VITE_VAR',
'replace string access': 'const x = import.meta.env["VITE_VAR"]',
'replace key access': 'const key = "VITE_VAR"; const x = import.meta.env[key]',
'replace PUBLIC_* variables': 'const x = import.meta.env.PUBLIC_VAR',
'replace string access': 'const x = import.meta.env["PUBLIC_VAR"]',
'replace key access': 'const key = "PUBLIC_VAR"; const x = import.meta.env[key]',
'replace env object': 'const env = import.meta.env',
'not replaceable': 'const x = import.meta.env.OTHER',
'not import.meta.env': 'const x = import.meta.other',
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-vite-meta-env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type babelCore from '@babel/core'

const replaceVars = [
{
regex: /^VITE_/,
regex: /^PUBLIC_/,
replacement: (template: typeof babelCore.template, variableName: string) =>
template.expression('process.env.%%variableName%%')({ variableName })
},
Expand All @@ -29,7 +29,7 @@ const replaceVars = [

const replaceEnv = (template: typeof babelCore.template) =>
template.expression.ast(`{
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^VITE_/.test(k))),
...Object.fromEntries(Object.entries(process.env).filter(([k]) => /^PUBLIC_/.test(k))),
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
Expand Down
10 changes: 1 addition & 9 deletions packages/babel-plugin-transform-vite-meta-glob/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "babel-plugin-transform-vite-meta-glob",
"name": "@fond-of/babel-plugin-transform-vite-meta-glob",
"version": "0.0.0-semantically-released",
"description": "babel plugin that emulates vite's import.meta.glob import.meta.globEager functionality",
"main": "lib/index.js",
Expand All @@ -8,10 +8,6 @@
"lib",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/OpenSourceRaidGuild/babel-vite.git"
},
"keywords": [
"babel",
"vite",
Expand All @@ -23,10 +19,6 @@
],
"author": "Michael Peyper <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenSourceRaidGuild/babel-vite/issues"
},
"homepage": "https://github.com/OpenSourceRaidGuild/babel-vite#readme",
"scripts": {
"build": "kcd-scripts build --out-dir lib",
"test": "kcd-scripts test"
Expand Down
10 changes: 1 addition & 9 deletions packages/babel-plugin-transform-vite-meta-hot/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "babel-plugin-transform-vite-meta-hot",
"name": "@fond-of/babel-plugin-transform-vite-meta-hot",
"version": "0.0.0-semantically-released",
"description": "babel plugin that emulates vite's import.meta.hot functionality",
"main": "lib/index.js",
Expand All @@ -8,10 +8,6 @@
"lib",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/OpenSourceRaidGuild/babel-vite.git"
},
"keywords": [
"babel",
"vite",
Expand All @@ -22,10 +18,6 @@
],
"author": "Kelvin Zhang <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenSourceRaidGuild/babel-vite/issues"
},
"homepage": "https://github.com/OpenSourceRaidGuild/babel-vite#readme",
"scripts": {
"build": "kcd-scripts build --out-dir lib",
"test": "kcd-scripts test"
Expand Down
16 changes: 4 additions & 12 deletions packages/babel-preset-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "babel-preset-vite",
"name": "@fond-of/babel-preset-vite",
"version": "0.0.0-semantically-released",
"description": "babel preset that emulates vite's non-standard functionality",
"main": "lib/index.js",
Expand All @@ -8,10 +8,6 @@
"lib",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/OpenSourceRaidGuild/babel-vite.git"
},
"keywords": [
"babel",
"vite",
Expand All @@ -22,10 +18,6 @@
],
"author": "Michael Peyper <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenSourceRaidGuild/babel-vite/issues"
},
"homepage": "https://github.com/OpenSourceRaidGuild/babel-vite#readme",
"scripts": {
"build": "kcd-scripts build --out-dir lib",
"test": "kcd-scripts test"
Expand All @@ -40,8 +32,8 @@
"dependencies": {
"@babel/runtime": "^7.13.9",
"@types/babel__core": "^7.1.12",
"babel-plugin-transform-vite-meta-env": "^0.0.0-semantically-released",
"babel-plugin-transform-vite-meta-glob": "^0.0.0-semantically-released",
"babel-plugin-transform-vite-meta-hot": "^0.0.0-semantically-released"
"@fond-of/babel-plugin-transform-vite-meta-env": "^0.0.0-semantically-released",
"@fond-of/babel-plugin-transform-vite-meta-glob": "^0.0.0-semantically-released",
"@fond-of/babel-plugin-transform-vite-meta-hot": "^0.0.0-semantically-released"
}
}
Loading

0 comments on commit 6e9b1bb

Please sign in to comment.