react-cosmos 6.0.0-alpha.9 → 6.0.0-beta.1

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 (158) hide show
  1. package/bin/cosmos-export.js +1 -3
  2. package/bin/cosmos-native.js +1 -3
  3. package/bin/cosmos.js +1 -7
  4. package/client.d.ts +1 -0
  5. package/client.js +1 -0
  6. package/config.schema.json +53 -15
  7. package/dist/cjsMocks/requireModule.js +7 -0
  8. package/dist/cjsMocks/resolve.js +7 -0
  9. package/dist/cjsMocks/staticPath.js +4 -0
  10. package/dist/client.d.ts +1 -0
  11. package/dist/client.js +1 -0
  12. package/dist/corePlugins/exposeImports.d.ts +2 -0
  13. package/dist/corePlugins/exposeImports.js +53 -0
  14. package/dist/corePlugins/httpProxy.d.ts +2 -0
  15. package/dist/corePlugins/httpProxy.js +21 -0
  16. package/dist/corePlugins/index.d.ts +2 -0
  17. package/dist/corePlugins/index.js +12 -0
  18. package/dist/corePlugins/openFile.d.ts +2 -0
  19. package/dist/corePlugins/openFile.js +59 -0
  20. package/dist/corePlugins/pluginEndpoint.d.ts +2 -0
  21. package/dist/corePlugins/pluginEndpoint.js +22 -0
  22. package/dist/corePlugins/portRetry.d.ts +2 -0
  23. package/dist/corePlugins/portRetry.js +14 -0
  24. package/dist/{server/cosmosConfig → cosmosConfig}/createCosmosConfig.js +37 -11
  25. package/dist/{server/cosmosConfig → cosmosConfig}/shared.js +2 -2
  26. package/dist/{server/cosmosConfig → cosmosConfig}/types.d.ts +12 -2
  27. package/dist/{server/cosmosPlugin → cosmosPlugin}/findCosmosPluginConfigs.js +2 -2
  28. package/dist/{server/cosmosPlugin → cosmosPlugin}/readCosmosPluginConfig.js +4 -7
  29. package/dist/{server/cosmosPlugin → cosmosPlugin}/types.d.ts +15 -3
  30. package/dist/devServer/expressApp.d.ts +5 -0
  31. package/dist/{server/devServer → devServer}/expressApp.js +2 -2
  32. package/dist/{server/devServer → devServer}/messageHandler.d.ts +1 -1
  33. package/dist/{server/devServer → devServer}/messageHandler.js +2 -2
  34. package/dist/devServer/startDevServer.d.ts +2 -0
  35. package/dist/{server/devServer → devServer}/startDevServer.js +23 -29
  36. package/dist/{server/export → export}/generateExport.js +21 -18
  37. package/dist/{server/getFixtures → getFixtures}/getFixtures.d.ts +6 -2
  38. package/dist/getFixtures/getFixtures.js +53 -0
  39. package/dist/getFixtures/importUserModules.d.ts +8 -0
  40. package/dist/getFixtures/importUserModules.js +28 -0
  41. package/dist/index.d.ts +20 -0
  42. package/dist/index.js +20 -1
  43. package/dist/jest.d.ts +4 -7
  44. package/dist/jest.js +4 -7
  45. package/dist/shared/applyServerConfigPlugins.d.ts +11 -0
  46. package/dist/shared/applyServerConfigPlugins.js +14 -0
  47. package/dist/shared/findNextAvailablePort.d.ts +1 -0
  48. package/dist/shared/findNextAvailablePort.js +29 -0
  49. package/dist/shared/getServerPlugins.d.ts +2 -0
  50. package/dist/shared/getServerPlugins.js +6 -0
  51. package/dist/shared/importServerPlugins.d.ts +3 -0
  52. package/dist/shared/importServerPlugins.js +16 -0
  53. package/dist/shared/playgroundHtml.d.ts +5 -0
  54. package/dist/{server/shared → shared}/playgroundHtml.js +25 -33
  55. package/dist/shared/staticPath.d.ts +1 -0
  56. package/dist/{server/shared → shared}/staticServer.js +3 -1
  57. package/dist/{server/testHelpers → testHelpers}/mockConsole.js +8 -4
  58. package/dist/{server/testHelpers → testHelpers}/mockFs.d.ts +2 -2
  59. package/dist/{server/testHelpers → testHelpers}/mockFs.js +26 -8
  60. package/dist/{server/testHelpers → testHelpers}/mockYargs.js +1 -0
  61. package/dist/{server/userDeps → userModules}/findUserModulePaths.js +2 -2
  62. package/dist/userModules/generateUserImports.d.ts +10 -0
  63. package/dist/{server/userDeps/generateUserDepsModule.js → userModules/generateUserImports.js} +8 -3
  64. package/dist/userModules/shared.d.ts +15 -0
  65. package/dist/{server/userDeps → userModules}/shared.js +16 -0
  66. package/dist/userModules/userImportsLazyTemplate.d.ts +2 -0
  67. package/dist/userModules/userImportsLazyTemplate.js +54 -0
  68. package/dist/userModules/userImportsTemplate.d.ts +2 -0
  69. package/dist/userModules/userImportsTemplate.js +56 -0
  70. package/dist/{server/utils → utils}/cli.d.ts +1 -0
  71. package/dist/utils/cli.js +4 -0
  72. package/dist/utils/fs.d.ts +5 -0
  73. package/dist/{server/utils → utils}/fs.js +10 -6
  74. package/dist/utils/json.d.ts +3 -0
  75. package/dist/utils/requireModule.d.ts +2 -0
  76. package/dist/utils/resolve.d.ts +2 -0
  77. package/package.json +10 -9
  78. package/dist/server/devServer/corePlugins/httpProxy.d.ts +0 -2
  79. package/dist/server/devServer/corePlugins/httpProxy.js +0 -18
  80. package/dist/server/devServer/corePlugins/openFile.d.ts +0 -2
  81. package/dist/server/devServer/corePlugins/openFile.js +0 -53
  82. package/dist/server/devServer/corePlugins/pluginEndpoint.d.ts +0 -2
  83. package/dist/server/devServer/corePlugins/pluginEndpoint.js +0 -17
  84. package/dist/server/devServer/corePlugins/userDepsFile.d.ts +0 -2
  85. package/dist/server/devServer/corePlugins/userDepsFile.js +0 -37
  86. package/dist/server/devServer/expressApp.d.ts +0 -5
  87. package/dist/server/devServer/startDevServer.d.ts +0 -2
  88. package/dist/server/getFixtures/getFixtures.js +0 -63
  89. package/dist/server/shared/playgroundHtml.d.ts +0 -6
  90. package/dist/server/shared/requirePluginModule.d.ts +0 -2
  91. package/dist/server/shared/requirePluginModule.js +0 -10
  92. package/dist/server/shared/resolveRendererUrl.d.ts +0 -1
  93. package/dist/server/shared/resolveRendererUrl.js +0 -7
  94. package/dist/server/testHelpers/mockEsmRequire.js +0 -13
  95. package/dist/server/testHelpers/mockEsmResolve.d.ts +0 -1
  96. package/dist/server/testHelpers/mockEsmResolve.js +0 -13
  97. package/dist/server/testHelpers/mockEsmStaticPath.d.ts +0 -1
  98. package/dist/server/testHelpers/mockEsmStaticPath.js +0 -7
  99. package/dist/server/userDeps/generateUserDepsModule.d.ts +0 -9
  100. package/dist/server/userDeps/getUserModules.d.ts +0 -8
  101. package/dist/server/userDeps/getUserModules.js +0 -26
  102. package/dist/server/userDeps/shared.d.ts +0 -5
  103. package/dist/server/userDeps/userDepsTemplate.d.ts +0 -11
  104. package/dist/server/userDeps/userDepsTemplate.js +0 -49
  105. package/dist/server/utils/cli.js +0 -4
  106. package/dist/server/utils/fs.d.ts +0 -4
  107. package/dist/server.d.ts +0 -20
  108. package/dist/server.js +0 -20
  109. package/server.d.ts +0 -1
  110. package/server.js +0 -1
  111. /package/dist/{server/utils → cjsMocks}/requireModule.d.ts +0 -0
  112. /package/dist/{server/utils → cjsMocks}/resolve.d.ts +0 -0
  113. /package/dist/{server/shared → cjsMocks}/staticPath.d.ts +0 -0
  114. /package/dist/{server/cosmosConfig → cosmosConfig}/createCosmosConfig.d.ts +0 -0
  115. /package/dist/{server/cosmosConfig → cosmosConfig}/detectCosmosConfig.d.ts +0 -0
  116. /package/dist/{server/cosmosConfig → cosmosConfig}/detectCosmosConfig.js +0 -0
  117. /package/dist/{server/cosmosConfig → cosmosConfig}/getCosmosConfigAtPath.d.ts +0 -0
  118. /package/dist/{server/cosmosConfig → cosmosConfig}/getCosmosConfigAtPath.js +0 -0
  119. /package/dist/{server/cosmosConfig → cosmosConfig}/shared.d.ts +0 -0
  120. /package/dist/{server/cosmosConfig → cosmosConfig}/types.js +0 -0
  121. /package/dist/{server/cosmosPlugin → cosmosPlugin}/findCosmosPluginConfigs.d.ts +0 -0
  122. /package/dist/{server/cosmosPlugin → cosmosPlugin}/pluginConfigs.d.ts +0 -0
  123. /package/dist/{server/cosmosPlugin → cosmosPlugin}/pluginConfigs.js +0 -0
  124. /package/dist/{server/cosmosPlugin → cosmosPlugin}/readCosmosPluginConfig.d.ts +0 -0
  125. /package/dist/{server/cosmosPlugin → cosmosPlugin}/types.js +0 -0
  126. /package/dist/{server/devServer → devServer}/httpServer.d.ts +0 -0
  127. /package/dist/{server/devServer → devServer}/httpServer.js +0 -0
  128. /package/dist/{server/export → export}/generateExport.d.ts +0 -0
  129. /package/dist/{server/shared → shared}/logPluginInfo.d.ts +0 -0
  130. /package/dist/{server/shared → shared}/logPluginInfo.js +0 -0
  131. /package/dist/{server/shared → shared}/playgroundUrl.d.ts +0 -0
  132. /package/dist/{server/shared → shared}/playgroundUrl.js +0 -0
  133. /package/dist/{server/shared → shared}/staticPath.js +0 -0
  134. /package/dist/{server/shared → shared}/staticServer.d.ts +0 -0
  135. /package/dist/{server/static → static}/favicon.ico +0 -0
  136. /package/dist/{server/static → static}/index.html +0 -0
  137. /package/dist/{server/testHelpers → testHelpers}/cwd.d.ts +0 -0
  138. /package/dist/{server/testHelpers → testHelpers}/cwd.js +0 -0
  139. /package/dist/{server/testHelpers → testHelpers}/mockConsole.d.ts +0 -0
  140. /package/dist/{server/testHelpers → testHelpers}/mockFetch.d.ts +0 -0
  141. /package/dist/{server/testHelpers → testHelpers}/mockFetch.js +0 -0
  142. /package/dist/{server/testHelpers → testHelpers}/mockYargs.d.ts +0 -0
  143. /package/dist/{server/userDeps → userModules}/findUserModulePaths.d.ts +0 -0
  144. /package/dist/{server/userDeps → userModules}/fixtureWatcher.d.ts +0 -0
  145. /package/dist/{server/userDeps → userModules}/fixtureWatcher.js +0 -0
  146. /package/dist/{server/utils → utils}/isNodeError.d.ts +0 -0
  147. /package/dist/{server/utils → utils}/isNodeError.js +0 -0
  148. /package/dist/{server/testHelpers/mockEsmRequire.d.ts → utils/json.js} +0 -0
  149. /package/dist/{server/utils → utils}/requireModule.js +0 -0
  150. /package/dist/{server/utils → utils}/requireSilent.d.ts +0 -0
  151. /package/dist/{server/utils → utils}/requireSilent.js +0 -0
  152. /package/dist/{server/utils → utils}/resolve.js +0 -0
  153. /package/dist/{server/utils → utils}/resolveLoose.d.ts +0 -0
  154. /package/dist/{server/utils → utils}/resolveLoose.js +0 -0
  155. /package/dist/{server/utils → utils}/resolveSilent.d.ts +0 -0
  156. /package/dist/{server/utils → utils}/resolveSilent.js +0 -0
  157. /package/dist/{server/utils → utils}/slash.d.ts +0 -0
  158. /package/dist/{server/utils → utils}/slash.js +0 -0
@@ -1,7 +0,0 @@
1
- export function resolveRendererUrl(publicUrl, filename) {
2
- if (publicUrl === './')
3
- return filename;
4
- if (publicUrl.endsWith('/'))
5
- return publicUrl + filename;
6
- return `${publicUrl}/${filename}`;
7
- }
@@ -1,13 +0,0 @@
1
- jest.mock('../utils/requireModule.js', () => {
2
- function requireModule(moduleId) {
3
- return require(moduleId);
4
- }
5
- function requireFrom(fromDirectory, moduleId) {
6
- return require(require.resolve(moduleId, { paths: [fromDirectory] }));
7
- }
8
- return {
9
- requireModule,
10
- requireFrom,
11
- };
12
- });
13
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- jest.mock('../utils/resolve.js', () => {
2
- function resolve(moduleId) {
3
- return require.resolve(moduleId);
4
- }
5
- function resolveFrom(fromDirectory, moduleId) {
6
- return require.resolve(moduleId, { paths: [fromDirectory] });
7
- }
8
- return {
9
- resolve,
10
- resolveFrom,
11
- };
12
- });
13
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- jest.mock('../shared/staticPath.js', () => {
2
- function getStaticPath(relPath) {
3
- return require.resolve(`../static/${relPath}`);
4
- }
5
- return { getStaticPath };
6
- });
7
- export {};
@@ -1,9 +0,0 @@
1
- import { CosmosConfig } from '../cosmosConfig/types.js';
2
- import { Json } from './shared.js';
3
- type Args = {
4
- cosmosConfig: CosmosConfig;
5
- rendererConfig: Json;
6
- relativeToDir: string | null;
7
- };
8
- export declare function generateUserDepsModule({ cosmosConfig, rendererConfig, relativeToDir, }: Args): string;
9
- export {};
@@ -1,8 +0,0 @@
1
- import { ReactDecorators, ReactFixtureExports } from 'react-cosmos-core';
2
- import { CosmosConfig } from '../cosmosConfig/types.js';
3
- type UserModules = {
4
- fixtures: ReactFixtureExports;
5
- decorators: ReactDecorators;
6
- };
7
- export declare function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): UserModules;
8
- export {};
@@ -1,26 +0,0 @@
1
- import path from 'path';
2
- import { slash } from '../utils/slash.js';
3
- import { findUserModulePaths } from './findUserModulePaths.js';
4
- export function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
- const { fixturePaths, decoratorPaths } = findUserModulePaths({
6
- rootDir,
7
- fixturesDir,
8
- fixtureFileSuffix,
9
- ignore,
10
- });
11
- return {
12
- fixtures: getDefaultExports(fixturePaths, rootDir),
13
- decorators: getDefaultExports(decoratorPaths, rootDir),
14
- };
15
- }
16
- function getDefaultExports(paths, rootDir) {
17
- const exportsByPath = {};
18
- paths.forEach(p => {
19
- // Converting to forward slashes on Windows is important because the
20
- // slashes are used for generating a sorted list of fixtures and
21
- // decorators.
22
- const relPath = slash(path.relative(rootDir, p));
23
- exportsByPath[relPath] = require(p).default;
24
- });
25
- return exportsByPath;
26
- }
@@ -1,5 +0,0 @@
1
- export type Json = string | number | boolean | null | {
2
- [property: string]: Json;
3
- } | Json[];
4
- export declare function getFixturePatterns(fixturesDir: string, fixtureFileSuffix: string): string[];
5
- export declare function getDecoratorPatterns(): string[];
@@ -1,11 +0,0 @@
1
- import { Json } from './shared.js';
2
- type Args = {
3
- globalImports: string[];
4
- fixturePaths: string[];
5
- decoratorPaths: string[];
6
- rendererConfig: Json;
7
- rootDir: string;
8
- relativeToDir: string | null;
9
- };
10
- export declare function userDepsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, }: Args): string;
11
- export {};
@@ -1,49 +0,0 @@
1
- import path from 'path';
2
- import { slash } from '../utils/slash.js';
3
- export function userDepsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, }) {
4
- const fixtures = createImportMap(fixturePaths, rootDir, relativeToDir);
5
- const fixtureKeys = Object.keys(fixtures);
6
- const decorators = createImportMap(decoratorPaths, rootDir, relativeToDir);
7
- const decoratorKeys = Object.keys(decorators);
8
- return `
9
- // This file is automatically generated by Cosmos. Add it to .gitignore and
10
- // only edit if you know what you're doing.
11
-
12
- // Keeping global imports here is superior to making them bundle entry points
13
- // because this way they become hot-reloadable.
14
- ${globalImports
15
- .map(p => `import '${resolveImportPath(p, relativeToDir)}';`)
16
- .join(`\n`)}
17
-
18
- ${fixtureKeys
19
- .map((k, i) => `import fixture${i} from '${fixtures[k]}';`)
20
- .join(`\n`)}
21
-
22
- ${decoratorKeys
23
- .map((k, i) => `import decorator${i} from '${decorators[k]}';`)
24
- .join(`\n`)}
25
-
26
- export const rendererConfig = ${JSON.stringify(rendererConfig, null, 2)};
27
-
28
- export const fixtures = {
29
- ${fixtureKeys
30
- .map((k, i) => ` '${k}': { module: { default: fixture${i} } }`)
31
- .join(`,\n`)}
32
- };
33
-
34
- export const decorators = {
35
- ${decoratorKeys.map((k, i) => ` '${k}': decorator${i}`).join(`,\n`)}
36
- };
37
- `.trimStart();
38
- }
39
- function createImportMap(paths, rootDir, relativeToDir) {
40
- return paths.reduce((acc, p) => ({
41
- ...acc,
42
- [slash(path.relative(rootDir, p))]: resolveImportPath(p, relativeToDir),
43
- }), {});
44
- }
45
- function resolveImportPath(filePath, relativeToDir) {
46
- return slash(relativeToDir
47
- ? `.${path.sep}${path.relative(relativeToDir, filePath)}`
48
- : filePath);
49
- }
@@ -1,4 +0,0 @@
1
- import yargs from 'yargs/yargs';
2
- export function getCliArgs() {
3
- return yargs(process.argv.slice(2)).parseSync();
4
- }
@@ -1,4 +0,0 @@
1
- export declare function importModule<T>(moduleId: string): Promise<T>;
2
- export declare function moduleExists(moduleId: string): boolean | "";
3
- export declare function fileExists(filePath: string): boolean;
4
- export declare function dirExists(dirPath: string): boolean;
package/dist/server.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export * from './server/cosmosConfig/createCosmosConfig.js';
2
- export * from './server/cosmosConfig/detectCosmosConfig.js';
3
- export * from './server/cosmosConfig/getCosmosConfigAtPath.js';
4
- export * from './server/cosmosConfig/types.js';
5
- export * from './server/cosmosPlugin/findCosmosPluginConfigs.js';
6
- export * from './server/cosmosPlugin/pluginConfigs.js';
7
- export * from './server/cosmosPlugin/types.js';
8
- export * from './server/getFixtures/getFixtures.js';
9
- export { RENDERER_FILENAME } from './server/shared/playgroundHtml.js';
10
- export * from './server/shared/playgroundUrl.js';
11
- export * from './server/shared/staticServer.js';
12
- export * from './server/testHelpers/cwd.js';
13
- export * from './server/userDeps/fixtureWatcher.js';
14
- export * from './server/userDeps/generateUserDepsModule.js';
15
- export * from './server/utils/cli.js';
16
- export * from './server/utils/fs.js';
17
- export * from './server/utils/requireSilent.js';
18
- export * from './server/utils/resolve.js';
19
- export * from './server/utils/resolveLoose.js';
20
- export * from './server/utils/resolveSilent.js';
package/dist/server.js DELETED
@@ -1,20 +0,0 @@
1
- export * from './server/cosmosConfig/createCosmosConfig.js';
2
- export * from './server/cosmosConfig/detectCosmosConfig.js';
3
- export * from './server/cosmosConfig/getCosmosConfigAtPath.js';
4
- export * from './server/cosmosConfig/types.js';
5
- export * from './server/cosmosPlugin/findCosmosPluginConfigs.js';
6
- export * from './server/cosmosPlugin/pluginConfigs.js';
7
- export * from './server/cosmosPlugin/types.js';
8
- export * from './server/getFixtures/getFixtures.js';
9
- export { RENDERER_FILENAME } from './server/shared/playgroundHtml.js';
10
- export * from './server/shared/playgroundUrl.js';
11
- export * from './server/shared/staticServer.js';
12
- export * from './server/testHelpers/cwd.js';
13
- export * from './server/userDeps/fixtureWatcher.js';
14
- export * from './server/userDeps/generateUserDepsModule.js';
15
- export * from './server/utils/cli.js';
16
- export * from './server/utils/fs.js';
17
- export * from './server/utils/requireSilent.js';
18
- export * from './server/utils/resolve.js';
19
- export * from './server/utils/resolveLoose.js';
20
- export * from './server/utils/resolveSilent.js';
package/server.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/server.js';
package/server.js DELETED
@@ -1 +0,0 @@
1
- export * from './dist/server.js';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes