Skip to content

Commit

Permalink
chore!: use pure ES modules (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Feb 2, 2022
1 parent bcb3d6e commit 81221e1
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 69 deletions.
File renamed without changes.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Linting and formatting configuration shared by Netlify Node.js repositories:
If you're creating a new repository, you can use the
[following GitHub template](https://github.com/netlify/node-template). Otherwise, please follow those steps:

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

```js
Expand All @@ -33,13 +33,7 @@ module.exports = {
"@netlify/eslint-config-node/.prettierrc.json"
```

- Add the following `commitlint.config.js` to the root of the project:

```js
module.exports = { extends: ['@commitlint/config-conventional'] }
```

- Copy the `.editorconfig` and `.gitattributes` files relativity to the root of the project.
- Copy the `commitlint.config.cjs`, `.editorconfig` and `.gitattributes` files relativity to the root of the project.
- Add the following properties to the `package.json`. Please replace the `config` globbing expressions to match the
files where the source JavaScript/Markdown/HTML/JSON/YAML files are located. `npm run format` should also be run
during `npm test` and `npm run format:ci` during CI
Expand All @@ -58,8 +52,8 @@ module.exports = { extends: ['@commitlint/config-conventional'] }
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier"
},
"config": {
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,tests,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
"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\""
"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}\"",
"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\""
}
}
```
Expand Down
3 changes: 0 additions & 3 deletions ava.config.js

This file was deleted.

17 changes: 0 additions & 17 deletions bin/run_ci.js

This file was deleted.

15 changes: 15 additions & 0 deletions bin/run_ci.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
import { argv } from 'process'

import execa from 'execa'
import isCI from 'is-ci'

const [, , command] = argv

const runCI = async function () {
if (isCI) {
await execa.command(command, { stdio: 'inherit' })
}
}

runCI()
6 changes: 3 additions & 3 deletions bin/run_e.js → bin/run_e.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node
const process = require('process')
import process, { argv } from 'process'

const execa = require('execa')
import execa from 'execa'

const [, , npmScript, npmScriptOnError] = process.argv
const [, , npmScript, npmScriptOnError] = argv

// Run a npm script. If that script fails, another npm script is run.
// We use this for example with ESLint and Prettier to be able to fail if
Expand Down
10 changes: 4 additions & 6 deletions bin/run_local.js → bin/run_local.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env node
'use strict'
import { argv } from 'process'

const process = require('process')
import execa from 'execa'
import isCI from 'is-ci'

const execa = require('execa')
const isCI = require('is-ci')

const [, , command] = process.argv
const [, , command] = argv

const runLocal = async function () {
if (!isCI) {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
{
"name": "@netlify/eslint-config-node",
"version": "4.1.7",
"main": ".eslintrc.js",
"type": "commonjs",
"exports": "./.eslintrc.cjs",
"main": "./.eslintrc.cjs",
"files": [
".eslintrc.js",
".eslintrc.cjs",
".prettierrc.json",
".editorconfig",
".gitattributes",
"bin/*.js",
"bin/*.mjs",
".husky/*"
],
"bin": {
"run-e": "./bin/run_e.js",
"run-ci": "./bin/run_ci.js",
"run-local": "./bin/run_local.js"
"run-e": "./bin/run_e.mjs",
"run-ci": "./bin/run_ci.mjs",
"run-local": "./bin/run_local.mjs"
},
"scripts": {
"test": "run-s format test:dev",
"format": "run-s format:check-fix:*",
"format:ci": "run-s format:check:*",
"format:check-fix:lint": "node ./bin/run_e.js format:check:lint format:fix:lint",
"format:check-fix:lint": "node ./bin/run_e.mjs format:check:lint format:fix:lint",
"format:check:lint": "cross-env-shell eslint $npm_package_config_eslint",
"format:fix:lint": "cross-env-shell eslint --fix $npm_package_config_eslint",
"format:check-fix:prettier": "node ./bin/run_e.js format:check:prettier format:fix:prettier",
"format:check-fix:prettier": "node ./bin/run_e.mjs format:check:prettier format:fix:prettier",
"format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
"test:dev": "run-s test:dev:*",
Expand All @@ -33,8 +35,8 @@
"prepare": "husky install"
},
"config": {
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{bin,.github}/**/*.{js,html}\" \".*.js\"",
"prettier": "--ignore-path .gitignore --loglevel=warn \"{bin,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \"!**/package-lock.json\" \"!CHANGELOG.md\""
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{bin,.github}/**/*.{cjs,mjs,js,html}\" \".*.{cjs,mjs,js}\"",
"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\""
},
"description": "ESLint and Prettier configuration for Netlify Node.js projects",
"keywords": [
Expand Down Expand Up @@ -105,5 +107,8 @@
},
"engines": {
"node": ">=16.0.0"
},
"ava": {
"verbose": true
}
}
3 changes: 0 additions & 3 deletions test/fixtures/_valid.js

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/_valid.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test = true
14 changes: 0 additions & 14 deletions test/main.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fileURLToPath } from 'url'

import test from 'ava'
import execa from 'execa'

const ESLINT_CONFIG = fileURLToPath(new URL('../.eslintrc.cjs', import.meta.url))
const TEST_FILE = fileURLToPath(new URL('fixtures/_valid.mjs', import.meta.url))

test('Smoke test', async (t) => {
const { exitCode, stdout, stderr } = await execa('eslint', [TEST_FILE, '--config', ESLINT_CONFIG], {
preferLocal: true,
})
t.is(exitCode, 0)
t.is(stdout.trim(), '')
t.is(stderr.trim(), '')
})

0 comments on commit 81221e1

Please sign in to comment.