Skip to content

Commit 5f701f2

Browse files
feat: dual publish CJS and ESM versions of lib (#52)
* feat: dual publish cjs and esm versions of lib * feat: add types export field * refactor: import named export * fix: add extensions for ESM support * fix: allow jest to resolve extensions correctly --------- Co-authored-by: cmorten <[email protected]> Co-authored-by: Craig Morten <[email protected]>
1 parent 487766f commit 5f701f2

File tree

134 files changed

+270
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+270
-200
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module.exports = {
22
root: true,
33
parser: "@typescript-eslint/parser",
4-
plugins: ["@typescript-eslint"],
54
extends: [
65
"eslint:recommended",
76
"plugin:@typescript-eslint/recommended",
7+
"plugin:require-extensions/recommended",
88
"prettier",
99
],
10+
plugins: ["@typescript-eslint", "require-extensions"],
1011
rules: { "sort-imports": ["error", { ignoreCase: true }] },
1112
};

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
},
1212
"[typescriptreact]": {
1313
"editor.defaultFormatter": "esbenp.prettier-vscode"
14+
},
15+
"[json]": {
16+
"editor.defaultFormatter": "esbenp.prettier-vscode"
1417
}
1518
}

jest.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// eslint-disable-next-line no-undef
22
module.exports = {
33
preset: "ts-jest",
4+
resolver: "ts-jest-resolver",
45
testEnvironment: "jsdom",
5-
roots: ["src"],
6+
roots: ["test"],
67
collectCoverageFrom: ["**/*.ts", "**/*.tsx"],
78
coveragePathIgnorePatterns: [],
89
coverageThreshold: {
@@ -13,5 +14,8 @@ module.exports = {
1314
statements: 98,
1415
},
1516
},
16-
setupFilesAfterEnv: ["<rootDir>/src/test/jest.setup.ts"],
17+
setupFilesAfterEnv: ["./test/jest.setup.ts"],
18+
transform: {
19+
"^.+\\.tsx?$": ["ts-jest", { tsconfig: "./tsconfig.test.json" }],
20+
},
1721
};

package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "@guidepup/virtual-screen-reader",
33
"version": "0.17.1",
44
"description": "Virtual Screen Reader driver for unit test automation.",
5-
"main": "lib/index.js",
65
"author": "Craig Morten <[email protected]>",
76
"license": "MIT",
87
"repository": {
@@ -20,12 +19,22 @@
2019
"a11y",
2120
"guidepup"
2221
],
22+
"main": "lib/cjs/index.js",
23+
"module": "lib/esm/index.js",
24+
"types": "lib/types/index.d.ts",
25+
"exports": {
26+
".": {
27+
"types": "./lib/cjs/index.d.ts",
28+
"import": "./lib/esm/index.js",
29+
"require": "./lib/cjs/index.js"
30+
}
31+
},
2332
"scripts": {
2433
"build": "yarn clean && yarn compile",
2534
"ci": "yarn clean && yarn lint && yarn test:coverage && yarn build",
2635
"clean": "rimraf lib",
27-
"compile": "tsc",
28-
"lint": "eslint src --ext .ts,.tsx --cache",
36+
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json && ./scripts/package.sh",
37+
"lint": "eslint src test --ext .js,.jsx,.ts,.tsx --cache",
2938
"lint:fix": "yarn lint --fix",
3039
"test": "jest",
3140
"test:coverage": "yarn test --coverage",
@@ -47,12 +56,14 @@
4756
"@typescript-eslint/parser": "^6.18.0",
4857
"eslint": "^8.56.0",
4958
"eslint-config-prettier": "^9.1.0",
59+
"eslint-plugin-require-extensions": "^0.1.3",
5060
"jest": "^29.7.0",
5161
"jest-environment-jsdom": "^29.7.0",
5262
"react": "^18.2.0",
5363
"react-dom": "^18.2.0",
5464
"rimraf": "^5.0.5",
5565
"ts-jest": "^29.1.1",
66+
"ts-jest-resolver": "^2.0.1",
5667
"ts-node": "^10.9.2",
5768
"typescript": "^5.3.3"
5869
}

scripts/package.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cat >lib/cjs/package.json <<!EOF
2+
{
3+
"type": "commonjs"
4+
}
5+
!EOF
6+
7+
cat >lib/esm/package.json <<!EOF
8+
{
9+
"type": "module"
10+
}
11+
!EOF

src/Virtual.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import {
22
AccessibilityNode,
33
createAccessibilityTree,
4-
} from "./createAccessibilityTree";
4+
} from './createAccessibilityTree.js';
55
import {
66
CommandOptions,
77
MacOSModifiers,
88
ScreenReader,
99
WindowsModifiers,
1010
} from "@guidepup/guidepup";
11-
import { commands, VirtualCommands } from "./commands";
11+
import { commands, VirtualCommands } from './commands/index.js';
1212
import {
1313
ERR_VIRTUAL_MISSING_CONTAINER,
1414
ERR_VIRTUAL_NOT_STARTED,
15-
} from "./errors";
16-
import { getLiveSpokenPhrase, Live } from "./getLiveSpokenPhrase";
17-
import { getElementFromNode } from "./getElementFromNode";
18-
import { getItemText } from "./getItemText";
19-
import { getSpokenPhrase } from "./getSpokenPhrase";
20-
import { observeDOM } from "./observeDOM";
21-
import { tick } from "./tick";
22-
import userEvent from "@testing-library/user-event";
23-
import { VirtualCommandArgs } from "./commands/types";
15+
} from './errors.js';
16+
import { getLiveSpokenPhrase, Live } from './getLiveSpokenPhrase.js';
17+
import { getElementFromNode } from './getElementFromNode.js';
18+
import { getItemText } from './getItemText.js';
19+
import { getSpokenPhrase } from './getSpokenPhrase.js';
20+
import { observeDOM } from './observeDOM.js';
21+
import { tick } from './tick.js';
22+
import { userEvent } from "@testing-library/user-event";
23+
import { VirtualCommandArgs } from './commands/types.js';
2424

2525
export interface StartOptions extends CommandOptions {
2626
/**

src/commands/getElementNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AccessibilityNode } from "../createAccessibilityTree";
2-
import { getElementFromNode } from "../getElementFromNode";
1+
import { AccessibilityNode } from '../createAccessibilityTree.js';
2+
import { getElementFromNode } from '../getElementFromNode.js';
33

44
export function getElementNode(accessibilityNode: AccessibilityNode): Element {
55
const { node } = accessibilityNode;

src/commands/getIndexByRoleAndAttributes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
AccessibilityNode,
33
END_OF_ROLE_PREFIX,
4-
} from "../createAccessibilityTree";
5-
import { matchesAccessibleAttributes, matchesRoles } from "./nodeMatchers";
6-
import type { AriaAttributes } from "./types";
4+
} from '../createAccessibilityTree.js';
5+
import { matchesAccessibleAttributes, matchesRoles } from './nodeMatchers.js';
6+
import type { AriaAttributes } from './types.js';
77

88
export interface GetIndexFilters {
99
/** Matches a node only if the node has any of these roles */

src/commands/getNextIndexByIdRefsAttribute.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getElementNode } from "./getElementNode";
2-
import { getIdRefsByAttribute } from "../getIdRefsByAttribute";
3-
import { getNodeByIdRef } from "../getNodeByIdRef";
4-
import { isElement } from "../isElement";
5-
import { VirtualCommandArgs } from "./types";
1+
import { getElementNode } from './getElementNode.js';
2+
import { getIdRefsByAttribute } from '../getIdRefsByAttribute.js';
3+
import { getNodeByIdRef } from '../getNodeByIdRef.js';
4+
import { isElement } from '../isElement.js';
5+
import { VirtualCommandArgs } from './types.js';
66

77
export interface GetNextIndexByIdRefsAttributeArgs extends VirtualCommandArgs {
88
attributeName: string;

src/commands/getNextIndexByRoleAndAttributes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
getIndexByRoleAndAttributes,
33
type GetIndexFilters,
4-
} from "./getIndexByRoleAndAttributes";
5-
import type { VirtualCommandArgs } from "./types";
4+
} from './getIndexByRoleAndAttributes.js';
5+
import type { VirtualCommandArgs } from './types.js';
66

77
export type GetNextIndexArgs = Omit<VirtualCommandArgs, "container">;
88

0 commit comments

Comments
 (0)