Skip to content

Commit

Permalink
feat: load .env as cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron committed Oct 28, 2024
1 parent 3cf1a73 commit d86db8e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"devDependencies": {
"@babel/core": "^7.23.2",
"@biomejs/biome": "1.6.1",
"@biomejs/biome": "1.6.2",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@fuels/ts-config": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import baseDefaultConfig from '@fuel-ui/test-utils/config';
import type { JestConfigWithTsJest } from 'ts-jest';
import { defaultsESM as tsjPreset } from 'ts-jest/presets';

import { getPublicEnvs } from './load.envs';
import { getPublicEnvs } from './load.envs.cts';
import pkg from './package.json';

const { globals, preset, ...baseConfig } = baseDefaultConfig;
Expand Down
6 changes: 4 additions & 2 deletions packages/app/load.envs.js → packages/app/load.envs.cts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getEnvName() {
});
});

export function getPublicEnvs() {
function getPublicEnvs() {
const WHITELIST = ['NODE_ENV', 'PUBLIC_URL'];
return Object.fromEntries(
Object.entries(process.env).filter(([key]) =>
Expand All @@ -39,6 +39,8 @@ export function getPublicEnvs() {
// Export the version to be used on database
// and application level
const versions = getVersion();
process.env.PORT = 3000;
process.env.PORT = '3000';
process.env.VITE_APP_VERSION = process.env.VITE_APP_VERSION || versions.version;
process.env.VITE_DATABASE_VERSION = versions.database;

module.exports.getPublicEnvs = getPublicEnvs;
2 changes: 1 addition & 1 deletion packages/app/manifest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineManifest } from '@crxjs/vite-plugin';

import './load.envs.js';
import './load.envs.cts';

// When releasing a stable version we need to inform for the build
// to use the white logo instead of the black one
Expand Down
5 changes: 3 additions & 2 deletions packages/app/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"outDir": "dist-crx"
},
"include": [
"load.envs.js",
"load.envs.cts",
"./src/exports.ts",
"env.d.ts",
"playwright/**/*.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/vite-utils/vite.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cleanPlugin from 'vite-plugin-clean';
import { Mode, plugin as viteMdPlugin } from 'vite-plugin-markdown';
import tsconfigPaths from 'vite-tsconfig-paths';

import '../load.envs.js';
import '../load.envs.cts';

const linkDeps = process.env.LINK_DEPS?.trim().split(' ').filter(Boolean) || [];

Expand Down
76 changes: 38 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d86db8e

Please sign in to comment.