Skip to content

Commit 60f4b11

Browse files
committed
- Enhancement: Add ESM distribution, with module property in package.json
- Refactoring: Add Rollup/Babel/Terser - Build: Have generator file produce consumable source files directly rather than logging to console - Linting: Switch from JSHint to ESLint (using rules, e.g., `indent` and `prefer-const`, in place on other estools project) - Testing: Convert coffeescript test files to ES6 - Testing: Add nyc - Testing: Check unmatched high surrogates and full coverage for AST expressions (further true `isExpression` and `isStatement`'s and false `isProblematicIfStatement`), bringing to 100% coverage - Travis: Drop previous versions for 10, 12, 14
1 parent 6281a63 commit 60f4b11

23 files changed

+1413
-1179
lines changed

.babelrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env"]
4+
]
5+
}

.eslintignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
dist
3+
4+
!.eslintrc.js
5+
coverage
6+
7+
src/es5-identifier.js
8+
src/es6-identifier.js

.eslintrc.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
module.exports = {
3+
env: {
4+
browser: true,
5+
commonjs: true,
6+
es6: true,
7+
node: true
8+
},
9+
extends: 'eslint:recommended',
10+
globals: {
11+
Atomics: 'readonly',
12+
SharedArrayBuffer: 'readonly'
13+
},
14+
overrides: [{
15+
files: '.eslintrc.js',
16+
parserOptions: {
17+
sourceType: 'script'
18+
},
19+
rules: {
20+
strict: 'error'
21+
}
22+
}, {
23+
files: 'test/**',
24+
globals: {
25+
expect: true
26+
},
27+
env: {
28+
mocha: true
29+
}
30+
}],
31+
parserOptions: {
32+
sourceType: 'module',
33+
ecmaVersion: 2018
34+
},
35+
rules: {
36+
semi: ['error'],
37+
indent: ['error', 4, { SwitchCase: 1 }],
38+
'prefer-const': ['error'],
39+
'no-var': ['error'],
40+
'prefer-destructuring': ['error'],
41+
'object-shorthand': ['error'],
42+
'object-curly-spacing': ['error', 'always'],
43+
quotes: ['error', 'single'],
44+
'quote-props': ['error', 'as-needed'],
45+
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
46+
'prefer-template': ['error']
47+
}
48+
};

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
dist
3+
coverage

.jshintrc

-16
This file was deleted.

.travis.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
language: node_js
22
node_js:
3-
- "0.10"
4-
- "0.11"
5-
6-
matrix:
7-
allow_failures:
8-
- node_js: "0.11"
3+
- 10
4+
- 12
5+
- 14

lib/ast.js

-144
This file was deleted.

lib/code.js

-135
This file was deleted.

package.json

+28-6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
"description": "utility box for ECMAScript language tools",
44
"homepage": "https://github.com/estools/esutils",
55
"bugs": "https://github.com/estools/esutils/issues",
6-
"main": "lib/utils.js",
6+
"main": "dist/esutils.min.js",
7+
"module": "dist/esutils.esm.min.js",
78
"version": "2.0.4-dev",
89
"engines": {
910
"node": ">=0.10.0"
1011
},
1112
"directories": {
12-
"lib": "./lib"
13+
"lib": "./dist"
1314
},
1415
"files": [
1516
"LICENSE.BSD",
1617
"README.md",
17-
"lib"
18+
"dist"
1819
],
1920
"keywords": [
2021
"ecmascript"
@@ -33,18 +34,39 @@
3334
},
3435
"dependencies": {},
3536
"devDependencies": {
37+
"@babel/core": "^7.9.0",
38+
"@babel/preset-env": "^7.9.5",
39+
"@babel/register": "^7.9.0",
40+
"@rollup/plugin-babel": "^5.0.0",
3641
"chai": "~4.2.0",
3742
"coffeescript": "^2.5.1",
38-
"jshint": "2.11.0",
43+
"eslint": "^6.8.0",
3944
"mocha": "~7.1.2",
45+
"nyc": "^15.0.1",
4046
"regenerate": "~1.4.0",
47+
"rollup": "^2.7.3",
48+
"rollup-plugin-terser": "^5.3.0",
4149
"unicode-13.0.0": "^0.8.0"
4250
},
4351
"license": "BSD-2-Clause",
52+
"nyc": {
53+
"branches": 100,
54+
"lines": 100,
55+
"functions": 100,
56+
"statements": 100,
57+
"reporter": [
58+
"html",
59+
"text"
60+
],
61+
"exclude": [
62+
"test"
63+
]
64+
},
4465
"scripts": {
66+
"build": "rollup -c",
4567
"test": "npm run lint && npm run unit-test",
46-
"lint": "jshint lib/*.js",
47-
"unit-test": "mocha --require chai/register-expect --require coffeescript/register test/**",
68+
"lint": "eslint .",
69+
"unit-test": "nyc mocha --require @babel/register --require chai/register-expect --require coffeescript/register test/**",
4870
"generate-regex": "node tools/generate-identifier-regex.js"
4971
}
5072
}

rollup.config.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { terser } from 'rollup-plugin-terser';
2+
3+
import babel from '@rollup/plugin-babel';
4+
5+
/**
6+
* @external RollupConfig
7+
* @type {PlainObject}
8+
* @see {@link https://rollupjs.org/guide/en#big-list-of-options}
9+
*/
10+
11+
/**
12+
* @param {PlainObject} [config= {}]
13+
* @param {boolean} [config.minifying=false]
14+
* @param {string} [config.format='umd']
15+
* @returns {external:RollupConfig}
16+
*/
17+
function getRollupObject ({ minifying, format = 'umd' } = {}) {
18+
const nonMinified = {
19+
input: 'src/utils.js',
20+
output: {
21+
format,
22+
sourcemap: minifying,
23+
file: `dist/esutils${
24+
format === 'umd' ? '' : `.${format}`
25+
}${minifying ? '.min' : ''}.js`,
26+
name: 'esutils'
27+
},
28+
plugins: [
29+
babel({
30+
babelHelpers: 'bundled'
31+
})
32+
]
33+
};
34+
if (minifying) {
35+
nonMinified.plugins.push(terser());
36+
}
37+
return nonMinified;
38+
}
39+
40+
export default [
41+
getRollupObject({ minifying: true, format: 'umd' }),
42+
getRollupObject({ minifying: false, format: 'umd' }),
43+
getRollupObject({ minifying: true, format: 'esm' }),
44+
getRollupObject({ minifying: false, format: 'esm' })
45+
];

0 commit comments

Comments
 (0)