@rushstack/typings-generator 0.14.21 → 0.14.23

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/CHANGELOG.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@rushstack/typings-generator",
3
3
  "entries": [
4
+ {
5
+ "version": "0.14.23",
6
+ "tag": "@rushstack/typings-generator_v0.14.23",
7
+ "date": "Wed, 26 Feb 2025 16:11:11 GMT",
8
+ "comments": {
9
+ "dependency": [
10
+ {
11
+ "comment": "Updating dependency \"@rushstack/heft\" to `0.69.0`"
12
+ }
13
+ ]
14
+ }
15
+ },
16
+ {
17
+ "version": "0.14.22",
18
+ "tag": "@rushstack/typings-generator_v0.14.22",
19
+ "date": "Sat, 22 Feb 2025 01:11:12 GMT",
20
+ "comments": {
21
+ "dependency": [
22
+ {
23
+ "comment": "Updating dependency \"@rushstack/heft\" to `0.68.18`"
24
+ }
25
+ ]
26
+ }
27
+ },
4
28
  {
5
29
  "version": "0.14.21",
6
30
  "tag": "@rushstack/typings-generator_v0.14.21",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Change Log - @rushstack/typings-generator
2
2
 
3
- This log was last generated on Wed, 19 Feb 2025 18:53:48 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 26 Feb 2025 16:11:11 GMT and should not be manually modified.
4
+
5
+ ## 0.14.23
6
+ Wed, 26 Feb 2025 16:11:11 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 0.14.22
11
+ Sat, 22 Feb 2025 01:11:12 GMT
12
+
13
+ _Version update only_
4
14
 
5
15
  ## 0.14.21
6
16
  Wed, 19 Feb 2025 18:53:48 GMT
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.50.0"
8
+ "packageVersion": "7.50.1"
9
9
  }
10
10
  ]
11
11
  }
@@ -91,7 +91,7 @@ class TypingsGenerator {
91
91
  await new Promise((resolve, reject) => {
92
92
  const watcher = chokidar.watch(this.inputFileGlob, {
93
93
  cwd: this.sourceFolderPath,
94
- ignored: this.ignoredFileGlobs
94
+ ignored: this.ignoredFileGlobs // `ignored` doesn't like the readonly array
95
95
  });
96
96
  const queue = new Set();
97
97
  let timeout;
@@ -1 +1 @@
1
- {"version":3,"file":"TypingsGenerator.js","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAAoF;AACpF,kDAAwF;AACxF,0DAA6B;AAC7B,2CAA6B;AAC7B,2BAAyB;AACzB,mDAAqC;AA2DrC;;;;GAIG;AACH,MAAa,gBAAgB;IAmC3B,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,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;QAE1C,IAAI,wBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,wBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,SAAS,CAA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YACD,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;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,GAAG,iBAAiB,IAAI,WAAW,EAAE,CAAC;QAC5C,IAAI,2BAA2B,EAAE,CAAC;YAChC,KAAK,MAAM,0BAA0B,IAAI,2BAA2B,EAAE,CAAC;gBACrE,MAAM,GAAG,0BAA0B,IAAI,WAAW,EAAE,CAAC;YACvD,CAAC;QACH,CAAC;IACH,CAAC;IAEO,wBAAwB,CAAC,cAAwB;QACvD,MAAM,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAC;QACtC,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,CAAC,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF;AA5TD,4CA4TC","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 { FileSystem, Path, NewlineKind, Async } from '@rushstack/node-core-library';\nimport { type ITerminal, Terminal, ConsoleTerminalProvider } from '@rushstack/terminal';\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\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 readonly _options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>;\n\n protected readonly terminal: ITerminal;\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.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 this.terminal = options.terminal ?? new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }));\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._reprocessFilesAsync(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._reprocessFilesAsync(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 _reprocessFilesAsync(\n relativePaths: Iterable<string>,\n checkFilePaths: boolean\n ): 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.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 `${generatedTsFolder}/${dtsFilename}`;\n if (secondaryGeneratedTsFolders) {\n for (const secondaryGeneratedTsFolder of secondaryGeneratedTsFolders) {\n yield `${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;;;;;;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AAM,0BAA0B,IAAI,2BAA2B,EAAE,CAAC;gBACrE,MAAM,GAAG,0BAA0B,IAAI,WAAW,EAAE,CAAC;YACvD,CAAC;QACH,CAAC;IACH,CAAC;IAEO,wBAAwB,CAAC,cAAwB;QACvD,MAAM,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAC;QACtC,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,CAAC,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF;AA5TD,4CA4TC","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 { FileSystem, Path, NewlineKind, Async } from '@rushstack/node-core-library';\nimport { type ITerminal, Terminal, ConsoleTerminalProvider } from '@rushstack/terminal';\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\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 readonly _options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>;\n\n protected readonly terminal: ITerminal;\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.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 this.terminal = options.terminal ?? new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }));\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._reprocessFilesAsync(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 as string[] // `ignored` doesn't like the readonly array\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._reprocessFilesAsync(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 _reprocessFilesAsync(\n relativePaths: Iterable<string>,\n checkFilePaths: boolean\n ): 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.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 `${generatedTsFolder}/${dtsFilename}`;\n if (secondaryGeneratedTsFolders) {\n for (const secondaryGeneratedTsFolder of secondaryGeneratedTsFolders) {\n yield `${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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/typings-generator",
3
- "version": "0.14.21",
3
+ "version": "0.14.23",
4
4
  "description": "This library provides functionality for automatically generating typings for non-TS files.",
5
5
  "keywords": [
6
6
  "dts",
@@ -16,14 +16,13 @@
16
16
  "directory": "libraries/typings-generator"
17
17
  },
18
18
  "dependencies": {
19
- "chokidar": "~3.4.0",
19
+ "chokidar": "~3.6.0",
20
20
  "fast-glob": "~3.3.1",
21
- "@rushstack/node-core-library": "5.11.0",
22
- "@rushstack/terminal": "0.15.0"
21
+ "@rushstack/terminal": "0.15.0",
22
+ "@rushstack/node-core-library": "5.11.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/glob": "7.1.1",
26
- "@rushstack/heft": "0.68.17",
25
+ "@rushstack/heft": "0.69.0",
27
26
  "local-node-rig": "1.0.0"
28
27
  },
29
28
  "peerDependencies": {