diff --git a/release/core/publish/steps/generate-tarballs.ts b/release/core/publish/steps/generate-tarballs.ts index 529d4535a09..232d89bc60a 100644 --- a/release/core/publish/steps/generate-tarballs.ts +++ b/release/core/publish/steps/generate-tarballs.ts @@ -303,8 +303,34 @@ async function convertTypesToModules(pkg: Package, subdir: 'unstable-preview-typ } } +function exposeTypes(pkg: Package, subdir: 'unstable-preview-types' | 'preview-types' | 'types') { + if (pkg.pkgData.exports) { + /** + * Allows tsconfig.json#compilerOptions#types to use import paths, + * rather than file paths (there are no file path guarantees for any given package manager) + */ + pkg.pkgData.exports[`./${subdir}`] = { + /** + * No default, import, or require here, because there are no actual modules to import. + */ + types: `./${subdir}/index.d.ts`, + }; + + /** + * For older tsconfig.json settings + */ + pkg.pkgData.typesVersions = { + // very loose TS version + '*': { + [subdir]: [`./${subdir}`], + }, + }; + } +} + async function makeTypesAlpha(pkg: Package) { scrubTypesFromExports(pkg); + exposeTypes(pkg, 'unstable-preview-types'); // enforce that the correct types directory is present const present = new Set(pkg.pkgData.files); @@ -331,6 +357,7 @@ async function makeTypesAlpha(pkg: Package) { async function makeTypesBeta(pkg: Package) { scrubTypesFromExports(pkg); + exposeTypes(pkg, 'preview-types'); // enforce that the correct types directory is present const present = new Set(pkg.pkgData.files); diff --git a/release/utils/package.ts b/release/utils/package.ts index 9a0b1387575..80916b23bc7 100644 --- a/release/utils/package.ts +++ b/release/utils/package.ts @@ -59,6 +59,7 @@ export type PACKAGEJSON = { scripts?: Record; files?: string[]; exports?: ExportConfig; + typesVersions?: { [tsVersion: string]: { [relativeImportPath: string]: string[] } }; 'ember-addon'?: { main?: 'addon-main.js'; type?: 'addon';