Skip to content

Commit

Permalink
Merge pull request #20671 from storybookjs/norbert/fix-20580
Browse files Browse the repository at this point in the history
Fix the d.ts file of addon-links, mark LinkTo in index as deprecated
  • Loading branch information
ndelangen authored Jan 20, 2023
2 parents 2a370ff + 0dac4c4 commit 3f1ece9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
],
"preview": [
"dist/preview.d.ts"
],
"react": [
"dist/react/index.d.ts"
]
}
},
Expand All @@ -89,6 +92,7 @@
"ts-dedent": "^2.0.0"
},
"devDependencies": {
"fs-extra": "^9.0.1",
"typescript": "~4.9.3"
},
"peerDependencies": {
Expand All @@ -112,7 +116,8 @@
"./src/manager.ts",
"./src/preview.ts",
"./src/react/index.ts"
]
],
"post": "./scripts/fix-preview-api-reference.ts"
},
"gitHead": "6d1ea7647fce605b2029077cbd02f655cafe1807",
"storybook": {
Expand Down
3 changes: 1 addition & 2 deletions code/addons/links/react.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './dist/react';
export { default } from './dist/react';
export * from './dist/react/index';
2 changes: 1 addition & 1 deletion code/addons/links/react.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import LinkTo from './dist/react';
import LinkTo from './dist/react/index';

export default LinkTo;
19 changes: 19 additions & 0 deletions code/addons/links/scripts/fix-preview-api-reference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { readFile, writeFile } from 'fs-extra';

/* I wish this wasn't needed..
* There seems to be some bug in tsup / the unlaying lib that does DTS bundling
* ...that makes it mess up the generation.
*/
const run = async () => {
const content = await readFile('./dist/index.d.ts', 'utf-8');

const regexp = /'lib\/preview-api/;
const replaced = content.replace(regexp, "'@storybook/preview-api");

await writeFile('./dist/index.d.ts', replaced);
};

run().catch((error) => {
console.error(error);
process.exit(1);
});
3 changes: 3 additions & 0 deletions code/addons/links/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { dedent } from 'ts-dedent';

let hasWarned = false;

/**
* @deprecated please import this specific function from @storybook/addon-links/react
*/
export function LinkTo(): null {
if (!hasWarned) {
// eslint-disable-next-line no-console
Expand Down
1 change: 1 addition & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5367,6 +5367,7 @@ __metadata:
"@storybook/preview-api": 7.0.0-beta.31
"@storybook/router": 7.0.0-beta.31
"@storybook/types": 7.0.0-beta.31
fs-extra: ^9.0.1
prop-types: ^15.7.2
ts-dedent: ^2.0.0
typescript: ~4.9.3
Expand Down

0 comments on commit 3f1ece9

Please sign in to comment.