Skip to content

Commit d7b8a33

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 d7b8a33

23 files changed

+1414
-1179
lines changed

.babelrc.json

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

.eslintignore

Lines changed: 8 additions & 0 deletions
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

Lines changed: 48 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
dist
3+
coverage

.jshintrc

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

.travis.yml

Lines changed: 3 additions & 6 deletions
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

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

lib/code.js

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

package.json

Lines changed: 29 additions & 6 deletions
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,40 @@
3334
},
3435
"dependencies": {},
3536
"devDependencies": {
37+
"@babel/cli": "^7.8.4",
38+
"@babel/core": "^7.9.0",
39+
"@babel/preset-env": "^7.9.5",
40+
"@babel/register": "^7.9.0",
41+
"@rollup/plugin-babel": "^5.0.0",
3642
"chai": "~4.2.0",
3743
"coffeescript": "^2.5.1",
38-
"jshint": "2.11.0",
44+
"eslint": "^6.8.0",
3945
"mocha": "~7.1.2",
46+
"nyc": "^15.0.1",
4047
"regenerate": "~1.4.0",
48+
"rollup": "^2.7.3",
49+
"rollup-plugin-terser": "^5.3.0",
4150
"unicode-13.0.0": "^0.8.0"
4251
},
4352
"license": "BSD-2-Clause",
53+
"nyc": {
54+
"branches": 100,
55+
"lines": 100,
56+
"functions": 100,
57+
"statements": 100,
58+
"reporter": [
59+
"html",
60+
"text"
61+
],
62+
"exclude": [
63+
"test"
64+
]
65+
},
4466
"scripts": {
67+
"build": "rollup -c",
4568
"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/**",
69+
"lint": "eslint .",
70+
"unit-test": "nyc mocha --require @babel/register --require chai/register-expect --require coffeescript/register test/**",
4871
"generate-regex": "node tools/generate-identifier-regex.js"
4972
}
5073
}

rollup.config.js

Lines changed: 45 additions & 0 deletions
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)