Skip to content

Commit

Permalink
feat: set build target to module (#98)
Browse files Browse the repository at this point in the history
* feat: support dual package exports

* chore!: set packages esm only
  • Loading branch information
orionmiz authored Jan 21, 2024
1 parent a460070 commit 2880187
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"keywords": [
"swc-plugin"
],
"main": "next_superjson.wasm",
"type": "module",
"main": "./dist/next_superjson.wasm",
"exports": {
".": "./dist/next_superjson.wasm",
"./tools": "./dist/tools.js",
Expand Down
2 changes: 1 addition & 1 deletion tools/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { SuperJSONProps, withSuperJSONPage } from "./tools";
import * as React from "react";

export default function SuperJSONComponent<P>({
export default function SuperJSONComponent<P extends JSX.IntrinsicAttributes>({
component,
props,
children
Expand Down
8 changes: 4 additions & 4 deletions tools/tools.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// original tool source from 'babel-plugin-superjson-next'

import * as hoistNonReactStatics from "hoist-non-react-statics";
import hoistNonReactStatics from "hoist-non-react-statics";
import type { GetServerSideProps } from "next";
import * as React from "react";
import React from "react";
import SuperJSON from "superjson";

export type SuperJSONProps<P> = P & {
_superjson?: ReturnType<typeof SuperJSON.serialize>["meta"];
};

export function withSuperJSONProps<P>(
export function withSuperJSONProps<P extends JSX.IntrinsicAttributes>(
gssp: GetServerSideProps<P>,
exclude: string[] = []
): GetServerSideProps<SuperJSONProps<P>> {
Expand Down Expand Up @@ -87,7 +87,7 @@ export function deserializeProps<P>(serializedProps: SuperJSONProps<P>): P {
return SuperJSON.deserialize({ json: props as any, meta: _superjson });
}

export function withSuperJSONPage<P>(
export function withSuperJSONPage<P extends JSX.IntrinsicAttributes>(
Page: React.ComponentType<P>
): React.ComponentType<SuperJSONProps<P>> {
function WithSuperJSON(serializedProps: SuperJSONProps<P>) {
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"compilerOptions": {
"declaration": true,
"sourceMap": true,
"target": "ES5",
"target": "ESNext",
"rootDir": "tools",
"outDir": "dist",
"strict": true,
"moduleResolution": "node",
"jsx": "react",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"jsx": "react-jsx",
"skipLibCheck": true
}
}

0 comments on commit 2880187

Please sign in to comment.