From 0c973525cc22163bee0942012013d539a5cdc5da Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 15 Oct 2021 11:06:55 -0400 Subject: [PATCH 1/4] Migrate to using ESM --- index.js | 34 ++++++++++++++++++++-------------- package.json | 1 + test.js | 16 +++++++++------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 5fdbcec..7be06cd 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,22 @@ -'use strict'; - -const { EOL } = require('os'); -const fs = require('fs'); -const which = require('which'); -const { Plugin } = require('release-it'); -const { format } = require('release-it/lib/util'); -const tmp = require('tmp'); -const execa = require('execa'); -const parse = require('mdast-util-from-markdown'); - -require('validate-peer-dependencies')(__dirname); - +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; +import { createRequire } from 'node:module'; +import { EOL } from 'node:os'; +import fs from 'node:fs'; +import which from 'which'; +import { Plugin } from 'release-it'; +import { format } from 'release-it/lib/util.js'; +import tmp from 'tmp'; +import execa from 'execa'; +import parse from 'mdast-util-from-markdown'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +import validatePeerDependencies from 'validate-peer-dependencies'; +validatePeerDependencies(__dirname); + +const require = createRequire(import.meta.url); const LERNA_PATH = require.resolve('lerna-changelog/bin/cli'); // using a const here, because we may need to change this value in the future @@ -23,7 +29,7 @@ function getToday() { return date.slice(0, date.indexOf('T')); } -module.exports = class LernaChangelogGeneratorPlugin extends Plugin { +export default class LernaChangelogGeneratorPlugin extends Plugin { async init() { let from = (await this.getTagForHEAD()) || (await this.getFirstCommit()); this.changelog = await this._execLernaChangelog(from); diff --git a/package.json b/package.json index 615b8e4..db7c7b8 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "ava": { "serial": true }, + "type": "module", "dependencies": { "execa": "^4.1.0", "lerna-changelog": "^2.2.0", diff --git a/test.js b/test.js index 5bb444f..6393b2b 100644 --- a/test.js +++ b/test.js @@ -1,16 +1,18 @@ -'use strict'; +import fs from 'node:fs'; +import path from 'node:path'; +import { createRequire } from 'node:module'; +import tmp from 'tmp'; +import test from 'ava'; +import { factory, runTasks } from 'release-it/test/util/index.js'; +import Plugin from './index.js'; -const fs = require('fs'); -const path = require('path'); -const tmp = require('tmp'); -const test = require('ava'); -const { factory, runTasks } = require('release-it/test/util'); -const Plugin = require('./index'); const EDITOR = process.env.EDITOR || null; const PATH = process.env.PATH; tmp.setGracefulCleanup(); +const require = createRequire(import.meta.url); + const LERNA_PATH = require.resolve('lerna-changelog/bin/cli'); const namespace = 'release-it-lerna-changelog'; From f648a0996281f7e88b3978a869fa4c4d82dd50e6 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 15 Oct 2021 11:16:10 -0400 Subject: [PATCH 2/4] Fix up linting with ESM changes --- .eslintrc.js => .eslintrc.cjs | 4 ++-- index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename .eslintrc.js => .eslintrc.cjs (83%) diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 83% rename from .eslintrc.js rename to .eslintrc.cjs index d2f001e..f80464b 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -3,8 +3,8 @@ module.exports = { extends: ['eslint:recommended', 'plugin:node/recommended', 'prettier'], plugins: ['prettier', 'node'], parserOptions: { - ecmaVersion: 2017, - sourceType: 'script', + ecmaVersion: 2020, + sourceType: 'module', }, env: { node: true, diff --git a/index.js b/index.js index 7be06cd..e5c77b8 100644 --- a/index.js +++ b/index.js @@ -208,4 +208,4 @@ export default class LernaChangelogGeneratorPlugin extends Plugin { await this.writeChangelog(processedChangelog); } } -}; +} From 1909f53fa043485890a9a80f8c1c5031699929a2 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 15 Oct 2021 11:31:47 -0400 Subject: [PATCH 3/4] Update linting packages --- package-lock.json | 74 +++++++++++++++++------------------------------ package.json | 8 ++--- 2 files changed, 31 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index f7bba6b..80d97b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,15 +19,15 @@ "devDependencies": { "ava": "^3.15.0", "eslint": "^7.32.0", - "eslint-config-prettier": "^6.15.0", + "eslint-config-prettier": "^8.3.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^3.4.0", - "prettier": "^2.2.1", + "eslint-plugin-prettier": "^4.0.0", + "prettier": "^2.4.1", "release-it": "^14.10.1", "sinon": "^9.2.4" }, "engines": { - "node": "12.* || 14.* || >= 16" + "node": "^12.20.0 || ^14.13.1 || >= 16" }, "peerDependencies": { "release-it": "^14.0.0" @@ -1837,18 +1837,15 @@ } }, "node_modules/eslint-config-prettier": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz", - "integrity": "sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz", + "integrity": "sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==", "dev": true, - "dependencies": { - "get-stdin": "^6.0.0" - }, "bin": { - "eslint-config-prettier-check": "bin/cli.js" + "eslint-config-prettier": "bin/cli.js" }, "peerDependencies": { - "eslint": ">=3.14.1" + "eslint": ">=7.0.0" } }, "node_modules/eslint-plugin-node": { @@ -1909,9 +1906,9 @@ } }, "node_modules/eslint-plugin-prettier": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.1.tgz", - "integrity": "sha512-htg25EUYUeIhKHXjOinK4BgCcDwtLHjqaxCDsMy5nbnUMkKFvIhMVCp+5GFUXQ4Nr8lBsPqtGAqBenbpFqAA2g==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.0.0.tgz", + "integrity": "sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ==", "dev": true, "dependencies": { "prettier-linter-helpers": "^1.0.0" @@ -1920,8 +1917,8 @@ "node": ">=6.0.0" }, "peerDependencies": { - "eslint": ">=5.0.0", - "prettier": ">=1.13.0" + "eslint": ">=7.28.0", + "prettier": ">=2.0.0" }, "peerDependenciesMeta": { "eslint-config-prettier": { @@ -2366,15 +2363,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/get-stdin": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", - "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/get-stream": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", @@ -2922,9 +2910,9 @@ "dev": true }, "node_modules/is-core-module": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.7.0.tgz", - "integrity": "sha512-ByY+tjCciCr+9nLryBYcSD50EOGWt95c7tIsKTG1J2ixKKXPvF7Ej3AVd+UfDydAJom3biBGDBALaO79ktwgEQ==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.0.tgz", + "integrity": "sha512-vd15qHsaqrRL7dtH6QNuy0ndJmRDrS9HAM1CAiSifNUFv4x1a0CCVsj18hJ1mShxIG6T2i1sO78MkP56r0nYRw==", "dependencies": { "has": "^1.0.3" }, @@ -7693,13 +7681,11 @@ } }, "eslint-config-prettier": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz", - "integrity": "sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz", + "integrity": "sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==", "dev": true, - "requires": { - "get-stdin": "^6.0.0" - } + "requires": {} }, "eslint-plugin-node": { "version": "11.1.0", @@ -7740,9 +7726,9 @@ } }, "eslint-plugin-prettier": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.1.tgz", - "integrity": "sha512-htg25EUYUeIhKHXjOinK4BgCcDwtLHjqaxCDsMy5nbnUMkKFvIhMVCp+5GFUXQ4Nr8lBsPqtGAqBenbpFqAA2g==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.0.0.tgz", + "integrity": "sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ==", "dev": true, "requires": { "prettier-linter-helpers": "^1.0.0" @@ -8081,12 +8067,6 @@ "has-symbols": "^1.0.1" } }, - "get-stdin": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", - "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", - "dev": true - }, "get-stream": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", @@ -8486,9 +8466,9 @@ } }, "is-core-module": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.7.0.tgz", - "integrity": "sha512-ByY+tjCciCr+9nLryBYcSD50EOGWt95c7tIsKTG1J2ixKKXPvF7Ej3AVd+UfDydAJom3biBGDBALaO79ktwgEQ==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.0.tgz", + "integrity": "sha512-vd15qHsaqrRL7dtH6QNuy0ndJmRDrS9HAM1CAiSifNUFv4x1a0CCVsj18hJ1mShxIG6T2i1sO78MkP56r0nYRw==", "requires": { "has": "^1.0.3" } diff --git a/package.json b/package.json index db7c7b8..48fbcf2 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "devDependencies": { "ava": "^3.15.0", "eslint": "^7.32.0", - "eslint-config-prettier": "^6.15.0", + "eslint-config-prettier": "^8.3.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^3.4.0", - "prettier": "^2.2.1", + "eslint-plugin-prettier": "^4.0.0", + "prettier": "^2.4.1", "release-it": "^14.10.1", "sinon": "^9.2.4" }, @@ -47,7 +47,7 @@ "release-it": "^14.0.0" }, "engines": { - "node": "12.* || 14.* || >= 16" + "node": "^12.20.0 || ^14.13.1 || >= 16" }, "publishConfig": { "registry": "https://registry.npmjs.org/" From a8b3cc783a0bf9fbe7a3ce462d99786ed581a553 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 15 Oct 2021 11:32:17 -0400 Subject: [PATCH 4/4] Only run linting on node 14 This works around an issue with node/no-missing-import that doesn't properly see that `node:path` is a valid module on Node 12.x. They are using `is-core-module` to figure out if it is a module or not, and it seems that `is-core-module` doesn't differentiate between core modules that are available for CJS (the `node:` prefixed paths are only available in 14.18+ and 16+ in CJS files) and those that are available to ESM. This is really just a bandaid, the right fix would be to send a PR to is-core-module to allow it to check CJS vs MJS modules (since they are actually different). See https://github.com/mysticatea/eslint-plugin-node/issues/299 --- .github/workflows/ci.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d77972c..f88fb95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,17 @@ on: pull_request: jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 14.x + - run: npm ci + - run: npm run lint:js + build: name: "Node ${{ matrix.node-version }}" @@ -23,7 +34,6 @@ jobs: node-version: ${{ matrix.node-version }} - name: install dependencies run: npm ci - - run: npm run lint:js - run: npm test release-it-compat: @@ -43,5 +53,4 @@ jobs: - name: install dependencies run: npm ci - run: npm install --saveDev release-it@${{ matrix.release-it-version }} - - run: npm run lint:js - run: npm test