Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce dotenv package for finding environment files #1334

Merged
merged 12 commits into from
Aug 21, 2024
1 change: 1 addition & 0 deletions demos/client-example-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"devDependencies": {
"@prosopo/config": "2.0.1",
"@prosopo/dotenv": "2.0.1",
"@types/jsonwebtoken": "^9.0.2",
"tslib": "2.6.2",
"typescript": "5.1.6",
Expand Down
28 changes: 14 additions & 14 deletions demos/client-example-server/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import * as path from "node:path";
import { loadEnv } from "@prosopo/cli";
import { loadEnv } from "@prosopo/dotenv";
import { ViteBackendConfig } from "@prosopo/config";
import { defineConfig } from "vite";
import { version } from "./package.json";
Expand All @@ -31,17 +31,17 @@ process.env.TS_NODE_PROJECT = path.resolve("./tsconfig.json");

// Merge with generic backend config
export default defineConfig(async ({ command, mode }) => {
const backendConfig = await ViteBackendConfig(
packageName,
packageVersion,
bundleName,
dir,
entry,
command,
mode,
);
return defineConfig({
...backendConfig,
server: { port: process.env.PROSOPO_SERVER_PORT },
});
const backendConfig = await ViteBackendConfig(
packageName,
packageVersion,
bundleName,
dir,
entry,
command,
mode,
);
return defineConfig({
...backendConfig,
server: { port: process.env.PROSOPO_SERVER_PORT },
});
});
2 changes: 1 addition & 1 deletion demos/client-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"devDependencies": {
"@prosopo/cli": "2.0.1",
"@prosopo/dotenv": "2.0.1",
"@prosopo/config": "2.0.1",
"@prosopo/vite-plugin-watch-workspace": "2.0.1",
"@types/node": "^20.3.1",
Expand Down
158 changes: 79 additions & 79 deletions demos/client-example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import * as path from "node:path";
import { loadEnv } from "@prosopo/cli";
import { loadEnv } from "@prosopo/dotenv";
import { getLogger } from "@prosopo/common";
import { VitePluginCloseAndCopy } from "@prosopo/config";
import { VitePluginWatchWorkspace } from "@prosopo/vite-plugin-watch-workspace";
Expand All @@ -23,83 +23,83 @@ const dir = path.resolve(".");
loadEnv(dir);
// https://vitejs.dev/config/
export default defineConfig(async ({ command, mode }) => {
logger.info(`Running at ${dir} in ${mode} mode`);
// NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
// mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
// issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
logger.info(`NODE_ENV: ${process.env.NODE_ENV}`);
logger.info(`Running at ${dir} in ${mode} mode`);
// NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
// mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
// issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
logger.info(`NODE_ENV: ${process.env.NODE_ENV}`);

// Set the env vars that we want to be available in the browser
const define = {
// used to stop websockets package from breaking
"process.env.WS_NO_BUFFER_UTIL": JSON.stringify("true"),
"process.env.WS_NO_UTF_8_VALIDATE": JSON.stringify("true"),
"process.env.NODE_ENV": JSON.stringify(mode),
"process.env.PROSOPO_DEFAULT_ENVIRONMENT": JSON.stringify(
process.env.PROSOPO_DEFAULT_ENVIRONMENT,
),
// only needed if bundling with a site key
"process.env.PROSOPO_SITE_KEY": JSON.stringify(
process.env.PROSOPO_SITE_KEY,
),
"process.env.PROSOPO_WEB2": JSON.stringify(process.env.PROSOPO_WEB2),
"process.env.PROSOPO_SERVER_URL": JSON.stringify(
process.env.PROSOPO_SERVER_URL,
),
"process.env.PROSOPO_SERVER_PORT": JSON.stringify(
process.env.PROSOPO_SERVER_PORT,
),
"process.env.PROSOPO_PORT": JSON.stringify(process.env.PROSOPO_PORT),
"process.env._DEV_ONLY_WATCH_EVENTS": JSON.stringify(
process.env._DEV_ONLY_WATCH_EVENTS,
),
};
logger.debug("define", JSON.stringify(define));
return {
watch: false,
mode: "development",
bundle: true,
define,
optimizeDeps: {
include: ["prop-types"],
},
esbuild: {
target: [
"es2020",
"chrome60",
"edge18",
"firefox60",
"node12",
"safari11",
],
},
build: {
modulePreload: { polyfill: true },
lib: {
entry: path.resolve(__dirname, "./index.html"),
name: "client_example",
},
},
plugins: [
// @ts-ignore
react(),
// Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
// mode, in which case we don't want to close the bundler because it will close the server
command !== "serve" ? VitePluginCloseAndCopy() : undefined,
// Watches external files (workspace packages) and rebuilds them when they change
await VitePluginWatchWorkspace({
workspaceRoot: path.resolve("../.."),
currentPackage: `${path.resolve(".")}/**/*`,
format: "esm",
ignorePaths: [
`${path.resolve("../..")}/demos/*`,
`${path.resolve("../..")}/dev/*`,
"**/dist/**/*",
],
}),
],
server: {
port: process.env.PROSOPO_PORT ? Number(process.env.PROSOPO_PORT) : 9230,
},
};
// Set the env vars that we want to be available in the browser
const define = {
// used to stop websockets package from breaking
"process.env.WS_NO_BUFFER_UTIL": JSON.stringify("true"),
"process.env.WS_NO_UTF_8_VALIDATE": JSON.stringify("true"),
"process.env.NODE_ENV": JSON.stringify(mode),
"process.env.PROSOPO_DEFAULT_ENVIRONMENT": JSON.stringify(
process.env.PROSOPO_DEFAULT_ENVIRONMENT,
),
// only needed if bundling with a site key
"process.env.PROSOPO_SITE_KEY": JSON.stringify(
process.env.PROSOPO_SITE_KEY,
),
"process.env.PROSOPO_WEB2": JSON.stringify(process.env.PROSOPO_WEB2),
"process.env.PROSOPO_SERVER_URL": JSON.stringify(
process.env.PROSOPO_SERVER_URL,
),
"process.env.PROSOPO_SERVER_PORT": JSON.stringify(
process.env.PROSOPO_SERVER_PORT,
),
"process.env.PROSOPO_PORT": JSON.stringify(process.env.PROSOPO_PORT),
"process.env._DEV_ONLY_WATCH_EVENTS": JSON.stringify(
process.env._DEV_ONLY_WATCH_EVENTS,
),
};
logger.debug("define", JSON.stringify(define));
return {
watch: false,
mode: "development",
bundle: true,
define,
optimizeDeps: {
include: ["prop-types"],
},
esbuild: {
target: [
"es2020",
"chrome60",
"edge18",
"firefox60",
"node12",
"safari11",
],
},
build: {
modulePreload: { polyfill: true },
lib: {
entry: path.resolve(__dirname, "./index.html"),
name: "client_example",
},
},
plugins: [
// @ts-ignore
react(),
// Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
// mode, in which case we don't want to close the bundler because it will close the server
command !== "serve" ? VitePluginCloseAndCopy() : undefined,
// Watches external files (workspace packages) and rebuilds them when they change
await VitePluginWatchWorkspace({
workspaceRoot: path.resolve("../.."),
currentPackage: `${path.resolve(".")}/**/*`,
format: "esm",
ignorePaths: [
`${path.resolve("../..")}/demos/*`,
`${path.resolve("../..")}/dev/*`,
"**/dist/**/*",
],
}),
],
server: {
port: process.env.PROSOPO_PORT ? Number(process.env.PROSOPO_PORT) : 9230,
},
};
});
2 changes: 1 addition & 1 deletion demos/client-frictionless-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@prosopo/procaptcha-pow": "2.0.1"
},
"devDependencies": {
"@prosopo/cli": "2.0.1",
"@prosopo/dotenv": "2.0.1",
"@prosopo/config": "2.0.1",
"@types/node": "^20.3.1",
"css-loader": "^6.8.1",
Expand Down
136 changes: 68 additions & 68 deletions demos/client-frictionless-example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import * as path from "node:path";
import { loadEnv } from "@prosopo/cli";
import { loadEnv } from "@prosopo/dotenv";
import { getLogger } from "@prosopo/common";
import { VitePluginCloseAndCopy } from "@prosopo/config";
import react from "@vitejs/plugin-react";
Expand All @@ -22,73 +22,73 @@ const dir = path.resolve(".");
loadEnv(dir);
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
logger.info(`Running at ${dir} in ${mode} mode`);
// NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
// mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
// issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
logger.info(`NODE_ENV: ${process.env.NODE_ENV}`);
logger.info(`Running at ${dir} in ${mode} mode`);
// NODE_ENV must be wrapped in quotes. We just set it to the mode and ignore what's in the env file, otherwise the
// mode and NODE_ENV can end up out of sync (one set to development and the other set to production, which causes
// issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
logger.info(`NODE_ENV: ${process.env.NODE_ENV}`);

// Set the env vars that we want to be available in the browser
const define = {
// used to stop websockets package from breaking
"process.env.WS_NO_BUFFER_UTIL": JSON.stringify("true"),
"process.env.WS_NO_UTF_8_VALIDATE": JSON.stringify("true"),
"process.env.NODE_ENV": JSON.stringify(mode),
"process.env.PROSOPO_SUBSTRATE_ENDPOINT": JSON.stringify(
process.env.PROSOPO_SUBSTRATE_ENDPOINT,
),
"process.env.PROSOPO_DEFAULT_ENVIRONMENT": JSON.stringify(
process.env.PROSOPO_DEFAULT_ENVIRONMENT,
),
// only needed if bundling with a site key
"process.env.PROSOPO_SITE_KEY": JSON.stringify(
process.env.PROSOPO_SITE_KEY,
),
"process.env.PROSOPO_CONTRACT_ADDRESS": JSON.stringify(
process.env.PROSOPO_CONTRACT_ADDRESS,
),
"process.env.PROSOPO_WEB2": JSON.stringify(process.env.PROSOPO_WEB2),
"process.env.PROSOPO_SERVER_URL": JSON.stringify(
process.env.PROSOPO_SERVER_URL,
),
"process.env.PROSOPO_PORT": JSON.stringify(process.env.PROSOPO_PORT),
};
logger.debug("define", JSON.stringify(define));
// Set the env vars that we want to be available in the browser
const define = {
// used to stop websockets package from breaking
"process.env.WS_NO_BUFFER_UTIL": JSON.stringify("true"),
"process.env.WS_NO_UTF_8_VALIDATE": JSON.stringify("true"),
"process.env.NODE_ENV": JSON.stringify(mode),
"process.env.PROSOPO_SUBSTRATE_ENDPOINT": JSON.stringify(
process.env.PROSOPO_SUBSTRATE_ENDPOINT,
),
"process.env.PROSOPO_DEFAULT_ENVIRONMENT": JSON.stringify(
process.env.PROSOPO_DEFAULT_ENVIRONMENT,
),
// only needed if bundling with a site key
"process.env.PROSOPO_SITE_KEY": JSON.stringify(
process.env.PROSOPO_SITE_KEY,
),
"process.env.PROSOPO_CONTRACT_ADDRESS": JSON.stringify(
process.env.PROSOPO_CONTRACT_ADDRESS,
),
"process.env.PROSOPO_WEB2": JSON.stringify(process.env.PROSOPO_WEB2),
"process.env.PROSOPO_SERVER_URL": JSON.stringify(
process.env.PROSOPO_SERVER_URL,
),
"process.env.PROSOPO_PORT": JSON.stringify(process.env.PROSOPO_PORT),
};
logger.debug("define", JSON.stringify(define));

return {
watch: false,
mode: "development",
bundle: true,
define,
optimizeDeps: {
include: ["prop-types"],
},
esbuild: {
target: [
"es2020",
"chrome60",
"edge18",
"firefox60",
"node12",
"safari11",
],
},
build: {
modulePreload: { polyfill: true },
lib: {
entry: path.resolve(__dirname, "./index.html"),
name: "client_example",
},
},
plugins: [
// @ts-ignore
react(),
// Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
// mode, in which case we don't want to close the bundler because it will close the server
command !== "serve" ? VitePluginCloseAndCopy() : undefined,
],
server: {
port: process.env.PROSOPO_PORT ? Number(process.env.PROSOPO_PORT) : 9234,
},
};
return {
watch: false,
mode: "development",
bundle: true,
define,
optimizeDeps: {
include: ["prop-types"],
},
esbuild: {
target: [
"es2020",
"chrome60",
"edge18",
"firefox60",
"node12",
"safari11",
],
},
build: {
modulePreload: { polyfill: true },
lib: {
entry: path.resolve(__dirname, "./index.html"),
name: "client_example",
},
},
plugins: [
// @ts-ignore
react(),
// Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
// mode, in which case we don't want to close the bundler because it will close the server
command !== "serve" ? VitePluginCloseAndCopy() : undefined,
],
server: {
port: process.env.PROSOPO_PORT ? Number(process.env.PROSOPO_PORT) : 9234,
},
};
});
2 changes: 1 addition & 1 deletion demos/client-pow-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@prosopo/cli": "2.0.1",
"@prosopo/dotenv": "2.0.1",
"@prosopo/config": "2.0.1",
"@types/node": "^20.3.1",
"css-loader": "^6.8.1",
Expand Down
Loading
Loading