Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-cli

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-cli - npm Package Compare versions

Comparing version 8.3.1 to 10.1.0

150

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 pc from 'picocolors'
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}'`)
}
})
)
: [],
}
}

@@ -55,3 +65,9 @@

if (argv.watch) {
let { isTTY } = process.stdin
if (process.env.FORCE_IS_TTY === 'true') {
isTTY = true
}
if (argv.watch && isTTY) {
process.stdin.on('end', () => process.exit(0))

@@ -66,10 +82,12 @@ process.stdin.resume()

Promise.resolve()
buildCliConfig()
.then(() => {
if (argv.watch && !(argv.output || argv.replace || argv.dir)) {
error('Cannot write to stdout in watch mode')
// Need to explicitly exit here, since error() doesn't exit in watch mode
process.exit(1)
}
if (input && input.length) {
return globber(
return globby(
input.map((i) => slash(String(i))),

@@ -112,3 +130,3 @@ { dot: argv.includeDotfiles }

const printMessage = () =>
printVerbose(chalk.dim('\nWaiting for file changes...'))
printVerbose(pc.dim('\nWaiting for file changes...'))
const watcher = chokidar.watch(input.concat(dependencies(results)), {

@@ -130,4 +148,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 +159,3 @@

return files(recompile)
return files([...new Set(recompile)])
.then((results) => watcher.add(dependencies(results)))

@@ -206,3 +228,3 @@ .then(printMessage)

printVerbose(chalk`{cyan Processing {bold ${relativePath}}...}`)
printVerbose(pc.cyan(`Processing ${pc.bold(relativePath)}...`))

@@ -244,7 +266,7 @@ return rc(ctx, argv.config)

if (options.to) {
tasks.push(fs.outputFile(options.to, result.css))
tasks.push(outputFile(options.to, result.css))
if (result.map) {
const mapfile = getMapfile(options)
tasks.push(fs.outputFile(mapfile, result.map.toString()))
tasks.push(outputFile(mapfile, result.map.toString()))
}

@@ -256,3 +278,5 @@ } else process.stdout.write(result.css, 'utf8')

printVerbose(
chalk`{green Finished {bold ${relativePath}} in {bold ${prettyTime}}}`
pc.green(
`Finished ${pc.bold(relativePath)} in ${pc.bold(prettyTime)}`
)
)

@@ -272,2 +296,9 @@

})
async function outputFile(file, string) {
const fileExists = await fs.pathExists(file)
const currentValue = fileExists ? await fs.readFile(file, 'utf8') : null
if (currentValue === string) return
return fs.outputFile(file, string)
}
}

@@ -284,5 +315,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)
}
})
})

@@ -302,3 +345,3 @@

if (typeof err === 'string') {
console.error(chalk.red(err))
console.error(pc.red(err))
} else if (err.name === 'CssSyntaxError') {

@@ -313,1 +356,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": "10.1.0",
"description": "CLI for PostCSS",
"main": "index.js",
"type": "module",
"engines": {
"node": ">=10"
"node": ">=14"
},
"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,29 +18,29 @@ "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",
"postcss-load-config": "^3.0.0",
"dependency-graph": "^0.11.0",
"fs-extra": "^11.0.0",
"get-stdin": "^9.0.0",
"globby": "^13.0.0",
"picocolors": "^1.0.0",
"postcss-load-config": "^4.0.0",
"postcss-reporter": "^7.0.0",
"pretty-hrtime": "^1.0.3",
"read-cache": "^1.0.0",
"slash": "^3.0.0",
"yargs": "^16.0.0"
"slash": "^5.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",
"eslint": "^8.2.0",
"eslint-config-problems": "7.0.1",
"postcss": "^8.0.4",
"postcss-import": "^12.0.0",
"prettier": "~2.2.0",
"sugarss": "^3.0.0",
"uuid": "^8.0.0"
"postcss-import": "^15.0.0",
"prettier": "~2.8.0",
"sugarss": "^4.0.0",
"uuid": "^9.0.0"
},

@@ -51,6 +51,5 @@ "peerDependencies": {

"files": [
"bin",
"index.js",
"lib",
"!*.test.js"
"!**/*.test.js"
],

@@ -57,0 +56,0 @@ "keywords": [

[![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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc