Skip to content

Commit

Permalink
fix(ts): Publish downleveled TS3.8 types, fix types path (#8954)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Sep 6, 2023
1 parent 6643671 commit 8766bdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
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

0 comments on commit 8766bdd

Please sign in to comment.