Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: Switch to ESM #24

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
@@ -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
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
/node_modules
/test.*
.eslint-release-info.json
/dist
2 changes: 1 addition & 1 deletion README.md
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"
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
```

### evk.KEYS
Expand Down
10 changes: 6 additions & 4 deletions lib/index.js
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
24 changes: 16 additions & 8 deletions package.json
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",
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
"exports": {
"import": "./lib/index.js",
"require": "./dist/eslint-visitor-keys.cjs"
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
},
"files": [
"lib"
],
"engines": {
"node": ">=10"
"node": ">=12"
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
},
"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
@@ -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
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