@css-modules-kit/core 0.7.0 → 0.8.0

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.
Files changed (59) hide show
  1. package/dist/checker.d.ts +9 -2
  2. package/dist/checker.d.ts.map +1 -1
  3. package/dist/checker.js +16 -14
  4. package/dist/checker.js.map +1 -1
  5. package/dist/config.d.ts +1 -0
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +31 -24
  8. package/dist/config.js.map +1 -1
  9. package/dist/diagnostic.d.ts.map +1 -1
  10. package/dist/diagnostic.js +9 -15
  11. package/dist/diagnostic.js.map +1 -1
  12. package/dist/dts-generator.d.ts +2 -6
  13. package/dist/dts-generator.d.ts.map +1 -1
  14. package/dist/dts-generator.js +53 -15
  15. package/dist/dts-generator.js.map +1 -1
  16. package/dist/error.js +2 -7
  17. package/dist/error.js.map +1 -1
  18. package/dist/export-builder.js +1 -4
  19. package/dist/export-builder.js.map +1 -1
  20. package/dist/file.js +17 -30
  21. package/dist/file.js.map +1 -1
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +12 -44
  25. package/dist/index.js.map +1 -1
  26. package/dist/parser/at-import-parser.js +3 -9
  27. package/dist/parser/at-import-parser.js.map +1 -1
  28. package/dist/parser/at-value-parser.js +1 -4
  29. package/dist/parser/at-value-parser.js.map +1 -1
  30. package/dist/parser/css-module-parser.js +15 -21
  31. package/dist/parser/css-module-parser.js.map +1 -1
  32. package/dist/parser/key-frame-parser.js +1 -4
  33. package/dist/parser/key-frame-parser.js.map +1 -1
  34. package/dist/parser/rule-parser.js +7 -13
  35. package/dist/parser/rule-parser.js.map +1 -1
  36. package/dist/path.d.ts +0 -1
  37. package/dist/path.d.ts.map +1 -1
  38. package/dist/path.js +16 -31
  39. package/dist/path.js.map +1 -1
  40. package/dist/resolver.d.ts.map +1 -1
  41. package/dist/resolver.js +12 -38
  42. package/dist/resolver.js.map +1 -1
  43. package/dist/type.d.ts +1 -1
  44. package/dist/type.d.ts.map +1 -1
  45. package/dist/type.js +1 -2
  46. package/dist/util.d.ts +1 -0
  47. package/dist/util.d.ts.map +1 -1
  48. package/dist/util.js +6 -8
  49. package/dist/util.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/checker.ts +20 -16
  52. package/src/config.ts +14 -0
  53. package/src/diagnostic.ts +2 -0
  54. package/src/dts-generator.ts +52 -18
  55. package/src/index.ts +3 -2
  56. package/src/path.ts +0 -3
  57. package/src/resolver.ts +5 -26
  58. package/src/type.ts +1 -1
  59. package/src/util.ts +4 -0
package/dist/resolver.js CHANGED
@@ -1,50 +1,24 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createResolver = createResolver;
7
- const node_url_1 = require("node:url");
8
- const typescript_1 = __importDefault(require("typescript"));
9
- const path_js_1 = require("./path.js");
10
- function createResolver(compilerOptions, moduleResolutionCache) {
11
- return (_specifier, options) => {
12
- let specifier = _specifier;
1
+ import ts from 'typescript';
2
+ import { isURLSpecifier } from './util.js';
3
+ export function createResolver(compilerOptions, moduleResolutionCache) {
4
+ return (specifier, options) => {
5
+ if (isURLSpecifier(specifier))
6
+ return undefined;
13
7
  const host = {
14
- ...typescript_1.default.sys,
8
+ ...ts.sys,
15
9
  fileExists: (fileName) => {
16
10
  if (fileName.endsWith('.module.d.css.ts')) {
17
- return typescript_1.default.sys.fileExists(fileName.replace(/\.module\.d\.css\.ts$/u, '.module.css'));
11
+ return ts.sys.fileExists(fileName.replace(/\.module\.d\.css\.ts$/u, '.module.css'));
18
12
  }
19
- return typescript_1.default.sys.fileExists(fileName);
13
+ return ts.sys.fileExists(fileName);
20
14
  },
21
15
  };
22
- const { resolvedModule } = typescript_1.default.resolveModuleName(specifier, options.request, compilerOptions, host, moduleResolutionCache);
16
+ const { resolvedModule } = ts.resolveModuleName(specifier, options.request, compilerOptions, host, moduleResolutionCache);
23
17
  if (resolvedModule) {
24
18
  // TODO: Logging that the paths is used.
25
- specifier = resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
26
- }
27
- if ((0, path_js_1.isAbsolute)(specifier)) {
28
- return (0, path_js_1.resolve)(specifier);
29
- }
30
- else if (isRelativeSpecifier(specifier)) {
31
- // Convert the specifier to an absolute path
32
- // NOTE: Node.js resolves relative specifier with standard relative URL resolution semantics. So we will follow that here as well.
33
- // ref: https://nodejs.org/docs/latest-v23.x/api/esm.html#terminology
34
- return (0, path_js_1.resolve)((0, node_url_1.fileURLToPath)(new URL(specifier, (0, node_url_1.pathToFileURL)(options.request)).href));
35
- }
36
- else {
37
- // Do not support URL or bare specifiers
38
- // TODO: Logging that the specifier could not resolve.
39
- return undefined;
19
+ return resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
40
20
  }
21
+ return undefined;
41
22
  };
42
23
  }
43
- /**
44
- * Check if the specifier is a relative specifier.
45
- * @see https://nodejs.org/docs/latest-v23.x/api/esm.html#terminology
46
- */
47
- function isRelativeSpecifier(specifier) {
48
- return specifier.startsWith('./') || specifier.startsWith('../');
49
- }
50
24
  //# sourceMappingURL=resolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":";;;;;AAMA,wCAwCC;AA9CD,uCAAwD;AAExD,4DAA4B;AAC5B,uCAAgD;AAGhD,SAAgB,cAAc,CAC5B,eAAgC,EAChC,qBAA2D;IAE3D,OAAO,CAAC,UAAkB,EAAE,OAAwB,EAAE,EAAE;QACtD,IAAI,SAAS,GAAG,UAAU,CAAC;QAE3B,MAAM,IAAI,GAA4B;YACpC,GAAG,oBAAE,CAAC,GAAG;YACT,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACvB,IAAI,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CA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appings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,UAAU,cAAc,CAC5B,eAAgC,EAChC,qBAA2D;IAE3D,OAAO,CAAC,SAAiB,EAAE,OAAwB,EAAE,EAAE;QACrD,IAAI,cAAc,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAChD,MAAM,IAAI,GAA4B;YACpC,GAAG,EAAE,CAAC,GAAG;YACT,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACvB,IAAI,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBAC1C,OAAO,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,aAAa,CAAC,CAAC,CAAC;gBACtF,CAAC;gBACD,OAAO,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACrC,CAAC;SACF,CAAC;QACF,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAC7C,SAAS,EACT,OAAO,CAAC,OAAO,EACf,eAAe,EACf,IAAI,EACJ,qBAAqB,CACtB,CAAC;QACF,IAAI,cAAc,EAAE,CAAC;YACnB,wCAAwC;YACxC,OAAO,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,wBAAwB,EAAE,aAAa,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
package/dist/type.d.ts CHANGED
@@ -138,7 +138,7 @@ export interface ExportBuilder {
138
138
  build(cssModule: CSSModule): ExportRecord;
139
139
  clearCache(): void;
140
140
  }
141
- export type DiagnosticCategory = 'error';
141
+ export type DiagnosticCategory = 'error' | 'warning';
142
142
  export interface DiagnosticSourceFile {
143
143
  fileName: string;
144
144
  text: string;
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","source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ED,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,yBAAyB;IACjC,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,QAAQ,EAAE,kBAAkB,CAAC;CAC9B;AAED,MAAM,WAAW,sBAAuB,SAAQ,yBAAyB;IACvE,gDAAgD;IAChD,IAAI,EAAE,oBAAoB,CAAC;IAC3B,qEAAqE;IACrE,KAAK,EAAE,kBAAkB,CAAC;IAC1B,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,sBAAsB,GAAG,yBAAyB,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,8BAA+B,SAAQ,yBAAyB;IAC/E,qEAAqE;IACrE,KAAK,EAAE,kBAAkB,CAAC;IAC1B,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB"}
package/dist/type.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=type.js.map
package/dist/util.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare function isPosixRelativePath(path: string): boolean;
2
2
  export declare function isValidAsJSIdentifier(name: string): boolean;
3
3
  export declare function findUsedTokenNames(componentText: string): Set<string>;
4
+ export declare function isURLSpecifier(specifier: string): boolean;
4
5
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAWD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAOrE"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAWD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAOrE;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEzD"}
package/dist/util.js CHANGED
@@ -1,13 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPosixRelativePath = isPosixRelativePath;
4
- exports.isValidAsJSIdentifier = isValidAsJSIdentifier;
5
- exports.findUsedTokenNames = findUsedTokenNames;
6
- function isPosixRelativePath(path) {
1
+ export function isPosixRelativePath(path) {
7
2
  return path.startsWith(`./`) || path.startsWith(`../`);
8
3
  }
9
4
  const JS_IDENTIFIER_PATTERN = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
10
- function isValidAsJSIdentifier(name) {
5
+ export function isValidAsJSIdentifier(name) {
11
6
  return JS_IDENTIFIER_PATTERN.test(name);
12
7
  }
13
8
  /**
@@ -18,7 +13,7 @@ function isValidAsJSIdentifier(name) {
18
13
  // MEMO: The `xxxStyles.foo` format is not supported, because the css module file for current component file is usually imported with `styles`.
19
14
  // It is sufficient to support only the `styles.foo` format.
20
15
  const TOKEN_CONSUMER_PATTERN = /styles\.([$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*)/gu;
21
- function findUsedTokenNames(componentText) {
16
+ export function findUsedTokenNames(componentText) {
22
17
  const usedClassNames = new Set();
23
18
  let match;
24
19
  while ((match = TOKEN_CONSUMER_PATTERN.exec(componentText)) !== null) {
@@ -26,4 +21,7 @@ function findUsedTokenNames(componentText) {
26
21
  }
27
22
  return usedClassNames;
28
23
  }
24
+ export function isURLSpecifier(specifier) {
25
+ return URL.canParse(specifier);
26
+ }
29
27
  //# sourceMappingURL=util.js.map
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAAA,kDAEC;AAID,sDAEC;AAWD,gDAOC;AA1BD,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,qBAAqB,GAAG,oDAAoD,CAAC;AAEnF,SAAgB,qBAAqB,CAAC,IAAY;IAChD,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,0DAA0D;AAC1D,+IAA+I;AAC/I,kEAAkE;AAClE,MAAM,sBAAsB,GAAG,6DAA6D,CAAC;AAE7F,SAAgB,kBAAkB,CAAC,aAAqB;IACtD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IACzC,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACrE,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC"}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,qBAAqB,GAAG,oDAAoD,CAAC;AAEnF,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,0DAA0D;AAC1D,+IAA+I;AAC/I,kEAAkE;AAClE,MAAM,sBAAsB,GAAG,6DAA6D,CAAC;AAE7F,MAAM,UAAU,kBAAkB,CAAC,aAAqB;IACtD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IACzC,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACrE,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,OAAO,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@css-modules-kit/core",
3
3
  "description": "The core of css-modules-kit",
4
- "version": "0.7.0",
5
- "type": "commonjs",
4
+ "version": "0.8.0",
5
+ "type": "module",
6
6
  "sideEffects": false,
7
7
  "repository": {
8
8
  "type": "git",
package/src/checker.ts CHANGED
@@ -4,23 +4,25 @@ import type {
4
4
  AtValueTokenImporterValue,
5
5
  CSSModule,
6
6
  Diagnostic,
7
- ExportBuilder,
7
+ ExportRecord,
8
8
  Location,
9
9
  MatchesPattern,
10
10
  Resolver,
11
11
  TokenImporter,
12
12
  } from './type.js';
13
- import { isValidAsJSIdentifier } from './util.js';
13
+ import { isURLSpecifier, isValidAsJSIdentifier } from './util.js';
14
14
 
15
- // eslint-disable-next-line max-params, complexity
16
- export function checkCSSModule(
17
- cssModule: CSSModule,
18
- config: CMKConfig,
19
- exportBuilder: ExportBuilder,
20
- matchesPattern: MatchesPattern,
21
- resolver: Resolver,
22
- getCSSModule: (path: string) => CSSModule | undefined,
23
- ): Diagnostic[] {
15
+ export interface CheckerArgs {
16
+ config: CMKConfig;
17
+ getExportRecord: (cssModule: CSSModule) => ExportRecord;
18
+ matchesPattern: MatchesPattern;
19
+ resolver: Resolver;
20
+ getCSSModule: (path: string) => CSSModule | undefined;
21
+ }
22
+
23
+ // eslint-disable-next-line complexity
24
+ export function checkCSSModule(cssModule: CSSModule, args: CheckerArgs): Diagnostic[] {
25
+ const { config } = args;
24
26
  const diagnostics: Diagnostic[] = [];
25
27
 
26
28
  for (const token of cssModule.localTokens) {
@@ -37,16 +39,18 @@ export function checkCSSModule(
37
39
  }
38
40
 
39
41
  for (const tokenImporter of cssModule.tokenImporters) {
40
- const from = resolver(tokenImporter.from, { request: cssModule.fileName });
41
- if (!from || !matchesPattern(from)) continue;
42
- const imported = getCSSModule(from);
43
- if (!imported) {
42
+ if (isURLSpecifier(tokenImporter.from)) continue;
43
+ const from = args.resolver(tokenImporter.from, { request: cssModule.fileName });
44
+ if (!from) {
44
45
  diagnostics.push(createCannotImportModuleDiagnostic(cssModule, tokenImporter));
45
46
  continue;
46
47
  }
48
+ if (!args.matchesPattern(from)) continue;
49
+ const imported = args.getCSSModule(from);
50
+ if (!imported) throw new Error('unreachable: `imported` is undefined');
47
51
 
48
52
  if (tokenImporter.type === 'value') {
49
- const exportRecord = exportBuilder.build(imported);
53
+ const exportRecord = args.getExportRecord(imported);
50
54
  for (const value of tokenImporter.values) {
51
55
  if (!exportRecord.allTokens.includes(value.name)) {
52
56
  diagnostics.push(createModuleHasNoExportedTokenDiagnostic(cssModule, tokenImporter, value));
package/src/config.ts CHANGED
@@ -13,6 +13,7 @@ const DEFAULT_INCLUDE_SPEC = '**/*';
13
13
  export interface CMKConfig {
14
14
  includes: string[];
15
15
  excludes: string[];
16
+ enabled: boolean | undefined;
16
17
  dtsOutDir: string;
17
18
  arbitraryExtensions: boolean;
18
19
  namedExports: boolean;
@@ -71,6 +72,7 @@ export interface CMKConfig {
71
72
  interface UnnormalizedRawConfig {
72
73
  includes?: string[];
73
74
  excludes?: string[];
75
+ enabled?: boolean;
74
76
  dtsOutDir?: string;
75
77
  arbitraryExtensions?: boolean;
76
78
  namedExports?: boolean;
@@ -99,6 +101,7 @@ function isTsConfigFileExists(fileName: string): boolean {
99
101
  return ts.findConfigFile(dirname(fileName), ts.sys.fileExists.bind(ts.sys), basename(fileName)) !== undefined;
100
102
  }
101
103
 
104
+ // eslint-disable-next-line complexity
102
105
  function parseRawData(raw: unknown, tsConfigSourceFile: ts.TsConfigSourceFile): ParsedRawData {
103
106
  const result: ParsedRawData = {
104
107
  config: {},
@@ -124,6 +127,16 @@ function parseRawData(raw: unknown, tsConfigSourceFile: ts.TsConfigSourceFile):
124
127
  // MEMO: The errors for this option are reported by `tsc` or `tsserver`, so we don't need to report.
125
128
  }
126
129
  if ('cmkOptions' in raw && typeof raw.cmkOptions === 'object' && raw.cmkOptions !== null) {
130
+ if ('enabled' in raw.cmkOptions) {
131
+ if (typeof raw.cmkOptions.enabled === 'boolean') {
132
+ result.config.enabled = raw.cmkOptions.enabled;
133
+ } else {
134
+ result.diagnostics.push({
135
+ category: 'error',
136
+ text: `\`enabled\` in ${tsConfigSourceFile.fileName} must be a boolean.`,
137
+ });
138
+ }
139
+ }
127
140
  if ('dtsOutDir' in raw.cmkOptions) {
128
141
  if (typeof raw.cmkOptions.dtsOutDir === 'string') {
129
142
  result.config.dtsOutDir = raw.cmkOptions.dtsOutDir;
@@ -255,6 +268,7 @@ export function readConfigFile(project: string): CMKConfig {
255
268
  namedExports: parsedTsConfig.config.namedExports ?? false,
256
269
  prioritizeNamedImports: parsedTsConfig.config.prioritizeNamedImports ?? false,
257
270
  keyframes: parsedTsConfig.config.keyframes ?? true,
271
+ enabled: parsedTsConfig.config.enabled,
258
272
  basePath,
259
273
  configFileName,
260
274
  compilerOptions: parsedTsConfig.compilerOptions,
package/src/diagnostic.ts CHANGED
@@ -11,6 +11,8 @@ function convertErrorCategory(category: DiagnosticCategory): ts.DiagnosticCatego
11
11
  switch (category) {
12
12
  case 'error':
13
13
  return ts.DiagnosticCategory.Error;
14
+ case 'warning':
15
+ return ts.DiagnosticCategory.Warning;
14
16
  default:
15
17
  throw new Error(`Unknown category: ${String(category)}`);
16
18
  }
@@ -1,13 +1,8 @@
1
- import type { CSSModule, MatchesPattern, Resolver, Token, TokenImporter } from './type.js';
2
- import { isValidAsJSIdentifier } from './util.js';
1
+ import type { CSSModule, Token, TokenImporter } from './type.js';
2
+ import { isURLSpecifier, isValidAsJSIdentifier } from './util.js';
3
3
 
4
4
  export const STYLES_EXPORT_NAME = 'styles';
5
5
 
6
- export interface GenerateDtsHost {
7
- resolver: Resolver;
8
- matchesPattern: MatchesPattern;
9
- }
10
-
11
6
  export interface GenerateDtsOptions {
12
7
  namedExports: boolean;
13
8
  prioritizeNamedImports: boolean;
@@ -46,11 +41,7 @@ interface GenerateDtsResult {
46
41
  /**
47
42
  * Generate .d.ts from `CSSModule`.
48
43
  */
49
- export function generateDts(
50
- cssModule: CSSModule,
51
- host: GenerateDtsHost,
52
- options: GenerateDtsOptions,
53
- ): GenerateDtsResult {
44
+ export function generateDts(cssModule: CSSModule, options: GenerateDtsOptions): GenerateDtsResult {
54
45
  // Exclude invalid tokens
55
46
  const localTokens = cssModule.localTokens.filter((token) => isValidName(token.name, options));
56
47
  const tokenImporters = cssModule.tokenImporters
@@ -69,10 +60,43 @@ export function generateDts(
69
60
  return tokenImporter;
70
61
  }
71
62
  })
72
- // Exclude token importers for external files
73
63
  .filter((tokenImporter) => {
74
- const resolved = host.resolver(tokenImporter.from, { request: cssModule.fileName });
75
- return resolved !== undefined && host.matchesPattern(resolved);
64
+ /**
65
+ * In principle, token importers with specifiers that cannot be resolved are still included in the type
66
+ * definitions. For example, consider the following:
67
+ *
68
+ * ```css
69
+ * // src/a.module.css
70
+ * @import './unresolved.module.css';
71
+ * @import './unmatched.css';
72
+ * .a_1 { color: red; }
73
+ * ```
74
+ *
75
+ * In this case, CSS Modules Kit generates the following type definitions:
76
+ *
77
+ * ```ts
78
+ * // generated/src/a.module.css.d.ts
79
+ * // @ts-nocheck
80
+ * declare const styles = {
81
+ * a_1: '' as readonly string,
82
+ * ...(await import('./unresolved.module.css')).default,
83
+ * ...(await import('./unmatched.css')).default,
84
+ * };
85
+ * ```
86
+ *
87
+ * Even if `./unresolved.module.css` or `./unmatched.css` does not exist, the same type definitions are
88
+ * generated. It is important that the generated type definitions do not change depending on whether the
89
+ * files exist. This provides the following benefits:
90
+ *
91
+ * - Simplifies the watch mode implementation
92
+ * - Only the type definitions for changed files need to be regenerated
93
+ * - Makes it easier to parallelize code generation
94
+ * - Type definitions can be generated independently per file
95
+ *
96
+ * However, as an exception, URL specifiers are not included in the type definitions, because URL
97
+ * specifiers are typically resolved at runtime.
98
+ */
99
+ return !isURLSpecifier(tokenImporter.from);
76
100
  });
77
101
 
78
102
  if (options.namedExports) {
@@ -219,8 +243,18 @@ function generateDefaultExportDts(
219
243
  //
220
244
  // If `--skipLibCheck` is false, those errors will be reported by `tsc`. However, these are negligible errors.
221
245
  // Therefore, `@ts-nocheck` is added to the generated type definition file.
222
- let text = `// @ts-nocheck\ndeclare const ${STYLES_EXPORT_NAME} = {\n`;
246
+ let text = `// @ts-nocheck\n`;
247
+
248
+ // This is a workaround to avoid the issue described as a "Drawbacks" in https://github.com/mizdra/css-modules-kit/pull/302.
249
+ // It uses the technique from https://stackoverflow.com/a/55541672 to fall back from `any` to `{}`.
250
+ // However, the import type for an unresolvable specifier becomes a special `any` type called `errorType`.
251
+ // The technique from https://stackoverflow.com/a/55541672 does not work with `errorType`.
252
+ // Therefore, this combines it with the approach from https://github.com/microsoft/TypeScript/issues/62972.
253
+ if (tokenImporters.some((importer) => importer.type === 'import')) {
254
+ text += `function blockErrorType<T>(val: T): [0] extends [(1 & T)] ? {} : T;\n`;
255
+ }
223
256
 
257
+ text += `declare const ${STYLES_EXPORT_NAME} = {\n`;
224
258
  for (const token of localTokens) {
225
259
  text += ` `;
226
260
  mapping.sourceOffsets.push(token.loc.start.offset);
@@ -230,11 +264,11 @@ function generateDefaultExportDts(
230
264
  }
231
265
  for (const tokenImporter of tokenImporters) {
232
266
  if (tokenImporter.type === 'import') {
233
- text += ` ...(await import(`;
267
+ text += ` ...blockErrorType((await import(`;
234
268
  mapping.sourceOffsets.push(tokenImporter.fromLoc.start.offset - 1);
235
269
  mapping.lengths.push(tokenImporter.from.length + 2);
236
270
  mapping.generatedOffsets.push(text.length);
237
- text += `'${tokenImporter.from}')).default,\n`;
271
+ text += `'${tokenImporter.from}')).default),\n`;
238
272
  } else {
239
273
  // eslint-disable-next-line no-loop-func
240
274
  tokenImporter.values.forEach((value, i) => {
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export {
15
15
  type Resolver,
16
16
  type MatchesPattern,
17
17
  type ExportBuilder,
18
+ type ExportRecord,
18
19
  type DiagnosticSourceFile,
19
20
  type Diagnostic,
20
21
  type DiagnosticWithLocation,
@@ -33,8 +34,8 @@ export {
33
34
  createMatchesPattern,
34
35
  getFileNamesByPattern,
35
36
  } from './file.js';
36
- export { checkCSSModule } from './checker.js';
37
+ export { checkCSSModule, type CheckerArgs } from './checker.js';
37
38
  export { createExportBuilder } from './export-builder.js';
38
- export { join, resolve, relative, dirname, basename, parse, isAbsolute } from './path.js';
39
+ export { join, resolve, relative, dirname, basename, parse } from './path.js';
39
40
  export { findUsedTokenNames } from './util.js';
40
41
  export { convertDiagnostic, convertDiagnosticWithLocation, convertSystemError } from './diagnostic.js';
package/src/path.ts CHANGED
@@ -32,6 +32,3 @@ export function parse(path: string): ParsedPath {
32
32
  const { root, dir, base, name, ext } = nodePath.parse(path);
33
33
  return { root: slash(root), dir: slash(dir), base, name, ext };
34
34
  }
35
-
36
- // eslint-disable-next-line @typescript-eslint/unbound-method
37
- export const isAbsolute = nodePath.isAbsolute;
package/src/resolver.ts CHANGED
@@ -1,16 +1,14 @@
1
- import { fileURLToPath, pathToFileURL } from 'node:url';
2
1
  import type { CompilerOptions } from 'typescript';
3
2
  import ts from 'typescript';
4
- import { isAbsolute, resolve } from './path.js';
5
3
  import type { Resolver, ResolverOptions } from './type.js';
4
+ import { isURLSpecifier } from './util.js';
6
5
 
7
6
  export function createResolver(
8
7
  compilerOptions: CompilerOptions,
9
8
  moduleResolutionCache: ts.ModuleResolutionCache | undefined,
10
9
  ): Resolver {
11
- return (_specifier: string, options: ResolverOptions) => {
12
- let specifier = _specifier;
13
-
10
+ return (specifier: string, options: ResolverOptions) => {
11
+ if (isURLSpecifier(specifier)) return undefined;
14
12
  const host: ts.ModuleResolutionHost = {
15
13
  ...ts.sys,
16
14
  fileExists: (fileName) => {
@@ -29,27 +27,8 @@ export function createResolver(
29
27
  );
30
28
  if (resolvedModule) {
31
29
  // TODO: Logging that the paths is used.
32
- specifier = resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
33
- }
34
- if (isAbsolute(specifier)) {
35
- return resolve(specifier);
36
- } else if (isRelativeSpecifier(specifier)) {
37
- // Convert the specifier to an absolute path
38
- // NOTE: Node.js resolves relative specifier with standard relative URL resolution semantics. So we will follow that here as well.
39
- // ref: https://nodejs.org/docs/latest-v23.x/api/esm.html#terminology
40
- return resolve(fileURLToPath(new URL(specifier, pathToFileURL(options.request)).href));
41
- } else {
42
- // Do not support URL or bare specifiers
43
- // TODO: Logging that the specifier could not resolve.
44
- return undefined;
30
+ return resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
45
31
  }
32
+ return undefined;
46
33
  };
47
34
  }
48
-
49
- /**
50
- * Check if the specifier is a relative specifier.
51
- * @see https://nodejs.org/docs/latest-v23.x/api/esm.html#terminology
52
- */
53
- function isRelativeSpecifier(specifier: string): boolean {
54
- return specifier.startsWith('./') || specifier.startsWith('../');
55
- }
package/src/type.ts CHANGED
@@ -151,7 +151,7 @@ export interface ExportBuilder {
151
151
  clearCache(): void;
152
152
  }
153
153
 
154
- export type DiagnosticCategory = 'error';
154
+ export type DiagnosticCategory = 'error' | 'warning';
155
155
 
156
156
  export interface DiagnosticSourceFile {
157
157
  fileName: string;
package/src/util.ts CHANGED
@@ -25,3 +25,7 @@ export function findUsedTokenNames(componentText: string): Set<string> {
25
25
  }
26
26
  return usedClassNames;
27
27
  }
28
+
29
+ export function isURLSpecifier(specifier: string): boolean {
30
+ return URL.canParse(specifier);
31
+ }