Skip to content

Commit

Permalink
fix: properly resolve types when using TypeScript's latest module res…
Browse files Browse the repository at this point in the history
…olution strategy (#182)

* fix: properly resolve types when using TypeScript's latest module resolution strategy

* fix: remove side-effectful process polyfill

* fix: use correct `react-server` types declaration file

* chore: remove `.d.ts` files from Size Limit output

* chore(deps): update `@prismicio/richtext`, `@prismicio/client`
  • Loading branch information
angeloashmore authored May 22, 2023
1 parent 436ebd9 commit 27332f5
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 36 deletions.
11 changes: 9 additions & 2 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ module.exports = [
]
.sort()
.filter((path) => {
return path && path !== "./package.json";
return path && path !== "./package.json" && !path.endsWith(".d.ts");
})
.map((path) => {
return { path };
return {
path,
modifyEsbuildConfig(config) {
config.platform = "node";

return config;
},
};
});
32 changes: 16 additions & 16 deletions package-lock.json

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

24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@
"exports": {
".": {
"react-server": {
"import": "./dist/react-server.js",
"require": "./dist/react-server.cjs"
"require": {
"types": "./dist/react-server/index.d.ts",
"default": "./dist/react-server.cjs"
},
"import": {
"types": "./dist/react-server/index.d.ts",
"default": "./dist/react-server.js"
}
},
"default": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"./package.json": "./package.json"
Expand Down Expand Up @@ -54,10 +66,10 @@
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
},
"dependencies": {
"@prismicio/richtext": "^2.1.4"
"@prismicio/richtext": "^2.1.5"
},
"devDependencies": {
"@prismicio/client": "^7.0.0-alpha.3",
"@prismicio/client": "^7.0.1",
"@prismicio/mock": "^0.2.0",
"@size-limit/preset-small-lib": "^8.2.4",
"@testing-library/react": "^14.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/PrismicImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ export const PrismicImage = React.forwardRef(function PrismicImage(
...restProps
} = props;

if (process.env.NODE_ENV === "development") {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
) {
if (typeof alt === "string" && props.alt !== "") {
console.warn(
`[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg(
Expand Down
5 changes: 4 additions & 1 deletion src/PrismicText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export type PrismicTextProps = {
* @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
*/
export const PrismicText = (props: PrismicTextProps): JSX.Element | null => {
if (process.env.NODE_ENV === "development") {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
) {
if ("className" in props) {
console.warn(
`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg(
Expand Down
2 changes: 1 addition & 1 deletion src/PrismicToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const PrismicToolbar = ({
// environments.
//
// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209
if (process.env.NODE_ENV === "test") {
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.
script._evaluateScript = false;
}
Expand Down
5 changes: 4 additions & 1 deletion src/SliceZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ export type SliceZoneComponents<
export const TODOSliceComponent = <TSlice extends SliceLike, TContext>({
slice,
}: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {
if (process.env.NODE_ENV === "development") {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
) {
const type = "slice_type" in slice ? slice.slice_type : slice.type;

console.warn(
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "./lib/processPolyfill";

export { PrismicProvider } from "./PrismicProvider";
export type {
PrismicProviderProps,
Expand Down
4 changes: 0 additions & 4 deletions src/lib/processPolyfill.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/react-server/PrismicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export const PrismicLink = React.forwardRef(function PrismicLink<
}: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,
ref: React.ForwardedRef<Element>,
): JSX.Element {
if (process.env.NODE_ENV === "development") {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
) {
if (field) {
if (!field.link_type) {
console.error(
Expand Down
5 changes: 4 additions & 1 deletion src/react-server/PrismicRichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ export function PrismicRichText<
...restProps
}: PrismicRichTextProps<LinkResolverFunction>): JSX.Element | null {
return React.useMemo(() => {
if (process.env.NODE_ENV === "development") {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
) {
if ("className" in restProps) {
console.warn(
`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(
Expand Down

0 comments on commit 27332f5

Please sign in to comment.