Skip to content

Commit fe5b5b2

Browse files
Merge pull request #227 from conveyal/dev
v4.0.0
2 parents 51f9cb0 + 05132f2 commit fe5b5b2

File tree

13 files changed

+3009
-2206
lines changed

13 files changed

+3009
-2206
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cache:
66
notifications:
77
email: false
88
node_js:
9-
- '6'
9+
- '8'
1010
before_install:
1111
- npm i -g codecov yarn
1212
install:

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
## Table of Contents
1111

12+
* [Node](#node)
1213
* [Install](#install)
1314
* [Configuration](#configuration)
1415
* [CLI Usage](#cli-usage)
@@ -22,9 +23,13 @@
2223
* [Test](#test)
2324
* [Lint Messages](#lint-messages)
2425

26+
## Node
27+
28+
We pin mastarm to a specific version of node due to inconsistencies across installation and building when using multiple versions. *Node 8 is now required to run mastarm*.
29+
2530
## Install
2631

27-
With [node v6 and npm 3 installed](https://nodejs.org/en/download/current/):
32+
With [node v8 and npm 5 installed](https://nodejs.org/en/download/current/):
2833

2934
```shell
3035
$ npm install -g mastarm

__tests__/bin/mastarm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('mastarm cli', () => {
3838

3939
it('should build a project', done => {
4040
exec(
41-
`node ${mastarm} build ${mockDir}/index.js:${buildDir}/index.js ${mockDir}/index.css:${buildDir}/index.css`,
41+
`node ${mastarm}-build ${mockDir}/index.js:${buildDir}/index.js ${mockDir}/index.css:${buildDir}/index.css`,
4242
(err, stdout, stderr) => {
4343
expect(err).toBeNull()
4444
expect(stdout).toContain('done building')
@@ -60,7 +60,7 @@ describe('mastarm cli', () => {
6060

6161
it('should prepublish a project', done => {
6262
exec(
63-
`node ${mastarm} prepublish ${mockDir}:${buildDir}`,
63+
`node ${mastarm}-prepublish ${mockDir}:${buildDir}`,
6464
(err, stdout, stderr) => {
6565
expect(err).toBeNull()
6666
expect(stdout).toBe('')

__tests__/lib/__snapshots__/build.js.snap

-9
This file was deleted.

__tests__/lib/build.js

+61-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ 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
11+
const MINIFIED_PROD_JS = 250000
12+
13+
const UNMINIFIED_CSS = 450000
14+
const MINIFIED_CSS = 400000
15+
916
describe('build', () => {
1017
const mockDir = util.mockDir
1118

@@ -16,34 +23,82 @@ describe('build', () => {
1623
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
1724
})
1825

19-
describe('development', () => {
20-
it('should transform js', async () => {
26+
describe('js', () => {
27+
it('should transform', async () => {
2128
const [result] = await build({
2229
config: loadConfig(process.cwd(), null, 'development'),
30+
env: 'development',
2331
files: [[`${mockDir}/index.js`]]
2432
})
2533

2634
const transpiledString = result.toString()
2735
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
2836
-1
2937
)
30-
expect(transpiledString.length).toMatchSnapshot()
38+
expect(transpiledString.length).toBeGreaterThan(UNMINIFIED_JS)
3139
})
3240

33-
it('should transform css', async () => {
41+
it('should transform and minify', async () => {
42+
const [result] = await build({
43+
config: loadConfig(process.cwd(), null, 'development'),
44+
env: 'development',
45+
files: [[`${mockDir}/index.js`]],
46+
minify: true
47+
})
48+
49+
const transpiledString = result.toString()
50+
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
51+
-1
52+
)
53+
expect(transpiledString.length).toBeGreaterThan(MINIFIED_JS)
54+
expect(transpiledString.length).toBeLessThan(UNMINIFIED_JS)
55+
})
56+
57+
it('should transform, minify, and use production settings', async () => {
58+
const [result] = await build({
59+
config: loadConfig(process.cwd(), null, 'production'),
60+
env: 'production',
61+
files: [[`${mockDir}/index.js`]],
62+
minify: true
63+
})
64+
65+
const transpiledString = result.toString()
66+
expect(transpiledString.indexOf('MockTestComponentUniqueName')).not.toBe(
67+
-1
68+
)
69+
expect(transpiledString.length).toBeGreaterThan(MINIFIED_PROD_JS)
70+
expect(transpiledString.length).toBeLessThan(MINIFIED_JS)
71+
})
72+
})
73+
74+
describe('css', () => {
75+
it('should transform', async () => {
3476
const [result] = await build({
3577
config: loadConfig(process.cwd(), null, 'development'),
3678
files: [[`${mockDir}/index.css`]]
3779
})
3880

3981
const css = result.css
4082
expect(css.indexOf('criticalClass')).toBeGreaterThan(-1)
41-
expect(css.length).toMatchSnapshot()
83+
expect(css.length).toBeGreaterThan(UNMINIFIED_CSS)
84+
})
85+
86+
it('should transform and minify', async () => {
87+
const [result] = await build({
88+
config: loadConfig(process.cwd(), null, 'development'),
89+
files: [[`${mockDir}/index.css`]],
90+
minify: true
91+
})
92+
93+
const css = result.css
94+
expect(css.indexOf('criticalClass')).toBeGreaterThan(-1)
95+
expect(css.length).toBeGreaterThan(MINIFIED_CSS)
96+
expect(css.length).toBeLessThan(UNMINIFIED_CSS)
4297
})
4398
})
4499

45100
describe('production', () => {
46-
it('should transform and minify js and css', async () => {
101+
it('should transform and minify js and css at the same time', async () => {
47102
const [jsResult, cssResult] = await build({
48103
config: loadConfig(process.cwd(), null, 'production'),
49104
env: 'production',
@@ -55,8 +110,6 @@ describe('build', () => {
55110
-1
56111
)
57112
expect(cssResult.css.indexOf('criticalClass')).not.toBe(-1)
58-
expect(transpiledString.length).toMatchSnapshot()
59-
expect(cssResult.css.length).toMatchSnapshot()
60113
})
61114
})
62115
})

__tests__/test-utils/mocks/index.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import url(node_modules/bootstrap/dist/css/bootstrap.css);
2+
13
.criticalClass {
24
font-weight: bold !important;
35
}

__tests__/test-utils/mocks/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import React, {Component} from 'react'
12
import uuid from 'uuid'
23
import png from '../../../mastarm.png'
34

4-
export default class MockTestComponentUniqueName {
5+
export default class MockTestComponentUniqueName extends Component {
56
static defaultProps = {
67
test: 'hi'
78
}

lib/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function ({config, env, files, minify, watch}) {
1414
files.map(
1515
([entry, outfile]) =>
1616
(path.extname(entry) === '.css'
17-
? buildCss({config, entry, outfile, watch})
17+
? buildCss({config, entry, minify, outfile, watch})
1818
: buildJs({config, entry, env, minify, outfile, watch}))
1919
)
2020
)

lib/css-transform.js

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const cssnano = require('cssnano')
12
const chokidar = require('chokidar')
23
const fs = require('fs')
34
const mimeType = require('mime')
@@ -11,27 +12,36 @@ const postcssSafeParser = require('postcss-safe-parser')
1112

1213
const logger = require('./logger')
1314

14-
module.exports = function ({config, entry, outfile, watch}) {
15+
module.exports = function ({config, entry, minify, outfile, watch}) {
1516
const configImport = config.stylePath
1617
? `@import url(${config.stylePath});`
1718
: ''
1819
let watcher
19-
const transform = () =>
20-
postcss([
21-
postcssImport({
22-
plugins: [
23-
base64ify(process.cwd()) // inline all url files
24-
],
25-
onImport: sources => {
26-
if (watch) {
27-
sources.forEach(source => watcher.add(source))
28-
}
20+
const plugins = [
21+
postcssImport({
22+
plugins: [
23+
base64ify(process.cwd()) // inline all url files
24+
],
25+
onImport: sources => {
26+
if (watch) {
27+
sources.forEach(source => watcher.add(source))
2928
}
30-
}),
31-
base64ify(process.cwd()),
32-
postcssNext(),
33-
postcssReporter({clearMessages: true})
34-
])
29+
}
30+
}),
31+
base64ify(process.cwd()),
32+
postcssNext({
33+
warnForDuplicates: false
34+
})
35+
]
36+
37+
if (minify) {
38+
plugins.push(cssnano({preset: 'default'}))
39+
}
40+
41+
plugins.push(postcssReporter({clearMessages: true}))
42+
43+
const transform = () =>
44+
postcss(plugins)
3545
.process(`${configImport}${fs.readFileSync(entry, 'utf8')}`, {
3646
parser: postcssSafeParser,
3747
map: {inline: false},
@@ -83,7 +93,7 @@ const base64ify = postcss.plugin('postcss-base64ify', function () {
8393
const buffer = fs.readFileSync(file)
8494
return (
8595
'url("data:' +
86-
mimeType.lookup(filename) +
96+
mimeType.getType(filename) +
8797
';base64,' +
8898
buffer.toString('base64') +
8999
'")'

lib/load-config.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module.exports = function load (cwd, config, environment) {
88
const env = loadYaml('env')
99
const settings = loadYaml('settings')
1010

11+
if (environment === 'production') {
12+
process.env.NODE_ENV = 'production'
13+
}
14+
1115
return {
1216
env: overrideWithEnvironment(env, environment),
1317
environment,

lib/push-to-s3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function upload ({body, s3bucket, cloudfront, outfile}) {
1515
ACL: 'public-read',
1616
Body: body,
1717
Bucket: s3bucket,
18-
ContentType: mime.lookup(outfile),
18+
ContentType: mime.getType(outfile),
1919
Key: outfile
2020
}
2121
})

0 commit comments

Comments
 (0)