Skip to content

Commit fc21df7

Browse files
fix: support ES Module & Common JS
1 parent 67a6de7 commit fc21df7

2 files changed

Lines changed: 36 additions & 35 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
],
2424
"activationEvents": [
2525
"workspaceContains:tailwind.config.js",
26+
"workspaceContains:tailwind.config.cjs",
2627
"workspaceContains:tailwind.config.ts",
2728
"workspaceContains:windi.config.js",
29+
"workspaceContains:windi.config.cjs",
2830
"workspaceContains:windi.config.ts",
2931
"onLanguage:vue",
3032
"onLanguage:javascript",

src/lib/core.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { registerTS } from 'sucrase/dist/register';
88
import type { Core } from '../interfaces';
99
import { Log } from '../utils/Log';
1010

11-
export async function init():Promise<Core> {
11+
export async function init(): Promise<Core> {
1212
try {
1313
const files = await workspace.findFiles('{tailwind,windi}.config.{js,cjs,ts}', '**​/node_modules/**');
1414
let configFile;
@@ -22,7 +22,7 @@ export async function init():Promise<Core> {
2222
if (mod.default) config = mod.default;
2323
} else {
2424
delete require.cache[require.resolve(resolve(configFile))];
25-
config = require(resolve(configFile));
25+
config = import(resolve(configFile));
2626
}
2727
Log.info(`Loading Config File: ${configFile}`);
2828
}
@@ -42,53 +42,52 @@ export async function init():Promise<Core> {
4242
});
4343

4444
let staticCompletions = Object.keys(staticUtilities);
45-
const colorCompletions: {label: string, detail: string, documentation: string}[] = [];
46-
const dynamicCompletions: {label: string, position: number}[] = [];
45+
const colorCompletions: { label: string, detail: string, documentation: string }[] = [];
46+
const dynamicCompletions: { label: string, position: number }[] = [];
4747

4848
for (const [config, list] of Object.entries(dynamic)) {
4949
list.forEach(utility => {
5050
const mark = utility.search(/\$/);
5151
if (mark === -1) {
5252
staticCompletions.push(utility);
5353
} else {
54-
const prefix = utility.slice(0, mark-1);
54+
const prefix = utility.slice(0, mark - 1);
5555
const suffix = utility.slice(mark);
56-
switch(suffix) {
57-
case '${static}':
58-
const staticConfig = Object.keys(processor.theme(config, {}) as any);
59-
const complections = staticConfig.map(i => i === 'DEFAULT'? prefix : i.charAt(0) === '-' ? `-${prefix}${i}` : `${prefix}-${i}`);
60-
// if (config in negative) complections = complections.concat(complections.map(i => `-${i}`));
61-
staticCompletions = staticCompletions.concat(complections);
62-
break;
63-
case '${color}':
64-
const colorConfig = flatColors(processor.theme(config, colors) as any);
65-
for (const [k, v] of Object.entries(colorConfig)) {
66-
const name = `${prefix}-${k}`;
67-
const color = Array.isArray(v) ? v[0] : v;
68-
colorCompletions.push({
69-
label: name,
70-
detail: processor.interpret(name).styleSheet.build(),
71-
documentation: ['transparent', 'currentColor'].includes(color) ? color: `rgb(${hex2RGB(color)?.join(', ')})`,
72-
});
73-
}
74-
break;
75-
default:
76-
dynamicCompletions.push({
77-
label: utility,
78-
position: utility.length - mark,
79-
});
80-
if (config in negative) {
56+
switch (suffix) {
57+
case '${static}':
58+
const staticConfig = Object.keys(processor.theme(config, {}) as any);
59+
const complections = staticConfig.map(i => i === 'DEFAULT' ? prefix : i.charAt(0) === '-' ? `-${prefix}${i}` : `${prefix}-${i}`);
60+
// if (config in negative) complections = complections.concat(complections.map(i => `-${i}`));
61+
staticCompletions = staticCompletions.concat(complections);
62+
break;
63+
case '${color}':
64+
const colorConfig = flatColors(processor.theme(config, colors) as any);
65+
for (const [k, v] of Object.entries(colorConfig)) {
66+
const name = `${prefix}-${k}`;
67+
const color = Array.isArray(v) ? v[0] : v;
68+
colorCompletions.push({
69+
label: name,
70+
detail: processor.interpret(name).styleSheet.build(),
71+
documentation: ['transparent', 'currentColor'].includes(color) ? color : `rgb(${hex2RGB(color)?.join(', ')})`,
72+
});
73+
}
74+
break;
75+
default:
8176
dynamicCompletions.push({
82-
label: `-${utility}`,
83-
position: utility.length + 1 - mark,
77+
label: utility,
78+
position: utility.length - mark,
8479
});
85-
}
86-
break;
80+
if (config in negative) {
81+
dynamicCompletions.push({
82+
label: `-${utility}`,
83+
position: utility.length + 1 - mark,
84+
});
85+
}
86+
break;
8787
}
8888
}
8989
});
9090
}
91-
9291
return {
9392
processor,
9493
colors,

0 commit comments

Comments
 (0)