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

Commit

Permalink
New: Switch to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Jun 20, 2021
1 parent c6846d6 commit 5545362
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
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"
},
"env": {
"es6": true,
"node": true
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ npm install eslint-visitor-keys
## 📖 Usage

```js
const evk = require("eslint-visitor-keys")
import evk from "eslint-visitor-keys"
```

### evk.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))
);

// 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({

/**
* 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
24 changes: 16 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@
"name": "eslint-visitor-keys",
"version": "2.1.0",
"description": "Constants and utilities about visitor keys to traverse AST.",
"type": "module",
"main": "lib/index.js",
"exports": {
"import": "./lib/index.js",
"require": "./dist/eslint-visitor-keys.cjs"
},
"files": [
"lib"
],
"engines": {
"node": ">=10"
"node": ">=12"
},
"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",
"lint": "eslint lib tests/lib",
"test": "nyc mocha tests/lib",
"coverage": "nyc report --reporter lcov && opener coverage/lcov-report/index.html",
"test": "c8 mocha tests/lib",
"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"],
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

0 comments on commit 5545362

Please sign in to comment.