Skip to content

Commit

Permalink
feat: upgrade all packages
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node support bumped to Node >= 8
  • Loading branch information
Kent C. Dodds committed Nov 14, 2019
1 parent 1e42fa0 commit c50df22
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 83 deletions.
17 changes: 17 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"arrowParens": "avoid",
"bracketSpacing": false,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
49 changes: 11 additions & 38 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Thanks for being willing to contribute!

**Working on your first Pull Request?** You can learn how from this _free_ series
[How to Contribute to an Open Source Project on GitHub][egghead]
**Working on your first Pull Request?** You can learn how from this _free_
series [How to Contribute to an Open Source Project on GitHub][egghead]

## Project setup

Expand All @@ -21,45 +21,17 @@ Thanks for being willing to contribute!
> git branch --set-upstream-to=upstream/master master
> ```
>
> This will add the original repository as a "remote" called "upstream,"
> Then fetch the git information from that remote, then set your local `master`
> branch to use the upstream master branch whenever you run `git pull`.
> Then you can make all of your pull request branches based on this `master`
> branch. Whenever you want to update your version of `master`, do a regular
> `git pull`.
## Add yourself as a contributor
This project follows the [all contributors][all-contributors] specification.
To add yourself to the table of contributors on the `README.md`, please use the
automated script as part of your PR:
```console
npm run add-contributor
```
Follow the prompt and commit `.all-contributorsrc` and `README.md` in the PR.
If you've already added yourself to the list and are making
a new type of contribution, you can run it again and select the added
contribution type.
> This will add the original repository as a "remote" called "upstream," Then
> fetch the git information from that remote, then set your local `master`
> branch to use the upstream master branch whenever you run `git pull`. Then you
> can make all of your pull request branches based on this `master` branch.
> Whenever you want to update your version of `master`, do a regular `git pull`.
## Committing and Pushing changes
Please make sure to run the tests before you commit your changes. You can run
`npm run test:update` which will update any snapshots that need updating.
Make sure to include those changes (if they exist) in your commit.

### opt into git hooks

There are git hooks set up with this project that are automatically installed
when you install dependencies. They're really handy, but are turned off by
default (so as to not hinder new contributors). You can opt into these by
creating a file called `.opt-in` at the root of the project and putting this
inside:

```
pre-commit
```
`npm run test:update` which will update any snapshots that need updating. Make
sure to include those changes (if they exist) in your commit.
## Help needed
Expand All @@ -68,6 +40,7 @@ Please checkout the [the open issues][issues]
Also, please watch the repo and respond to questions/bug reports/feature
requests! Thanks!
[egghead]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github
[egghead]:
https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github
[all-contributors]: https://github.com/kentcdodds/all-contributors
[issues]: https://github.com/kentcdodds/babel-plugin-preval/issues
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
"version": "0.0.0-semantically-released",
"description": "Pre-evaluate code at build-time",
"engines": {
"node": ">=4",
"npm": ">=3"
"node": ">=8",
"npm": ">=6"
},
"main": "dist/index.js",
"scripts": {
"add-contributor": "kcd-scripts contributors add",
"build": "kcd-scripts build",
"lint": "kcd-scripts lint",
"test": "kcd-scripts test",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"precommit": "kcd-scripts precommit"
"validate": "kcd-scripts validate"
},
"husky": {
"hooks": {
"pre-commit": "kcd-scripts pre-commit"
}
},
"files": [
"dist",
Expand All @@ -30,13 +33,14 @@
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
"license": "MIT",
"dependencies": {
"babel-plugin-macros": "^2.2.2",
"@babel/runtime": "^7.7.2",
"babel-plugin-macros": "^2.6.1",
"require-from-string": "^2.0.2"
},
"devDependencies": {
"ast-pretty-print": "^2.0.1",
"babel-plugin-tester": "^5.4.0",
"kcd-scripts": "^0.39.1"
"babel-plugin-tester": "^7.0.3",
"kcd-scripts": "^1.11.0"
},
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js"
Expand All @@ -47,7 +51,9 @@
"dist"
],
"babel": {
"presets": "kcd-scripts/babel"
"presets": [
"kcd-scripts/babel"
]
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/fixtures/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["env"],
"plugins": ["transform-inline-environment-variables"],
"presets": ["@babel/preset-env"],
"plugins": ["transform-inline-environment-variables"]
}
15 changes: 12 additions & 3 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ pluginTester({
'import x from /* preval */ /* this is extra stuff */ "./fixtures/compute-one.js"',
'import comment (with extras before)':
'import x from /* this is extra stuff */ /* preval */ "./fixtures/compute-one.js"',
'invalid comment': noSnapshot(
'import x from /* this is extra stuff */"./fixtures/compute-one.js";',
),
'invalid comment': {
// no real changes here, but babel does weird stuff to comments like this...
code:
'import x from /* this is extra stuff */"./fixtures/compute-one.js";',
output: `
import x from
/* this is extra stuff */
"./fixtures/compute-one.js";
`,
snapshot: false,
},
'import string arg':
'import x from /* preval("string argument") */ "./fixtures/identity.js"',
'import object arg':
Expand Down Expand Up @@ -90,6 +98,7 @@ pluginTester({
'comment no contents': noSnapshot('// @preval'),
'comment with only comment contents': noSnapshot(`
// @preval
/* comment */
`),
'handles transpiled modules (uses default export)': `
Expand Down
42 changes: 11 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ function prevalPlugin(babel) {
return {
name: 'preval',
visitor: {
Program(
path,
{
file: {opts: fileOpts},
},
) {
Program(path, {file: {opts: fileOpts}}) {
const firstNode = path.node.body[0] || {}
const comments = firstNode.leadingComments || []
const isPreval = comments.some(isPrevalComment)
Expand All @@ -40,9 +35,8 @@ function prevalPlugin(babel) {
)
const replacement = getReplacement({string, fileOpts, babel})

const moduleExports = Object.assign(
{},
t.expressionStatement(
const moduleExports = {
...t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(
Expand All @@ -52,17 +46,12 @@ function prevalPlugin(babel) {
replacement,
),
),
{leadingComments: comments},
)
leadingComments: comments,
}

path.replaceWith(t.program([moduleExports]))
},
TaggedTemplateExpression(
path,
{
file: {opts: fileOpts},
},
) {
TaggedTemplateExpression(path, {file: {opts: fileOpts}}) {
const isPreval = path.node.tag.name === 'preval'
if (!isPreval) {
return
Expand All @@ -74,12 +63,7 @@ function prevalPlugin(babel) {
const replacement = getReplacement({string, fileOpts, babel})
path.replaceWith(replacement)
},
ImportDeclaration(
path,
{
file: {opts: fileOpts},
},
) {
ImportDeclaration(path, {file: {opts: fileOpts}}) {
const isPreval = looksLike(path, {
node: {
source: {
Expand Down Expand Up @@ -124,12 +108,7 @@ function prevalPlugin(babel) {
}),
)
},
CallExpression(
path,
{
file: {opts: fileOpts},
},
) {
CallExpression(path, {file: {opts: fileOpts}}) {
const isPreval = looksLike(path, {
node: {
callee: {
Expand Down Expand Up @@ -204,6 +183,7 @@ function isPrimitive(val) {

/*
eslint
import/no-unassigned-import:0
import/no-dynamic-require:0
import/no-unassigned-import: off,
import/no-dynamic-require: off,
max-lines-per-function: off,
*/

0 comments on commit c50df22

Please sign in to comment.