Skip to content

Commit a462808

Browse files
committed
Require Node.js 18 and move to ESM
1 parent 788efa2 commit a462808

File tree

8 files changed

+41
-62
lines changed

8 files changed

+41
-62
lines changed

.github/funding.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
15-
- 10
13+
- 20
14+
- 18
1615
steps:
17-
- uses: actions/checkout@v2
18-
- uses: actions/setup-node@v1
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1918
with:
2019
node-version: ${{ matrix.node-version }}
2120
- run: npm install

gulpfile.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
'use strict';
2-
const gulp = require('gulp');
3-
const jsValidate = require('.');
1+
import gulp from 'gulp';
2+
import jsValidate from './index.js';
43

5-
exports.default = () => (
6-
gulp.src('fixture.js')
7-
.pipe(jsValidate())
8-
);
4+
export default function main() {
5+
return gulp.src('fixture.js')
6+
.pipe(jsValidate());
7+
}

index.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
1-
'use strict';
2-
const through = require('through2');
3-
const esprima = require('esprima');
4-
const PluginError = require('plugin-error');
1+
import esprima from 'esprima';
2+
import {gulpPlugin} from 'gulp-plugin-extras';
53

6-
module.exports = ({module: useModule = true} = {}) => {
4+
export default function gulpJsValidate({module: useModule = true} = {}) {
75
const parse = useModule ? esprima.parseModule : esprima.parseScript;
86

9-
return through.obj(function (file, encoding, callback) {
10-
if (file.isNull()) {
11-
callback(null, file);
12-
return;
13-
}
14-
15-
if (file.isStream()) {
16-
callback(new PluginError('gulp-jsvalidate', 'Streaming not supported'));
17-
return;
18-
}
19-
20-
let errors;
21-
22-
try {
23-
errors = parse(file.contents.toString(), {tolerant: true}).errors;
24-
} catch (error_) { // eslint-disable-line unicorn/catch-error-name
25-
this.emit('error', new PluginError('gulp-jsvalidate', error_, {fileName: file.path}));
26-
}
7+
return gulpPlugin('gulp-jsvalidate', file => {
8+
const {errors} = parse(file.contents.toString(), {tolerant: true});
279

28-
if (errors && errors.length > 0) {
29-
this.emit('error', new PluginError('gulp-jsvalidate', '\n' + errors.join('\n'), {
30-
fileName: file.path,
31-
showStack: false
32-
}));
10+
if (errors.length > 0) {
11+
const error = new Error(`\n${errors.join('\n')}`);
12+
error.isPresentable = true;
13+
throw error;
3314
}
3415

35-
callback(null, file);
16+
return file;
3617
});
37-
};
18+
}

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"email": "[email protected]",
1111
"url": "https://sindresorhus.com"
1212
},
13+
"type": "module",
14+
"exports": "./index.js",
1315
"engines": {
14-
"node": ">=10"
16+
"node": ">=18"
1517
},
1618
"scripts": {
1719
"test": "xo && ava"
@@ -34,16 +36,15 @@
3436
"code"
3537
],
3638
"dependencies": {
37-
"esprima": "^4.0.0",
38-
"plugin-error": "^1.0.1",
39-
"through2": "^3.0.1"
39+
"esprima": "^4.0.1",
40+
"gulp-plugin-extras": "^0.2.2"
4041
},
4142
"devDependencies": {
42-
"ava": "^2.3.0",
43+
"ava": "^5.3.1",
4344
"gulp": "^4.0.2",
44-
"p-event": "^4.1.0",
45-
"vinyl": "^2.1.0",
46-
"xo": "^0.25.3"
45+
"p-event": "^6.0.0",
46+
"vinyl": "^3.0.0",
47+
"xo": "^0.56.0"
4748
},
4849
"peerDependencies": {
4950
"gulp": ">=4"

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ The earlier you find syntax errors, the earlier you can fix them.
88

99
## Install
1010

11-
```
12-
$ npm install --save-dev gulp-jsvalidate
11+
```sh
12+
npm install --save-dev gulp-jsvalidate
1313
```
1414

1515
## Usage
1616

1717
```js
18-
const gulp = require('gulp');
19-
const jsValidate = require('gulp-jsvalidate');
18+
import gulp from 'gulp';
19+
import jsValidate from 'gulp-jsvalidate';
2020

21-
exports.default = () => (
21+
export default () => (
2222
gulp.src('app.js')
2323
.pipe(jsValidate())
2424
);

test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import {Buffer} from 'node:buffer';
12
import test from 'ava';
23
import Vinyl from 'vinyl';
3-
import pEvent from 'p-event';
4-
import gulpJsvalidate from '.';
4+
import {pEvent} from 'p-event';
5+
import gulpJsvalidate from './index.js';
56

67
test('main', async t => {
78
const stream = gulpJsvalidate({module: false});
89
const errorPromise = pEvent(stream);
910

1011
stream.end(new Vinyl({
11-
contents: Buffer.from('const foo = \'bar;')
12+
contents: Buffer.from('const foo = \'bar;'),
1213
}));
1314

1415
await t.throwsAsync(errorPromise, {message: /Unexpected token/});
@@ -19,7 +20,7 @@ test('supports `import`', async t => {
1920
const errorPromise = pEvent(stream, 'data');
2021

2122
stream.end(new Vinyl({
22-
contents: Buffer.from('import foo from \'foo\';')
23+
contents: Buffer.from('import foo from \'foo\';'),
2324
}));
2425

2526
await t.notThrowsAsync(errorPromise);

0 commit comments

Comments
 (0)