@rushstack/typings-generator 0.10.37 → 0.11.1
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 +32 -1
- package/dist/typings-generator.d.ts +43 -8
- package/lib/StringValuesTypingsGenerator.d.ts +15 -4
- package/lib/StringValuesTypingsGenerator.d.ts.map +1 -1
- package/lib/StringValuesTypingsGenerator.js +36 -31
- package/lib/StringValuesTypingsGenerator.js.map +1 -1
- package/lib/TypingsGenerator.d.ts +24 -5
- package/lib/TypingsGenerator.d.ts.map +1 -1
- package/lib/TypingsGenerator.js +12 -11
- package/lib/TypingsGenerator.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -33,6 +33,29 @@ await typingsGenerator.generateTypings();
|
|
|
33
33
|
await typingsGenerator.runWatcher();
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
```TypeScript
|
|
37
|
+
import { TypingsGenerator } from '@rushstack/typings-generator';
|
|
38
|
+
|
|
39
|
+
const assetTypingsGenerator: TypingsGenerator = new TypingsGenerator({
|
|
40
|
+
srcFolder: '/repo/package/src',
|
|
41
|
+
generatedTsFolder: '/repo/package/temp/generated-typings',
|
|
42
|
+
fileExtensions: ['.jpg'],
|
|
43
|
+
parseAndGenerateTypings: (fileContents: false, filePath: string) => {
|
|
44
|
+
const parsedFile = parseFile(fileContents);
|
|
45
|
+
const typings: string = 'declare const path: string;\nexport default path;';
|
|
46
|
+
return typings;
|
|
47
|
+
},
|
|
48
|
+
// Don't read files at all
|
|
49
|
+
readFile: (filePath: string, relativePath: string) => false
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// To run once before a compilation:
|
|
53
|
+
await typingsGenerator.generateTypings();
|
|
54
|
+
|
|
55
|
+
// To start a watcher:
|
|
56
|
+
await typingsGenerator.runWatcher();
|
|
57
|
+
```
|
|
58
|
+
|
|
36
59
|
## Options
|
|
37
60
|
|
|
38
61
|
### `srcFolder = '...'`
|
|
@@ -50,12 +73,20 @@ that this be a folder parallel to the source folder, specified in addition to th
|
|
|
50
73
|
|
|
51
74
|
This property enumerates the file extensions that should be handled.
|
|
52
75
|
|
|
53
|
-
### `parseAndGenerateTypings = (fileContents:
|
|
76
|
+
### `parseAndGenerateTypings = (fileContents: TFileContents, filePath: string, relativePath: string) => string | Promise<string>`
|
|
54
77
|
|
|
55
78
|
This property is used to specify the function that should be called on every file for which typings
|
|
56
79
|
are being generated. In watch mode, this is called on every file creation and file update. It should
|
|
57
80
|
return TypeScript declarations for the file it is called with.
|
|
58
81
|
|
|
82
|
+
### `readFile = (filePath: string, relativePath: string) => TFileContents | Promise<TFileContents>`
|
|
83
|
+
|
|
84
|
+
This property allows customizing the process by which files are read from the specified paths.
|
|
85
|
+
Use cases include:
|
|
86
|
+
- Disabling reads altogether, if the typings don't depend on file content
|
|
87
|
+
- Reading from an alternate data source
|
|
88
|
+
- Reading files with a different encoding than 'utf-8'
|
|
89
|
+
|
|
59
90
|
### `terminal`
|
|
60
91
|
|
|
61
92
|
Optionally provide a [Terminal](https://github.com/microsoft/rushstack/blob/main/libraries/node-core-library/src/Terminal/Terminal.ts)
|
|
@@ -11,7 +11,7 @@ import { ITerminal } from '@rushstack/node-core-library';
|
|
|
11
11
|
/**
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
export declare interface
|
|
14
|
+
export declare interface IStringValuesTypingsGeneratorBaseOptions {
|
|
15
15
|
/**
|
|
16
16
|
* Setting this option wraps the typings export in a default property.
|
|
17
17
|
*/
|
|
@@ -23,6 +23,18 @@ export declare interface IStringValuesTypingsGeneratorOptions extends ITypingsGe
|
|
|
23
23
|
exportAsDefaultInterfaceName?: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare interface IStringValuesTypingsGeneratorOptions<TFileContents extends string = string> extends ITypingsGeneratorOptions<IStringValueTypings | undefined, TFileContents>, IStringValuesTypingsGeneratorBaseOptions {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare interface IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents = string> extends ITypingsGeneratorOptionsWithCustomReadFile<IStringValueTypings | undefined, TFileContents>, IStringValuesTypingsGeneratorBaseOptions {
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
/**
|
|
27
39
|
* @public
|
|
28
40
|
*/
|
|
@@ -52,9 +64,25 @@ export declare interface ITypingsGeneratorBaseOptions {
|
|
|
52
64
|
/**
|
|
53
65
|
* @public
|
|
54
66
|
*/
|
|
55
|
-
export declare interface ITypingsGeneratorOptions<TTypingsResult = string | undefined> extends
|
|
67
|
+
export declare interface ITypingsGeneratorOptions<TTypingsResult = string | undefined, TFileContents extends string = string> extends ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult, TFileContents> {
|
|
68
|
+
readFile?: ReadFile<TFileContents>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Options for a TypingsGenerator that needs to customize how files are read.
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export declare interface ITypingsGeneratorOptionsWithCustomReadFile<TTypingsResult = string | undefined, TFileContents = string> extends ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult, TFileContents> {
|
|
77
|
+
readFile: ReadFile<TFileContents>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export declare interface ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult = string | undefined, TFileContents = string> extends ITypingsGeneratorBaseOptions {
|
|
56
84
|
fileExtensions: string[];
|
|
57
|
-
parseAndGenerateTypings: (fileContents:
|
|
85
|
+
parseAndGenerateTypings: (fileContents: TFileContents, filePath: string, relativePath: string) => TTypingsResult | Promise<TTypingsResult>;
|
|
58
86
|
getAdditionalOutputFiles?: (relativePath: string) => string[];
|
|
59
87
|
/**
|
|
60
88
|
* @deprecated
|
|
@@ -64,14 +92,20 @@ export declare interface ITypingsGeneratorOptions<TTypingsResult = string | unde
|
|
|
64
92
|
filesToIgnore?: string[];
|
|
65
93
|
}
|
|
66
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare type ReadFile<TFileContents = string> = (filePath: string, relativePath: string) => Promise<TFileContents> | TFileContents;
|
|
99
|
+
|
|
67
100
|
/**
|
|
68
101
|
* This is a simple tool that generates .d.ts files for non-TS files that can be represented as
|
|
69
102
|
* a simple set of named string exports.
|
|
70
103
|
*
|
|
71
104
|
* @public
|
|
72
105
|
*/
|
|
73
|
-
export declare class StringValuesTypingsGenerator extends TypingsGenerator {
|
|
74
|
-
constructor(options: IStringValuesTypingsGeneratorOptions);
|
|
106
|
+
export declare class StringValuesTypingsGenerator<TFileContents = string> extends TypingsGenerator<TFileContents> {
|
|
107
|
+
constructor(options: TFileContents extends string ? IStringValuesTypingsGeneratorOptions<TFileContents> : never);
|
|
108
|
+
constructor(options: IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents>);
|
|
75
109
|
}
|
|
76
110
|
|
|
77
111
|
/**
|
|
@@ -79,11 +113,11 @@ export declare class StringValuesTypingsGenerator extends TypingsGenerator {
|
|
|
79
113
|
*
|
|
80
114
|
* @public
|
|
81
115
|
*/
|
|
82
|
-
export declare class TypingsGenerator {
|
|
116
|
+
export declare class TypingsGenerator<TFileContents = string> {
|
|
83
117
|
private readonly _dependenciesOfFile;
|
|
84
118
|
private readonly _consumersOfFile;
|
|
85
119
|
private readonly _relativePaths;
|
|
86
|
-
protected _options:
|
|
120
|
+
protected _options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>;
|
|
87
121
|
/**
|
|
88
122
|
* The folder path that contains all input source files.
|
|
89
123
|
*/
|
|
@@ -96,7 +130,8 @@ export declare class TypingsGenerator {
|
|
|
96
130
|
* The glob patterns that should be ignored when finding input files to process.
|
|
97
131
|
*/
|
|
98
132
|
readonly ignoredFileGlobs: readonly string[];
|
|
99
|
-
constructor(options: ITypingsGeneratorOptions);
|
|
133
|
+
constructor(options: TFileContents extends string ? ITypingsGeneratorOptions<string | undefined, TFileContents> : never);
|
|
134
|
+
constructor(options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>);
|
|
100
135
|
/**
|
|
101
136
|
* Generate typings for the provided input files.
|
|
102
137
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITypingsGeneratorOptions, TypingsGenerator } from './TypingsGenerator';
|
|
1
|
+
import { type ITypingsGeneratorOptions, TypingsGenerator, type ITypingsGeneratorOptionsWithCustomReadFile } from './TypingsGenerator';
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
@@ -15,7 +15,7 @@ export interface IStringValueTypings {
|
|
|
15
15
|
/**
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
|
-
export interface
|
|
18
|
+
export interface IStringValuesTypingsGeneratorBaseOptions {
|
|
19
19
|
/**
|
|
20
20
|
* Setting this option wraps the typings export in a default property.
|
|
21
21
|
*/
|
|
@@ -26,13 +26,24 @@ export interface IStringValuesTypingsGeneratorOptions extends ITypingsGeneratorO
|
|
|
26
26
|
*/
|
|
27
27
|
exportAsDefaultInterfaceName?: string;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export interface IStringValuesTypingsGeneratorOptions<TFileContents extends string = string> extends ITypingsGeneratorOptions<IStringValueTypings | undefined, TFileContents>, IStringValuesTypingsGeneratorBaseOptions {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents = string> extends ITypingsGeneratorOptionsWithCustomReadFile<IStringValueTypings | undefined, TFileContents>, IStringValuesTypingsGeneratorBaseOptions {
|
|
38
|
+
}
|
|
29
39
|
/**
|
|
30
40
|
* This is a simple tool that generates .d.ts files for non-TS files that can be represented as
|
|
31
41
|
* a simple set of named string exports.
|
|
32
42
|
*
|
|
33
43
|
* @public
|
|
34
44
|
*/
|
|
35
|
-
export declare class StringValuesTypingsGenerator extends TypingsGenerator {
|
|
36
|
-
constructor(options: IStringValuesTypingsGeneratorOptions);
|
|
45
|
+
export declare class StringValuesTypingsGenerator<TFileContents = string> extends TypingsGenerator<TFileContents> {
|
|
46
|
+
constructor(options: TFileContents extends string ? IStringValuesTypingsGeneratorOptions<TFileContents> : never);
|
|
47
|
+
constructor(options: IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents>);
|
|
37
48
|
}
|
|
38
49
|
//# sourceMappingURL=StringValuesTypingsGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringValuesTypingsGenerator.d.ts","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"StringValuesTypingsGenerator.d.ts","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,wBAAwB,EAC7B,gBAAgB,EAChB,KAAK,0CAA0C,EAChD,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,wCAAwC;IACvD;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAAW,oCAAoC,CAAC,aAAa,SAAS,MAAM,GAAG,MAAM,CACzF,SAAQ,wBAAwB,CAAC,mBAAmB,GAAG,SAAS,EAAE,aAAa,CAAC,EAC9E,wCAAwC;CAE3C;AAED;;GAEG;AACH,MAAM,WAAW,sDAAsD,CAAC,aAAa,GAAG,MAAM,CAC5F,SAAQ,0CAA0C,CAAC,mBAAmB,GAAG,SAAS,EAAE,aAAa,CAAC,EAChG,wCAAwC;CAE3C;AA6DD;;;;;GAKG;AACH,qBAAa,4BAA4B,CAAC,aAAa,GAAG,MAAM,CAAE,SAAQ,gBAAgB,CAAC,aAAa,CAAC;gBAErG,OAAO,EAAE,aAAa,SAAS,MAAM,GAAG,oCAAoC,CAAC,aAAa,CAAC,GAAG,KAAK;gBAElF,OAAO,EAAE,sDAAsD,CAAC,aAAa,CAAC;CAIlG"}
|
|
@@ -6,6 +6,41 @@ exports.StringValuesTypingsGenerator = void 0;
|
|
|
6
6
|
const os_1 = require("os");
|
|
7
7
|
const TypingsGenerator_1 = require("./TypingsGenerator");
|
|
8
8
|
const EXPORT_AS_DEFAULT_INTERFACE_NAME = 'IExport';
|
|
9
|
+
function convertToTypingsGeneratorOptions(options) {
|
|
10
|
+
async function parseAndGenerateTypings(fileContents, filePath, relativePath) {
|
|
11
|
+
const stringValueTypings = await options.parseAndGenerateTypings(fileContents, filePath, relativePath);
|
|
12
|
+
if (stringValueTypings === undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const outputLines = [];
|
|
16
|
+
const interfaceName = options.exportAsDefaultInterfaceName
|
|
17
|
+
? options.exportAsDefaultInterfaceName
|
|
18
|
+
: EXPORT_AS_DEFAULT_INTERFACE_NAME;
|
|
19
|
+
let indent = '';
|
|
20
|
+
if (options.exportAsDefault) {
|
|
21
|
+
outputLines.push(`export interface ${interfaceName} {`);
|
|
22
|
+
indent = ' ';
|
|
23
|
+
}
|
|
24
|
+
for (const stringValueTyping of stringValueTypings.typings) {
|
|
25
|
+
const { exportName, comment } = stringValueTyping;
|
|
26
|
+
if (comment && comment.trim() !== '') {
|
|
27
|
+
outputLines.push(`${indent}/**`, `${indent} * ${comment.replace(/\*\//g, '*\\/')}`, `${indent} */`);
|
|
28
|
+
}
|
|
29
|
+
if (options.exportAsDefault) {
|
|
30
|
+
outputLines.push(`${indent}'${exportName}': string;`, '');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
outputLines.push(`export declare const ${exportName}: string;`, '');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (options.exportAsDefault) {
|
|
37
|
+
outputLines.push('}', '', `declare const strings: ${interfaceName};`, '', 'export default strings;');
|
|
38
|
+
}
|
|
39
|
+
return outputLines.join(os_1.EOL);
|
|
40
|
+
}
|
|
41
|
+
const convertedOptions = Object.assign(Object.assign({}, options), { parseAndGenerateTypings });
|
|
42
|
+
return convertedOptions;
|
|
43
|
+
}
|
|
9
44
|
/**
|
|
10
45
|
* This is a simple tool that generates .d.ts files for non-TS files that can be represented as
|
|
11
46
|
* a simple set of named string exports.
|
|
@@ -14,37 +49,7 @@ const EXPORT_AS_DEFAULT_INTERFACE_NAME = 'IExport';
|
|
|
14
49
|
*/
|
|
15
50
|
class StringValuesTypingsGenerator extends TypingsGenerator_1.TypingsGenerator {
|
|
16
51
|
constructor(options) {
|
|
17
|
-
super(
|
|
18
|
-
const stringValueTypings = await options.parseAndGenerateTypings(fileContents, filePath, relativePath);
|
|
19
|
-
if (stringValueTypings === undefined) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const outputLines = [];
|
|
23
|
-
const interfaceName = options.exportAsDefaultInterfaceName
|
|
24
|
-
? options.exportAsDefaultInterfaceName
|
|
25
|
-
: EXPORT_AS_DEFAULT_INTERFACE_NAME;
|
|
26
|
-
let indent = '';
|
|
27
|
-
if (options.exportAsDefault) {
|
|
28
|
-
outputLines.push(`export interface ${interfaceName} {`);
|
|
29
|
-
indent = ' ';
|
|
30
|
-
}
|
|
31
|
-
for (const stringValueTyping of stringValueTypings.typings) {
|
|
32
|
-
const { exportName, comment } = stringValueTyping;
|
|
33
|
-
if (comment && comment.trim() !== '') {
|
|
34
|
-
outputLines.push(`${indent}/**`, `${indent} * ${comment.replace(/\*\//g, '*\\/')}`, `${indent} */`);
|
|
35
|
-
}
|
|
36
|
-
if (options.exportAsDefault) {
|
|
37
|
-
outputLines.push(`${indent}'${exportName}': string;`, '');
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
outputLines.push(`export declare const ${exportName}: string;`, '');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (options.exportAsDefault) {
|
|
44
|
-
outputLines.push('}', '', `declare const strings: ${interfaceName};`, '', 'export default strings;');
|
|
45
|
-
}
|
|
46
|
-
return outputLines.join(os_1.EOL);
|
|
47
|
-
} }));
|
|
52
|
+
super(convertToTypingsGeneratorOptions(options));
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
exports.StringValuesTypingsGenerator = StringValuesTypingsGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringValuesTypingsGenerator.js","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AAEzB,
|
|
1
|
+
{"version":3,"file":"StringValuesTypingsGenerator.js","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AAEzB,yDAI4B;AAmD5B,MAAM,gCAAgC,GAAW,SAAS,CAAC;AAE3D,SAAS,gCAAgC,CACvC,OAA8E;IAE9E,KAAK,UAAU,uBAAuB,CACpC,YAA2B,EAC3B,QAAgB,EAChB,YAAoB;QAEpB,MAAM,kBAAkB,GAAoC,MAAM,OAAO,CAA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AC;IAED,MAAM,gBAAgB,mCACjB,OAAO,KACV,uBAAuB,GACxB,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAa,4BAAqD,SAAQ,mCAA+B;IAKvG,YAAmB,OAA8E;QAC/F,KAAK,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AARD,oEAQC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { EOL } from 'os';\n\nimport {\n type ITypingsGeneratorOptions,\n TypingsGenerator,\n type ITypingsGeneratorOptionsWithCustomReadFile\n} from './TypingsGenerator';\n\n/**\n * @public\n */\nexport interface IStringValueTyping {\n exportName: string;\n comment?: string;\n}\n\n/**\n * @public\n */\nexport interface IStringValueTypings {\n typings: IStringValueTyping[];\n}\n\n/**\n * @public\n */\nexport interface IStringValuesTypingsGeneratorBaseOptions {\n /**\n * Setting this option wraps the typings export in a default property.\n */\n exportAsDefault?: boolean;\n\n /**\n * When `exportAsDefault` is true, this optional setting determines the interface name\n * for the default wrapped export. Ignored when `exportAsDefault` is false.\n */\n exportAsDefaultInterfaceName?: string;\n}\n\n/**\n * @public\n */\nexport interface IStringValuesTypingsGeneratorOptions<TFileContents extends string = string>\n extends ITypingsGeneratorOptions<IStringValueTypings | undefined, TFileContents>,\n IStringValuesTypingsGeneratorBaseOptions {\n // Nothing added.\n}\n\n/**\n * @public\n */\nexport interface IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents = string>\n extends ITypingsGeneratorOptionsWithCustomReadFile<IStringValueTypings | undefined, TFileContents>,\n IStringValuesTypingsGeneratorBaseOptions {\n // Nothing added.\n}\n\nconst EXPORT_AS_DEFAULT_INTERFACE_NAME: string = 'IExport';\n\nfunction convertToTypingsGeneratorOptions<TFileContents>(\n options: IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents>\n): ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents> {\n async function parseAndGenerateTypings(\n fileContents: TFileContents,\n filePath: string,\n relativePath: string\n ): Promise<string | undefined> {\n const stringValueTypings: IStringValueTypings | undefined = await options.parseAndGenerateTypings(\n fileContents,\n filePath,\n relativePath\n );\n\n if (stringValueTypings === undefined) {\n return;\n }\n\n const outputLines: string[] = [];\n const interfaceName: string = options.exportAsDefaultInterfaceName\n ? options.exportAsDefaultInterfaceName\n : EXPORT_AS_DEFAULT_INTERFACE_NAME;\n let indent: string = '';\n if (options.exportAsDefault) {\n outputLines.push(`export interface ${interfaceName} {`);\n indent = ' ';\n }\n\n for (const stringValueTyping of stringValueTypings.typings) {\n const { exportName, comment } = stringValueTyping;\n\n if (comment && comment.trim() !== '') {\n outputLines.push(`${indent}/**`, `${indent} * ${comment.replace(/\\*\\//g, '*\\\\/')}`, `${indent} */`);\n }\n\n if (options.exportAsDefault) {\n outputLines.push(`${indent}'${exportName}': string;`, '');\n } else {\n outputLines.push(`export declare const ${exportName}: string;`, '');\n }\n }\n\n if (options.exportAsDefault) {\n outputLines.push('}', '', `declare const strings: ${interfaceName};`, '', 'export default strings;');\n }\n\n return outputLines.join(EOL);\n }\n\n const convertedOptions: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents> = {\n ...options,\n parseAndGenerateTypings\n };\n\n return convertedOptions;\n}\n\n/**\n * This is a simple tool that generates .d.ts files for non-TS files that can be represented as\n * a simple set of named string exports.\n *\n * @public\n */\nexport class StringValuesTypingsGenerator<TFileContents = string> extends TypingsGenerator<TFileContents> {\n public constructor(\n options: TFileContents extends string ? IStringValuesTypingsGeneratorOptions<TFileContents> : never\n );\n public constructor(options: IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents>);\n public constructor(options: IStringValuesTypingsGeneratorOptionsWithCustomReadFile<TFileContents>) {\n super(convertToTypingsGeneratorOptions(options));\n }\n}\n"]}
|
|
@@ -12,9 +12,9 @@ export interface ITypingsGeneratorBaseOptions {
|
|
|
12
12
|
/**
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
export interface
|
|
15
|
+
export interface ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult = string | undefined, TFileContents = string> extends ITypingsGeneratorBaseOptions {
|
|
16
16
|
fileExtensions: string[];
|
|
17
|
-
parseAndGenerateTypings: (fileContents:
|
|
17
|
+
parseAndGenerateTypings: (fileContents: TFileContents, filePath: string, relativePath: string) => TTypingsResult | Promise<TTypingsResult>;
|
|
18
18
|
getAdditionalOutputFiles?: (relativePath: string) => string[];
|
|
19
19
|
/**
|
|
20
20
|
* @deprecated
|
|
@@ -23,16 +23,34 @@ export interface ITypingsGeneratorOptions<TTypingsResult = string | undefined> e
|
|
|
23
23
|
*/
|
|
24
24
|
filesToIgnore?: string[];
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export type ReadFile<TFileContents = string> = (filePath: string, relativePath: string) => Promise<TFileContents> | TFileContents;
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface ITypingsGeneratorOptions<TTypingsResult = string | undefined, TFileContents extends string = string> extends ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult, TFileContents> {
|
|
34
|
+
readFile?: ReadFile<TFileContents>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for a TypingsGenerator that needs to customize how files are read.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export interface ITypingsGeneratorOptionsWithCustomReadFile<TTypingsResult = string | undefined, TFileContents = string> extends ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult, TFileContents> {
|
|
42
|
+
readFile: ReadFile<TFileContents>;
|
|
43
|
+
}
|
|
26
44
|
/**
|
|
27
45
|
* This is a simple tool that generates .d.ts files for non-TS files.
|
|
28
46
|
*
|
|
29
47
|
* @public
|
|
30
48
|
*/
|
|
31
|
-
export declare class TypingsGenerator {
|
|
49
|
+
export declare class TypingsGenerator<TFileContents = string> {
|
|
32
50
|
private readonly _dependenciesOfFile;
|
|
33
51
|
private readonly _consumersOfFile;
|
|
34
52
|
private readonly _relativePaths;
|
|
35
|
-
protected _options:
|
|
53
|
+
protected _options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>;
|
|
36
54
|
/**
|
|
37
55
|
* The folder path that contains all input source files.
|
|
38
56
|
*/
|
|
@@ -45,7 +63,8 @@ export declare class TypingsGenerator {
|
|
|
45
63
|
* The glob patterns that should be ignored when finding input files to process.
|
|
46
64
|
*/
|
|
47
65
|
readonly ignoredFileGlobs: readonly string[];
|
|
48
|
-
constructor(options: ITypingsGeneratorOptions);
|
|
66
|
+
constructor(options: TFileContents extends string ? ITypingsGeneratorOptions<string | undefined, TFileContents> : never);
|
|
67
|
+
constructor(options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>);
|
|
49
68
|
/**
|
|
50
69
|
* Generate typings for the provided input files.
|
|
51
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypingsGenerator.d.ts","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,SAAS,EAMV,MAAM,8BAA8B,CAAC;AAMtC;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,2BAA2B,CAAC,EAAE,MAAM,EAAE,CAAC;IACvC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"TypingsGenerator.d.ts","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,SAAS,EAMV,MAAM,8BAA8B,CAAC;AAMtC;;GAEG;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sGenerator {
|
|
43
43
|
constructor(options) {
|
|
44
|
-
|
|
44
|
+
var _a;
|
|
45
|
+
this._options = Object.assign(Object.assign({}, options), { readFile: (_a = options.readFile) !== null && _a !== void 0 ? _a : ((filePath, relativePath) => node_core_library_1.FileSystem.readFileAsync(filePath)) });
|
|
45
46
|
if (options.filesToIgnore) {
|
|
46
47
|
throw new Error('The filesToIgnore option is no longer supported. Please use globsToIgnore instead.');
|
|
47
48
|
}
|
|
48
|
-
if (!
|
|
49
|
+
if (!options.generatedTsFolder) {
|
|
49
50
|
throw new Error('generatedTsFolder must be provided');
|
|
50
51
|
}
|
|
51
|
-
if (!
|
|
52
|
+
if (!options.srcFolder) {
|
|
52
53
|
throw new Error('srcFolder must be provided');
|
|
53
54
|
}
|
|
54
|
-
this.sourceFolderPath =
|
|
55
|
-
if (node_core_library_1.Path.isUnder(
|
|
55
|
+
this.sourceFolderPath = options.srcFolder;
|
|
56
|
+
if (node_core_library_1.Path.isUnder(options.srcFolder, options.generatedTsFolder)) {
|
|
56
57
|
throw new Error('srcFolder must not be under generatedTsFolder');
|
|
57
58
|
}
|
|
58
|
-
if (node_core_library_1.Path.isUnder(
|
|
59
|
+
if (node_core_library_1.Path.isUnder(options.generatedTsFolder, options.srcFolder)) {
|
|
59
60
|
throw new Error('generatedTsFolder must not be under srcFolder');
|
|
60
61
|
}
|
|
61
|
-
if (!
|
|
62
|
+
if (!options.fileExtensions || options.fileExtensions.length === 0) {
|
|
62
63
|
throw new Error('At least one file extension must be provided.');
|
|
63
64
|
}
|
|
64
|
-
this.ignoredFileGlobs =
|
|
65
|
-
if (!
|
|
65
|
+
this.ignoredFileGlobs = options.globsToIgnore || [];
|
|
66
|
+
if (!options.terminal) {
|
|
66
67
|
this._options.terminal = new node_core_library_1.Terminal(new node_core_library_1.ConsoleTerminalProvider({ verboseEnabled: true }));
|
|
67
68
|
}
|
|
68
|
-
this._options.fileExtensions = this._normalizeFileExtensions(
|
|
69
|
+
this._options.fileExtensions = this._normalizeFileExtensions(options.fileExtensions);
|
|
69
70
|
this._dependenciesOfFile = new Map();
|
|
70
71
|
this._consumersOfFile = new Map();
|
|
71
72
|
this._relativePaths = new Map();
|
|
@@ -210,7 +211,7 @@ class TypingsGenerator {
|
|
|
210
211
|
// Clear registered dependencies prior to reprocessing.
|
|
211
212
|
this._clearDependencies(resolvedPath);
|
|
212
213
|
try {
|
|
213
|
-
const fileContents = await
|
|
214
|
+
const fileContents = await this._options.readFile(resolvedPath, relativePath);
|
|
214
215
|
const typingsData = await this._options.parseAndGenerateTypings(fileContents, resolvedPath, relativePath);
|
|
215
216
|
// Typings data will be undefined when no types should be generated for the parsed file.
|
|
216
217
|
if (typingsData === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypingsGenerator.js","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAQsC;AACtC,0DAA6B;AAC7B,2CAA6B;AAC7B,2BAAyB;AACzB,mDAAqC;AAiCrC;;;;GAIG;AACH,MAAa,gBAAgB;IA2B3B,YAAmB,OAAiC;QAClD,IAAI,CAAC,QAAQ,qBACR,OAAO,CACX,CAAC;QAEF,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;SACvG;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QACD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QAEhD,IAAI,wBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAA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,CAAC,UAAU,CAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;aACzD;YACD,YAAY,CAAC,KAAK,EAAE,CAAC;SACtB;IACH,CAAC;IAEO,CAAC,oBAAoB,CAAC,YAAoB;QAChD,MAAM,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QACzE,MAAM,WAAW,GAAW,GAAG,YAAY,OAAO,CAAC;QACnD,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACnD,IAAI,2BAA2B,EAAE;YAC/B,KAAK,MAAM,0BAA0B,IAAI,2BAA2B,EAAE;gBACpE,MAAM,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,WAAW,CAAC,CAAC;aAC7D;SACF;IACH,CAAC;IAEO,wBAAwB,CAAC,cAAwB;QACvD,MAAM,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAC;QACtC,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;YAC1C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAClC,MAAM,CAAC,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;aACjC;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;aAC3B;SACF;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF;AAnTD,4CAmTC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport {\n FileSystem,\n ITerminal,\n Terminal,\n ConsoleTerminalProvider,\n Path,\n NewlineKind,\n Async\n} from '@rushstack/node-core-library';\nimport glob from 'fast-glob';\nimport * as path from 'path';\nimport { EOL } from 'os';\nimport * as chokidar from 'chokidar';\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorBaseOptions {\n srcFolder: string;\n generatedTsFolder: string;\n secondaryGeneratedTsFolders?: string[];\n globsToIgnore?: string[];\n terminal?: ITerminal;\n}\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorOptions<TTypingsResult = string | undefined>\n extends ITypingsGeneratorBaseOptions {\n fileExtensions: string[];\n parseAndGenerateTypings: (\n fileContents: string,\n filePath: string,\n relativePath: string\n ) => TTypingsResult | Promise<TTypingsResult>;\n getAdditionalOutputFiles?: (relativePath: string) => string[];\n /**\n * @deprecated\n *\n * TODO: Remove when version 1.0.0 is released.\n */\n filesToIgnore?: string[];\n}\n\n/**\n * This is a simple tool that generates .d.ts files for non-TS files.\n *\n * @public\n */\nexport class TypingsGenerator {\n // Map of resolved consumer file path -> Set<resolved dependency file path>\n private readonly _dependenciesOfFile: Map<string, Set<string>>;\n\n // Map of resolved dependency file path -> Set<resolved consumer file path>\n private readonly _consumersOfFile: Map<string, Set<string>>;\n\n // Map of resolved file path -> relative file path\n private readonly _relativePaths: Map<string, string>;\n\n protected _options: ITypingsGeneratorOptions;\n\n /**\n * The folder path that contains all input source files.\n */\n public readonly sourceFolderPath: string;\n\n /**\n * The glob pattern used to find input files to process.\n */\n public readonly inputFileGlob: string;\n\n /**\n * The glob patterns that should be ignored when finding input files to process.\n */\n public readonly ignoredFileGlobs: readonly string[];\n\n public constructor(options: ITypingsGeneratorOptions) {\n this._options = {\n ...options\n };\n\n if (options.filesToIgnore) {\n throw new Error('The filesToIgnore option is no longer supported. Please use globsToIgnore instead.');\n }\n\n if (!this._options.generatedTsFolder) {\n throw new Error('generatedTsFolder must be provided');\n }\n\n if (!this._options.srcFolder) {\n throw new Error('srcFolder must be provided');\n }\n this.sourceFolderPath = this._options.srcFolder;\n\n if (Path.isUnder(this._options.srcFolder, this._options.generatedTsFolder)) {\n throw new Error('srcFolder must not be under generatedTsFolder');\n }\n\n if (Path.isUnder(this._options.generatedTsFolder, this._options.srcFolder)) {\n throw new Error('generatedTsFolder must not be under srcFolder');\n }\n\n if (!this._options.fileExtensions || this._options.fileExtensions.length === 0) {\n throw new Error('At least one file extension must be provided.');\n }\n\n this.ignoredFileGlobs = this._options.globsToIgnore || [];\n\n if (!this._options.terminal) {\n this._options.terminal = new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }));\n }\n\n this._options.fileExtensions = this._normalizeFileExtensions(this._options.fileExtensions);\n\n this._dependenciesOfFile = new Map();\n this._consumersOfFile = new Map();\n this._relativePaths = new Map();\n\n this.inputFileGlob = `**/*+(${this._options.fileExtensions.join('|')})`;\n }\n\n /**\n * Generate typings for the provided input files.\n *\n * @param relativeFilePaths - The input files to process, relative to the source folder. If not provided,\n * all input files will be processed.\n */\n public async generateTypingsAsync(relativeFilePaths?: string[]): Promise<void> {\n let checkFilePaths: boolean = true;\n if (!relativeFilePaths?.length) {\n checkFilePaths = false; // Don't check file paths if we generate them\n relativeFilePaths = await glob(this.inputFileGlob, {\n cwd: this.sourceFolderPath,\n ignore: this.ignoredFileGlobs as string[],\n onlyFiles: true\n });\n }\n\n await this._reprocessFiles(relativeFilePaths, checkFilePaths);\n }\n\n public async runWatcherAsync(): Promise<void> {\n await FileSystem.ensureFolderAsync(this._options.generatedTsFolder);\n\n await new Promise((resolve, reject): void => {\n const watcher: chokidar.FSWatcher = chokidar.watch(this.inputFileGlob, {\n cwd: this.sourceFolderPath,\n ignored: this.ignoredFileGlobs\n });\n\n const queue: Set<string> = new Set();\n let timeout: NodeJS.Timeout | undefined;\n let processing: boolean = false;\n let flushAfterCompletion: boolean = false;\n\n const flushInternal: () => void = () => {\n processing = true;\n\n const toProcess: string[] = Array.from(queue);\n queue.clear();\n this._reprocessFiles(toProcess, false)\n .then(() => {\n processing = false;\n // If the timeout was invoked again, immediately reexecute with the changed files.\n if (flushAfterCompletion) {\n flushAfterCompletion = false;\n flushInternal();\n }\n })\n .catch(reject);\n };\n\n const debouncedFlush: () => void = () => {\n timeout = undefined;\n if (processing) {\n // If the callback was invoked while processing is ongoing, indicate that we should flush immediately\n // upon completion of the current change batch.\n flushAfterCompletion = true;\n return;\n }\n\n flushInternal();\n };\n\n const onChange: (relativePath: string) => void = (relativePath: string) => {\n queue.add(relativePath);\n if (timeout) {\n clearTimeout(timeout);\n }\n\n setTimeout(debouncedFlush, 100);\n };\n\n watcher.on('add', onChange);\n watcher.on('change', onChange);\n watcher.on('unlink', async (relativePath) => {\n await Promise.all(\n this._getOutputFilePathsWithoutCheck(relativePath).map(async (outputFile: string) => {\n await FileSystem.deleteFileAsync(outputFile);\n })\n );\n });\n watcher.on('error', reject);\n });\n }\n\n /**\n * Register file dependencies that may effect the typings of a consumer file.\n * Note: This feature is only useful in watch mode.\n * The registerDependency method must be called in the body of parseAndGenerateTypings every\n * time because the registry for a file is cleared at the beginning of processing.\n */\n public registerDependency(consumer: string, rawDependency: string): void {\n // Need to normalize slashes in the dependency path\n const dependency: string = path.resolve(this._options.srcFolder, rawDependency);\n\n let dependencies: Set<string> | undefined = this._dependenciesOfFile.get(consumer);\n if (!dependencies) {\n dependencies = new Set();\n this._dependenciesOfFile.set(consumer, dependencies);\n }\n dependencies.add(dependency);\n\n let consumers: Set<string> | undefined = this._consumersOfFile.get(dependency);\n if (!consumers) {\n consumers = new Set();\n this._consumersOfFile.set(dependency, consumers);\n }\n consumers.add(consumer);\n }\n\n public getOutputFilePaths(relativePath: string): string[] {\n if (path.isAbsolute(relativePath)) {\n throw new Error(`\"${relativePath}\" must be relative`);\n }\n\n return this._getOutputFilePathsWithoutCheck(relativePath);\n }\n\n private _getOutputFilePathsWithoutCheck(relativePath: string): string[] {\n const typingsFilePaths: Iterable<string> = this._getTypingsFilePaths(relativePath);\n const additionalPaths: string[] | undefined = this._options.getAdditionalOutputFiles?.(relativePath);\n return additionalPaths ? [...typingsFilePaths, ...additionalPaths] : Array.from(typingsFilePaths);\n }\n\n private async _reprocessFiles(relativePaths: Iterable<string>, checkFilePaths: boolean): Promise<void> {\n // Build a queue of resolved paths\n const toProcess: Set<string> = new Set();\n for (const rawPath of relativePaths) {\n if (checkFilePaths && path.isAbsolute(rawPath)) {\n throw new Error(`\"${rawPath}\" must be relative`);\n }\n\n const relativePath: string = Path.convertToSlashes(rawPath);\n const resolvedPath: string = path.resolve(this._options.srcFolder, rawPath);\n this._relativePaths.set(resolvedPath, relativePath);\n toProcess.add(resolvedPath);\n }\n\n // Expand out all registered consumers, according to the current dependency graph\n for (const file of toProcess) {\n const consumers: Set<string> | undefined = this._consumersOfFile.get(file);\n if (consumers) {\n for (const consumer of consumers) {\n toProcess.add(consumer);\n }\n }\n }\n\n // Map back to the relative paths so that the information is available\n await Async.forEachAsync(\n toProcess,\n async (resolvedPath: string) => {\n const relativePath: string | undefined = this._relativePaths.get(resolvedPath);\n if (!relativePath) {\n throw new Error(`Missing relative path for file ${resolvedPath}`);\n }\n await this._parseFileAndGenerateTypingsAsync(relativePath, resolvedPath);\n },\n { concurrency: 20 }\n );\n }\n\n private async _parseFileAndGenerateTypingsAsync(relativePath: string, resolvedPath: string): Promise<void> {\n // Clear registered dependencies prior to reprocessing.\n this._clearDependencies(resolvedPath);\n\n try {\n const fileContents: string = await FileSystem.readFileAsync(resolvedPath);\n const typingsData: string | undefined = await this._options.parseAndGenerateTypings(\n fileContents,\n resolvedPath,\n relativePath\n );\n\n // Typings data will be undefined when no types should be generated for the parsed file.\n if (typingsData === undefined) {\n return;\n }\n\n const prefixedTypingsData: string = [\n '// This file was generated by a tool. Modifying it will produce unexpected behavior',\n '',\n typingsData\n ].join(EOL);\n\n const generatedTsFilePaths: Iterable<string> = this._getTypingsFilePaths(relativePath);\n for (const generatedTsFilePath of generatedTsFilePaths) {\n await FileSystem.writeFileAsync(generatedTsFilePath, prefixedTypingsData, {\n ensureFolderExists: true,\n convertLineEndings: NewlineKind.OsDefault\n });\n }\n } catch (e) {\n this._options.terminal!.writeError(\n `Error occurred parsing and generating typings for file \"${resolvedPath}\": ${e}`\n );\n }\n }\n\n /**\n * Removes the consumer from all extant dependencies\n */\n private _clearDependencies(consumer: string): void {\n const dependencies: Set<string> | undefined = this._dependenciesOfFile.get(consumer);\n if (dependencies) {\n for (const dependency of dependencies) {\n this._consumersOfFile.get(dependency)!.delete(consumer);\n }\n dependencies.clear();\n }\n }\n\n private *_getTypingsFilePaths(relativePath: string): Iterable<string> {\n const { generatedTsFolder, secondaryGeneratedTsFolders } = this._options;\n const dtsFilename: string = `${relativePath}.d.ts`;\n yield path.resolve(generatedTsFolder, dtsFilename);\n if (secondaryGeneratedTsFolders) {\n for (const secondaryGeneratedTsFolder of secondaryGeneratedTsFolders) {\n yield path.resolve(secondaryGeneratedTsFolder, dtsFilename);\n }\n }\n }\n\n private _normalizeFileExtensions(fileExtensions: string[]): string[] {\n const result: Set<string> = new Set();\n for (const fileExtension of fileExtensions) {\n if (!fileExtension.startsWith('.')) {\n result.add(`.${fileExtension}`);\n } else {\n result.add(fileExtension);\n }\n }\n\n return Array.from(result);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TypingsGenerator.js","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAQsC;AACtC,0DAA6B;AAC7B,2CAA6B;AAC7B,2BAAyB;AACzB,mDAAqC;AAiErC;;;;GAIG;AACH,MAAa,gBAAgB;IAiC3B,YAAmB,OAAsF;;QACvG,IAAI,CAAC,QAAQ,mCACR,OAAO,KACV,QAAQ,EACN,MAAA,OAAO,CAAC,QAAQ,mCAChB,CAAC,CAAC,QAAgB,EAAE,YAAoB,EAA0B,EAAE,CAClE,8BAAU,CAAC,aAAa,CAAC,QAAQ,CAA2B,CAAC,GAClE,CAAC;QAEF,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;SACvG;QAED,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,IAAI,CAAC,OAAO,CAAC,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E;YAChB,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE;gBACrC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;aACzD;YACD,YAAY,CAAC,KAAK,EAAE,CAAC;SACtB;IACH,CAAC;IAEO,CAAC,oBAAoB,CAAC,YAAoB;QAChD,MAAM,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QACzE,MAAM,WAAW,GAAW,GAAG,YAAY,OAAO,CAAC;QACnD,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACnD,IAAI,2BAA2B,EAAE;YAC/B,KAAK,MAAM,0BAA0B,IAAI,2BAA2B,EAAE;gBACpE,MAAM,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,WAAW,CAAC,CAAC;aAC7D;SACF;IACH,CAAC;IAEO,wBAAwB,CAAC,cAAwB;QACvD,MAAM,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAC;QACtC,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;YAC1C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAClC,MAAM,CAAC,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;aACjC;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;aAC3B;SACF;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF;AA7TD,4CA6TC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport {\n FileSystem,\n ITerminal,\n Terminal,\n ConsoleTerminalProvider,\n Path,\n NewlineKind,\n Async\n} from '@rushstack/node-core-library';\nimport glob from 'fast-glob';\nimport * as path from 'path';\nimport { EOL } from 'os';\nimport * as chokidar from 'chokidar';\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorBaseOptions {\n srcFolder: string;\n generatedTsFolder: string;\n secondaryGeneratedTsFolders?: string[];\n globsToIgnore?: string[];\n terminal?: ITerminal;\n}\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorOptionsWithoutReadFile<\n TTypingsResult = string | undefined,\n TFileContents = string\n> extends ITypingsGeneratorBaseOptions {\n fileExtensions: string[];\n parseAndGenerateTypings: (\n fileContents: TFileContents,\n filePath: string,\n relativePath: string\n ) => TTypingsResult | Promise<TTypingsResult>;\n getAdditionalOutputFiles?: (relativePath: string) => string[];\n /**\n * @deprecated\n *\n * TODO: Remove when version 1.0.0 is released.\n */\n filesToIgnore?: string[];\n}\n\n/**\n * @public\n */\nexport type ReadFile<TFileContents = string> = (\n filePath: string,\n relativePath: string\n) => Promise<TFileContents> | TFileContents;\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorOptions<\n TTypingsResult = string | undefined,\n TFileContents extends string = string\n> extends ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult, TFileContents> {\n readFile?: ReadFile<TFileContents>;\n}\n\n/**\n * Options for a TypingsGenerator that needs to customize how files are read.\n *\n * @public\n */\nexport interface ITypingsGeneratorOptionsWithCustomReadFile<\n TTypingsResult = string | undefined,\n TFileContents = string\n> extends ITypingsGeneratorOptionsWithoutReadFile<TTypingsResult, TFileContents> {\n readFile: ReadFile<TFileContents>;\n}\n\n/**\n * This is a simple tool that generates .d.ts files for non-TS files.\n *\n * @public\n */\nexport class TypingsGenerator<TFileContents = string> {\n // Map of resolved consumer file path -> Set<resolved dependency file path>\n private readonly _dependenciesOfFile: Map<string, Set<string>>;\n\n // Map of resolved dependency file path -> Set<resolved consumer file path>\n private readonly _consumersOfFile: Map<string, Set<string>>;\n\n // Map of resolved file path -> relative file path\n private readonly _relativePaths: Map<string, string>;\n\n protected _options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>;\n\n /**\n * The folder path that contains all input source files.\n */\n public readonly sourceFolderPath: string;\n\n /**\n * The glob pattern used to find input files to process.\n */\n public readonly inputFileGlob: string;\n\n /**\n * The glob patterns that should be ignored when finding input files to process.\n */\n public readonly ignoredFileGlobs: readonly string[];\n\n public constructor(\n options: TFileContents extends string\n ? ITypingsGeneratorOptions<string | undefined, TFileContents>\n : never\n );\n public constructor(options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>);\n public constructor(options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>) {\n this._options = {\n ...options,\n readFile:\n options.readFile ??\n ((filePath: string, relativePath: string): Promise<TFileContents> =>\n FileSystem.readFileAsync(filePath) as Promise<TFileContents>)\n };\n\n if (options.filesToIgnore) {\n throw new Error('The filesToIgnore option is no longer supported. Please use globsToIgnore instead.');\n }\n\n if (!options.generatedTsFolder) {\n throw new Error('generatedTsFolder must be provided');\n }\n\n if (!options.srcFolder) {\n throw new Error('srcFolder must be provided');\n }\n this.sourceFolderPath = options.srcFolder;\n\n if (Path.isUnder(options.srcFolder, options.generatedTsFolder)) {\n throw new Error('srcFolder must not be under generatedTsFolder');\n }\n\n if (Path.isUnder(options.generatedTsFolder, options.srcFolder)) {\n throw new Error('generatedTsFolder must not be under srcFolder');\n }\n\n if (!options.fileExtensions || options.fileExtensions.length === 0) {\n throw new Error('At least one file extension must be provided.');\n }\n\n this.ignoredFileGlobs = options.globsToIgnore || [];\n\n if (!options.terminal) {\n this._options.terminal = new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }));\n }\n\n this._options.fileExtensions = this._normalizeFileExtensions(options.fileExtensions);\n\n this._dependenciesOfFile = new Map();\n this._consumersOfFile = new Map();\n this._relativePaths = new Map();\n\n this.inputFileGlob = `**/*+(${this._options.fileExtensions.join('|')})`;\n }\n\n /**\n * Generate typings for the provided input files.\n *\n * @param relativeFilePaths - The input files to process, relative to the source folder. If not provided,\n * all input files will be processed.\n */\n public async generateTypingsAsync(relativeFilePaths?: string[]): Promise<void> {\n let checkFilePaths: boolean = true;\n if (!relativeFilePaths?.length) {\n checkFilePaths = false; // Don't check file paths if we generate them\n relativeFilePaths = await glob(this.inputFileGlob, {\n cwd: this.sourceFolderPath,\n ignore: this.ignoredFileGlobs as string[],\n onlyFiles: true\n });\n }\n\n await this._reprocessFiles(relativeFilePaths!, checkFilePaths);\n }\n\n public async runWatcherAsync(): Promise<void> {\n await FileSystem.ensureFolderAsync(this._options.generatedTsFolder);\n\n await new Promise((resolve, reject): void => {\n const watcher: chokidar.FSWatcher = chokidar.watch(this.inputFileGlob, {\n cwd: this.sourceFolderPath,\n ignored: this.ignoredFileGlobs\n });\n\n const queue: Set<string> = new Set();\n let timeout: NodeJS.Timeout | undefined;\n let processing: boolean = false;\n let flushAfterCompletion: boolean = false;\n\n const flushInternal: () => void = () => {\n processing = true;\n\n const toProcess: string[] = Array.from(queue);\n queue.clear();\n this._reprocessFiles(toProcess, false)\n .then(() => {\n processing = false;\n // If the timeout was invoked again, immediately reexecute with the changed files.\n if (flushAfterCompletion) {\n flushAfterCompletion = false;\n flushInternal();\n }\n })\n .catch(reject);\n };\n\n const debouncedFlush: () => void = () => {\n timeout = undefined;\n if (processing) {\n // If the callback was invoked while processing is ongoing, indicate that we should flush immediately\n // upon completion of the current change batch.\n flushAfterCompletion = true;\n return;\n }\n\n flushInternal();\n };\n\n const onChange: (relativePath: string) => void = (relativePath: string) => {\n queue.add(relativePath);\n if (timeout) {\n clearTimeout(timeout);\n }\n\n setTimeout(debouncedFlush, 100);\n };\n\n watcher.on('add', onChange);\n watcher.on('change', onChange);\n watcher.on('unlink', async (relativePath) => {\n await Promise.all(\n this._getOutputFilePathsWithoutCheck(relativePath).map(async (outputFile: string) => {\n await FileSystem.deleteFileAsync(outputFile);\n })\n );\n });\n watcher.on('error', reject);\n });\n }\n\n /**\n * Register file dependencies that may effect the typings of a consumer file.\n * Note: This feature is only useful in watch mode.\n * The registerDependency method must be called in the body of parseAndGenerateTypings every\n * time because the registry for a file is cleared at the beginning of processing.\n */\n public registerDependency(consumer: string, rawDependency: string): void {\n // Need to normalize slashes in the dependency path\n const dependency: string = path.resolve(this._options.srcFolder, rawDependency);\n\n let dependencies: Set<string> | undefined = this._dependenciesOfFile.get(consumer);\n if (!dependencies) {\n dependencies = new Set();\n this._dependenciesOfFile.set(consumer, dependencies);\n }\n dependencies.add(dependency);\n\n let consumers: Set<string> | undefined = this._consumersOfFile.get(dependency);\n if (!consumers) {\n consumers = new Set();\n this._consumersOfFile.set(dependency, consumers);\n }\n consumers.add(consumer);\n }\n\n public getOutputFilePaths(relativePath: string): string[] {\n if (path.isAbsolute(relativePath)) {\n throw new Error(`\"${relativePath}\" must be relative`);\n }\n\n return this._getOutputFilePathsWithoutCheck(relativePath);\n }\n\n private _getOutputFilePathsWithoutCheck(relativePath: string): string[] {\n const typingsFilePaths: Iterable<string> = this._getTypingsFilePaths(relativePath);\n const additionalPaths: string[] | undefined = this._options.getAdditionalOutputFiles?.(relativePath);\n return additionalPaths ? [...typingsFilePaths, ...additionalPaths] : Array.from(typingsFilePaths);\n }\n\n private async _reprocessFiles(relativePaths: Iterable<string>, checkFilePaths: boolean): Promise<void> {\n // Build a queue of resolved paths\n const toProcess: Set<string> = new Set();\n for (const rawPath of relativePaths) {\n if (checkFilePaths && path.isAbsolute(rawPath)) {\n throw new Error(`\"${rawPath}\" must be relative`);\n }\n\n const relativePath: string = Path.convertToSlashes(rawPath);\n const resolvedPath: string = path.resolve(this._options.srcFolder, rawPath);\n this._relativePaths.set(resolvedPath, relativePath);\n toProcess.add(resolvedPath);\n }\n\n // Expand out all registered consumers, according to the current dependency graph\n for (const file of toProcess) {\n const consumers: Set<string> | undefined = this._consumersOfFile.get(file);\n if (consumers) {\n for (const consumer of consumers) {\n toProcess.add(consumer);\n }\n }\n }\n\n // Map back to the relative paths so that the information is available\n await Async.forEachAsync(\n toProcess,\n async (resolvedPath: string) => {\n const relativePath: string | undefined = this._relativePaths.get(resolvedPath);\n if (!relativePath) {\n throw new Error(`Missing relative path for file ${resolvedPath}`);\n }\n await this._parseFileAndGenerateTypingsAsync(relativePath, resolvedPath);\n },\n { concurrency: 20 }\n );\n }\n\n private async _parseFileAndGenerateTypingsAsync(relativePath: string, resolvedPath: string): Promise<void> {\n // Clear registered dependencies prior to reprocessing.\n this._clearDependencies(resolvedPath);\n\n try {\n const fileContents: TFileContents = await this._options.readFile(resolvedPath, relativePath);\n const typingsData: string | undefined = await this._options.parseAndGenerateTypings(\n fileContents,\n resolvedPath,\n relativePath\n );\n\n // Typings data will be undefined when no types should be generated for the parsed file.\n if (typingsData === undefined) {\n return;\n }\n\n const prefixedTypingsData: string = [\n '// This file was generated by a tool. Modifying it will produce unexpected behavior',\n '',\n typingsData\n ].join(EOL);\n\n const generatedTsFilePaths: Iterable<string> = this._getTypingsFilePaths(relativePath);\n for (const generatedTsFilePath of generatedTsFilePaths) {\n await FileSystem.writeFileAsync(generatedTsFilePath, prefixedTypingsData, {\n ensureFolderExists: true,\n convertLineEndings: NewlineKind.OsDefault\n });\n }\n } catch (e) {\n this._options.terminal!.writeError(\n `Error occurred parsing and generating typings for file \"${resolvedPath}\": ${e}`\n );\n }\n }\n\n /**\n * Removes the consumer from all extant dependencies\n */\n private _clearDependencies(consumer: string): void {\n const dependencies: Set<string> | undefined = this._dependenciesOfFile.get(consumer);\n if (dependencies) {\n for (const dependency of dependencies) {\n this._consumersOfFile.get(dependency)!.delete(consumer);\n }\n dependencies.clear();\n }\n }\n\n private *_getTypingsFilePaths(relativePath: string): Iterable<string> {\n const { generatedTsFolder, secondaryGeneratedTsFolders } = this._options;\n const dtsFilename: string = `${relativePath}.d.ts`;\n yield path.resolve(generatedTsFolder, dtsFilename);\n if (secondaryGeneratedTsFolders) {\n for (const secondaryGeneratedTsFolder of secondaryGeneratedTsFolders) {\n yield path.resolve(secondaryGeneratedTsFolder, dtsFilename);\n }\n }\n }\n\n private _normalizeFileExtensions(fileExtensions: string[]): string[] {\n const result: Set<string> = new Set();\n for (const fileExtension of fileExtensions) {\n if (!fileExtension.startsWith('.')) {\n result.add(`.${fileExtension}`);\n } else {\n result.add(fileExtension);\n }\n }\n\n return Array.from(result);\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
|
-
export { ITypingsGeneratorBaseOptions, ITypingsGeneratorOptions, TypingsGenerator } from './TypingsGenerator';
|
|
9
|
-
export { IStringValueTyping, IStringValueTypings, IStringValuesTypingsGeneratorOptions, StringValuesTypingsGenerator } from './StringValuesTypingsGenerator';
|
|
8
|
+
export { type ReadFile, type ITypingsGeneratorBaseOptions, type ITypingsGeneratorOptionsWithoutReadFile, type ITypingsGeneratorOptions, type ITypingsGeneratorOptionsWithCustomReadFile, TypingsGenerator } from './TypingsGenerator';
|
|
9
|
+
export { type IStringValueTyping, type IStringValueTypings, type IStringValuesTypingsGeneratorBaseOptions, type IStringValuesTypingsGeneratorOptions, type IStringValuesTypingsGeneratorOptionsWithCustomReadFile, StringValuesTypingsGenerator } from './StringValuesTypingsGenerator';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,4BAA4B,EACjC,KAAK,uCAAuC,EAC5C,KAAK,wBAAwB,EAC7B,KAAK,0CAA0C,EAC/C,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,wCAAwC,EAC7C,KAAK,oCAAoC,EACzC,KAAK,sDAAsD,EAC3D,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;;GAMG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;;GAMG;AAEH,uDAO4B;AAD1B,oHAAA,gBAAgB,OAAA;AAGlB,+EAOwC;AADtC,4IAAA,4BAA4B,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * An engine for generating TypeScript .d.ts files that provide type signatures\n * for non-TypeScript modules such as generated JavaScript or CSS. It can operate\n * in either a single-run mode or a watch mode.\n *\n * @packageDocumentation\n */\n\nexport {\n type ReadFile,\n type ITypingsGeneratorBaseOptions,\n type ITypingsGeneratorOptionsWithoutReadFile,\n type ITypingsGeneratorOptions,\n type ITypingsGeneratorOptionsWithCustomReadFile,\n TypingsGenerator\n} from './TypingsGenerator';\n\nexport {\n type IStringValueTyping,\n type IStringValueTypings,\n type IStringValuesTypingsGeneratorBaseOptions,\n type IStringValuesTypingsGeneratorOptions,\n type IStringValuesTypingsGeneratorOptionsWithCustomReadFile,\n StringValuesTypingsGenerator\n} from './StringValuesTypingsGenerator';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/typings-generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "This library provides functionality for automatically generating typings for non-TS files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dts",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"chokidar": "~3.4.0",
|
|
20
20
|
"fast-glob": "~3.2.4",
|
|
21
|
-
"@rushstack/node-core-library": "3.59.
|
|
21
|
+
"@rushstack/node-core-library": "3.59.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "14.18.36",
|
|
25
|
-
"@rushstack/eslint-config": "3.3.
|
|
26
|
-
"@rushstack/heft": "0.58.
|
|
27
|
-
"@rushstack/heft-node-rig": "2.2.
|
|
25
|
+
"@rushstack/eslint-config": "3.3.3",
|
|
26
|
+
"@rushstack/heft": "0.58.2",
|
|
27
|
+
"@rushstack/heft-node-rig": "2.2.22"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@types/node": "*"
|