don't search for pnp file above root dir

master
Brad Cornes 2020-12-10 13:47:05 +00:00
parent b6dbe71797
commit 0369ee74e0
5 changed files with 60 additions and 38 deletions

View File

@ -4,8 +4,19 @@ import findUp from 'find-up'
import resolveFrom from 'resolve-from' import resolveFrom from 'resolve-from'
import importFrom from 'import-from' import importFrom from 'import-from'
export function withUserEnvironment(base, cb) { export function withUserEnvironment(base, root, cb) {
const pnpPath = findUp.sync('.pnp.js', { cwd: base }) const pnpPath = findUp.sync(
(dir) => {
const pnpFile = path.join(dir, '.pnp.js')
if (findUp.sync.exists(pnpFile)) {
return pnpFile
}
if (dir === root) {
return findUp.stop
}
},
{ cwd: base }
)
if (pnpPath) { if (pnpPath) {
return withPnpEnvironment(pnpPath, cb) return withPnpEnvironment(pnpPath, cb)
} }

View File

@ -4,8 +4,8 @@ import pkgUp from 'pkg-up'
import { isObject } from './isObject' import { isObject } from './isObject'
import { withUserEnvironment } from './environment' import { withUserEnvironment } from './environment'
export async function getBuiltInPlugins({ cwd, resolvedConfig }) { export async function getBuiltInPlugins({ base, root, resolvedConfig }) {
return withUserEnvironment(cwd, ({ require, resolve }) => { return withUserEnvironment(base, root, ({ require, resolve }) => {
const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
try { try {
return require('./lib/corePlugins.js', tailwindBase).default({ return require('./lib/corePlugins.js', tailwindBase).default({

View File

@ -19,12 +19,13 @@ const proxyHandler = (base = []) => ({
}) })
export async function getUtilityConfigMap({ export async function getUtilityConfigMap({
cwd, base,
root,
resolvedConfig, resolvedConfig,
postcss, postcss,
browserslist, browserslist,
}) { }) {
const builtInPlugins = await getBuiltInPlugins({ cwd, resolvedConfig }) const builtInPlugins = await getBuiltInPlugins({ base, root, resolvedConfig })
const userPlugins = Array.isArray(resolvedConfig.plugins) const userPlugins = Array.isArray(resolvedConfig.plugins)
? resolvedConfig.plugins ? resolvedConfig.plugins
: [] : []

View File

@ -52,7 +52,7 @@ export default async function getClassNames(
version, version,
featureFlags = { future: [], experimental: [] }, featureFlags = { future: [], experimental: [] },
tailwindBase, tailwindBase,
} = loadMeta(configDir) } = loadMeta(configDir, cwd)
console.log(`Found tailwindcss v${version}: ${tailwindBase}`) console.log(`Found tailwindcss v${version}: ${tailwindBase}`)
@ -90,6 +90,7 @@ export default async function getClassNames(
postcss, postcss,
} = await withPackages( } = await withPackages(
configDir, configDir,
cwd,
async ({ async ({
postcss, postcss,
tailwindcss, tailwindcss,
@ -131,7 +132,11 @@ export default async function getClassNames(
delete config.purge delete config.purge
} }
const resolvedConfig = resolveConfig({ cwd: configDir, config }) const resolvedConfig = resolveConfig({
base: configDir,
root: cwd,
config,
})
let browserslist = [] let browserslist = []
if ( if (
@ -180,7 +185,8 @@ export default async function getClassNames(
plugins: getPlugins(config), plugins: getPlugins(config),
variants: getVariants({ config, version, postcss, browserslist }), variants: getVariants({ config, version, postcss, browserslist }),
utilityConfigMap: await getUtilityConfigMap({ utilityConfigMap: await getUtilityConfigMap({
cwd: configDir, base: configDir,
root: cwd,
resolvedConfig, resolvedConfig,
postcss, postcss,
browserslist, browserslist,
@ -235,8 +241,8 @@ export default async function getClassNames(
return result return result
} }
function loadMeta(configDir) { function loadMeta(configDir, root) {
return withUserEnvironment(configDir, ({ require, resolve }) => { return withUserEnvironment(configDir, root, ({ require, resolve }) => {
const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
const version = require('tailwindcss/package.json').version const version = require('tailwindcss/package.json').version
let featureFlags let featureFlags
@ -249,31 +255,35 @@ function loadMeta(configDir) {
}) })
} }
function withPackages(configDir, cb) { function withPackages(configDir, root, cb) {
return withUserEnvironment(configDir, async ({ isPnP, require, resolve }) => { return withUserEnvironment(
const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) configDir,
const postcss = require('postcss', tailwindBase) root,
const tailwindcss = require('tailwindcss') async ({ isPnP, require, resolve }) => {
const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
const postcss = require('postcss', tailwindBase)
const tailwindcss = require('tailwindcss')
let browserslistCommand let browserslistCommand
let browserslistArgs = [] let browserslistArgs = []
try { try {
const browserslistBin = resolve( const browserslistBin = resolve(
path.join( path.join(
'browserslist', 'browserslist',
require('browserslist/package.json', tailwindBase).bin.browserslist require('browserslist/package.json', tailwindBase).bin.browserslist
), ),
tailwindBase tailwindBase
) )
if (isPnP) { if (isPnP) {
browserslistCommand = 'yarn' browserslistCommand = 'yarn'
browserslistArgs = ['node', browserslistBin] browserslistArgs = ['node', browserslistBin]
} else { } else {
browserslistCommand = process.execPath browserslistCommand = process.execPath
browserslistArgs = [browserslistBin] browserslistArgs = [browserslistBin]
} }
} catch (_) {} } catch (_) {}
return cb({ postcss, tailwindcss, browserslistCommand, browserslistArgs }) return cb({ postcss, tailwindcss, browserslistCommand, browserslistArgs })
}) }
)
} }

View File

@ -2,7 +2,7 @@ import * as path from 'path'
import decache from './decache' import decache from './decache'
import { withUserEnvironment } from './environment' import { withUserEnvironment } from './environment'
export default function resolveConfig({ cwd, config }) { export default function resolveConfig({ base, root, config }) {
if (typeof config === 'string') { if (typeof config === 'string') {
if (!cwd) { if (!cwd) {
cwd = path.dirname(config) cwd = path.dirname(config)
@ -11,7 +11,7 @@ export default function resolveConfig({ cwd, config }) {
config = __non_webpack_require__(config) config = __non_webpack_require__(config)
} }
return withUserEnvironment(cwd, ({ require, resolve }) => { return withUserEnvironment(base, root, ({ require, resolve }) => {
let resolveConfigFn = (config) => config let resolveConfigFn = (config) => config
const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
try { try {