Skip to content

Commit

Permalink
Merge pull request #21 from homer0/next
Browse files Browse the repository at this point in the history
Drop Yarn, Node < 18, and update dependences
  • Loading branch information
homer0 authored Oct 6, 2023
2 parents e701911 + 99d3aa3 commit 537a277
Show file tree
Hide file tree
Showing 24 changed files with 19,744 additions and 8,256 deletions.
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
"extends": [
"plugin:@homer0/node-with-prettier",
"plugin:@homer0/jsdoc"
]
],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {
"node/no-unsupported-features/es-syntax": "off"
}
}
2 changes: 0 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

```bash
npm test
# or
yarn test
```

### TODOs
18 changes: 8 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "::set-output name=NVMRC::$(cat .nvmrc)"
id: nvm
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- name: Node.js
uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
node-version-file: '.nvmrc'
- name: Install dependencies
env:
HUSKY: 0
run: yarn --frozen-lockfile
- run: yarn semantic-release
run: npm ci
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Generate documentation
run: yarn docs
run: npm run docs
- name: Deploy documentation
uses: JamesIves/github-pages-deploy-action@4.1.1
uses: JamesIves/github-pages-deploy-action@4
with:
BRANCH: gh-pages
FOLDER: docs
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16' ]
node: [ '18', '20' ]
name: Run jest and ESLint (Node ${{ matrix.node }})
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: yarn --frozen-lockfile
- run: yarn lint:all
- run: yarn test
- run: npm ci
- run: npm run lint:all
- run: npm test
- name: Coveralls
if: ${{ matrix.node == '14' }}
if: ${{ matrix.node == '18' }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 1 addition & 5 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn commitlint --edit $1
else
npx commitlint --edit $1
fi
npx commitlint --edit $1

6 changes: 1 addition & 5 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn
else
npm install
fi
npm install

6 changes: 1 addition & 5 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

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

if hash yarn 2>/dev/null; then
yarn test
else
npm test
fi
npm test
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ docs
documents
tests
utils
npm-debug.log
yarn-error.log
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18
1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('@homer0/prettier-config');

module.exports = {
...base,
plugins: ['@homer0/prettier-plugin-jsdoc'],
};
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# CJS 2 ESM

[![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)
[![GitHub Workflow Status (main)](https://img.shields.io/github/actions/workflow/status/homer0/cjs2esm/test.yml?branch=main&style=flat-square)](https://github.com/homer0/cjs2esm/actions/workflows/test.yml?query=branch%3Amain)
[![Coveralls GitHub](https://img.shields.io/coveralls/github/homer0/cjs2esm.svg?style=flat-square)](https://coveralls.io/github/homer0/cjs2esm?branch=main)
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/cjs2esm?style=flat-square)

Transforms a project that uses CommonJS to ES Modules.

## 📝 Introduction

> If you are wondering why I built this, go to the [Motivation](#motivation) section.
You can use this tool to transform a project that uses **CommonJS** to **ES Modules** and get it ready for Node `v14`, any module bundler with **ESM** support, or even [`typedef` imports on JSDoc](https://github.com/homer0/jsdoc-ts-utils#import-type-defintions).
You can use this tool to transform a project that uses **CommonJS** to **ES Modules** and get it ready for an ESM world, any module bundler with **ESM** support, or even [`typedef` imports on JSDoc](https://github.com/homer0/jsdoc-ts-utils#import-type-defintions).

This tool internally uses [`jscodeshift`](https://github.com/facebook/jscodeshift) with the transformations from [`5to6`](https://github.com/5to6/5to6-codemod) and an extra one created to fix missing extensions.

Expand Down Expand Up @@ -64,11 +63,12 @@ The package comes with a binary that you can execute from your `package.json`, o
# From the package.json
cjs2esm

# NPM
npx cjs2esm

# Yarn
yarn cjs2esm

# NPM
npx cjs2esm
```

### Configuration
Expand Down Expand Up @@ -252,18 +252,21 @@ Yes, if you want to use the tool as a library, the tool uses itself to generate

```js
// commonjs
const { getConfiguration } = require('cjs2esm');
const { prepare, getConfiguration } = require('cjs2esm');

// ESM
import { getConfiguration } from 'cjs2esm/esm';
import { prepare, getConfiguration } from 'cjs2esm/esm';

// #dogfooding
```

> Check `src/index.js` to see how the API is used.
## ⚙️ Development

### NPM/Yarn tasks
### Scripts

| Task | Description |
| Script | Description |
|------------|-------------------------------------|
| `test` | Run the project unit tests. |
| `lint` | Lint the modified files. |
Expand All @@ -274,7 +277,7 @@ import { getConfiguration } from 'cjs2esm/esm';

### Repository hooks

I use [`husky`](https://yarnpkg.com/package/husky) to automatically install the repository hooks so the code will be tested and linted before any commit, and the dependencies updated after every merge.
I use [`husky`](https://www.npmjs.com/package/husky) to automatically install the repository hooks so the code will be tested and linted before any commit, and the dependencies updated after every merge.

#### Commits convention

Expand All @@ -284,7 +287,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 main.
I use [`semantic-release`](https://www.npmjs.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 @@ -296,9 +299,9 @@ The configuration file is on `./.jestrc.js`, the tests are on `./tests` and the

### Linting && Formatting

I use [ESlint](https://eslint.org) with [my own custom configuration](https://yarnpkg.com/en/package/@homer0/eslint-plugin) to validate all the JS code. The configuration file for the project code is on `./.eslintrc` and the one for the tests is on `./tests/.eslintrc`. There's also an `./.eslintignore` to exclude some files on the process. The script that runs it is on `./utils/scripts/lint-all`.
I use [ESlint](https://eslint.org) with [my own custom configuration](https://www.npmjs.com/package/@homer0/eslint-plugin) to validate all the JS code. The configuration file for the project code is on `./.eslintrc` and the one for the tests is on `./tests/.eslintrc`. There's also an `./.eslintignore` to exclude some files on the process. The script that runs it is on `./utils/scripts/lint-all`.

For formatting I use [Prettier](https://prettier.io) with [my custom configuration](https://yarnpkg.com/en/package/@homer0/prettier-config). The configuration file for the project code is on `./.prettierrc`.
For formatting I use [Prettier](https://prettier.io) with [my custom configuration](https://www.npmjs.com/package/@homer0/prettier-config). The configuration file for the project code is on `./.prettierrc`.

### Documentation

Expand All @@ -308,7 +311,7 @@ The configuration file is on `./.jsdoc.js` and the script that runs it is on `./

### To-Dos

I use `@todo` comments to write all the pending improvements and fixes, and [Leasot](https://yarnpkg.com/en/package/leasot) to generate a report. The script that runs it is on `./utils/scripts/todo`.
I use `@todo` comments to write all the pending improvements and fixes, and [Leasot](https://www.npmjs.com/package/leasot) to generate a report. The script that runs it is on `./utils/scripts/todo`.

## 💡 Motivation

Expand Down
Loading

0 comments on commit 537a277

Please sign in to comment.