Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
feat: modernize and fix plugin (#110)
Browse files Browse the repository at this point in the history
@babel/traverse has a bug in the ExportNamedDeclaration traverser, which is fixed by iterating over the program level nodes by hand. This was suggested by the a maintainer of the babel repo and he said it should also improve performance.
  • Loading branch information
eseliger committed May 17, 2021
1 parent 780244f commit 38bf15d
Show file tree
Hide file tree
Showing 13 changed files with 5,455 additions and 5,726 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["@sourcegraph/eslint-config"],
"parserOptions": {
"project": "tsconfig.all.json"
}
}
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release
on:
push:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install dependencies
run: yarn install
- name: Run build
run: yarn build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn semantic-release
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test
on:
- push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install dependencies
run: yarn install
- name: Run build
run: yarn build
- name: Run prettier
run: yarn prettier-check
- name: Run eslint
run: yarn eslint
- name: Run tests
run: yarn test
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"files.exclude": {
"node_modules/**": true
}
"node_modules/**": true,
},
"editor.formatOnSave": true,
}
37 changes: 20 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"semantic-release": "semantic-release",
"prettier": "prettier '**/*.{js?(on),ts?(x),scss,md,yml}' --write --list-different",
"prettier-check": "npm run prettier -- --write=false",
"tslint": "tslint -c tslint.json -p tsconfig.json './src/*.ts?(x)' './*.ts?(x)'",
"eslint": "eslint './src/*.ts?(x)'",
"build": "tsc -p .",
"watch": "tsc -p . -w"
},
Expand All @@ -43,33 +43,36 @@
"private": false,
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/traverse": "^7.4.4"
"@babel/helper-plugin-utils": "^7.13.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
"@babel/core": "^7.2.0"
},
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/helper-plugin-test-runner": "^7.1.0",
"@babel/plugin-syntax-jsx": "^7.2.0",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@babel/traverse": "^7.4.4",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@sourcegraph/eslint-config": "^0.25.0",
"@sourcegraph/prettierrc": "^3.0.3",
"@sourcegraph/tsconfig": "^4.0.1",
"@sourcegraph/tslint-config": "^13.4.0",
"@types/babel__core": "7.1.7",
"@types/babel__traverse": "7.0.10",
"@types/jest": "25.2.1",
"@types/node": "12.12.14",
"babel-jest": "^24.8.0",
"babel-plugin-tester": "^6.2.1",
"husky": "^2.2.0",
"jest": "^24.8.0",
"@types/babel-plugin-tester": "^9.0.2",
"@types/babel__core": "7.1.14",
"@types/babel__helper-plugin-utils": "^7.10.0",
"@types/babel__traverse": "7.11.1",
"@types/jest": "26.0.23",
"@types/node": "15.3.0",
"babel-jest": "^26.6.3",
"babel-plugin-tester": "^10.0.0",
"eslint": "^7.26.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"prettier": "^2.0.5",
"semantic-release": "^15.13.12",
"tslint": "^6.1.1",
"typescript": "^3.4.5"
"semantic-release": "^17.4.3",
"typescript": "^4.2.4"
}
}
41 changes: 25 additions & 16 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
import pluginTester from 'babel-plugin-tester'

import plugin from '.'

const IMPORTS = `import { hot as _hot } from "react-hot-loader/root";\n`
const IMPORTS = "import { hot as _hot } from 'react-hot-loader/root'\n"

pluginTester({
plugin,
pluginName: 'babel-plugin-transform-react-hot-loader-wrapper',
babelOptions: { filename: 'Page.tsx' },
tests: [
{
title: 'const arrowfunc',
code: `export const A = () => 'a'`,
output: `${IMPORTS}export const A = _hot(() => 'a');`,
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' },
code: "export const A = () => 'a'",
output: `${IMPORTS}export const A = _hot(() => 'a')`,
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' },
},
{
title: 'class',
code: `export class A extends React.Component {}`,
output: `${IMPORTS}export const A = _hot(class A extends React.Component {});`,
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' },
code: 'export class A extends React.Component {}',
output: `${IMPORTS}export const A = _hot(class A extends React.Component {})`,
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' },
},
{
title: 'function',
code: `export function A(props) { return 'a'; }`,
output: `${IMPORTS}export const A = _hot(function A(props) {\n return 'a';\n});`,
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' },
code: "export function A(props) { return 'a'; }",
output: `${IMPORTS}export const A = _hot(function A(props) {\n return 'a'\n})`,
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' },
},
{
title: 'ignored by componentNamePattern',
code: `export const X = () => 'a'`,
output: `export const X = () => 'a';`,
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' },
code: "export const X = () => 'a'",
output: "export const X = () => 'a'",
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' },
},
{
title: 'ignored by modulePattern',
code: "export const A = () => 'a'",
output: "export const A = () => 'a'",
pluginOptions: { modulePattern: 'Area\\.tsx?', componentNamePattern: '^A$' },
},
{
title: 'multiple in same file',
code: `export const A = () => 'a'; export const B = () => 'b'`,
output: `${IMPORTS}export const A = _hot(() => 'a');\nexport const B = _hot(() => 'b');`,
pluginOptions: { modulePattern: '', componentNamePattern: '' },
code: "export const A = () => 'a'; export const B = () => 'b'",
output: `${IMPORTS}export const A = _hot(() => 'a')\nexport const B = _hot(() => 'b')`,
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '' },
},
],
})

0 comments on commit 38bf15d

Please sign in to comment.