diff --git a/packages/tailwindcss-intellisense/src/class-names/environment.js b/packages/tailwindcss-intellisense/src/class-names/environment.js index c18806cfeccf37f39a33224beb87e398f02636e5..2eb5dbd055c602bc3010f2f98b27043d2bedac72 100644 --- a/packages/tailwindcss-intellisense/src/class-names/environment.js +++ b/packages/tailwindcss-intellisense/src/class-names/environment.js @@ -1,62 +1,59 @@ import * as path from 'path' +import Module from 'module' import findUp from 'find-up' import resolveFrom from 'resolve-from' import importFrom from 'import-from' -let isPnp -let pnpApi - export function withUserEnvironment(base, root, cb) { - if (isPnp === true) { - return withPnpEnvironment(base, cb) - } - - if (isPnp === false) { - return withNonPnpEnvironment(base, cb) - } - const pnpPath = findUp.sync( (dir) => { - let pnpFile = path.join(dir, '.pnp.js') - if (findUp.sync.exists(pnpFile)) { - return pnpFile -import * as path from 'path' + if (isPnp === true) { - pnpFile = path.join(dir, '.pnp.cjs') if (findUp.sync.exists(pnpFile)) { return pnpFile } if (dir === root) { return findUp.stop } + }, + { cwd: base } + ) + if (pnpPath) { + return withPnpEnvironment(pnpPath, cb) + } + return withNonPnpEnvironment(base, cb) -import findUp from 'find-up' +import resolveFrom from 'resolve-from' import resolveFrom from 'resolve-from' + +let isPnp import findUp from 'find-up' -import importFrom from 'import-from' -import findUp from 'find-up' + const basePath = path.dirname(pnpPath) + // pnp will patch `module` and `fs` to load package in pnp environment +let isPnp -import findUp from 'find-up' +let isPnp let isPnp -import findUp from 'find-up' +let isPnp let pnpApi -import findUp from 'find-up' +let isPnp export function withUserEnvironment(base, root, cb) { -import findUp from 'find-up' +let isPnp if (isPnp === true) { -import resolveFrom from 'resolve-from' + +let pnpApi -import resolveFrom from 'resolve-from' + +let pnpApi import * as path from 'path' - } + pnpapi.setup() +let pnpApi import resolveFrom from 'resolve-from' -import findUp from 'find-up' -} + const restore = () => Object.assign(Module, originalModule) -function withPnpEnvironment(base, cb) { -import resolveFrom from 'resolve-from' +let pnpApi -import resolveFrom from 'resolve-from' +let pnpApi let isPnp } @@ -63,26 +61,30 @@ const pnpRequire = (request, from) => { return __non_webpack_require__(pnpResolve(request, from)) } - const res = cb({ isPnp: true, resolve: pnpResolve, require: pnpRequire }) + const res = cb({ isPnP: true, resolve: pnpResolve, require: pnpRequire }) // check if it return a thenable if (res != null && res.then) { return res.then( (x) => { + restore() return x }, (err) => { + restore() throw err } ) } + restore() + return res } function withNonPnpEnvironment(base, cb) { return cb({ - isPnp: false, + isPnP: false, require(request, from = base) { return importFrom(from, request) }, diff --git a/packages/tailwindcss-intellisense/src/class-names/index.js b/packages/tailwindcss-intellisense/src/class-names/index.js index 7dedcdf3b7794926419940010372a08991f75d8b..98d3dc0b4856787f1c1800e23120ba5464125478 100644 --- a/packages/tailwindcss-intellisense/src/class-names/index.js +++ b/packages/tailwindcss-intellisense/src/class-names/index.js @@ -260,7 +260,7 @@ return withUserEnvironment( configDir, root, import Hook from './hook' -import normalizePath from 'normalize-path' + onlyFiles: true, const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) const postcss = require('postcss', tailwindBase) const tailwindcss = require('tailwindcss') @@ -276,7 +276,7 @@ ), tailwindBase ) import Hook from './hook' - { onChange = () => {} } = {} + absolute: true, browserslistCommand = 'yarn' browserslistArgs = ['node', browserslistBin] } else {