Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types reference to package.json exports #1184

Merged
merged 4 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"jest": "^27.0.6",
"jest-serializer-vue": "^2.0.2",
"lerna": "^4.0.0",
"rollup-plugin-copy": "^3.4.0",
"standard-version": "^9.3.1",
"rollup": "^3.19.1",
"vue": "^3.2.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/validators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.0.2",
"description": "Validators for Vuelidate",
"main": "dist/index.cjs",
"types": "index.d.ts",
"types": "dist/index.d.cts",
"module": "dist/index.mjs",
"unpkg": "dist/index.iife.min.js",
"jsdelivr": "dist/index.iife.min.js",
Expand Down Expand Up @@ -41,7 +41,6 @@
"access": "public"
},
"files": [
"dist",
"index.d.ts"
"dist"
]
}
3 changes: 2 additions & 1 deletion packages/validators/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { generateConfigFactory, generateOutputConfig } from '../../rollup.base.m
export default [
generateConfigFactory({
libraryName: 'VuelidateValidators',
outputConfigs: generateOutputConfig('index')
outputConfigs: generateOutputConfig('index'),
copyTypes: true
}),
generateConfigFactory({
libraryName: 'VuelidateValidators',
Expand Down
5 changes: 2 additions & 3 deletions packages/vuelidate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Simple, lightweight model-based validation for Vue.js",
"version": "2.0.2",
"main": "dist/index.cjs",
"types": "index.d.ts",
"types": "dist/index.d.cts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could changing the extension break older versions of typescript?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah maybe it could... So I looked at the documentation here and just pushed two changes to the package.json files based on the last example given on that page:

  1. Reverted "files" to include the uncopied index.d.ts file again, and reverted the "types" field to reference that file. So basically no change to those fields from before this PR.
  2. Updated the "exports" field to include the new type declaration files alongside the default import conditions.

I've found this a tad confusing (three identical type declaration files now?) so apologies if I've not got it right again, but arethetypeswrong seems to be happy. Ultimately all this PR now does is copy the type declaration twice, and reference those files in the package.json "exports". So maybe the solution was quite simple after all.

Maybe @andrewbranch can give us a final verification on if this is an OK resolution?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, TS versions/configurations that understand exports (and the newer file extensions) won’t look at this top-level types field since they’ll look in exports instead, so it’s best practice to leave the top-level types as a .d.ts (as long as you have exports) for the benefit of old TS versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the clarification, that's really helpful to know.

"module": "dist/index.mjs",
"unpkg": "dist/index.iife.min.js",
"jsdelivr": "dist/index.iife.min.js",
Expand All @@ -14,8 +14,7 @@
},
"license": "MIT",
"files": [
"dist",
"index.d.ts"
"dist"
],
"exports": {
".": {
Expand Down
3 changes: 2 additions & 1 deletion packages/vuelidate/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { generateConfigFactory, generateOutputConfig } from '../../rollup.base.m

export default generateConfigFactory({
libraryName: 'Vuelidate',
outputConfigs: generateOutputConfig('index')
outputConfigs: generateOutputConfig('index'),
copyTypes: true
})
28 changes: 27 additions & 1 deletion rollup.base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import terser from '@rollup/plugin-terser'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { babel } from '@rollup/plugin-babel'
import copy from 'rollup-plugin-copy'

export function generateOutputConfig (fileName = 'index', opts) {
return {
Expand All @@ -23,7 +24,12 @@ export function generateOutputConfig (fileName = 'index', opts) {
}
}

function generateConfigFactory ({ libraryName, input = 'src/index.js', outputConfigs }) {
function generateConfigFactory({
libraryName,
input = 'src/index.js',
outputConfigs,
copyTypes = false
}) {
/**
* @type {import('rollup').RollupOptions}
*/
Expand Down Expand Up @@ -58,6 +64,26 @@ function generateConfigFactory ({ libraryName, input = 'src/index.js', outputCon
terser()
)
}
if (copyTypes) {
opts.plugins.push(
copy({
hook: 'writeBundle',
flatten: true,
targets: [
{
src: 'index.d.ts',
dest: 'dist',
rename: 'index.d.cts'
},
{
src: 'index.d.ts',
dest: 'dist',
rename: 'index.d.mts'
}
]
})
)
}
return opts
}

Expand Down
70 changes: 68 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,21 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2"
integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==

"@types/fs-extra@^8.0.1":
version "8.1.2"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.2.tgz#7125cc2e4bdd9bd2fc83005ffdb1d0ba00cca61f"
integrity sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/graceful-fs@^4.1.2":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
Expand Down Expand Up @@ -2637,6 +2652,11 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=

"@types/minimatch@*":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==

"@types/minimatch@^3.0.3":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
Expand Down Expand Up @@ -3705,6 +3725,11 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

colorette@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==

columnify@^1.5.4:
version "1.5.4"
resolved "https://registry.yarnpkg.com/columnify/-/columnify-1.5.4.tgz#4737ddf1c7b69a8a7c340570782e947eec8e78bb"
Expand Down Expand Up @@ -4975,6 +5000,17 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==

fast-glob@^3.0.3:
version "3.2.12"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80"
integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
glob-parent "^5.1.2"
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-glob@^3.1.1, fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
Expand Down Expand Up @@ -5161,7 +5197,7 @@ fs-access@^1.0.1:
dependencies:
null-check "^1.0.0"

fs-extra@8.1.0:
fs-extra@8.1.0, fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
Expand Down Expand Up @@ -5443,6 +5479,20 @@ globals@^13.6.0, globals@^13.9.0:
dependencies:
type-fest "^0.20.2"

globby@10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22"
integrity sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==
dependencies:
"@types/glob" "^7.1.1"
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.0.3"
glob "^7.1.3"
ignore "^5.1.1"
merge2 "^1.2.3"
slash "^3.0.0"

globby@^11.0.2:
version "11.0.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.2.tgz#1af538b766a3b540ebfb58a32b2e2d5897321d83"
Expand Down Expand Up @@ -6049,6 +6099,11 @@ is-plain-object@^2.0.3, is-plain-object@^2.0.4:
dependencies:
isobject "^3.0.1"

is-plain-object@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-3.0.1.tgz#662d92d24c0aa4302407b0d45d21f2251c85f85b"
integrity sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==

is-plain-object@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
Expand Down Expand Up @@ -7134,7 +7189,7 @@ merge-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

merge2@^1.3.0, merge2@^1.4.1:
merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
Expand Down Expand Up @@ -8570,6 +8625,17 @@ rimraf@^3.0.0, rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rollup-plugin-copy@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz#f1228a3ffb66ffad8606e2f3fb7ff23141ed3286"
integrity sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==
dependencies:
"@types/fs-extra" "^8.0.1"
colorette "^1.1.0"
fs-extra "^8.1.0"
globby "10.0.1"
is-plain-object "^3.0.0"

rollup@^2.59.0:
version "2.64.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.64.0.tgz#f0f59774e21fbb56de438a37d06a2189632b207a"
Expand Down