Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try using local postcss installation first in the CLI #8270

Merged
merged 2 commits into from May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Only check selectors containing base apply candidates for circular dependencies ([#8222](https://github.com/tailwindlabs/tailwindcss/pull/8222))
- Rewrite default class extractor ([#8204](https://github.com/tailwindlabs/tailwindcss/pull/8204))

### Changed

- Try using local `postcss` installation first in the CLI ([#8270](https://github.com/tailwindlabs/tailwindcss/pull/8270))

### Added

- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
Expand Down
4 changes: 3 additions & 1 deletion src/cli-peer-dependencies.js
@@ -1,4 +1,6 @@
export let postcss = require('postcss')
export function lazyPostcss() {
return require('postcss')
}

export function lazyAutoprefixer() {
return require('autoprefixer')
Expand Down
13 changes: 12 additions & 1 deletion src/cli.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { postcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
import { lazyPostcss, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'

import chokidar from 'chokidar'
import path from 'path'
Expand Down Expand Up @@ -146,6 +146,15 @@ function oneOf(...options) {
)
}

function loadPostcss() {
// Try to load a local `postcss` version first
try {
return require('postcss')
} catch {}

return lazyPostcss()
}

let commands = {
init: {
run: init,
Expand Down Expand Up @@ -576,6 +585,7 @@ async function build() {
})(),
].filter(Boolean)

let postcss = loadPostcss()
let processor = postcss(plugins)

function processCSS(css) {
Expand Down Expand Up @@ -709,6 +719,7 @@ async function build() {
let tailwindPluginIdx = plugins.indexOf('__TAILWIND_PLUGIN_POSITION__')
let copy = plugins.slice()
copy.splice(tailwindPluginIdx, 1, tailwindPlugin)
let postcss = loadPostcss()
let processor = postcss(copy)

function processCSS(css) {
Expand Down