Skip to content

Commit 0897630

Browse files
authored
feat: export mjs and cjs (#155)
* feat: export mjs and cjs replaces interop cjs * build just like we would on release * fix jest tests * Add smoke test for kcd-scripts build * fix wpt tests
1 parent 2d4c118 commit 0897630

11 files changed

Lines changed: 114 additions & 8 deletions

File tree

.babelrc.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
module.exports = {
22
presets: [
3-
require.resolve("@babel/preset-env"),
3+
[
4+
require.resolve("@babel/preset-env"),
5+
// for jest we need to transpile esmodules
6+
// otherwise transform-commonjs takes care of the correct module syntax
7+
{ modules: process.env.NODE_ENV === "test" ? "auto" : false }
8+
],
49
require.resolve("@babel/preset-typescript")
5-
]
10+
],
11+
env: {
12+
cjs: {
13+
plugins: [
14+
[
15+
require.resolve("@babel/plugin-transform-modules-commonjs"),
16+
// helps rollup identify exports but also means __esmodule is enumerated
17+
// not aware of a use case for enumerating imports though
18+
{ loose: true }
19+
]
20+
]
21+
}
22+
}
623
};

.codesandbox/ci.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"buildCommand": "build:source",
2+
"buildCommand": "build",
33
"sandboxes": ["new"],
44
"silent": true
55
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ tests/cypress/videos
55
# jest results
66
/junit.xml
77
/coverage
8-
/yarn-error.log
8+
/yarn-error.log
9+
/dom-accessibility-api.tgz

azure-pipelines.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ steps:
3535
yarn build
3636
displayName: "Build"
3737
38+
- script: |
39+
npm pack
40+
mv dom-accessibility-api-*.tgz dom-accessibility-api.tgz
41+
displayName: "Prepare smoke tests of build"
42+
43+
- script: yarn start
44+
displayName: "kcd-rollup smoke tests of build"
45+
workingDirectory: tests/build/fixtures/kcd-rollup
46+
3847
- script: yarn test:ci
3948
displayName: "Run jest tests"
4049

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "dom-accessibility-api",
33
"version": "0.4.1",
44
"main": "dist/index.js",
5-
"types": "dist/index.d.ts",
5+
"type": "commonjs",
6+
"exports": {
7+
"import": "dist/index.mjs",
8+
"require": "dist/index.js"
9+
},
610
"license": "MIT",
711
"repository": {
812
"type": "git",
@@ -16,9 +20,10 @@
1620
"dist/"
1721
],
1822
"scripts": {
19-
"build": "yarn build:clean && yarn build:source && yarn build:types",
23+
"build": "yarn build:clean && yarn build:source && yarn build:source:cjs && yarn build:types",
2024
"build:clean": "rimraf dist",
21-
"build:source": "babel sources --extensions \".ts\" --ignore \"**/__tests__/**/*\" --out-dir dist/ --source-maps",
25+
"build:source": "babel sources --extensions \".ts\" --ignore \"**/__tests__/**/*\" --out-dir dist/ --out-file-extension=.mjs --source-maps",
26+
"build:source:cjs": "cross-env BABEL_ENV=cjs babel sources --extensions \".ts\" --ignore \"**/__tests__/**/*\" --out-dir dist/ --out-file-extension=.js --source-maps",
2227
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
2328
"format": "prettier \"**/*.{json,js,md,ts,yml}\" --write --ignore-path .prettierignore",
2429
"lint": "eslint --report-unused-disable-directives \"sources/**/*.ts\"",
@@ -40,6 +45,7 @@
4045
"devDependencies": {
4146
"@babel/cli": "^7.8.4",
4247
"@babel/core": "^7.8.7",
48+
"@babel/plugin-transform-modules-commonjs": "^7.9.0",
4349
"@babel/preset-env": "^7.8.7",
4450
"@babel/preset-typescript": "^7.8.3",
4551
"@changesets/changelog-github": "^0.2.2",
@@ -49,6 +55,7 @@
4955
"@typescript-eslint/eslint-plugin": "^2.23.0",
5056
"@typescript-eslint/parser": "^2.23.0",
5157
"concurrently": "^5.1.0",
58+
"cross-env": "^7.0.2",
5259
"cypress": "^4.1.0",
5360
"eslint": "^6.8.0",
5461
"jest": "^25.1.0",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# kcd scripts output
2+
dist/
3+
yarn.lock
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# kdc-rollup
2+
3+
How `@testing-library/dom` builds.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "build-fixture-kcd-rollup",
3+
"private": true,
4+
"dependencies": {
5+
"dom-accessibility-api": "file:../../../../dom-accessibility-api.tgz",
6+
"kcd-scripts": "^5.5.0"
7+
},
8+
"scripts": {
9+
"start": "yarn install --no-lockfile && yarn build",
10+
"build": "kcd-scripts build --bundle --no-clean"
11+
}
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const rollupConfig = require("kcd-scripts/dist/config/rollup.config");
2+
3+
// the exports in this library should always be named for all formats.
4+
rollupConfig.output[0].exports = "named";
5+
module.exports = rollupConfig;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { computeAccessibleName } from "dom-accessibility-api";
2+
3+
if (typeof computeAccessibleName !== "function") {
4+
throw new TypeError();
5+
}

0 commit comments

Comments
 (0)