Skip to content

Commit 0e1b784

Browse files
authored
feat(apidom-core): convert to ESM (#1177)
Refs #930
1 parent b25e9f0 commit 0e1b784

File tree

13 files changed

+32
-40
lines changed

13 files changed

+32
-40
lines changed

packages/apidom-ast/test/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"files": ["mocha-bootstrap.cjs"],
3131
"parserOptions": {
3232
"sourceType": "script"
33+
},
34+
"rules": {
35+
"@typescript-eslint/no-var-requires": 0
3336
}
3437
}]
3538
}

packages/apidom-core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/cjs
44
/types
55
/NOTICE
6+
/swagger-api-apidom-core-*.tgz

packages/apidom-core/.mocharc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/apidom-core/.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recursive": true,
3+
"spec": "test/**/*.ts",
4+
"file": ["test/mocha-bootstrap.cjs"]
5+
}

packages/apidom-core/config/rollup/types.dist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ const config = [
88
external: ['Function/Curry'],
99
},
1010
];
11+
1112
export default config;

packages/apidom-core/config/webpack/browser.config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
2-
3-
const path = require('path');
4-
const { nonMinimizeTrait, minimizeTrait } = require('./traits.config');
1+
import path from 'node:path';
2+
import { nonMinimizeTrait, minimizeTrait } from './traits.config.js';
53

64
const browser = {
75
mode: 'production',
@@ -69,4 +67,4 @@ const browserMin = {
6967
...minimizeTrait,
7068
};
7169

72-
module.exports = [browser, browserMin];
70+
export default [browser, browserMin];

packages/apidom-core/config/webpack/traits.config.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
'use strict';
1+
import webpack from 'webpack';
2+
import TerserPlugin from 'terser-webpack-plugin';
23

3-
const webpack = require('webpack');
4-
const TerserPlugin = require('terser-webpack-plugin');
5-
6-
const nonMinimizeTrait = {
4+
export const nonMinimizeTrait = {
75
optimization: {
86
minimize: false,
97
usedExports: false,
108
concatenateModules: false,
119
},
1210
};
1311

14-
const minimizeTrait = {
12+
export const minimizeTrait = {
1513
plugins: [
1614
new webpack.LoaderOptionsPlugin({
1715
minimize: true,
@@ -32,8 +30,3 @@ const minimizeTrait = {
3230
],
3331
},
3432
};
35-
36-
module.exports = {
37-
nonMinimizeTrait,
38-
minimizeTrait,
39-
};

packages/apidom-core/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
"publishConfig": {
66
"registry": "https://npm.pkg.github.com"
77
},
8-
"main": "cjs/index.js",
9-
"module": "es/index.js",
10-
"jsnext:main": "es/index.js",
8+
"type": "module",
119
"unpkg": "dist/apidom.browser.min.js",
1210
"types": "types/dist.d.ts",
11+
"exports": {
12+
"import": "./es/index.js",
13+
"require": "./cjs/index.cjs"
14+
},
1315
"scripts": {
1416
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
1517
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --root-mode 'upward'",
16-
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --root-mode 'upward'",
18+
"build:cjs": "cross-env BABEL_ENV=cjs-new babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
1719
"build:umd:browser": "cross-env BABEL_ENV=browser BROWSERSLIST_ENV=production webpack --config config/webpack/browser.config.js --progress",
1820
"lint": "eslint ./",
1921
"lint:fix": "eslint ./ --fix",
2022
"clean": "rimraf ./es ./cjs ./dist ./types",
2123
"typescript:check-types": "tsc --noEmit",
2224
"typescript:declaration": "tsc -p declaration.tsconfig.json && copyfiles -u 2 ../@types/*.d.ts ./types && rollup -c config/rollup/types.dist.js",
23-
"test": "cross-env BABEL_ENV=cjs mocha",
25+
"test": "cross-env NODE_ENV=test BABEL_ENV=cjs-new mocha",
2426
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 BABEL_ENV=cjs mocha",
2527
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
2628
"postpack": "rimraf NOTICE LICENSES"

packages/apidom-core/src/.mocharc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/apidom-core/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ export {
4949
hasElementSourceMap,
5050
includesSymbols,
5151
includesClasses,
52-
} from './predicates';
52+
} from './predicates/index';
5353
export { default as createPredicate } from './predicates/helpers';
5454

55-
export { filter, reject, find, findAtOffset, some, traverse, parents } from './traversal';
55+
export { filter, reject, find, findAtOffset, some, traverse, parents } from './traversal/index';
5656
export {
5757
visit,
5858
BREAK,
5959
mergeAllVisitors,
6060
getNodeType,
6161
keyMapDefault as keyMap,
6262
} from './traversal/visitor';
63-
export { transclude, default as Transcluder } from './transcluder';
63+
export { transclude, default as Transcluder } from './transcluder/index';
6464
export { dereference } from './util';
6565

6666
/**

0 commit comments

Comments
 (0)