Skip to content

Commit 81221e1

Browse files
authored
chore!: use pure ES modules (#435)
1 parent bcb3d6e commit 81221e1

14 files changed

+61
-69
lines changed
File renamed without changes.

README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Linting and formatting configuration shared by Netlify Node.js repositories:
1414
If you're creating a new repository, you can use the
1515
[following GitHub template](https://github.com/netlify/node-template). Otherwise, please follow those steps:
1616

17-
- Add a `.eslintrc.js` file to the root of the project. Individual `rules` and `overrides` can be tweaked for the
17+
- Add a `.eslintrc.cjs` file to the root of the project. Individual `rules` and `overrides` can be tweaked for the
1818
specific project.
1919

2020
```js
@@ -33,13 +33,7 @@ module.exports = {
3333
"@netlify/eslint-config-node/.prettierrc.json"
3434
```
3535

36-
- Add the following `commitlint.config.js` to the root of the project:
37-
38-
```js
39-
module.exports = { extends: ['@commitlint/config-conventional'] }
40-
```
41-
42-
- Copy the `.editorconfig` and `.gitattributes` files relativity to the root of the project.
36+
- Copy the `commitlint.config.cjs`, `.editorconfig` and `.gitattributes` files relativity to the root of the project.
4337
- Add the following properties to the `package.json`. Please replace the `config` globbing expressions to match the
4438
files where the source JavaScript/Markdown/HTML/JSON/YAML files are located. `npm run format` should also be run
4539
during `npm test` and `npm run format:ci` during CI
@@ -58,8 +52,8 @@ module.exports = { extends: ['@commitlint/config-conventional'] }
5852
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier"
5953
},
6054
"config": {
61-
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,tests,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
62-
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,tests,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \".*.{js,yml,json,html}\" \"!package-lock.json\""
55+
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,tests,.github}/**/*.{cjs,mjs,js,md,html}\" \"*.{cjs,mjs,js,md,html}\" \".*.{cjs,mjs,js,md,html}\"",
56+
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,tests,.github}/**/*.{cjs,mjs,js,md,yml,json,html}\" \"*.{cjs,mjs,js,yml,json,html}\" \".*.{cjs,mjs,js,yml,json,html}\" \"!package-lock.json\""
6357
}
6458
}
6559
```

ava.config.js

-3
This file was deleted.

bin/run_ci.js

-17
This file was deleted.

bin/run_ci.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
import { argv } from 'process'
3+
4+
import execa from 'execa'
5+
import isCI from 'is-ci'
6+
7+
const [, , command] = argv
8+
9+
const runCI = async function () {
10+
if (isCI) {
11+
await execa.command(command, { stdio: 'inherit' })
12+
}
13+
}
14+
15+
runCI()

bin/run_e.js renamed to bin/run_e.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
2-
const process = require('process')
2+
import process, { argv } from 'process'
33

4-
const execa = require('execa')
4+
import execa from 'execa'
55

6-
const [, , npmScript, npmScriptOnError] = process.argv
6+
const [, , npmScript, npmScriptOnError] = argv
77

88
// Run a npm script. If that script fails, another npm script is run.
99
// We use this for example with ESLint and Prettier to be able to fail if

bin/run_local.js renamed to bin/run_local.mjs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/usr/bin/env node
2-
'use strict'
2+
import { argv } from 'process'
33

4-
const process = require('process')
4+
import execa from 'execa'
5+
import isCI from 'is-ci'
56

6-
const execa = require('execa')
7-
const isCI = require('is-ci')
8-
9-
const [, , command] = process.argv
7+
const [, , command] = argv
108

119
const runLocal = async function () {
1210
if (!isCI) {
File renamed without changes.

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
{
22
"name": "@netlify/eslint-config-node",
33
"version": "4.1.7",
4-
"main": ".eslintrc.js",
4+
"type": "commonjs",
5+
"exports": "./.eslintrc.cjs",
6+
"main": "./.eslintrc.cjs",
57
"files": [
6-
".eslintrc.js",
8+
".eslintrc.cjs",
79
".prettierrc.json",
810
".editorconfig",
911
".gitattributes",
10-
"bin/*.js",
12+
"bin/*.mjs",
1113
".husky/*"
1214
],
1315
"bin": {
14-
"run-e": "./bin/run_e.js",
15-
"run-ci": "./bin/run_ci.js",
16-
"run-local": "./bin/run_local.js"
16+
"run-e": "./bin/run_e.mjs",
17+
"run-ci": "./bin/run_ci.mjs",
18+
"run-local": "./bin/run_local.mjs"
1719
},
1820
"scripts": {
1921
"test": "run-s format test:dev",
2022
"format": "run-s format:check-fix:*",
2123
"format:ci": "run-s format:check:*",
22-
"format:check-fix:lint": "node ./bin/run_e.js format:check:lint format:fix:lint",
24+
"format:check-fix:lint": "node ./bin/run_e.mjs format:check:lint format:fix:lint",
2325
"format:check:lint": "cross-env-shell eslint $npm_package_config_eslint",
2426
"format:fix:lint": "cross-env-shell eslint --fix $npm_package_config_eslint",
25-
"format:check-fix:prettier": "node ./bin/run_e.js format:check:prettier format:fix:prettier",
27+
"format:check-fix:prettier": "node ./bin/run_e.mjs format:check:prettier format:fix:prettier",
2628
"format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
2729
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
2830
"test:dev": "run-s test:dev:*",
@@ -33,8 +35,8 @@
3335
"prepare": "husky install"
3436
},
3537
"config": {
36-
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{bin,.github}/**/*.{js,html}\" \".*.js\"",
37-
"prettier": "--ignore-path .gitignore --loglevel=warn \"{bin,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \"!**/package-lock.json\" \"!CHANGELOG.md\""
38+
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{bin,.github}/**/*.{cjs,mjs,js,html}\" \".*.{cjs,mjs,js}\"",
39+
"prettier": "--ignore-path .gitignore --loglevel=warn \"{bin,.github}/**/*.{cjs,mjs,js,md,yml,json,html}\" \"*.{cjs,mjs,js,yml,json,html}\" \"!**/package-lock.json\" \"!CHANGELOG.md\""
3840
},
3941
"description": "ESLint and Prettier configuration for Netlify Node.js projects",
4042
"keywords": [
@@ -105,5 +107,8 @@
105107
},
106108
"engines": {
107109
"node": ">=16.0.0"
110+
},
111+
"ava": {
112+
"verbose": true
108113
}
109114
}

test/fixtures/_valid.js

-3
This file was deleted.

test/fixtures/_valid.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const test = true

test/main.js

-14
This file was deleted.

test/main.mjs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fileURLToPath } from 'url'
2+
3+
import test from 'ava'
4+
import execa from 'execa'
5+
6+
const ESLINT_CONFIG = fileURLToPath(new URL('../.eslintrc.cjs', import.meta.url))
7+
const TEST_FILE = fileURLToPath(new URL('fixtures/_valid.mjs', import.meta.url))
8+
9+
test('Smoke test', async (t) => {
10+
const { exitCode, stdout, stderr } = await execa('eslint', [TEST_FILE, '--config', ESLINT_CONFIG], {
11+
preferLocal: true,
12+
})
13+
t.is(exitCode, 0)
14+
t.is(stdout.trim(), '')
15+
t.is(stderr.trim(), '')
16+
})

0 commit comments

Comments
 (0)