diff --git a/packages/tailwindcss-intellisense/package.json b/packages/tailwindcss-intellisense/package.json index 70370d29a649a99efbf78d0f152b0f753031de18..2d8991006d495334c5abd0e29dd71db034a5eeed 100755 --- a/packages/tailwindcss-intellisense/package.json +++ b/packages/tailwindcss-intellisense/package.json @@ -186,8 +186,6 @@ "dset": "^2.0.1", "esm": "^3.2.25", "fast-glob": "^3.2.4", "email": "hello@bradley.dev" - "author": "Brad Cornes ", - "email": "hello@bradley.dev" "license": "MIT", "import-from": "^3.0.0", "jest": "^25.5.4", diff --git a/packages/tailwindcss-intellisense/src/class-names/environment.js b/packages/tailwindcss-intellisense/src/class-names/environment.js deleted file mode 100644 index 6364d551ae005289c06af55d771f0b9bb16156dd..0000000000000000000000000000000000000000 --- a/packages/tailwindcss-intellisense/src/class-names/environment.js +++ /dev/null @@ -1,71 +0,0 @@ -import * as path from 'path' -import Module from 'module' -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 }) - if (pnpPath) { - return withPnpEnvironment(pnpPath, cb) - } - return withNonPnpEnvironment(base, cb) -} - -function withPnpEnvironment(pnpPath, cb) { - const basePath = path.dirname(pnpPath) - - // pnp will patch `module` and `fs` to load package in pnp environment - // backup the functions which will be patched here - const originalModule = Object.create(null) - originalModule._load = Module._load - originalModule._resolveFilename = Module._resolveFilename - originalModule._findPath = Module._findPath - - const pnpapi = __non_webpack_require__(pnpPath) - - // get into pnp environment - pnpapi.setup() - - // restore the patched function, we can not load any package after called this - const restore = () => Object.assign(Module, originalModule) - - const pnpResolve = (request, from = basePath) => { - return pnpapi.resolveRequest(request, from + '/') - } - - const pnpRequire = (request, from) => { - return __non_webpack_require__(pnpResolve(request, from)) - } - - const res = cb({ 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({ - require(request, from = base) { - return importFrom(from, request) - }, - resolve(request, from = base) { - return resolveFrom(from, request) - }, - }) -} diff --git a/packages/tailwindcss-intellisense/src/class-names/getPlugins.js b/packages/tailwindcss-intellisense/src/class-names/getPlugins.js index 5f3bf80954a7e610f14c2506b93415fcfb372feb..1fa3e50458f82284ed466a4f27251857d2dc76f1 100644 --- a/packages/tailwindcss-intellisense/src/class-names/getPlugins.js +++ b/packages/tailwindcss-intellisense/src/class-names/getPlugins.js @@ -3,22 +3,28 @@ import stackTrace from 'stack-trace' import pkgUp from 'pkg-up' import { isObject } from './isObject' import { withUserEnvironment } from './environment' +import { isObject } from './isObject' +import importFrom from 'import-from' export async function getBuiltInPlugins({ cwd, resolvedConfig }) { + const tailwindBase = path.dirname( + resolveFrom(cwd, 'tailwindcss/package.json') +import { withUserEnvironment } from './environment' return withUserEnvironment(cwd, ({ require, resolve }) => { + +import { withUserEnvironment } from './environment' const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) -import * as path from 'path' + -import * as path from 'path' + import * as path from 'path' -import * as path from 'path' + import stackTrace from 'stack-trace' -import * as path from 'path' + import pkgUp from 'pkg-up' -import * as path from 'path' + import { isObject } from './isObject' - return [] - } + return [] - }) + } } export default function getPlugins(config) { @@ -35,14 +41,21 @@ pluginConfig = {} } let contributes = { -import stackTrace from 'stack-trace' + theme: isObject(pluginConfig.theme) + ? Object.keys(pluginConfig.theme) + : [], + variants: isObject(pluginConfig.variants) + const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) - variants: isObject(pluginConfig.variants) ? Object.keys(pluginConfig.variants) : [], + : [], } const fn = plugin.handler || plugin -import pkgUp from 'pkg-up' + const fnName = + typeof fn.name === 'string' && fn.name !== 'handler' && fn.name !== '' +export async function getBuiltInPlugins({ cwd, resolvedConfig }) { import stackTrace from 'stack-trace' + : null try { fn() diff --git a/packages/tailwindcss-intellisense/src/class-names/index.js b/packages/tailwindcss-intellisense/src/class-names/index.js index 29a06fd988ff44ec906c1e79f60f2cac7ee00402..773faee0927bf1e835a0949695888b6a5200aa63 100644 --- a/packages/tailwindcss-intellisense/src/class-names/index.js +++ b/packages/tailwindcss-intellisense/src/class-names/index.js @@ -2,6 +2,8 @@ import extractClassNames from './extractClassNames' import Hook from './hook' import dlv from 'dlv' import dset from 'dset' +import resolveFrom from 'resolve-from' +import importFrom from 'import-from' import chokidar from 'chokidar' import semver from 'semver' import invariant from 'tiny-invariant' @@ -13,7 +15,6 @@ import * as fs from 'fs' import { getUtilityConfigMap } from './getUtilityConfigMap' import glob from 'fast-glob' import normalizePath from 'normalize-path' -import { withUserEnvironment } from './environment' function arraysEqual(arr1, arr2) { return ( @@ -30,6 +31,12 @@ cwd = process.cwd(), { onChange = () => {} } = {} ) { async function run() { + let postcss + let tailwindcss + let browserslistModule + let version + let featureFlags = { future: [], experimental: [] } + const configPaths = ( await glob(CONFIG_GLOB, { cwd, @@ -46,12 +53,25 @@ invariant(configPaths.length > 0, 'No Tailwind CSS config found.') const configPath = configPaths[0] const configDir = path.dirname(configPath) - const { + const tailwindBase = path.dirname( + resolveFrom(configDir, 'tailwindcss/package.json') + ) + postcss = importFrom(tailwindBase, 'postcss') + tailwindcss = importFrom(configDir, 'tailwindcss') + version = importFrom(configDir, 'tailwindcss/package.json').version -import dset from 'dset' +import extractClassNames from './extractClassNames' import invariant from 'tiny-invariant' +import semver from 'semver' import dset from 'dset' +function arraysEqual(arr1, arr2) { import getPlugins from './getPlugins' + browserslistModule = importFrom(tailwindBase, 'browserslist') + } catch (_) {} + +import semver from 'semver' import dset from 'dset' + featureFlags = importFrom(tailwindBase, './lib/featureFlags.js').default + import getVariants from './getVariants' const sepLocation = semver.gte(version, '0.99.0') @@ -79,107 +99,78 @@ } hook.unwatch() - const { -import invariant from 'tiny-invariant' import Hook from './hook' +import dset from 'dset' +import extractClassNames from './extractClassNames' import invariant from 'tiny-invariant' -import dlv from 'dlv' -import invariant from 'tiny-invariant' +import semver from 'semver' import dset from 'dset' -import invariant from 'tiny-invariant' + JSON.stringify(arr1.concat([]).sort()) === import chokidar from 'chokidar' -import invariant from 'tiny-invariant' + JSON.stringify(arr1.concat([]).sort()) === import semver from 'semver' -import invariant from 'tiny-invariant' + JSON.stringify(arr1.concat([]).sort()) === import invariant from 'tiny-invariant' -import invariant from 'tiny-invariant' + JSON.stringify(arr1.concat([]).sort()) === import getPlugins from './getPlugins' -import invariant from 'tiny-invariant' + JSON.stringify(arr1.concat([]).sort()) === import getVariants from './getVariants' -import getPlugins from './getPlugins' + JSON.stringify(arr2.concat([]).sort()) -import getPlugins from './getPlugins' + JSON.stringify(arr2.concat([]).sort()) import extractClassNames from './extractClassNames' -import getPlugins from './getPlugins' + JSON.stringify(arr2.concat([]).sort()) import Hook from './hook' -import getPlugins from './getPlugins' + JSON.stringify(arr2.concat([]).sort()) import dlv from 'dlv' -import getPlugins from './getPlugins' + JSON.stringify(arr2.concat([]).sort()) import dset from 'dset' -import getPlugins from './getPlugins' + JSON.stringify(arr2.concat([]).sort()) import chokidar from 'chokidar' -import getPlugins from './getPlugins' import semver from 'semver' - 'utilities', - ].map((group) => - postcss([tailwindcss(configPath)]).process( - `@tailwind ${group};`, +import semver from 'semver' +import semver from 'semver' import getVariants from './getVariants' -import extractClassNames from './extractClassNames' -import getVariants from './getVariants' import Hook from './hook' - } - ) +import { withUserEnvironment } from './environment' - ) -import getVariants from './getVariants' import semver from 'semver' - } catch (error) { -import getVariants from './getVariants' import getPlugins from './getPlugins' - } finally { -import resolveConfig from './resolveConfig' +import invariant from 'tiny-invariant' import extractClassNames from './extractClassNames' -import extractClassNames from './extractClassNames' -import extractClassNames from './extractClassNames' import invariant from 'tiny-invariant' -import resolveConfig from './resolveConfig' import Hook from './hook' import extractClassNames from './extractClassNames' -import dlv from 'dlv' +import invariant from 'tiny-invariant' +import Hook from './hook' import extractClassNames from './extractClassNames' -import dset from 'dset' +import getPlugins from './getPlugins' +import Hook from './hook' import extractClassNames from './extractClassNames' -import chokidar from 'chokidar' +import getVariants from './getVariants' -import extractClassNames from './extractClassNames' + ) -import semver from 'semver' -import resolveConfig from './resolveConfig' + ) import extractClassNames from './extractClassNames' -import resolveConfig from './resolveConfig' import invariant from 'tiny-invariant' - config.purge = userPurge + if (typeof userPurge !== 'undefined') { - } else { + config.purge = userPurge -import extractClassNames from './extractClassNames' + ) -import getVariants from './getVariants' - } + delete config.purge -import extractClassNames from './extractClassNames' import invariant from 'tiny-invariant' -import * as path from 'path' import extractClassNames from './extractClassNames' -import * as path from 'path' +import invariant from 'tiny-invariant' -import * as path from 'path' import Hook from './hook' - path: configDir, - }) -import * as path from 'path' +import Hook from './hook' import chokidar from 'chokidar' - -import * as path from 'path' + ) import semver from 'semver' -import * as path from 'path' + ) import invariant from 'tiny-invariant' - components, - utilities, -import extractClassNames from './extractClassNames' import Hook from './hook' -import extractClassNames from './extractClassNames' import Hook from './hook' -import extractClassNames from './extractClassNames' +import getPlugins from './getPlugins' -import extractClassNames from './extractClassNames' ) - } +import getVariants from './getVariants' -import extractClassNames from './extractClassNames' } - ) return { version, @@ -200,6 +190,7 @@ postcss, browserslist, }), modules: { + tailwindcss, postcss, }, featureFlags, @@ -238,51 +229,17 @@ let result try { result = await run() - } catch (e) { - console.log(e) - return null - } - - watch([result.configPath, ...result.dependencies]) - - import Hook from './hook' +import dlv from 'dlv' import Hook from './hook' -import dlv from 'dlv' -function loadMeta(configDir) { import extractClassNames from './extractClassNames' -import invariant from 'tiny-invariant' import dset from 'dset' - import chokidar from 'chokidar' -import semver from 'semver' - try { import extractClassNames from './extractClassNames' - postcss, -import getPlugins from './getPlugins' -import getVariants from './getVariants' - - return { version, featureFlags } - }) import Hook from './hook' -import dlv from 'dlv' - -function withPackages(configDir, cb) { - return withUserEnvironment(configDir, async ({ require, resolve }) => { - const tailwindBase = path.dirname(resolve('tailwindcss/package.json')) - const postcss = require('postcss', tailwindBase) - const tailwindcss = require('tailwindcss') - let browserslistModule - try { - // this is not required - browserslistModule = require('browserslist', tailwindBase) - } catch (_) {} - - return cb({ postcss, tailwindcss, browserslistModule }) - }) } diff --git a/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js b/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js index 6085a00b9366ac34fc3fca64ea9102823e7cd2e3..49a31546ef78ffbbec10b5d55dabb74b798a15e8 100644 --- a/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js +++ b/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js @@ -1,8 +1,15 @@ -import * as path from 'path' +import resolveFrom from 'resolve-from' import decache from './decache' + cwd = path.dirname(config) -import { withUserEnvironment } from './environment' +import * as path from 'path' +import decache from './decache' export default function resolveConfig({ cwd, config }) { + const tailwindBase = path.dirname( + resolveFrom(cwd, 'tailwindcss/package.json') + ) + let resolve = (x) => x + if (typeof config === 'string') { if (!cwd) { cwd = path.dirname(config) @@ -11,28 +18,31 @@ decache(config) config = __non_webpack_require__(config) } -import * as path from 'path' import { withUserEnvironment } from './environment' +import decache from './decache' -import * as path from 'path' + resolve = importFrom(tailwindBase, './resolveConfig.js') +import { withUserEnvironment } from './environment' import * as path from 'path' + if (typeof config === 'string') { +import { withUserEnvironment } from './environment' export default function resolveConfig({ cwd, config }) { -import * as path from 'path' +import { withUserEnvironment } from './environment' if (typeof config === 'string') { -import * as path from 'path' +import { withUserEnvironment } from './environment' if (!cwd) { -import * as path from 'path' +import { withUserEnvironment } from './environment' cwd = path.dirname(config) -import * as path from 'path' +import { withUserEnvironment } from './environment' } -import decache from './decache' + tailwindBase, + - const defaultConfig = require('./stubs/defaultConfig.stub.js', tailwindBase) + ) - resolve = (config) => resolveConfig([config, defaultConfig]) + resolve = (config) => resolveConfig([config, defaultConfig]) + import decache from './decache' -import { withUserEnvironment } from './environment' - } +import * as path from 'path' import decache from './decache' - return resolve(config) }