Skip to content

Commit

Permalink
feat: add native Node ESM, with ESM lite export
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brettz9 committed Mar 13, 2022
1 parent 7c3800a commit d3e4ec3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
dist
parser.js
parser.cjs

!.eslintrc.js
File renamed without changes.
2 changes: 1 addition & 1 deletion esquery.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 32 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@
"author": "Joel Feenstra <jrfeenst+esquery@gmail.com>",
"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,
Expand All @@ -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 ."
},
Expand All @@ -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"
}
}
File renamed without changes.
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
];
24 changes: 12 additions & 12 deletions tests/parser.js
Original file line number Diff line number Diff line change
@@ -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 '));
});
});

0 comments on commit d3e4ec3

Please sign in to comment.