From d3e4ec3596acf8db3697397e85b96962b5b8cf54 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 13 Mar 2022 23:39:42 +0800 Subject: [PATCH] feat: add native Node ESM, with ESM lite export BREAKING CHANGE: Adds `exports` and changes path for /parser.js to /parser.cjs Also: - chore: updates estraverse - chore: updates devDeps. - chore: lints - test: switches to c8 for ESM testing --- .eslintignore | 2 +- .eslintrc.js => .eslintrc.cjs | 0 esquery.js | 2 +- package.json | 53 +++++++++++++++++++++-------------- parser.js => parser.cjs | 0 rollup.config.js | 3 +- tests/parser.js | 24 ++++++++-------- 7 files changed, 48 insertions(+), 36 deletions(-) rename .eslintrc.js => .eslintrc.cjs (100%) rename parser.js => parser.cjs (100%) diff --git a/.eslintignore b/.eslintignore index 6edbe70..d8d5f10 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ node_modules dist -parser.js +parser.cjs !.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 100% rename from .eslintrc.js rename to .eslintrc.cjs diff --git a/esquery.js b/esquery.js index b451ad6..dd892e5 100644 --- a/esquery.js +++ b/esquery.js @@ -1,6 +1,6 @@ /* vim: set sw=4 sts=4 : */ import estraverse from 'estraverse'; -import parser from './parser.js'; +import parser from './parser.cjs'; /** * @typedef {"LEFT_SIDE"|"RIGHT_SIDE"} Side diff --git a/package.json b/package.json index 3d81875..31ffbb7 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,27 @@ "author": "Joel Feenstra ", "contributors": [], "description": "A query library for ECMAScript AST using a CSS selector like query language.", - "main": "dist/esquery.min.js", - "module": "dist/esquery.esm.min.js", + "type": "module", + "main": "./dist/esquery.min.js", + "module": "./dist/esquery.esm.min.js", + "exports": { + ".": { + "import": "./dist/esquery.esm.min.js", + "require": "./dist/esquery.min.js" + }, + "./lite": { + "import": "./dist/esquery.lite.esm.min.js", + "require": "./dist/esquery.lite.min.js" + } + }, "files": [ "dist/*.js", "dist/*.map", - "parser.js", + "parser.cjs", "license.txt", "README.md" ], - "nyc": { + "c8": { "branches": 100, "lines": 100, "functions": 100, @@ -23,18 +34,18 @@ "text" ], "exclude": [ - "parser.js", + "parser.cjs", "dist", "tests" ] }, "scripts": { "prepublishOnly": "npm run build && npm test", - "build:parser": "rm parser.js && pegjs --cache --format umd -o \"parser.js\" \"grammar.pegjs\"", + "build:parser": "rm parser.cjs && pegjs --cache --format umd -o \"parser.cjs\" \"grammar.pegjs\"", "build:browser": "rollup -c", "build": "npm run build:parser && npm run build:browser", - "mocha": "mocha --require chai/register-assert --require @babel/register tests", - "test": "nyc npm run mocha && npm run lint", + "mocha": "mocha --require chai/register-assert.js --require @babel/register tests", + "test": "c8 npm run mocha && npm run lint", "test:ci": "npm run mocha", "lint": "eslint ." }, @@ -51,28 +62,28 @@ "query" ], "devDependencies": { - "@babel/core": "^7.9.0", - "@babel/preset-env": "^7.9.5", - "@babel/register": "^7.9.0", - "@rollup/plugin-commonjs": "^11.1.0", - "@rollup/plugin-json": "^4.0.2", - "@rollup/plugin-node-resolve": "^7.1.3", + "@babel/core": "^7.17.5", + "@babel/preset-env": "^7.16.11", + "@babel/register": "^7.17.0", + "@rollup/plugin-commonjs": "^21.0.2", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.1.3", "babel-plugin-transform-es2017-object-entries": "0.0.5", - "chai": "^4.2.0", - "eslint": "^6.8.0", + "c8": "^7.11.0", + "chai": "^4.3.6", + "eslint": "^8.11.0", "esprima": "~4.0.1", - "mocha": "^7.1.1", - "nyc": "^15.0.1", + "mocha": "^9.2.2", "pegjs": "~0.10.0", - "rollup": "^1.32.1", + "rollup": "^2.70.0", "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-terser": "^5.3.0" + "rollup-plugin-terser": "^7.0.2" }, "license": "BSD-3-Clause", "engines": { "node": ">=0.10" }, "dependencies": { - "estraverse": "^5.1.0" + "estraverse": "^5.3.0" } } diff --git a/parser.js b/parser.cjs similarity index 100% rename from parser.js rename to parser.cjs diff --git a/rollup.config.js b/rollup.config.js index 563a1bb..90c818c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -60,5 +60,6 @@ export default [ getRollupObject({ minifying: true, format: 'esm' }), getRollupObject({ minifying: false, format: 'esm' }), getRollupObject({ minifying: true, format: 'umd', lite: true }), - getRollupObject({ minifying: false, format: 'umd', lite: true }) + getRollupObject({ minifying: false, format: 'umd', lite: true }), + getRollupObject({ minifying: true, format: 'esm', lite: true }) ]; diff --git a/tests/parser.js b/tests/parser.js index 08b5ec7..b046127 100644 --- a/tests/parser.js +++ b/tests/parser.js @@ -1,18 +1,18 @@ -import esquery from "../esquery.js"; +import esquery from '../esquery.js'; -describe("basic query parsing", function () { +describe('basic query parsing', function () { - it("empty query", function () { - assert.equal(void 0, esquery.parse("")); - assert.equal(void 0, esquery.parse(" ")); + it('empty query', function () { + assert.equal(void 0, esquery.parse('')); + assert.equal(void 0, esquery.parse(' ')); }); - it("leading/trailing whitespace", function () { - assert.notEqual(void 0, esquery.parse(" A")); - assert.notEqual(void 0, esquery.parse(" A")); - assert.notEqual(void 0, esquery.parse("A ")); - assert.notEqual(void 0, esquery.parse("A ")); - assert.notEqual(void 0, esquery.parse(" A ")); - assert.notEqual(void 0, esquery.parse(" A ")); + it('leading/trailing whitespace', function () { + assert.notEqual(void 0, esquery.parse(' A')); + assert.notEqual(void 0, esquery.parse(' A')); + assert.notEqual(void 0, esquery.parse('A ')); + assert.notEqual(void 0, esquery.parse('A ')); + assert.notEqual(void 0, esquery.parse(' A ')); + assert.notEqual(void 0, esquery.parse(' A ')); }); });