postcss-cli
Advanced tools
Comparing version 8.3.1 to 9.0.0
127
index.js
@@ -1,21 +0,23 @@ | ||
'use strict' | ||
#!/usr/bin/env node | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
const prettyHrtime = require('pretty-hrtime') | ||
const stdin = require('get-stdin') | ||
const read = require('read-cache') | ||
const chalk = require('chalk') | ||
const globber = require('globby') | ||
const slash = require('slash') | ||
const chokidar = require('chokidar') | ||
import prettyHrtime from 'pretty-hrtime' | ||
import stdin from 'get-stdin' | ||
import read from 'read-cache' | ||
import { bold, dim, red, cyan, green } from 'colorette' | ||
import { globby } from 'globby' | ||
import slash from 'slash' | ||
import chokidar from 'chokidar' | ||
const postcss = require('postcss') | ||
const postcssrc = require('postcss-load-config') | ||
const reporter = require('postcss-reporter/lib/formatter')() | ||
import postcss from 'postcss' | ||
import postcssrc from 'postcss-load-config' | ||
import postcssReporter from 'postcss-reporter/lib/formatter.js' | ||
const argv = require('./lib/args') | ||
const createDependencyGraph = require('./lib/DependencyGraph') | ||
const getMapfile = require('./lib/getMapfile') | ||
import argv from './lib/args.js' | ||
import createDependencyGraph from './lib/DependencyGraph.js' | ||
import getMapfile from './lib/getMapfile.js' | ||
const reporter = postcssReporter() | ||
const depGraph = createDependencyGraph() | ||
@@ -28,21 +30,29 @@ | ||
const cliConfig = { | ||
options: { | ||
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, | ||
}, | ||
plugins: argv.use | ||
? argv.use.map((plugin) => { | ||
try { | ||
return require(plugin)() | ||
} catch (e) { | ||
const msg = e.message || `Cannot find module '${plugin}'` | ||
let prefix = msg.includes(plugin) ? '' : ` (${plugin})` | ||
if (e.name && e.name !== 'Error') prefix += `: ${e.name}` | ||
return error(`Plugin Error${prefix}: ${msg}'`) | ||
} | ||
}) | ||
: [], | ||
let cliConfig | ||
async function buildCliConfig() { | ||
cliConfig = { | ||
options: { | ||
map: argv.map !== undefined ? argv.map : { inline: true }, | ||
parser: argv.parser ? await import(argv.parser) : undefined, | ||
syntax: argv.syntax ? await import(argv.syntax) : undefined, | ||
stringifier: argv.stringifier | ||
? await import(argv.stringifier) | ||
: undefined, | ||
}, | ||
plugins: argv.use | ||
? await Promise.all( | ||
argv.use.map(async (plugin) => { | ||
try { | ||
return (await import(plugin)).default() | ||
} catch (e) { | ||
const msg = e.message || `Cannot find module '${plugin}'` | ||
let prefix = msg.includes(plugin) ? '' : ` (${plugin})` | ||
if (e.name && e.name !== 'Error') prefix += `: ${e.name}` | ||
return error(`Plugin Error${prefix}: ${msg}'`) | ||
} | ||
}) | ||
) | ||
: [], | ||
} | ||
} | ||
@@ -65,3 +75,3 @@ | ||
Promise.resolve() | ||
buildCliConfig() | ||
.then(() => { | ||
@@ -73,3 +83,3 @@ if (argv.watch && !(argv.output || argv.replace || argv.dir)) { | ||
if (input && input.length) { | ||
return globber( | ||
return globby( | ||
input.map((i) => slash(String(i))), | ||
@@ -112,3 +122,3 @@ { dot: argv.includeDotfiles } | ||
const printMessage = () => | ||
printVerbose(chalk.dim('\nWaiting for file changes...')) | ||
printVerbose(dim('\nWaiting for file changes...')) | ||
const watcher = chokidar.watch(input.concat(dependencies(results)), { | ||
@@ -130,4 +140,8 @@ usePolling: argv.poll, | ||
const dependants = depGraph | ||
.dependantsOf(file) | ||
.concat(getAncestorDirs(file).flatMap(depGraph.dependantsOf)) | ||
recompile = recompile.concat( | ||
depGraph.dependantsOf(file).filter((file) => input.includes(file)) | ||
dependants.filter((file) => input.includes(file)) | ||
) | ||
@@ -137,3 +151,3 @@ | ||
return files(recompile) | ||
return files([...new Set(recompile)]) | ||
.then((results) => watcher.add(dependencies(results))) | ||
@@ -206,3 +220,3 @@ .then(printMessage) | ||
printVerbose(chalk`{cyan Processing {bold ${relativePath}}...}`) | ||
printVerbose(cyan(`Processing ${bold(relativePath)}...`)) | ||
@@ -255,3 +269,3 @@ return rc(ctx, argv.config) | ||
printVerbose( | ||
chalk`{green Finished {bold ${relativePath}} in {bold ${prettyTime}}}` | ||
green(`Finished ${bold(relativePath)} in ${bold(prettyTime)}`) | ||
) | ||
@@ -282,5 +296,17 @@ | ||
result.messages | ||
.filter((msg) => (msg.type === 'dependency' ? msg : '')) | ||
.filter((msg) => | ||
msg.type === 'dependency' || msg.type === 'dir-dependency' ? msg : '' | ||
) | ||
.map(depGraph.add) | ||
.forEach((dependency) => messages.push(dependency.file)) | ||
.forEach((dependency) => { | ||
if (dependency.type === 'dir-dependency') { | ||
messages.push( | ||
dependency.glob | ||
? path.join(dependency.dir, dependency.glob) | ||
: dependency.dir | ||
) | ||
} else { | ||
messages.push(dependency.file) | ||
} | ||
}) | ||
}) | ||
@@ -300,3 +326,3 @@ | ||
if (typeof err === 'string') { | ||
console.error(chalk.red(err)) | ||
console.error(red(err)) | ||
} else if (err.name === 'CssSyntaxError') { | ||
@@ -311,1 +337,12 @@ console.error(err.toString()) | ||
} | ||
// Input: '/imports/components/button.css' | ||
// Output: ['/imports/components', '/imports', '/'] | ||
function getAncestorDirs(fileOrDir) { | ||
const { root } = path.parse(fileOrDir) | ||
if (fileOrDir === root) { | ||
return [] | ||
} | ||
const parentDir = path.dirname(fileOrDir) | ||
return [parentDir, ...getAncestorDirs(parentDir)] | ||
} |
@@ -1,20 +0,6 @@ | ||
'use strict' | ||
const chalk = require('chalk') | ||
import yargs from 'yargs' | ||
const logo = ` | ||
/|\\ | ||
// // | ||
// // | ||
//___*___*___// | ||
//--*---------*--// | ||
/|| * * ||/ | ||
// ||* *|| // | ||
// || * * || // | ||
//_____||___*_________*___||_____// | ||
` | ||
module.exports = require('yargs') | ||
const { argv } = yargs(process.argv.slice(2)) | ||
.usage( | ||
`${chalk.bold.red(logo)} | ||
Usage: | ||
`Usage: | ||
$0 [input.css] [OPTIONS] [-o|--output output.css] [--watch|-w] | ||
@@ -91,10 +77,5 @@ $0 <input.css>... [OPTIONS] --dir <output-directory> [--watch|-w] | ||
implies: 'dir', | ||
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', | ||
desc: 'Mirror the directory structure relative to this path in the output directory, for use with --dir', | ||
type: 'string', | ||
@@ -109,4 +90,3 @@ implies: 'dir', | ||
.option('poll', { | ||
desc: | ||
'Use polling for file watching. Can optionally pass polling interval; default 100 ms', | ||
desc: 'Use polling for file watching. Can optionally pass polling interval; default 100 ms', | ||
implies: 'watch', | ||
@@ -133,2 +113,6 @@ }) | ||
For more details, please see https://github.com/postcss/postcss-cli` | ||
).argv | ||
) | ||
if (argv.ext && argv.ext.indexOf('.') !== 0) argv.ext = `.${argv.ext}` | ||
export default argv |
@@ -1,6 +0,5 @@ | ||
'use strict' | ||
const path = require('path') | ||
const { DepGraph } = require('dependency-graph') | ||
import path from 'path' | ||
import { DepGraph } from 'dependency-graph' | ||
module.exports = function () { | ||
export default function createDependencyGraph() { | ||
const graph = new DepGraph() | ||
@@ -10,7 +9,14 @@ return { | ||
message.parent = path.resolve(message.parent) | ||
message.file = path.resolve(message.file) | ||
graph.addNode(message.parent) | ||
graph.addNode(message.parent) | ||
graph.addNode(message.file) | ||
graph.addDependency(message.parent, message.file) | ||
if (message.type === 'dir-dependency') { | ||
message.dir = path.resolve(message.dir) | ||
graph.addNode(message.dir) | ||
graph.addDependency(message.parent, message.dir) | ||
} else { | ||
message.file = path.resolve(message.file) | ||
graph.addNode(message.file) | ||
graph.addDependency(message.parent, message.file) | ||
} | ||
return message | ||
@@ -17,0 +23,0 @@ }, |
@@ -1,4 +0,3 @@ | ||
'use strict' | ||
const path = require('path') | ||
module.exports = function getMapfile(options) { | ||
import path from 'path' | ||
export default function getMapfile(options) { | ||
if (options.map && typeof options.map.annotation === 'string') { | ||
@@ -5,0 +4,0 @@ return `${path.dirname(options.to)}/${options.map.annotation}` |
{ | ||
"name": "postcss-cli", | ||
"version": "8.3.1", | ||
"version": "9.0.0", | ||
"description": "CLI for PostCSS", | ||
"main": "index.js", | ||
"type": "module", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12" | ||
}, | ||
"bin": { | ||
"postcss": "./bin/postcss" | ||
"postcss": "./index.js" | ||
}, | ||
"scripts": { | ||
"ci": "eslint . && nyc ava -v && npm run prettier -- --list-different", | ||
"ci": "eslint . && c8 ava -v && npm run prettier -- --list-different", | ||
"clean": "node test/helpers/clean.js", | ||
@@ -18,11 +18,11 @@ "prettier": "prettier --single-quote --no-semi \"**/*.{js,md}\"", | ||
"pretest": "npm run clean && npm run format", | ||
"test": "nyc ava -v" | ||
"test": "c8 ava -v" | ||
}, | ||
"dependencies": { | ||
"chalk": "^4.0.0", | ||
"chokidar": "^3.3.0", | ||
"dependency-graph": "^0.9.0", | ||
"fs-extra": "^9.0.0", | ||
"get-stdin": "^8.0.0", | ||
"globby": "^11.0.0", | ||
"colorette": "^2.0.0", | ||
"dependency-graph": "^0.11.0", | ||
"fs-extra": "^10.0.0", | ||
"get-stdin": "^9.0.0", | ||
"globby": "^12.0.0", | ||
"postcss-load-config": "^3.0.0", | ||
@@ -32,15 +32,15 @@ "postcss-reporter": "^7.0.0", | ||
"read-cache": "^1.0.0", | ||
"slash": "^3.0.0", | ||
"yargs": "^16.0.0" | ||
"slash": "^4.0.0", | ||
"yargs": "^17.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.1.0", | ||
"c8": "^7.9.0", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^7.8.0", | ||
"eslint-config-problems": "5.0.0", | ||
"nyc": "^15.0.0", | ||
"postcss": "^8.0.4", | ||
"postcss-import": "^12.0.0", | ||
"prettier": "~2.2.0", | ||
"sugarss": "^3.0.0", | ||
"postcss-import": "^14.0.0", | ||
"prettier": "~2.4.0", | ||
"sugarss": "^4.0.0", | ||
"uuid": "^8.0.0" | ||
@@ -47,0 +47,0 @@ }, |
[![npm][npm]][npm-url] | ||
[![node][node]][node-url] | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/postcss/postcss-cli.svg)](https://greenkeeper.io/) | ||
[![tests][tests]][tests-url] | ||
@@ -101,3 +100,3 @@ [![cover][cover]][cover-url] | ||
For more advanced usage it's recommend to to use a function in `postcss.config.js`, this gives you access to the CLI context to dynamically apply options and plugins **per file** | ||
For more advanced usage, it's recommended to use a function in `postcss.config.js`; this gives you access to the CLI context to dynamically apply options and plugins **per file** | ||
@@ -146,4 +145,4 @@ | Name | Type | Default | Description | | ||
[node-url]: https://nodejs.org/ | ||
[tests]: http://img.shields.io/travis/postcss/postcss-cli/master.svg | ||
[tests-url]: https://travis-ci.org/postcss/postcss-cli | ||
[tests]: https://img.shields.io/github/workflow/status/postcss/postcss-cli/Node.js%20CI/master | ||
[tests-url]: https://github.com/postcss/postcss-cli/actions?query=branch%3Amaster | ||
[cover]: https://img.shields.io/coveralls/postcss/postcss-cli/master.svg | ||
@@ -150,0 +149,0 @@ [cover-url]: https://coveralls.io/github/postcss/postcss-cli |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
457
2
Yes
23488
150
+ Addedcolorette@^2.0.0
+ Addedarray-union@3.0.1(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolorette@2.0.20(transitive)
+ Addeddependency-graph@0.11.0(transitive)
+ Addedfs-extra@10.1.0(transitive)
+ Addedget-stdin@9.0.0(transitive)
+ Addedglobby@12.2.0(transitive)
+ Addedslash@4.0.0(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedchalk@^4.0.0
- Removedarray-union@2.1.0(transitive)
- Removedat-least-node@1.0.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcliui@7.0.4(transitive)
- Removeddependency-graph@0.9.0(transitive)
- Removedfs-extra@9.1.0(transitive)
- Removedget-stdin@8.0.0(transitive)
- Removedglobby@11.1.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedslash@3.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedyargs@16.2.0(transitive)
- Removedyargs-parser@20.2.9(transitive)
Updateddependency-graph@^0.11.0
Updatedfs-extra@^10.0.0
Updatedget-stdin@^9.0.0
Updatedglobby@^12.0.0
Updatedslash@^4.0.0
Updatedyargs@^17.0.0