Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit 7591f40

Browse files
authored
fix(packages): 🐛 Resolve issue with duplicated exports (#69)
1 parent b4ab85a commit 7591f40

File tree

17 files changed

+84
-59
lines changed

17 files changed

+84
-59
lines changed

.changeset/yellow-socks-wash.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@terminal-nerds/snippets-config": minor
3+
"@terminal-nerds/snippets-error": minor
4+
"@terminal-nerds/snippets-runtime": minor
5+
---
6+
7+
🐛 Resolve issue with duplicated re-export - `RuntimeError`

packages/config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dist/"
4242
],
4343
"dependencies": {
44+
"@terminal-nerds/snippets-error": "workspace:*",
4445
"@terminal-nerds/snippets-runtime": "workspace:*",
4546
"deepmerge-ts": "4.3.0",
4647
"pkg-dir": "7.0.0",

packages/config/source/read/read.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { existsSync } from "node:fs";
22
import { join } from "node:path";
33

4+
import { RuntimeError } from "@terminal-nerds/snippets-error/custom/runtime";
45
import { getRuntimeEnvironmentName, IN_BROWSER } from "@terminal-nerds/snippets-runtime/environment";
5-
import { RuntimeError } from "@terminal-nerds/snippets-runtime/error";
66
import { packageDirectorySync } from "pkg-dir";
77
import type { Join } from "type-fest";
88

packages/error/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
"types": "./dist/*/*.d.ts",
3636
"import": "./dist/*/*.js",
3737
"require": "./dist/*/*.cjs"
38+
},
39+
"./custom/*": {
40+
"types": "./dist/custom/*/*.d.ts",
41+
"import": "./dist/custom/*/*.js",
42+
"require": "./dist/custom/*/*.cjs"
3843
}
3944
},
4045
"files": [
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,2 @@
1-
/**
2-
* FIXME: There's a bug with pnpm and TypeScript, this a workaround.
3-
*
4-
* @see {@link https://github.com/microsoft/TypeScript/issues/42873}
5-
*/
6-
import type {} from "modern-errors";
7-
import ModernError from "modern-errors";
8-
import { z, ZodError } from "zod";
9-
10-
/** Error related to the currently used JavaScript runtime environment. */
11-
export const RuntimeError: typeof ModernError = ModernError.subclass("RuntimeError", {
12-
props: {
13-
bun: typeof globalThis.Bun,
14-
deno: typeof globalThis.Deno,
15-
process: typeof globalThis.process,
16-
window: typeof globalThis.window,
17-
},
18-
});
19-
/** @see {@link RuntimeError} */
20-
export const RUNTIME_ERROR_SCHEMA: ReturnType<typeof z.instanceof<typeof RuntimeError>> = z.instanceof(RuntimeError);
21-
/** @see {@link RuntimeError} */
22-
export function isRuntimeError(error: unknown): error is typeof RuntimeError {
23-
return RUNTIME_ERROR_SCHEMA.safeParse(error).success;
24-
}
25-
26-
/** Error related to the type validation. */
27-
export const ValidationError = ZodError;
28-
/** @see {@link ValidationError} */
29-
export const VALIDATION_ERROR_SCHEMA = z.instanceof(ValidationError);
30-
/** @see {@link ValidationError} */
31-
export function isValidationError(error: unknown): error is typeof ValidationError {
32-
return VALIDATION_ERROR_SCHEMA.safeParse(error).success;
33-
}
1+
export * from "./runtime/runtime.ts";
2+
export * from "./validation/validation.ts";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { returns } from "@terminal-nerds/snippets-test/unit";
2+
import { describe, expect, it } from "vitest";
3+
4+
import { isRuntimeError, RuntimeError } from "./runtime.ts";
5+
6+
describe("isRuntimeError(error)", () => {
7+
it(returns(false).on(`Error`), () => {
8+
expect(isRuntimeError(Error)).toBe(false);
9+
});
10+
11+
it(returns(false).on(`random value`).sample(""), () => {
12+
expect(isRuntimeError("")).toBe(false);
13+
});
14+
15+
it(returns(true).on(`RuntimeError`), () => {
16+
expect(isRuntimeError(new RuntimeError("message"))).toBe(true);
17+
});
18+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* FIXME: There's a bug with pnpm and TypeScript, this a workaround.
3+
*
4+
* @see {@link https://github.com/microsoft/TypeScript/issues/42873}
5+
*/
6+
import type {} from "modern-errors";
7+
import ModernError from "modern-errors";
8+
import { z } from "zod";
9+
10+
/** Error related to the currently used JavaScript runtime environment. */
11+
export const RuntimeError: typeof ModernError = ModernError.subclass("RuntimeError", {
12+
props: {
13+
bun: typeof globalThis.Bun,
14+
deno: typeof globalThis.Deno,
15+
process: typeof globalThis.process,
16+
window: typeof globalThis.window,
17+
},
18+
});
19+
/** @see {@link RuntimeError} */
20+
export const RUNTIME_ERROR_SCHEMA: ReturnType<typeof z.instanceof<typeof RuntimeError>> = z.instanceof(RuntimeError);
21+
/** @see {@link RuntimeError} */
22+
export function isRuntimeError(error: unknown): error is typeof RuntimeError {
23+
return RUNTIME_ERROR_SCHEMA.safeParse(error).success;
24+
}

packages/error/source/custom/custom.test.ts renamed to packages/error/source/custom/validation/validation.test.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
import { returns } from "@terminal-nerds/snippets-test/unit";
22
import { describe, expect, it } from "vitest";
33

4-
import { isRuntimeError, isValidationError, RuntimeError, ValidationError } from "./custom.ts";
5-
6-
describe("isRuntimeError(error)", () => {
7-
it(returns(false).on(`Error`), () => {
8-
expect(isRuntimeError(Error)).toBe(false);
9-
});
10-
11-
it(returns(false).on(`random value`).sample(""), () => {
12-
expect(isRuntimeError("")).toBe(false);
13-
});
14-
15-
it(returns(true).on(`RuntimeError`), () => {
16-
expect(isRuntimeError(new RuntimeError("message"))).toBe(true);
17-
});
18-
});
4+
import { isValidationError, ValidationError } from "./validation.ts";
195

206
describe("isValidationError(error)", () => {
217
it(returns(false).on(`Error`), () => {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { z, ZodError } from "zod";
2+
3+
/** Error related to the type validation. */
4+
export const ValidationError = ZodError;
5+
/** @see {@link ValidationError} */
6+
export const VALIDATION_ERROR_SCHEMA = z.instanceof(ValidationError);
7+
/** @see {@link ValidationError} */
8+
export function isValidationError(error: unknown): error is typeof ValidationError {
9+
return VALIDATION_ERROR_SCHEMA.safeParse(error).success;
10+
}

packages/runtime/source/environment/environment.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
import { RuntimeError } from "@terminal-nerds/snippets-error/custom";
12
import { z } from "zod";
2-
3-
import { RuntimeError } from "../error/error.ts";
4-
53
/* prettier-ignore */
64
export const RUNTIME_ENVIRONMENTS = [
75
"browser",

0 commit comments

Comments
 (0)