Skip to content

Commit

Permalink
fix: 🐛 tailwind config ignored when extension config enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Sep 21, 2022
1 parent 1820ad4 commit faa113d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import ignore from "ignore";
import { Formatter } from "blade-formatter";
import { setExtensionContext } from './extensionContext';
import { telemetry, TelemetryEventNames } from './telemetry';
import { findConfigFile, readRuntimeConfig } from './runtimeConfig';
import { readRuntimeConfig } from './runtimeConfig';
import { ExtensionConstants } from "./constants";
import { messages } from "./messages";
import { formatFromCommand } from "./commands";
import { getCoreNodeModule, requireUncached } from "./util";
import { resolveTailwindConfig } from "./tailwind";
import { resolveTailwindConfig, TailwindConfig } from "./tailwind";

const { Range, Position } = vscode;
const vsctmModule = getCoreNodeModule("vscode-textmate");
Expand Down Expand Up @@ -73,16 +73,18 @@ export function activate(context: ExtensionContext) {

const runtimeConfig = readRuntimeConfig(document.uri.fsPath);

if (runtimeConfig?.sortTailwindcssClasses) {
const tailwindConfig: TailwindConfig = {};

if (runtimeConfig?.sortTailwindcssClasses || extConfig.sortTailwindcssClasses) {
const tailwindConfigPath = resolveTailwindConfig(document.uri.fsPath, runtimeConfig?.tailwindcssConfigPath ?? '');
runtimeConfig.tailwindcssConfigPath = tailwindConfigPath;
tailwindConfig.tailwindcssConfigPath = tailwindConfigPath;

try {
requireUncached(tailwindConfigPath);
} catch (error) {
// @ts-ignore
// fallback to default config
runtimeConfig.tailwindcssConfigPath = __non_webpack_require__.resolve('tailwindcss/lib/public/default-config');
tailwindConfig.tailwindcssConfigPath = __non_webpack_require__.resolve('tailwindcss/lib/public/default-config');
}
}

Expand All @@ -97,6 +99,7 @@ export function activate(context: ExtensionContext) {
sortHtmlAttributes: extConfig.sortHtmlAttributes ?? 'none',
noMultipleEmptyLines: extConfig.noMultipleEmptyLines,
...runtimeConfig, // override all settings by runtime config
...tailwindConfig,
};

const progressMessage = isLargeFile(document) ? messages.largeFileFormattingMessage : messages.formattingMessage;
Expand Down
5 changes: 5 additions & 0 deletions src/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { requireUncached } from './util';

const __config__ = 'tailwind.config.js';

export type TailwindConfig = {
tailwindcssConfigPath?: string,
tailwindcssConfig?: object,
};

/**
* Resolve tailwind config path if resolvable
*
Expand Down

0 comments on commit faa113d

Please sign in to comment.