Skip to content

Commit bcdc337

Browse files
committed
ci: use Github Actions, standard style
1 parent f80ef52 commit bcdc337

File tree

10 files changed

+106
-66
lines changed

10 files changed

+106
-66
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "04:00"
8+
open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Node CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
node-version: [4.x, 6.x, 8.x, 10.x, 12.x, 14.x, 16.x, 18.x]
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: npm install
20+
run: npm install
21+
- name: npm test
22+
run: npm run tests-only
23+
24+
lint:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
- name: Use Node.js LTS
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: lts/*
33+
- name: npm install
34+
run: npm install
35+
- name: npm run lint
36+
run: npm run lint

.travis.yml

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

example/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
var message = require('./xyz').getMessage()
1+
const message = require('./xyz').getMessage()
22
console.log(message)

example/build.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
var path = require('path')
2-
var browserify = require('browserify')
3-
var commonShake = require('../')
1+
const path = require('path')
2+
const browserify = require('browserify')
3+
const commonShake = require('../')
44

5-
var b = browserify({ entries: path.join(__dirname, 'app.js') })
5+
const b = browserify({ entries: path.join(__dirname, 'app.js') })
66
.plugin(commonShake, {
77
verbose: true
88
})
99
.bundle()
1010

1111
// Minify & save
12-
var fs = require('fs')
13-
var concat = require('concat-stream')
14-
var uglify = require('uglify-js')
12+
const fs = require('fs')
13+
const concat = require('concat-stream')
14+
const uglify = require('uglify-js')
1515
b.pipe(concat(function (source) {
16-
var minified = uglify.minify(source.toString('utf8'), {
16+
const minified = uglify.minify(source.toString('utf8'), {
1717
mangle: false,
1818
compress: true
1919
})

example/xyz.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var target = exports.target = 'world'
1+
let target = exports.target = 'world'
22
exports.getMessage = function () {
33
return 'hello ' + target
44
}

index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = function commonShake (b, opts) {
5757
aliases.set(id, file)
5858
})
5959
b.pipeline.get('label').unshift(createStream(opts, {
60-
getSideEffects(name) {
60+
getSideEffects (name) {
6161
const file = aliases.get(name) || name
6262
let pkg
6363
let dir = file
@@ -66,7 +66,7 @@ module.exports = function commonShake (b, opts) {
6666
pkg = packages.get(dir)
6767
prevDir = dir
6868
}
69-
return pkg && pkg.sideEffects === false ? false : true
69+
return !(pkg && pkg.sideEffects === false)
7070
}
7171
}))
7272
}
@@ -227,7 +227,7 @@ function createStream (opts, api) {
227227

228228
function remove (string, node) {
229229
if (node.type === 'AssignmentExpression') {
230-
var prefix = commentify(`${node.left.getSource()} =`) + ' '
230+
let prefix = commentify(`${node.left.getSource()} =`) + ' '
231231
// Anonymous function and class expressions are parsed as statements if they
232232
// are the first thing in a statement, which can happen if the `exports.xyz`
233233
// assignment happened inside a SequenceExpression (usually after minification).
@@ -238,25 +238,25 @@ function createStream (opts, api) {
238238
// In the case of non-function/class expressions, we can void the whole thing
239239
// eg: `exports.a={},exports.b=''`
240240
// becomes: `void {},void ''`
241-
var isFunction = node.right.type === 'FunctionExpression'
242-
var isAssignment = node.right.type === 'AssignmentExpression'
243-
var isArrowFunction = node.right.type === 'ArrowFunctionExpression'
244-
var isVariableDeclarator = node.parent.parent.type === 'VariableDeclarator'
241+
const isFunction = node.right.type === 'FunctionExpression'
242+
const isAssignment = node.right.type === 'AssignmentExpression'
243+
const isArrowFunction = node.right.type === 'ArrowFunctionExpression'
244+
const isVariableDeclarator = node.parent.parent.type === 'VariableDeclarator'
245245
if (
246-
// persist sequential variable declarations
247-
// eg: `var a = (0, exports.a = function(){})`
248-
(!isVariableDeclarator && node.parent.type === 'SequenceExpression') ||
246+
// persist sequential variable declarations
247+
// eg: `var a = (0, exports.a = function(){})`
248+
(!isVariableDeclarator && node.parent.type === 'SequenceExpression') ||
249249
// without this, `exports.a = exports.b = xyz` eliminating exports.a becomes `void exports.b = xyz`
250250
// which is invalid.
251251
isAssignment ||
252252
// Don't output a statement containing only `void () => {}`
253253
isArrowFunction
254-
) {
254+
) {
255255
// ignore alias assignment expression `exports.a = exports.b = exports.c`
256256
// unless the last argument is noname function
257-
var isAliasAssignment = isAssignment && node.right.left.type === 'MemberExpression' && node.right.left.object.name === 'exports'
258-
var isAliasFunction = isAliasAssignment && node.right.right.type === 'FunctionExpression'
259-
var isAliasClass = isAliasAssignment && node.right.right.type === 'ClassExpression'
257+
const isAliasAssignment = isAssignment && node.right.left.type === 'MemberExpression' && node.right.left.object.name === 'exports'
258+
const isAliasFunction = isAliasAssignment && node.right.right.type === 'FunctionExpression'
259+
const isAliasClass = isAliasAssignment && node.right.right.type === 'ClassExpression'
260260
if (!isAliasAssignment || isAliasFunction || isAliasClass) {
261261
prefix += 'void '
262262
if (isAssignment || isArrowFunction || isFunction || isAliasFunction || isAliasClass) {

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "browserify tree shaking plugin using @indutny common-shake",
55
"main": "index.js",
66
"scripts": {
7-
"test": "tape test/test.js"
7+
"lint": "standard",
8+
"tests-only": "tape test/test.js",
9+
"test": "npm run lint && npm run tests-only"
810
},
911
"repository": {
1012
"type": "git",
@@ -40,7 +42,14 @@
4042
"browserify": "^16.1.1",
4143
"concat-stream": "^1.6.1",
4244
"net-browserify-stub": "0.0.1",
45+
"standard": "^17.0.0",
4346
"tape": "^4.9.0",
4447
"uglify-js": "^3.3.15"
48+
},
49+
"standard": {
50+
"ignore": [
51+
"test/*/*.js",
52+
"example/bundle.*"
53+
]
4554
}
4655
}

test/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var test = require('tape')
2-
var path = require('path')
3-
var browserify = require('browserify')
4-
var commonShakeify = require('../')
1+
const test = require('tape')
2+
const path = require('path')
3+
const browserify = require('browserify')
4+
const commonShakeify = require('../')
55

6-
var sampleEntry = path.join(__dirname, 'simple/app.js')
6+
const sampleEntry = path.join(__dirname, 'simple/app.js')
77

88
test('should work as a plugin', function (t) {
99
try {

test/test.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
var test = require('tape')
2-
var assert = require('assert')
3-
var fs = require('fs')
4-
var path = require('path')
5-
var browserify = require('browserify')
6-
var concat = require('concat-stream')
7-
var commonShake = require('../')
1+
const test = require('tape')
2+
const assert = require('assert')
3+
const fs = require('fs')
4+
const path = require('path')
5+
const browserify = require('browserify')
6+
const concat = require('concat-stream')
7+
const commonShake = require('../')
88

99
function runTest (t, name) {
1010
t.plan(1)
11-
var basedir = path.join(__dirname, name)
12-
var optionsPath = path.join(basedir, 'options.js')
13-
var options = {}
11+
const basedir = path.join(__dirname, name)
12+
const optionsPath = path.join(basedir, 'options.js')
13+
let options = {}
1414
try { options = require(optionsPath)(t) } catch (err) {}
15-
var entry = path.join(basedir, 'app.js')
16-
var expected = path.join(basedir, 'expected.js')
17-
var actual = path.join(basedir, 'actual.js')
18-
var bundle = browserify({ entries: entry })
15+
const entry = path.join(basedir, 'app.js')
16+
const expected = path.join(basedir, 'expected.js')
17+
const actual = path.join(basedir, 'actual.js')
18+
const bundle = browserify({ entries: entry })
1919
.plugin(commonShake, options)
2020
.bundle()
2121
.on('error', t.fail)
@@ -74,7 +74,7 @@ test('side-effects', function (t) {
7474
})
7575

7676
test('external', function (t) {
77-
var b = browserify({
77+
const b = browserify({
7878
entries: path.join(__dirname, 'external/app.js')
7979
})
8080

@@ -87,7 +87,7 @@ test('external', function (t) {
8787
})
8888

8989
test('source maps', function (t) {
90-
var b = browserify({
90+
const b = browserify({
9191
entries: path.join(__dirname, 'source-map/app.js'),
9292
debug: true,
9393
preludePath: 'node_modules/browser-pack/_prelude.js'
@@ -99,7 +99,7 @@ test('source maps', function (t) {
9999
})
100100
b.plugin(commonShake)
101101

102-
var bundle = b.bundle()
102+
const bundle = b.bundle()
103103
bundle.on('error', t.fail)
104104

105105
// Write actual output to a file for easier inspection
@@ -118,13 +118,13 @@ test('source maps', function (t) {
118118
})
119119

120120
test('dash-r', function (t) {
121-
var b = browserify({
121+
const b = browserify({
122122
entries: path.join(__dirname, 'dash-r/app.js')
123123
})
124124
b.require(path.join(__dirname, 'dash-r/expose.js'), { expose: 'whatever' })
125125
b.plugin(commonShake)
126126

127-
var bundle = b.bundle()
127+
const bundle = b.bundle()
128128
bundle.on('error', t.fail)
129129

130130
bundle.pipe(fs.createWriteStream(
@@ -142,13 +142,13 @@ test('dash-r', function (t) {
142142
})
143143

144144
test('dash-r node_modules', function (t) {
145-
var b = browserify({
145+
const b = browserify({
146146
entries: path.join(__dirname, 'dash-r-node-modules/app.js')
147147
})
148148
b.require('net-browserify-stub', { expose: 'net' })
149149
b.plugin(commonShake)
150150

151-
var bundle = b.bundle()
151+
const bundle = b.bundle()
152152
bundle.on('error', t.fail)
153153

154154
bundle.pipe(fs.createWriteStream(
@@ -167,14 +167,14 @@ test('dash-r node_modules', function (t) {
167167

168168
// TODO fix this one
169169
test('dash-r node_modules with full paths', { skip: true }, function (t) {
170-
var b = browserify({
170+
const b = browserify({
171171
fullPaths: true,
172172
entries: path.join(__dirname, 'dash-r-node-modules/app.js')
173173
})
174174
b.require('net-browserify-stub', { expose: 'net' })
175175
b.plugin(commonShake)
176176

177-
var bundle = b.bundle()
177+
const bundle = b.bundle()
178178
bundle.on('error', t.fail)
179179

180180
bundle.pipe(fs.createWriteStream(

0 commit comments

Comments
 (0)