* A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the * `options` parameter. * * @param fileName The normalized absolute path to check the format of (it need not exist on disk) * @param [packageJsonIn
(fileName, packageJsonInfoCache, host, options)
| 116474 | * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format |
| 116475 | */ |
| 116476 | function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) { |
| 116477 | switch (ts.getEmitModuleResolutionKind(options)) { |
| 116478 | case ts.ModuleResolutionKind.Node16: |
| 116479 | case ts.ModuleResolutionKind.NodeNext: |
| 116480 | return ts.fileExtensionIsOneOf(fileName, [".d.mts" /* Extension.Dmts */, ".mts" /* Extension.Mts */, ".mjs" /* Extension.Mjs */]) ? ts.ModuleKind.ESNext : |
| 116481 | ts.fileExtensionIsOneOf(fileName, [".d.cts" /* Extension.Dcts */, ".cts" /* Extension.Cts */, ".cjs" /* Extension.Cjs */]) ? ts.ModuleKind.CommonJS : |
| 116482 | ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Extension.Dts */, ".ts" /* Extension.Ts */, ".tsx" /* Extension.Tsx */, ".js" /* Extension.Js */, ".jsx" /* Extension.Jsx */]) ? lookupFromPackageJson() : |
| 116483 | undefined; // other extensions, like `json` or `tsbuildinfo`, are set as `undefined` here but they should never be fed through the transformer pipeline |
| 116484 | default: |
| 116485 | return undefined; |
| 116486 | } |
| 116487 | function lookupFromPackageJson() { |
| 116488 | var scope = ts.getPackageScopeForPath(fileName, packageJsonInfoCache, host, options); |
| 116489 | return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; |
| 116490 | } |
| 116491 | } |
| 116492 | ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile; |
| 116493 | /** @internal */ |
| 116494 | ts.plainJSErrors = new ts.Set([ |
no test coverage detected
searching dependent graphs…