-
Notifications
You must be signed in to change notification settings - Fork 264
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
export package.json from module #1542
Conversation
❌ Deploy Preview for vue-test-utils-docs failed.
|
@@ -13,7 +13,8 @@ | |||
"browser": "./dist/vue-test-utils.browser.js", | |||
"require": "./dist/vue-test-utils.cjs.js", | |||
"default": "./dist/vue-test-utils.cjs.js" | |||
} | |||
}, | |||
"./package.json": "./package.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be in the exports section no?
But anyway, I'm not sure that's really useful and that we want to do that: package.json
is not part of the public API we want to expose.
What are you trying to achieve with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I put it in the wrong place? This comment in the linked issues indicates that it should be a sibling of the "."
entry.
As for what I'm trying to achieve, like I said in the PR description - I have some tooling I'm working on which is designed to assist with an upgrade from VTU 1 to VTU 2 (and which I would like to soon publish as open-source) which wants reads the installed version of VTU in order to decide how it should act. Since VTU hasn't been explicitly exporting its version number as part of its public interface anywhere I'm aware of I was trying to get it from the package.json
.
This comment suggests that it's not that uncommon for tooling ecosystems to read package.json
. Indeed, it's what eslint-plugin-jest
does in order to detect which deprecation warnings it should emit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is this would also go in exports
, Cypress does something similar:
https://github.com/cypress-io/cypress/blob/develop/cli/package.json#L119-L134.
That said, I am not super clear on why we need to list it in exports
- wouldn't you just do const pkg = require('@vue/test-utils/package.json')
? That would work for both VTU v1 and v2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, that is exactly what I am trying to do, and cause of the exports that are now defined, I can't (hence the PR). try it yourself:
snooz@C02FL4M5Q05N public-dashboard % node
Welcome to Node.js v14.19.1.
Type ".help" for more information.
> require('@vue/test-utils/package.json')
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /SNIP/node_modules/@vue/test-utils/package.json
at new NodeError (internal/errors.js:322:7)
at throwExportsNotFound (internal/modules/esm/resolve.js:332:9)
at packageExportsResolve (internal/modules/esm/resolve.js:565:3)
at resolveExports (internal/modules/cjs/loader.js:450:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at REPL9:1:1 {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird! I swear this used to work... I didn't even know Node 14 supported exports
.
I just tested, I think it should be:
{
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/vue-test-utils.esm-bundler.mjs",
"browser": "./dist/vue-test-utils.browser.js",
"require": "./dist/vue-test-utils.cjs.js",
"default": "./dist/vue-test-utils.cjs.js"
},
"./package.json": "./package.json"
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: that's exactly what you did, LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man, I was gonna say... am I hallucinating? I did make this edit in github's UI but I triple checked it so many times 😆
See nodejs/modules#445 for context. This package doesn't export its own package.json ever since the exports were added, which breaks some tooling I've written to help me with upgrading from VTU 1 to VTU 2 that tries to read the package.json to get the installed version.