@css-modules-kit/codegen 0.1.4 → 0.2.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.
package/README.md CHANGED
@@ -39,6 +39,7 @@ Options:
39
39
  --help, -h Show help information
40
40
  --version, -v Show version number
41
41
  --project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
42
+ --pretty Enable color and formatting in output to make errors easier to read.
42
43
  ```
43
44
 
44
45
  ## Configuration
package/bin/cmk.mjs CHANGED
@@ -1,18 +1,28 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable n/no-process-exit */
2
3
 
3
4
  import { SystemError } from '@css-modules-kit/core';
4
- import { createLogger, parseCLIArgs, runCMK } from '../dist/index.js';
5
+ import { createLogger, parseCLIArgs, printHelpText, printVersion, runCMK, shouldBePretty } from '../dist/index.js';
5
6
 
6
7
  const cwd = process.cwd();
7
- const logger = createLogger(cwd);
8
- const args = parseCLIArgs(process.argv.slice(2), cwd, logger);
8
+ let logger = createLogger(cwd, shouldBePretty(undefined));
9
9
 
10
10
  try {
11
+ const args = parseCLIArgs(process.argv.slice(2), cwd);
12
+ logger = createLogger(cwd, shouldBePretty(args.pretty));
13
+
14
+ if (args.help) {
15
+ printHelpText();
16
+ process.exit(0);
17
+ } else if (args.version) {
18
+ printVersion();
19
+ process.exit(0);
20
+ }
21
+
11
22
  await runCMK(args.project, logger);
12
23
  } catch (e) {
13
24
  if (e instanceof SystemError) {
14
25
  logger.logSystemError(e);
15
- // eslint-disable-next-line n/no-process-exit
16
26
  process.exit(1);
17
27
  }
18
28
  throw e;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @fileoverview
3
+ * This is forked from microsoft/TypeScript.
4
+ * @see https://github.com/microsoft/TypeScript/blob/ee3dd7264b23e58bbad86d08a475cac78f330abf/src/compiler/executeCommandLine.ts#L160-L169
5
+ * @license
6
+ * Apache License
7
+ *
8
+ * Version 2.0, January 2004
9
+ *
10
+ * http://www.apache.org/licenses/
11
+ *
12
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
+ *
14
+ * 1. Definitions.
15
+ *
16
+ * "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
17
+ *
18
+ * "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
19
+ *
20
+ * "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
21
+ *
22
+ * "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
23
+ *
24
+ * "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
25
+ *
26
+ * "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
27
+ *
28
+ * "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
29
+ *
30
+ * "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
31
+ *
32
+ * "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
33
+ *
34
+ * "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
35
+ *
36
+ * 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
37
+ *
38
+ * 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
39
+ *
40
+ * 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41
+ *
42
+ * You must give any other recipients of the Work or Derivative Works a copy of this License; and
43
+ *
44
+ * You must cause any modified files to carry prominent notices stating that You changed the files; and
45
+ *
46
+ * You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
47
+ *
48
+ * If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
49
+ *
50
+ * 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51
+ *
52
+ * 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
53
+ *
54
+ * 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
55
+ *
56
+ * 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
57
+ *
58
+ * 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
59
+ *
60
+ * END OF TERMS AND CONDITIONS
61
+ */
62
+ export declare function defaultIsPretty(): boolean;
63
+ export declare function shouldBePretty(pretty: boolean | undefined): boolean;
64
+ //# sourceMappingURL=typescript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/3rd-party/typescript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAIH,wBAAgB,eAAe,YAE9B;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAKnE"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview
4
+ * This is forked from microsoft/TypeScript.
5
+ * @see https://github.com/microsoft/TypeScript/blob/ee3dd7264b23e58bbad86d08a475cac78f330abf/src/compiler/executeCommandLine.ts#L160-L169
6
+ * @license
7
+ * Apache License
8
+ *
9
+ * Version 2.0, January 2004
10
+ *
11
+ * http://www.apache.org/licenses/
12
+ *
13
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
+ *
15
+ * 1. Definitions.
16
+ *
17
+ * "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
18
+ *
19
+ * "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
20
+ *
21
+ * "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
22
+ *
23
+ * "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
24
+ *
25
+ * "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
26
+ *
27
+ * "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
28
+ *
29
+ * "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
30
+ *
31
+ * "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
32
+ *
33
+ * "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
34
+ *
35
+ * "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
36
+ *
37
+ * 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
38
+ *
39
+ * 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
40
+ *
41
+ * 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
42
+ *
43
+ * You must give any other recipients of the Work or Derivative Works a copy of this License; and
44
+ *
45
+ * You must cause any modified files to carry prominent notices stating that You changed the files; and
46
+ *
47
+ * You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
48
+ *
49
+ * If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+ *
51
+ * 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
52
+ *
53
+ * 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
54
+ *
55
+ * 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
56
+ *
57
+ * 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
58
+ *
59
+ * 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
60
+ *
61
+ * END OF TERMS AND CONDITIONS
62
+ */
63
+ var __importDefault = (this && this.__importDefault) || function (mod) {
64
+ return (mod && mod.__esModule) ? mod : { "default": mod };
65
+ };
66
+ Object.defineProperty(exports, "__esModule", { value: true });
67
+ exports.defaultIsPretty = defaultIsPretty;
68
+ exports.shouldBePretty = shouldBePretty;
69
+ const typescript_1 = __importDefault(require("typescript"));
70
+ function defaultIsPretty() {
71
+ return !!typescript_1.default.sys.writeOutputIsTTY && typescript_1.default.sys.writeOutputIsTTY() && !process.env['NO_COLOR'];
72
+ }
73
+ function shouldBePretty(pretty) {
74
+ if (pretty === undefined) {
75
+ return defaultIsPretty();
76
+ }
77
+ return pretty;
78
+ }
79
+ //# sourceMappingURL=typescript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/3rd-party/typescript.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;;;;;AAIH,0CAEC;AAED,wCAKC;AAXD,4DAA4B;AAE5B,SAAgB,eAAe;IAC7B,OAAO,CAAC,CAAC,oBAAE,CAAC,GAAG,CAAC,gBAAgB,IAAI,oBAAE,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC5F,CAAC;AAED,SAAgB,cAAc,CAAC,MAA2B;IACxD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,eAAe,EAAE,CAAC;IAC3B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/dist/cli.d.ts CHANGED
@@ -1,10 +1,14 @@
1
- import type { Logger } from './logger/logger.js';
1
+ export declare function printHelpText(): void;
2
+ export declare function printVersion(): void;
2
3
  export interface ParsedArgs {
4
+ help: boolean;
5
+ version: boolean;
3
6
  project: string;
7
+ pretty: boolean | undefined;
4
8
  }
5
9
  /**
6
10
  * Parse command-line arguments.
7
- * If `--help` or `--version` is passed, print the corresponding information and exit the process.
11
+ * @throws {ParseCLIArgsError} If failed to parse CLI arguments.
8
12
  */
9
- export declare function parseCLIArgs(args: string[], cwd: string, logger: Logger): ParsedArgs;
13
+ export declare function parseCLIArgs(args: string[], cwd: string): ParsedArgs;
10
14
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAWjD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAqBpF"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAeA,wBAAgB,aAAa,IAAI,IAAI,CAGpC;AAED,wBAAgB,YAAY,IAAI,IAAI,CAGnC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAqBpE"}
package/dist/cli.js CHANGED
@@ -3,10 +3,13 @@ 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.printHelpText = printHelpText;
7
+ exports.printVersion = printVersion;
6
8
  exports.parseCLIArgs = parseCLIArgs;
7
9
  const node_util_1 = require("node:util");
8
10
  const core_1 = require("@css-modules-kit/core");
9
11
  const package_json_1 = __importDefault(require("../package.json"));
12
+ const error_js_1 = require("./error.js");
10
13
  const helpText = `
11
14
  Usage: cmk [options]
12
15
 
@@ -14,32 +17,41 @@ Options:
14
17
  --help, -h Show help information
15
18
  --version, -v Show version number
16
19
  --project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
20
+ --pretty Enable color and formatting in output to make errors easier to read.
17
21
  `;
22
+ function printHelpText() {
23
+ // eslint-disable-next-line no-console
24
+ console.log(helpText);
25
+ }
26
+ function printVersion() {
27
+ // eslint-disable-next-line no-console
28
+ console.log(package_json_1.default.version);
29
+ }
18
30
  /**
19
31
  * Parse command-line arguments.
20
- * If `--help` or `--version` is passed, print the corresponding information and exit the process.
32
+ * @throws {ParseCLIArgsError} If failed to parse CLI arguments.
21
33
  */
22
- function parseCLIArgs(args, cwd, logger) {
23
- const { values } = (0, node_util_1.parseArgs)({
24
- args,
25
- options: {
26
- help: { type: 'boolean', short: 'h' },
27
- version: { type: 'boolean', short: 'v' },
28
- project: { type: 'string', short: 'p', default: '.' },
29
- },
30
- });
31
- if (values.help) {
32
- logger.logMessage(helpText);
33
- // eslint-disable-next-line n/no-process-exit
34
- process.exit(0);
34
+ function parseCLIArgs(args, cwd) {
35
+ try {
36
+ const { values } = (0, node_util_1.parseArgs)({
37
+ args,
38
+ options: {
39
+ help: { type: 'boolean', short: 'h', default: false },
40
+ version: { type: 'boolean', short: 'v', default: false },
41
+ project: { type: 'string', short: 'p', default: '.' },
42
+ pretty: { type: 'boolean' },
43
+ },
44
+ allowNegative: true,
45
+ });
46
+ return {
47
+ help: values.help,
48
+ version: values.version,
49
+ project: (0, core_1.resolve)(cwd, values.project),
50
+ pretty: values.pretty,
51
+ };
35
52
  }
36
- else if (values.version) {
37
- logger.logMessage(package_json_1.default.version);
38
- // eslint-disable-next-line n/no-process-exit
39
- process.exit(0);
53
+ catch (cause) {
54
+ throw new error_js_1.ParseCLIArgsError(cause);
40
55
  }
41
- return {
42
- project: (0, core_1.resolve)(cwd, values.project),
43
- };
44
56
  }
45
57
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAsBA,oCAqBC;AA3CD,yCAAsC;AACtC,gDAAgD;AAChD,mEAA0C;AAG1C,MAAM,QAAQ,GAAG;;;;;;;CAOhB,CAAC;AAMF;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAc,EAAE,GAAW,EAAE,MAAc;IACtE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,qBAAS,EAAC;QAC3B,IAAI;QACJ,OAAO,EAAE;YACP,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE;YACrC,OAAO,EA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AAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;gBACrD,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;gBACxD,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;gBACrD,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;aAC5B;YACD,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,IAAA,cAAO,EAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC;YACrC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,4BAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
package/dist/error.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { SystemError } from '@css-modules-kit/core';
2
+ export declare class ParseCLIArgsError extends SystemError {
3
+ constructor(cause: unknown);
4
+ }
2
5
  export declare class WriteDtsFileError extends SystemError {
3
6
  constructor(fileName: string, cause: unknown);
4
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAG7C;AAED,qBAAa,sBAAuB,SAAQ,WAAW;gBACzC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAG7C"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,KAAK,EAAE,OAAO;CAG3B;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAG7C;AAED,qBAAa,sBAAuB,SAAQ,WAAW;gBACzC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAG7C"}
package/dist/error.js CHANGED
@@ -1,16 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReadCSSModuleFileError = exports.WriteDtsFileError = void 0;
3
+ exports.ReadCSSModuleFileError = exports.WriteDtsFileError = exports.ParseCLIArgsError = void 0;
4
4
  const core_1 = require("@css-modules-kit/core");
5
+ class ParseCLIArgsError extends core_1.SystemError {
6
+ constructor(cause) {
7
+ super('PARSE_CLI_ARGS_ERROR', `Failed to parse CLI arguments.`, cause);
8
+ }
9
+ }
10
+ exports.ParseCLIArgsError = ParseCLIArgsError;
5
11
  class WriteDtsFileError extends core_1.SystemError {
6
12
  constructor(fileName, cause) {
7
- super('WRITE_DTS_FILE_ERROR', `Failed to write .d.ts file ${fileName}.`, { cause });
13
+ super('WRITE_DTS_FILE_ERROR', `Failed to write .d.ts file ${fileName}.`, cause);
8
14
  }
9
15
  }
10
16
  exports.WriteDtsFileError = WriteDtsFileError;
11
17
  class ReadCSSModuleFileError extends core_1.SystemError {
12
18
  constructor(fileName, cause) {
13
- super('READ_CSS_MODULE_FILE_ERROR', `Failed to read CSS Module file ${fileName}.`, { cause });
19
+ super('READ_CSS_MODULE_FILE_ERROR', `Failed to read CSS Module file ${fileName}.`, cause);
14
20
  }
15
21
  }
16
22
  exports.ReadCSSModuleFileError = ReadCSSModuleFileError;
package/dist/error.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,gDAAoD;AAEpD,MAAa,iBAAkB,SAAQ,kBAAW;IAChD,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,sBAAsB,EAAE,8BAA8B,QAAQ,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACtF,CAAC;CACF;AAJD,8CAIC;AAED,MAAa,sBAAuB,SAAQ,kBAAW;IACrD,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,4BAA4B,EAAE,kCAAkC,QAAQ,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAChG,CAAC;CACF;AAJD,wDAIC"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,gDAAoD;AAEpD,MAAa,iBAAkB,SAAQ,kBAAW;IAChD,YAAY,KAAc;QACxB,KAAK,CAAC,sBAAsB,EAAE,gCAAgC,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;CACF;AAJD,8CAIC;AAED,MAAa,iBAAkB,SAAQ,kBAAW;IAChD,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,sBAAsB,EAAE,8BAA8B,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;IAClF,CAAC;CACF;AAJD,8CAIC;AAED,MAAa,sBAAuB,SAAQ,kBAAW;IACrD,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,4BAA4B,EAAE,kCAAkC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5F,CAAC;CACF;AAJD,wDAIC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { runCMK } from './runner.js';
2
2
  export { type Logger, createLogger } from './logger/logger.js';
3
3
  export { WriteDtsFileError, ReadCSSModuleFileError } from './error.js';
4
- export { parseCLIArgs } from './cli.js';
4
+ export { parseCLIArgs, printHelpText, printVersion } from './cli.js';
5
+ export { shouldBePretty } from './3rd-party/typescript.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCLIArgs = exports.ReadCSSModuleFileError = exports.WriteDtsFileError = exports.createLogger = exports.runCMK = void 0;
3
+ exports.shouldBePretty = exports.printVersion = exports.printHelpText = exports.parseCLIArgs = exports.ReadCSSModuleFileError = exports.WriteDtsFileError = exports.createLogger = exports.runCMK = void 0;
4
4
  var runner_js_1 = require("./runner.js");
5
5
  Object.defineProperty(exports, "runCMK", { enumerable: true, get: function () { return runner_js_1.runCMK; } });
6
6
  var logger_js_1 = require("./logger/logger.js");
@@ -10,4 +10,8 @@ Object.defineProperty(exports, "WriteDtsFileError", { enumerable: true, get: fun
10
10
  Object.defineProperty(exports, "ReadCSSModuleFileError", { enumerable: true, get: function () { return error_js_1.ReadCSSModuleFileError; } });
11
11
  var cli_js_1 = require("./cli.js");
12
12
  Object.defineProperty(exports, "parseCLIArgs", { enumerable: true, get: function () { return cli_js_1.parseCLIArgs; } });
13
+ Object.defineProperty(exports, "printHelpText", { enumerable: true, get: function () { return cli_js_1.printHelpText; } });
14
+ Object.defineProperty(exports, "printVersion", { enumerable: true, get: function () { return cli_js_1.printVersion; } });
15
+ var typescript_js_1 = require("./3rd-party/typescript.js");
16
+ Object.defineProperty(exports, "shouldBePretty", { enumerable: true, get: function () { return typescript_js_1.shouldBePretty; } });
13
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAA5B,mGAAA,MAAM,OAAA;AACf,gDAA+D;AAAzC,yGAAA,YAAY,OAAA;AAClC,uCAAuE;AAA9D,6GAAA,iBAAiB,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AAClD,mCAAwC;AAA/B,sGAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAA5B,mGAAA,MAAM,OAAA;AACf,gDAA+D;AAAzC,yGAAA,YAAY,OAAA;AAClC,uCAAuE;AAA9D,6GAAA,iBAAiB,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AAClD,mCAAqE;AAA5D,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AAAE,sGAAA,YAAY,OAAA;AAClD,2DAA2D;AAAlD,+GAAA,cAAc,OAAA"}
@@ -1,4 +1,3 @@
1
- import { type Diagnostic, type SystemError } from '@css-modules-kit/core';
2
- export declare function formatDiagnostic(diagnostic: Diagnostic, cwd: string): string;
3
- export declare function formatSystemError(error: SystemError): string;
1
+ import ts from 'typescript';
2
+ export declare function formatDiagnostics(diagnostics: ts.Diagnostic[], host: ts.FormatDiagnosticsHost, pretty: boolean): string;
4
3
  //# sourceMappingURL=formatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/logger/formatter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,UAAU,EAIf,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAS5E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAS5D"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/logger/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,EAAE,CAAC,UAAU,EAAE,EAC5B,IAAI,EAAE,EAAE,CAAC,qBAAqB,EAC9B,MAAM,EAAE,OAAO,GACd,MAAM,CAOR"}
@@ -1,48 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatDiagnostic = formatDiagnostic;
4
- exports.formatSystemError = formatSystemError;
5
- const node_util_1 = require("node:util");
6
- const core_1 = require("@css-modules-kit/core");
7
- function formatDiagnostic(diagnostic, cwd) {
6
+ exports.formatDiagnostics = formatDiagnostics;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ function formatDiagnostics(diagnostics, host, pretty) {
9
+ const format = pretty ? typescript_1.default.formatDiagnosticsWithColorAndContext : typescript_1.default.formatDiagnostics;
8
10
  let result = '';
9
- if (diagnostic.fileName) {
10
- result += `${formatLocation(diagnostic.fileName, diagnostic.start, cwd)} - `;
11
+ for (const diagnostic of diagnostics) {
12
+ result += format([diagnostic], host).replace(` TS${diagnostic.code}`, '') + host.getNewLine();
11
13
  }
12
- result += `${formatCategory(diagnostic.category)}: `;
13
- result += diagnostic.text;
14
- // TODO(#124): Add source code if diagnostics has a location
15
14
  return result;
16
15
  }
17
- function formatSystemError(error) {
18
- let result = '';
19
- result += `${formatCategory('error')}`;
20
- result += ' ';
21
- result += (0, node_util_1.styleText)('gray', error.code);
22
- result += ': ';
23
- result += error.message;
24
- // TODO(#118): Include cause if exists
25
- return result;
26
- }
27
- function formatLocation(fileName, start, cwd) {
28
- let result = '';
29
- result += (0, node_util_1.styleText)('cyan', (0, core_1.relative)(cwd, fileName));
30
- if (start !== undefined) {
31
- result += ':';
32
- result += (0, node_util_1.styleText)('yellow', start.line.toString());
33
- result += ':';
34
- result += (0, node_util_1.styleText)('yellow', start.column.toString());
35
- }
36
- return result;
37
- }
38
- function formatCategory(category) {
39
- switch (category) {
40
- case 'error':
41
- return (0, node_util_1.styleText)('red', 'error');
42
- case 'warning':
43
- return (0, node_util_1.styleText)('yellow', 'warning');
44
- default:
45
- throw new Error(`Unknown diagnostic category: ${String(category)}`);
46
- }
47
- }
48
16
  //# sourceMappingURL=formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/logger/formatter.ts"],"names":[],"mappings":";;AASA,4CASC;AAED,8CASC;AA7BD,yCAAsC;AACtC,gDAM+B;AAE/B,SAAgB,gBAAgB,CAAC,UAAsB,EAAE,GAAW;IAClE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,cAAc,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC;IAC/E,CAAC;IACD,MAAM,IAAI,GAAG,cAAc,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;IACrD,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC;IAC1B,4DA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AAC,EAAE,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/logger/formatter.ts"],"names":[],"mappings":";;;;;AAEA,8CAWC;AAbD,4DAA4B;AAE5B,SAAgB,iBAAiB,CAC/B,WAA4B,EAC5B,IAA8B,EAC9B,MAAe;IAEf,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,oBAAE,CAAC,oCAAoC,CAAC,CAAC,CAAC,oBAAE,CAAC,iBAAiB,CAAC;IACvF,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,IAAI,MAAM,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAChG,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,8 +1,8 @@
1
- import type { Diagnostic, SystemError } from '@css-modules-kit/core';
1
+ import { type Diagnostic, type SystemError } from '@css-modules-kit/core';
2
2
  export interface Logger {
3
3
  logDiagnostics(diagnostics: Diagnostic[]): void;
4
4
  logSystemError(error: SystemError): void;
5
5
  logMessage(message: string): void;
6
6
  }
7
- export declare function createLogger(cwd: string): Logger;
7
+ export declare function createLogger(cwd: string, pretty: boolean): Logger;
8
8
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGrE,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAChD,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACzC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAgBhD"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAyC,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIjH,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAChD,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACzC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CA4BjE"}
@@ -1,18 +1,29 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.createLogger = createLogger;
7
+ const core_1 = require("@css-modules-kit/core");
8
+ const typescript_1 = __importDefault(require("typescript"));
4
9
  const formatter_js_1 = require("./formatter.js");
5
- function createLogger(cwd) {
10
+ function createLogger(cwd, pretty) {
11
+ const host = {
12
+ getCurrentDirectory: () => cwd,
13
+ getCanonicalFileName: (fileName) => (typescript_1.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase()),
14
+ getNewLine: () => typescript_1.default.sys.newLine,
15
+ };
16
+ function getSourceFile(file) {
17
+ return typescript_1.default.createSourceFile(file.fileName, file.text, typescript_1.default.ScriptTarget.JSON, undefined, typescript_1.default.ScriptKind.Unknown);
18
+ }
6
19
  return {
7
20
  logDiagnostics(diagnostics) {
8
- let result = '';
9
- for (const diagnostic of diagnostics) {
10
- result += `${(0, formatter_js_1.formatDiagnostic)(diagnostic, cwd)}\n\n`;
11
- }
21
+ const result = (0, formatter_js_1.formatDiagnostics)(diagnostics.map((d) => (0, core_1.convertDiagnostic)(d, getSourceFile)), host, pretty);
12
22
  process.stderr.write(result);
13
23
  },
14
24
  logSystemError(error) {
15
- process.stderr.write(`${(0, formatter_js_1.formatSystemError)(error)}\n`);
25
+ const result = (0, formatter_js_1.formatDiagnostics)([(0, core_1.convertSystemError)(error)], host, pretty);
26
+ process.stderr.write(result);
16
27
  },
17
28
  logMessage(message) {
18
29
  process.stdout.write(`${message}\n`);
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;AASA,oCAgBC;AAxBD,iDAAqE;AAQrE,SAAgB,YAAY,CAAC,GAAW;IACtC,OAAO;QACL,cAAc,CAAC,WAAyB;YACtC,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;gBACrC,MAAM,IAAI,GAAG,IAAA,+BAAgB,EAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC;YACvD,CAAC;YACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;QACD,cAAc,CAAC,KAAkB;YAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,gCAAiB,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,UAAU,CAAC,OAAe;YACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;AAWA,oCA4BC;AAtCD,gDAAiH;AACjH,4DAA4B;AAC5B,iDAAmD;AAQnD,SAAgB,YAAY,CAAC,GAAW,EAAE,MAAe;IACvD,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type { Logger } from './logger/logger.js';
2
2
  /**
3
3
  * Run css-modules-kit .d.ts generation.
4
4
  * @param project The absolute path to the project directory or the path to `tsconfig.json`.
5
- * @throws {GlobError} When failed to retrieve files by glob pattern.
6
5
  * @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
7
6
  * @throws {WriteDtsFileError}
8
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAgCjD;;;;;;GAMG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwD3E"}
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAgCjD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8D3E"}
package/dist/runner.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.runCMK = runCMK;
4
7
  const promises_1 = require("node:fs/promises");
5
8
  const core_1 = require("@css-modules-kit/core");
9
+ const typescript_1 = __importDefault(require("typescript"));
6
10
  const dts_writer_js_1 = require("./dts-writer.js");
7
11
  const error_js_1 = require("./error.js");
8
12
  /**
@@ -32,7 +36,6 @@ async function writeDtsByCSSModule(cssModule, { dtsOutDir, basePath, arbitraryEx
32
36
  /**
33
37
  * Run css-modules-kit .d.ts generation.
34
38
  * @param project The absolute path to the project directory or the path to `tsconfig.json`.
35
- * @throws {GlobError} When failed to retrieve files by glob pattern.
36
39
  * @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
37
40
  * @throws {WriteDtsFileError}
38
41
  */
@@ -43,7 +46,9 @@ async function runCMK(project, logger) {
43
46
  // eslint-disable-next-line n/no-process-exit
44
47
  process.exit(1);
45
48
  }
46
- const resolver = (0, core_1.createResolver)(config.compilerOptions);
49
+ const getCanonicalFileName = (fileName) => typescript_1.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
50
+ const moduleResolutionCache = typescript_1.default.createModuleResolutionCache(config.basePath, getCanonicalFileName, config.compilerOptions);
51
+ const resolver = (0, core_1.createResolver)(config.compilerOptions, moduleResolutionCache);
47
52
  const matchesPattern = (0, core_1.createMatchesPattern)(config);
48
53
  const cssModuleMap = new Map();
49
54
  const syntacticDiagnostics = [];
@@ -51,7 +56,6 @@ async function runCMK(project, logger) {
51
56
  if (fileNames.length === 0) {
52
57
  logger.logDiagnostics([
53
58
  {
54
- type: 'semantic',
55
59
  category: 'warning',
56
60
  text: `The file specified in tsconfig.json not found.`,
57
61
  },
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":";;AA6DA,wBAwDC;AArHD,+CAA4C;AAU5C,gDAS+B;AAC/B,mDAA+C;AAC/C,yCAAoD;AAGpD;;GAEG;AACH,KAAK,UAAU,wBAAwB,CAAC,QAAgB;IACtD,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,iCAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,IAAA,qBAAc,EAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACzD,CAAC;AA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ED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@css-modules-kit/codegen",
3
3
  "description": "A tool for generating `*.d.ts` files for `*.module.css`.",
4
- "version": "0.1.4",
4
+ "version": "0.2.0",
5
5
  "type": "commonjs",
6
6
  "sideEffects": false,
7
7
  "repository": {
@@ -46,7 +46,7 @@
46
46
  "dist"
47
47
  ],
48
48
  "dependencies": {
49
- "@css-modules-kit/core": "^0.1.0"
49
+ "@css-modules-kit/core": "^0.2.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "typescript": "^5.7.3"
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @fileoverview
3
+ * This is forked from microsoft/TypeScript.
4
+ * @see https://github.com/microsoft/TypeScript/blob/ee3dd7264b23e58bbad86d08a475cac78f330abf/src/compiler/executeCommandLine.ts#L160-L169
5
+ * @license
6
+ * Apache License
7
+ *
8
+ * Version 2.0, January 2004
9
+ *
10
+ * http://www.apache.org/licenses/
11
+ *
12
+ * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
+ *
14
+ * 1. Definitions.
15
+ *
16
+ * "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
17
+ *
18
+ * "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
19
+ *
20
+ * "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
21
+ *
22
+ * "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
23
+ *
24
+ * "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
25
+ *
26
+ * "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
27
+ *
28
+ * "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
29
+ *
30
+ * "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
31
+ *
32
+ * "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
33
+ *
34
+ * "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
35
+ *
36
+ * 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
37
+ *
38
+ * 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
39
+ *
40
+ * 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41
+ *
42
+ * You must give any other recipients of the Work or Derivative Works a copy of this License; and
43
+ *
44
+ * You must cause any modified files to carry prominent notices stating that You changed the files; and
45
+ *
46
+ * You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
47
+ *
48
+ * If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
49
+ *
50
+ * 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51
+ *
52
+ * 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
53
+ *
54
+ * 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
55
+ *
56
+ * 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
57
+ *
58
+ * 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
59
+ *
60
+ * END OF TERMS AND CONDITIONS
61
+ */
62
+
63
+ import ts from 'typescript';
64
+
65
+ export function defaultIsPretty() {
66
+ return !!ts.sys.writeOutputIsTTY && ts.sys.writeOutputIsTTY() && !process.env['NO_COLOR'];
67
+ }
68
+
69
+ export function shouldBePretty(pretty: boolean | undefined): boolean {
70
+ if (pretty === undefined) {
71
+ return defaultIsPretty();
72
+ }
73
+ return pretty;
74
+ }
package/src/cli.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { parseArgs } from 'node:util';
2
2
  import { resolve } from '@css-modules-kit/core';
3
3
  import packageJson from '../package.json';
4
- import type { Logger } from './logger/logger.js';
4
+ import { ParseCLIArgsError } from './error.js';
5
5
 
6
6
  const helpText = `
7
7
  Usage: cmk [options]
@@ -10,35 +10,49 @@ Options:
10
10
  --help, -h Show help information
11
11
  --version, -v Show version number
12
12
  --project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
13
+ --pretty Enable color and formatting in output to make errors easier to read.
13
14
  `;
14
15
 
16
+ export function printHelpText(): void {
17
+ // eslint-disable-next-line no-console
18
+ console.log(helpText);
19
+ }
20
+
21
+ export function printVersion(): void {
22
+ // eslint-disable-next-line no-console
23
+ console.log(packageJson.version);
24
+ }
25
+
15
26
  export interface ParsedArgs {
27
+ help: boolean;
28
+ version: boolean;
16
29
  project: string;
30
+ pretty: boolean | undefined;
17
31
  }
18
32
 
19
33
  /**
20
34
  * Parse command-line arguments.
21
- * If `--help` or `--version` is passed, print the corresponding information and exit the process.
35
+ * @throws {ParseCLIArgsError} If failed to parse CLI arguments.
22
36
  */
23
- export function parseCLIArgs(args: string[], cwd: string, logger: Logger): ParsedArgs {
24
- const { values } = parseArgs({
25
- args,
26
- options: {
27
- help: { type: 'boolean', short: 'h' },
28
- version: { type: 'boolean', short: 'v' },
29
- project: { type: 'string', short: 'p', default: '.' },
30
- },
31
- });
32
- if (values.help) {
33
- logger.logMessage(helpText);
34
- // eslint-disable-next-line n/no-process-exit
35
- process.exit(0);
36
- } else if (values.version) {
37
- logger.logMessage(packageJson.version);
38
- // eslint-disable-next-line n/no-process-exit
39
- process.exit(0);
37
+ export function parseCLIArgs(args: string[], cwd: string): ParsedArgs {
38
+ try {
39
+ const { values } = parseArgs({
40
+ args,
41
+ options: {
42
+ help: { type: 'boolean', short: 'h', default: false },
43
+ version: { type: 'boolean', short: 'v', default: false },
44
+ project: { type: 'string', short: 'p', default: '.' },
45
+ pretty: { type: 'boolean' },
46
+ },
47
+ allowNegative: true,
48
+ });
49
+ return {
50
+ help: values.help,
51
+ version: values.version,
52
+ project: resolve(cwd, values.project),
53
+ pretty: values.pretty,
54
+ };
55
+ } catch (cause) {
56
+ throw new ParseCLIArgsError(cause);
40
57
  }
41
- return {
42
- project: resolve(cwd, values.project),
43
- };
44
58
  }
package/src/error.ts CHANGED
@@ -1,13 +1,19 @@
1
1
  import { SystemError } from '@css-modules-kit/core';
2
2
 
3
+ export class ParseCLIArgsError extends SystemError {
4
+ constructor(cause: unknown) {
5
+ super('PARSE_CLI_ARGS_ERROR', `Failed to parse CLI arguments.`, cause);
6
+ }
7
+ }
8
+
3
9
  export class WriteDtsFileError extends SystemError {
4
10
  constructor(fileName: string, cause: unknown) {
5
- super('WRITE_DTS_FILE_ERROR', `Failed to write .d.ts file ${fileName}.`, { cause });
11
+ super('WRITE_DTS_FILE_ERROR', `Failed to write .d.ts file ${fileName}.`, cause);
6
12
  }
7
13
  }
8
14
 
9
15
  export class ReadCSSModuleFileError extends SystemError {
10
16
  constructor(fileName: string, cause: unknown) {
11
- super('READ_CSS_MODULE_FILE_ERROR', `Failed to read CSS Module file ${fileName}.`, { cause });
17
+ super('READ_CSS_MODULE_FILE_ERROR', `Failed to read CSS Module file ${fileName}.`, cause);
12
18
  }
13
19
  }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { runCMK } from './runner.js';
2
2
  export { type Logger, createLogger } from './logger/logger.js';
3
3
  export { WriteDtsFileError, ReadCSSModuleFileError } from './error.js';
4
- export { parseCLIArgs } from './cli.js';
4
+ export { parseCLIArgs, printHelpText, printVersion } from './cli.js';
5
+ export { shouldBePretty } from './3rd-party/typescript.js';
@@ -1,53 +1,14 @@
1
- import { styleText } from 'node:util';
2
- import {
3
- type Diagnostic,
4
- type DiagnosticCategory,
5
- type DiagnosticPosition,
6
- relative,
7
- type SystemError,
8
- } from '@css-modules-kit/core';
9
-
10
- export function formatDiagnostic(diagnostic: Diagnostic, cwd: string): string {
1
+ import ts from 'typescript';
2
+
3
+ export function formatDiagnostics(
4
+ diagnostics: ts.Diagnostic[],
5
+ host: ts.FormatDiagnosticsHost,
6
+ pretty: boolean,
7
+ ): string {
8
+ const format = pretty ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics;
11
9
  let result = '';
12
- if (diagnostic.fileName) {
13
- result += `${formatLocation(diagnostic.fileName, diagnostic.start, cwd)} - `;
10
+ for (const diagnostic of diagnostics) {
11
+ result += format([diagnostic], host).replace(` TS${diagnostic.code}`, '') + host.getNewLine();
14
12
  }
15
- result += `${formatCategory(diagnostic.category)}: `;
16
- result += diagnostic.text;
17
- // TODO(#124): Add source code if diagnostics has a location
18
13
  return result;
19
14
  }
20
-
21
- export function formatSystemError(error: SystemError): string {
22
- let result = '';
23
- result += `${formatCategory('error')}`;
24
- result += ' ';
25
- result += styleText('gray', error.code);
26
- result += ': ';
27
- result += error.message;
28
- // TODO(#118): Include cause if exists
29
- return result;
30
- }
31
-
32
- function formatLocation(fileName: string, start: DiagnosticPosition | undefined, cwd: string): string {
33
- let result = '';
34
- result += styleText('cyan', relative(cwd, fileName));
35
- if (start !== undefined) {
36
- result += ':';
37
- result += styleText('yellow', start.line.toString());
38
- result += ':';
39
- result += styleText('yellow', start.column.toString());
40
- }
41
- return result;
42
- }
43
-
44
- function formatCategory(category: DiagnosticCategory): string {
45
- switch (category) {
46
- case 'error':
47
- return styleText('red', 'error');
48
- case 'warning':
49
- return styleText('yellow', 'warning');
50
- default:
51
- throw new Error(`Unknown diagnostic category: ${String(category)}`);
52
- }
53
- }
@@ -1,5 +1,7 @@
1
- import type { Diagnostic, SystemError } from '@css-modules-kit/core';
2
- import { formatDiagnostic, formatSystemError } from './formatter.js';
1
+ import type { DiagnosticSourceFile } from '@css-modules-kit/core';
2
+ import { convertDiagnostic, convertSystemError, type Diagnostic, type SystemError } from '@css-modules-kit/core';
3
+ import ts from 'typescript';
4
+ import { formatDiagnostics } from './formatter.js';
3
5
 
4
6
  export interface Logger {
5
7
  logDiagnostics(diagnostics: Diagnostic[]): void;
@@ -7,17 +9,29 @@ export interface Logger {
7
9
  logMessage(message: string): void;
8
10
  }
9
11
 
10
- export function createLogger(cwd: string): Logger {
12
+ export function createLogger(cwd: string, pretty: boolean): Logger {
13
+ const host: ts.FormatDiagnosticsHost = {
14
+ getCurrentDirectory: () => cwd,
15
+ getCanonicalFileName: (fileName) => (ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase()),
16
+ getNewLine: () => ts.sys.newLine,
17
+ };
18
+
19
+ function getSourceFile(file: DiagnosticSourceFile): ts.SourceFile {
20
+ return ts.createSourceFile(file.fileName, file.text, ts.ScriptTarget.JSON, undefined, ts.ScriptKind.Unknown);
21
+ }
22
+
11
23
  return {
12
24
  logDiagnostics(diagnostics: Diagnostic[]): void {
13
- let result = '';
14
- for (const diagnostic of diagnostics) {
15
- result += `${formatDiagnostic(diagnostic, cwd)}\n\n`;
16
- }
25
+ const result = formatDiagnostics(
26
+ diagnostics.map((d) => convertDiagnostic(d, getSourceFile)),
27
+ host,
28
+ pretty,
29
+ );
17
30
  process.stderr.write(result);
18
31
  },
19
32
  logSystemError(error: SystemError): void {
20
- process.stderr.write(`${formatSystemError(error)}\n`);
33
+ const result = formatDiagnostics([convertSystemError(error)], host, pretty);
34
+ process.stderr.write(result);
21
35
  },
22
36
  logMessage(message: string): void {
23
37
  process.stdout.write(`${message}\n`);
package/src/runner.ts CHANGED
@@ -2,11 +2,11 @@ import { readFile } from 'node:fs/promises';
2
2
  import type {
3
3
  CMKConfig,
4
4
  CSSModule,
5
+ Diagnostic,
6
+ DiagnosticWithLocation,
5
7
  MatchesPattern,
6
8
  ParseCSSModuleResult,
7
9
  Resolver,
8
- SemanticDiagnostic,
9
- SyntacticDiagnostic,
10
10
  } from '@css-modules-kit/core';
11
11
  import {
12
12
  checkCSSModule,
@@ -18,6 +18,7 @@ import {
18
18
  parseCSSModule,
19
19
  readConfigFile,
20
20
  } from '@css-modules-kit/core';
21
+ import ts from 'typescript';
21
22
  import { writeDtsFile } from './dts-writer.js';
22
23
  import { ReadCSSModuleFileError } from './error.js';
23
24
  import type { Logger } from './logger/logger.js';
@@ -55,7 +56,6 @@ async function writeDtsByCSSModule(
55
56
  /**
56
57
  * Run css-modules-kit .d.ts generation.
57
58
  * @param project The absolute path to the project directory or the path to `tsconfig.json`.
58
- * @throws {GlobError} When failed to retrieve files by glob pattern.
59
59
  * @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
60
60
  * @throws {WriteDtsFileError}
61
61
  */
@@ -67,17 +67,23 @@ export async function runCMK(project: string, logger: Logger): Promise<void> {
67
67
  process.exit(1);
68
68
  }
69
69
 
70
- const resolver = createResolver(config.compilerOptions);
70
+ const getCanonicalFileName = (fileName: string) =>
71
+ ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
72
+ const moduleResolutionCache = ts.createModuleResolutionCache(
73
+ config.basePath,
74
+ getCanonicalFileName,
75
+ config.compilerOptions,
76
+ );
77
+ const resolver = createResolver(config.compilerOptions, moduleResolutionCache);
71
78
  const matchesPattern = createMatchesPattern(config);
72
79
 
73
80
  const cssModuleMap = new Map<string, CSSModule>();
74
- const syntacticDiagnostics: SyntacticDiagnostic[] = [];
81
+ const syntacticDiagnostics: DiagnosticWithLocation[] = [];
75
82
 
76
83
  const fileNames = getFileNamesByPattern(config);
77
84
  if (fileNames.length === 0) {
78
85
  logger.logDiagnostics([
79
86
  {
80
- type: 'semantic',
81
87
  category: 'warning',
82
88
  text: `The file specified in tsconfig.json not found.`,
83
89
  },
@@ -98,7 +104,7 @@ export async function runCMK(project: string, logger: Logger): Promise<void> {
98
104
 
99
105
  const getCSSModule = (path: string) => cssModuleMap.get(path);
100
106
  const exportBuilder = createExportBuilder({ getCSSModule, matchesPattern, resolver });
101
- const semanticDiagnostics: SemanticDiagnostic[] = [];
107
+ const semanticDiagnostics: Diagnostic[] = [];
102
108
  for (const { cssModule } of parseResults) {
103
109
  const diagnostics = checkCSSModule(cssModule, exportBuilder, matchesPattern, resolver, getCSSModule);
104
110
  semanticDiagnostics.push(...diagnostics);