Skip to content

feat: add esm support #55

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 1 commit into from
May 24, 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
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["@babel/preset-env", { "targets": { "node": "8" } }]],
["@babel/preset-env", { "targets": { "node": "12" } }]],
Copy link
Member Author

Choose a reason for hiding this comment

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

This is our supported version according to pkg.json

"plugins": [
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-transform-react-jsx", { "pragma": "h" }],
Expand Down
15 changes: 15 additions & 0 deletions .babelrc.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": { "node": "12" }
}
]
],
"plugins": [
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-transform-react-jsx", { "pragma": "h" }]
]
}
2 changes: 1 addition & 1 deletion dont-clean-up-after-each.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
process.env.PTL_SKIP_AUTO_CLEANUP = true;
process.env.PTL_SKIP_AUTO_CLEANUP = true
22 changes: 19 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
"name": "@testing-library/preact",
"version": "0.0.0-semantically-released",
"description": "Simple and complete Preact DOM testing utilities that encourage good testing practices.",
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./dist/esm/index.js",
"browser": "./dist/cjs/index.js"
},
"./pure": {
"types": "./pure.d.ts",
"import": "./dist/esm/pure.js",
"browser": "./dist/cjs/pure.js"
Comment on lines +10 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

ESM output as .js with no "type": "module"? Any reason not to support Node here?

"browser" being CJS also looks a bit odd to me, though could be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I realised a moment ago as well, we have to output these as mjs as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, apologies then!

Thanks for doing all of this!

Copy link
Member Author

Choose a reason for hiding this comment

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

No need to apologize, was a very good shout, thanks 😄

}
},
"license": "MIT",
"author": "Rahim Alwer <[email protected]>",
"homepage": "https://github.com/testing-library/preact-testing-library#readme",
Expand Down Expand Up @@ -33,13 +46,16 @@
"dist",
"dont-cleanup-after-each.js",
"pure.js",
"types/index.d.ts"
"types/index.d.ts",
"pure.d.ts"
],
"scripts": {
"toc": "doctoc README.md",
"lint": "eslint src/**/*.js --fix",
"clean": "rimraf dist",
"build": " babel src --out-dir dist --ignore '**/__tests__/**,**/__mocks__/**'",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "babel src --out-dir dist/cjs --config-file ./.babelrc --ignore '**/__tests__/**,**/__mocks__/**'",
"build:esm": "babel src --no-babelrc --out-dir dist/esm --config-file ./.babelrc.esm.json --ignore '**/__tests__/**,**/__mocks__/**'",
"test": "jest src/__tests__ ",
"test:watch": "npm test --watch",
"test:update": "npm test --updateSnapshot --coverage",
Expand Down
2 changes: 1 addition & 1 deletion pure.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Makes it so people can import from '@testing-library/preact/pure'
module.exports = require('./dist/pure');
module.exports = require('./dist/pure')