From ab1133306fdfd3865d61cd4734685e1eb7605d4a Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 21 Jan 2021 18:08:35 -0500 Subject: [PATCH] fix it --- README.md | 23 +++- example/.testcaferc.json | 6 +- example/package.json | 10 +- example/tests/fallback.ts | 2 +- example/tests/gsp-arrow.ts | 2 +- example/tests/index.ts | 2 +- example/tests/no-meta.ts | 2 +- example/tests/static.ts | 2 +- example/tests/with-static-methods.ts | 2 +- example/yarn.lock | 176 +++++++++++++-------------- src/index.ts | 19 +-- src/tools.tsx | 17 ++- test/pages/unexported gSSP/code.js | 18 --- test/pages/unexported gSSP/output.js | 18 --- 14 files changed, 136 insertions(+), 163 deletions(-) delete mode 100644 test/pages/unexported gSSP/code.js delete mode 100644 test/pages/unexported gSSP/output.js diff --git a/README.md b/README.md index 56db05c..b28b3b0 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,12 @@ npm install superjson Add the plugin to your `.babelrc`. If you don't have one, create it. - ```json5 { - "presets": ["next/babel"], - "plugins": [ - ... - "superjson-next" // 👈 - ] + presets: ['next/babel'], + plugins: [ + ...'superjson-next', // 👈 + ], } ``` @@ -58,9 +56,22 @@ That's it! Now you're free to use all values and type supported by SuperJSON in +## Contributing + +1. Clone the repo +1. `yarn` +1. `yarn build` + +### Test Example App + +1. `cd example` +2. `yarn` (make sure you first run `yarn build` in the repo root) +3. `yarn test` + ## Contributors ✨ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): + diff --git a/example/.testcaferc.json b/example/.testcaferc.json index 866daa2..7f19ac3 100644 --- a/example/.testcaferc.json +++ b/example/.testcaferc.json @@ -1,4 +1,4 @@ { - "appCommand": "yarn start", - "appInitDelay": 2000 -} \ No newline at end of file + "appCommand": "yarn start -p 3099", + "appInitDelay": 2000 +} diff --git a/example/package.json b/example/package.json index 14fff37..3073dac 100644 --- a/example/package.json +++ b/example/package.json @@ -10,13 +10,13 @@ }, "dependencies": { "babel-plugin-superjson-next": "file:../", - "next": "10", - "react": "16.13.1", - "react-dom": "16.13.1", - "superjson": "^1.4.1" + "next": "10.0.5", + "react": "17.0.1", + "react-dom": "17.0.1", + "superjson": "^1.5.0" }, "devDependencies": { - "@types/react": "^16.9.44", + "@types/react": "^17.0.0", "testcafe": "^1.10.1" } } diff --git a/example/tests/fallback.ts b/example/tests/fallback.ts index bba6994..4c998b3 100644 --- a/example/tests/fallback.ts +++ b/example/tests/fallback.ts @@ -1,6 +1,6 @@ import { Selector } from 'testcafe'; -fixture`Fallback`.page`http://localhost:3000/fallback/hello`; +fixture`Fallback`.page`http://localhost:3099/fallback/hello`; test('Date is preserved', async (t) => { const result = Selector('#__next'); diff --git a/example/tests/gsp-arrow.ts b/example/tests/gsp-arrow.ts index 976358c..858e609 100644 --- a/example/tests/gsp-arrow.ts +++ b/example/tests/gsp-arrow.ts @@ -1,6 +1,6 @@ import { Selector } from 'testcafe'; -fixture`gSP Arrow`.page`http://localhost:3000/gsp-arrow`; +fixture`gSP Arrow`.page`http://localhost:3099/gsp-arrow`; test('Date is preserved', async (t) => { const result = Selector('#__next'); diff --git a/example/tests/index.ts b/example/tests/index.ts index 497f1af..367cf36 100644 --- a/example/tests/index.ts +++ b/example/tests/index.ts @@ -1,6 +1,6 @@ import { Selector } from 'testcafe'; -fixture`Index`.page`http://localhost:3000/`; +fixture`Index`.page`http://localhost:3099/`; test('Date is preserved', async (t) => { const result = Selector('#__next'); diff --git a/example/tests/no-meta.ts b/example/tests/no-meta.ts index 85ca8c0..7aedcb4 100644 --- a/example/tests/no-meta.ts +++ b/example/tests/no-meta.ts @@ -1,6 +1,6 @@ import { Selector } from 'testcafe'; -fixture`No meta`.page`http://localhost:3000/no-meta`; +fixture`No meta`.page`http://localhost:3099/no-meta`; test('Raw object is built', async (t) => { const result = Selector('#__next'); diff --git a/example/tests/static.ts b/example/tests/static.ts index 8927730..21adbc1 100644 --- a/example/tests/static.ts +++ b/example/tests/static.ts @@ -1,6 +1,6 @@ import { Selector } from 'testcafe'; -fixture`Static`.page`http://localhost:3000/static`; +fixture`Static`.page`http://localhost:3099/static`; test('Date is preserved', async (t) => { const result = Selector('#__next'); diff --git a/example/tests/with-static-methods.ts b/example/tests/with-static-methods.ts index 3a8d14b..d185c70 100644 --- a/example/tests/with-static-methods.ts +++ b/example/tests/with-static-methods.ts @@ -1,6 +1,6 @@ import { Selector } from 'testcafe'; -fixture`With Static Methods`.page`http://localhost:3000/with-static-methods`; +fixture`With Static Methods`.page`http://localhost:3099/with-static-methods`; test('Static methods are preserved', async (t) => { const result = Selector('#__next'); diff --git a/example/yarn.lock b/example/yarn.lock index 39fac6d..1909c84 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -53,14 +53,7 @@ dependencies: cross-fetch "3.0.6" -"@babel/code-frame@7.10.4": - version "7.10.4" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a" - integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg== - dependencies: - "@babel/highlight" "^7.10.4" - -"@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.11": +"@babel/code-frame@7.12.11", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.11": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw== @@ -1015,36 +1008,37 @@ call-me-maybe "^1.0.1" glob-to-regexp "^0.3.0" -"@next/env@10.0.4": - version "10.0.4" - resolved "https://registry.yarnpkg.com/@next/env/-/env-10.0.4.tgz#ac759094d021853616af56a7bd6720e44a92a303" - integrity sha512-U+XIL75XM1pCmY4+9kYbst/0IptlfDnkFfKdgADBZulQlfng4RB3zirdzkoBtod0lVcrGgDryzOi1mM23RiiVQ== +"@next/env@10.0.5": + version "10.0.5" + resolved "https://registry.yarnpkg.com/@next/env/-/env-10.0.5.tgz#446e59ee7a8d05061be784b24732c369653038ab" + integrity sha512-dw6Q7PALIo7nTFfaB4OnRDte3EikrApGtjX/4cRmYXLh+uudDI50aS39MaGeKKZ2mxPKoNiFcY6Slv1f6KIPOw== -"@next/polyfill-module@10.0.4": - version "10.0.4" - resolved "https://registry.yarnpkg.com/@next/polyfill-module/-/polyfill-module-10.0.4.tgz#c34391a12ad80d6e373c403f96c8e2bbd793dca1" - integrity sha512-i2gLUa3YuZ2eQg+d91n+jS4YbPVKg1v0HHIUeJFJMMtpG/apBkTuTLBQGJXe4nKNf7/41NWLDft4ihC3Zfd+Yw== +"@next/polyfill-module@10.0.5": + version "10.0.5" + resolved "https://registry.yarnpkg.com/@next/polyfill-module/-/polyfill-module-10.0.5.tgz#f2de3deee8694cc75094fea4e91225724b3a21e1" + integrity sha512-R6ySTTIl6yqyO3Xft7h+QR9Z4e6epEw+AGO125CrwPmCDQ8ASLGltsHYvSHBP7Eae7xaorkXHW0jeI8NewLpew== -"@next/react-dev-overlay@10.0.4": - version "10.0.4" - resolved "https://registry.yarnpkg.com/@next/react-dev-overlay/-/react-dev-overlay-10.0.4.tgz#c578a3c71e2f8a8fe2aae8007cc40d1cf10bc768" - integrity sha512-8pKN0PspEtfVFqeSpNQymfXWyV95OTIT0xP9IqILJX2+52ICdU5D+YNuNIwpc4ZOZ0CssM/uYsz6K1FHbCaU7A== +"@next/react-dev-overlay@10.0.5": + version "10.0.5" + resolved "https://registry.yarnpkg.com/@next/react-dev-overlay/-/react-dev-overlay-10.0.5.tgz#f0006e56d8c8b4269f341ff22233e4a7e1176b52" + integrity sha512-olqIaaRvFezzi02V/AYwvmrGbShUNrJDvyZTGNahxXEkiYsuu67llY5IKFM5Oya93/eRqaCCKMn89vpvYtvDcw== dependencies: - "@babel/code-frame" "7.10.4" - ally.js "1.4.1" + "@babel/code-frame" "7.12.11" anser "1.4.9" chalk "4.0.0" classnames "2.2.6" - data-uri-to-buffer "3.0.0" + css.escape "1.5.1" + data-uri-to-buffer "3.0.1" + platform "1.3.6" shell-quote "1.7.2" source-map "0.8.0-beta.0" stacktrace-parser "0.1.10" strip-ansi "6.0.0" -"@next/react-refresh-utils@10.0.4": - version "10.0.4" - resolved "https://registry.yarnpkg.com/@next/react-refresh-utils/-/react-refresh-utils-10.0.4.tgz#5ad753572891aa7cb1010b358cc4241d7be20d20" - integrity sha512-kZ/37aSQaR0GCZVqh7WDLkeEZqzjPQoZUDdo6TOWiIEb+089AmfYp8A4/1ra9Fu8T4b4wnB76TRl6tp6DeJLXg== +"@next/react-refresh-utils@10.0.5": + version "10.0.5" + resolved "https://registry.yarnpkg.com/@next/react-refresh-utils/-/react-refresh-utils-10.0.5.tgz#c1ca664c4ffe2f79d14383323d783368833d503b" + integrity sha512-Eo+nvW1ZhdkuxBWSsKHGDLNspUaJJQClld9R+H+EtiIuAQtTa8f2rhcQeyUOtvUNQoPyq7Em2PwUqOQD6LOOMA== "@nodelib/fs.scandir@2.1.4": version "2.1.4" @@ -1132,10 +1126,10 @@ resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw== -"@types/react@^16.9.44": - version "16.14.2" - resolved "https://registry.yarnpkg.com/@types/react/-/react-16.14.2.tgz#85dcc0947d0645349923c04ccef6018a1ab7538c" - integrity sha512-BzzcAlyDxXl2nANlabtT4thtvbbnhee8hMmH/CcJrISDBVcJS1iOsP1f0OAgSdGE0MsY9tqcrb9YoZcOFv9dbQ== +"@types/react@^17.0.0": + version "17.0.0" + resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.0.tgz#5af3eb7fad2807092f0046a1302b7823e27919b8" + integrity sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw== dependencies: "@types/prop-types" "*" csstype "^3.0.2" @@ -1357,14 +1351,6 @@ ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.4, ajv@^6.12.5: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ally.js@1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/ally.js/-/ally.js-1.4.1.tgz#9fb7e6ba58efac4ee9131cb29aa9ee3b540bcf1e" - integrity sha1-n7fmuljvrE7pExyymqnuO1QLzx4= - dependencies: - css.escape "^1.5.0" - platform "1.3.3" - amdefine@>=0.0.4: version "1.0.1" resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" @@ -1463,6 +1449,11 @@ array-find@^1.0.0: resolved "https://registry.yarnpkg.com/array-find/-/array-find-1.0.0.tgz#6c8e286d11ed768327f8e62ecee87353ca3e78b8" integrity sha1-bI4obRHtdoMn+OYuzuhzU8o+eLg= +array-flatten@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-3.0.0.tgz#6428ca2ee52c7b823192ec600fa3ed2f157cd541" + integrity sha512-zPMVc3ZYlGLNk4mpK1NzP2wg0ml9t7fUgDsayR5Y5rSzxQilzR9FGu/EH2jQOcKSAeAfWeylyW8juy3OkWRvNA== + array-union@^1.0.1, array-union@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39" @@ -1577,7 +1568,7 @@ babel-plugin-module-resolver@^4.0.0: resolve "^1.13.1" "babel-plugin-superjson-next@file:..": - version "0.1.8" + version "0.1.10" dependencies: "@babel/helper-module-imports" "^7.12.5" hoist-non-react-statics "^3.3.2" @@ -1821,7 +1812,7 @@ browserslist@^4.14.5, browserslist@^4.15.0: escalade "^3.1.1" node-releases "^1.1.67" -buffer-from@^1.0.0, buffer-from@^1.1.1: +buffer-from@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A== @@ -2125,7 +2116,7 @@ color-string@^1.5.4: color-name "^1.0.0" simple-swizzle "^0.2.2" -color@^3.1.2: +color@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/color/-/color-3.1.3.tgz#ca67fb4e7b97d611dcde39eceed422067d91596e" integrity sha512-xgXAcTHa2HeFCGLE9Xs/R82hujGtu9Jd9x4NW3T34+OMs7VoPsjwzRczKHvTAHeJwWFwX5j15+MgAppE8ztObQ== @@ -2329,7 +2320,7 @@ css-loader@4.3.0: schema-utils "^2.7.1" semver "^7.3.2" -css.escape@^1.5.0: +css.escape@1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/css.escape/-/css.escape-1.5.1.tgz#42e27d4fa04ae32f931a4b4d4191fa9cddee97cb" integrity sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s= @@ -2398,12 +2389,10 @@ d@1, d@^1.0.1: es5-ext "^0.10.50" type "^1.0.1" -data-uri-to-buffer@3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.0.tgz#8a3088a5efd3f53c3682343313c6895d498eb8d7" - integrity sha512-MJ6mFTZ+nPQO+39ua/ltwNePXrfdF3Ww0wP1Od7EePySXN1cP9XNqRQOG3FxTfipp8jx898LUCgBCEP11Qw/ZQ== - dependencies: - buffer-from "^1.1.1" +data-uri-to-buffer@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz#594b8973938c5bc2c33046535785341abc4f3636" + integrity sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og== debug@4, debug@^4.1.0: version "4.3.1" @@ -4248,18 +4237,18 @@ next-tick@~1.0.0: resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" integrity sha1-yobR/ogoFpsBICCOPchCS524NCw= -next@10: - version "10.0.4" - resolved "https://registry.yarnpkg.com/next/-/next-10.0.4.tgz#0d256f58a57d6bab7db7e533900c15f322960b4a" - integrity sha512-WXEYr1FuR2cLuWGN8peYGM6ykmbtwaHvrI6RqR2qrTXUNsW+KU5pzIMK5WPcpqP+xOuMhlykOCJvwJH8qU9FZQ== +next@10.0.5: + version "10.0.5" + resolved "https://registry.yarnpkg.com/next/-/next-10.0.5.tgz#8071e0aa1883266c91943aa7c6b73deadb064793" + integrity sha512-yr7ap2TLugf0aMHz+3JoKFP9CCkFE+k6jCfdUymORhptjLYZbD3YGlTcUC1CRl+b5Phlbl7m/WUIPde0VcguiA== dependencies: "@ampproject/toolbox-optimizer" "2.7.1-alpha.0" "@babel/runtime" "7.12.5" "@hapi/accept" "5.0.1" - "@next/env" "10.0.4" - "@next/polyfill-module" "10.0.4" - "@next/react-dev-overlay" "10.0.4" - "@next/react-refresh-utils" "10.0.4" + "@next/env" "10.0.5" + "@next/polyfill-module" "10.0.5" + "@next/react-dev-overlay" "10.0.5" + "@next/react-refresh-utils" "10.0.5" "@opentelemetry/api" "0.14.0" ast-types "0.13.2" babel-plugin-transform-define "2.0.0" @@ -4300,7 +4289,7 @@ next@10: webpack "4.44.1" webpack-sources "1.4.3" optionalDependencies: - sharp "0.26.2" + sharp "0.26.3" node-abi@^2.7.0: version "2.19.3" @@ -4716,10 +4705,10 @@ pkg-up@^3.1.0: dependencies: find-up "^3.0.0" -platform@1.3.3: - version "1.3.3" - resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.3.tgz#646c77011899870b6a0903e75e997e8e51da7461" - integrity sha1-ZGx3ARiZhwtqCQPnXpl+jlHadGE= +platform@1.3.6: + version "1.3.6" + resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" + integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== pngjs@^3.3.1: version "3.4.0" @@ -4830,10 +4819,10 @@ postcss@^7.0.14, postcss@^7.0.26, postcss@^7.0.32, postcss@^7.0.5, postcss@^7.0. source-map "^0.6.1" supports-color "^6.1.0" -prebuild-install@^5.3.5: - version "5.3.6" - resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-5.3.6.tgz#7c225568d864c71d89d07f8796042733a3f54291" - integrity sha512-s8Aai8++QQGi4sSbs/M1Qku62PFK49Jm1CbgXklGz4nmHveDq0wzJkg7Na5QbnO1uNH8K7iqx2EQ/mV0MZEmOg== +prebuild-install@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-6.0.0.tgz#669022bcde57c710a869e39c5ca6bf9cd207f316" + integrity sha512-h2ZJ1PXHKWZpp1caLw0oX9sagVpL2YTk+ZwInQbQ3QqNd4J03O6MpFNmMTJlkfgPENWqe5kP0WjQLqz5OjLfsw== dependencies: detect-libc "^1.0.3" expand-template "^2.0.3" @@ -4873,7 +4862,7 @@ promisify-event@^1.0.0: dependencies: pinkie-promise "^2.0.0" -prop-types@15.7.2, prop-types@^15.6.2: +prop-types@15.7.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== @@ -4989,15 +4978,14 @@ rc@^1.2.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-dom@16.13.1: - version "16.13.1" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f" - integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag== +react-dom@17.0.1: + version "17.0.1" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6" + integrity sha512-6eV150oJZ9U2t9svnsspTMrWNyHc6chX0KzDeAOXftRa8bNeOKTTfCJ7KorIwenkHd2xqVTBTCZd79yk/lx/Ug== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" - prop-types "^15.6.2" - scheduler "^0.19.1" + scheduler "^0.20.1" react-is@16.13.1, react-is@^16.7.0, react-is@^16.8.1: version "16.13.1" @@ -5009,14 +4997,13 @@ react-refresh@0.8.3: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" integrity sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg== -react@16.13.1: - version "16.13.1" - resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e" - integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w== +react@17.0.1: + version "17.0.1" + resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127" + integrity sha512-lG9c9UuMHdcAexXtigOZLX8exLWkW0Ku29qPRU8uhF2R9BN96dLCt0psvzPLlHc5OWkgymP3qwTRgbnw5BKx3w== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" - prop-types "^15.6.2" read-file-relative@^1.2.0: version "1.2.0" @@ -5299,10 +5286,10 @@ sass-loader@10.0.5: schema-utils "^3.0.0" semver "^7.3.2" -scheduler@^0.19.1: - version "0.19.1" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196" - integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA== +scheduler@^0.20.1: + version "0.20.1" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.1.tgz#da0b907e24026b01181ecbc75efdc7f27b5a000c" + integrity sha512-LKTe+2xNJBNxu/QhHvDR14wUXHRQbVY5ZOYpOGWRzhydZUqrLb2JBvLPY7cAqFmqrWuDED0Mjk7013SZiOz6Bw== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" @@ -5401,19 +5388,20 @@ sha.js@^2.4.0, sha.js@^2.4.8: inherits "^2.0.1" safe-buffer "^5.0.1" -sharp@0.26.2: - version "0.26.2" - resolved "https://registry.yarnpkg.com/sharp/-/sharp-0.26.2.tgz#3d5777d246ae32890afe82a783c1cbb98456a88c" - integrity sha512-bGBPCxRAvdK9bX5HokqEYma4j/Q5+w8Nrmb2/sfgQCLEUx/HblcpmOfp59obL3+knIKnOhyKmDb4tEOhvFlp6Q== +sharp@0.26.3: + version "0.26.3" + resolved "https://registry.yarnpkg.com/sharp/-/sharp-0.26.3.tgz#9de8577a986b22538e6e12ced1f7e8a53f9728de" + integrity sha512-NdEJ9S6AMr8Px0zgtFo1TJjMK/ROMU92MkDtYn2BBrDjIx3YfH9TUyGdzPC+I/L619GeYQc690Vbaxc5FPCCWg== dependencies: - color "^3.1.2" + array-flatten "^3.0.0" + color "^3.1.3" detect-libc "^1.0.3" node-addon-api "^3.0.2" npmlog "^4.1.2" - prebuild-install "^5.3.5" + prebuild-install "^6.0.0" semver "^7.3.2" simple-get "^4.0.0" - tar-fs "^2.1.0" + tar-fs "^2.1.1" tunnel-agent "^0.6.0" shebang-command@^2.0.0: @@ -5751,10 +5739,10 @@ stylis@3.5.4: resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.4.tgz#f665f25f5e299cf3d64654ab949a57c768b73fbe" integrity sha512-8/3pSmthWM7lsPBKv7NXkzn2Uc9W7NotcwGNpJaa3k7WMM1XDCA4MgT5k/8BIexd5ydZdboXtU90XH9Ec4Bv/Q== -superjson@^1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/superjson/-/superjson-1.4.1.tgz#c96501fc0cc32cc9cb25ecc3fb476db631eceba2" - integrity sha512-+PjOQNj7mW4I0t3KphIgwwQvQObd5Tc1DtUoIMj3iN7RXQyoWr2R8LXLtQw/UNEItSd0Al+qn0I/8yCnTXiAIw== +superjson@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/superjson/-/superjson-1.5.0.tgz#88c8ead3afa8d2ef47e7bdbee85c645d1653957f" + integrity sha512-unM/AG3zy0NbKV4bkNQrxCPZVEJNoCuAihKpNMKqZUCTf30XV4nkJjnKdRTa2G1xJgkoxUxJAoUJ64+wuRQJjw== dependencies: lodash "^4.17.20" lodash-es "^4.17.15" @@ -5785,7 +5773,7 @@ tapable@^1.0.0, tapable@^1.1.3: resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2" integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA== -tar-fs@^2.0.0, tar-fs@^2.1.0: +tar-fs@^2.0.0, tar-fs@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784" integrity sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng== diff --git a/src/index.ts b/src/index.ts index b82df0d..f209e30 100644 --- a/src/index.ts +++ b/src/index.ts @@ -130,7 +130,7 @@ function wrapExportDefaultDeclaration(path: NodePath) { function superJsonWithNext(): PluginObj { return { - name: 'replace gSSP', + name: 'add superjson to pages with prop getters', visitor: { Program(path, state) { const filename = @@ -138,27 +138,32 @@ function superJsonWithNext(): PluginObj { if (!filename.includes('pages' + nodePath.sep)) { return; } + const filesToSkip = ([] as string[]).concat( + ...['_app', '_document', '_error'].map((name) => [ + name + '.js', + name + '.jsx', + name + '.ts', + name + '.tsx', + ]) + ); + if (filesToSkip.some((name) => filename.includes(name))) { + return; + } const body = path.get('body'); - let foundGSSP = false; - body .filter((path) => t.isExportNamedDeclaration(path)) .forEach((path) => { transformPropGetters( path as NodePath, (decl) => { - foundGSSP = true; return t.callExpression(addWithSuperJSONPropsImport(path), [ decl, ]); } ); }); - if (!foundGSSP) { - return; - } const exportDefaultDeclaration = body.find((path) => t.isExportDefaultDeclaration(path) diff --git a/src/tools.tsx b/src/tools.tsx index db8b7f6..5441a11 100644 --- a/src/tools.tsx +++ b/src/tools.tsx @@ -3,11 +3,13 @@ import * as hoistNonReactStatics from 'hoist-non-react-statics'; import type { GetServerSideProps } from 'next'; import * as React from 'react'; -type SuperJSONResult = ReturnType; +type SuperJSONProps = ReturnType & { + _superjson: true; +}; export function withSuperJSONProps

( gssp: GetServerSideProps

-): GetServerSideProps { +): GetServerSideProps { return async function withSuperJSON(...args) { const result = await gssp(...args); @@ -17,7 +19,10 @@ export function withSuperJSONProps

( const { json, meta } = SuperJSON.serialize(result.props); - const props: SuperJSONResult = { json }; + const props: SuperJSONProps = { + json, + _superjson: true, + }; if (Boolean(meta)) { props.meta = meta; @@ -32,9 +37,9 @@ export function withSuperJSONProps

( export function withSuperJSONPage

( Page: React.ComponentType

-): React.ComponentType { - function WithSuperJSON(serializedProps: SuperJSONResult) { - if (!serializedProps.json) { +): React.ComponentType { + function WithSuperJSON(serializedProps: SuperJSONProps) { + if (!serializedProps._superjson) { const PageWithoutProps = Page as React.ComponentType<{}>; return ; } diff --git a/test/pages/unexported gSSP/code.js b/test/pages/unexported gSSP/code.js deleted file mode 100644 index e7ec478..0000000 --- a/test/pages/unexported gSSP/code.js +++ /dev/null @@ -1,18 +0,0 @@ -// is not exported, so this shouldn't be transformed -const getServerSideProps = async () => { - const products = [ - { - name: 'Hat', - publishedAt: new Date(0), - }, - ]; - return { - props: { - products, - }, - }; -}; - -export default function Page({ products }) { - return JSON.stringify(products); -} diff --git a/test/pages/unexported gSSP/output.js b/test/pages/unexported gSSP/output.js deleted file mode 100644 index e7ec478..0000000 --- a/test/pages/unexported gSSP/output.js +++ /dev/null @@ -1,18 +0,0 @@ -// is not exported, so this shouldn't be transformed -const getServerSideProps = async () => { - const products = [ - { - name: 'Hat', - publishedAt: new Date(0), - }, - ]; - return { - props: { - products, - }, - }; -}; - -export default function Page({ products }) { - return JSON.stringify(products); -}