Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Breaking: Switch to ESM #24

Merged
merged 23 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; EditorConfig file: https://EditorConfig.org
; Install the "EditorConfig" plugin into your editor to use

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[package.json]
indent_size = 2
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "eslint",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "2020"
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
},
"env": {
"es6": true,
"node": true
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [14.x, 12.x, 10.x]
node: [16.x, 14.x, 12.x, "12.22.0"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/node_modules
/test.*
.eslint-release-info.json
/dist
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ $ npm install eslint-visitor-keys

## 📖 Usage

To use in an ESM file:

```js
import evk from "eslint-visitor-keys"
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
```

To use in a CommonJS file:

```js
const evk = require("eslint-visitor-keys")
```
Expand Down
10 changes: 6 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict";
import { readFileSync } from "fs";

const KEYS = require("./visitor-keys.json");
const KEYS = JSON.parse(
readFileSync(new URL("./visitor-keys.json", import.meta.url))
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
);

// Types.
const NODE_TYPES = Object.freeze(Object.keys(KEYS));
Expand Down Expand Up @@ -35,7 +37,7 @@ function filterKey(key) {
// Public interfaces
//------------------------------------------------------------------------------

module.exports = Object.freeze({
export default Object.freeze({
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved

/**
* Visitor keys.
Expand Down Expand Up @@ -63,7 +65,7 @@ module.exports = Object.freeze({
const retv = Object.assign({}, KEYS);

for (const type of Object.keys(additionalKeys)) {
if (retv.hasOwnProperty(type)) {
if (Object.prototype.hasOwnProperty.call(retv, type)) {
const keys = new Set(additionalKeys[type]);

for (const key of retv[type]) {
Expand Down
30 changes: 21 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,37 @@
"name": "eslint-visitor-keys",
"version": "2.1.0",
"description": "Constants and utilities about visitor keys to traverse AST.",
"main": "lib/index.js",
"type": "module",
"main": "dist/eslint-visitor-keys.cjs",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./dist/eslint-visitor-keys.cjs"
},
"./package.json": "./package.json"
},
"files": [
"dist",
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
"lib"
],
"engines": {
"node": ">=10"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"devDependencies": {
"eslint": "^4.7.2",
"eslint-config-eslint": "^4.0.0",
"c8": "^7.7.3",
"eslint": "^7.29.0",
"eslint-config-eslint": "^7.0.0",
"eslint-release": "^3.1.2",
"mocha": "^3.5.3",
"nyc": "^11.2.1",
"opener": "^1.4.3"
"mocha": "^9.0.1",
"opener": "^1.5.2",
"rollup": "^2.52.1"
},
"scripts": {
"prepare": "npm run build",
"build": "rollup -c",
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
"lint": "eslint lib tests/lib",
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
"test": "nyc mocha tests/lib",
"coverage": "nyc report --reporter lcov && opener coverage/lcov-report/index.html",
"test": "c8 mocha tests/lib",
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
"coverage": "c8 report --reporter lcov && opener coverage/lcov-report/index.html",
"generate-release": "eslint-generate-release",
"generate-alpharelease": "eslint-generate-prerelease alpha",
"generate-betarelease": "eslint-generate-prerelease beta",
Expand Down
9 changes: 9 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
input: "./lib/index.js",
external: ["fs"],
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
output: {
exports: "default",
format: "cjs",
file: "dist/eslint-visitor-keys.cjs"
}
};
8 changes: 3 additions & 5 deletions tests/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict";

const assert = require("assert");
const fs = require("fs");
const evk = require("../..");
import assert from "assert";
import fs from "fs";
import evk from "../../lib/index.js";

const keys = JSON.parse(fs.readFileSync("lib/visitor-keys.json", "utf8"));

Expand Down