@rushstack/heft-typescript-plugin 1.2.4 → 1.3.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/CHANGELOG.json +44 -0
- package/CHANGELOG.md +13 -1
- package/dist/heft-typescript-plugin.d.ts +1 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib-commonjs/TypeScriptBuilder.js +65 -13
- package/lib-commonjs/TypeScriptBuilder.js.map +1 -1
- package/lib-commonjs/TypeScriptPlugin.js.map +1 -1
- package/lib-commonjs/schemas/typescript.schema.json +5 -0
- package/lib-commonjs/types.js.map +1 -1
- package/lib-dts/TypeScriptBuilder.d.ts +6 -0
- package/lib-dts/TypeScriptBuilder.d.ts.map +1 -1
- package/lib-dts/TypeScriptPlugin.d.ts +1 -0
- package/lib-dts/TypeScriptPlugin.d.ts.map +1 -1
- package/lib-dts/types.d.ts +5 -0
- package/lib-dts/types.d.ts.map +1 -1
- package/lib-esm/TypeScriptBuilder.js +65 -13
- package/lib-esm/TypeScriptBuilder.js.map +1 -1
- package/lib-esm/TypeScriptPlugin.js.map +1 -1
- package/lib-esm/schemas/typescript.schema.json +5 -0
- package/lib-esm/types.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptPlugin.js","sourceRoot":"","sources":["../src/TypeScriptPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6J3D,oFAQC;AAQD,oEAkEC;AA7OD,gDAAkC;AAGlC,qCAAmC;AAEnC,oEAA0D;AAE1D,kEAA8G;AAY9G,2DAA8F;AAC9F,0FAA4D;AAC5D,8FAAsE;AACtE,qDAAuD;AAEvD;;;;GAIG;AACU,QAAA,WAAW,GAAwB,mBAAmB,CAAC;AAEpE;;;GAGG;AACH,MAAM,gBAAgB,GAAmB,cAAc,CAAC;AAoGxD,MAAM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A0C,EAC1C,EAAE;gBACF,mDAAmD;gBACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC;oBAC9C,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC;SACF,CAAC;QAEF,kBAAkB;QAClB,MAAM,iBAAiB,GAAsB,IAAI,qCAAiB,CAAC,8BAA8B,CAAC,CAAC;QACnG,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAC5B,WAA6B,EAC7B,iBAAoC;QAEpC,MAAM,QAAQ,GAAc,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;QAExD,MAAM,2BAA2B,GAC/B,MAAM,oCAAoC,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QAE1E,MAAM,mBAAmB,GAAiC,MAAM,4BAA4B,CAC1F,iBAAiB,EACjB,QAAQ,EACR,2BAA2B,CAC5B,CAAC;QAEF,OAAO;YACL,2BAA2B;YAC3B,mBAAmB;SACpB,CAAC;IACJ,CAAC;CACF;AArKD,mCAqKC","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 * as path from 'node:path';\n\nimport type * as TTypescript from 'typescript';\nimport { SyncHook } from 'tapable';\n\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { ITerminal } from '@rushstack/terminal';\nimport { ProjectConfigurationFile, InheritanceType, PathResolutionMethod } from '@rushstack/heft-config-file';\nimport type {\n HeftConfiguration,\n IHeftTaskSession,\n IHeftTaskPlugin,\n IHeftTaskRunHookOptions,\n IHeftTaskRunIncrementalHookOptions,\n ICopyOperation,\n IHeftTaskFileOperations,\n ConfigurationFile\n} from '@rushstack/heft';\n\nimport { TypeScriptBuilder, type ITypeScriptBuilderConfiguration } from './TypeScriptBuilder';\nimport anythingSchema from './schemas/anything.schema.json';\nimport typescriptConfigSchema from './schemas/typescript.schema.json';\nimport { getTsconfigFilePath } from './tsconfigLoader';\n\n/**\n * The name of the plugin, as specified in heft-plugin.json\n *\n * @public\n */\nexport const PLUGIN_NAME: 'typescript-plugin' = 'typescript-plugin';\n\n/**\n * The ${configDir} token supported in TypeScript 5.5\n * @see {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#the-configdir-template-variable-for-configuration-files}\n */\nconst CONFIG_DIR_TOKEN: '${configDir}' = '${configDir}';\n\n/**\n * @beta\n */\nexport interface IEmitModuleKind {\n moduleKind: 'commonjs' | 'amd' | 'umd' | 'system' | 'es2015' | 'esnext';\n outFolderName: string;\n jsExtensionOverride?: string;\n}\n\n/**\n * @beta\n */\nexport interface IStaticAssetsCopyConfiguration {\n fileExtensions: string[];\n excludeGlobs: string[];\n includeGlobs: string[];\n}\n\n/**\n * @beta\n */\nexport interface ITypeScriptConfigurationJson {\n /**\n * If provided, emit these module kinds in addition to the modules specified in the tsconfig.\n * Note that this option only applies to the main tsconfig.json configuration.\n */\n additionalModuleKindsToEmit?: IEmitModuleKind[] | undefined;\n\n /**\n * If 'true', emit CommonJS output into the TSConfig outDir with the file extension '.cjs'\n */\n emitCjsExtensionForCommonJS?: boolean | undefined;\n\n /**\n * If 'true', emit ESModule output into the TSConfig outDir with the file extension '.mjs'\n */\n emitMjsExtensionForESModule?: boolean | undefined;\n\n /**\n * If true, enable behavior analogous to the \"tsc --build\" command. Will build projects referenced by the main project in dependency order.\n * Note that this will effectively enable \\\"noEmitOnError\\\".\n */\n buildProjectReferences?: boolean;\n\n /**\n * If true, and the tsconfig has \\\"isolatedModules\\\": true, then transpilation will happen in parallel in a worker thread.\n */\n useTranspilerWorker?: boolean;\n\n /**\n * If true, the TypeScript compiler will only resolve symlinks to their targets if the links are in a node_modules folder.\n * This significantly reduces file system operations in typical usage.\n */\n onlyResolveSymlinksInNodeModules?: boolean;\n\n /*\n * Specifies the tsconfig.json file that will be used for compilation. Equivalent to the \"project\" argument for the 'tsc' and 'tslint' command line tools.\n *\n * The default value is \"./tsconfig.json\"\n */\n project?: string;\n\n /**\n * Configures additional file types that should be copied into the TypeScript compiler's emit folders, for example\n * so that these files can be resolved by import statements.\n */\n staticAssetsToCopy?: IStaticAssetsCopyConfiguration;\n}\n\n/**\n * @beta\n */\nexport interface IPartialTsconfigCompilerOptions {\n outDir?: string;\n}\n\n/**\n * @beta\n */\nexport interface IPartialTsconfig {\n compilerOptions?: IPartialTsconfigCompilerOptions;\n}\n\n/**\n * @beta\n */\nexport interface IChangedFilesHookOptions {\n program: TTypescript.Program;\n changedFiles?: ReadonlySet<TTypescript.SourceFile>;\n}\n\n/**\n * @beta\n */\nexport interface ITypeScriptPluginAccessor {\n readonly onChangedFilesHook: SyncHook<IChangedFilesHookOptions>;\n}\n\nconst TYPESCRIPT_LOADER_CONFIG: ConfigurationFile.IProjectConfigurationFileSpecification<ITypeScriptConfigurationJson> =\n {\n projectRelativeFilePath: 'config/typescript.json',\n jsonSchemaObject: typescriptConfigSchema,\n propertyInheritance: {\n staticAssetsToCopy: {\n // When merging objects, arrays will be automatically appended\n inheritanceType: InheritanceType.merge\n }\n },\n jsonPathMetadata: {\n '$.additionalModuleKindsToEmit.*.outFolderName': {\n pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot\n }\n }\n };\n\n/**\n * @beta\n */\nexport async function loadTypeScriptConfigurationFileAsync(\n heftConfiguration: HeftConfiguration,\n terminal: ITerminal\n): Promise<ITypeScriptConfigurationJson | undefined> {\n return await heftConfiguration.tryLoadProjectConfigurationFileAsync<ITypeScriptConfigurationJson>(\n TYPESCRIPT_LOADER_CONFIG,\n terminal\n );\n}\n\nlet _partialTsconfigFileLoader: ProjectConfigurationFile<IPartialTsconfig> | undefined;\nconst _partialTsconfigFilePromiseCache: Map<string, Promise<IPartialTsconfig | undefined>> = new Map();\n\n/**\n * @beta\n */\nexport async function loadPartialTsconfigFileAsync(\n heftConfiguration: HeftConfiguration,\n terminal: ITerminal,\n typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined\n): Promise<IPartialTsconfig | undefined> {\n const buildFolderPath: string = heftConfiguration.buildFolderPath;\n\n // Check the cache first\n let partialTsconfigFilePromise: Promise<IPartialTsconfig | undefined> | undefined =\n _partialTsconfigFilePromiseCache.get(buildFolderPath);\n\n if (!partialTsconfigFilePromise) {\n // We don't want to load the tsconfig.json file through the rig, but we do want to take\n // advantage of the extends functionality that ConfigurationFile provides. So we'll\n // check to see if the file exists and exit early if not.\n\n const tsconfigFilePath: string = getTsconfigFilePath(\n heftConfiguration,\n typeScriptConfigurationJson?.project\n );\n terminal.writeVerboseLine(`Looking for tsconfig at ${tsconfigFilePath}`);\n const tsconfigExists: boolean = await FileSystem.existsAsync(tsconfigFilePath);\n if (!tsconfigExists) {\n partialTsconfigFilePromise = Promise.resolve(undefined);\n } else {\n // Ensure that the file loader has been initialized.\n if (!_partialTsconfigFileLoader) {\n _partialTsconfigFileLoader = new ProjectConfigurationFile<IPartialTsconfig>({\n projectRelativeFilePath: typeScriptConfigurationJson?.project || 'tsconfig.json',\n jsonSchemaObject: anythingSchema,\n propertyInheritance: {\n compilerOptions: {\n inheritanceType: InheritanceType.merge\n }\n },\n jsonPathMetadata: {\n '$.compilerOptions.outDir': {\n pathResolutionMethod: PathResolutionMethod.custom,\n customResolver(\n resolverOptions: ConfigurationFile.IJsonPathMetadataResolverOptions<IPartialTsconfig>\n ): string {\n if (resolverOptions.propertyValue.includes(CONFIG_DIR_TOKEN)) {\n // Typescript 5.5. introduced the `${configDir}` token to refer to the directory containing the root tsconfig\n const configDir: string = path.dirname(tsconfigFilePath);\n // The token is an absolute path, so it should occur at most once.\n return path.resolve(resolverOptions.propertyValue.replace(CONFIG_DIR_TOKEN, configDir));\n } else {\n const thisConfigDir: string = path.dirname(resolverOptions.configurationFilePath);\n return path.resolve(thisConfigDir, resolverOptions.propertyValue);\n }\n }\n }\n }\n });\n }\n\n partialTsconfigFilePromise = _partialTsconfigFileLoader.loadConfigurationFileForProjectAsync(\n terminal,\n buildFolderPath,\n heftConfiguration.rigConfig\n );\n }\n _partialTsconfigFilePromiseCache.set(buildFolderPath, partialTsconfigFilePromise);\n }\n\n return await partialTsconfigFilePromise;\n}\n\ninterface ITypeScriptConfigurationJsonAndPartialTsconfigFile {\n typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined;\n partialTsconfigFile: IPartialTsconfig | undefined;\n}\n\nexport default class TypeScriptPlugin implements IHeftTaskPlugin {\n public accessor: ITypeScriptPluginAccessor = {\n onChangedFilesHook: new SyncHook<IChangedFilesHookOptions>(['changedFilesHookOptions'])\n };\n\n public apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration): void {\n taskSession.hooks.registerFileOperations.tapPromise(\n PLUGIN_NAME,\n async (fileOperations: IHeftTaskFileOperations): Promise<IHeftTaskFileOperations> => {\n // TODO: We should consider maybe only doing one copy of static assets and pointing\n // all source files to this set of static assets. This would allow us to avoid\n // having to copy the static assets multiple times, increasing build times and\n // package size.\n for (const copyOperation of await this._getStaticAssetCopyOperationsAsync(\n taskSession,\n heftConfiguration\n )) {\n fileOperations.copyOperations.add(copyOperation);\n }\n\n return fileOperations;\n }\n );\n\n taskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions: IHeftTaskRunHookOptions) => {\n const builder: TypeScriptBuilder | false = await this._getTypeScriptBuilderAsync(\n taskSession,\n heftConfiguration\n );\n if (builder) {\n await builder.invokeAsync();\n }\n });\n\n let incrementalBuilder: TypeScriptBuilder | undefined | false;\n taskSession.hooks.runIncremental.tapPromise(\n PLUGIN_NAME,\n async (runIncrementalOptions: IHeftTaskRunIncrementalHookOptions) => {\n if (incrementalBuilder === undefined) {\n // eslint-disable-next-line require-atomic-updates\n incrementalBuilder = await this._getTypeScriptBuilderAsync(taskSession, heftConfiguration);\n }\n\n if (incrementalBuilder) {\n await incrementalBuilder.invokeAsync(runIncrementalOptions.requestRun);\n }\n }\n );\n }\n\n private async _getStaticAssetCopyOperationsAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<ICopyOperation[]> {\n const { typeScriptConfigurationJson, partialTsconfigFile } = await this._loadConfigAsync(\n taskSession,\n heftConfiguration\n );\n\n // We only care about the copy if static assets were specified.\n const copyOperations: ICopyOperation[] = [];\n const staticAssetsConfig: IStaticAssetsCopyConfiguration | undefined =\n typeScriptConfigurationJson?.staticAssetsToCopy;\n if (\n staticAssetsConfig &&\n (staticAssetsConfig.fileExtensions?.length ||\n staticAssetsConfig.includeGlobs?.length ||\n staticAssetsConfig.excludeGlobs?.length)\n ) {\n const destinationFolderPaths: Set<string> = new Set<string>();\n\n // Add the output folder and all additional module kind output folders as destinations\n const tsconfigOutDir: string | undefined = partialTsconfigFile?.compilerOptions?.outDir;\n if (tsconfigOutDir) {\n destinationFolderPaths.add(tsconfigOutDir);\n }\n\n for (const emitModule of typeScriptConfigurationJson?.additionalModuleKindsToEmit || []) {\n destinationFolderPaths.add(emitModule.outFolderName);\n }\n\n copyOperations.push({\n ...staticAssetsConfig,\n\n // For now - these may need to be revised later\n sourcePath: path.resolve(heftConfiguration.buildFolderPath, 'src'),\n destinationFolders: Array.from(destinationFolderPaths),\n flatten: false,\n hardlink: false\n });\n }\n\n return copyOperations;\n }\n\n private async _getTypeScriptBuilderAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<TypeScriptBuilder | false> {\n const { typeScriptConfigurationJson, partialTsconfigFile } = await this._loadConfigAsync(\n taskSession,\n heftConfiguration\n );\n\n if (!partialTsconfigFile) {\n // There is no tsconfig file, we can exit early\n // This check may need watch mode to break on tsconfig addition/deletion\n return false;\n }\n\n // Build out the configuration\n const typeScriptBuilderConfiguration: ITypeScriptBuilderConfiguration = {\n buildFolderPath: heftConfiguration.buildFolderPath,\n // Build metadata is just another build output, but we put it in the temp folder because it will\n // usually be discarded when published.\n buildMetadataFolderPath: taskSession.tempFolderPath,\n heftConfiguration,\n\n buildProjectReferences: typeScriptConfigurationJson?.buildProjectReferences,\n\n useTranspilerWorker: typeScriptConfigurationJson?.useTranspilerWorker,\n\n onlyResolveSymlinksInNodeModules: typeScriptConfigurationJson?.onlyResolveSymlinksInNodeModules,\n\n tsconfigPath: getTsconfigFilePath(heftConfiguration, typeScriptConfigurationJson?.project),\n additionalModuleKindsToEmit: typeScriptConfigurationJson?.additionalModuleKindsToEmit,\n emitCjsExtensionForCommonJS: !!typeScriptConfigurationJson?.emitCjsExtensionForCommonJS,\n emitMjsExtensionForESModule: !!typeScriptConfigurationJson?.emitMjsExtensionForESModule,\n scopedLogger: taskSession.logger,\n emitChangedFilesCallback: (\n program: TTypescript.Program,\n changedFiles?: Set<TTypescript.SourceFile>\n ) => {\n // Provide the typescript program dependent plugins\n if (this.accessor.onChangedFilesHook.isUsed()) {\n this.accessor.onChangedFilesHook.call({ program, changedFiles });\n }\n }\n };\n\n // Run the builder\n const typeScriptBuilder: TypeScriptBuilder = new TypeScriptBuilder(typeScriptBuilderConfiguration);\n return typeScriptBuilder;\n }\n\n private async _loadConfigAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<ITypeScriptConfigurationJsonAndPartialTsconfigFile> {\n const terminal: ITerminal = taskSession.logger.terminal;\n\n const typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined =\n await loadTypeScriptConfigurationFileAsync(heftConfiguration, terminal);\n\n const partialTsconfigFile: IPartialTsconfig | undefined = await loadPartialTsconfigFileAsync(\n heftConfiguration,\n terminal,\n typeScriptConfigurationJson\n );\n\n return {\n typeScriptConfigurationJson,\n partialTsconfigFile\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TypeScriptPlugin.js","sourceRoot":"","sources":["../src/TypeScriptPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8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2BAA2B,EAAE,CAAC,CAAC,CAAA,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAE,2BAA2B,CAAA;YACvF,2BAA2B,EAAE,CAAC,CAAC,CAAA,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAE,2BAA2B,CAAA;YACvF,YAAY,EAAE,WAAW,CAAC,MAAM;YAChC,wBAAwB,EAAE,CACxB,OAA4B,EAC5B,YAA0C,EAC1C,EAAE;gBACF,mDAAmD;gBACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC;oBAC9C,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC;SACF,CAAC;QAEF,kBAAkB;QAClB,MAAM,iBAAiB,GAAsB,IAAI,qCAAiB,CAAC,8BAA8B,CAAC,CAAC;QACnG,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAC5B,WAA6B,EAC7B,iBAAoC;QAEpC,MAAM,QAAQ,GAAc,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;QAExD,MAAM,2BAA2B,GAC/B,MAAM,oCAAoC,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QAE1E,MAAM,mBAAmB,GAAiC,MAAM,4BAA4B,CAC1F,iBAAiB,EACjB,QAAQ,EACR,2BAA2B,CAC5B,CAAC;QAEF,OAAO;YACL,2BAA2B;YAC3B,mBAAmB;SACpB,CAAC;IACJ,CAAC;CACF;AArKD,mCAqKC","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 * as path from 'node:path';\n\nimport type * as TTypescript from 'typescript';\nimport { SyncHook } from 'tapable';\n\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { ITerminal } from '@rushstack/terminal';\nimport { ProjectConfigurationFile, InheritanceType, PathResolutionMethod } from '@rushstack/heft-config-file';\nimport type {\n HeftConfiguration,\n IHeftTaskSession,\n IHeftTaskPlugin,\n IHeftTaskRunHookOptions,\n IHeftTaskRunIncrementalHookOptions,\n ICopyOperation,\n IHeftTaskFileOperations,\n ConfigurationFile\n} from '@rushstack/heft';\n\nimport { TypeScriptBuilder, type ITypeScriptBuilderConfiguration } from './TypeScriptBuilder';\nimport anythingSchema from './schemas/anything.schema.json';\nimport typescriptConfigSchema from './schemas/typescript.schema.json';\nimport { getTsconfigFilePath } from './tsconfigLoader';\n\n/**\n * The name of the plugin, as specified in heft-plugin.json\n *\n * @public\n */\nexport const PLUGIN_NAME: 'typescript-plugin' = 'typescript-plugin';\n\n/**\n * The ${configDir} token supported in TypeScript 5.5\n * @see {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#the-configdir-template-variable-for-configuration-files}\n */\nconst CONFIG_DIR_TOKEN: '${configDir}' = '${configDir}';\n\n/**\n * @beta\n */\nexport interface IEmitModuleKind {\n moduleKind: 'commonjs' | 'amd' | 'umd' | 'system' | 'es2015' | 'esnext';\n outFolderName: string;\n jsExtensionOverride?: string;\n emitModulePackageJson?: boolean;\n}\n\n/**\n * @beta\n */\nexport interface IStaticAssetsCopyConfiguration {\n fileExtensions: string[];\n excludeGlobs: string[];\n includeGlobs: string[];\n}\n\n/**\n * @beta\n */\nexport interface ITypeScriptConfigurationJson {\n /**\n * If provided, emit these module kinds in addition to the modules specified in the tsconfig.\n * Note that this option only applies to the main tsconfig.json configuration.\n */\n additionalModuleKindsToEmit?: IEmitModuleKind[] | undefined;\n\n /**\n * If 'true', emit CommonJS output into the TSConfig outDir with the file extension '.cjs'\n */\n emitCjsExtensionForCommonJS?: boolean | undefined;\n\n /**\n * If 'true', emit ESModule output into the TSConfig outDir with the file extension '.mjs'\n */\n emitMjsExtensionForESModule?: boolean | undefined;\n\n /**\n * If true, enable behavior analogous to the \"tsc --build\" command. Will build projects referenced by the main project in dependency order.\n * Note that this will effectively enable \\\"noEmitOnError\\\".\n */\n buildProjectReferences?: boolean;\n\n /**\n * If true, and the tsconfig has \\\"isolatedModules\\\": true, then transpilation will happen in parallel in a worker thread.\n */\n useTranspilerWorker?: boolean;\n\n /**\n * If true, the TypeScript compiler will only resolve symlinks to their targets if the links are in a node_modules folder.\n * This significantly reduces file system operations in typical usage.\n */\n onlyResolveSymlinksInNodeModules?: boolean;\n\n /*\n * Specifies the tsconfig.json file that will be used for compilation. Equivalent to the \"project\" argument for the 'tsc' and 'tslint' command line tools.\n *\n * The default value is \"./tsconfig.json\"\n */\n project?: string;\n\n /**\n * Configures additional file types that should be copied into the TypeScript compiler's emit folders, for example\n * so that these files can be resolved by import statements.\n */\n staticAssetsToCopy?: IStaticAssetsCopyConfiguration;\n}\n\n/**\n * @beta\n */\nexport interface IPartialTsconfigCompilerOptions {\n outDir?: string;\n}\n\n/**\n * @beta\n */\nexport interface IPartialTsconfig {\n compilerOptions?: IPartialTsconfigCompilerOptions;\n}\n\n/**\n * @beta\n */\nexport interface IChangedFilesHookOptions {\n program: TTypescript.Program;\n changedFiles?: ReadonlySet<TTypescript.SourceFile>;\n}\n\n/**\n * @beta\n */\nexport interface ITypeScriptPluginAccessor {\n readonly onChangedFilesHook: SyncHook<IChangedFilesHookOptions>;\n}\n\nconst TYPESCRIPT_LOADER_CONFIG: ConfigurationFile.IProjectConfigurationFileSpecification<ITypeScriptConfigurationJson> =\n {\n projectRelativeFilePath: 'config/typescript.json',\n jsonSchemaObject: typescriptConfigSchema,\n propertyInheritance: {\n staticAssetsToCopy: {\n // When merging objects, arrays will be automatically appended\n inheritanceType: InheritanceType.merge\n }\n },\n jsonPathMetadata: {\n '$.additionalModuleKindsToEmit.*.outFolderName': {\n pathResolutionMethod: PathResolutionMethod.resolvePathRelativeToProjectRoot\n }\n }\n };\n\n/**\n * @beta\n */\nexport async function loadTypeScriptConfigurationFileAsync(\n heftConfiguration: HeftConfiguration,\n terminal: ITerminal\n): Promise<ITypeScriptConfigurationJson | undefined> {\n return await heftConfiguration.tryLoadProjectConfigurationFileAsync<ITypeScriptConfigurationJson>(\n TYPESCRIPT_LOADER_CONFIG,\n terminal\n );\n}\n\nlet _partialTsconfigFileLoader: ProjectConfigurationFile<IPartialTsconfig> | undefined;\nconst _partialTsconfigFilePromiseCache: Map<string, Promise<IPartialTsconfig | undefined>> = new Map();\n\n/**\n * @beta\n */\nexport async function loadPartialTsconfigFileAsync(\n heftConfiguration: HeftConfiguration,\n terminal: ITerminal,\n typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined\n): Promise<IPartialTsconfig | undefined> {\n const buildFolderPath: string = heftConfiguration.buildFolderPath;\n\n // Check the cache first\n let partialTsconfigFilePromise: Promise<IPartialTsconfig | undefined> | undefined =\n _partialTsconfigFilePromiseCache.get(buildFolderPath);\n\n if (!partialTsconfigFilePromise) {\n // We don't want to load the tsconfig.json file through the rig, but we do want to take\n // advantage of the extends functionality that ConfigurationFile provides. So we'll\n // check to see if the file exists and exit early if not.\n\n const tsconfigFilePath: string = getTsconfigFilePath(\n heftConfiguration,\n typeScriptConfigurationJson?.project\n );\n terminal.writeVerboseLine(`Looking for tsconfig at ${tsconfigFilePath}`);\n const tsconfigExists: boolean = await FileSystem.existsAsync(tsconfigFilePath);\n if (!tsconfigExists) {\n partialTsconfigFilePromise = Promise.resolve(undefined);\n } else {\n // Ensure that the file loader has been initialized.\n if (!_partialTsconfigFileLoader) {\n _partialTsconfigFileLoader = new ProjectConfigurationFile<IPartialTsconfig>({\n projectRelativeFilePath: typeScriptConfigurationJson?.project || 'tsconfig.json',\n jsonSchemaObject: anythingSchema,\n propertyInheritance: {\n compilerOptions: {\n inheritanceType: InheritanceType.merge\n }\n },\n jsonPathMetadata: {\n '$.compilerOptions.outDir': {\n pathResolutionMethod: PathResolutionMethod.custom,\n customResolver(\n resolverOptions: ConfigurationFile.IJsonPathMetadataResolverOptions<IPartialTsconfig>\n ): string {\n if (resolverOptions.propertyValue.includes(CONFIG_DIR_TOKEN)) {\n // Typescript 5.5. introduced the `${configDir}` token to refer to the directory containing the root tsconfig\n const configDir: string = path.dirname(tsconfigFilePath);\n // The token is an absolute path, so it should occur at most once.\n return path.resolve(resolverOptions.propertyValue.replace(CONFIG_DIR_TOKEN, configDir));\n } else {\n const thisConfigDir: string = path.dirname(resolverOptions.configurationFilePath);\n return path.resolve(thisConfigDir, resolverOptions.propertyValue);\n }\n }\n }\n }\n });\n }\n\n partialTsconfigFilePromise = _partialTsconfigFileLoader.loadConfigurationFileForProjectAsync(\n terminal,\n buildFolderPath,\n heftConfiguration.rigConfig\n );\n }\n _partialTsconfigFilePromiseCache.set(buildFolderPath, partialTsconfigFilePromise);\n }\n\n return await partialTsconfigFilePromise;\n}\n\ninterface ITypeScriptConfigurationJsonAndPartialTsconfigFile {\n typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined;\n partialTsconfigFile: IPartialTsconfig | undefined;\n}\n\nexport default class TypeScriptPlugin implements IHeftTaskPlugin {\n public accessor: ITypeScriptPluginAccessor = {\n onChangedFilesHook: new SyncHook<IChangedFilesHookOptions>(['changedFilesHookOptions'])\n };\n\n public apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration): void {\n taskSession.hooks.registerFileOperations.tapPromise(\n PLUGIN_NAME,\n async (fileOperations: IHeftTaskFileOperations): Promise<IHeftTaskFileOperations> => {\n // TODO: We should consider maybe only doing one copy of static assets and pointing\n // all source files to this set of static assets. This would allow us to avoid\n // having to copy the static assets multiple times, increasing build times and\n // package size.\n for (const copyOperation of await this._getStaticAssetCopyOperationsAsync(\n taskSession,\n heftConfiguration\n )) {\n fileOperations.copyOperations.add(copyOperation);\n }\n\n return fileOperations;\n }\n );\n\n taskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions: IHeftTaskRunHookOptions) => {\n const builder: TypeScriptBuilder | false = await this._getTypeScriptBuilderAsync(\n taskSession,\n heftConfiguration\n );\n if (builder) {\n await builder.invokeAsync();\n }\n });\n\n let incrementalBuilder: TypeScriptBuilder | undefined | false;\n taskSession.hooks.runIncremental.tapPromise(\n PLUGIN_NAME,\n async (runIncrementalOptions: IHeftTaskRunIncrementalHookOptions) => {\n if (incrementalBuilder === undefined) {\n // eslint-disable-next-line require-atomic-updates\n incrementalBuilder = await this._getTypeScriptBuilderAsync(taskSession, heftConfiguration);\n }\n\n if (incrementalBuilder) {\n await incrementalBuilder.invokeAsync(runIncrementalOptions.requestRun);\n }\n }\n );\n }\n\n private async _getStaticAssetCopyOperationsAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<ICopyOperation[]> {\n const { typeScriptConfigurationJson, partialTsconfigFile } = await this._loadConfigAsync(\n taskSession,\n heftConfiguration\n );\n\n // We only care about the copy if static assets were specified.\n const copyOperations: ICopyOperation[] = [];\n const staticAssetsConfig: IStaticAssetsCopyConfiguration | undefined =\n typeScriptConfigurationJson?.staticAssetsToCopy;\n if (\n staticAssetsConfig &&\n (staticAssetsConfig.fileExtensions?.length ||\n staticAssetsConfig.includeGlobs?.length ||\n staticAssetsConfig.excludeGlobs?.length)\n ) {\n const destinationFolderPaths: Set<string> = new Set<string>();\n\n // Add the output folder and all additional module kind output folders as destinations\n const tsconfigOutDir: string | undefined = partialTsconfigFile?.compilerOptions?.outDir;\n if (tsconfigOutDir) {\n destinationFolderPaths.add(tsconfigOutDir);\n }\n\n for (const emitModule of typeScriptConfigurationJson?.additionalModuleKindsToEmit || []) {\n destinationFolderPaths.add(emitModule.outFolderName);\n }\n\n copyOperations.push({\n ...staticAssetsConfig,\n\n // For now - these may need to be revised later\n sourcePath: path.resolve(heftConfiguration.buildFolderPath, 'src'),\n destinationFolders: Array.from(destinationFolderPaths),\n flatten: false,\n hardlink: false\n });\n }\n\n return copyOperations;\n }\n\n private async _getTypeScriptBuilderAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<TypeScriptBuilder | false> {\n const { typeScriptConfigurationJson, partialTsconfigFile } = await this._loadConfigAsync(\n taskSession,\n heftConfiguration\n );\n\n if (!partialTsconfigFile) {\n // There is no tsconfig file, we can exit early\n // This check may need watch mode to break on tsconfig addition/deletion\n return false;\n }\n\n // Build out the configuration\n const typeScriptBuilderConfiguration: ITypeScriptBuilderConfiguration = {\n buildFolderPath: heftConfiguration.buildFolderPath,\n // Build metadata is just another build output, but we put it in the temp folder because it will\n // usually be discarded when published.\n buildMetadataFolderPath: taskSession.tempFolderPath,\n heftConfiguration,\n\n buildProjectReferences: typeScriptConfigurationJson?.buildProjectReferences,\n\n useTranspilerWorker: typeScriptConfigurationJson?.useTranspilerWorker,\n\n onlyResolveSymlinksInNodeModules: typeScriptConfigurationJson?.onlyResolveSymlinksInNodeModules,\n\n tsconfigPath: getTsconfigFilePath(heftConfiguration, typeScriptConfigurationJson?.project),\n additionalModuleKindsToEmit: typeScriptConfigurationJson?.additionalModuleKindsToEmit,\n emitCjsExtensionForCommonJS: !!typeScriptConfigurationJson?.emitCjsExtensionForCommonJS,\n emitMjsExtensionForESModule: !!typeScriptConfigurationJson?.emitMjsExtensionForESModule,\n scopedLogger: taskSession.logger,\n emitChangedFilesCallback: (\n program: TTypescript.Program,\n changedFiles?: Set<TTypescript.SourceFile>\n ) => {\n // Provide the typescript program dependent plugins\n if (this.accessor.onChangedFilesHook.isUsed()) {\n this.accessor.onChangedFilesHook.call({ program, changedFiles });\n }\n }\n };\n\n // Run the builder\n const typeScriptBuilder: TypeScriptBuilder = new TypeScriptBuilder(typeScriptBuilderConfiguration);\n return typeScriptBuilder;\n }\n\n private async _loadConfigAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<ITypeScriptConfigurationJsonAndPartialTsconfigFile> {\n const terminal: ITerminal = taskSession.logger.terminal;\n\n const typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined =\n await loadTypeScriptConfigurationFileAsync(heftConfiguration, terminal);\n\n const partialTsconfigFile: IPartialTsconfig | undefined = await loadPartialTsconfigFileAsync(\n heftConfiguration,\n terminal,\n typeScriptConfigurationJson\n );\n\n return {\n typeScriptConfigurationJson,\n partialTsconfigFile\n };\n }\n}\n"]}
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"outFolderName": {
|
|
32
32
|
"type": "string",
|
|
33
33
|
"pattern": "[^\\\\\\/]"
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
"emitModulePackageJson": {
|
|
37
|
+
"description": "If true, a package.json file will be written to the output folder with the appropriate \"type\" field for the specified module kind. This ensures that Node.js correctly interprets .js files in the output folder regardless of the nearest ancestor package.json \"type\" setting. Only valid for CommonJS, UMD, and ES module kinds.",
|
|
38
|
+
"type": "boolean"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"required": ["moduleKind", "outFolderName"]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 type * as TTypescript from 'typescript';\n\nexport interface ITypescriptWorkerData {\n /**\n * Path to the version of TypeScript to use.\n */\n typeScriptToolPath: string;\n}\n\nexport interface ITranspilationRequestMessage {\n /**\n * Unique identifier for this request.\n */\n requestId: number;\n /**\n * The tsconfig compiler options to use for the request.\n */\n compilerOptions: TTypescript.CompilerOptions;\n /**\n * The variants to emit.\n */\n moduleKindsToEmit: ICachedEmitModuleKind[];\n /**\n * The set of files to build.\n */\n filesToTranspile: Map<string, string>;\n}\n\nexport interface ITranspilationSuccessMessage {\n requestId: number;\n type: 'success';\n result: TTypescript.EmitResult;\n}\n\nexport interface ITranspilationErrorMessage {\n requestId: number;\n type: 'error';\n result: {\n message: string;\n [key: string]: unknown;\n };\n}\n\nexport type ITranspilationResponseMessage = ITranspilationSuccessMessage | ITranspilationErrorMessage;\n\nexport interface ICachedEmitModuleKind {\n moduleKind: TTypescript.ModuleKind;\n\n outFolderPath: string;\n\n /**\n * File extension to use instead of '.js' for emitted ECMAScript files.\n * For example, '.cjs' to indicate commonjs content, or '.mjs' to indicate ECMAScript modules.\n */\n jsExtensionOverride: string | undefined;\n\n /**\n * Set to true if this is the emit kind that is specified in the tsconfig.json.\n * Declarations are only emitted for the primary module kind.\n */\n isPrimary: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 type * as TTypescript from 'typescript';\n\nexport interface ITypescriptWorkerData {\n /**\n * Path to the version of TypeScript to use.\n */\n typeScriptToolPath: string;\n}\n\nexport interface ITranspilationRequestMessage {\n /**\n * Unique identifier for this request.\n */\n requestId: number;\n /**\n * The tsconfig compiler options to use for the request.\n */\n compilerOptions: TTypescript.CompilerOptions;\n /**\n * The variants to emit.\n */\n moduleKindsToEmit: ICachedEmitModuleKind[];\n /**\n * The set of files to build.\n */\n filesToTranspile: Map<string, string>;\n}\n\nexport interface ITranspilationSuccessMessage {\n requestId: number;\n type: 'success';\n result: TTypescript.EmitResult;\n}\n\nexport interface ITranspilationErrorMessage {\n requestId: number;\n type: 'error';\n result: {\n message: string;\n [key: string]: unknown;\n };\n}\n\nexport type ITranspilationResponseMessage = ITranspilationSuccessMessage | ITranspilationErrorMessage;\n\nexport interface ICachedEmitModuleKind {\n moduleKind: TTypescript.ModuleKind;\n\n outFolderPath: string;\n\n /**\n * File extension to use instead of '.js' for emitted ECMAScript files.\n * For example, '.cjs' to indicate commonjs content, or '.mjs' to indicate ECMAScript modules.\n */\n jsExtensionOverride: string | undefined;\n\n /**\n * Set to true if this is the emit kind that is specified in the tsconfig.json.\n * Declarations are only emitted for the primary module kind.\n */\n isPrimary: boolean;\n\n /**\n * If true, a package.json with the appropriate \"type\" field will be written\n * to the output folder after emit.\n */\n emitModulePackageJson: boolean;\n}\n"]}
|
|
@@ -88,6 +88,12 @@ export declare class TypeScriptBuilder {
|
|
|
88
88
|
private _buildWatchCompilerHost;
|
|
89
89
|
private _changeCompilerHostToUseCache;
|
|
90
90
|
private _buildWatchSolutionBuilderHost;
|
|
91
|
+
/**
|
|
92
|
+
* For each module kind configured with `emitModulePackageJson: true`, writes a
|
|
93
|
+
* `package.json` with the appropriate `"type"` field to ensure Node.js correctly
|
|
94
|
+
* interprets `.js` files in the output folder.
|
|
95
|
+
*/
|
|
96
|
+
private _emitModulePackageJsonFiles;
|
|
91
97
|
private _parseModuleKind;
|
|
92
98
|
private _queueTranspileInWorker;
|
|
93
99
|
private _cleanupWorker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptBuilder.d.ts","sourceRoot":"","sources":["../src/TypeScriptBuilder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,KAAK,KAAK,WAAW,MAAM,YAAY,CAAC;AAI/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAExE,OAAO,KAAK,EAEV,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,4BAA4B,EAAmB,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAWzD,MAAM,WAAW,+BAAgC,SAAQ,4BAA4B;IACnF;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAEhC;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IAIrC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,YAAY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hC,OAAO,CAAC,yBAAyB;IA+BjC,OAAO,CAAC,6BAA6B;IAuBrC,OAAO,CAAC,uBAAuB;IAwB/B,OAAO,CAAC,6BAA6B;IA6CrC,OAAO,CAAC,8BAA8B;IActC;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IA8CnC,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,uBAAuB;IAiF/B,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptPlugin.d.ts","sourceRoot":"","sources":["../src/TypeScriptPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,WAAW,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAMhB,MAAM,iBAAiB,CAAC;AAOzB;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,mBAAyC,CAAC;AAQpE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACxE,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"TypeScriptPlugin.d.ts","sourceRoot":"","sources":["../src/TypeScriptPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,WAAW,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAMhB,MAAM,iBAAiB,CAAC;AAO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CAAC,UAAU,CAAC,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,kBAAkB,EAAE,QAAQ,CAAC,wBAAwB,CAAC,CAAC;CACjE;AAmBD;;GAEG;AACH,wBAAsB,oCAAoC,CACxD,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,SAAS,GAClB,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAAC,CAKnD;AAKD;;GAEG;AACH,wBAAsB,4BAA4B,CAChD,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,SAAS,EACnB,2BAA2B,EAAE,4BAA4B,GAAG,SAAS,GACpE,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CA8DvC;AAOD,MAAM,CAAC,OAAO,OAAO,gBAAiB,YAAW,eAAe;IACvD,QAAQ,EAAE,yBAAyB,CAExC;IAEK,KAAK,CAAC,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,IAAI;YA6CzE,kCAAkC;YA6ClC,0BAA0B;YAkD1B,gBAAgB;CAoB/B"}
|
package/lib-dts/types.d.ts
CHANGED
|
@@ -50,5 +50,10 @@ export interface ICachedEmitModuleKind {
|
|
|
50
50
|
* Declarations are only emitted for the primary module kind.
|
|
51
51
|
*/
|
|
52
52
|
isPrimary: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* If true, a package.json with the appropriate "type" field will be written
|
|
55
|
+
* to the output folder after emit.
|
|
56
|
+
*/
|
|
57
|
+
emitModulePackageJson: boolean;
|
|
53
58
|
}
|
|
54
59
|
//# sourceMappingURL=types.d.ts.map
|
package/lib-dts/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,WAAW,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,kB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iB,EAAE,qBAAqB,EAAE,CAAC;IAC3C;;OAEG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED,MAAM,MAAM,6BAA6B,GAAG,4BAA4B,GAAG,0BAA0B,CAAC;AAEtG,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC;IAEnC,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,qBAAqB,EAAE,OAAO,CAAC;CAChC"}
|
|
@@ -257,6 +257,7 @@ export class TypeScriptBuilder {
|
|
|
257
257
|
ts.sys.writeFile, undefined, undefined, undefined);
|
|
258
258
|
this._cleanupWorker();
|
|
259
259
|
//#endregion
|
|
260
|
+
this._emitModulePackageJsonFiles(ts);
|
|
260
261
|
this._logEmitPerformance(ts);
|
|
261
262
|
//#region FINAL_ANALYSIS
|
|
262
263
|
// Need to ensure that we include emit diagnostics, since they might not be part of the other sets
|
|
@@ -309,6 +310,7 @@ export class TypeScriptBuilder {
|
|
|
309
310
|
tool.solutionBuilder.build();
|
|
310
311
|
this._cleanupWorker();
|
|
311
312
|
//#endregion
|
|
313
|
+
this._emitModulePackageJsonFiles(ts);
|
|
312
314
|
if (pendingTranspilePromises.size) {
|
|
313
315
|
const emitResults = await Promise.all(pendingTranspilePromises.values());
|
|
314
316
|
for (const { diagnostics } of emitResults) {
|
|
@@ -422,7 +424,8 @@ export class TypeScriptBuilder {
|
|
|
422
424
|
}
|
|
423
425
|
if (this._configuration.emitCjsExtensionForCommonJS) {
|
|
424
426
|
this._addModuleKindToEmit(ts.ModuleKind.CommonJS, tsconfig.options.outDir,
|
|
425
|
-
/* isPrimary */ tsconfig.options.module === ts.ModuleKind.CommonJS, '.cjs'
|
|
427
|
+
/* isPrimary */ tsconfig.options.module === ts.ModuleKind.CommonJS, '.cjs',
|
|
428
|
+
/* emitModulePackageJson */ false);
|
|
426
429
|
const cjsReason = {
|
|
427
430
|
outDir: tsconfig.options.outDir,
|
|
428
431
|
kind: 'CommonJS',
|
|
@@ -434,7 +437,8 @@ export class TypeScriptBuilder {
|
|
|
434
437
|
}
|
|
435
438
|
if (this._configuration.emitMjsExtensionForESModule) {
|
|
436
439
|
this._addModuleKindToEmit(ts.ModuleKind.ESNext, tsconfig.options.outDir,
|
|
437
|
-
/* isPrimary */ tsconfig.options.module === ts.ModuleKind.ESNext, '.mjs'
|
|
440
|
+
/* isPrimary */ tsconfig.options.module === ts.ModuleKind.ESNext, '.mjs',
|
|
441
|
+
/* emitModulePackageJson */ false);
|
|
438
442
|
const mjsReason = {
|
|
439
443
|
outDir: tsconfig.options.outDir,
|
|
440
444
|
kind: 'ESNext',
|
|
@@ -447,7 +451,8 @@ export class TypeScriptBuilder {
|
|
|
447
451
|
if (!specifiedKinds.has(tsconfig.options.module)) {
|
|
448
452
|
this._addModuleKindToEmit(tsconfig.options.module, tsconfig.options.outDir,
|
|
449
453
|
/* isPrimary */ true,
|
|
450
|
-
/* jsExtensionOverride */ undefined
|
|
454
|
+
/* jsExtensionOverride */ undefined,
|
|
455
|
+
/* emitModulePackageJson */ false);
|
|
451
456
|
const tsConfigReason = {
|
|
452
457
|
outDir: tsconfig.options.outDir,
|
|
453
458
|
kind: ts.ModuleKind[tsconfig.options.module],
|
|
@@ -458,26 +463,27 @@ export class TypeScriptBuilder {
|
|
|
458
463
|
specifiedOutDirs.set(`${tsconfig.options.outDir}:.js`, tsConfigReason);
|
|
459
464
|
}
|
|
460
465
|
if (this._configuration.additionalModuleKindsToEmit) {
|
|
461
|
-
for (const
|
|
462
|
-
|
|
463
|
-
const
|
|
466
|
+
for (const { moduleKind: moduleKindString, outFolderName, emitModulePackageJson = false } of this
|
|
467
|
+
._configuration.additionalModuleKindsToEmit) {
|
|
468
|
+
const moduleKind = this._parseModuleKind(ts, moduleKindString);
|
|
469
|
+
const outDirKey = `${outFolderName}:.js`;
|
|
464
470
|
const moduleKindReason = {
|
|
465
471
|
kind: ts.ModuleKind[moduleKind],
|
|
466
|
-
outDir:
|
|
472
|
+
outDir: outFolderName,
|
|
467
473
|
extension: '.js',
|
|
468
474
|
reason: `additionalModuleKindsToEmit`
|
|
469
475
|
};
|
|
470
476
|
const existingKind = specifiedKinds.get(moduleKind);
|
|
471
477
|
const existingDir = specifiedOutDirs.get(outDirKey);
|
|
472
478
|
if (existingKind) {
|
|
473
|
-
throw new Error(`Module kind "${
|
|
479
|
+
throw new Error(`Module kind "${moduleKind}" is already emitted at ${existingKind.outDir} with extension '${existingKind.extension}' by option ${existingKind.reason}.`);
|
|
474
480
|
}
|
|
475
481
|
else if (existingDir) {
|
|
476
|
-
throw new Error(`Output folder "${
|
|
482
|
+
throw new Error(`Output folder "${outFolderName}" already contains module kind ${existingDir.kind} with extension '${existingDir.extension}', specified by option ${existingDir.reason}.`);
|
|
477
483
|
}
|
|
478
484
|
else {
|
|
479
|
-
const outFolderKey = this._addModuleKindToEmit(moduleKind,
|
|
480
|
-
/* isPrimary */ false, undefined);
|
|
485
|
+
const outFolderKey = this._addModuleKindToEmit(moduleKind, outFolderName,
|
|
486
|
+
/* isPrimary */ false, undefined, emitModulePackageJson);
|
|
481
487
|
if (outFolderKey) {
|
|
482
488
|
specifiedKinds.set(moduleKind, moduleKindReason);
|
|
483
489
|
specifiedOutDirs.set(outFolderKey, moduleKindReason);
|
|
@@ -486,7 +492,7 @@ export class TypeScriptBuilder {
|
|
|
486
492
|
}
|
|
487
493
|
}
|
|
488
494
|
}
|
|
489
|
-
_addModuleKindToEmit(moduleKind, outFolderPath, isPrimary, jsExtensionOverride) {
|
|
495
|
+
_addModuleKindToEmit(moduleKind, outFolderPath, isPrimary, jsExtensionOverride, emitModulePackageJson) {
|
|
490
496
|
let outFolderName;
|
|
491
497
|
if (path.isAbsolute(outFolderPath)) {
|
|
492
498
|
outFolderName = path.relative(this._configuration.buildFolderPath, outFolderPath);
|
|
@@ -533,7 +539,8 @@ export class TypeScriptBuilder {
|
|
|
533
539
|
outFolderPath,
|
|
534
540
|
moduleKind,
|
|
535
541
|
jsExtensionOverride,
|
|
536
|
-
isPrimary
|
|
542
|
+
isPrimary,
|
|
543
|
+
emitModulePackageJson
|
|
537
544
|
});
|
|
538
545
|
return `${outFolderName}:${jsExtensionOverride || '.js'}`;
|
|
539
546
|
}
|
|
@@ -561,6 +568,7 @@ export class TypeScriptBuilder {
|
|
|
561
568
|
const result = originalEmit.call(newProgram, outerTargetSourceFile, outerWriteFile, outerCancellationToken, outerEmitOnlyDtsFiles, outerCustomTransformers);
|
|
562
569
|
result.changedSourceFiles = changedFiles;
|
|
563
570
|
this._typescriptTerminal.writeVerboseLine(`Emitting program "${innerCompilerOptions.configFilePath}"`);
|
|
571
|
+
this._emitModulePackageJsonFiles(ts);
|
|
564
572
|
this._logEmitPerformance(ts);
|
|
565
573
|
// Reset performance counters
|
|
566
574
|
ts.performance.disable();
|
|
@@ -639,6 +647,50 @@ export class TypeScriptBuilder {
|
|
|
639
647
|
const host = ts.createSolutionBuilderWithWatchHost(system, this._getCreateBuilderProgram(ts), reportDiagnostic, reportDiagnostic, reportDiagnostic);
|
|
640
648
|
return host;
|
|
641
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* For each module kind configured with `emitModulePackageJson: true`, writes a
|
|
652
|
+
* `package.json` with the appropriate `"type"` field to ensure Node.js correctly
|
|
653
|
+
* interprets `.js` files in the output folder.
|
|
654
|
+
*/
|
|
655
|
+
_emitModulePackageJsonFiles(ts) {
|
|
656
|
+
for (const { emitModulePackageJson, moduleKind, outFolderPath } of this._moduleKindsToEmit) {
|
|
657
|
+
if (!emitModulePackageJson) {
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
// "module" and "commonjs" are the only recognized values. See
|
|
661
|
+
// https://nodejs.org/api/packages.html#type
|
|
662
|
+
let moduleType;
|
|
663
|
+
switch (moduleKind) {
|
|
664
|
+
// UMD contains a CommonJS wrapper, so it should be treated as CommonJS for package.json generation purposes
|
|
665
|
+
case ts.ModuleKind.UMD:
|
|
666
|
+
case ts.ModuleKind.CommonJS: {
|
|
667
|
+
moduleType = 'commonjs';
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
case ts.ModuleKind.AMD:
|
|
671
|
+
case ts.ModuleKind.None:
|
|
672
|
+
case ts.ModuleKind.Preserve:
|
|
673
|
+
case ts.ModuleKind.System: {
|
|
674
|
+
moduleType = undefined;
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
default: {
|
|
678
|
+
moduleType = 'module';
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (moduleType) {
|
|
683
|
+
const packageJsonPath = `${outFolderPath}package.json`;
|
|
684
|
+
const packageJsonContent = `{\n "type": "${moduleType}"\n}\n`;
|
|
685
|
+
ts.sys.writeFile(packageJsonPath, packageJsonContent);
|
|
686
|
+
this._typescriptTerminal.writeVerboseLine(`Wrote ${packageJsonPath} with "type": "${moduleType}"`);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
throw new Error(`Unsupported module kind ${ts.ModuleKind[moduleKind]} for package.json generation. ` +
|
|
690
|
+
`Remove the \`emitModulePackageJson\` option for this module kind.`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
642
694
|
_parseModuleKind(ts, moduleKindName) {
|
|
643
695
|
switch (moduleKindName.toLowerCase()) {
|
|
644
696
|
case 'commonjs':
|