Skip to content

Commit 1a5f4b9

Browse files
committed
Use ESM
1 parent e299184 commit 1a5f4b9

File tree

15 files changed

+55
-111
lines changed

15 files changed

+55
-111
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
6-
mdast-zone.js
7-
mdast-zone.min.js
85
yarn.lock

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
mdast-zone.js
3-
mdast-zone.min.js
4-
*.json
52
*.md

index.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
'use strict'
1+
import {commentMarker} from 'mdast-comment-marker'
2+
import {visit} from 'unist-util-visit'
23

3-
var commentMarker = require('mdast-comment-marker')
4-
var visit = require('unist-util-visit')
5-
6-
module.exports = zone
7-
8-
var splice = [].splice
9-
10-
function zone(node, name, callback) {
4+
export function zone(node, name, callback) {
115
var level
126
var marker
137
var scope
@@ -44,14 +38,11 @@ function zone(node, name, callback) {
4438
marker,
4539
scope.children.slice(start + 1, index),
4640
node,
47-
{start: start, end: index, parent: parent}
41+
{start, end: index, parent}
4842
)
4943

5044
if (result) {
51-
splice.apply(
52-
scope.children,
53-
[start, index - start + 1].concat(result)
54-
)
45+
scope.children.splice(start, index - start + 1, ...result)
5546
}
5647

5748
marker = undefined

package.json

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,31 @@
2626
"contributors": [
2727
"Titus Wormer <[email protected]> (https://wooorm.com)"
2828
],
29+
"sideEffects": false,
30+
"type": "module",
31+
"main": "index.js",
2932
"files": [
3033
"index.js"
3134
],
3235
"dependencies": {
33-
"mdast-comment-marker": "^1.0.0",
34-
"unist-util-visit": "^2.0.0"
36+
"mdast-comment-marker": "^2.0.0",
37+
"unist-util-visit": "^3.0.0"
3538
},
3639
"devDependencies": {
37-
"browserify": "^17.0.0",
38-
"is-hidden": "^1.0.0",
39-
"nyc": "^15.0.0",
40+
"c8": "^7.0.0",
41+
"is-hidden": "^2.0.0",
4042
"prettier": "^2.0.0",
4143
"remark": "^13.0.0",
4244
"remark-cli": "^9.0.0",
4345
"remark-preset-wooorm": "^8.0.0",
4446
"tape": "^5.0.0",
45-
"tinyify": "^3.0.0",
46-
"xo": "^0.38.0"
47+
"xo": "^0.39.0"
4748
},
4849
"scripts": {
4950
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
50-
"build-bundle": "browserify . -s mdastZone -o mdast-zone.js",
51-
"build-mangle": "browserify . -s mdastZone -o mdast-zone.min.js -p tinyify",
52-
"build": "npm run build-bundle && npm run build-mangle",
53-
"test-api": "node test",
54-
"test-coverage": "nyc --reporter lcov tape test/index.js",
55-
"test": "npm run format && npm run build && npm run test-coverage"
56-
},
57-
"nyc": {
58-
"check-coverage": true,
59-
"lines": 100,
60-
"functions": 100,
61-
"branches": 100
51+
"test-api": "node test/index.js",
52+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
53+
"test": "npm run format && npm run test-coverage"
6254
},
6355
"prettier": {
6456
"tabWidth": 2,
@@ -70,14 +62,10 @@
7062
},
7163
"xo": {
7264
"prettier": true,
73-
"esnext": false,
7465
"rules": {
75-
"unicorn/no-fn-reference-in-iterator": "off",
76-
"unicorn/prefer-optional-catch-binding": "off"
77-
},
78-
"ignores": [
79-
"mdast-zone.js"
80-
]
66+
"no-var": "off",
67+
"prefer-arrow-callback": "off"
68+
}
8169
},
8270
"remarkConfig": {
8371
"plugins": [

readme.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Useful in [**remark**][remark] plugins.
1414

1515
## Install
1616

17+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
18+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
19+
1720
[npm][]:
1821

1922
```sh
@@ -35,13 +38,13 @@ Foo
3538
And our script, `example.js`, looks as follows:
3639

3740
```js
38-
var vfile = require('to-vfile')
39-
var remark = require('remark')
40-
var zone = require('mdast-zone')
41+
import toVFile from 'to-vfile'
42+
import remark from 'remark'
43+
import {zone} from 'mdast-zone'
4144

4245
remark()
4346
.use(plugin)
44-
.process(vfile.readSync('example.md'), function(err, file) {
47+
.process(toVFile.readSync('example.md'), function(err, file) {
4548
if (err) throw err
4649
console.log(String(file))
4750
})
@@ -75,6 +78,9 @@ Bar
7578

7679
## API
7780

81+
This package exports the following identifiers: `zone`.
82+
There is no default export.
83+
7884
### `zone(tree, name, handler)`
7985

8086
Search `tree` for comment ranges (“zones”).

test/fixtures/mismatched/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
zone(tree, 'foo', handle)
73

84
function handle() {

test/fixtures/nodes/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
var count = 0
73

84
t.test('nodes', function (st) {

test/fixtures/non-marker/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
zone(tree, 'foo', handle)
73

84
function handle() {

test/fixtures/range-children/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
var count = 0
73

84
t.test('range-children', function (st) {

test/fixtures/remove-children/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
zone(tree, 'foo', handle)
73

84
function handle(start, nodes, end) {

test/fixtures/remove/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
zone(tree, 'foo', handle)
73

84
function handle() {

test/fixtures/replace-children/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
zone(tree, 'foo', handle)
73

84
function handle(start, nodes, end) {

test/fixtures/replace/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
zone(tree, 'foo', handle)
73

84
function handle() {

test/fixtures/simple/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
'use strict'
2-
3-
module.exports = assertion
4-
5-
function assertion(t, zone, tree) {
1+
export default function assertion(t, zone, tree) {
62
t.test('range', function (st) {
73
st.plan(5)
84

test/index.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
'use strict'
2-
3-
var fs = require('fs')
4-
var path = require('path')
5-
var test = require('tape')
6-
var remark = require('remark')
7-
var hidden = require('is-hidden')
8-
var zone = require('..')
9-
10-
test('mdast-zone', function (t) {
11-
var root = path.join(__dirname, 'fixtures')
1+
import fs from 'fs'
2+
import path from 'path'
3+
import test from 'tape'
4+
import remark from 'remark'
5+
import {isHidden} from 'is-hidden'
6+
import {zone} from '../index.js'
7+
8+
test('mdast-zone', async function (t) {
9+
var root = path.join('test', 'fixtures')
1210
var fixtures = fs.readdirSync(root)
1311
var index = -1
1412
var output
1513
var name
16-
var test
14+
var mod
1715

1816
while (++index < fixtures.length) {
1917
name = fixtures[index]
2018
output = null
2119

22-
if (hidden(name)) continue
20+
if (isHidden(name)) continue
2321

2422
try {
2523
output = fs.readFileSync(path.join(root, name, 'output.md'))
26-
} catch (_) {}
24+
} catch {}
2725

28-
test = require(path.join(root, name))
26+
mod =
27+
/* eslint-disable-next-line no-await-in-loop */
28+
(await import(new URL('fixtures/' + name + '/index.js', import.meta.url)))
29+
.default
2930

3031
remark()
3132
.use(() => (tree) => {
32-
test(t, zone, tree)
33+
mod(t, zone, tree)
3334
})
3435
.process(
3536
fs.readFileSync(path.join(root, name, 'input.md')),

0 commit comments

Comments
 (0)