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

Add support for nextjs Edge runtime #11

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-typescript"
]
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
35 changes: 26 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "znv",
"version": "0.4.0",
"name": "bowlingx-znv",
"version": "0.4.8",
"description": "Parse your environment with Zod schemas",
"type": "module",
"keywords": [
Expand Down Expand Up @@ -39,7 +39,7 @@
},
"license": "MIT",
"scripts": {
"build": "run-s -l build:*",
"build": "run-s -l \"build:*\"",
"build:clean": "rm -rf dist/ dist-cjs/",
"build:mjs": "tsc --project tsconfig.build.json",
"build:cjs": "tsc --project tsconfig.cjs.build.json",
Expand All @@ -60,28 +60,44 @@
"zod": "^3.13.2"
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.5",
"@types/jest": "^29.5.4",
"@types/node": "^16.18.24",
"eslint": "^8.48.0",
"babel-jest": "^29.6.2",
"eslint": "^8.47.0",
"eslint-config-lostfictions": "^6.0.0",
"jest": "^29.6.4",
"jest": "^29.6.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"prettier": "^2.8.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"typescript": "^5.1.6",
"zod": "~3.13.2"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
"^(\\.{1,2}/.*)\\.c?js$": "$1"
},
"moduleFileExtensions": [
"js",
"mjs",
"cjs",
"cts",
"jsx",
"ts",
"tsx",
"json",
"node"
],
"extensionsToTreatAsEsm": [
".ts"
],
"rootDir": "src",
"transform": {
"^.+\\.cts$": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I had to add babel here is that ts-jest does not support the cts extension.
See kulshekhar/ts-jest#3996

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it's clumsy and I think not all runtimes can be detected properly, so it's better to just use export maps.

"babel-jest"
],
"^.+\\.tsx?$": [
"ts-jest",
{
Expand All @@ -90,5 +106,6 @@
}
]
}
}
},
"packageManager": "yarn@4.4.1"
}
16 changes: 16 additions & 0 deletions src/colors.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const identity = (input: string | number) => input;

declare const EdgeRuntime: unknown;

let colors = {
yellow: identity,
red: identity,
cyan: identity,
green: identity,
};

if (typeof EdgeRuntime !== "string") {
colors = require("colorette");
}

export { colors };
4 changes: 2 additions & 2 deletions src/extra-schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ describe("extra schemas", () => {
describe("deprecate", () => {
it("throws when a value is passed", () => {
expect(() =>
parseEnv({ DEPRECATED: "something" }, { DEPRECATED: deprecate() }),
parseEnv({ DEPRECATED: "something" }, { DEPRECATED: deprecate() })
).toThrow();

expect(() =>
parseEnv({ DEPRECATED: "" }, { DEPRECATED: deprecate() }),
parseEnv({ DEPRECATED: "" }, { DEPRECATED: deprecate() })
).toThrow();

expect(() => parseEnv({}, { DEPRECATED: deprecate() })).not.toThrow();
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { z } from "zod";
export * from "./parse-env.js";
export * from "./preprocessors.js";
export * from "./extra-schemas.js";
export type * from "./util.js";
Loading