Skip to content

Commit 8055c2e

Browse files
authored
Merge pull request #14 from unassert-js/unassert-v2
Update unassert to v2.0.0
2 parents e8a7e5d + 4719de9 commit 8055c2e

File tree

13 files changed

+6198
-1574
lines changed

13 files changed

+6198
-1574
lines changed

.github/workflows/node.js.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [14.x, 16.x, 18.x]
17+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
- run: npm ci
26+
- run: npm test

.travis.yml

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

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[![unassert][unassert-banner]][unassert-url]
66

7-
[![Build Status][travis-image]][travis-url]
7+
[![Build Status][ci-image]][ci-url]
88
[![NPM version][npm-image]][npm-url]
99
[![Code Style][style-image]][style-url]
1010
[![License][license-image]][license-url]
@@ -58,6 +58,27 @@ function build() {
5858
exports.build = build;
5959
```
6060

61+
### custom unassert options
62+
63+
```javascript
64+
const { src, dest } = require('gulp');
65+
const unassert = require('gulp-unassert');
66+
67+
function build() {
68+
return src('./src/*.js')
69+
.pipe(unassert({
70+
modules: [
71+
'node:assert',
72+
'node:assert/strict',
73+
'invariant',
74+
'uvu/assert'
75+
]
76+
}))
77+
.pipe(dest('./dist'));
78+
}
79+
exports.build = build;
80+
```
81+
6182

6283
## Source maps
6384

@@ -138,8 +159,8 @@ Licensed under the [MIT](https://github.com/unassert-js/gulp-unassert/blob/maste
138159
[npm-url]: https://npmjs.org/package/gulp-unassert
139160
[npm-image]: https://badge.fury.io/js/gulp-unassert.svg
140161

141-
[travis-url]: https://travis-ci.org/unassert-js/gulp-unassert
142-
[travis-image]: https://secure.travis-ci.org/unassert-js/gulp-unassert.svg?branch=master
162+
[ci-image]: https://github.com/unassert-js/gulp-unassert/workflows/Node.js%20CI/badge.svg
163+
[ci-url]: https://github.com/unassert-js/gulp-unassert/actions?query=workflow%3A%22Node.js+CI%22
143164

144165
[license-url]: https://github.com/unassert-js/gulp-unassert/blob/master/LICENSE-MIT
145166
[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
'use strict';
1313

14-
const unassert = require('unassert');
14+
const { unassertAst } = require('unassert');
1515
const through = require('through2');
1616
const PluginError = require('plugin-error');
1717
const BufferStreams = require('bufferstreams');
@@ -41,8 +41,8 @@ function applyUnassertWithSourceMap (file, encoding, opt) {
4141
const inMap = file.sourceMap;
4242
const code = file.contents.toString(encoding);
4343

44-
const ast = acorn.parse(code, { ecmaVersion: 2020, sourceType: 'module', locations: true });
45-
const instrumented = escodegen.generate(unassert(ast), {
44+
const ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', locations: true });
45+
const instrumented = escodegen.generate(unassertAst(ast, opt), {
4646
file: file.relative,
4747
sourceMap: file.relative,
4848
sourceMapWithCode: true
@@ -69,16 +69,16 @@ function applyUnassertWithSourceMap (file, encoding, opt) {
6969
file.sourceMap = reMap.toObject();
7070
}
7171

72-
function applyUnassertWithoutSourceMap (code) {
73-
const ast = acorn.parse(code, { ecmaVersion: 2020, sourceType: 'module' });
74-
return escodegen.generate(unassert(ast));
72+
function applyUnassertWithoutSourceMap (code, opt) {
73+
const ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module' });
74+
return escodegen.generate(unassertAst(ast, opt));
7575
}
7676

7777
function transform (file, encoding, opt) {
7878
if (file.sourceMap) {
7979
applyUnassertWithSourceMap(file, encoding, opt);
8080
} else {
81-
file.contents = Buffer.from(applyUnassertWithoutSourceMap(file.contents.toString(encoding)));
81+
file.contents = Buffer.from(applyUnassertWithoutSourceMap(file.contents.toString(encoding), opt));
8282
}
8383
}
8484

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy