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 the d.ts file of addon-links, mark LinkTo in index as deprecated #20671

Merged
merged 3 commits into from
Jan 20, 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
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