Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ts): Publish downleveled TS3.8 types, fix types path #8954

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
!/cjs/**/*
!/esm/**/*
!/types/**/*
!/types-ts3.8/**/*
1 change: 1 addition & 0 deletions packages/gatsby/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
!/cjs/**/*
!/esm/**/*
!/types/**/*
!/types-ts3.8/**/*

# Gatsby specific
!gatsby-browser.js
Expand Down
15 changes: 9 additions & 6 deletions scripts/prepack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR;

type PackageJsonEntryPoints = Record<typeof ENTRY_POINTS[number], string>;

interface TypeVersions {
[key: string]: {
[key: string]: string[];
};
};

interface PackageJson extends Record<string, unknown>, PackageJsonEntryPoints {
[EXPORT_MAP_ENTRY_POINT]: {
[key: string]: {
Expand All @@ -31,11 +37,7 @@ interface PackageJson extends Record<string, unknown>, PackageJsonEntryPoints {
types: string;
};
};
[TYPES_VERSIONS_ENTRY_POINT]: {
[key: string]: {
[key: string]: string[];
};
};
[TYPES_VERSIONS_ENTRY_POINT]: TypeVersions;
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -81,7 +83,8 @@ if (newPkgJson[EXPORT_MAP_ENTRY_POINT]) {
if (newPkgJson[TYPES_VERSIONS_ENTRY_POINT]) {
Object.entries(newPkgJson[TYPES_VERSIONS_ENTRY_POINT]).forEach(([key, val]) => {
newPkgJson[TYPES_VERSIONS_ENTRY_POINT][key] = Object.entries(val).reduce((acc, [key, val]) => {
return { ...acc, [key]: val.map(v => v.replace(`${buildDir}/`, '')) };
const newKey = key.replace(`${buildDir}/`, '');
return { ...acc, [newKey]: val.map(v => v.replace(`${buildDir}/`, '')) };
}, {});
});
}
Expand Down