8000 refactor: renamed configs · Viijay-Kr/react-ts-css@8853bc9 · GitHub
Skip to content

Commit 8853bc9

Browse files
committed
refactor: renamed configs
1 parent c8bbc45 commit 8853bc9

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

examples/jsconfig-react/jsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": "./src",
3+
"baseUrl": ".",
44
"paths": {
5-
"standard/*": [
6-
"./styles/standard/*"
5+
"@standard/*": [
6+
"src/styles/standard/*"
77
]
88
}
99
},

examples/jsconfig-react/src/App.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useState } from "react";
22
import reactLogo from "./assets/react.svg";
33
import viteLogo from "/vite.svg";
44
import "./App.css";
5-
import styles from "standard/button.module.css";
6-
import rootStyles from 'styles/root.module.css';
7-
import rootStyles2 from 'styles/root2.module.css';
5+
import styles from "@standard/button.module.css";
6+
import rootStyles from 'src/styles/root.module.css';
7+
import rootStyles2 from 'src/styles/root2.module.css';
88

99

1010

src/parser/Parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import {
88
import path = require("path");
99
import { TS_MODULE_EXTENSIONS } from "../constants";
1010
import { normalizePath } from "../path-utils";
11-
import Store, { TsConfigMap } from "../store/Store";
11+
import Store, { TsJsConfigMap } from "../store/Store";
1212
import { parseCss } from "./v2/css";
1313
import { ParserResult, isCssModuleDeclaration, parseTypescript } from "./v2/ts";
1414

1515
type StyleIdentifier = Identifier["name"];
1616

1717
export type ParserContext = {
1818
workspaceRoot: string | undefined;
19-
tsConfig: TsConfigMap;
19+
tsConfig: TsJsConfigMap;
2020
baseDir: string | undefined;
2121
};
2222

src/store/Store.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { normalizePath } from "../path-utils";
1616
type CssModules = Map<string, string>;
1717
type TsModules = Map<string, string>;
1818

19-
export type TsConfig = {
19+
export type TsJsConfig = {
2020
compilerOptions: {
2121
baseUrl?: string;
2222
paths?: {
@@ -26,7 +26,7 @@ export type TsConfig = {
2626
baseDir: string;
2727
};
2828

29-
export type TsConfigMap = Map<string, TsConfig>;
29+
export type TsJsConfigMap = Map<string, TsJsConfig>;
3030

3131
export type IgnoreDiagnostis = Map<
3232
string, // Selector
@@ -41,7 +41,7 @@ export class Store {
4141
languages.createDiagnosticCollection("react-ts-css");
4242
protected diagnosticsProvider: DiagnosticsProvider | undefined;
4343
public ignoredDiagnostics: IgnoreDiagnostis = new Map();
44-
public tsConfig: TsConfigMap = new Map();
44+
public tsJsConfig: TsJsConfigMap = new Map();
4545
public tsModules: TsModules = new Map();
4646
public parser: Parser | undefined;
4747

@@ -123,7 +123,7 @@ export class Store {
123123
}
124124
}
125125

126-
private async saveTsConfigAutomatically() {
126+
private async saveTsJsConfig() {
127127
try {
128128
const configs = await fsg(
129129
[
@@ -151,12 +151,12 @@ export class Store {
151151
const _path = path.resolve(this.workSpaceRoot ?? "", config);
152152
const contents = (await fs_promises.readFile(_path)).toString();
153153
try {
154-
this.tsConfig.set(_path, {
154+
this.tsJsConfig.set(_path, {
155155
...JSON.parse(contents),
156156
baseDir: normalizePath(
157157
path.join(this.workSpaceRoot ?? "", path.dirname(config))
158158
),
159-
} as TsConfig);
159+
} as TsJsConfig);
160160
} catch (e) {
161161
console.error(e);
162162
}
@@ -188,7 +188,7 @@ export class Store {
188188
const activeFileDir = normalizePath(
189189
path.dirname(this.getActiveTextDocument().fileName)
190190
);
191-
for (const [, config] of this.tsConfig) {
191+
for (const [, config] of this.tsJsConfig) {
192192
if (activeFileDir.includes(config.baseDir)) {
193193
const alias = normalizePath(path.dirname(source));
194194
const module_name = path.basename(source);
@@ -208,10 +208,10 @@ export class Store {
208208
}
209209

210210
for (const [_path, values] of Object.entries(paths ?? {})) {
211-
const tsconfig_alias_path_dir = normalizePath(path.dirname(_path));
211+
const alias_dir_path = normalizePath(path.dirname(_path));
212212
let final_path = "";
213213
const alias_value = values[0].replace("*", "");
214-
if (alias === tsconfig_alias_path_dir) {
214+
if (alias === alias_dir_path) {
215215
final_path = normalizePath(
216216
path.join(
217217
config.baseDir,
@@ -220,12 +220,12 @@ export class Store {
220220
module_name
221221
)
222222
);
223-
} else if (alias.indexOf(tsconfig_alias_path_dir) === 0) {
223+
} else if (alias.indexOf(alias_dir_path) === 0) {
224224
final_path = normalizePath(
225225
path.join(
226226
config.baseDir,
227227
alias_value,
228-
alias.replace(tsconfig_alias_path_dir, ""),
228+
alias.replace(alias_dir_path, ""),
229229
module_name
230230
)
231231
);
@@ -262,12 +262,12 @@ export class Store {
262262
await this.experimental_setTsModules();
263263
}
264264

265-
await this.saveTsConfigAutomatically();
265+
await this.saveTsJsConfig();
266266

267267
if (!this.parser) {
268268
this.parser = new Parser({
269269
workspaceRoot: this.workSpaceRoot,
270-
tsConfig: this.tsConfig,
270+
tsConfig: this.tsJsConfig,
271271
baseDir: Settings.baseDir,
272272
});
273273
}
@@ -289,7 +289,7 @@ export class Store {
289289
*/
290290
public flushStorage() {
291291
this.workSpaceRoot = undefined;
292-
this.tsConfig = new Map();
292+
this.tsJsConfig = new Map();
293293
this.cssModules = new Map();
294294
}
295295

0 commit comments

Comments
 (0)