Skip to content

Commit c550139

Browse files
Merge pull request #233 from conveyal/dev
v4.1.0
2 parents fe5b5b2 + 4007c87 commit c550139

37 files changed

+913
-481
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/__tests__/test-utils/tmp/**
2+
/node_modules/**
3+
/react/**
4+
/tmp/**

__tests__/bin/mastarm.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* globals afterEach, beforeEach, describe, it, jasmine, expect */
2-
1+
// @flow
32
const exec = require('child_process').exec
43
const fs = require('fs')
5-
const mkdirp = require('mkdirp')
64
const path = require('path')
5+
6+
const mkdirp = require('mkdirp')
77
const rimraf = require('rimraf')
88

99
const util = require('../test-utils/util.js')
@@ -73,7 +73,7 @@ describe('mastarm cli', () => {
7373
})
7474

7575
it('should run lint on a project', done => {
76-
exec(`node ${mastarm}-lint`, (err, stdout, stderr) => {
76+
exec(`${mastarm}-lint lib --quiet`, (err, stdout, stderr) => {
7777
expect(err).toBeNull()
7878
expect(stdout).toBe('')
7979
expect(stderr).toBe('')

__tests__/lib/__snapshots__/format.js.snap

-8
This file was deleted.

__tests__/lib/babel.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/* globals describe, expect, it */
2-
1+
// @flow
32
describe('babel', () => {
43
/** As of 2016-12-15 this test fails in babel loose mode. https://github.com/babel/babel/issues/4916 */
54
it('should iterate correctly over a set after using the spread operator', () => {
6-
const originalArr = [1, 1, 2]
5+
const originalArr = [1, 1]
76
const set = new Set(originalArr)
87
const arr = [...set]
9-
expect(arr.length).toBe(2)
8+
expect(arr).toHaveLength(1)
109
})
1110
})

__tests__/lib/build.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
/* globals afterEach, beforeEach, describe, it, expect, jasmine */
1+
// @flow
22

33
const build = require('../../lib/build')
44
const loadConfig = require('../../lib/load-config')
55
const util = require('../test-utils/util.js')
66

77
const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
88

9-
const UNMINIFIED_JS = 450000
10-
const MINIFIED_JS = 400000
119
const MINIFIED_PROD_JS = 250000
10+
const MINIFIED_JS = 350000
11+
const UNMINIFIED_JS = 430000
1212

1313
const UNMINIFIED_CSS = 450000
1414
const MINIFIED_CSS = 400000
@@ -36,6 +36,7 @@ describe('build', () => {
3636
-1
3737
)
3838
expect(transpiledString.length).toBeGreaterThan(UNMINIFIED_JS)
39+
expect(transpiledString.length).toBeLessThan(UNMINIFIED_JS + UNMINIFIED_JS)
3940
})
4041

4142
it('should transform and minify', async () => {

__tests__/lib/format.js

-19
This file was deleted.

__tests__/lib/jest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals describe, it, expect */
1+
// @flow
22

33
const jestUtils = require('../../lib/jest')
44

__tests__/lib/lint-messages.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals describe, expect, it */
1+
// @flow
22

33
const testFile = `
44
import messages, { analysis, project as proj } from '../utils/messages'
@@ -18,12 +18,12 @@ const test8 = test7 ? messages.common.runRegional : messages.common.stopRegional
1818

1919
// test messages, some of the referenced messages are undefined
2020
const testMessages = {
21-
common: {
22-
download: 'Download'
23-
},
2421
analysis: {
2522
run: 'Run'
2623
},
24+
common: {
25+
download: 'Download'
26+
},
2727
project: {
2828
new: 'New'
2929
}

__tests__/lib/load-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals describe, expect, it */
1+
// @flow
22

33
const loadConfig = require('../../lib/load-config')
44

__tests__/lib/prepublish.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals afterEach, beforeEach, describe, it, expect */
1+
// @flow
22

33
const mkdirp = require('mkdirp')
44
const rimraf = require('rimraf')
@@ -17,7 +17,7 @@ describe('prepublish', () => {
1717
env: 'development'
1818
})
1919

20-
expect(results.length).toBe(1)
20+
expect(results).toHaveLength(1)
2121
})
2222

2323
it('should transpile a directory of files to a specific outdir', () => {
@@ -27,7 +27,7 @@ describe('prepublish', () => {
2727
outdir: buildDir
2828
})
2929

30-
expect(results.length).toBe(1)
30+
expect(results).toHaveLength(1)
3131
})
3232

3333
it('should transpile entries', () => {
@@ -36,7 +36,7 @@ describe('prepublish', () => {
3636
env: 'development'
3737
})
3838

39-
expect(results.length).toBe(1)
39+
expect(results).toHaveLength(1)
4040
})
4141

4242
it('should transpile entries to a specific outdir', () => {
@@ -46,6 +46,6 @@ describe('prepublish', () => {
4646
outdir: buildDir
4747
})
4848

49-
expect(results.length).toBe(1)
49+
expect(results).toHaveLength(1)
5050
})
5151
})

__tests__/lib/push-to-s3.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* global describe, it */
2-
1+
// @flow
32
const fs = require('fs')
43
const path = require('path')
54

@@ -22,8 +21,8 @@ describe('lib > push to s3', () => {
2221
'development'
2322
)
2423
const push = createPushToS3({
25-
env: 'development',
2624
config,
25+
env: 'development',
2726
minify: false,
2827
s3bucket: 'test-bucket'
2928
})

__tests__/lib/util.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals describe, expect, it */
1+
// @flow
22

33
const util = require('../../lib/util')
44
const testUtils = require('../test-utils/util')
@@ -12,8 +12,8 @@ describe('util.js', () => {
1212
const store = {}
1313
const config = {
1414
env: 'mock-env',
15-
path: '/made/up/path',
1615
messages,
16+
path: '/made/up/path',
1717
settings,
1818
store
1919
}
@@ -32,7 +32,7 @@ describe('util.js', () => {
3232
const get = () => null
3333
it('should try to find default file paths', () => {
3434
const result = util.parseEntries([], get)
35-
expect(result.length).toBe(0)
35+
expect(result).toHaveLength(0)
3636
expect(result).toMatchSnapshot()
3737
})
3838

@@ -41,7 +41,7 @@ describe('util.js', () => {
4141
[`${mockDir}/index.css:blah`, `${mockDir}/index.js:blah`],
4242
get
4343
)
44-
expect(result.length).toBe(2)
44+
expect(result).toHaveLength(2)
4545
expect(result).toMatchSnapshot()
4646
})
4747
})

__tests__/test-utils/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tmp/**

__tests__/test-utils/mocks/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import React, {Component} from 'react'
1+
import {Component} from 'react'
22
import uuid from 'uuid'
3+
34
import png from '../../../mastarm.png'
45

6+
/**
7+
* A Mock Component to test to ensure that building of React jsx components works
8+
*/
59
export default class MockTestComponentUniqueName extends Component {
610
static defaultProps = {
711
test: 'hi'
812
}
913

14+
/**
15+
* Render the component.
16+
*/
1017
render () {
1118
return <div />
1219
}

bin/mastarm-flow

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
#!/usr/bin/env node
1+
#!/bin/bash
22

3-
const execFile = require('child_process').execFile
4-
const flow = require('flow-bin')
5-
6-
const args = process.argv.slice(2)
7-
if (args.length === 0) args.push('check')
8-
9-
execFile(flow, args, (error, stdout) => {
10-
console.log(stdout)
11-
if (error) process.exit(1)
12-
})
3+
$(dirname $0)/../node_modules/.bin/flow

bin/mastarm-format

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
#!/usr/bin/env node
1+
#!/bin/bash
22

3-
require('../lib/format')(process.argv.slice(3))
3+
CWD=$(dirname $0)
4+
5+
$CWD/../node_modules/.bin/prettier-eslint \
6+
--eslint-path $CWD/../node_modules/eslint \
7+
--eslint-config-path $CWD/../lib/eslintrc.json \
8+
$@

bin/mastarm-lint

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/bin/bash
2+
CWD=$(dirname $0)
23

3-
const eslint = require('eslint')
4-
const path = require('path')
5-
const engine = require('standard-engine')
6-
7-
const mastarmVersion = require('../package.json').version
8-
9-
// get lint out of there
10-
process.argv = process.argv.filter(arg => arg !== 'lint')
11-
// Force verbose
12-
process.argv.push('--verbose')
13-
14-
engine.cli({
15-
bugs: 'github.com/conveyal/mastarm/issues',
16-
cmd: 'mastarm lint',
17-
eslint,
18-
eslintConfig: {
19-
configFile: path.join(__dirname, '../lib/eslintrc.json')
20-
},
21-
homepage: 'github.com/conveyal/mastarm',
22-
tagline: 'never forget to floss...or lint!',
23-
version: mastarmVersion
24-
})
4+
$CWD/../node_modules/.bin/eslint --config $CWD/../lib/eslintrc.json $FILES $@

lib/babel-config.js

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
const addExports = require('babel-plugin-add-module-exports')
22
const babelEnv = require('babel-preset-env')
3+
const flowRuntime = require('babel-plugin-flow-runtime').default
4+
const flowStripTypes = require('babel-plugin-transform-flow-strip-types')
35
const react = require('babel-preset-react')
6+
const reactRequire = require('babel-plugin-react-require').default
47
const lodash = require('babel-plugin-lodash')
58
const runtime = require('babel-plugin-transform-runtime')
6-
const stripFlow = require('babel-plugin-transform-flow-strip-types')
79
const stage2 = require('babel-preset-stage-2')
10+
const transformDecorators = require('babel-plugin-transform-decorators-legacy').default
811

912
module.exports = function (env) {
10-
const browsers = env === 'production'
11-
? '> 1%, last 2 versions'
12-
: '> 10%, last 2 versions'
13+
const browsers =
14+
env === 'production' ? '> 1%, last 2 versions' : '> 10%, last 2 versions'
15+
16+
const plugins = [
17+
addExports,
18+
lodash,
19+
reactRequire,
20+
runtime
21+
]
22+
if (env === 'production') {
23+
plugins.push(flowStripTypes)
24+
} else {
25+
plugins.push([
26+
flowRuntime,
27+
{
28+
warn: true
29+
}
30+
])
31+
plugins.push(transformDecorators)
32+
}
33+
1334
return {
35+
plugins,
1436
presets: [
1537
[
1638
babelEnv,
1739
{
18-
targets: {browsers},
19-
loose: false // Loose mode breaks spread operator on `Set`s
40+
loose: false, // Loose mode breaks spread operator on `Set`s
41+
targets: { browsers }
2042
}
2143
],
2244
react,
2345
stage2
24-
],
25-
plugins: [addExports, lodash, runtime, stripFlow]
46+
]
2647
}
2748
}

lib/browserify.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
const browserify = require('browserify')
21
const path = require('path')
2+
3+
const browserify = require('browserify')
34
const uglifyify = require('uglifyify')
45

56
const transform = require('./js-transform')
67

78
module.exports = browserifyIt
89

9-
function browserifyIt ({config, entry, env, minify}) {
10+
/**
11+
* Bundle some js together with browserify
12+
*/
13+
function browserifyIt ({ config, entry, env, minify }) {
1014
return browserify(entry, {
1115
basedir: process.cwd(),
1216
cache: {},
@@ -17,12 +21,12 @@ function browserifyIt ({config, entry, env, minify}) {
1721
path.join(__dirname, '/../node_modules'),
1822
path.join(process.cwd(), '/node_modules')
1923
],
20-
transform: transform({config, env})
24+
transform: transform({ config, env })
2125
})
2226
}
2327

2428
module.exports.minify = function (opts) {
2529
const pipeline = browserifyIt(opts)
26-
pipeline.transform(uglifyify, {global: true})
30+
pipeline.transform(uglifyify, { global: true })
2731
return pipeline
2832
}

0 commit comments

Comments
 (0)