Skip to content

Commit 64ab286

Browse files
authored
Merge pull request #102 from willofindie/fix/issue-97-import-failures
[Fix] import error for incomplete node_module paths
2 parents 65f9f3a + 1dad502 commit 64ab286

File tree

9 files changed

+34
-5
lines changed

9 files changed

+34
-5
lines changed

TASKS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Doing this still shows `open-props/open-props.min.css` in the autocomplete/definition-provider list.
1616
- Support variable defaults syntax as well, like the following:
1717
- `color: var(--color, #333)`, this is a valid syntax.
18+
- `cssvar.enable` disables the extension entirely. It is not scoped for each root folder.
1819

1920

2021
## Notes:

examples/basics/local.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ body {
1414
.container {
1515
width: var(--container-size);
1616
padding: var(--container-padding);
17+
background-color: var(--test-custom-selector);
1718
}

examples/basics/theme.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@
1313
--container-padding: 1rem;
1414
}
1515
}
16+
17+
/* CSS with new at-rules */
18+
19+
@custom-selector :--root :root, :after, :before;
20+
21+
@layer variables {
22+
@layer colors {
23+
:--root {
24+
--test-custom-selector: rgba(17, 17, 17, 1);
25+
}
26+
}
27+
}

examples/css-imports/index.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
/* Following is very specific to webpack/react projects */
1111
/* I won't be supporting this in this extension, as a user can import */
1212
/* such css files from extension settings */
13-
/* @import '~open-props/open-props.min.css' */
13+
/* But's it's wise to ignore such imports */
14+
@import '~open-props/open-props.min.css';
15+
@import 'modern-normalize/modern-normalize.css';
1416

1517
@import url('node_modules/open-props/red.min.css') layer(utilities) print, screen;
1618

@@ -29,4 +31,5 @@ body {
2931
background-color: var(--c-blue);
3032
border-top-color: var(--orange-2);
3133
box-shadow: 0 0 3px 0 var(--violet-2);
34+
margin: var(--size-10);
3235
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:root {
2+
--pop: violet;
3+
--chop1: var(--pop);
4+
--chop2: var(--chop1);
5+
}
6+
7+
body {
8+
color: var(--chop2);
9+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"cssvar.postcssPlugins": [
33
// `cwd` option is required only if tokencss config is not declared directly under project root
4-
["@tokencss/postcss", { "cwd": "examples/tokencss-plugin/config" }]
4+
["@tokencss/postcss", { "cwd": "config" }]
55
]
66
}

examples/tokencss-plugin/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
body {
22
color: var(--color-red-2);
3+
background-color: var(--color-blue-4);
34
padding: var(--space-2xl);
45
}

src/parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ const parseFile = async function (
290290
}, {} as CSSVarLocation);
291291
}
292292
if (acceptedFile && !allLocalFiles.includes(acceptedFile.local)) {
293-
resolvedPaths.push(acceptedFile);
293+
if (Object.keys(acceptedFile).length !== 0) {
294+
resolvedPaths.push(acceptedFile);
295+
}
294296
}
295297
}
296298
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,11 @@ export async function postcssPluginResolver(
401401
const { lookupPaths, cwd, ...rest } = options;
402402
switch (name) {
403403
case "@tokencss/postcss": {
404-
if (!cwd || !existsSync(resolve(cwd, "token.config.json"))) {
404+
const _cwd = resolve(CACHE.activeRootPath, cwd);
405+
if (!cwd || !existsSync(resolve(_cwd, "token.config.json"))) {
405406
LOGGER.error("TokenCSS Config not found in: ", resolve(cwd));
406407
return null;
407408
}
408-
const _cwd = resolve(cwd);
409409
// VSCode/Electron does not support ESM modules, thus it becomes important to bundle them
410410
// with the code to make it work.
411411
try {

0 commit comments

Comments
 (0)