File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
packages/tailwindcss-language-server/src Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -442,16 +442,24 @@ export async function createProjectService(
442
442
let applyComplexClasses : any
443
443
444
444
try {
445
- let tailwindcssPath = await resolver . resolveJsId ( 'tailwindcss' , configDir )
446
- let tailwindcssPkgPath = await resolver . resolveJsId ( 'tailwindcss/package.json' , configDir )
445
+ let tailwindcssPkgPath = await resolver . resolveCjsId ( 'tailwindcss/package.json' , configDir )
447
446
let tailwindDir = path . dirname ( tailwindcssPkgPath )
448
447
tailwindcssVersion = require ( tailwindcssPkgPath ) . version
449
448
450
449
let features = supportedFeatures ( tailwindcssVersion )
451
450
log ( `supported features: ${ JSON . stringify ( features ) } ` )
452
451
453
- tailwindcssPath = pathToFileURL ( tailwindcssPath ) . href
454
- tailwindcss = await import ( tailwindcssPath )
452
+ // Loading via `await import(…)` with the Yarn PnP API is not possible
453
+ if ( await resolver . hasPnP ( ) ) {
454
+ let tailwindcssPath = await resolver . resolveCjsId ( 'tailwindcss' , configDir )
455
+
456
+ tailwindcss = require ( tailwindcssPath )
457
+ } else {
458
+ let tailwindcssPath = await resolver . resolveJsId ( 'tailwindcss' , configDir )
459
+ let tailwindcssURL = pathToFileURL ( tailwindcssPath ) . href
460
+
461
+ tailwindcss = await import ( tailwindcssURL )
462
+ }
455
463
456
464
if ( ! features . includes ( 'css-at-theme' ) ) {
457
465
tailwindcss = tailwindcss . default ?? tailwindcss
Original file line number Diff line number Diff line change @@ -55,6 +55,16 @@ export interface Resolver {
55
55
*/
56
56
resolveJsId ( id : string , base : string ) : Promise < string >
57
57
58
+ /**
59
+ * Resolves a CJS module to a file path.
60
+ *
61
+ * Assumes ESM-captable mechanisms are not available.
62
+ *
63
+ * @param id The module or file to resolve
64
+ * @param base The base directory to resolve the module from
65
+ */
66
+ resolveCjsId ( id : string , base : string ) : Promise < string >
67
+
58
68
/**
59
69
* Resolves a CSS module to a file path.
60
70
*
@@ -204,6 +214,10 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
204
214
}
205
215
}
206
216
217
+ async function resolveCjsId ( id : string , base : string ) : Promise < string > {
218
+ return ( await resolveId ( cjsResolver , id , base ) ) || id
219
+ }
220
+
207
221
async function resolveCssId ( id : string , base : string ) : Promise < string > {
208
222
return ( await resolveId ( cssResolver , id , base ) ) || id
209
223
}
@@ -230,6 +244,7 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
230
244
231
245
return {
232
246
resolveJsId,
247
+ resolveCjsId,
233
248
resolveCssId,
234
249
substituteId,
235
250
refresh,
Original file line number Diff line number Diff line change @@ -36,7 +36,6 @@ import normalizePath from 'normalize-path'
36
36
import * as path from 'node:path'
37
37
import type * as chokidar from 'chokidar'
38
38
import picomatch from 'picomatch'
39
- import { resolveFrom } from './util/resolveFrom'
40
39
import * as parcel from './watcher/index.js'
41
40
import { equal } from '@tailwindcss/language-service/src/util/array'
42
41
import { CONFIG_GLOB , CSS_GLOB , PACKAGE_LOCK_GLOB , TSCONFIG_GLOB } from './lib/constants'
@@ -321,9 +320,9 @@ export class TW {
321
320
let twVersion = require ( 'tailwindcss/package.json' ) . version
322
321
try {
323
322
let v = require (
324
- resolveFrom (
325
- path . dirname ( project . projectConfig . configPath ) ,
323
+ await resolver . resolveCjsId (
326
324
'tailwindcss/package.json' ,
325
+ path . dirname ( project . projectConfig . configPath ) ,
327
326
) ,
328
327
) . version
329
328
if ( typeof v === 'string' ) {
You can’t perform that action at this time.
0 commit comments