diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..843a114 --- /dev/null +++ b/.prettierrc @@ -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 +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 10b9aae..0f1ba96 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 @@ -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 diff --git a/package.json b/package.json index eb3741e..ef701c4 100644 --- a/package.json +++ b/package.json @@ -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", @@ -30,13 +33,14 @@ "author": "Kent C. Dodds (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" @@ -47,7 +51,9 @@ "dist" ], "babel": { - "presets": "kcd-scripts/babel" + "presets": [ + "kcd-scripts/babel" + ] }, "repository": { "type": "git", diff --git a/src/__tests__/fixtures/.babelrc b/src/__tests__/fixtures/.babelrc index b7be34e..e9904b5 100644 --- a/src/__tests__/fixtures/.babelrc +++ b/src/__tests__/fixtures/.babelrc @@ -1,4 +1,4 @@ { - "presets": ["env"], - "plugins": ["transform-inline-environment-variables"], + "presets": ["@babel/preset-env"], + "plugins": ["transform-inline-environment-variables"] } diff --git a/src/__tests__/index.js b/src/__tests__/index.js index fae7e63..ae9926e 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -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': @@ -90,6 +98,7 @@ pluginTester({ 'comment no contents': noSnapshot('// @preval'), 'comment with only comment contents': noSnapshot(` // @preval + /* comment */ `), 'handles transpiled modules (uses default export)': ` diff --git a/src/index.js b/src/index.js index 3f4d634..906c102 100644 --- a/src/index.js +++ b/src/index.js @@ -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) @@ -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( @@ -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 @@ -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: { @@ -124,12 +108,7 @@ function prevalPlugin(babel) { }), ) }, - CallExpression( - path, - { - file: {opts: fileOpts}, - }, - ) { + CallExpression(path, {file: {opts: fileOpts}}) { const isPreval = looksLike(path, { node: { callee: { @@ -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, */