Skip to content

Commit a8d44b6

Browse files
committed
Require Node.js 14, move to ESM, and support modern JS syntax
Fixes #28
1 parent 3c88207 commit a8d44b6

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 18
14+
- 16
1315
- 14
14-
- 12
1516
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v1
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
1819
with:
1920
node-version: ${{ matrix.node-version }}
2021
- run: npm install

index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
'use strict';
2-
const through = require('through2');
3-
const stripDebug = require('strip-debug');
4-
const PluginError = require('plugin-error');
1+
import {Buffer} from 'node:buffer';
2+
import transformStream from 'easy-transform-stream';
3+
import PluginError from 'plugin-error';
4+
import {transformAsync} from '@babel/core';
5+
import stripDebug from 'strip-debug';
56

6-
module.exports = () => {
7-
return through.obj(function (file, encoding, callback) {
7+
export default function gulpStripDebug() {
8+
return transformStream({objectMode: true}, async file => {
89
if (file.isNull()) {
9-
callback(null, file);
10-
return;
10+
return file;
1111
}
1212

1313
if (file.isStream()) {
14-
callback(new PluginError('gulp-strip-debug', 'Streaming not supported'));
15-
return;
14+
throw new PluginError('gulp-strip-debug', 'Streaming not supported');
1615
}
1716

1817
try {
19-
file.contents = Buffer.from(stripDebug(file.contents.toString()).toString());
20-
this.push(file);
18+
const {code} = await transformAsync(file.contents.toString(), {plugins: [stripDebug]});
19+
file.contents = Buffer.from(code);
2120
} catch (error) {
22-
this.emit('error', new PluginError('gulp-strip-debug', error, {fileName: file.path}));
21+
throw new PluginError('gulp-strip-debug', error, {fileName: file.path});
2322
}
2423

25-
callback();
24+
return file;
2625
});
27-
};
26+
}

package.json

Lines changed: 11 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": ">=12"
16+
"node": ">=14.16"
1517
},
1618
"scripts": {
1719
"test": "xo && ava"
@@ -37,15 +39,16 @@
3739
"esprima"
3840
],
3941
"dependencies": {
40-
"plugin-error": "^1.0.1",
41-
"strip-debug": "^5.0.0",
42-
"through2": "^4.0.2"
42+
"@babel/core": "^7.20.5",
43+
"easy-transform-stream": "^1.0.0",
44+
"plugin-error": "^2.0.0",
45+
"strip-debug": "^7.0.0"
4346
},
4447
"devDependencies": {
45-
"ava": "^2.4.0",
46-
"p-event": "^4.2.0",
47-
"vinyl": "^2.2.1",
48-
"xo": "^0.38.2"
48+
"ava": "^5.1.0",
49+
"p-event": "^5.0.1",
50+
"vinyl": "^3.0.0",
51+
"xo": "^0.53.1"
4952
},
5053
"peerDependencies": {
5154
"gulp": ">=4"

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
55
## Install
66

7-
```
8-
$ npm install --save-dev gulp-strip-debug
7+
```sh
8+
npm install --save-dev gulp-strip-debug
99
```
1010

1111
## Usage
1212

1313
```js
14-
const gulp = require('gulp');
15-
const stripDebug = require('gulp-strip-debug');
14+
import gulp from 'gulp';
15+
import stripDebug from'gulp-strip-debug';
1616

17-
exports.default = () => (
17+
export default () => (
1818
gulp.src('src/app.js')
1919
.pipe(stripDebug())
2020
.pipe(gulp.dest('dist'))

test.js

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

67
test('strips debugging statements', async t => {
78
const stream = stripDebug();
89
const promise = pEvent(stream, 'data');
910

1011
stream.end(new Vinyl({
11-
contents: Buffer.from('function test(){debugger;}')
12+
contents: Buffer.from('function test(){const x = a ?? b; debugger;}'),
1213
}));
1314

1415
const file = await promise;
15-
t.is(file.contents.toString(), 'function test(){}');
16+
t.is(file.contents.toString(), 'function test() {\n const x = a ?? b;\n}');
1617
});
1718

1819
test('strips `console.log()` statements', async t => {
1920
const stream = stripDebug();
2021
const promise = pEvent(stream, 'data');
2122

2223
stream.end(new Vinyl({
23-
contents: Buffer.from('function test(){console.log(...colors);}')
24+
contents: Buffer.from('function test(){console.log(...colors);}'),
2425
}));
2526

2627
const file = await promise;
27-
t.is(file.contents.toString(), 'function test(){void 0;}');
28+
t.is(file.contents.toString(), 'function test() {\n void 0;\n}');
2829
});

0 commit comments

Comments
 (0)