Skip to content

Commit

Permalink
Merge pull request #3 from homer0/next
Browse files Browse the repository at this point in the history
Drop Node 10 and update dependencies
  • Loading branch information
homer0 authored Apr 11, 2021
2 parents 63e8335 + d0f5ae8 commit bd6ef2b
Show file tree
Hide file tree
Showing 20 changed files with 1,814 additions and 2,707 deletions.
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"root": true,
"plugins": ["homer0"],
"plugins": ["@homer0"],
"extends": [
"plugin:homer0/node",
"plugin:homer0/jsdoc"
"plugin:@homer0/node-with-prettier",
"plugin:@homer0/jsdoc"
]
}
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release NPM package
on:
push:
branches:
- master
- main

jobs:
release:
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Generate documentation
run: yarn docs
- name: Deploy documentation
uses: JamesIves/[email protected].0
uses: JamesIves/[email protected].1
with:
BRANCH: gh-pages
FOLDER: docs
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '10', '12', '14' ]
node: [ '12', '14' ]
name: Run jest and ESLint (Node ${{ matrix.node }})
steps:
- uses: actions/checkout@v2
Expand All @@ -18,7 +18,7 @@ jobs:
- run: yarn lint:all
- run: yarn test
- name: Coveralls
if: ${{ matrix.node == '10' }}
if: ${{ matrix.node == '12' }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn-error.log
dist
/docs
/esm
.vscode
2 changes: 0 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

if hash yarn 2>/dev/null; then
yarn run lint
yarn test
else
npm run lint
npm test
fi
8 changes: 8 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn test
else
npm test
fi
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
12
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@homer0/prettier-config"
5 changes: 3 additions & 2 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"@semantic-release/npm",
"@semantic-release/git",
["@semantic-release/github", {
"releasedLabels": ["on:master", "released"]
"releasedLabels": ["on:main", "released"]
}]
]
],
"branches": ["main"]
}
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CJS 2 ESM

[![GitHub Workflow Status (master)](https://img.shields.io/github/workflow/status/homer0/cjs2esm/Test/master?style=flat-square)](https://github.com/homer0/cjs2esm/actions?query=workflow%3ATest)
[![Coveralls github](https://img.shields.io/coveralls/github/homer0/cjs2esm.svg?style=flat-square)](https://coveralls.io/github/homer0/cjs2esm?branch=master)
[![GitHub Workflow Status (main)](https://img.shields.io/github/workflow/status/homer0/cjs2esm/Test/main?style=flat-square)](https://github.com/homer0/cjs2esm/actions?query=workflow%3ATest)
[![Coveralls github](https://img.shields.io/coveralls/github/homer0/cjs2esm.svg?style=flat-square)](https://coveralls.io/github/homer0/cjs2esm?branch=main)
[![David](https://img.shields.io/david/homer0/cjs2esm.svg?style=flat-square)](https://david-dm.org/homer0/cjs2esm)
[![David](https://img.shields.io/david/dev/homer0/cjs2esm.svg?style=flat-square)](https://david-dm.org/homer0/cjs2esm)

Expand Down Expand Up @@ -224,7 +224,7 @@ The configuration is on the `commitlint` property of the `package.json`.

### Releases

I use [`semantic-release`](https://yarnpkg.com/package/semantic-release) and a GitHub action to automatically release on NPM everything that gets merged to master.
I use [`semantic-release`](https://yarnpkg.com/package/semantic-release) and a GitHub action to automatically release on NPM everything that gets merged to main.

The configuration for `semantic-release` is on `./releaserc` and the workflow for the release is on `./.github/workflow/release.yml`.

Expand All @@ -250,13 +250,11 @@ I use `@todo` comments to write all the pending improvements and fixes, and [Lea

## 💡 Motivation

I maintain a lot of open source projects (that only I use :P), and most of them are Node libraries and I alway respect the good practice of giving support to the oldes LTS, currently `v10`.

Node started supporting ES Modules, without a flag, starting on `v14`, so I can't ship a ESM-only version... I would need to transpile the code.
I maintain a lot of open source projects (that only I use :P), most of them are Node libraries, and I alway respect the good practice of giving support to the oldest LTS, currently `v10` (for two more weeks).

**I don't want to add transpilation just for this**, Node `v10` has enough features that I don't need Babel, which means that I don't have to use `babel-eslint` to lint, nor configure Jest for transpilation.

So I started looking for something that would transpile from CJS to ESM, but most of the tooling out there are for ESM to CJS, "code with modern syntax, transpile for legay"... Node `v12`, the active LTS, only supports ESM if you use a flag, so we are not talking about a really legacy functionality here.
So I started looking for something that would transpile from CJS to ESM, but most of the tooling out there are for ESM to CJS, "code with modern syntax, transpile for legacy"... Node `v12`, the active LTS (soon to be the oldest), now supports ESM, but you cannot `require` an ESM module, even if it's natively supported.

The thing I like the least from transpiling from ESM to CJS is that if you use CJS, you have to use `require('something').default`, as `export default` becomes `exports.default`; I've had to update a lot of tools for this kind of changes (on the `webpack` ecosystem)...That's a sh*#ty experience.

Expand All @@ -268,4 +266,5 @@ I believe it's a better experencie to have the ESM version on a different path :

Enjoy 🤘!

> Once `v14` becomes the oldest LTS, I'll archive this repository and deprecate the tool.
> ~~Once `v14` becomes the oldest LTS, I'll archive this repository and deprecate the tool.~~
> Node 12 now supports ESM without a flag, but there are still a lot of things that use CommonJS, and the fact that you can't `require` ESM makes things complicated, so I'm not sure yet when I'll deprecate the tool.
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,53 @@
],
"license": "MIT",
"dependencies": {
"@babel/core": "^7.13.8",
"@babel/preset-env": "^7.13.9",
"@babel/core": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"5to6-codemod": "1.8.0",
"chalk": "^4.1.0",
"del": "^6.0.0",
"fs-extra": "^9.1.0",
"jscodeshift": "0.10.0"
},
"devDependencies": {
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@homer0/eslint-plugin": "^7.0.0",
"@homer0/prettier-config": "^1.1.1",
"@homer0/prettier-plugin-jsdoc": "^4.0.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"eslint": "^7.21.0",
"eslint-plugin-homer0": "^5.0.2",
"husky": "^5.1.3",
"eslint": "^7.24.0",
"husky": "^6.0.0",
"is-ci": "^3.0.0",
"jest": "^26.6.3",
"jimple": "^1.5.0",
"jsdoc": "^3.6.6",
"jsdoc-ts-utils": "^1.1.2",
"docdash": "homer0/docdash#semver:^2.1.0",
"leasot": "^11.5.0",
"leasot": "^11.6.0",
"lint-staged": "^10.5.4",
"semantic-release": "^17.4.1"
"prettier": "^2.2.1",
"semantic-release": "^17.4.2"
},
"main": "src/index.js",
"bin": {
"cjs2esm": "./src/bin.js"
},
"engine-strict": true,
"engines": {
"node": ">=10"
"node": ">=12"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"lint-staged": {
"*.js": "eslint"
"*.js": [
"eslint",
"prettier --write"
]
},
"scripts": {
"prepublishOnly": "./utils/scripts/prepublishOnly",
Expand Down
Loading

0 comments on commit bd6ef2b

Please sign in to comment.