@css-modules-kit/core 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +20 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -58
- package/dist/config.js.map +1 -1
- package/dist/dts-creator.d.ts +1 -0
- package/dist/dts-creator.d.ts.map +1 -1
- package/dist/dts-creator.js +7 -9
- package/dist/dts-creator.js.map +1 -1
- package/dist/parser/location.d.ts.map +1 -1
- package/dist/parser/location.js.map +1 -1
- package/dist/resolver.d.ts +2 -1
- package/dist/resolver.d.ts.map +1 -1
- package/dist/resolver.js +2 -2
- package/dist/resolver.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +41 -65
- package/src/dts-creator.ts +7 -9
- package/src/parser/location.ts +0 -3
- package/src/resolver.ts +3 -2
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
1
2
|
import type { SemanticDiagnostic } from './diagnostic.js';
|
|
2
3
|
type RemoveUndefined<T> = {
|
|
3
4
|
[K in keyof T]: Exclude<T[K], undefined>;
|
|
@@ -9,7 +10,6 @@ type RemoveUndefined<T> = {
|
|
|
9
10
|
export interface CMKConfig {
|
|
10
11
|
includes: string[];
|
|
11
12
|
excludes: string[];
|
|
12
|
-
paths: Record<string, string[]>;
|
|
13
13
|
dtsOutDir: string;
|
|
14
14
|
arbitraryExtensions: boolean;
|
|
15
15
|
/**
|
|
@@ -51,17 +51,17 @@ export interface CMKConfig {
|
|
|
51
51
|
*/
|
|
52
52
|
basePath: string;
|
|
53
53
|
configFileName: string;
|
|
54
|
+
compilerOptions: ts.CompilerOptions;
|
|
54
55
|
/** The diagnostics that occurred while reading the config file. */
|
|
55
56
|
diagnostics: SemanticDiagnostic[];
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
|
-
* The config loaded from `
|
|
59
|
+
* The config loaded from `ts.ParsedCommandLine['raw']`.
|
|
59
60
|
* This is unnormalized. Paths are relative, and some options may be omitted.
|
|
60
61
|
*/
|
|
61
|
-
interface
|
|
62
|
+
interface UnnormalizedRawConfig {
|
|
62
63
|
includes: string[] | undefined;
|
|
63
64
|
excludes: string[] | undefined;
|
|
64
|
-
paths: Record<string, string[]> | undefined;
|
|
65
65
|
dtsOutDir: string | undefined;
|
|
66
66
|
arbitraryExtensions: boolean | undefined;
|
|
67
67
|
}
|
|
@@ -69,11 +69,26 @@ interface UnnormalizedCMKConfig {
|
|
|
69
69
|
* The validated data of `ts.ParsedCommandLine['raw']`.
|
|
70
70
|
*/
|
|
71
71
|
interface ParsedRawData {
|
|
72
|
-
config:
|
|
72
|
+
config: UnnormalizedRawConfig;
|
|
73
73
|
diagnostics: SemanticDiagnostic[];
|
|
74
74
|
}
|
|
75
|
+
export declare function findTsConfigFile(project: string): string | undefined;
|
|
75
76
|
declare function parseRawData(raw: unknown, configFileName: string): ParsedRawData;
|
|
76
77
|
export { parseRawData as parseRawDataForTest };
|
|
78
|
+
/**
|
|
79
|
+
* @throws {TsConfigFileNotFoundError}
|
|
80
|
+
*/
|
|
81
|
+
export declare function readTsConfigFile(project: string): {
|
|
82
|
+
configFileName: string;
|
|
83
|
+
config: UnnormalizedRawConfig;
|
|
84
|
+
compilerOptions: ts.CompilerOptions;
|
|
85
|
+
diagnostics: SemanticDiagnostic[];
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Normalize `UnnormalizedRawConfig`. Resolve relative paths to absolute paths, and set default values for missing options.
|
|
89
|
+
* @param basePath A root directory to resolve relative path entries in the config file to.
|
|
90
|
+
*/
|
|
91
|
+
export declare function normalizeConfig(config: UnnormalizedRawConfig, basePath: string): RemoveUndefined<UnnormalizedRawConfig>;
|
|
77
92
|
/**
|
|
78
93
|
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
79
94
|
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
|
@@ -83,16 +98,4 @@ export { parseRawData as parseRawDataForTest };
|
|
|
83
98
|
* @throws {TsConfigFileNotFoundError}
|
|
84
99
|
*/
|
|
85
100
|
export declare function readConfigFile(project: string): CMKConfig;
|
|
86
|
-
export declare function findTsConfigFile(project: string): string | undefined;
|
|
87
|
-
/**
|
|
88
|
-
* @throws {TsConfigFileNotFoundError}
|
|
89
|
-
*/
|
|
90
|
-
export declare function readTsConfigFile(project: string): {
|
|
91
|
-
configFileName: string;
|
|
92
|
-
} & ParsedRawData;
|
|
93
|
-
/**
|
|
94
|
-
* Normalize the config. Resolve relative paths to absolute paths, and set default values for missing options.
|
|
95
|
-
* @param basePath A root directory to resolve relative path entries in the config file to.
|
|
96
|
-
*/
|
|
97
|
-
export declare function normalizeConfig(config: UnnormalizedCMKConfig, basePath: string): RemoveUndefined<UnnormalizedCMKConfig>;
|
|
98
101
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAO1D,KAAK,eAAe,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC;CACzC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,OAAO,CAAC;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC;IACpC,mEAAmE;IACnE,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC;AAED;;;GAGG;AACH,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,mBAAmB,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,UAAU,aAAa;IACrB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOpE;AAED,iBAAS,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,aAAa,CAwDzE;AACD,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,CAAC;AAa/C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC;IACpC,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,CAgDA;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,EAAE,MAAM,GACf,eAAe,CAAC,qBAAqB,CAAC,CASxC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAUzD"}
|
package/dist/config.js
CHANGED
|
@@ -3,23 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseRawDataForTest = parseRawData;
|
|
7
|
-
exports.readConfigFile = readConfigFile;
|
|
8
6
|
exports.findTsConfigFile = findTsConfigFile;
|
|
7
|
+
exports.parseRawDataForTest = parseRawData;
|
|
9
8
|
exports.readTsConfigFile = readTsConfigFile;
|
|
10
9
|
exports.normalizeConfig = normalizeConfig;
|
|
10
|
+
exports.readConfigFile = readConfigFile;
|
|
11
11
|
const typescript_1 = __importDefault(require("typescript"));
|
|
12
12
|
const error_js_1 = require("./error.js");
|
|
13
13
|
const path_js_1 = require("./path.js");
|
|
14
14
|
// https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3006
|
|
15
15
|
const DEFAULT_INCLUDE_SPEC = '**/*';
|
|
16
|
-
|
|
16
|
+
function findTsConfigFile(project) {
|
|
17
|
+
const configFile = typescript_1.default.sys.directoryExists(project) ?
|
|
18
|
+
typescript_1.default.findConfigFile(project, typescript_1.default.sys.fileExists.bind(typescript_1.default.sys), 'tsconfig.json')
|
|
19
|
+
: typescript_1.default.findConfigFile((0, path_js_1.dirname)(project), typescript_1.default.sys.fileExists.bind(typescript_1.default.sys), (0, path_js_1.basename)(project));
|
|
20
|
+
if (!configFile)
|
|
21
|
+
return undefined;
|
|
22
|
+
return (0, path_js_1.resolve)(configFile);
|
|
23
|
+
}
|
|
17
24
|
function parseRawData(raw, configFileName) {
|
|
18
25
|
const result = {
|
|
19
26
|
config: {
|
|
20
27
|
includes: undefined,
|
|
21
28
|
excludes: undefined,
|
|
22
|
-
paths: undefined,
|
|
23
29
|
dtsOutDir: undefined,
|
|
24
30
|
arbitraryExtensions: undefined,
|
|
25
31
|
},
|
|
@@ -43,21 +49,6 @@ function parseRawData(raw, configFileName) {
|
|
|
43
49
|
}
|
|
44
50
|
// MEMO: The errors for this option are reported by `tsc` or `tsserver`, so we don't need to report.
|
|
45
51
|
}
|
|
46
|
-
if ('compilerOptions' in raw && typeof raw.compilerOptions === 'object' && raw.compilerOptions !== null) {
|
|
47
|
-
if ('paths' in raw.compilerOptions) {
|
|
48
|
-
if (typeof raw.compilerOptions.paths === 'object' && raw.compilerOptions.paths !== null) {
|
|
49
|
-
const paths = {};
|
|
50
|
-
for (const [key, value] of Object.entries(raw.compilerOptions.paths)) {
|
|
51
|
-
if (Array.isArray(value)) {
|
|
52
|
-
const resolvedValue = value.filter((v) => typeof v === 'string');
|
|
53
|
-
paths[key] = resolvedValue;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
result.config.paths = paths;
|
|
57
|
-
}
|
|
58
|
-
// MEMO: The errors for this option are reported by `tsc` or `tsserver`, so we don't need to report.
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
52
|
if ('cmkOptions' in raw && typeof raw.cmkOptions === 'object' && raw.cmkOptions !== null) {
|
|
62
53
|
if ('dtsOutDir' in raw.cmkOptions) {
|
|
63
54
|
if (typeof raw.cmkOptions.dtsOutDir === 'string') {
|
|
@@ -88,40 +79,12 @@ function parseRawData(raw, configFileName) {
|
|
|
88
79
|
}
|
|
89
80
|
return result;
|
|
90
81
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
93
|
-
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
|
94
|
-
* this function attempts to parse as much as possible and still returns a valid config.
|
|
95
|
-
*
|
|
96
|
-
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
97
|
-
* @throws {TsConfigFileNotFoundError}
|
|
98
|
-
*/
|
|
99
|
-
function readConfigFile(project) {
|
|
100
|
-
const { configFileName, config, diagnostics } = readTsConfigFile(project);
|
|
101
|
-
const basePath = (0, path_js_1.dirname)(configFileName);
|
|
102
|
-
return {
|
|
103
|
-
...normalizeConfig(config, basePath),
|
|
104
|
-
basePath,
|
|
105
|
-
configFileName,
|
|
106
|
-
diagnostics,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
function findTsConfigFile(project) {
|
|
110
|
-
const configFile = typescript_1.default.sys.directoryExists(project) ?
|
|
111
|
-
typescript_1.default.findConfigFile(project, typescript_1.default.sys.fileExists.bind(typescript_1.default.sys), 'tsconfig.json')
|
|
112
|
-
: typescript_1.default.findConfigFile((0, path_js_1.dirname)(project), typescript_1.default.sys.fileExists.bind(typescript_1.default.sys), (0, path_js_1.basename)(project));
|
|
113
|
-
if (!configFile)
|
|
114
|
-
return undefined;
|
|
115
|
-
return (0, path_js_1.resolve)(configFile);
|
|
116
|
-
}
|
|
117
82
|
function mergeParsedRawData(base, overrides) {
|
|
118
83
|
const result = { config: { ...base.config }, diagnostics: [...base.diagnostics] };
|
|
119
84
|
if (overrides.config.includes !== undefined)
|
|
120
85
|
result.config.includes = overrides.config.includes;
|
|
121
86
|
if (overrides.config.excludes !== undefined)
|
|
122
87
|
result.config.excludes = overrides.config.excludes;
|
|
123
|
-
if (overrides.config.paths !== undefined)
|
|
124
|
-
result.config.paths = overrides.config.paths;
|
|
125
88
|
if (overrides.config.dtsOutDir !== undefined)
|
|
126
89
|
result.config.dtsOutDir = overrides.config.dtsOutDir;
|
|
127
90
|
if (overrides.config.arbitraryExtensions !== undefined)
|
|
@@ -168,20 +131,12 @@ function readTsConfigFile(project) {
|
|
|
168
131
|
}
|
|
169
132
|
return {
|
|
170
133
|
configFileName,
|
|
134
|
+
compilerOptions: parsedCommandLine.options,
|
|
171
135
|
...parsedRawData,
|
|
172
136
|
};
|
|
173
137
|
}
|
|
174
|
-
function resolvePaths(paths, cwd) {
|
|
175
|
-
if (paths === undefined)
|
|
176
|
-
return {};
|
|
177
|
-
const resolvedPaths = {};
|
|
178
|
-
for (const [key, value] of Object.entries(paths)) {
|
|
179
|
-
resolvedPaths[key] = value.map((path) => (0, path_js_1.join)(cwd, path));
|
|
180
|
-
}
|
|
181
|
-
return resolvedPaths;
|
|
182
|
-
}
|
|
183
138
|
/**
|
|
184
|
-
* Normalize
|
|
139
|
+
* Normalize `UnnormalizedRawConfig`. Resolve relative paths to absolute paths, and set default values for missing options.
|
|
185
140
|
* @param basePath A root directory to resolve relative path entries in the config file to.
|
|
186
141
|
*/
|
|
187
142
|
function normalizeConfig(config, basePath) {
|
|
@@ -190,9 +145,27 @@ function normalizeConfig(config, basePath) {
|
|
|
190
145
|
// ref: https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3102
|
|
191
146
|
includes: (config.includes ?? [DEFAULT_INCLUDE_SPEC]).map((i) => (0, path_js_1.join)(basePath, i)),
|
|
192
147
|
excludes: (config.excludes ?? []).map((e) => (0, path_js_1.join)(basePath, e)),
|
|
193
|
-
paths: resolvePaths(config.paths, basePath),
|
|
194
148
|
dtsOutDir: (0, path_js_1.join)(basePath, config.dtsOutDir ?? 'generated'),
|
|
195
149
|
arbitraryExtensions: config.arbitraryExtensions ?? false,
|
|
196
150
|
};
|
|
197
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
154
|
+
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
|
155
|
+
* this function attempts to parse as much as possible and still returns a valid config.
|
|
156
|
+
*
|
|
157
|
+
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
158
|
+
* @throws {TsConfigFileNotFoundError}
|
|
159
|
+
*/
|
|
160
|
+
function readConfigFile(project) {
|
|
161
|
+
const { configFileName, config, compilerOptions, diagnostics } = readTsConfigFile(project);
|
|
162
|
+
const basePath = (0, path_js_1.dirname)(configFileName);
|
|
163
|
+
return {
|
|
164
|
+
...normalizeConfig(config, basePath),
|
|
165
|
+
basePath,
|
|
166
|
+
configFileName,
|
|
167
|
+
compilerOptions,
|
|
168
|
+
diagnostics,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
198
171
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AAoFA,4CAOC;AA2DwB,2CAAmB;AAgB5C,4CAqDC;AAMD,0CAYC;AAUD,wCAUC;AAjQD,4DAA4B;AAE5B,yCAAuD;AACvD,uCAA6D;AAE7D,gIAAgI;AAChI,MAAM,oBAAoB,GAAG,MAAM,CAAC;AA8EpC,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,MAAM,UAAU,GACd,oBAAE,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/B,oBAAE,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,oBAAE,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC;QAC7E,CAAC,CAAC,oBAAE,CAAC,cAAc,CAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,EAAE,oBAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,oBAAE,CAAC,GAAG,CAAC,EAAE,IAAA,kBAAQ,EAAC,OAAO,CAAC,CAAC,CAAC;IAC3F,IAAI,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IAClC,OAAO,IAAA,iBAAO,EAAC,UAAU,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,YAAY,CAAC,GAAY,EAAE,cAAsB;IACxD,MAAM,MAAM,GAAkB;QAC5B,MAAM,EAAE;YACN,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,SAAS;YACpB,mBAAmB,EAAE,SAAS;SAC/B;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;IACF,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IA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","sourceRoot":"","sources":["../src/dts-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,UAAU,WAAW;IACnB,iEAAiE;IACjE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,8DAA8D;IAC9D,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,8CAA8C;AAE9C,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,iDAAiD;IACjD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iDAAiD;IACjD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED
|
|
1
|
+
{"version":3,"file":"dts-creator.d.ts","sourceRoot":"","sources":["../src/dts-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,UAAU,WAAW;IACnB,iEAAiE;IACjE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,8DAA8D;IAC9D,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,8CAA8C;AAE9C,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,iDAAiD;IACjD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iDAAiD;IACjD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CACvB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,EAAE,SAAS,EACrE,OAAO,EAAE,gBAAgB,GACxB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAC;IAAC,iBAAiB,EAAE,iBAAiB,CAAA;CAAE,CAkE9E"}
|
package/dist/dts-creator.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.STYLES_EXPORT_NAME = 'styles';
|
|
|
15
15
|
* ```
|
|
16
16
|
* The d.ts file would be:
|
|
17
17
|
* ```ts
|
|
18
|
+
* // @ts-nocheck
|
|
18
19
|
* const styles = {
|
|
19
20
|
* local1: '' as readonly string,
|
|
20
21
|
* local2: '' as readonly string,
|
|
@@ -38,15 +39,12 @@ function createDts({ fileName, localTokens, tokenImporters: _tokenImporters }, o
|
|
|
38
39
|
const resolved = options.resolver(tokenImporter.from, { request: fileName });
|
|
39
40
|
return resolved !== undefined && options.matchesPattern(resolved);
|
|
40
41
|
});
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
let text = `declare const ${exports.STYLES_EXPORT_NAME} = {\n`;
|
|
42
|
+
// MEMO: Depending on the TypeScript compilation options, the generated type definition file contains compile errors.
|
|
43
|
+
// For example, it contains `Top-level 'await' expressions are only allowed when the 'module' option is set to ...` error.
|
|
44
|
+
//
|
|
45
|
+
// If `--skipLibCheck` is false, those errors will be reported by `tsc`. However, these are negligible errors.
|
|
46
|
+
// Therefore, `@ts-nocheck` is added to the generated type definition file.
|
|
47
|
+
let text = `// @ts-nocheck\ndeclare const ${exports.STYLES_EXPORT_NAME} = {\n`;
|
|
50
48
|
for (const token of localTokens) {
|
|
51
49
|
text += ` `;
|
|
52
50
|
mapping.sourceOffsets.push(token.loc.start.offset);
|
package/dist/dts-creator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dts-creator.js","sourceRoot":"","sources":["../src/dts-creator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"dts-creator.js","sourceRoot":"","sources":["../src/dts-creator.ts"],"names":[],"mappings":";;;AAwDA,8BAqEC;AAzHY,QAAA,kBAAkB,GAAG,QAAQ,CAAC;AA6B3C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,SAAS,CACvB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAa,EACrE,OAAyB;IAEzB,MAAM,OAAO,GAAgB,EAAE,aAAa,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC;IACtF,MAAM,iBAAiB,GAAsB;QAC3C,aAAa,EAAE,EAAE;QACjB,OAAO,EAAE,EAAE;QACX,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE;KACrB,CAAC;IAEF,wBAAwB;IACxB,MAAM,cAAc,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,EAAE;QAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE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gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC3C,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACrD,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC3D,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,CAAC;YAC7B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,IAAI,IAAI,sBAAsB,0BAAkB,KAAK,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/parser/location.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,cAAc,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACvB;;;OAGG;
|
|
1
|
+
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/parser/location.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,cAAc,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,KAAK,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,GAAG,EAAE,QAAQ,CAAC;CACf;AAED,wBAAgB,4CAA4C,CAC1D,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,cAAc,CAAC,IAAI,GACxB;IAAE,KAAK,EAAE,kBAAkB,CAAC;IAAC,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAIxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.js","sourceRoot":"","sources":["../../src/parser/location.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"location.js","sourceRoot":"","sources":["../../src/parser/location.ts"],"names":[],"mappings":";;AAgCA,oGAOC;AAPD,SAAgB,4CAA4C,CAC1D,IAAU,EACV,IAAyB;IAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;IAClF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/resolver.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CompilerOptions } from 'typescript';
|
|
1
2
|
export interface ResolverOptions {
|
|
2
3
|
/** The file that imports the specifier. It is a absolute path. */
|
|
3
4
|
request: string;
|
|
@@ -9,5 +10,5 @@ export interface ResolverOptions {
|
|
|
9
10
|
* @returns The resolved import specifier. It is a absolute path. If the import specifier cannot be resolved, return `undefined`.
|
|
10
11
|
*/
|
|
11
12
|
export type Resolver = (specifier: string, options: ResolverOptions) => string | undefined;
|
|
12
|
-
export declare function createResolver(
|
|
13
|
+
export declare function createResolver(compilerOptions: CompilerOptions): Resolver;
|
|
13
14
|
//# sourceMappingURL=resolver.d.ts.map
|
package/dist/resolver.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,MAAM,GAAG,SAAS,CAAC;AAE3F,wBAAgB,cAAc,CAAC,eAAe,EAAE,eAAe,GAAG,QAAQ,CA+BzE"}
|
package/dist/resolver.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.createResolver = createResolver;
|
|
|
7
7
|
const node_url_1 = require("node:url");
|
|
8
8
|
const typescript_1 = __importDefault(require("typescript"));
|
|
9
9
|
const path_js_1 = require("./path.js");
|
|
10
|
-
function createResolver(
|
|
10
|
+
function createResolver(compilerOptions) {
|
|
11
11
|
return (_specifier, options) => {
|
|
12
12
|
let specifier = _specifier;
|
|
13
13
|
const host = {
|
|
@@ -19,7 +19,7 @@ function createResolver(paths) {
|
|
|
19
19
|
return typescript_1.default.sys.fileExists(fileName);
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
|
-
const { resolvedModule } = typescript_1.default.resolveModuleName(specifier, options.request,
|
|
22
|
+
const { resolvedModule } = typescript_1.default.resolveModuleName(specifier, options.request, compilerOptions, host);
|
|
23
23
|
if (resolvedModule) {
|
|
24
24
|
// TODO: Logging that the paths is used.
|
|
25
25
|
specifier = resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
|
package/dist/resolver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.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,EAAE,IAAA,wBAAa,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACzF,CAAC;aAAM,CAAC;YACN,wCAAwC;YACxC,sDAAsD;YACtD,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,SAAiB;IAC5C,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -17,7 +17,6 @@ type RemoveUndefined<T> = {
|
|
|
17
17
|
export interface CMKConfig {
|
|
18
18
|
includes: string[];
|
|
19
19
|
excludes: string[];
|
|
20
|
-
paths: Record<string, string[]>;
|
|
21
20
|
dtsOutDir: string;
|
|
22
21
|
arbitraryExtensions: boolean;
|
|
23
22
|
/**
|
|
@@ -59,18 +58,18 @@ export interface CMKConfig {
|
|
|
59
58
|
*/
|
|
60
59
|
basePath: string;
|
|
61
60
|
configFileName: string;
|
|
61
|
+
compilerOptions: ts.CompilerOptions;
|
|
62
62
|
/** The diagnostics that occurred while reading the config file. */
|
|
63
63
|
diagnostics: SemanticDiagnostic[];
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* The config loaded from `
|
|
67
|
+
* The config loaded from `ts.ParsedCommandLine['raw']`.
|
|
68
68
|
* This is unnormalized. Paths are relative, and some options may be omitted.
|
|
69
69
|
*/
|
|
70
|
-
interface
|
|
70
|
+
interface UnnormalizedRawConfig {
|
|
71
71
|
includes: string[] | undefined;
|
|
72
72
|
excludes: string[] | undefined;
|
|
73
|
-
paths: Record<string, string[]> | undefined;
|
|
74
73
|
dtsOutDir: string | undefined;
|
|
75
74
|
arbitraryExtensions: boolean | undefined;
|
|
76
75
|
}
|
|
@@ -79,17 +78,24 @@ interface UnnormalizedCMKConfig {
|
|
|
79
78
|
* The validated data of `ts.ParsedCommandLine['raw']`.
|
|
80
79
|
*/
|
|
81
80
|
interface ParsedRawData {
|
|
82
|
-
config:
|
|
81
|
+
config: UnnormalizedRawConfig;
|
|
83
82
|
diagnostics: SemanticDiagnostic[];
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
export function findTsConfigFile(project: string): string | undefined {
|
|
86
|
+
const configFile =
|
|
87
|
+
ts.sys.directoryExists(project) ?
|
|
88
|
+
ts.findConfigFile(project, ts.sys.fileExists.bind(ts.sys), 'tsconfig.json')
|
|
89
|
+
: ts.findConfigFile(dirname(project), ts.sys.fileExists.bind(ts.sys), basename(project));
|
|
90
|
+
if (!configFile) return undefined;
|
|
91
|
+
return resolve(configFile);
|
|
92
|
+
}
|
|
93
|
+
|
|
87
94
|
function parseRawData(raw: unknown, configFileName: string): ParsedRawData {
|
|
88
95
|
const result: ParsedRawData = {
|
|
89
96
|
config: {
|
|
90
97
|
includes: undefined,
|
|
91
98
|
excludes: undefined,
|
|
92
|
-
paths: undefined,
|
|
93
99
|
dtsOutDir: undefined,
|
|
94
100
|
arbitraryExtensions: undefined,
|
|
95
101
|
},
|
|
@@ -114,21 +120,6 @@ function parseRawData(raw: unknown, configFileName: string): ParsedRawData {
|
|
|
114
120
|
}
|
|
115
121
|
// MEMO: The errors for this option are reported by `tsc` or `tsserver`, so we don't need to report.
|
|
116
122
|
}
|
|
117
|
-
if ('compilerOptions' in raw && typeof raw.compilerOptions === 'object' && raw.compilerOptions !== null) {
|
|
118
|
-
if ('paths' in raw.compilerOptions) {
|
|
119
|
-
if (typeof raw.compilerOptions.paths === 'object' && raw.compilerOptions.paths !== null) {
|
|
120
|
-
const paths: Record<string, string[]> = {};
|
|
121
|
-
for (const [key, value] of Object.entries(raw.compilerOptions.paths)) {
|
|
122
|
-
if (Array.isArray(value)) {
|
|
123
|
-
const resolvedValue = value.filter((v) => typeof v === 'string');
|
|
124
|
-
paths[key] = resolvedValue;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
result.config.paths = paths;
|
|
128
|
-
}
|
|
129
|
-
// MEMO: The errors for this option are reported by `tsc` or `tsserver`, so we don't need to report.
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
123
|
if ('cmkOptions' in raw && typeof raw.cmkOptions === 'object' && raw.cmkOptions !== null) {
|
|
133
124
|
if ('dtsOutDir' in raw.cmkOptions) {
|
|
134
125
|
if (typeof raw.cmkOptions.dtsOutDir === 'string') {
|
|
@@ -159,39 +150,10 @@ function parseRawData(raw: unknown, configFileName: string): ParsedRawData {
|
|
|
159
150
|
}
|
|
160
151
|
export { parseRawData as parseRawDataForTest };
|
|
161
152
|
|
|
162
|
-
/**
|
|
163
|
-
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
164
|
-
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
|
165
|
-
* this function attempts to parse as much as possible and still returns a valid config.
|
|
166
|
-
*
|
|
167
|
-
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
168
|
-
* @throws {TsConfigFileNotFoundError}
|
|
169
|
-
*/
|
|
170
|
-
export function readConfigFile(project: string): CMKConfig {
|
|
171
|
-
const { configFileName, config, diagnostics } = readTsConfigFile(project);
|
|
172
|
-
const basePath = dirname(configFileName);
|
|
173
|
-
return {
|
|
174
|
-
...normalizeConfig(config, basePath),
|
|
175
|
-
basePath,
|
|
176
|
-
configFileName,
|
|
177
|
-
diagnostics,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function findTsConfigFile(project: string): string | undefined {
|
|
182
|
-
const configFile =
|
|
183
|
-
ts.sys.directoryExists(project) ?
|
|
184
|
-
ts.findConfigFile(project, ts.sys.fileExists.bind(ts.sys), 'tsconfig.json')
|
|
185
|
-
: ts.findConfigFile(dirname(project), ts.sys.fileExists.bind(ts.sys), basename(project));
|
|
186
|
-
if (!configFile) return undefined;
|
|
187
|
-
return resolve(configFile);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
153
|
function mergeParsedRawData(base: ParsedRawData, overrides: ParsedRawData): ParsedRawData {
|
|
191
154
|
const result: ParsedRawData = { config: { ...base.config }, diagnostics: [...base.diagnostics] };
|
|
192
155
|
if (overrides.config.includes !== undefined) result.config.includes = overrides.config.includes;
|
|
193
156
|
if (overrides.config.excludes !== undefined) result.config.excludes = overrides.config.excludes;
|
|
194
|
-
if (overrides.config.paths !== undefined) result.config.paths = overrides.config.paths;
|
|
195
157
|
if (overrides.config.dtsOutDir !== undefined) result.config.dtsOutDir = overrides.config.dtsOutDir;
|
|
196
158
|
if (overrides.config.arbitraryExtensions !== undefined)
|
|
197
159
|
result.config.arbitraryExtensions = overrides.config.arbitraryExtensions;
|
|
@@ -204,7 +166,10 @@ function mergeParsedRawData(base: ParsedRawData, overrides: ParsedRawData): Pars
|
|
|
204
166
|
*/
|
|
205
167
|
export function readTsConfigFile(project: string): {
|
|
206
168
|
configFileName: string;
|
|
207
|
-
|
|
169
|
+
config: UnnormalizedRawConfig;
|
|
170
|
+
compilerOptions: ts.CompilerOptions;
|
|
171
|
+
diagnostics: SemanticDiagnostic[];
|
|
172
|
+
} {
|
|
208
173
|
const configFileName = findTsConfigFile(project);
|
|
209
174
|
if (!configFileName) throw new TsConfigFileNotFoundError();
|
|
210
175
|
|
|
@@ -249,34 +214,45 @@ export function readTsConfigFile(project: string): {
|
|
|
249
214
|
|
|
250
215
|
return {
|
|
251
216
|
configFileName,
|
|
217
|
+
compilerOptions: parsedCommandLine.options,
|
|
252
218
|
...parsedRawData,
|
|
253
219
|
};
|
|
254
220
|
}
|
|
255
221
|
|
|
256
|
-
function resolvePaths(paths: Record<string, string[]> | undefined, cwd: string): Record<string, string[]> {
|
|
257
|
-
if (paths === undefined) return {};
|
|
258
|
-
const resolvedPaths: Record<string, string[]> = {};
|
|
259
|
-
for (const [key, value] of Object.entries(paths)) {
|
|
260
|
-
resolvedPaths[key] = value.map((path) => join(cwd, path));
|
|
261
|
-
}
|
|
262
|
-
return resolvedPaths;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
222
|
/**
|
|
266
|
-
* Normalize
|
|
223
|
+
* Normalize `UnnormalizedRawConfig`. Resolve relative paths to absolute paths, and set default values for missing options.
|
|
267
224
|
* @param basePath A root directory to resolve relative path entries in the config file to.
|
|
268
225
|
*/
|
|
269
226
|
export function normalizeConfig(
|
|
270
|
-
config:
|
|
227
|
+
config: UnnormalizedRawConfig,
|
|
271
228
|
basePath: string,
|
|
272
|
-
): RemoveUndefined<
|
|
229
|
+
): RemoveUndefined<UnnormalizedRawConfig> {
|
|
273
230
|
return {
|
|
274
231
|
// If `include` is not specified, fallback to the default include spec.
|
|
275
232
|
// ref: https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3102
|
|
276
233
|
includes: (config.includes ?? [DEFAULT_INCLUDE_SPEC]).map((i) => join(basePath, i)),
|
|
277
234
|
excludes: (config.excludes ?? []).map((e) => join(basePath, e)),
|
|
278
|
-
paths: resolvePaths(config.paths, basePath),
|
|
279
235
|
dtsOutDir: join(basePath, config.dtsOutDir ?? 'generated'),
|
|
280
236
|
arbitraryExtensions: config.arbitraryExtensions ?? false,
|
|
281
237
|
};
|
|
282
238
|
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
242
|
+
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
|
243
|
+
* this function attempts to parse as much as possible and still returns a valid config.
|
|
244
|
+
*
|
|
245
|
+
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
246
|
+
* @throws {TsConfigFileNotFoundError}
|
|
247
|
+
*/
|
|
248
|
+
export function readConfigFile(project: string): CMKConfig {
|
|
249
|
+
const { configFileName, config, compilerOptions, diagnostics } = readTsConfigFile(project);
|
|
250
|
+
const basePath = dirname(configFileName);
|
|
251
|
+
return {
|
|
252
|
+
...normalizeConfig(config, basePath),
|
|
253
|
+
basePath,
|
|
254
|
+
configFileName,
|
|
255
|
+
compilerOptions,
|
|
256
|
+
diagnostics,
|
|
257
|
+
};
|
|
258
|
+
}
|
package/src/dts-creator.ts
CHANGED
|
@@ -43,6 +43,7 @@ interface LinkedCodeMapping extends CodeMapping {
|
|
|
43
43
|
* ```
|
|
44
44
|
* The d.ts file would be:
|
|
45
45
|
* ```ts
|
|
46
|
+
* // @ts-nocheck
|
|
46
47
|
* const styles = {
|
|
47
48
|
* local1: '' as readonly string,
|
|
48
49
|
* local2: '' as readonly string,
|
|
@@ -71,16 +72,13 @@ export function createDts(
|
|
|
71
72
|
return resolved !== undefined && options.matchesPattern(resolved);
|
|
72
73
|
});
|
|
73
74
|
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
}
|
|
75
|
+
// MEMO: Depending on the TypeScript compilation options, the generated type definition file contains compile errors.
|
|
76
|
+
// For example, it contains `Top-level 'await' expressions are only allowed when the 'module' option is set to ...` error.
|
|
77
|
+
//
|
|
78
|
+
// If `--skipLibCheck` is false, those errors will be reported by `tsc`. However, these are negligible errors.
|
|
79
|
+
// Therefore, `@ts-nocheck` is added to the generated type definition file.
|
|
80
|
+
let text = `// @ts-nocheck\ndeclare const ${STYLES_EXPORT_NAME} = {\n`;
|
|
82
81
|
|
|
83
|
-
let text = `declare const ${STYLES_EXPORT_NAME} = {\n`;
|
|
84
82
|
for (const token of localTokens) {
|
|
85
83
|
text += ` `;
|
|
86
84
|
mapping.sourceOffsets.push(token.loc.start.offset);
|
package/src/parser/location.ts
CHANGED
|
@@ -7,13 +7,11 @@ export interface Position {
|
|
|
7
7
|
* The line number in the source file. It is 1-based.
|
|
8
8
|
* This is compatible with postcss and tsserver.
|
|
9
9
|
*/
|
|
10
|
-
// TODO: Maybe it should be deleted since it is not used
|
|
11
10
|
line: number;
|
|
12
11
|
/**
|
|
13
12
|
* The column number in the source file. It is 1-based.
|
|
14
13
|
* This is compatible with postcss and tsserver.
|
|
15
14
|
*/
|
|
16
|
-
// TODO: Maybe it should be deleted since it is not used
|
|
17
15
|
column: number;
|
|
18
16
|
/** The offset in the source file. It is 0-based. */
|
|
19
17
|
offset: number;
|
|
@@ -29,7 +27,6 @@ export interface Location {
|
|
|
29
27
|
* The ending position of the node. It is exclusive.
|
|
30
28
|
* This is compatible with tsserver, but not postcss.
|
|
31
29
|
*/
|
|
32
|
-
// TODO: Maybe it should be deleted since it is not used
|
|
33
30
|
end: Position;
|
|
34
31
|
}
|
|
35
32
|
|
package/src/resolver.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import type { CompilerOptions } from 'typescript';
|
|
2
3
|
import ts from 'typescript';
|
|
3
4
|
import { isAbsolute, resolve } from './path.js';
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ export interface ResolverOptions {
|
|
|
15
16
|
*/
|
|
16
17
|
export type Resolver = (specifier: string, options: ResolverOptions) => string | undefined;
|
|
17
18
|
|
|
18
|
-
export function createResolver(
|
|
19
|
+
export function createResolver(compilerOptions: CompilerOptions): Resolver {
|
|
19
20
|
return (_specifier: string, options: ResolverOptions) => {
|
|
20
21
|
let specifier = _specifier;
|
|
21
22
|
|
|
@@ -28,7 +29,7 @@ export function createResolver(paths: Record<string, string[]>): Resolver {
|
|
|
28
29
|
return ts.sys.fileExists(fileName);
|
|
29
30
|
},
|
|
30
31
|
};
|
|
31
|
-
const { resolvedModule } = ts.resolveModuleName(specifier, options.request,
|
|
32
|
+
const { resolvedModule } = ts.resolveModuleName(specifier, options.request, compilerOptions, host);
|
|
32
33
|
if (resolvedModule) {
|
|
33
34
|
// TODO: Logging that the paths is used.
|
|
34
35
|
specifier = resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
|