Skip to content

Commit 0821e06

Browse files
committed
Merge pull request #117 from apache/esm-tests
2 parents 5b19264 + bed5006 commit 0821e06

Some content is hidden

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

49 files changed

+495
-757
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
extends: ['eslint:recommended', 'plugin:import/recommended', 'prettier'],
2626
plugins: ['import', 'prettier'],
2727
rules: {
28-
'import/extensions': ['error', 'never'],
28+
'import/extensions': ['error', 'ignorePackages'],
2929
'import/first': 'error',
3030
'import/newline-after-import': 'error',
3131
'import/no-absolute-path': 'error',

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.d.ts
22
!/packages/**/src/**/*.d.ts
33
*.d.ts.map
4-
.nyc_output
54
coverage
65
docs
76
node_modules

.mocharc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
module.exports = {
2424
extension: ['.ts'],
2525
ignore: ['node_modules'],
26-
require: ['./babel-register.js', 'global-jsdom/register'],
26+
loader: 'babel-register-esm',
27+
require: ['global-jsdom/register'],
2728
timeout: 5000,
2829
watchFiles: [
2930
'./test/**/*.ts',

babel-register.js

-26
This file was deleted.

babel.config.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
*/
2222

2323
const path = require('path');
24-
const { DEFAULT_EXTENSIONS } = require('@babel/core');
24+
const { resolvePath } = require('babel-plugin-module-resolver');
25+
26+
const packagePath = path.join(__dirname, 'packages');
2527

2628
module.exports = (api) => {
2729
const ENV = api.env();
@@ -33,8 +35,8 @@ module.exports = (api) => {
3335
// Use minimal syntax fixes where possible
3436
// Note: This setting may become the default in Babel 8.
3537
bugfixes: true,
36-
// Transform module syntax if necessary.
37-
modules: TEST ? 'commonjs' : false,
38+
// Do not transform module syntax.
39+
modules: false,
3840
};
3941

4042
// Options for the @babel/typescript preset.
@@ -45,37 +47,40 @@ module.exports = (api) => {
4547
onlyRemoveTypeImports: true,
4648
};
4749

48-
const addImportExtensionOptions = {
49-
extension: DEV || TEST ? 'ts' : 'js',
50-
};
51-
5250
// Options for the module-resolver plugin.
5351
// Used for resolving source files during development.
5452
const resolverOptions = {
55-
alias: {
56-
...(DEV || TEST
57-
? {
53+
...(DEV || TEST
54+
? {
55+
alias: {
5856
'^@apache-annotator/([^/]+)$': ([, name]) =>
59-
path.join(__dirname, 'packages', name, '/src/index.ts'),
60-
}
61-
: null),
62-
},
63-
extensions: ['.ts', '.tsx', ...DEFAULT_EXTENSIONS],
57+
path.join(packagePath, name, 'src', 'index.ts'),
58+
},
59+
resolvePath(sourcePath, currentFile, opts) {
60+
if (
61+
currentFile.startsWith(packagePath) &&
62+
currentFile.endsWith('.ts') &&
63+
sourcePath.startsWith('.') &&
64+
sourcePath.endsWith('.js')
65+
) {
66+
return sourcePath.replace(/\.js$/, '.ts');
67+
}
68+
return resolvePath(sourcePath, currentFile, opts);
69+
},
70+
}
71+
: null),
6472
};
6573

6674
// Options for the @babel/transform-runtime plugin.
6775
const runtimeOptions = {
6876
// Use corejs version 3.
6977
corejs: { version: 3, proposals: true },
70-
// Use helpers formatted for the target environment.
71-
useESModules: !TEST,
7278
};
7379

7480
return {
7581
plugins: [
7682
'@babel/plugin-proposal-class-properties',
7783
['@babel/transform-runtime', runtimeOptions],
78-
['add-import-extension', addImportExtensionOptions],
7984
['module-resolver', resolverOptions],
8085
'preserve-comment-header',
8186
...(TEST ? ['istanbul'] : []),

nyc.config.js

-29
This file was deleted.

package.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"build:js": "lerna exec --parallel -- babel -d lib -s -x .ts --env-name production --root-mode upward src",
2020
"build:misc": "lerna exec --parallel -- cp ../../DISCLAIMER-WIP ../../LICENSE ../../NOTICE ../../README.md .",
2121
"build:types": "tsc --build",
22-
"clean": "tsc --build --clean && lerna exec -- rimraf DISCLAIMER-WIP LICENSE NOTICE README.md lib && rimraf .nyc_output coverage docs web/dist *.tsbuildinfo",
22+
"clean": "tsc --build --clean && lerna exec -- rimraf DISCLAIMER-WIP LICENSE NOTICE README.md coverage docs lib web/dist",
2323
"docs": "tsc --build && typedoc",
2424
"lint": "eslint .",
2525
"prepublishOnly": "yarn run build",
2626
"publish": "lerna publish",
2727
"publish:ci": "yarn run publish --canary --exact --force-publish '*' --no-verify-access --yes minor",
2828
"start": "yarn run web:server",
29-
"test": "cross-env BABEL_ENV=test nyc mocha packages/**/*.test.ts",
29+
"test": "cross-env BABEL_ENV=test c8 -a -r html -r text mocha packages/**/*.test.ts",
30+
"test:watch": "cross-env BABEL_ENV=test mocha -p -w packages/**/*.test.ts",
3031
"validate": "cross-env BABEL_ENV=test mocha test/**/*.test.ts",
3132
"web:build": "webpack --config=web/webpack.config.js --mode development",
3233
"web:server": "webpack-dev-server --config=web/webpack.config.js --hot --mode development"
@@ -38,20 +39,18 @@
3839
"@babel/plugin-transform-runtime": "^7.13.10",
3940
"@babel/preset-env": "^7.13.12",
4041
"@babel/preset-typescript": "^7.13.0",
41-
"@babel/register": "^7.13.14",
42-
"@types/chai": "^4.2.11",
43-
"@types/mocha": "^7.0.2",
42+
"@types/mocha": "^9.0.0",
4443
"@types/node-fetch": "^2.5.7",
4544
"@types/resolve": "^1.17.0",
4645
"@typescript-eslint/eslint-plugin": "^4.20.0",
4746
"@typescript-eslint/parser": "^4.20.0",
4847
"ajv": "^6.11.0",
4948
"babel-loader": "^8.0.5",
50-
"babel-plugin-add-import-extension": "^1.4.1",
5149
"babel-plugin-istanbul": "^6.0.0",
5250
"babel-plugin-module-resolver": "^4.0.0",
5351
"babel-plugin-preserve-comment-header": "^1.0.1",
54-
"chai": "^4.2.0",
52+
"babel-register-esm": "^1.2.1",
53+
"c8": "^7.10.0",
5554
"concurrently": "^5.3.0",
5655
"cross-env": "^6.0.3",
5756
"eslint": "^7.5.0",
@@ -66,9 +65,8 @@
6665
"jsdom": "^16.2.2",
6766
"lerna": "^3.20.2",
6867
"lint-staged": "^10.0.2",
69-
"mocha": "^8.0.1",
68+
"mocha": "^9.1.3",
7069
"node-fetch": "^2.5.0",
71-
"nyc": "^15.0.0",
7270
"prettier": "^2.0.5",
7371
"resolve": "^1.15.0",
7472
"rimraf": "^3.0.0",
@@ -80,7 +78,7 @@
8078
"webpack-dev-server": "^3.10.1"
8179
},
8280
"engines": {
83-
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0",
81+
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0 || ^17.0",
8482
"yarn": "^1.5.0"
8583
}
8684
}

packages/apache-annotator/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@babel/runtime-corejs3": "^7.13.10"
2121
},
2222
"engines": {
23-
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0"
23+
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0 || ^17.0"
2424
},
2525
"publishConfig": {
2626
"access": "public"

packages/dom/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"dependencies": {
1717
"@apache-annotator/selector": "^0.2.0",
1818
"@babel/runtime-corejs3": "^7.13.10",
19-
"optimal-select": "^4.0.1"
19+
"@medv/finder": "^2.1.0"
2020
},
2121
"engines": {
22-
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0"
22+
"node": "^12.20 || ^14.15 || ^15.4 || ^16.0 || ^17.0"
2323
},
2424
"publishConfig": {
2525
"access": "public"

packages/dom/src/css.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
* under the License.
2121
*/
2222

23-
import optimalSelect from 'optimal-select';
23+
import { finder } from '@medv/finder';
2424
import type { CssSelector, Matcher } from '@apache-annotator/selector';
25-
import { ownerDocument } from './owner-document';
26-
import { toRange } from './to-range';
25+
import { ownerDocument } from './owner-document.js';
26+
import { toRange } from './to-range.js';
2727

2828
/**
2929
* Find the elements corresponding to the given {@link
@@ -112,9 +112,9 @@ export function createCssSelectorMatcher(
112112
*/
113113
export async function describeCss(
114114
element: HTMLElement,
115-
scope: Node = element.ownerDocument,
115+
scope: Element = element.ownerDocument.documentElement,
116116
): Promise<CssSelector> {
117-
const selector = optimalSelect(element, { root: scope });
117+
const selector = finder(element, { root: scope });
118118
return {
119119
type: 'CssSelector',
120120
value: selector,

packages/dom/src/highlight-text.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
* under the License.
2121
*/
2222

23-
import { ownerDocument } from './owner-document';
24-
import { toRange } from './to-range';
23+
import { ownerDocument } from './owner-document.js';
24+
import { toRange } from './to-range.js';
2525

2626
/**
2727
* Wrap each text node in a given Node or Range with a `<mark>` or other

packages/dom/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
* under the License.
2121
*/
2222

23-
export * from './css';
24-
export * from './range';
25-
export * from './text-quote';
26-
export * from './text-position';
27-
export * from './highlight-text';
23+
export * from './css.js';
24+
export * from './range/index.js';
25+
export * from './text-quote/index.js';
26+
export * from './text-position/index.js';
27+
export * from './highlight-text.js';

packages/dom/src/normalize-range.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* under the License.
2121
*/
2222

23-
import { ownerDocument } from './owner-document';
23+
import { ownerDocument } from './owner-document.js';
2424

2525
/**
2626
* TextRange is a Range that guarantees to always have Text nodes as its start

packages/dom/src/optimal-select.d.ts

-31
This file was deleted.

packages/dom/src/range/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
* under the License.
2121
*/
2222

23-
export * from './match';
23+
export * from './match.js';

packages/dom/src/range/match.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import type {
2525
RangeSelector,
2626
Selector,
2727
} from '@apache-annotator/selector';
28-
import { ownerDocument } from '../owner-document';
29-
import { toRange } from '../to-range';
30-
import { cartesian } from './cartesian';
28+
import { ownerDocument } from '../owner-document.js';
29+
import { toRange } from '../to-range.js';
30+
import { cartesian } from './cartesian.js';
3131

3232
/**
3333
* Find the range(s) corresponding to the given {@link RangeSelector}.

packages/dom/src/text-node-chunker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222

2323
import type { Chunk, Chunker, ChunkRange } from '@apache-annotator/selector';
24-
import { normalizeRange } from './normalize-range';
25-
import { ownerDocument } from './owner-document';
26-
import { toRange } from './to-range';
24+
import { normalizeRange } from './normalize-range.js';
25+
import { ownerDocument } from './owner-document.js';
26+
import { toRange } from './to-range.js';
2727

2828
export interface PartialTextNode extends Chunk<string> {
2929
readonly node: Text;

packages/dom/src/text-position/describe.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
import type { TextPositionSelector } from '@apache-annotator/selector';
2424
import { describeTextPosition as abstractDescribeTextPosition } from '@apache-annotator/selector';
25-
import { ownerDocument } from '../owner-document';
26-
import { TextNodeChunker } from '../text-node-chunker';
27-
import { toRange } from '../to-range';
25+
import { ownerDocument } from '../owner-document.js';
26+
import { TextNodeChunker } from '../text-node-chunker.js';
27+
import { toRange } from '../to-range.js';
2828

2929
/**
3030
* Returns a {@link TextPositionSelector} that points at the target text within

packages/dom/src/text-position/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
* under the License.
2121
*/
2222

23-
export * from './describe';
24-
export * from './match';
23+
export * from './describe.js';
24+
export * from './match.js';

packages/dom/src/text-position/match.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import type { Matcher, TextPositionSelector } from '@apache-annotator/selector';
2424
import { textPositionSelectorMatcher as abstractTextPositionSelectorMatcher } from '@apache-annotator/selector';
25-
import { TextNodeChunker } from '../text-node-chunker';
25+
import { TextNodeChunker } from '../text-node-chunker.js';
2626

2727
/**
2828
* Find the range of text corresponding to the given {@link

0 commit comments

Comments
 (0)