Skip to content

feat: fork eslint-plugin-lodash, add extension support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
}
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.md]
indent_size = 4
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set the default behavior, in case people don't have core.autocrlf set
* text=auto

# Files that will always have CRLF line endings on checkout
*.js text eol=lf
*.json text eol=lf
*.yml text eol=lf
*.md text eol=lf
.*rc text eol=lf
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@main
with:
node-version: 20
- name: Install dependencies
run: npm ci --verbose
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm run release
41 changes: 15 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
name: Test
"on":
push:
branches:
- main
- dependabot/**
pull_request:
types:
- opened
- synchronize

on: push
jobs:
test_matrix:
strategy:
matrix:
node-version:
- 14.17
- 16
os:
- ubuntu-latest
runs-on: "${{ matrix.os }}"
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Use Node.js ${{ matrix.node-version }}"
uses: actions/setup-node@v2
- name: Checkout
uses: actions/checkout@main
with:
node-version: "${{ matrix.node-version }}"
cache: npm
- run: npm ci
- run: "npm run test --ci"
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@main
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Test
run: npm test
22 changes: 20 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
node_modules
node_modules/
.husky/*/

.DS_Store
# common ignore files
test.*.json
*.log
*.orig
*.env
*.tgz
*.tar

# common editor and system directories and files
.DS_Store
.idea
.sublime-*
.*-project
*.suo
*.ntvs*
*.njsproj
*.sln
*.patch
5 changes: 5 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

[ -n "$CI" ] && exit 0
./node_modules/.bin/commitlint --edit ${1}
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

[ -n "$CI" ] && exit 0
./node_modules/.bin/lint-staged
5 changes: 5 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

[ -n "$CI" ] && exit 0
npm run test:unit
3 changes: 3 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"**/*": "prettier --write --ignore-unknown"
}
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# blacklists it all
/*

# enable only the needed files
!README.md
!LICENSE
!package.json
!index.js
!index.d.ts
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__tests__/fixtures/**/*
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"quoteProps": "consistent",
"endOfLine": "lf",
"trailingComma": "none",
"arrowParens": "avoid",
"bracketSpacing": true
}
14 changes: 0 additions & 14 deletions .release-it.json

This file was deleted.

27 changes: 27 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const changelogFile = 'CHANGELOG.md'
const writerOpts = { commitsSort: ['scope', 'subject'] }
const assets = [changelogFile, 'package.json']
const preset = 'conventionalcommits'

// //////////////////////////////////////////////

module.exports = {
branches: [
'main',
{
name: 'next',
prerelease: 'rc',
channel: 'next'
}
],
plugins: [
['@semantic-release/commit-analyzer', { preset }],
['@semantic-release/release-notes-generator', { preset, writerOpts }],
['@semantic-release/changelog', { changelogFile }],
['@semantic-release/git', { assets }],
'@semantic-release/github',
'@semantic-release/npm'
]
}
49 changes: 0 additions & 49 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,49 +0,0 @@
# [1.2.0](https://github.com/josteph/esbuild-plugin-lodash/compare/1.1.0...1.2.0) (2022-05-22)


### Features

* handle double quotes lodash imports ([#4](https://github.com/josteph/esbuild-plugin-lodash/issues/4)) ([ee59f86](https://github.com/josteph/esbuild-plugin-lodash/commit/ee59f86ce5f45239098e7e6740eb94008484ccdb)), closes [/github.com/mikeduminy/esbuild-plugin-ramda/blob/main/index.js#L18](https://github.com//github.com/mikeduminy/esbuild-plugin-ramda/blob/main/index.js/issues/L18)

# [1.1.0](https://github.com/josteph/esbuild-plugin-lodash/compare/1.0.4...1.1.0) (2021-10-01)


### Features

* Add outLodashPackage feature to allow for lodash-es, fix .cjs and .mjs files. ([#2](https://github.com/josteph/esbuild-plugin-lodash/issues/2)) ([f604fee](https://github.com/josteph/esbuild-plugin-lodash/commit/f604feed0a4a61b7fbbc8caf35a525d2898a28ee))

## [1.0.4](https://github.com/josteph/esbuild-plugin-lodash/compare/1.0.3...1.0.4) (2021-06-26)


### Bug Fixes

* import lodash/last bug ([#1](https://github.com/josteph/esbuild-plugin-lodash/issues/1)) ([e91dff2](https://github.com/josteph/esbuild-plugin-lodash/commit/e91dff2c9f5559a16446bdfe1761e56bba1ac2b9))

## [1.0.3](https://github.com/josteph/esbuild-plugin-lodash/compare/1.0.2...1.0.3) (2021-05-16)


### Bug Fixes

* remove namespace option, use esbuild default namespace ([489d8b3](https://github.com/josteph/esbuild-plugin-lodash/commit/489d8b32a86e32aef8d4fcc32aad3475091efc17))

## [1.0.2](https://github.com/josteph/esbuild-plugin-lodash/compare/1.0.1...1.0.2) (2021-03-06)


### Bug Fixes

* loader & function type ([e710105](https://github.com/josteph/esbuild-plugin-lodash/commit/e710105e9a795ac2180b10efeeb52078668ba052))

## [1.0.1](https://github.com/josteph/esbuild-plugin-lodash/compare/1.0.0...1.0.1) (2021-03-06)


### Bug Fixes

* rename plugins ([da4f0e4](https://github.com/josteph/esbuild-plugin-lodash/commit/da4f0e4010c9d7a8ca0a2b77c42a69d9a97fde9f))


## [1.0.0](https://github.com/josteph/esbuild-plugin-lodash/releases/tag/1.0.0) (2021-03-06)
### Chores
* chore: add release opts [f028907](https://github.com/josteph/esbuild-plugin-lodash/commit/f028907)
* chore: add workflow [7426660](https://github.com/josteph/esbuild-plugin-lodash/commit/7426660)
* feat: add initial plugin [9ed8499](https://github.com/josteph/esbuild-plugin-lodash/commit/9ed8499)
* Initial commit [7197081](https://github.com/josteph/esbuild-plugin-lodash/commit/7197081)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Joshua Stephen
Copyright (c) 2024 DigitalMaas Pty Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
92 changes: 56 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,88 @@
# esbuild-plugin-lodash
# Esbuild Lodash Transform Plugin

[![npm](https://img.shields.io/npm/v/esbuild-plugin-lodash.svg)](https://www.npmjs.com/package/esbuild-plugin-lodash)

This plugin is for [esbuild](https://github.com/evanw/esbuild), similar to how [babel-plugin-lodash](https://github.com/lodash/babel-plugin-lodash) works for babel.


## Thoughts

The non-es `lodash` package is not tree-shakeable, this plugin is only for direct import workaround.

For better coding practices, you can use instead `lodash-es` directly or strictly import the required lodash function manually.
[![NPM version][version-badge]][npm-url]
[![NPM downloads][downloads-badge]][npm-url]
[![digitalmaas][dmaas-badge]][dmaas-url]

> An [esbuild](https://esbuild.github.io/) plugin that transforms [lodash](https://lodash.com/) imports.

## Installation

```sh
npm install --save-dev esbuild-plugin-lodash
```bash
npm install @digitalmaas/esbuild-plugin-lodash --save-dev
```


## Usage

Define plugin in the `plugins` section of esbuild config like this:
## Setup

```js
const esbuild = require('esbuild');
const lodashTransformer = require('esbuild-plugin-lodash');
import esbuild from 'esbuild'
import { transformLodashPlugin } from '@digitalmaas/esbuild-plugin-lodash'

esbuild.build({
// ...
await esbuild.build({
/* all of your config */,
plugins: [
lodashTransformer(),
],
transformLodashPlugin({ /* options */ }),
]
})
```

## Result
## Usage

Having this input file:

```js
import { get, isEmpty } from 'lodash';
import { get, isEmpty } from 'lodash'

const something = {};
const something = {}

get(something);
isEmpty(something);
get(something)
isEmpty(something)
```

It will output this following file content:

```js
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import get from 'lodash/get.js'
import isEmpty from 'lodash/isEmpty.js'

const something = {};
const something = {}

get(something);
isEmpty(something);
get(something)
isEmpty(something)
```

## Options

You can specify your own `filter` as per according to esbuild docs [here](https://esbuild.github.io/plugins/#concepts).
### `filter: RegExp`

You can specify your own `filter` as per according to esbuild docs [here][esbuild-onload]. Defaults to `/\.(js|cjs|mjs|ts|cts|mts|tsx)$/`.

### `namespace: string`

You can specify your own `namespace` as per according to esbuild docs [here][esbuild-onload].

### `appendJsExtension: boolean`

If `true`, the plugin will append `.js` to the end of CommonJS lodash imports. Defaults to `true`.

### `outputLodashPackage: string`

Specifies lodash package to use in output. Can be either `lodash` or `lodash-es`. Defaults to `lodash`.

## More Info

- https://esbuild.github.io/
- https://lodash.com/

## License

MIT License.

Complete license in [./LICENSE](./LICENSE) file.

You can specify `outLodashPackage` which by default is `lodash`. An example
of this would be specifying calls to be rewritten to use `lodash-es`.
[version-badge]: https://img.shields.io/npm/v/@digitalmaas/esbuild-plugin-lodash.svg?style=flat-square
[downloads-badge]: https://img.shields.io/npm/dm/@digitalmaas/esbuild-plugin-lodash.svg?style=flat-square
[dmaas-badge]: https://img.shields.io/badge/sponsored%20by-digitalmaas-green.svg?colorB=00CD98&style=flat-square
[npm-url]: https://www.npmjs.com/package/@digitalmaas/esbuild-plugin-lodash
[dmaas-url]: https://digitalmaas.com/
[esbuild-onload]: https://esbuild.github.io/plugins/#on-load-options
Loading