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 importFrom from 'import-from'
export function withUserEnvironment(base, cb) {
const pnpPath = findUp.sync('.pnp.js', { cwd: base })
export function withUserEnvironment(base, root, cb) {
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) {
return withPnpEnvironment(pnpPath, cb)
}

View File

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

View File

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

View File

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