@storybook/core-server 6.5.9 → 7.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/build-dev.js +55 -140
  3. package/dist/cjs/build-static.js +45 -75
  4. package/dist/cjs/dev-server.js +10 -7
  5. package/dist/cjs/presets/babel-cache-preset.js +2 -4
  6. package/dist/cjs/presets/common-preset.js +31 -23
  7. package/dist/cjs/standalone.js +9 -1
  8. package/dist/cjs/utils/StoryIndexGenerator.js +16 -4
  9. package/dist/cjs/utils/{get-manager-builder.js → get-builders.js} +28 -27
  10. package/dist/esm/build-dev.js +53 -130
  11. package/dist/esm/build-static.js +40 -64
  12. package/dist/esm/dev-server.js +10 -6
  13. package/dist/esm/presets/babel-cache-preset.js +1 -2
  14. package/dist/esm/presets/common-preset.js +23 -22
  15. package/dist/esm/standalone.js +8 -1
  16. package/dist/esm/utils/StoryIndexGenerator.js +17 -5
  17. package/dist/esm/utils/get-builders.js +31 -0
  18. package/dist/types/build-dev.d.ts +2 -0
  19. package/dist/{ts3.9 → types}/build-static.d.ts +0 -1
  20. package/dist/{ts3.9 → types}/dev-server.d.ts +1 -1
  21. package/dist/{ts3.9 → types}/index.d.ts +0 -0
  22. package/dist/types/presets/babel-cache-preset.d.ts +1 -0
  23. package/dist/{ts3.4 → types}/presets/common-preset.d.ts +29 -31
  24. package/dist/{ts3.9 → types}/standalone.d.ts +0 -0
  25. package/dist/{ts3.9 → types}/utils/StoryIndexGenerator.d.ts +4 -1
  26. package/dist/{ts3.9 → types}/utils/__mockdata__/E.stories.d.ts +0 -0
  27. package/dist/{ts3.9 → types}/utils/__mockdata__/deeply/nested/single/File.stories.d.ts +0 -0
  28. package/dist/{ts3.9 → types}/utils/__mockdata__/src/B.stories.d.ts +0 -0
  29. package/dist/{ts3.9 → types}/utils/__mockdata__/src/NoMeta.stories.d.ts +0 -0
  30. package/dist/{ts3.9 → types}/utils/__mockdata__/src/nested/Button.d.ts +0 -0
  31. package/dist/{ts3.9 → types}/utils/__mockdata__/src/nested/Button.stories.d.ts +0 -0
  32. package/dist/{ts3.9 → types}/utils/__mockdata__/src/second-nested/G.stories.d.ts +0 -0
  33. package/dist/{ts3.9 → types}/utils/copy-all-static-files.d.ts +0 -0
  34. package/dist/types/utils/get-builders.d.ts +2 -0
  35. package/dist/{ts3.9 → types}/utils/get-server-channel.d.ts +0 -0
  36. package/dist/{ts3.9 → types}/utils/metadata.d.ts +0 -0
  37. package/dist/{ts3.9 → types}/utils/middleware.d.ts +0 -0
  38. package/dist/{ts3.9 → types}/utils/open-in-browser.d.ts +0 -0
  39. package/dist/{ts3.9 → types}/utils/output-startup-information.d.ts +0 -0
  40. package/dist/{ts3.4 → types}/utils/output-stats.d.ts +3 -3
  41. package/dist/{ts3.9 → types}/utils/release-notes.d.ts +0 -0
  42. package/dist/{ts3.9 → types}/utils/server-address.d.ts +0 -0
  43. package/dist/{ts3.9 → types}/utils/server-init.d.ts +0 -0
  44. package/dist/{ts3.9 → types}/utils/server-statics.d.ts +0 -0
  45. package/dist/{ts3.9 → types}/utils/stories-json.d.ts +0 -0
  46. package/dist/{ts3.9 → types}/utils/update-check.d.ts +0 -0
  47. package/dist/{ts3.9 → types}/utils/watch-story-specifiers.d.ts +0 -0
  48. package/package.json +14 -23
  49. package/dist/cjs/cli/dev.js +0 -63
  50. package/dist/cjs/cli/index.js +0 -31
  51. package/dist/cjs/cli/prod.js +0 -43
  52. package/dist/cjs/cli/utils.js +0 -63
  53. package/dist/cjs/utils/get-preview-builder.js +0 -47
  54. package/dist/esm/cli/dev.js +0 -44
  55. package/dist/esm/cli/index.js +0 -2
  56. package/dist/esm/cli/prod.js +0 -26
  57. package/dist/esm/cli/utils.js +0 -48
  58. package/dist/esm/utils/get-manager-builder.js +0 -26
  59. package/dist/esm/utils/get-preview-builder.js +0 -28
  60. package/dist/modern/build-dev.js +0 -232
  61. package/dist/modern/build-static.js +0 -237
  62. package/dist/modern/cli/dev.js +0 -44
  63. package/dist/modern/cli/index.js +0 -2
  64. package/dist/modern/cli/prod.js +0 -26
  65. package/dist/modern/cli/utils.js +0 -48
  66. package/dist/modern/dev-server.js +0 -200
  67. package/dist/modern/index.js +0 -4
  68. package/dist/modern/presets/babel-cache-preset.js +0 -18
  69. package/dist/modern/presets/common-preset.js +0 -124
  70. package/dist/modern/standalone.js +0 -30
  71. package/dist/modern/utils/StoryIndexGenerator.js +0 -222
  72. package/dist/modern/utils/__mockdata__/E.stories.js +0 -5
  73. package/dist/modern/utils/__mockdata__/deeply/nested/single/File.stories.js +0 -4
  74. package/dist/modern/utils/__mockdata__/preview.js +0 -1
  75. package/dist/modern/utils/__mockdata__/src/A.stories.js +0 -5
  76. package/dist/modern/utils/__mockdata__/src/B.stories.js +0 -5
  77. package/dist/modern/utils/__mockdata__/src/C.js +0 -1
  78. package/dist/modern/utils/__mockdata__/src/D.stories.js +0 -5
  79. package/dist/modern/utils/__mockdata__/src/NoMeta.stories.js +0 -4
  80. package/dist/modern/utils/__mockdata__/src/first-nested/deeply/F.stories.js +0 -5
  81. package/dist/modern/utils/__mockdata__/src/nested/Button.js +0 -1
  82. package/dist/modern/utils/__mockdata__/src/nested/Button.stories.js +0 -5
  83. package/dist/modern/utils/__mockdata__/src/second-nested/G.stories.js +0 -5
  84. package/dist/modern/utils/copy-all-static-files.js +0 -62
  85. package/dist/modern/utils/get-manager-builder.js +0 -26
  86. package/dist/modern/utils/get-preview-builder.js +0 -28
  87. package/dist/modern/utils/get-server-channel.js +0 -39
  88. package/dist/modern/utils/metadata.js +0 -14
  89. package/dist/modern/utils/middleware.js +0 -27
  90. package/dist/modern/utils/open-in-browser.js +0 -26
  91. package/dist/modern/utils/output-startup-information.js +0 -54
  92. package/dist/modern/utils/output-stats.js +0 -37
  93. package/dist/modern/utils/release-notes.js +0 -63
  94. package/dist/modern/utils/server-address.js +0 -20
  95. package/dist/modern/utils/server-init.js +0 -29
  96. package/dist/modern/utils/server-statics.js +0 -97
  97. package/dist/modern/utils/stories-json.js +0 -42
  98. package/dist/modern/utils/update-check.js +0 -65
  99. package/dist/modern/utils/watch-story-specifiers.js +0 -99
  100. package/dist/ts3.4/build-dev.d.ts +0 -3
  101. package/dist/ts3.4/build-static.d.ts +0 -3
  102. package/dist/ts3.4/cli/dev.d.ts +0 -6
  103. package/dist/ts3.4/cli/index.d.ts +0 -2
  104. package/dist/ts3.4/cli/prod.d.ts +0 -7
  105. package/dist/ts3.4/cli/utils.d.ts +0 -5
  106. package/dist/ts3.4/dev-server.d.ts +0 -24
  107. package/dist/ts3.4/index.d.ts +0 -4
  108. package/dist/ts3.4/presets/babel-cache-preset.d.ts +0 -2
  109. package/dist/ts3.4/standalone.d.ts +0 -2
  110. package/dist/ts3.4/utils/StoryIndexGenerator.d.ts +0 -27
  111. package/dist/ts3.4/utils/__mockdata__/E.stories.d.ts +0 -5
  112. package/dist/ts3.4/utils/__mockdata__/deeply/nested/single/File.stories.d.ts +0 -5
  113. package/dist/ts3.4/utils/__mockdata__/src/B.stories.d.ts +0 -5
  114. package/dist/ts3.4/utils/__mockdata__/src/NoMeta.stories.d.ts +0 -1
  115. package/dist/ts3.4/utils/__mockdata__/src/nested/Button.d.ts +0 -1
  116. package/dist/ts3.4/utils/__mockdata__/src/nested/Button.stories.d.ts +0 -5
  117. package/dist/ts3.4/utils/__mockdata__/src/second-nested/G.stories.d.ts +0 -5
  118. package/dist/ts3.4/utils/copy-all-static-files.d.ts +0 -2
  119. package/dist/ts3.4/utils/get-manager-builder.d.ts +0 -2
  120. package/dist/ts3.4/utils/get-preview-builder.d.ts +0 -2
  121. package/dist/ts3.4/utils/get-server-channel.d.ts +0 -9
  122. package/dist/ts3.4/utils/metadata.d.ts +0 -3
  123. package/dist/ts3.4/utils/middleware.d.ts +0 -1
  124. package/dist/ts3.4/utils/open-in-browser.d.ts +0 -1
  125. package/dist/ts3.4/utils/output-startup-information.d.ts +0 -16
  126. package/dist/ts3.4/utils/release-notes.d.ts +0 -8
  127. package/dist/ts3.4/utils/server-address.d.ts +0 -8
  128. package/dist/ts3.4/utils/server-init.d.ts +0 -10
  129. package/dist/ts3.4/utils/server-statics.d.ts +0 -8
  130. package/dist/ts3.4/utils/stories-json.d.ts +0 -13
  131. package/dist/ts3.4/utils/update-check.d.ts +0 -3
  132. package/dist/ts3.4/utils/watch-story-specifiers.d.ts +0 -5
  133. package/dist/ts3.9/build-dev.d.ts +0 -3
  134. package/dist/ts3.9/cli/dev.d.ts +0 -6
  135. package/dist/ts3.9/cli/index.d.ts +0 -2
  136. package/dist/ts3.9/cli/prod.d.ts +0 -7
  137. package/dist/ts3.9/cli/utils.d.ts +0 -5
  138. package/dist/ts3.9/presets/babel-cache-preset.d.ts +0 -2
  139. package/dist/ts3.9/presets/common-preset.d.ts +0 -31
  140. package/dist/ts3.9/utils/get-manager-builder.d.ts +0 -2
  141. package/dist/ts3.9/utils/get-preview-builder.d.ts +0 -2
  142. package/dist/ts3.9/utils/output-stats.d.ts +0 -3
@@ -1,63 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
- import "core-js/modules/es.array.sort.js";
3
- import semver from '@storybook/semver';
4
-
5
- // We only expect to have release notes available for major and minor releases.
6
- // For this reason, we convert the actual version of the build here so that
7
- // every place that relies on this data can reference the version of the
8
- // release notes that we expect to use.
9
- var getReleaseNotesVersion = function (version) {
10
- var _semver$parse = semver.parse(version),
11
- major = _semver$parse.major,
12
- minor = _semver$parse.minor;
13
-
14
- var _semver$coerce = semver.coerce(`${major}.${minor}`),
15
- releaseNotesVersion = _semver$coerce.version;
16
-
17
- return releaseNotesVersion;
18
- };
19
-
20
- export var getReleaseNotesFailedState = function (version) {
21
- return {
22
- success: false,
23
- currentVersion: getReleaseNotesVersion(version),
24
- showOnFirstLaunch: false
25
- };
26
- };
27
- export var RELEASE_NOTES_CACHE_KEY = 'releaseNotesData';
28
- export var getReleaseNotesData = async function (currentVersionToParse, fileSystemCache) {
29
- var result;
30
-
31
- try {
32
- var fromCache = (await fileSystemCache.get('releaseNotesData', []).catch(function () {})) || [];
33
- var releaseNotesVersion = getReleaseNotesVersion(currentVersionToParse);
34
- var versionHasNotBeenSeen = !fromCache.includes(releaseNotesVersion);
35
-
36
- if (versionHasNotBeenSeen) {
37
- await fileSystemCache.set('releaseNotesData', [...fromCache, releaseNotesVersion]);
38
- }
39
-
40
- var sortedHistory = semver.sort(fromCache);
41
- var highestVersionSeenInThePast = sortedHistory.slice(-1)[0];
42
- var isUpgrading = false;
43
- var isMajorOrMinorDiff = false;
44
-
45
- if (highestVersionSeenInThePast) {
46
- isUpgrading = semver.gt(releaseNotesVersion, highestVersionSeenInThePast);
47
- var versionDiff = semver.diff(releaseNotesVersion, highestVersionSeenInThePast);
48
- isMajorOrMinorDiff = versionDiff === 'major' || versionDiff === 'minor';
49
- }
50
-
51
- result = {
52
- success: true,
53
- showOnFirstLaunch: versionHasNotBeenSeen && // Only show the release notes if this is not the first time Storybook
54
- // has been built.
55
- !!highestVersionSeenInThePast && isUpgrading && isMajorOrMinorDiff,
56
- currentVersion: releaseNotesVersion
57
- };
58
- } catch (e) {
59
- result = getReleaseNotesFailedState(currentVersionToParse);
60
- }
61
-
62
- return result;
63
- };
@@ -1,20 +0,0 @@
1
- import ip from 'ip';
2
- import { logger } from '@storybook/node-logger';
3
- import detectFreePort from 'detect-port';
4
- export function getServerAddresses(port, host, proto) {
5
- return {
6
- address: `${proto}://localhost:${port}/`,
7
- networkAddress: `${proto}://${host || ip.address()}:${port}/`
8
- };
9
- }
10
- export var getServerPort = function (port) {
11
- return detectFreePort(port).catch(function (error) {
12
- logger.error(error);
13
- process.exit(-1);
14
- });
15
- };
16
- export var getServerChannelUrl = function (port, {
17
- https: https
18
- }) {
19
- return `${https ? 'wss' : 'ws'}://localhost:${port}/storybook-server-channel`;
20
- };
@@ -1,29 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
- import { logger } from '@storybook/node-logger';
3
- import { readFile } from 'fs-extra';
4
- import http from 'http';
5
- import https from 'https';
6
- export async function getServer(app, options) {
7
- if (!options.https) {
8
- return http.createServer(app);
9
- }
10
-
11
- if (!options.sslCert) {
12
- logger.error('Error: --ssl-cert is required with --https');
13
- process.exit(-1);
14
- }
15
-
16
- if (!options.sslKey) {
17
- logger.error('Error: --ssl-key is required with --https');
18
- process.exit(-1);
19
- }
20
-
21
- var sslOptions = {
22
- ca: await Promise.all((options.sslCa || []).map(function (ca) {
23
- return readFile(ca, 'utf-8');
24
- })),
25
- cert: await readFile(options.sslCert, 'utf-8'),
26
- key: await readFile(options.sslKey, 'utf-8')
27
- };
28
- return https.createServer(sslOptions, app);
29
- }
@@ -1,97 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
- import { logger } from '@storybook/node-logger';
3
- import { getDirectoryFromWorkingDir } from '@storybook/core-common';
4
- import chalk from 'chalk';
5
- import express from 'express';
6
- import { pathExists } from 'fs-extra';
7
- import path from 'path';
8
- import favicon from 'serve-favicon';
9
- import dedent from 'ts-dedent';
10
-
11
- var defaultFavIcon = require.resolve('@storybook/core-server/public/favicon.ico');
12
-
13
- export async function useStatics(router, options) {
14
- var hasCustomFavicon = false;
15
- var staticDirs = await options.presets.apply('staticDirs');
16
-
17
- if (staticDirs && options.staticDir) {
18
- throw new Error(dedent`
19
- Conflict when trying to read staticDirs:
20
- * Storybook's configuration option: 'staticDirs'
21
- * Storybook's CLI flag: '--staticDir' or '-s'
22
-
23
- Choose one of them, but not both.
24
- `);
25
- }
26
-
27
- var statics = staticDirs ? staticDirs.map(function (dir) {
28
- return typeof dir === 'string' ? dir : `${dir.from}:${dir.to}`;
29
- }) : options.staticDir;
30
-
31
- if (statics && statics.length > 0) {
32
- await Promise.all(statics.map(async function (dir) {
33
- try {
34
- var relativeDir = staticDirs ? getDirectoryFromWorkingDir({
35
- configDir: options.configDir,
36
- workingDir: process.cwd(),
37
- directory: dir
38
- }) : dir;
39
-
40
- var _await$parseStaticDir = await parseStaticDir(relativeDir),
41
- staticDir = _await$parseStaticDir.staticDir,
42
- staticPath = _await$parseStaticDir.staticPath,
43
- targetEndpoint = _await$parseStaticDir.targetEndpoint;
44
-
45
- logger.info(chalk`=> Serving static files from {cyan ${staticDir}} at {cyan ${targetEndpoint}}`);
46
- router.use(targetEndpoint, express.static(staticPath, {
47
- index: false
48
- }));
49
-
50
- if (!hasCustomFavicon && targetEndpoint === '/') {
51
- var faviconPath = path.join(staticPath, 'favicon.ico');
52
-
53
- if (await pathExists(faviconPath)) {
54
- hasCustomFavicon = true;
55
- router.use(favicon(faviconPath));
56
- }
57
- }
58
- } catch (e) {
59
- logger.warn(e.message);
60
- }
61
- }));
62
- }
63
-
64
- if (!hasCustomFavicon) {
65
- router.use(favicon(defaultFavIcon));
66
- }
67
- }
68
- export var parseStaticDir = async function (arg) {
69
- // Split on last index of ':', for Windows compatibility (e.g. 'C:\some\dir:\foo')
70
- var lastColonIndex = arg.lastIndexOf(':');
71
- var isWindowsAbsolute = path.win32.isAbsolute(arg);
72
- var isWindowsRawDirOnly = isWindowsAbsolute && lastColonIndex === 1; // e.g. 'C:\some\dir'
73
-
74
- var splitIndex = lastColonIndex !== -1 && !isWindowsRawDirOnly ? lastColonIndex : arg.length;
75
- var targetRaw = arg.substring(splitIndex + 1) || '/';
76
- var target = targetRaw.split(path.sep).join(path.posix.sep); // Ensure target has forward-slash path
77
-
78
- var rawDir = arg.substring(0, splitIndex);
79
- var staticDir = path.isAbsolute(rawDir) ? rawDir : `./${rawDir}`;
80
- var staticPath = path.resolve(staticDir);
81
- var targetDir = target.replace(/^\/?/, './');
82
- var targetEndpoint = targetDir.substring(1);
83
-
84
- if (!(await pathExists(staticPath))) {
85
- throw new Error(dedent(chalk`
86
- Failed to load static files, no such directory: {cyan ${staticPath}}
87
- Make sure this directory exists, or omit the {bold -s (--static-dir)} option.
88
- `));
89
- }
90
-
91
- return {
92
- staticDir: staticDir,
93
- staticPath: staticPath,
94
- targetDir: targetDir,
95
- targetEndpoint: targetEndpoint
96
- };
97
- };
@@ -1,42 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
- import fs from 'fs-extra';
3
- import { debounce } from 'lodash';
4
- import { STORY_INDEX_INVALIDATED } from '@storybook/core-events';
5
- import { watchStorySpecifiers } from './watch-story-specifiers';
6
- export var DEBOUNCE = 100;
7
- export async function extractStoriesJson(outputFile, initializedStoryIndexGenerator) {
8
- var generator = await initializedStoryIndexGenerator;
9
- var storyIndex = await generator.getIndex();
10
- await fs.writeJson(outputFile, storyIndex);
11
- }
12
- export function useStoriesJson({
13
- router: router,
14
- initializedStoryIndexGenerator: initializedStoryIndexGenerator,
15
- workingDir = process.cwd(),
16
- serverChannel: serverChannel,
17
- normalizedStories: normalizedStories
18
- }) {
19
- var maybeInvalidate = debounce(function () {
20
- return serverChannel.emit(STORY_INDEX_INVALIDATED);
21
- }, DEBOUNCE, {
22
- leading: true
23
- });
24
- watchStorySpecifiers(normalizedStories, {
25
- workingDir: workingDir
26
- }, async function (specifier, path, removed) {
27
- var generator = await initializedStoryIndexGenerator;
28
- generator.invalidate(specifier, path, removed);
29
- maybeInvalidate();
30
- });
31
- router.use('/stories.json', async function (req, res) {
32
- try {
33
- var generator = await initializedStoryIndexGenerator;
34
- var index = await generator.getIndex();
35
- res.header('Content-Type', 'application/json');
36
- res.send(JSON.stringify(index));
37
- } catch (err) {
38
- res.status(500);
39
- res.send(err.message);
40
- }
41
- });
42
- }
@@ -1,65 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
- import fetch from 'node-fetch';
3
- import chalk from 'chalk';
4
- import { colors } from '@storybook/node-logger';
5
- import semver from '@storybook/semver';
6
- import dedent from 'ts-dedent';
7
- import { cache } from '@storybook/core-common';
8
- var _process$env = process.env,
9
- _process$env$STORYBOO = _process$env.STORYBOOK_VERSION_BASE,
10
- STORYBOOK_VERSION_BASE = _process$env$STORYBOO === void 0 ? 'https://storybook.js.org' : _process$env$STORYBOO,
11
- CI = _process$env.CI;
12
- export var updateCheck = async function (version) {
13
- var result;
14
- var time = Date.now();
15
-
16
- try {
17
- var fromCache = await cache.get('lastUpdateCheck', {
18
- success: false,
19
- time: 0
20
- }); // if last check was more then 24h ago
21
-
22
- if (time - 86400000 > fromCache.time && !CI) {
23
- var fromFetch = await Promise.race([fetch(`${STORYBOOK_VERSION_BASE}/versions.json?current=${version}`), // if fetch is too slow, we won't wait for it
24
- new Promise(function (res, rej) {
25
- return global.setTimeout(rej, 1500);
26
- })]);
27
- var data = await fromFetch.json();
28
- result = {
29
- success: true,
30
- data: data,
31
- time: time
32
- };
33
- await cache.set('lastUpdateCheck', result);
34
- } else {
35
- result = fromCache;
36
- }
37
- } catch (error) {
38
- result = {
39
- success: false,
40
- error: error,
41
- time: time
42
- };
43
- }
44
-
45
- return result;
46
- };
47
- export function createUpdateMessage(updateInfo, version) {
48
- var updateMessage;
49
-
50
- try {
51
- var suffix = semver.prerelease(updateInfo.data.latest.version) ? '--prerelease' : '';
52
- var upgradeCommand = `npx storybook@latest upgrade ${suffix}`.trim();
53
- updateMessage = updateInfo.success && semver.lt(version, updateInfo.data.latest.version) ? dedent`
54
- ${colors.orange(`A new version (${chalk.bold(updateInfo.data.latest.version)}) is available!`)}
55
-
56
- ${chalk.gray('Upgrade now:')} ${colors.green(upgradeCommand)}
57
-
58
- ${chalk.gray('Read full changelog:')} ${chalk.gray.underline('https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md')}
59
- ` : '';
60
- } catch (e) {
61
- updateMessage = '';
62
- }
63
-
64
- return updateMessage;
65
- }
@@ -1,99 +0,0 @@
1
- import "core-js/modules/es.promise.js";
2
- import Watchpack from 'watchpack';
3
- import slash from 'slash';
4
- import fs from 'fs';
5
- import path from 'path';
6
- import glob from 'globby';
7
-
8
- var isDirectory = function (directory) {
9
- try {
10
- return fs.lstatSync(directory).isDirectory();
11
- } catch (err) {
12
- return false;
13
- }
14
- }; // Watchpack (and path.relative) passes paths either with no leading './' - e.g. `src/Foo.stories.js`,
15
- // or with a leading `../` (etc), e.g. `../src/Foo.stories.js`.
16
- // We want to deal in importPaths relative to the working dir, so we normalize
17
-
18
-
19
- function toImportPath(relativePath) {
20
- return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
21
- }
22
-
23
- export function watchStorySpecifiers(specifiers, options, onInvalidate) {
24
- // See https://www.npmjs.com/package/watchpack for full options.
25
- // If you want less traffic, consider using aggregation with some interval
26
- var wp = new Watchpack({
27
- // poll: true, // Slow!!! Enable only in special cases
28
- followSymlinks: false,
29
- ignored: ['**/.git', 'node_modules']
30
- });
31
- wp.watch({
32
- directories: specifiers.map(function (ns) {
33
- return ns.directory;
34
- })
35
- });
36
-
37
- async function onChangeOrRemove(watchpackPath, removed) {
38
- // Watchpack passes paths either with no leading './' - e.g. `src/Foo.stories.js`,
39
- // or with a leading `../` (etc), e.g. `../src/Foo.stories.js`.
40
- // We want to deal in importPaths relative to the working dir, or absolute paths.
41
- var importPath = slash(watchpackPath.startsWith('.') ? watchpackPath : `./${watchpackPath}`);
42
- var matchingSpecifier = specifiers.find(function (ns) {
43
- return ns.importPathMatcher.exec(importPath);
44
- });
45
-
46
- if (matchingSpecifier) {
47
- onInvalidate(matchingSpecifier, importPath, removed);
48
- return;
49
- } // When a directory is removed, watchpack will fire a removed event for each file also
50
- // (so we don't need to do anything special).
51
- // However, when a directory is added, it does not fire events for any files *within* the directory,
52
- // so we need to scan within that directory for new files. It is tricky to use a glob for this,
53
- // so we'll do something a bit more "dumb" for now
54
-
55
-
56
- var absolutePath = path.join(options.workingDir, importPath);
57
-
58
- if (!removed && isDirectory(absolutePath)) {
59
- await Promise.all(specifiers // We only receive events for files (incl. directories) that are *within* a specifier,
60
- // so will match one (or more) specifiers with this simple `startsWith`
61
- .filter(function (specifier) {
62
- return importPath.startsWith(specifier.directory);
63
- }).map(async function (specifier) {
64
- // If `./path/to/dir` was added, check all files matching `./path/to/dir/**/*.stories.*`
65
- // (where the last bit depends on `files`).
66
- var dirGlob = path.join(options.workingDir, importPath, '**', // files can be e.g. '**/foo/*/*.js' so we just want the last bit,
67
- // because the directoru could already be within the files part (e.g. './x/foo/bar')
68
- path.basename(specifier.files)); // glob only supports forward slashes
69
-
70
- var files = await glob(dirGlob.replace(/\\/g, '/'));
71
- files.forEach(function (filePath) {
72
- var fileImportPath = toImportPath( // use posix path separators even on windows
73
- path.relative(options.workingDir, filePath).replace(/\\/g, '/'));
74
-
75
- if (specifier.importPathMatcher.exec(fileImportPath)) {
76
- onInvalidate(specifier, fileImportPath, removed);
77
- }
78
- });
79
- }));
80
- }
81
- }
82
-
83
- wp.on('change', async function (filePath, mtime, explanation) {
84
- // When a file is renamed (including being moved out of the watched dir)
85
- // we see first an event with explanation=rename and no mtime for the old name.
86
- // then an event with explanation=rename with an mtime for the new name.
87
- // In theory we could try and track both events together and move the exports
88
- // but that seems dangerous (what if the contents changed?) and frankly not worth it
89
- // (at this stage at least)
90
- var removed = !mtime;
91
- await onChangeOrRemove(filePath, removed);
92
- });
93
- wp.on('remove', async function (filePath, explanation) {
94
- await onChangeOrRemove(filePath, true);
95
- });
96
- return function () {
97
- return wp.close();
98
- };
99
- }
@@ -1,3 +0,0 @@
1
- import { CLIOptions, LoadOptions, BuilderOptions } from '@storybook/core-common';
2
- export declare function buildDevStandalone(options: CLIOptions & LoadOptions & BuilderOptions): Promise<void>;
3
- export declare function buildDev(loadOptions: LoadOptions): Promise<void>;
@@ -1,3 +0,0 @@
1
- import { LoadOptions, CLIOptions, BuilderOptions } from '@storybook/core-common';
2
- export declare function buildStaticStandalone(options: CLIOptions & LoadOptions & BuilderOptions): Promise<void>;
3
- export declare function buildStatic({ packageJson, ...loadOptions }: LoadOptions): Promise<void>;
@@ -1,6 +0,0 @@
1
- import { CommanderStatic } from 'commander';
2
- import { CLIOptions } from '@storybook/core-common';
3
- export declare function getDevCli(packageJson: {
4
- version: string;
5
- name: string;
6
- }): Promise<CommanderStatic & CLIOptions>;
@@ -1,2 +0,0 @@
1
- export * from './dev';
2
- export * from './prod';
@@ -1,7 +0,0 @@
1
- import { CommanderStatic } from 'commander';
2
- import { CLIOptions } from '@storybook/core-common';
3
- export declare type ProdCliOptions = Pick<CLIOptions, 'configDir' | 'debugWebpack' | 'dll' | 'docs' | 'docsDll' | 'forceBuildPreview' | 'loglevel' | 'modern' | 'outputDir' | 'previewUrl' | 'quiet' | 'staticDir' | 'uiDll'>;
4
- export declare function getProdCli(packageJson: {
5
- version: string;
6
- name: string;
7
- }): CommanderStatic & ProdCliOptions;
@@ -1,5 +0,0 @@
1
- import { CLIOptions } from '@storybook/core-common';
2
- import { ProdCliOptions } from './prod';
3
- export declare function parseList(str: string): string[];
4
- export declare function getEnvConfig(program: Record<string, any>, configEnv: Record<string, any>): void;
5
- export declare function checkDeprecatedFlags({ dll, uiDll, docsDll, staticDir, }: CLIOptions | ProdCliOptions): void;
@@ -1,24 +0,0 @@
1
- import { Router } from 'express';
2
- import { Options } from '@storybook/core-common';
3
- export declare const router: Router;
4
- export declare const DEBOUNCE = 100;
5
- export declare function storybookDevServer(options: Options): Promise<{
6
- previewResult: void | {
7
- stats: unknown;
8
- totalTime: [
9
- number,
10
- number
11
- ];
12
- bail: (e?: Error) => Promise<void>;
13
- };
14
- managerResult: void | {
15
- stats: unknown;
16
- totalTime: [
17
- number,
18
- number
19
- ];
20
- bail: (e?: Error) => Promise<void>;
21
- };
22
- address: string;
23
- networkAddress: string;
24
- }>;
@@ -1,4 +0,0 @@
1
- import { getPreviewHeadTemplate, getManagerHeadTemplate, getManagerMainTemplate, getPreviewBodyTemplate, getPreviewMainTemplate } from '@storybook/core-common';
2
- export { getPreviewHeadTemplate, getManagerHeadTemplate, getManagerMainTemplate, getPreviewBodyTemplate, getPreviewMainTemplate, };
3
- export * from './build-static';
4
- export * from './build-dev';
@@ -1,2 +0,0 @@
1
- export declare const babel: (babelConfig: any) => any;
2
- export declare const managerBabel: (babelConfig: any) => any;
@@ -1,2 +0,0 @@
1
- declare function build(options?: any, frameworkOptions?: any): Promise<void>;
2
- export default build;
@@ -1,27 +0,0 @@
1
- import { Path, StoryIndex } from '@storybook/store';
2
- import { NormalizedStoriesSpecifier } from '@storybook/core-common';
3
- export declare class StoryIndexGenerator {
4
- readonly specifiers: NormalizedStoriesSpecifier[];
5
- readonly options: {
6
- workingDir: Path;
7
- configDir: Path;
8
- storiesV2Compatibility: boolean;
9
- storyStoreV7: boolean;
10
- };
11
- private storyIndexEntries;
12
- private lastIndex?;
13
- constructor(specifiers: NormalizedStoriesSpecifier[], options: {
14
- workingDir: Path;
15
- configDir: Path;
16
- storiesV2Compatibility: boolean;
17
- storyStoreV7: boolean;
18
- });
19
- initialize(): Promise<void>;
20
- ensureExtracted(): Promise<StoryIndex['stories'][]>;
21
- extractStories(specifier: NormalizedStoriesSpecifier, absolutePath: Path): Promise<Record<string, import("@storybook/store").StoryIndexEntry>>;
22
- sortStories(storiesList: StoryIndex['stories'][]): Promise<Record<string, import("@storybook/store").StoryIndexEntry>>;
23
- getIndex(): Promise<StoryIndex>;
24
- invalidate(specifier: NormalizedStoriesSpecifier, importPath: Path, removed: boolean): void;
25
- getStorySortParameter(): Promise<any>;
26
- storyFileNames(): string[];
27
- }
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- component: {};
3
- };
4
- export default _default;
5
- export declare const StoryOne: {};
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- component: {};
3
- };
4
- export default _default;
5
- export declare const StoryOne: {};
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- component: {};
3
- };
4
- export default _default;
5
- export declare const StoryOne: {};
@@ -1 +0,0 @@
1
- export declare const StoryOne: {};
@@ -1 +0,0 @@
1
- export declare const Button: {};
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- component: {};
3
- };
4
- export default _default;
5
- export declare const StoryOne: {};
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- component: {};
3
- };
4
- export default _default;
5
- export declare const StoryOne: {};
@@ -1,2 +0,0 @@
1
- export declare function copyAllStaticFiles(staticDirs: any[] | undefined, outputDir: string): Promise<void>;
2
- export declare function copyAllStaticFilesRelativeToMain(staticDirs: any[] | undefined, outputDir: string, configDir: string): Promise<void>;
@@ -1,2 +0,0 @@
1
- import { Options } from '@storybook/core-common';
2
- export declare function getManagerBuilder(configDir: Options['configDir']): Promise<any>;
@@ -1,2 +0,0 @@
1
- import { Options } from '@storybook/core-common';
2
- export declare function getPreviewBuilder(configDir: Options['configDir']): Promise<any>;
@@ -1,9 +0,0 @@
1
- import { WebSocketServer } from 'ws';
2
- declare type Server = ConstructorParameters<typeof WebSocketServer>[0]['server'];
3
- export declare class ServerChannel {
4
- webSocketServer: WebSocketServer;
5
- constructor(server: Server);
6
- emit(type: string, args?: any[]): void;
7
- }
8
- export declare function getServerChannel(server: Server): ServerChannel;
9
- export {};
@@ -1,3 +0,0 @@
1
- import { Router } from 'express';
2
- export declare function extractStorybookMetadata(outputFile: string, configDir: string): Promise<void>;
3
- export declare function useStorybookMetadata(router: Router, configDir?: string): void;
@@ -1 +0,0 @@
1
- export declare function getMiddleware(configDir: string): any;
@@ -1 +0,0 @@
1
- export declare function openInBrowser(address: string): void;
@@ -1,16 +0,0 @@
1
- import { VersionCheck } from '@storybook/core-common';
2
- export declare function outputStartupInformation(options: {
3
- updateInfo: VersionCheck;
4
- version: string;
5
- name: string;
6
- address: string;
7
- networkAddress: string;
8
- managerTotalTime?: [
9
- number,
10
- number
11
- ];
12
- previewTotalTime?: [
13
- number,
14
- number
15
- ];
16
- }): void;
@@ -1,8 +0,0 @@
1
- import { ReleaseNotesData } from '@storybook/core-common';
2
- export declare const getReleaseNotesFailedState: (version: string) => {
3
- success: boolean;
4
- currentVersion: string;
5
- showOnFirstLaunch: boolean;
6
- };
7
- export declare const RELEASE_NOTES_CACHE_KEY = "releaseNotesData";
8
- export declare const getReleaseNotesData: (currentVersionToParse: string, fileSystemCache: any) => Promise<ReleaseNotesData>;
@@ -1,8 +0,0 @@
1
- export declare function getServerAddresses(port: number, host: string, proto: string): {
2
- address: string;
3
- networkAddress: string;
4
- };
5
- export declare const getServerPort: (port: number) => Promise<number>;
6
- export declare const getServerChannelUrl: (port: number, { https }: {
7
- https?: boolean;
8
- }) => string;
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- import { Express } from 'express';
3
- import http from 'http';
4
- import https from 'https';
5
- export declare function getServer(app: Express, options: {
6
- https?: boolean;
7
- sslCert?: string;
8
- sslKey?: string;
9
- sslCa?: string[];
10
- }): Promise<http.Server | https.Server>;