Skip to content
This repository was archived by the owner on Feb 8, 2020. It is now read-only.

Commit 322aa8b

Browse files
author
tunnckoCore
committed
fix(build): move to es6 modules by default
expose both CJS and ESM modules; move contents of root to src/ folder TAG: latest
1 parent d9d2835 commit 322aa8b

File tree

11 files changed

+60
-44
lines changed

11 files changed

+60
-44
lines changed

.verb.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $ npm install {%= name %}
5353
## API
5454
Review carefully the provided examples and the working [tests](./test.js).
5555

56-
{%= apidocs('index.js') %}
56+
{%= apidocs('src/index.js') %}
5757

5858
{% if (verb.related && verb.related.list && verb.related.list.length) { %}
5959
## Related

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ $ npm install parse-function
6464
## API
6565
Review carefully the provided examples and the working [tests](./test.js).
6666

67-
### [parseFunction](index.js#L59)
67+
### [parseFunction](src/index.js#L59)
6868

6969
> Initializes with optional `opts` object which is passed directly
7070
to the desired parser and returns an object
@@ -106,7 +106,7 @@ console.log(result.args) // => ['a', 'b', 'c']
106106
console.log(result.params) // => 'a, b, c'
107107
```
108108

109-
### [.parse](index.js#L98)
109+
### [.parse](src/index.js#L98)
110110

111111
> Parse a given `code` and returns a `result` object
112112
with useful properties - such as `name`, `body` and `args`.
@@ -144,7 +144,7 @@ console.log(result.isAnonymous) // => false
144144
console.log(result.isGenerator) // => false
145145
```
146146

147-
### [.use](index.js#L164)
147+
### [.use](src/index.js#L164)
148148
> Add a plugin `fn` function for extending the API or working on the AST nodes. The `fn` is immediately invoked and passed with `app` argument which is instance of `parseFunction()` call. That `fn` may return another function that accepts `(node, result)` signature, where `node` is an AST node and `result` is an object which will be returned [result](#result) from the `.parse` method. This retuned function is called on each node only when `.parse` method is called.
149149
150150
_See [Plugins Architecture](#plugins-architecture) section._
@@ -184,7 +184,7 @@ console.log(result.isArrow) // => false
184184
console.log(result.thatIsArrow) // => undefined
185185
```
186186

187-
### [.define](index.js#L223)
187+
### [.define](src/index.js#L223)
188188

189189
> Define a non-enumerable property on an object. Just
190190
a convenience mirror of the [define-property][] library,
@@ -261,7 +261,7 @@ Copyright © 2016-2017, [Charlike Mike Reagent](https://i.am.charlike.online). R
261261

262262
***
263263

264-
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 10, 2017._
264+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 11, 2017._
265265
Project scaffolded using [charlike-cli][].
266266

267267
[acorn]: https://github.com/ternjs/acorn

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
"homepage": "https://github.com/tunnckoCore/parse-function",
77
"author": "Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)",
88
"nspId": "5d75a388-acfe-4668-ad18-e98564e387e1",
9-
"main": "./index.js",
9+
"module": "./dest/index.mjs",
10+
"main": "./dest/index.js",
1011
"license": "MIT",
1112
"scripts": {
1213
"renovate": "hela renovate",
1314
"lint": "hela lint -c .eslintrc.json",
15+
"pretest": "hela build && hela pretest",
1416
"test": "hela test node test.js",
17+
"posttest": "hela posttest",
1518
"precommit": "hela precommit",
1619
"commit": "hela commit",
1720
"postcommit": "git push",
@@ -22,8 +25,7 @@
2225
"npm": ">=5"
2326
},
2427
"files": [
25-
"index.js",
26-
"lib/"
28+
"dest/"
2729
],
2830
"dependencies": {
2931
"arrify": "1.0.1",

rollup.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const pkg = require('./package.json')
2+
3+
module.exports = {
4+
entry: 'src/index.js',
5+
external: Object.keys(pkg.dependencies),
6+
targets: [
7+
{ dest: 'dest/index.js', format: 'cjs' },
8+
{ dest: 'dest/index.mjs', format: 'es' },
9+
],
10+
}

index.js renamed to src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* Utilities
1010
*/
1111

12-
const utils = require('./lib/utils')
12+
import utils from './lib/utils.js'
1313

1414
/**
1515
* Core plugins
1616
*/
1717

18-
const initial = require('./lib/plugins/initial')
18+
import initial from './lib/plugins/initial.js'
1919

2020
/**
2121
* > Initializes with optional `opts` object which is passed directly
@@ -55,7 +55,7 @@ const initial = require('./lib/plugins/initial')
5555
* @name parseFunction
5656
* @public
5757
*/
58-
module.exports = function parseFunction (opts) {
58+
export default function parseFunction (opts) {
5959
const plugins = []
6060
const app = {
6161
/**

lib/plugins/body.js renamed to src/lib/plugins/body.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
* Released under the MIT license.
66
*/
77

8+
/* eslint-disable jsdoc/require-param-description, jsdoc/check-param-names */
9+
810
/**
911
* > Micro plugin to get the raw body, without the
1012
* surrounding curly braces. It also preserves
1113
* the whitespaces and newlines - they are original.
1214
*
13-
* @param {Object} `node`
14-
* @param {Object} `result`
15-
* @return {Object} `result`
16-
* @api private
15+
* @param {Object} node
16+
* @param {Object} result
17+
* @return {Object} result
18+
* @private
1719
*/
18-
19-
module.exports = (app) => (node, result) => {
20+
export default (app) => (node, result) => {
2021
result.body = result.value.slice(node.body.start, node.body.end)
2122

2223
const openCurly = result.body.charCodeAt(0) === 123

lib/plugins/initial.js renamed to src/lib/plugins/initial.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55
* Released under the MIT license.
66
*/
77

8-
const body = require('./body')
9-
const props = require('./props')
10-
const params = require('./params')
8+
/* eslint-disable jsdoc/require-param-description, jsdoc/check-param-names */
9+
10+
import body from './body.js'
11+
import props from './props.js'
12+
import params from './params.js'
1113

1214
/**
1315
* > Default plugin that handles regular functions,
1416
* arrow functions, generator functions
1517
* and ES6 object method notation.
1618
*
17-
* @param {Object} `node`
18-
* @param {Object} `result`
19-
* @return {Object} `result`
20-
* @api private
19+
* @param {Object} node
20+
* @param {Object} result
21+
* @return {Object} resul
22+
* @private
2123
*/
22-
23-
module.exports = (app) => (node, result) => {
24+
export default (app) => (node, result) => {
2425
const isFn = node.type.endsWith('FunctionExpression')
2526
const isMethod = node.type === 'ObjectExpression'
2627

lib/plugins/params.js renamed to src/lib/plugins/params.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
* Released under the MIT license.
66
*/
77

8+
/* eslint-disable jsdoc/require-param-description, jsdoc/check-param-names */
9+
810
/**
911
* > Micro plugin to visit each of the params
1012
* in the given function and collect them into
1113
* an `result.args` array and `result.params` string.
1214
*
13-
* @param {Object} `node`
14-
* @param {Object} `result`
15-
* @return {Object} `result`
16-
* @api private
15+
* @param {Object} node
16+
* @param {Object} result
17+
* @return {Object} result
18+
* @private
1719
*/
18-
19-
module.exports = (app) => (node, result) => {
20+
export default (app) => (node, result) => {
2021
if (!node.params.length) {
2122
return result
2223
}

lib/plugins/props.js renamed to src/lib/plugins/props.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Released under the MIT license.
66
*/
77

8+
/* eslint-disable jsdoc/require-param-description, jsdoc/check-param-names */
9+
810
/**
911
* > Set couple of hidden properties and
1012
* the name of the given function to
@@ -15,13 +17,12 @@
1517
* only when function is really anonymous and don't have
1618
* any name.
1719
*
18-
* @param {Object} `node`
19-
* @param {Object} `result`
20-
* @return {Object} `result`
21-
* @api private
20+
* @param {Object} node
21+
* @param {Object} result
22+
* @return {Object} result
23+
* @private
2224
*/
23-
24-
module.exports = (app) => (node, result) => {
25+
export default (app) => (node, result) => {
2526
app.define(result, 'isArrow', node.type.startsWith('Arrow'))
2627
app.define(result, 'isAsync', node.async || false)
2728
app.define(result, 'isGenerator', node.generator || false)

lib/utils.js renamed to src/lib/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
/* eslint-disable jsdoc/require-param-description */
99

10-
const arrayify = require('arrify')
11-
const babylon = require('babylon')
12-
const define = require('define-property')
10+
import arrayify from 'arrify'
11+
import babylon from 'babylon'
12+
import define from 'define-property'
1313

1414
const utils = {}
1515
utils.define = define
@@ -87,4 +87,4 @@ utils.getNode = function getNode (result, opts) {
8787
return babylon.parseExpression(result.value, opts)
8888
}
8989

90-
module.exports = utils
90+
export default utils

0 commit comments

Comments
 (0)