Skip to content

build: add esm bundle #1990

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

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
"version": "1.3.0",
"description": "Utilities for testing Vue components.",
"main": "dist/vue-test-utils.js",
"module": "dist/vue-test-utils.esm.js",
"exports": {
".": {
"import": {
"node": "./dist/vue-test-utils.js",
"require": "./dist/vue-test-utils.js",
"default": "./dist/vue-test-utils.esm.js"
}
}
},
Comment on lines +7 to +15

Choose a reason for hiding this comment

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

Why was this added as-is, i.e. why with the import nesting? That breaks importing @vue/test-utils v1.3.1 in jest (non esm) for me with:

Cannot find module '@vue/test-utils' from '...'

    > 1 | import { createLocalVue } from '@vue/test-utils'

when I remove the import like this:

  "exports": {
    ".": {
      "node": "./dist/vue-test-utils.js",
      "require": "./dist/vue-test-utils.js",
      "default": "./dist/vue-test-utils.esm.js"
    }
  },

then it works again.

The comment that suggested to add the exports key was referencing this, i.e. the vue3 version of test-utils:

https://github.com/vuejs/test-utils/blob/main/package.json#L9-L15

There is no nested import there.

Maybe the following would be best?

  "exports": {
    ".": {
      "import": "./dist/vue-test-utils.esm.js",
      "require": "./dist/vue-test-utils.js",
      "default": "./dist/vue-test-utils.js"
    }
  },

That would be the most similar to what is done in vue/test-utils right now.

Copy link
Member

Choose a reason for hiding this comment

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

Uh oh, did not realize this broke things. I'll patch this right now.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Done
https://github.com/vuejs/vue-test-utils/releases/tag/v1.3.2

Gave it a quick test, seems okay, LMK if you run into any problems.

Choose a reason for hiding this comment

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

Thanks that fixed it!

"types": "types/index.d.ts",
"files": [
"dist/*.js",
Expand Down
9 changes: 9 additions & 0 deletions packages/test-utils/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ const rollupOptionsBuild = [
'vue-template-compiler': 'VueTemplateCompiler'
}
},
{
file: 'dist/vue-test-utils.esm.js',
format: 'esm',
name: 'VueTestUtils',
globals: {
vue: 'Vue',
'vue-template-compiler': 'VueTemplateCompiler'
}
},
{
file: 'dist/vue-test-utils.umd.js',
format: 'umd',
Expand Down