@css-modules-kit/codegen 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.
- package/README.md +7 -21
- package/dist/3rd-party/typescript.js +4 -11
- package/dist/3rd-party/typescript.js.map +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +21 -25
- package/dist/cli.js.map +1 -1
- package/dist/dts-writer.js +12 -16
- package/dist/dts-writer.js.map +1 -1
- package/dist/error.d.ts +4 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +9 -10
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -17
- package/dist/index.js.map +1 -1
- package/dist/logger/formatter.js +4 -11
- package/dist/logger/formatter.js.map +1 -1
- package/dist/logger/logger.js +13 -19
- package/dist/logger/logger.js.map +1 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +31 -25
- package/dist/project.js.map +1 -1
- package/dist/runner.d.ts +3 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +31 -20
- package/dist/runner.js.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +12 -7
- package/src/error.ts +11 -1
- package/src/index.ts +1 -1
- package/src/project.ts +15 -2
- package/src/runner.ts +22 -3
- /package/bin/{cmk.mjs → cmk.js} +0 -0
package/README.md
CHANGED
|
@@ -8,21 +8,6 @@ A tool for generating `*.d.ts` files for `*.module.css`.
|
|
|
8
8
|
npm i -D @css-modules-kit/codegen
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Requirements
|
|
12
|
-
|
|
13
|
-
Set `cmkOptions.dtsOutDir` and `"."` to `rootDirs`. This is necessary for the `tsc` command to load the generated `*.d.ts` files.
|
|
14
|
-
|
|
15
|
-
```json
|
|
16
|
-
{
|
|
17
|
-
"compilerOptions": {
|
|
18
|
-
"rootDirs": [".", "generated"] // Required
|
|
19
|
-
},
|
|
20
|
-
"cmkOptions": {
|
|
21
|
-
"dtsOutDir": "generated" // Default is `"generated"`, so it can be omitted
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
11
|
## Usage
|
|
27
12
|
|
|
28
13
|
From the command line, run the `cmk` command.
|
|
@@ -36,12 +21,13 @@ $ npx cmk --help
|
|
|
36
21
|
Usage: cmk [options]
|
|
37
22
|
|
|
38
23
|
Options:
|
|
39
|
-
--help, -h
|
|
40
|
-
--version, -v
|
|
41
|
-
--project, -p
|
|
42
|
-
--pretty
|
|
43
|
-
--clean
|
|
44
|
-
--watch, -w
|
|
24
|
+
--help, -h Show help information
|
|
25
|
+
--version, -v Show version number
|
|
26
|
+
--project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
27
|
+
--pretty Enable color and formatting in output to make errors easier to read.
|
|
28
|
+
--clean Remove the output directory before generating files. [default: false]
|
|
29
|
+
--watch, -w Watch for changes and regenerate files. [default: false]
|
|
30
|
+
--preserveWatchOutput Disable wiping the console in watch mode. [default: false]
|
|
45
31
|
```
|
|
46
32
|
|
|
47
33
|
## Configuration
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @fileoverview
|
|
4
3
|
* This is forked from microsoft/TypeScript.
|
|
@@ -60,17 +59,11 @@
|
|
|
60
59
|
*
|
|
61
60
|
* END OF TERMS AND CONDITIONS
|
|
62
61
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
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'];
|
|
62
|
+
import ts from 'typescript';
|
|
63
|
+
export function defaultIsPretty() {
|
|
64
|
+
return !!ts.sys.writeOutputIsTTY && ts.sys.writeOutputIsTTY() && !process.env['NO_COLOR'];
|
|
72
65
|
}
|
|
73
|
-
function shouldBePretty(pretty) {
|
|
66
|
+
export function shouldBePretty(pretty) {
|
|
74
67
|
if (pretty === undefined) {
|
|
75
68
|
return defaultIsPretty();
|
|
76
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/3rd-party/typescript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/3rd-party/typescript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC5F,CAAC;AAED,MAAM,UAAU,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
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAmBA,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;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CA2BpE"}
|
package/dist/cli.js
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.printHelpText = printHelpText;
|
|
7
|
-
exports.printVersion = printVersion;
|
|
8
|
-
exports.parseCLIArgs = parseCLIArgs;
|
|
9
|
-
const node_util_1 = require("node:util");
|
|
10
|
-
const core_1 = require("@css-modules-kit/core");
|
|
11
|
-
const package_json_1 = __importDefault(require("../package.json"));
|
|
12
|
-
const error_js_1 = require("./error.js");
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { resolve } from '@css-modules-kit/core';
|
|
3
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
4
|
+
import { ParseCLIArgsError } from './error.js';
|
|
5
|
+
// NOTE: Keep this help text in sync with the one in packages/codegen/README.md.
|
|
13
6
|
const helpText = `
|
|
14
7
|
Usage: cmk [options]
|
|
15
8
|
|
|
16
9
|
Options:
|
|
17
|
-
--help, -h
|
|
18
|
-
--version, -v
|
|
19
|
-
--project, -p
|
|
20
|
-
--pretty
|
|
21
|
-
--clean
|
|
22
|
-
--watch, -w
|
|
10
|
+
--help, -h Show help information
|
|
11
|
+
--version, -v Show version number
|
|
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.
|
|
14
|
+
--clean Remove the output directory before generating files. [default: false]
|
|
15
|
+
--watch, -w Watch for changes and regenerate files. [default: false]
|
|
16
|
+
--preserveWatchOutput Disable wiping the console in watch mode. [default: false]
|
|
23
17
|
`;
|
|
24
|
-
function printHelpText() {
|
|
18
|
+
export function printHelpText() {
|
|
25
19
|
// eslint-disable-next-line no-console
|
|
26
20
|
console.log(helpText);
|
|
27
21
|
}
|
|
28
|
-
function printVersion() {
|
|
22
|
+
export function printVersion() {
|
|
29
23
|
// eslint-disable-next-line no-console
|
|
30
|
-
console.log(
|
|
24
|
+
console.log(packageJson.version);
|
|
31
25
|
}
|
|
32
26
|
/**
|
|
33
27
|
* Parse command-line arguments.
|
|
34
28
|
* @throws {ParseCLIArgsError} If failed to parse CLI arguments.
|
|
35
29
|
*/
|
|
36
|
-
function parseCLIArgs(args, cwd) {
|
|
30
|
+
export function parseCLIArgs(args, cwd) {
|
|
37
31
|
try {
|
|
38
|
-
const { values } =
|
|
32
|
+
const { values } = parseArgs({
|
|
39
33
|
args,
|
|
40
34
|
options: {
|
|
41
35
|
help: { type: 'boolean', short: 'h', default: false },
|
|
@@ -44,20 +38,22 @@ function parseCLIArgs(args, cwd) {
|
|
|
44
38
|
pretty: { type: 'boolean' },
|
|
45
39
|
clean: { type: 'boolean', default: false },
|
|
46
40
|
watch: { type: 'boolean', short: 'w', default: false },
|
|
41
|
+
preserveWatchOutput: { type: 'boolean', default: false },
|
|
47
42
|
},
|
|
48
43
|
allowNegative: true,
|
|
49
44
|
});
|
|
50
45
|
return {
|
|
51
46
|
help: values.help,
|
|
52
47
|
version: values.version,
|
|
53
|
-
project:
|
|
48
|
+
project: resolve(cwd, values.project),
|
|
54
49
|
pretty: values.pretty,
|
|
55
50
|
clean: values.clean,
|
|
56
51
|
watch: values.watch,
|
|
52
|
+
preserveWatchOutput: values.preserveWatchOutput,
|
|
57
53
|
};
|
|
58
54
|
}
|
|
59
55
|
catch (cause) {
|
|
60
|
-
throw new
|
|
56
|
+
throw new ParseCLIArgsError(cause);
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
59
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,gFAAgF;AAChF,MAAM,QAAQ,GAAG;;;;;;;;;;;CAWhB,CAAC;AAEF,MAAM,UAAU,aAAa;IAC3B,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAYD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc,EAAE,GAAW;IACtD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;YAC3B,IAAI;YACJ,OAAO,EAAE;gBACP,IAAI,EAAE,EAAE,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;gBAC3B,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;gBAC1C,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;gBACtD,mBAAmB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;aACzD;YACD,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC;YACrC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;SAChD,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
|
package/dist/dts-writer.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.writeDtsFile = writeDtsFile;
|
|
5
|
-
const promises_1 = require("node:fs/promises");
|
|
6
|
-
const core_1 = require("@css-modules-kit/core");
|
|
7
|
-
const error_js_1 = require("./error.js");
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, parse, relative, resolve } from '@css-modules-kit/core';
|
|
3
|
+
import { WriteDtsFileError } from './error.js';
|
|
8
4
|
/**
|
|
9
5
|
* Get .d.ts file path.
|
|
10
6
|
* @param cssModuleFileName The path to the CSS Module file (i.e. `/src/foo.module.css`). It is absolute.
|
|
11
7
|
* @param options Output directory options
|
|
12
8
|
* @returns The path to the .d.ts file. It is absolute.
|
|
13
9
|
*/
|
|
14
|
-
function getDtsFilePath(cssModuleFileName, options) {
|
|
15
|
-
const relativePath =
|
|
16
|
-
const outputFilePath =
|
|
10
|
+
export function getDtsFilePath(cssModuleFileName, options) {
|
|
11
|
+
const relativePath = relative(options.basePath, cssModuleFileName);
|
|
12
|
+
const outputFilePath = resolve(options.outDir, relativePath);
|
|
17
13
|
if (options.arbitraryExtensions) {
|
|
18
|
-
const { dir, name, ext } =
|
|
19
|
-
return
|
|
14
|
+
const { dir, name, ext } = parse(outputFilePath);
|
|
15
|
+
return join(dir, `${name}.d${ext}.ts`);
|
|
20
16
|
}
|
|
21
17
|
else {
|
|
22
18
|
return `${outputFilePath}.d.ts`;
|
|
@@ -29,14 +25,14 @@ function getDtsFilePath(cssModuleFileName, options) {
|
|
|
29
25
|
* @param options Options for writing the d.ts file.
|
|
30
26
|
* @throws {WriteDtsFileError} When the file cannot be written.
|
|
31
27
|
*/
|
|
32
|
-
async function writeDtsFile(text, cssModuleFileName, options) {
|
|
28
|
+
export async function writeDtsFile(text, cssModuleFileName, options) {
|
|
33
29
|
const dtsFileName = getDtsFilePath(cssModuleFileName, options);
|
|
34
30
|
try {
|
|
35
|
-
await
|
|
36
|
-
await
|
|
31
|
+
await mkdir(dirname(dtsFileName), { recursive: true });
|
|
32
|
+
await writeFile(dtsFileName, text);
|
|
37
33
|
}
|
|
38
34
|
catch (error) {
|
|
39
|
-
throw new
|
|
35
|
+
throw new WriteDtsFileError(dtsFileName, error);
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
38
|
//# sourceMappingURL=dts-writer.js.map
|
package/dist/dts-writer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dts-writer.js","sourceRoot":"","sources":["../src/dts-writer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dts-writer.js","sourceRoot":"","sources":["../src/dts-writer.ts"],"names":[],"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@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CMKConfig } from '@css-modules-kit/core';
|
|
1
2
|
import { SystemError } from '@css-modules-kit/core';
|
|
2
3
|
export declare class ParseCLIArgsError extends SystemError {
|
|
3
4
|
constructor(cause: unknown);
|
|
@@ -8,4 +9,7 @@ export declare class WriteDtsFileError extends SystemError {
|
|
|
8
9
|
export declare class ReadCSSModuleFileError extends SystemError {
|
|
9
10
|
constructor(fileName: string, cause: unknown);
|
|
10
11
|
}
|
|
12
|
+
export declare class CMKDisabledError extends SystemError {
|
|
13
|
+
constructor(config: CMKConfig);
|
|
14
|
+
}
|
|
11
15
|
//# sourceMappingURL=error.d.ts.map
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAY,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE9D,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;AAED,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,MAAM,EAAE,SAAS;CAM9B"}
|
package/dist/error.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ReadCSSModuleFileError = exports.WriteDtsFileError = exports.ParseCLIArgsError = void 0;
|
|
4
|
-
const core_1 = require("@css-modules-kit/core");
|
|
5
|
-
class ParseCLIArgsError extends core_1.SystemError {
|
|
1
|
+
import { relative, SystemError } from '@css-modules-kit/core';
|
|
2
|
+
export class ParseCLIArgsError extends SystemError {
|
|
6
3
|
constructor(cause) {
|
|
7
4
|
super('PARSE_CLI_ARGS_ERROR', `Failed to parse CLI arguments.`, cause);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
class WriteDtsFileError extends core_1.SystemError {
|
|
7
|
+
export class WriteDtsFileError extends SystemError {
|
|
12
8
|
constructor(fileName, cause) {
|
|
13
9
|
super('WRITE_DTS_FILE_ERROR', `Failed to write .d.ts file ${fileName}.`, cause);
|
|
14
10
|
}
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
class ReadCSSModuleFileError extends core_1.SystemError {
|
|
12
|
+
export class ReadCSSModuleFileError extends SystemError {
|
|
18
13
|
constructor(fileName, cause) {
|
|
19
14
|
super('READ_CSS_MODULE_FILE_ERROR', `Failed to read CSS Module file ${fileName}.`, cause);
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
|
-
|
|
17
|
+
export class CMKDisabledError extends SystemError {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super('CMK_DISABLED_ERROR', `css-modules-kit is disabled by configuration. Set \`"cmkOptions": { "enabled": true }\` in ${relative(config.basePath, config.configFileName)} to enable it.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
23
22
|
//# sourceMappingURL=error.js.map
|
package/dist/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAChD,YAAY,KAAc;QACxB,KAAK,CAAC,sBAAsB,EAAE,gCAAgC,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAChD,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,sBAAsB,EAAE,8BAA8B,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;IAClF,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,4BAA4B,EAAE,kCAAkC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5F,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAC/C,YAAY,MAAiB;QAC3B,KAAK,CACH,oBAAoB,EACpB,8FAA8F,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAC/J,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { runCMK, runCMKInWatchMode } from './runner.js';
|
|
2
2
|
export { type Logger, createLogger } from './logger/logger.js';
|
|
3
|
-
export { WriteDtsFileError, ReadCSSModuleFileError } from './error.js';
|
|
3
|
+
export { WriteDtsFileError, ReadCSSModuleFileError, CMKDisabledError } from './error.js';
|
|
4
4
|
export { parseCLIArgs, printHelpText, printVersion } from './cli.js';
|
|
5
5
|
export { shouldBePretty } from './3rd-party/typescript.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACzF,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,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "runCMKInWatchMode", { enumerable: true, get: function () { return runner_js_1.runCMKInWatchMode; } });
|
|
7
|
-
var logger_js_1 = require("./logger/logger.js");
|
|
8
|
-
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return logger_js_1.createLogger; } });
|
|
9
|
-
var error_js_1 = require("./error.js");
|
|
10
|
-
Object.defineProperty(exports, "WriteDtsFileError", { enumerable: true, get: function () { return error_js_1.WriteDtsFileError; } });
|
|
11
|
-
Object.defineProperty(exports, "ReadCSSModuleFileError", { enumerable: true, get: function () { return error_js_1.ReadCSSModuleFileError; } });
|
|
12
|
-
var cli_js_1 = require("./cli.js");
|
|
13
|
-
Object.defineProperty(exports, "parseCLIArgs", { enumerable: true, get: function () { return cli_js_1.parseCLIArgs; } });
|
|
14
|
-
Object.defineProperty(exports, "printHelpText", { enumerable: true, get: function () { return cli_js_1.printHelpText; } });
|
|
15
|
-
Object.defineProperty(exports, "printVersion", { enumerable: true, get: function () { return cli_js_1.printVersion; } });
|
|
16
|
-
var typescript_js_1 = require("./3rd-party/typescript.js");
|
|
17
|
-
Object.defineProperty(exports, "shouldBePretty", { enumerable: true, get: function () { return typescript_js_1.shouldBePretty; } });
|
|
1
|
+
export { runCMK, runCMKInWatchMode } from './runner.js';
|
|
2
|
+
export { createLogger } from './logger/logger.js';
|
|
3
|
+
export { WriteDtsFileError, ReadCSSModuleFileError, CMKDisabledError } from './error.js';
|
|
4
|
+
export { parseCLIArgs, printHelpText, printVersion } from './cli.js';
|
|
5
|
+
export { shouldBePretty } from './3rd-party/typescript.js';
|
|
18
6
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAe,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/logger/formatter.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
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.formatDiagnostics = formatDiagnostics;
|
|
7
|
-
exports.formatTime = formatTime;
|
|
8
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
1
|
+
import ts from 'typescript';
|
|
9
2
|
const GRAY = '\u001b[90m';
|
|
10
3
|
const RESET = '\u001b[0m';
|
|
11
|
-
function formatDiagnostics(diagnostics, host, pretty) {
|
|
12
|
-
const format = pretty ?
|
|
4
|
+
export function formatDiagnostics(diagnostics, host, pretty) {
|
|
5
|
+
const format = pretty ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics;
|
|
13
6
|
let result = '';
|
|
14
7
|
for (const diagnostic of diagnostics) {
|
|
15
8
|
result += format([diagnostic], host).replace(` TS${diagnostic.code}`, '') + host.getNewLine();
|
|
16
9
|
}
|
|
17
10
|
return result;
|
|
18
11
|
}
|
|
19
|
-
function formatTime(date, pretty) {
|
|
12
|
+
export function formatTime(date, pretty) {
|
|
20
13
|
const text = date.toLocaleTimeString('en-US', { timeZone: 'UTC' });
|
|
21
14
|
if (pretty) {
|
|
22
15
|
return `[${GRAY}${text}${RESET}]`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/logger/formatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/logger/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,IAAI,GAAG,YAAY,CAAC;AAC1B,MAAM,KAAK,GAAG,WAAW,CAAC;AAE1B,MAAM,UAAU,iBAAiB,CAC/B,WAA4B,EAC5B,IAA8B,EAC9B,MAAe;IAEf,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,oCAAoC,CAAC,CAAC,CAAC,EAAE,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;AAED,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,MAAe;IACpD,MAAM,IAAI,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACnE,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,IAAI,GAAG,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/logger/logger.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.createLogger = createLogger;
|
|
7
|
-
const node_util_1 = require("node:util");
|
|
8
|
-
const core_1 = require("@css-modules-kit/core");
|
|
9
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
-
const formatter_js_1 = require("./formatter.js");
|
|
11
|
-
function createLogger(cwd, pretty) {
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { convertDiagnostic, convertSystemError, SystemError } from '@css-modules-kit/core';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { formatDiagnostics, formatTime } from './formatter.js';
|
|
5
|
+
export function createLogger(cwd, pretty) {
|
|
12
6
|
const host = {
|
|
13
7
|
getCurrentDirectory: () => cwd,
|
|
14
|
-
getCanonicalFileName: (fileName) => (
|
|
15
|
-
getNewLine: () =>
|
|
8
|
+
getCanonicalFileName: (fileName) => (ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase()),
|
|
9
|
+
getNewLine: () => ts.sys.newLine,
|
|
16
10
|
};
|
|
17
11
|
function getSourceFile(file) {
|
|
18
|
-
return
|
|
12
|
+
return ts.createSourceFile(file.fileName, file.text, ts.ScriptTarget.JSON, undefined, ts.ScriptKind.Unknown);
|
|
19
13
|
}
|
|
20
14
|
return {
|
|
21
15
|
logDiagnostics(diagnostics) {
|
|
22
|
-
const result =
|
|
16
|
+
const result = formatDiagnostics(diagnostics.map((d) => convertDiagnostic(d, getSourceFile)), host, pretty);
|
|
23
17
|
process.stderr.write(result);
|
|
24
18
|
},
|
|
25
19
|
logError(error) {
|
|
@@ -27,16 +21,16 @@ function createLogger(cwd, pretty) {
|
|
|
27
21
|
// These errors are formatted clearly and concisely. No stack trace is output.
|
|
28
22
|
//
|
|
29
23
|
// All other errors are unexpected errors. To assist in debugging when these errors occur, a stack trace is output.
|
|
30
|
-
if (error instanceof
|
|
31
|
-
const result =
|
|
24
|
+
if (error instanceof SystemError) {
|
|
25
|
+
const result = formatDiagnostics([convertSystemError(error)], host, pretty);
|
|
32
26
|
process.stderr.write(result);
|
|
33
27
|
}
|
|
34
28
|
else {
|
|
35
|
-
process.stderr.write(`${
|
|
29
|
+
process.stderr.write(`${inspect(error, { colors: pretty })}\n`);
|
|
36
30
|
}
|
|
37
31
|
},
|
|
38
32
|
logMessage(message, options) {
|
|
39
|
-
const header = options?.time ? `${
|
|
33
|
+
const header = options?.time ? `${formatTime(new Date(), pretty)} ` : '';
|
|
40
34
|
process.stdout.write(`${header}${message}\n`);
|
|
41
35
|
},
|
|
42
36
|
clearScreen() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAmB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC5G,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gB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AAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QACD,UAAU,CAAC,OAAe,EAAE,OAA4B;YACtD,MAAM,MAAM,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,OAAO,IAAI,CAAC,CAAC;QAChD,CAAC;QACD,WAAW;YACT,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/project.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAEL,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAEL,KAAK,SAAS,EASf,MAAM,uBAAuB,CAAC;AAK/B,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,SAAS,CAAC;IAClB,sFAAsF;IACtF,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACjD;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,sCAAsC;IACtC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC;;;;;;;OAOG;IACH,cAAc,IAAI,UAAU,EAAE,CAAC;IAC/B;;;OAGG;IACH,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAgLxD"}
|
package/dist/project.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.createProject = createProject;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const core_1 = require("@css-modules-kit/core");
|
|
9
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
-
const dts_writer_js_1 = require("./dts-writer.js");
|
|
11
|
-
const error_js_1 = require("./error.js");
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { checkCSSModule, createExportBuilder, createMatchesPattern, createResolver, generateDts, getFileNamesByPattern, parseCSSModule, readConfigFile, relative, } from '@css-modules-kit/core';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { writeDtsFile } from './dts-writer.js';
|
|
5
|
+
import { ReadCSSModuleFileError } from './error.js';
|
|
12
6
|
/**
|
|
13
7
|
* Create a Project instance.
|
|
14
8
|
* Project is like a facade that calls core operations such as loading settings, parsing CSS Module files, and performing checks.
|
|
@@ -16,19 +10,19 @@ const error_js_1 = require("./error.js");
|
|
|
16
10
|
* @throws {TsConfigFileNotFoundError}
|
|
17
11
|
* @throws {ReadCSSModuleFileError}
|
|
18
12
|
*/
|
|
19
|
-
function createProject(args) {
|
|
20
|
-
const config =
|
|
21
|
-
const getCanonicalFileName = (fileName) =>
|
|
22
|
-
const moduleResolutionCache =
|
|
23
|
-
const resolver =
|
|
24
|
-
const matchesPattern =
|
|
13
|
+
export function createProject(args) {
|
|
14
|
+
const config = readConfigFile(args.project);
|
|
15
|
+
const getCanonicalFileName = (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
|
16
|
+
const moduleResolutionCache = ts.createModuleResolutionCache(config.basePath, getCanonicalFileName, config.compilerOptions);
|
|
17
|
+
const resolver = createResolver(config.compilerOptions, moduleResolutionCache);
|
|
18
|
+
const matchesPattern = createMatchesPattern(config);
|
|
25
19
|
const cssModuleMap = new Map();
|
|
26
20
|
const semanticDiagnosticsMap = new Map();
|
|
27
21
|
// Tracks whether .d.ts has been emitted after the last change
|
|
28
22
|
const emittedSet = new Set();
|
|
29
23
|
const getCSSModule = (path) => cssModuleMap.get(path);
|
|
30
|
-
const exportBuilder =
|
|
31
|
-
for (const fileName of
|
|
24
|
+
const exportBuilder = createExportBuilder({ getCSSModule, matchesPattern, resolver });
|
|
25
|
+
for (const fileName of getFileNamesByPattern(config)) {
|
|
32
26
|
// NOTE: Files may be deleted between executing `getFileNamesByPattern` and `tryParseCSSModule`.
|
|
33
27
|
// Therefore, `tryParseCSSModule` may return `undefined`.
|
|
34
28
|
const cssModule = tryParseCSSModule(fileName);
|
|
@@ -89,15 +83,15 @@ function createProject(args) {
|
|
|
89
83
|
// - Using an asynchronous API makes `addFile` asynchronous too.
|
|
90
84
|
// - If `deleteFile` runs while `addFile` is executing, a race condition occurs.
|
|
91
85
|
// - Avoiding this requires something like a mutex. However, implementing that is cumbersome.
|
|
92
|
-
text =
|
|
86
|
+
text = readFileSync(fileName, 'utf-8');
|
|
93
87
|
}
|
|
94
88
|
catch (error) {
|
|
95
89
|
if (isNodeJSSystemError(error) && error.code === 'ENOENT') {
|
|
96
90
|
return undefined;
|
|
97
91
|
}
|
|
98
|
-
throw new
|
|
92
|
+
throw new ReadCSSModuleFileError(fileName, error);
|
|
99
93
|
}
|
|
100
|
-
return
|
|
94
|
+
return parseCSSModule(text, { fileName, includeSyntaxError: true, keyframes: config.keyframes });
|
|
101
95
|
}
|
|
102
96
|
function getDiagnostics() {
|
|
103
97
|
const diagnostics = [...getProjectDiagnostics(), ...getSyntacticDiagnostics()];
|
|
@@ -110,6 +104,12 @@ function createProject(args) {
|
|
|
110
104
|
function getProjectDiagnostics() {
|
|
111
105
|
const diagnostics = [];
|
|
112
106
|
diagnostics.push(...config.diagnostics);
|
|
107
|
+
if (config.enabled === undefined) {
|
|
108
|
+
diagnostics.push({
|
|
109
|
+
category: 'warning',
|
|
110
|
+
text: `"cmkOptions.enabled" will be required in a future version of css-modules-kit. Add \`"cmkOptions": { "enabled": true }\` to ${relative(config.basePath, config.configFileName)}. See https://github.com/mizdra/css-modules-kit/issues/289 for details.`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
113
|
if (cssModuleMap.size === 0) {
|
|
114
114
|
diagnostics.push({
|
|
115
115
|
category: 'error',
|
|
@@ -126,7 +126,13 @@ function createProject(args) {
|
|
|
126
126
|
for (const cssModule of cssModuleMap.values()) {
|
|
127
127
|
let diagnostics = semanticDiagnosticsMap.get(cssModule.fileName);
|
|
128
128
|
if (!diagnostics) {
|
|
129
|
-
diagnostics =
|
|
129
|
+
diagnostics = checkCSSModule(cssModule, {
|
|
130
|
+
config,
|
|
131
|
+
getExportRecord: (m) => exportBuilder.build(m),
|
|
132
|
+
matchesPattern,
|
|
133
|
+
resolver,
|
|
134
|
+
getCSSModule,
|
|
135
|
+
});
|
|
130
136
|
semanticDiagnosticsMap.set(cssModule.fileName, diagnostics);
|
|
131
137
|
}
|
|
132
138
|
allDiagnostics.push(...diagnostics);
|
|
@@ -141,8 +147,8 @@ function createProject(args) {
|
|
|
141
147
|
for (const cssModule of cssModuleMap.values()) {
|
|
142
148
|
if (emittedSet.has(cssModule.fileName))
|
|
143
149
|
continue;
|
|
144
|
-
const dts =
|
|
145
|
-
promises.push(
|
|
150
|
+
const dts = generateDts(cssModule, { ...config, forTsPlugin: false });
|
|
151
|
+
promises.push(writeDtsFile(dts.text, cssModule.fileName, {
|
|
146
152
|
outDir: config.dtsOutDir,
|
|
147
153
|
basePath: config.basePath,
|
|
148
154
|
arbitraryExtensions: config.arbitraryExtensions,
|
package/dist/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAsCpD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAiB;IAC7C,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE5C,MAAM,oBAAoB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAChD,EAAE,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;IACvE,MAAM,qBAAqB,GAAG,EAAE,CAAC,2BAA2B,CAC1D,MAAM,CAAC,QAAQ,EACf,oBAAoB,EACpB,MAAM,CAAC,eAAe,CACvB,CAAC;IACF,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;IAC/E,MAAM,cAAc,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAEpD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;IAClD,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAwB,C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mB,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC1G,CAAC"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type Project } from './project.js';
|
|
|
3
3
|
interface RunnerArgs {
|
|
4
4
|
project: string;
|
|
5
5
|
clean: boolean;
|
|
6
|
+
preserveWatchOutput: boolean;
|
|
6
7
|
}
|
|
7
8
|
export interface Watcher {
|
|
8
9
|
/** Exported for testing purposes */
|
|
@@ -12,6 +13,7 @@ export interface Watcher {
|
|
|
12
13
|
/**
|
|
13
14
|
* Run css-modules-kit .d.ts generation.
|
|
14
15
|
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
16
|
+
* @throws {CMKDisabledError} When css-modules-kit is disabled.
|
|
15
17
|
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
|
|
16
18
|
* @throws {WriteDtsFileError}
|
|
17
19
|
* @returns Whether the process succeeded without errors.
|
|
@@ -25,6 +27,7 @@ export declare function runCMK(args: RunnerArgs, logger: Logger): Promise<boolea
|
|
|
25
27
|
*
|
|
26
28
|
* NOTE: For implementation simplicity, config file changes are not watched.
|
|
27
29
|
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
30
|
+
* @throws {CMKDisabledError} When css-modules-kit is disabled.
|
|
28
31
|
* @throws {TsConfigFileNotFoundError}
|
|
29
32
|
* @throws {ReadCSSModuleFileError}
|
|
30
33
|
* @throws {WriteDtsFileError}
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAE3D,UAAU,UAAU;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,OAAO;IACtB,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB/E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA6G1F"}
|
package/dist/runner.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.runCMK = runCMK;
|
|
7
|
-
exports.runCMKInWatchMode = runCMKInWatchMode;
|
|
8
|
-
const promises_1 = require("node:fs/promises");
|
|
9
|
-
const chokidar_1 = __importDefault(require("chokidar"));
|
|
10
|
-
const project_js_1 = require("./project.js");
|
|
1
|
+
import { rm } from 'node:fs/promises';
|
|
2
|
+
import chokidar from 'chokidar';
|
|
3
|
+
import { CMKDisabledError } from './error.js';
|
|
4
|
+
import { createProject } from './project.js';
|
|
11
5
|
/**
|
|
12
6
|
* Run css-modules-kit .d.ts generation.
|
|
13
7
|
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
8
|
+
* @throws {CMKDisabledError} When css-modules-kit is disabled.
|
|
14
9
|
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
|
|
15
10
|
* @throws {WriteDtsFileError}
|
|
16
11
|
* @returns Whether the process succeeded without errors.
|
|
17
12
|
*/
|
|
18
|
-
async function runCMK(args, logger) {
|
|
19
|
-
const project =
|
|
13
|
+
export async function runCMK(args, logger) {
|
|
14
|
+
const project = createProject(args);
|
|
15
|
+
if (project.config.enabled === false) {
|
|
16
|
+
throw new CMKDisabledError(project.config);
|
|
17
|
+
}
|
|
20
18
|
if (args.clean) {
|
|
21
|
-
await
|
|
19
|
+
await rm(project.config.dtsOutDir, { recursive: true, force: true });
|
|
22
20
|
}
|
|
23
21
|
await project.emitDtsFiles();
|
|
24
22
|
const diagnostics = project.getDiagnostics();
|
|
25
23
|
if (diagnostics.length > 0) {
|
|
26
24
|
logger.logDiagnostics(diagnostics);
|
|
27
|
-
|
|
25
|
+
const hasErrors = diagnostics.some((d) => d.category === 'error');
|
|
26
|
+
return !hasErrors;
|
|
28
27
|
}
|
|
29
28
|
return true;
|
|
30
29
|
}
|
|
@@ -36,16 +35,20 @@ async function runCMK(args, logger) {
|
|
|
36
35
|
*
|
|
37
36
|
* NOTE: For implementation simplicity, config file changes are not watched.
|
|
38
37
|
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
38
|
+
* @throws {CMKDisabledError} When css-modules-kit is disabled.
|
|
39
39
|
* @throws {TsConfigFileNotFoundError}
|
|
40
40
|
* @throws {ReadCSSModuleFileError}
|
|
41
41
|
* @throws {WriteDtsFileError}
|
|
42
42
|
*/
|
|
43
|
-
async function runCMKInWatchMode(args, logger) {
|
|
43
|
+
export async function runCMKInWatchMode(args, logger) {
|
|
44
44
|
const fsWatchers = [];
|
|
45
|
-
const project =
|
|
45
|
+
const project = createProject(args);
|
|
46
|
+
if (project.config.enabled === false) {
|
|
47
|
+
throw new CMKDisabledError(project.config);
|
|
48
|
+
}
|
|
46
49
|
let emitAndReportDiagnosticsTimer = undefined;
|
|
47
50
|
if (args.clean) {
|
|
48
|
-
await
|
|
51
|
+
await rm(project.config.dtsOutDir, { recursive: true, force: true });
|
|
49
52
|
}
|
|
50
53
|
await emitAndReportDiagnostics();
|
|
51
54
|
// Watch project files and report diagnostics on changes
|
|
@@ -53,7 +56,7 @@ async function runCMKInWatchMode(args, logger) {
|
|
|
53
56
|
for (const wildcardDirectory of project.config.wildcardDirectories) {
|
|
54
57
|
const { promise, resolve } = promiseWithResolvers();
|
|
55
58
|
readyPromises.push(promise);
|
|
56
|
-
fsWatchers.push(
|
|
59
|
+
fsWatchers.push(chokidar
|
|
57
60
|
.watch(wildcardDirectory.fileName, {
|
|
58
61
|
ignored: (fileName, stats) => {
|
|
59
62
|
// The ignored function is called twice for the same path. The first time with stats undefined,
|
|
@@ -117,13 +120,21 @@ async function runCMKInWatchMode(args, logger) {
|
|
|
117
120
|
* @throws {WriteDtsFileError}
|
|
118
121
|
*/
|
|
119
122
|
async function emitAndReportDiagnostics() {
|
|
120
|
-
|
|
123
|
+
if (!args.preserveWatchOutput) {
|
|
124
|
+
logger.clearScreen();
|
|
125
|
+
}
|
|
121
126
|
await project.emitDtsFiles();
|
|
122
127
|
const diagnostics = project.getDiagnostics();
|
|
123
128
|
if (diagnostics.length > 0) {
|
|
124
129
|
logger.logDiagnostics(diagnostics);
|
|
125
130
|
}
|
|
126
|
-
|
|
131
|
+
const errorCount = diagnostics.filter((d) => d.category === 'error').length;
|
|
132
|
+
const warningCount = diagnostics.filter((d) => d.category === 'warning').length;
|
|
133
|
+
const warningPart = warningCount > 0 ? ` and ${warningCount} warning${warningCount === 1 ? '' : 's'}` : '';
|
|
134
|
+
logger.logMessage(`Found ${errorCount} error${errorCount === 1 ? '' : 's'}${warningPart}. Watching for file changes.`, { time: true });
|
|
135
|
+
if (args.preserveWatchOutput) {
|
|
136
|
+
logger.logMessage('');
|
|
137
|
+
}
|
|
127
138
|
}
|
|
128
139
|
async function close() {
|
|
129
140
|
await Promise.all(fsWatchers.map(async (watcher) => watcher.close()));
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,QAA4B,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AAc3D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAgB,EAAE,MAAc;IAC3D,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,IAAI,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC7C,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACnC,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;QAClE,OAAO,CAAC,SAAS,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IA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EAAE,IAAI,EAAE,CACf,CAAC;QACF,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC7B,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,KAAK,UAAU,KAAK;QAClB,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,SAAS,oBAAoB;IAC3B,IAAI,OAAO,CAAC;IACZ,IAAI,MAAM,CAAC;IACX,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,OAAO,GAAG,GAAG,CAAC;QACd,MAAM,GAAG,GAAG,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO;QACL,OAAO;QACP,OAAO,EAAE,OAAwC;QACjD,MAAM,EAAE,MAA+C;KACxD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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.
|
|
5
|
-
"type": "
|
|
4
|
+
"version": "0.8.0",
|
|
5
|
+
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"registry": "https://registry.npmjs.org/"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
|
-
"cmk": "bin/cmk.
|
|
26
|
+
"cmk": "bin/cmk.js"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [
|
|
29
29
|
"css-modules",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@css-modules-kit/core": "^0.
|
|
41
|
+
"@css-modules-kit/core": "^0.8.0",
|
|
42
42
|
"chokidar": "^4.0.3"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
package/src/cli.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
import { resolve } from '@css-modules-kit/core';
|
|
3
|
-
import packageJson from '../package.json';
|
|
3
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
4
4
|
import { ParseCLIArgsError } from './error.js';
|
|
5
5
|
|
|
6
|
+
// NOTE: Keep this help text in sync with the one in packages/codegen/README.md.
|
|
6
7
|
const helpText = `
|
|
7
8
|
Usage: cmk [options]
|
|
8
9
|
|
|
9
10
|
Options:
|
|
10
|
-
--help, -h
|
|
11
|
-
--version, -v
|
|
12
|
-
--project, -p
|
|
13
|
-
--pretty
|
|
14
|
-
--clean
|
|
15
|
-
--watch, -w
|
|
11
|
+
--help, -h Show help information
|
|
12
|
+
--version, -v Show version number
|
|
13
|
+
--project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
14
|
+
--pretty Enable color and formatting in output to make errors easier to read.
|
|
15
|
+
--clean Remove the output directory before generating files. [default: false]
|
|
16
|
+
--watch, -w Watch for changes and regenerate files. [default: false]
|
|
17
|
+
--preserveWatchOutput Disable wiping the console in watch mode. [default: false]
|
|
16
18
|
`;
|
|
17
19
|
|
|
18
20
|
export function printHelpText(): void {
|
|
@@ -32,6 +34,7 @@ export interface ParsedArgs {
|
|
|
32
34
|
pretty: boolean | undefined;
|
|
33
35
|
clean: boolean;
|
|
34
36
|
watch: boolean;
|
|
37
|
+
preserveWatchOutput: boolean;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -49,6 +52,7 @@ export function parseCLIArgs(args: string[], cwd: string): ParsedArgs {
|
|
|
49
52
|
pretty: { type: 'boolean' },
|
|
50
53
|
clean: { type: 'boolean', default: false },
|
|
51
54
|
watch: { type: 'boolean', short: 'w', default: false },
|
|
55
|
+
preserveWatchOutput: { type: 'boolean', default: false },
|
|
52
56
|
},
|
|
53
57
|
allowNegative: true,
|
|
54
58
|
});
|
|
@@ -59,6 +63,7 @@ export function parseCLIArgs(args: string[], cwd: string): ParsedArgs {
|
|
|
59
63
|
pretty: values.pretty,
|
|
60
64
|
clean: values.clean,
|
|
61
65
|
watch: values.watch,
|
|
66
|
+
preserveWatchOutput: values.preserveWatchOutput,
|
|
62
67
|
};
|
|
63
68
|
} catch (cause) {
|
|
64
69
|
throw new ParseCLIArgsError(cause);
|
package/src/error.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CMKConfig } from '@css-modules-kit/core';
|
|
2
|
+
import { relative, SystemError } from '@css-modules-kit/core';
|
|
2
3
|
|
|
3
4
|
export class ParseCLIArgsError extends SystemError {
|
|
4
5
|
constructor(cause: unknown) {
|
|
@@ -17,3 +18,12 @@ export class ReadCSSModuleFileError extends SystemError {
|
|
|
17
18
|
super('READ_CSS_MODULE_FILE_ERROR', `Failed to read CSS Module file ${fileName}.`, cause);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
|
|
22
|
+
export class CMKDisabledError extends SystemError {
|
|
23
|
+
constructor(config: CMKConfig) {
|
|
24
|
+
super(
|
|
25
|
+
'CMK_DISABLED_ERROR',
|
|
26
|
+
`css-modules-kit is disabled by configuration. Set \`"cmkOptions": { "enabled": true }\` in ${relative(config.basePath, config.configFileName)} to enable it.`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { runCMK, runCMKInWatchMode } from './runner.js';
|
|
2
2
|
export { type Logger, createLogger } from './logger/logger.js';
|
|
3
|
-
export { WriteDtsFileError, ReadCSSModuleFileError } from './error.js';
|
|
3
|
+
export { WriteDtsFileError, ReadCSSModuleFileError, CMKDisabledError } from './error.js';
|
|
4
4
|
export { parseCLIArgs, printHelpText, printVersion } from './cli.js';
|
|
5
5
|
export { shouldBePretty } from './3rd-party/typescript.js';
|
package/src/project.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
getFileNamesByPattern,
|
|
11
11
|
parseCSSModule,
|
|
12
12
|
readConfigFile,
|
|
13
|
+
relative,
|
|
13
14
|
} from '@css-modules-kit/core';
|
|
14
15
|
import ts from 'typescript';
|
|
15
16
|
import { writeDtsFile } from './dts-writer.js';
|
|
@@ -166,6 +167,12 @@ export function createProject(args: ProjectArgs): Project {
|
|
|
166
167
|
function getProjectDiagnostics() {
|
|
167
168
|
const diagnostics: Diagnostic[] = [];
|
|
168
169
|
diagnostics.push(...config.diagnostics);
|
|
170
|
+
if (config.enabled === undefined) {
|
|
171
|
+
diagnostics.push({
|
|
172
|
+
category: 'warning',
|
|
173
|
+
text: `"cmkOptions.enabled" will be required in a future version of css-modules-kit. Add \`"cmkOptions": { "enabled": true }\` to ${relative(config.basePath, config.configFileName)}. See https://github.com/mizdra/css-modules-kit/issues/289 for details.`,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
169
176
|
if (cssModuleMap.size === 0) {
|
|
170
177
|
diagnostics.push({
|
|
171
178
|
category: 'error',
|
|
@@ -184,7 +191,13 @@ export function createProject(args: ProjectArgs): Project {
|
|
|
184
191
|
for (const cssModule of cssModuleMap.values()) {
|
|
185
192
|
let diagnostics = semanticDiagnosticsMap.get(cssModule.fileName);
|
|
186
193
|
if (!diagnostics) {
|
|
187
|
-
diagnostics = checkCSSModule(cssModule,
|
|
194
|
+
diagnostics = checkCSSModule(cssModule, {
|
|
195
|
+
config,
|
|
196
|
+
getExportRecord: (m) => exportBuilder.build(m),
|
|
197
|
+
matchesPattern,
|
|
198
|
+
resolver,
|
|
199
|
+
getCSSModule,
|
|
200
|
+
});
|
|
188
201
|
semanticDiagnosticsMap.set(cssModule.fileName, diagnostics);
|
|
189
202
|
}
|
|
190
203
|
allDiagnostics.push(...diagnostics);
|
|
@@ -199,7 +212,7 @@ export function createProject(args: ProjectArgs): Project {
|
|
|
199
212
|
const promises: Promise<void>[] = [];
|
|
200
213
|
for (const cssModule of cssModuleMap.values()) {
|
|
201
214
|
if (emittedSet.has(cssModule.fileName)) continue;
|
|
202
|
-
const dts = generateDts(cssModule, {
|
|
215
|
+
const dts = generateDts(cssModule, { ...config, forTsPlugin: false });
|
|
203
216
|
promises.push(
|
|
204
217
|
writeDtsFile(dts.text, cssModule.fileName, {
|
|
205
218
|
outDir: config.dtsOutDir,
|
package/src/runner.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { Stats } from 'node:fs';
|
|
2
2
|
import { rm } from 'node:fs/promises';
|
|
3
3
|
import chokidar, { type FSWatcher } from 'chokidar';
|
|
4
|
+
import { CMKDisabledError } from './error.js';
|
|
4
5
|
import type { Logger } from './logger/logger.js';
|
|
5
6
|
import { createProject, type Project } from './project.js';
|
|
6
7
|
|
|
7
8
|
interface RunnerArgs {
|
|
8
9
|
project: string;
|
|
9
10
|
clean: boolean;
|
|
11
|
+
preserveWatchOutput: boolean;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export interface Watcher {
|
|
@@ -18,12 +20,16 @@ export interface Watcher {
|
|
|
18
20
|
/**
|
|
19
21
|
* Run css-modules-kit .d.ts generation.
|
|
20
22
|
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
23
|
+
* @throws {CMKDisabledError} When css-modules-kit is disabled.
|
|
21
24
|
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
|
|
22
25
|
* @throws {WriteDtsFileError}
|
|
23
26
|
* @returns Whether the process succeeded without errors.
|
|
24
27
|
*/
|
|
25
28
|
export async function runCMK(args: RunnerArgs, logger: Logger): Promise<boolean> {
|
|
26
29
|
const project = createProject(args);
|
|
30
|
+
if (project.config.enabled === false) {
|
|
31
|
+
throw new CMKDisabledError(project.config);
|
|
32
|
+
}
|
|
27
33
|
if (args.clean) {
|
|
28
34
|
await rm(project.config.dtsOutDir, { recursive: true, force: true });
|
|
29
35
|
}
|
|
@@ -31,7 +37,8 @@ export async function runCMK(args: RunnerArgs, logger: Logger): Promise<boolean>
|
|
|
31
37
|
const diagnostics = project.getDiagnostics();
|
|
32
38
|
if (diagnostics.length > 0) {
|
|
33
39
|
logger.logDiagnostics(diagnostics);
|
|
34
|
-
|
|
40
|
+
const hasErrors = diagnostics.some((d) => d.category === 'error');
|
|
41
|
+
return !hasErrors;
|
|
35
42
|
}
|
|
36
43
|
return true;
|
|
37
44
|
}
|
|
@@ -44,6 +51,7 @@ export async function runCMK(args: RunnerArgs, logger: Logger): Promise<boolean>
|
|
|
44
51
|
*
|
|
45
52
|
* NOTE: For implementation simplicity, config file changes are not watched.
|
|
46
53
|
* @param project The absolute path to the project directory or the path to `tsconfig.json`.
|
|
54
|
+
* @throws {CMKDisabledError} When css-modules-kit is disabled.
|
|
47
55
|
* @throws {TsConfigFileNotFoundError}
|
|
48
56
|
* @throws {ReadCSSModuleFileError}
|
|
49
57
|
* @throws {WriteDtsFileError}
|
|
@@ -51,6 +59,9 @@ export async function runCMK(args: RunnerArgs, logger: Logger): Promise<boolean>
|
|
|
51
59
|
export async function runCMKInWatchMode(args: RunnerArgs, logger: Logger): Promise<Watcher> {
|
|
52
60
|
const fsWatchers: FSWatcher[] = [];
|
|
53
61
|
const project = createProject(args);
|
|
62
|
+
if (project.config.enabled === false) {
|
|
63
|
+
throw new CMKDisabledError(project.config);
|
|
64
|
+
}
|
|
54
65
|
let emitAndReportDiagnosticsTimer: NodeJS.Timeout | undefined = undefined;
|
|
55
66
|
|
|
56
67
|
if (args.clean) {
|
|
@@ -129,16 +140,24 @@ export async function runCMKInWatchMode(args: RunnerArgs, logger: Logger): Promi
|
|
|
129
140
|
* @throws {WriteDtsFileError}
|
|
130
141
|
*/
|
|
131
142
|
async function emitAndReportDiagnostics() {
|
|
132
|
-
|
|
143
|
+
if (!args.preserveWatchOutput) {
|
|
144
|
+
logger.clearScreen();
|
|
145
|
+
}
|
|
133
146
|
await project.emitDtsFiles();
|
|
134
147
|
const diagnostics = project.getDiagnostics();
|
|
135
148
|
if (diagnostics.length > 0) {
|
|
136
149
|
logger.logDiagnostics(diagnostics);
|
|
137
150
|
}
|
|
151
|
+
const errorCount = diagnostics.filter((d) => d.category === 'error').length;
|
|
152
|
+
const warningCount = diagnostics.filter((d) => d.category === 'warning').length;
|
|
153
|
+
const warningPart = warningCount > 0 ? ` and ${warningCount} warning${warningCount === 1 ? '' : 's'}` : '';
|
|
138
154
|
logger.logMessage(
|
|
139
|
-
`Found ${
|
|
155
|
+
`Found ${errorCount} error${errorCount === 1 ? '' : 's'}${warningPart}. Watching for file changes.`,
|
|
140
156
|
{ time: true },
|
|
141
157
|
);
|
|
158
|
+
if (args.preserveWatchOutput) {
|
|
159
|
+
logger.logMessage('');
|
|
160
|
+
}
|
|
142
161
|
}
|
|
143
162
|
|
|
144
163
|
async function close() {
|
/package/bin/{cmk.mjs → cmk.js}
RENAMED
|
File without changes
|