Skip to content

Commit

Permalink
improve text
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Jun 8, 2024
1 parent 6a9ab3b commit 9107d61
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions designs/0003-generate-d-ts-files-for-altcss.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,23 @@ For example, consider the following Sass files:

In this case, the tokens exported from `1.module.scss` are `foo` and `bar`.

Here, the tokens from `1.module.scss` are `foo` and `bar`.
Now, if `2.module.scss` is changed as follows:

If `happy-css-modules` is run with the `--cache` option, it needs to detect that `1.module.scss` should be reprocessed if `2.module.scss` changes. To achieve this, we need to implement a dependency graph that tracks the relationship between AltCSS files. When an AltCSS file is transpiled, its dependencies should be detected, and this information should be stored in the dependency graph. When a file changes, the dependency graph should be consulted to determine which files need to be reprocessed.
```scss
// 2.module.scss
.bar {
color: green;
}
.baz {
color: yellow;
}
```

The following pseudo-code demonstrates this:
In this case, the tokens exported from `1.module.scss` will be `foo`, `bar`, and `baz`. Therefore, even if `1.module.scss` itself has not been modified, the `happy-css-modules` command needs to regenerate the type definition file for `1.module.scss`.

```ts
import { watch } from 'chokidar';
const dependenciesGraph = new Map();
To achieve this, `happy-css-modules` will retrieve information about embedded files from the preprocessor. Here is the code:

```ts
async function readCSS(filePath: string): Promise<{ css: string; transpileDependencies: string[] }> {
const css = await readFile(filePath, 'utf-8');
const ext = path.extname(filePath);
Expand Down

0 comments on commit 9107d61

Please sign in to comment.