-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate withStorybook to typescript (#633)
* fix: migrate withStorybook to typescript * fix: with storybook exports configuration * fix: account for vscode not finding exports * do same for preview * fix: update snapshots --------- Co-authored-by: Daniel Williams <[email protected]>
- Loading branch information
Showing
13 changed files
with
210 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1 @@ | ||
const path = require('path'); | ||
|
||
const { generate } = require('../scripts/generate'); | ||
const { WebSocketServer } = require('ws'); | ||
|
||
module.exports = ( | ||
config, | ||
{ configPath, enabled = true, websockets, useJs = false, onDisabledRemoveStorybook = false } = { | ||
enabled: true, | ||
useJs: false, | ||
onDisabledRemoveStorybook: false, | ||
} | ||
) => { | ||
if (!enabled) { | ||
if (onDisabledRemoveStorybook) { | ||
return { | ||
...config, | ||
resolver: { | ||
...config.resolver, | ||
resolveRequest: (context, moduleName, platform) => { | ||
const resolveFunction = config?.resolver?.resolveRequest | ||
? config?.resolver?.resolveRequest | ||
: context.resolveRequest; | ||
|
||
if (moduleName.startsWith('storybook') || moduleName.startsWith('@storybook')) { | ||
return { | ||
type: 'empty', | ||
}; | ||
} | ||
|
||
return resolveFunction(context, moduleName, platform); | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
return config; | ||
} | ||
|
||
if (websockets) { | ||
const port = websockets.port ?? 7007; | ||
|
||
const host = websockets.host ?? 'localhost'; | ||
|
||
const wss = new WebSocketServer({ port, host }); | ||
|
||
wss.on('connection', function connection(ws) { | ||
console.log('websocket connection established'); | ||
|
||
ws.on('error', console.error); | ||
|
||
ws.on('message', function message(data) { | ||
try { | ||
const json = JSON.parse(data.toString()); | ||
|
||
wss.clients.forEach((wsClient) => wsClient.send(JSON.stringify(json))); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
generate({ | ||
configPath: configPath ?? path.resolve(process.cwd(), './.storybook'), | ||
useJs, | ||
}); | ||
|
||
return { | ||
...config, | ||
transformer: { | ||
...config.transformer, | ||
unstable_allowRequireContext: true, | ||
}, | ||
resolver: { | ||
...config.resolver, | ||
resolveRequest: (context, moduleName, platform) => { | ||
const resolveFunction = config?.resolver?.resolveRequest | ||
? config?.resolver?.resolveRequest | ||
: context.resolveRequest; | ||
|
||
const isStorybookModule = | ||
moduleName.startsWith('storybook') || moduleName.startsWith('@storybook'); | ||
|
||
const theContext = isStorybookModule | ||
? { | ||
...context, | ||
unstable_enablePackageExports: true, | ||
unstable_conditionNames: ['import'], | ||
} | ||
: context; | ||
|
||
const resolveResult = resolveFunction(theContext, moduleName, platform); | ||
|
||
// workaround for template files with invalid imports | ||
if (resolveResult?.filePath?.includes?.('@storybook/react/template/cli')) { | ||
return { | ||
type: 'empty', | ||
}; | ||
} | ||
|
||
return resolveResult; | ||
}, | ||
}, | ||
}; | ||
}; | ||
module.exports = require('../dist/metro/withStorybook.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/preview.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.