-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from pcattori/unreplaced-macros-throw
feat: unreplaced macros throw an error
- Loading branch information
Showing
4 changed files
with
35 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { expect, test } from "vitest" | ||
|
||
import { server$, client$ } from "./macro" | ||
|
||
test("unreplaced macro throws error", () => { | ||
expect(() => server$("hello")).toThrowError(/unreplaced macro/) | ||
expect(() => client$("world")).toThrowError(/unreplaced macro/) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { name as pkgName } from "../package.json" | ||
|
||
const maybe = <T>(_: T): T | undefined => { | ||
throw Error( | ||
[ | ||
`${pkgName}: unreplaced macro`, | ||
"", | ||
`Did you forget to add the '${pkgName}' plugin to your Vite config?`, | ||
"👉 https://github.com/pcattori/vite-env-only?tab=readme-ov-file#installation", | ||
].join("\n"), | ||
) | ||
} | ||
|
||
/** | ||
* On the server, replaced with the value passed in. | ||
* On the client, replaced with `undefined`. | ||
*/ | ||
export const server$ = maybe | ||
|
||
/** | ||
* On the client, replaced with the value passed in. | ||
* On the server, replaced with `undefined`. | ||
*/ | ||
export const client$ = maybe |