Skip to content

Commit

Permalink
Add bundled version of tailwindcss and first-party plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
bradlc committed Jan 7, 2022
1 parent 2594afb commit 6fdef86
Show file tree
Hide file tree
Showing 8 changed files with 2,404 additions and 14,580 deletions.
2,853 changes: 1,787 additions & 1,066 deletions package-lock.json

Large diffs are not rendered by default.

13,646 changes: 151 additions & 13,495 deletions packages/tailwindcss-language-server/package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/tailwindcss-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
},
"devDependencies": {
"@parcel/watcher": "2.0.3",
"@tailwindcss/aspect-ratio": "0.4.0",
"@tailwindcss/forms": "0.4.0",
"@tailwindcss/line-clamp": "0.3.0",
"@tailwindcss/typography": "0.5.0",
"@types/debounce": "1.2.0",
"@types/node": "14.14.34",
"@types/vscode": "1.52.0",
Expand Down Expand Up @@ -50,6 +54,7 @@
"rimraf": "3.0.2",
"semver": "7.3.2",
"stack-trace": "0.0.10",
"tailwindcss": "3.0.11",
"terser": "4.6.12",
"typescript": "4.2.4",
"vscode-languageserver": "7.0.0",
Expand Down
28 changes: 26 additions & 2 deletions packages/tailwindcss-language-server/src/lib/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
* Adapted from: https://github.com/elastic/require-in-the-middle
*/
import Module from 'module'
import plugins from './plugins'

let bundledModules = {
...plugins,
'tailwindcss/colors': require('tailwindcss/colors'),
'tailwindcss/defaultConfig': require('tailwindcss/defaultConfig'),
'tailwindcss/defaultTheme': require('tailwindcss/defaultTheme'),
'tailwindcss/resolveConfig': require('tailwindcss/resolveConfig'),
'tailwindcss/plugin': require('tailwindcss/plugin'),
}

export default class Hook {
cache = {}
Expand Down Expand Up @@ -31,8 +41,22 @@ export default class Hook {
return self._origRequire.apply(this, arguments)
}

// @ts-ignore
let filename = Module._resolveFilename(request, this)
let filename

if (bundledModules.hasOwnProperty(request)) {
try {
// @ts-ignore
filename = Module._resolveFilename(request, this)
} catch (_) {
// if (plugins.hasOwnProperty(request)) {
// console.log(`Using bundled version of \`${request}\`: v${plugins[request].version}`)
// }
return bundledModules[request].module || bundledModules[request]
}
} else {
// @ts-ignore
filename = Module._resolveFilename(request, this)
}

// return known patched modules immediately
if (self.cache.hasOwnProperty(filename)) {
Expand Down
18 changes: 18 additions & 0 deletions packages/tailwindcss-language-server/src/lib/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
'@tailwindcss/aspect-ratio': {
module: require('@tailwindcss/aspect-ratio'),
version: require('@tailwindcss/aspect-ratio/package.json').version,
},
'@tailwindcss/forms': {
module: require('@tailwindcss/forms'),
version: require('@tailwindcss/forms/package.json').version,
},
'@tailwindcss/line-clamp': {
module: require('@tailwindcss/line-clamp'),
version: require('@tailwindcss/line-clamp/package.json').version,
},
'@tailwindcss/typography': {
module: require('@tailwindcss/typography'),
version: require('@tailwindcss/typography/package.json').version,
},
}
Loading

0 comments on commit 6fdef86

Please sign in to comment.