Skip to content

Commit

Permalink
Update dependency prettier to v2 (#319)
Browse files Browse the repository at this point in the history
* Update dependency prettier to v2

* Update files

* Fix autocrlf

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Ryan Zimmerman <opensrc@ryanzim.com>
  • Loading branch information
3 people committed Mar 31, 2020
1 parent 42fc85e commit 96699c1
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: node_js
git:
autocrlf: input
os:
- linux
- windows
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ module.exports = {
parser: 'sugarss',
plugins: [
require('postcss-import')({ ...options }),
require('postcss-url')({ url: 'copy', useHash: true })
]
require('postcss-url')({ url: 'copy', useHash: true }),
],
}
```

Expand All @@ -105,13 +105,13 @@ For more advanced usage it's recommend to to use a function in `postcss.config.j
**postcss.config.js**

```js
module.exports = ctx => ({
module.exports = (ctx) => ({
map: ctx.options.map,
parser: ctx.file.extname === '.sss' ? 'sugarss' : false,
plugins: {
'postcss-import': { root: ctx.file.dirname },
cssnano: ctx.env === 'production' ? {} : false
}
cssnano: ctx.env === 'production' ? {} : false,
},
})
```

Expand All @@ -124,13 +124,13 @@ postcss input.sss -p sugarss -o output.css -m
**postcss.config.js**

```js
module.exports = ctx => ({
module.exports = (ctx) => ({
map: ctx.options.map,
parser: ctx.options.parser,
plugins: {
'postcss-import': { root: ctx.file.dirname },
cssnano: ctx.env === 'production' ? {} : false
}
cssnano: ctx.env === 'production' ? {} : false,
},
})
```

Expand Down
48 changes: 24 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const cliConfig = {
map: argv.map !== undefined ? argv.map : { inline: true },
parser: argv.parser ? require(argv.parser) : undefined,
syntax: argv.syntax ? require(argv.syntax) : undefined,
stringifier: argv.stringifier ? require(argv.stringifier) : undefined
stringifier: argv.stringifier ? require(argv.stringifier) : undefined,
},
plugins: argv.use
? argv.use.map(plugin => {
? argv.use.map((plugin) => {
try {
return require(plugin)()
} catch (e) {
Expand All @@ -41,7 +41,7 @@ const cliConfig = {
return error(`Plugin Error${prefix}: ${msg}'`)
}
})
: []
: [],
}

let configFile
Expand Down Expand Up @@ -71,7 +71,7 @@ Promise.resolve()

return ['stdin']
})
.then(i => {
.then((i) => {
if (!i || !i.length) {
error('Input Error: You must pass a valid list of files to parse')
}
Expand All @@ -82,13 +82,13 @@ Promise.resolve()
)
}

if (i[0] !== 'stdin') i = i.map(i => path.resolve(i))
if (i[0] !== 'stdin') i = i.map((i) => path.resolve(i))

input = i

return files(input)
})
.then(results => {
.then((results) => {
if (argv.watch) {
const printMessage = () =>
printVerbose(chalk.dim('\nWaiting for file changes...'))
Expand All @@ -97,31 +97,31 @@ Promise.resolve()
interval: argv.poll && typeof argv.poll === 'number' ? argv.poll : 100,
awaitWriteFinish: {
stabilityThreshold: 50,
pollInterval: 10
}
pollInterval: 10,
},
})

if (configFile) watcher.add(configFile)

watcher.on('ready', printMessage).on('change', file => {
watcher.on('ready', printMessage).on('change', (file) => {
let recompile = []

if (input.includes(file)) recompile.push(file)

recompile = recompile.concat(
depGraph.dependantsOf(file).filter(file => input.includes(file))
depGraph.dependantsOf(file).filter((file) => input.includes(file))
)

if (!recompile.length) recompile = input

return files(recompile)
.then(results => watcher.add(dependencies(results)))
.then((results) => watcher.add(dependencies(results)))
.then(printMessage)
.catch(error)
})
}
})
.catch(err => {
.catch((err) => {
error(err)

process.exit(1)
Expand All @@ -131,7 +131,7 @@ function rc(ctx, path) {
if (argv.use) return Promise.resolve(cliConfig)

return postcssrc(ctx, path)
.then(rc => {
.then((rc) => {
if (rc.options.from || rc.options.to) {
error(
'Config Error: Can not set from or to options in config file, use CLI arguments instead'
Expand All @@ -140,7 +140,7 @@ function rc(ctx, path) {
configFile = rc.file
return rc
})
.catch(err => {
.catch((err) => {
if (!err.message.includes('No PostCSS Config found')) throw err
})
}
Expand All @@ -149,15 +149,15 @@ function files(files) {
if (typeof files === 'string') files = [files]

return Promise.all(
files.map(file => {
files.map((file) => {
if (file === 'stdin') {
return stdin().then(content => {
return stdin().then((content) => {
if (!content) return error('Input Error: Did not receive any STDIN')
return css(content, 'stdin')
})
}

return read(file).then(content => css(content, file))
return read(file).then((content) => css(content, file))
})
)
}
Expand All @@ -169,7 +169,7 @@ function css(css, file) {
ctx.file = {
dirname: path.dirname(file),
basename: path.basename(file),
extname: path.extname(file)
extname: path.extname(file),
}

if (!argv.config) argv.config = path.dirname(file)
Expand All @@ -185,7 +185,7 @@ function css(css, file) {
printVerbose(chalk`{cyan Processing {bold ${relativePath}}...}`)

return rc(ctx, argv.config)
.then(config => {
.then((config) => {
config = config || cliConfig
const options = { ...config.options }

Expand Down Expand Up @@ -215,7 +215,7 @@ function css(css, file) {

return postcss(config.plugins)
.process(css, options)
.then(result => {
.then((result) => {
const tasks = []

if (options.to) {
Expand All @@ -242,7 +242,7 @@ function css(css, file) {
})
})
})
.catch(err => {
.catch((err) => {
throw err
})
}
Expand All @@ -252,13 +252,13 @@ function dependencies(results) {

const messages = []

results.forEach(result => {
results.forEach((result) => {
if (result.messages <= 0) return

result.messages
.filter(msg => (msg.type === 'dependency' ? msg : ''))
.filter((msg) => (msg.type === 'dependency' ? msg : ''))
.map(depGraph.add)
.forEach(dependency => messages.push(dependency.file))
.forEach((dependency) => messages.push(dependency.file))
})

return messages
Expand Down
30 changes: 15 additions & 15 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,40 @@ Usage:
alias: 'output',
desc: 'Output file',
type: 'string',
conflicts: ['dir', 'replace']
conflicts: ['dir', 'replace'],
})
.option('d', {
alias: 'dir',
desc: 'Output directory',
type: 'string',
conflicts: ['output', 'replace']
conflicts: ['output', 'replace'],
})
.option('r', {
alias: 'replace',
desc: 'Replace (overwrite) the input file',
type: 'boolean',
conflicts: ['output', 'dir']
conflicts: ['output', 'dir'],
})
.option('include-dotfiles', {
desc: 'Enables glob to match files/dirs that begin with "."',
type: 'boolean'
type: 'boolean',
})
.alias('map', 'm')
.describe('map', 'Create an external sourcemap')
.describe('no-map', 'Disable the default inline sourcemaps')
.option('verbose', {
desc: 'Be verbose',
type: 'boolean'
type: 'boolean',
})
.option('watch', {
alias: 'w',
desc: 'Watch files for changes and recompile as needed',
type: 'boolean',
conflicts: 'replace'
conflicts: 'replace',
})
.option('env', {
desc: 'A shortcut for setting NODE_ENV',
type: 'string'
type: 'string',
})
.group(
['u', 'parser', 'stringifier', 'syntax'],
Expand All @@ -86,19 +86,19 @@ Usage:
.option('u', {
alias: 'use',
desc: 'List of postcss plugins to use',
type: 'array'
type: 'array',
})
.option('parser', {
desc: 'Custom postcss parser',
type: 'string'
type: 'string',
})
.option('stringifier', {
desc: 'Custom postcss stringifier',
type: 'string'
type: 'string',
})
.option('syntax', {
desc: 'Custom postcss syntax',
type: 'string'
type: 'string',
})
.group(['ext', 'base', 'poll', 'config'], 'Advanced options:')
.option('ext', {
Expand All @@ -108,22 +108,22 @@ Usage:
coerce(ext) {
if (ext.indexOf('.') !== 0) return `.${ext}`
return ext
}
},
})
.option('base', {
desc:
'Mirror the directory structure relative to this path in the output directory, for use with --dir',
type: 'string',
implies: 'dir'
implies: 'dir',
})
.option('poll', {
desc:
'Use polling for file watching. Can optionally pass polling interval; default 100 ms',
implies: 'watch'
implies: 'watch',
})
.option('config', {
desc: 'Set a custom directory to look for a config file',
type: 'string'
type: 'string',
})
.version(version)
.alias('h', 'help')
Expand Down
4 changes: 2 additions & 2 deletions lib/depGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const DepGraph = require('dependency-graph').DepGraph

const graph = new DepGraph()

exports.add = message => {
exports.add = (message) => {
message.parent = path.resolve(message.parent)
message.file = path.resolve(message.file)

Expand All @@ -14,7 +14,7 @@ exports.add = message => {
return message
}

exports.dependantsOf = node => {
exports.dependantsOf = (node) => {
node = path.resolve(node)

if (graph.hasNode(node)) return graph.dependantsOf(node)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-problems": "4.0.0",
"nyc": "^15.0.0",
"postcss-import": "^12.0.0",
"prettier": "~1.19.1",
"prettier": "~2.0.0",
"sugarss": "^2.0.0",
"uuid": "^3.0.1"
},
Expand Down
4 changes: 2 additions & 2 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')

test('--base --dir works', async t => {
test('--base --dir works', async (t) => {
const dir = tmp()

const { error, stderr } = await cli([
Expand All @@ -14,7 +14,7 @@ test('--base --dir works', async t => {
dir,
'--base',
'test/fixtures/base',
'--no-map'
'--no-map',
])

t.falsy(error, stderr)
Expand Down
4 changes: 2 additions & 2 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')

test('works with defaults', async t => {
test('works with defaults', async (t) => {
const output = tmp('output.css')

const { error, stderr } = await cli([
'test/fixtures/a.css',
'-o',
output,
'--no-map'
'--no-map',
])

t.falsy(error, stderr)
Expand Down

0 comments on commit 96699c1

Please sign in to comment.