support tailwindcss v2.2

master
Brad Cornes 2021-06-04 12:17:00 +01:00
parent bdb398bf80
commit 4de605928b
7 changed files with 1704 additions and 16272 deletions

15
package-lock.json generated
View File

@ -10,7 +10,7 @@
"@types/debounce": "1.2.0", "@types/debounce": "1.2.0",
"@types/moo": "0.5.3", "@types/moo": "0.5.3",
"@types/node": "14.14.34", "@types/node": "14.14.34",
"@types/vscode": "1.56.0", "@types/vscode": "1.52.0",
"@vercel/ncc": "0.28.4", "@vercel/ncc": "0.28.4",
"builtin-modules": "3.2.0", "builtin-modules": "3.2.0",
"chokidar": "3.5.1", "chokidar": "3.5.1",
@ -4451,9 +4451,10 @@
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==" "integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw=="
}, },
"node_modules/@types/vscode": { "node_modules/@types/vscode": {
"version": "1.56.0", "version": "1.52.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.56.0.tgz", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.52.0.tgz",
"integrity": "sha512-Q5VmQxOx+L1Y6lIJiGcJzwcyV3pQo/eiW8P+7sNLhFI16tJCwtua2DLjHRcpjbCLNVYpQM73kzfFo1Z0HyP9eQ==" "integrity": "sha512-Kt3bvWzAvvF/WH9YEcrCICDp0Z7aHhJGhLJ1BxeyNP6yRjonWqWnAIh35/pXAjswAnWOABrYlF7SwXR9+1nnLA==",
"license": "MIT"
}, },
"node_modules/@types/yargs": { "node_modules/@types/yargs": {
"version": "15.0.13", "version": "15.0.13",
@ -23077,9 +23078,9 @@
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==" "integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw=="
}, },
"@types/vscode": { "@types/vscode": {
"version": "1.56.0", "version": "1.52.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.56.0.tgz", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.52.0.tgz",
"integrity": "sha512-Q5VmQxOx+L1Y6lIJiGcJzwcyV3pQo/eiW8P+7sNLhFI16tJCwtua2DLjHRcpjbCLNVYpQM73kzfFo1Z0HyP9eQ==" "integrity": "sha512-Kt3bvWzAvvF/WH9YEcrCICDp0Z7aHhJGhLJ1BxeyNP6yRjonWqWnAIh35/pXAjswAnWOABrYlF7SwXR9+1nnLA=="
}, },
"@types/yargs": { "@types/yargs": {
"version": "15.0.13", "version": "15.0.13",

File diff suppressed because it is too large Load Diff

View File

@ -431,21 +431,41 @@ async function createProjectService(
} }
try { try {
featureFlags = __non_webpack_require__(resolveFrom(tailwindDir, './lib/featureFlags.js')) featureFlags = __non_webpack_require__(
.default resolveFrom(tailwindDir, './lib/featureFlags.js')
).default
} catch (_) {} } catch (_) {}
// stubs
let tailwindDirectives = new Set()
let root = postcss.root()
let result = { opts: {}, messages: [] }
try { try {
let createContext
try {
let createContextFn = __non_webpack_require__(
resolveFrom(configDir, 'tailwindcss/lib/jit/lib/setupContextUtils')
).createContext
createContext = (state) => createContextFn(state.config)
} catch (_) {
// TODO: only for canary releases so can probably remove
let setupContext = __non_webpack_require__(
resolveFrom(configDir, 'tailwindcss/lib/jit/lib/setupContext')
).default
createContext = (state) =>
setupContext(state.configPath, tailwindDirectives)(result, root)
}
jitModules = { jitModules = {
generateRules: { generateRules: {
module: __non_webpack_require__( module: __non_webpack_require__(
resolveFrom(configDir, 'tailwindcss/lib/jit/lib/generateRules') resolveFrom(configDir, 'tailwindcss/lib/jit/lib/generateRules')
).generateRules, ).generateRules,
}, },
setupContext: { createContext: {
module: __non_webpack_require__( module: createContext,
resolveFrom(configDir, 'tailwindcss/lib/jit/lib/setupContext')
).default,
}, },
expandApplyAtRules: { expandApplyAtRules: {
module: __non_webpack_require__( module: __non_webpack_require__(
@ -455,16 +475,18 @@ async function createProjectService(
} }
} catch (_) { } catch (_) {
try { try {
let setupContext = __non_webpack_require__(
resolveFrom(configDir, 'tailwindcss/jit/lib/setupContext')
)
jitModules = { jitModules = {
generateRules: { generateRules: {
module: __non_webpack_require__( module: __non_webpack_require__(
resolveFrom(configDir, 'tailwindcss/jit/lib/generateRules') resolveFrom(configDir, 'tailwindcss/jit/lib/generateRules')
).generateRules, ).generateRules,
}, },
setupContext: { createContext: {
module: __non_webpack_require__( module: (state) => setupContext(state.configPath, tailwindDirectives)(result, root),
resolveFrom(configDir, 'tailwindcss/jit/lib/setupContext')
),
}, },
expandApplyAtRules: { expandApplyAtRules: {
module: __non_webpack_require__( module: __non_webpack_require__(
@ -500,6 +522,14 @@ async function createProjectService(
state.featureFlags = featureFlags state.featureFlags = featureFlags
state.version = tailwindcssVersion state.version = tailwindcssVersion
try {
state.corePlugins = Object.keys(
__non_webpack_require__(
resolveFrom(path.dirname(state.configPath), 'tailwindcss/lib/plugins/index.js')
)
)
} catch (_) {}
if (applyComplexClasses && !applyComplexClasses.default.__patched) { if (applyComplexClasses && !applyComplexClasses.default.__patched) {
let _applyComplexClasses = applyComplexClasses.default let _applyComplexClasses = applyComplexClasses.default
applyComplexClasses.default = (config, ...args) => { applyComplexClasses.default = (config, ...args) => {
@ -572,25 +602,18 @@ async function createProjectService(
const sepLocation = semver.gte(tailwindcss.version, '0.99.0') const sepLocation = semver.gte(tailwindcss.version, '0.99.0')
? ['separator'] ? ['separator']
: ['options', 'separator'] : ['options', 'separator']
let userSeperator: string
let userPurge
let userVariants: any
let userMode: any
let userPlugins: any
let presetModes: any[] = [] let presetModes: any[] = []
let presetVariants: any[] = [] let presetVariants: any[] = []
let originalConfig: any
let hook = new Hook(fs.realpathSync(state.configPath), (exports) => { let hook = new Hook(fs.realpathSync(state.configPath), (exports) => {
userSeperator = dlv(exports, sepLocation) originalConfig = klona(exports)
if (typeof userSeperator !== 'string') {
userSeperator = undefined let separator = dlv(exports, sepLocation)
if (typeof separator !== 'string') {
separator = ''
} }
userPurge = exports.purge dset(exports, sepLocation, `__TWSEP__${separator}__TWSEP__`)
dset(
exports,
sepLocation,
`__TWSEP__${typeof userSeperator === 'undefined' ? ':' : userSeperator}__TWSEP__`
)
exports.purge = [] exports.purge = []
let mode: any let mode: any
@ -606,12 +629,10 @@ async function createProjectService(
if (typeof exports.mode !== 'undefined') { if (typeof exports.mode !== 'undefined') {
mode = exports.mode mode = exports.mode
} }
userMode = exports.mode
delete exports.mode delete exports.mode
if (state.modules.jit && mode === 'jit') { if (state.modules.jit && mode === 'jit') {
state.jit = true state.jit = true
userVariants = exports.variants
exports.variants = [] exports.variants = []
if (Array.isArray(exports.presets)) { if (Array.isArray(exports.presets)) {
@ -624,9 +645,16 @@ async function createProjectService(
state.jit = false state.jit = false
} }
if (state.corePlugins) {
let corePluginsConfig = {}
for (let pluginName of state.corePlugins) {
corePluginsConfig[pluginName] = true
}
exports.corePlugins = corePluginsConfig
}
// inject JIT `matchUtilities` function // inject JIT `matchUtilities` function
if (Array.isArray(exports.plugins)) { if (Array.isArray(exports.plugins)) {
userPlugins = exports.plugins
exports.plugins = exports.plugins.map((plugin) => { exports.plugins = exports.plugins.map((plugin) => {
if (plugin.__isOptionsFunction) { if (plugin.__isOptionsFunction) {
plugin = plugin() plugin = plugin()
@ -661,21 +689,22 @@ async function createProjectService(
return exports return exports
}) })
let config
try { try {
config = __non_webpack_require__(state.configPath) __non_webpack_require__(state.configPath)
} catch (error) { } catch (error) {
hook.unhook() hook.unhook()
throw error throw error
} }
if (!originalConfig) {
throw new SilentError(`Failed to load config file: ${state.configPath}`)
}
state.config = resolveConfig.module(originalConfig)
if (state.jit) { if (state.jit) {
state.jitContext = state.modules.jit.setupContext.module(state.configPath, new Set())( state.jitContext = state.modules.jit.createContext.module(state)
{ opts: {}, messages: [] }, state.jitContext.tailwindConfig.separator = state.config.separator
state.modules.postcss.module.root()
)
state.jitContext.tailwindConfig.separator =
typeof userSeperator === 'undefined' ? ':' : userSeperator
} }
let postcssResult: Result let postcssResult: Result
@ -704,43 +733,6 @@ async function createProjectService(
hook.unhook() hook.unhook()
} }
if (typeof userSeperator !== 'undefined') {
dset(config, sepLocation, userSeperator)
} else {
deletePropertyPath(config, sepLocation)
}
if (typeof userPurge !== 'undefined') {
config.purge = userPurge
} else {
delete config.purge
}
if (typeof userVariants !== 'undefined') {
config.variants = userVariants
} else {
delete config.variants
}
if (typeof userMode !== 'undefined') {
config.mode = userMode
}
if (typeof userPlugins !== 'undefined') {
config.plugins = userPlugins
}
for (let index in presetModes) {
if (typeof presetModes[index] === 'undefined') {
delete config.presets[index].mode
} else {
config.presets[index].mode = presetModes[index]
}
}
for (let index in presetVariants) {
if (typeof presetVariants[index] === 'undefined') {
delete config.presets[index].variants
} else {
config.presets[index].variants = presetVariants[index]
}
}
if (state.dependencies) { if (state.dependencies) {
watcher.unwatch(state.dependencies) watcher.unwatch(state.dependencies)
} }
@ -749,9 +741,8 @@ async function createProjectService(
state.configId = getConfigId(state.configPath, state.dependencies) state.configId = getConfigId(state.configPath, state.dependencies)
state.config = resolveConfig.module(config) state.separator = state.config.separator
state.separator = typeof userSeperator === 'string' ? userSeperator : ':' state.plugins = await getPlugins(originalConfig)
state.plugins = await getPlugins(config)
state.classNames = (await extractClassNames(postcssResult.root)) as ClassNames state.classNames = (await extractClassNames(postcssResult.root)) as ClassNames
state.variants = getVariants(state) state.variants = getVariants(state)
@ -908,8 +899,15 @@ function getVariants(state: State): Record<string, string> {
return dlv(node, 'raws.value', node.value) return dlv(node, 'raws.value', node.value)
} }
return Array.from(state.jitContext.variantMap as Map<string, [any, any]>).reduce( let result = {}
(acc, [variant, [, applyVariant]]) => { // [name, [sort, fn]]
// [name, [[sort, fn]]]
Array.from(state.jitContext.variantMap as Map<string, [any, any]>).forEach(
([variantName, variantFnOrFns]) => {
let fns = (Array.isArray(variantFnOrFns[0]) ? variantFnOrFns : [variantFnOrFns]).map(
([_sort, fn]) => fn
)
let placeholder = '__variant_placeholder__' let placeholder = '__variant_placeholder__'
let root = state.modules.postcss.module.root({ let root = state.modules.postcss.module.root({
@ -947,26 +945,37 @@ function getVariants(state: State): Record<string, string> {
return root return root
} }
applyVariant({ let definitions = []
container: root,
for (let fn of fns) {
let container = root.clone()
fn({
container,
separator: state.separator, separator: state.separator,
modifySelectors, modifySelectors,
}) })
let definition = root container.walkDecls((decl) => {
decl.remove()
})
let definition = container
.toString() .toString()
.replace(`.${escape(`${variant}:${placeholder}`)}`, '&') .replace(`.${escape(`${variantName}:${placeholder}`)}`, '&')
.replace(/(?<!\\)[{}]/g, '') .replace(/(?<!\\)[{}]/g, '')
.replace(/\s*\n\s*/g, ' ') .replace(/\s*\n\s*/g, ' ')
.trim() .trim()
return { if (!definition.includes(placeholder)) {
...acc, definitions.push(definition)
[variant]: definition.includes(placeholder) ? null : definition, }
}
result[variantName] = definitions.join(', ') || null
} }
},
{}
) )
return result
} }
let config = state.config let config = state.config
@ -1232,8 +1241,7 @@ function supportsDynamicRegistration(connection: Connection, params: InitializeP
const tw = new TW(connection) const tw = new TW(connection)
connection.onInitialize( connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
async (params: InitializeParams): Promise<InitializeResult> => {
tw.initializeParams = params tw.initializeParams = params
if (supportsDynamicRegistration(connection, params)) { if (supportsDynamicRegistration(connection, params)) {
@ -1258,8 +1266,7 @@ connection.onInitialize(
}, },
}, },
} }
} })
)
connection.onInitialized(async () => { connection.onInitialized(async () => {
await tw.init() await tw.init()

View File

@ -72,6 +72,7 @@ export interface State {
plugins?: any plugins?: any
screens?: string[] screens?: string[]
variants?: Record<string, string | null> variants?: Record<string, string | null>
corePlugins?: string[]
modules?: { modules?: {
tailwindcss?: { version: string; module: any } tailwindcss?: { version: string; module: any }
postcss?: { version: string; module: Postcss } postcss?: { version: string; module: Postcss }
@ -79,7 +80,7 @@ export interface State {
resolveConfig?: { module: any } resolveConfig?: { module: any }
jit?: { jit?: {
generateRules: { module: any } generateRules: { module: any }
setupContext: { module: any } createContext: { module: any }
expandApplyAtRules: { module: any } expandApplyAtRules: { module: any }
} }
} }

View File

@ -1 +1,2 @@
/dist /dist
/*.vsix

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"preview": true, "preview": true,
"author": "Brad Cornes <hello@bradley.dev>", "author": "Brad Cornes <hello@bradley.dev>",
"license": "MIT", "license": "MIT",
"version": "0.6.6", "version": "0.6.7",
"homepage": "https://github.com/tailwindlabs/tailwindcss-intellisense", "homepage": "https://github.com/tailwindlabs/tailwindcss-intellisense",
"bugs": { "bugs": {
"url": "https://github.com/tailwindlabs/tailwindcss-intellisense/issues", "url": "https://github.com/tailwindlabs/tailwindcss-intellisense/issues",
@ -196,7 +196,7 @@
}, },
"devDependencies": { "devDependencies": {
"@ctrl/tinycolor": "3.1.4", "@ctrl/tinycolor": "3.1.4",
"@types/vscode": "1.56.0", "@types/vscode": "1.52.0",
"@vercel/ncc": "0.28.4", "@vercel/ncc": "0.28.4",
"glob-exec": "0.1.1", "glob-exec": "0.1.1",
"rimraf": "3.0.2", "rimraf": "3.0.2",