Skip to content

Commit 7ec8d04

Browse files
authored
Merge pull request #74 from mr150/fix/windows-issues
Fix Windows issues
2 parents 2762c36 + 9b81d9b commit 7ec8d04

File tree

8 files changed

+40
-12
lines changed

8 files changed

+40
-12
lines changed

docs/homepage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Addons may contains any tools, settings and styles. Addons now at the **preview*
171171
## Articles ##
172172
- Atomic CSS Deep Dive: [EN](https://dev.to/mr150/atomic-css-deep-dive-1hee), [RU](https://habr.com/ru/articles/833712/)
173173
- [mlut - a new word in the Utility-First CSS approach](https://dev.to/mr150/mlut-a-new-word-in-the-utility-first-css-approach-gbl)
174+
- How to make one plugin for all frontend bundlers at once: [RU](https://habr.com/ru/articles/856028/)
174175

175176
</section>
176177

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mlut/core",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Atomic CSS toolkit with Sass and ergonomics for creating styles of any complexity",
55
"author": "mr150",
66
"type": "module",

packages/core/src/jit/JitEngine.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23

34
import { logger } from '../utils/index.js';
45

@@ -10,7 +11,7 @@ const sass = await import('sass-embedded')
1011
);
1112
});
1213

13-
const __dirname = new URL('.', import.meta.url).pathname;
14+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1415

1516
export class JitEngine {
1617
private utils = new Set<string>();
@@ -29,6 +30,7 @@ export class JitEngine {
2930
utilName: /^-?[A-Z]{1}[a-zA-Z]*/,
3031
uppercaseLetter: /[A-Z]/,
3132
contextUtil: /-Ctx([\d\-#]|$)/,
33+
valueSeparator: /[0-9-#=]/,
3234
};
3335
private readonly configRegexps = {
3436
userSettings: /@use ['"][^'"]*(tools|mlut|core)['"](\s*as\s+[\w]+)?\s+with\s*\(([^;]+)\);/s,
@@ -122,6 +124,12 @@ export class JitEngine {
122124
));
123125

124126
if (utility) {
127+
const separator = utility.replace(this.utilsRegexps.utilName, '')[0];
128+
129+
if (separator && !this.utilsRegexps.valueSeparator.test(separator)) {
130+
return acc;
131+
}
132+
125133
const utilName = utility.match(this.utilsRegexps.utilName)?.[0] as string;
126134

127135
if (

packages/mlut/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Available [here](https://mr150.github.io/mlut/) or can be run locally. Documenta
276276
## Articles ##
277277
- Atomic CSS Deep Dive: [EN](https://dev.to/mr150/atomic-css-deep-dive-1hee), [RU](https://habr.com/ru/articles/833712/)
278278
- [mlut - a new word in the Utility-First CSS approach](https://dev.to/mr150/mlut-a-new-word-in-the-utility-first-css-approach-gbl)
279+
- How to make one plugin for all frontend bundlers at once: [RU](https://habr.com/ru/articles/856028/)
279280

280281
## What next? ##
281282
- first class CSS functions in utilities values

packages/plugins/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mlut/plugins",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "mlut plugins for Rollup, Vite and Webpack",
55
"author": "mr150",
66
"type": "module",

packages/plugins/src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
2424
const cwd = process.cwd();
2525
const pluginName = 'unplugin-mlut';
2626
const finalOptions: Options = { output: '' };
27-
const inputPath = options.input && path.resolve(cwd, options.input);
27+
let inputPath = options.input && path.resolve(cwd, options.input);
2828
let outputPath = '';
29+
let viteWatchOutputPath = '';
2930
let lastCompiledCss = '';
3031
const isWebpack = meta.framework === 'webpack';
32+
const isWindows = process.platform === 'win32';
3133
let isVite = false;
3234
let isViteWatch = false;
3335

@@ -84,6 +86,13 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
8486
outputPath = path.resolve(cwd, finalOptions.output);
8587

8688
if (isViteWatch) {
89+
if (isWindows) {
90+
viteWatchOutputPath = path.isAbsolute(finalOptions.output) ?
91+
finalOptions.output.replace(cwd, '') : finalOptions.output;
92+
} else {
93+
viteWatchOutputPath = outputPath;
94+
}
95+
8796
await fs.outputFile(outputPath, '').catch(() => undefined);
8897
}
8998
};
@@ -95,6 +104,7 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
95104
// TODO: add the Vite types
96105
async config(_config: unknown, { command }: { command: string }) {
97106
isVite = true;
107+
inputPath = inputPath?.replaceAll('\\', '/');
98108

99109
if (command === 'serve') {
100110
isViteWatch = true;
@@ -149,6 +159,11 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
149159

150160
transform(code, id) {
151161
jitEngine.putContent(id, code);
162+
163+
if (isViteWatch) {
164+
debouncedWriteCssFile();
165+
}
166+
152167
return null;
153168
},
154169

@@ -164,7 +179,7 @@ export const unplugin = createUnplugin<Options>((options, meta) => {
164179
tags: [
165180
{
166181
tag: 'link',
167-
attrs: { rel: 'stylesheet', href: outputPath },
182+
attrs: { rel: 'stylesheet', href: viteWatchOutputPath },
168183
},
169184
],
170185
};

test/jit/JitEngine.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23
import { assert } from 'chai';
34
import { JitEngine } from '../../packages/core/src/jit/JitEngine.js';
45

5-
const __dirname = new URL('.', import.meta.url).pathname;
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
67

78
describe('JitEngine', () => {
89
const htmlContent0 = '<div class="P1r">000</div>';
@@ -45,11 +46,13 @@ md_Gc-s1 Pb6u Ps Lol5 md_Mxh130vh Ps
4546
Lorem \`Ipsum\`
4647
</div>
4748
49+
<style type="text/css" data-vite-dev-id="C:/Users/mister/Documents/web/ptoject/src/App.vue?vue&amp;type=style">
50+
4851
const myStr = "simpl'e text" + ' testou' + "" + "[email protected]";
49-
const wrapperCss = "M1u -Myvar12 \\"Ps\\" d-g";
52+
const wrapperCss = "M1u -Myvar=block \\"Ps\\" d-g";
5053
5154
<MyComponent className={cn('D-f \\'Gap5u', wrapperCss)}/>
52-
` + "\n<button className={`D-ib ${flag ? 'Bgc-red' : ''}`}>Clear</div>";
55+
` + "\n<button className={`D-ib ${flag ? 'Bgc#f00' : ''}`}>Clear</div>";
5356
/* eslint-enable */
5457

5558
it('extract utils from the content', async () => {
@@ -71,10 +74,10 @@ const wrapperCss = "M1u -Myvar12 \\"Ps\\" d-g";
7174
//eslint-disable-next-line
7275
"Ct-'id:';attr(id)_b",
7376
'M1u',
74-
'-Myvar12',
77+
'-Myvar=block',
7578
'D-f',
7679
'Gap5u',
77-
'Bgc-red',
80+
'Bgc#f00',
7881
'D-ib',
7982
],
8083
);

0 commit comments

Comments
 (0)