react-cosmos 6.0.0-canary.fdbaa56.0 → 6.0.0

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 (64) hide show
  1. package/README.md +37 -3
  2. package/config.schema.json +10 -10
  3. package/dist/cjsMocks/requireModule.d.ts +2 -0
  4. package/dist/cjsMocks/requireModule.js +7 -0
  5. package/dist/cjsMocks/resolve.d.ts +2 -0
  6. package/dist/cjsMocks/resolve.js +7 -0
  7. package/dist/cjsMocks/staticPath.d.ts +1 -0
  8. package/dist/cjsMocks/staticPath.js +4 -0
  9. package/dist/client.d.ts +1 -1
  10. package/dist/client.js +1 -1
  11. package/dist/corePlugins/{openFile.d.ts → fixtureWatcherPlugin.d.ts} +1 -1
  12. package/dist/corePlugins/{exposeImports.js → fixtureWatcherPlugin.js} +26 -10
  13. package/dist/corePlugins/httpProxyPlugin.d.ts +2 -0
  14. package/dist/corePlugins/{httpProxy.js → httpProxyPlugin.js} +1 -1
  15. package/dist/corePlugins/index.js +13 -10
  16. package/dist/corePlugins/openFilePlugin.d.ts +2 -0
  17. package/dist/corePlugins/{openFile.js → openFilePlugin.js} +1 -1
  18. package/dist/corePlugins/pluginEndpointPlugin.d.ts +2 -0
  19. package/dist/corePlugins/{pluginEndpoint.js → pluginEndpointPlugin.js} +1 -1
  20. package/dist/corePlugins/portRetryPlugin.d.ts +2 -0
  21. package/dist/corePlugins/{portRetry.js → portRetryPlugin.js} +1 -1
  22. package/dist/devServer/expressApp.js +2 -3
  23. package/dist/devServer/startDevServer.js +12 -22
  24. package/dist/export/generateExport.js +10 -20
  25. package/dist/getFixtures/getFixtures.d.ts +5 -1
  26. package/dist/getFixtures/getFixtures.js +29 -27
  27. package/dist/{userModules → getFixtures}/importUserModules.d.ts +3 -3
  28. package/dist/{userModules → getFixtures}/importUserModules.js +10 -8
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.js +2 -0
  31. package/dist/jest.d.ts +0 -3
  32. package/dist/jest.js +0 -3
  33. package/dist/shared/applyServerConfigPlugins.d.ts +11 -0
  34. package/dist/shared/applyServerConfigPlugins.js +14 -0
  35. package/dist/shared/getServerPlugins.d.ts +2 -0
  36. package/dist/shared/getServerPlugins.js +6 -0
  37. package/dist/shared/playgroundHtml.js +5 -13
  38. package/dist/shared/serverFixtureList.d.ts +4 -0
  39. package/dist/shared/serverFixtureList.js +19 -0
  40. package/dist/static/favicon.ico +0 -0
  41. package/dist/userModules/findUserModulePaths.d.ts +1 -4
  42. package/dist/userModules/findUserModulePaths.js +1 -1
  43. package/dist/userModules/generateUserImports.d.ts +3 -1
  44. package/dist/userModules/generateUserImports.js +4 -12
  45. package/dist/userModules/shared.d.ts +6 -3
  46. package/dist/userModules/shared.js +3 -3
  47. package/dist/userModules/userImportsLazyTemplate.d.ts +1 -1
  48. package/dist/userModules/userImportsLazyTemplate.js +1 -1
  49. package/dist/userModules/userImportsTemplate.d.ts +1 -1
  50. package/dist/userModules/userImportsTemplate.js +1 -1
  51. package/dist/utils/findUp.d.ts +1 -0
  52. package/dist/utils/findUp.js +19 -0
  53. package/jest.js +1 -1
  54. package/package.json +16 -17
  55. package/dist/corePlugins/exposeImports.d.ts +0 -2
  56. package/dist/corePlugins/httpProxy.d.ts +0 -2
  57. package/dist/corePlugins/pluginEndpoint.d.ts +0 -2
  58. package/dist/corePlugins/portRetry.d.ts +0 -2
  59. package/dist/testHelpers/mockEsmRequire.d.ts +0 -1
  60. package/dist/testHelpers/mockEsmRequire.js +0 -13
  61. package/dist/testHelpers/mockEsmResolve.d.ts +0 -1
  62. package/dist/testHelpers/mockEsmResolve.js +0 -13
  63. package/dist/testHelpers/mockEsmStaticPath.d.ts +0 -1
  64. package/dist/testHelpers/mockEsmStaticPath.js +0 -7
package/README.md CHANGED
@@ -1,7 +1,41 @@
1
1
  <p align="center">
2
- <a href="https://reactcosmos.org"><img alt="Cosmos" width="150" height="150" src="https://raw.githubusercontent.com/react-cosmos/react-cosmos/main/cosmos.png"></a>
2
+ <a href="https://reactcosmos.org"><img alt="Cosmos" width="150" height="150" src="cosmos.png"></a>
3
+ <h1 align="center">React Cosmos</h1>
3
4
  </p>
4
5
 
5
- # React Cosmos
6
+ <p align="center">
7
+ <a aria-label="npm version" href="https://www.npmjs.com/package/react-cosmos"><img src="https://img.shields.io/npm/v/react-cosmos/next.svg?style=flat&colorA=000000&colorB=000000" alt="" /></a>
8
+ <a aria-label="CI Status" href="https://github.com/react-cosmos/react-cosmos/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/react-cosmos/react-cosmos/test.yml?branch=main&style=flat&colorA=000000&colorB=000000" alt="" /></a>
9
+ <a aria-label="Codecov" href="https://app.codecov.io/gh/react-cosmos/react-cosmos"><img src="https://img.shields.io/codecov/c/github/react-cosmos/react-cosmos?colorA=000000&colorB=000000" alt="" /></a>
10
+ <a aria-label="Twitter" href="https://twitter.com/ReactCosmos"><img src="https://img.shields.io/badge/twitter-follow-%2300acee?colorA=000000&colorB=000000" alt="" /></a>
11
+ <a aria-label="Discord" href="https://discord.gg/3X95VgfnW5"><img src="https://img.shields.io/discord/620737684859781150?label=discord&logo=discord&logoColor=ffffff&colorA=000000&colorB=000000" alt="" /></a>
12
+ <a aria-label="PRs Welcome" href="https://github.com/react-cosmos/react-cosmos/blob/main/CONTRIBUTING.md#how-to-contribute"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?colorA=000000&colorB=000000" alt="" /></a>
13
+ </p>
14
+
15
+ ## Getting Started
16
+
17
+ Choose one of the [Getting Started](https://reactcosmos.org/docs/getting-started) guides to dive into React Cosmos.
18
+
19
+ > Check out the [Next.js integration](https://reactcosmos.org/docs/getting-started/next) to get started with React Server Components.
20
+
21
+ Visit [reactcosmos.org/docs](https://reactcosmos.org/docs) to view the full documentation.
22
+
23
+ ## Community
24
+
25
+ To chat with other community members you can join the [React Cosmos Discord](https://discord.gg/3X95VgfnW5).
26
+
27
+ You can also ask questions, voice ideas, and share your projects on [GitHub Discussions](https://github.com/react-cosmos/react-cosmos/discussions).
28
+
29
+ Our [Code of Conduct](/CODE_OF_CONDUCT.md) applies to all React Cosmos community channels.
30
+
31
+ ## Contributing
32
+
33
+ Please see our [CONTRIBUTING.md](/CONTRIBUTING.md).
34
+
35
+ [Become a Sponsor](https://github.com/users/skidding/sponsorship) to support the ongoing development of React Cosmos.
36
+
37
+ ## Live Demo
38
+
39
+ Visit [reactcosmos.org/demo/](https://reactcosmos.org/demo/) for a live demo of React Cosmos.
6
40
 
7
- Sandbox for developing and testing UI components in isolation.
41
+ [![React Cosmos](/docs/public/demo.png)](https://reactcosmos.org/demo/)
@@ -11,16 +11,16 @@
11
11
  "minLength": 1
12
12
  },
13
13
  "exportPath": {
14
- "description": "Where to generate static exports on disk. [default: \"cosmos-export\"]",
14
+ "description": "Output directory for static exports. [default: \"cosmos-export\"]",
15
15
  "type": "string",
16
16
  "minLength": 1
17
17
  },
18
18
  "detectLocalPlugins": {
19
- "description": "Automatically detect and load local plugins",
19
+ "description": "Automatically detect and load local plugins. [default: true]",
20
20
  "type": "boolean"
21
21
  },
22
22
  "disablePlugins": {
23
- "description": "Disable plugins",
23
+ "description": "Disable plugins. [default: false]",
24
24
  "type": "boolean"
25
25
  },
26
26
  "staticPath": {
@@ -39,7 +39,7 @@
39
39
  "type": "string"
40
40
  },
41
41
  "fixturesDir": {
42
- "description": "Name for directories that contain fixtures (eg. __fixtures__/example.jsx). [default: \"__fixtures__\"]",
42
+ "description": "Name for directories that contain fixture files (eg. __fixtures__/example.jsx). [default: \"__fixtures__\"]",
43
43
  "type": "string",
44
44
  "minLength": 1
45
45
  },
@@ -49,7 +49,7 @@
49
49
  "minLength": 1
50
50
  },
51
51
  "ignore": {
52
- "description": "Patterns for ignoring fixture and decorator files (eg. [\"**/dist/**\"]]).",
52
+ "description": "Patterns for ignoring fixture and decorator files (eg. [\"**/dist/**\"]).",
53
53
  "type": "array",
54
54
  "items": { "type": "string", "minLength": 1 },
55
55
  "uniqueItems": true
@@ -93,17 +93,17 @@
93
93
  "additionalProperties": false,
94
94
  "properties": {
95
95
  "certPath": {
96
- "description": "Path of a certificate file",
96
+ "description": "Path of a certificate file.",
97
97
  "type": "string"
98
98
  },
99
99
  "keyPath": {
100
- "description": "Path of a certificate's key file",
100
+ "description": "Path of a certificate's key file.",
101
101
  "type": "string"
102
102
  }
103
103
  }
104
104
  },
105
105
  "httpProxy": {
106
- "description": "Proxy some URLs to a different HTTP server (eg. an API backend dev server). Similar to devServer.proxy in webpack config.",
106
+ "description": "Proxy some URLs to a different HTTP server (eg. an API backend dev server).",
107
107
  "type": "object",
108
108
  "additionalProperties": true,
109
109
  "patternProperties": {
@@ -171,11 +171,11 @@
171
171
  "additionalProperties": false,
172
172
  "properties": {
173
173
  "configPath": {
174
- "description": "Path to Vite config. Set to false to disable reading it from the default path. [default: \"vite.config.js\"]",
174
+ "description": "Path to Vite config. Set to false to disable reading it from the default path. [default: \"vite.config.js\" or \"vite.config.ts\"]",
175
175
  "anyOf": [{ "type": "string", "minLength": 1 }, { "enum": [false] }]
176
176
  },
177
177
  "indexPath": {
178
- "description": "Path to index module (eg. \"src/my-index.tsx\"). [default: matches common index/main module paths]",
178
+ "description": "Path to index module (eg. \"src/my-index.tsx\"). [default: detects common index/main module paths]",
179
179
  "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
180
180
  },
181
181
  "port": {
@@ -0,0 +1,2 @@
1
+ export declare function requireModule(moduleId: string): any;
2
+ export declare function requireFrom(fromDirectory: string, moduleId: string): any;
@@ -0,0 +1,7 @@
1
+ // CJS mock for packages/react-cosmos/src/utils/requireModule.ts
2
+ export function requireModule(moduleId) {
3
+ return require(moduleId);
4
+ }
5
+ export function requireFrom(fromDirectory, moduleId) {
6
+ return require(require.resolve(moduleId, { paths: [fromDirectory] }));
7
+ }
@@ -0,0 +1,2 @@
1
+ export declare function resolve(moduleId: string): string;
2
+ export declare function resolveFrom(fromDirectory: string, moduleId: string): string;
@@ -0,0 +1,7 @@
1
+ // CJS mock for packages/react-cosmos/src/utils/resolve.ts
2
+ export function resolve(moduleId) {
3
+ return require.resolve(moduleId);
4
+ }
5
+ export function resolveFrom(fromDirectory, moduleId) {
6
+ return require.resolve(moduleId, { paths: [fromDirectory] });
7
+ }
@@ -0,0 +1 @@
1
+ export declare function getStaticPath(relPath: string): string;
@@ -0,0 +1,4 @@
1
+ // CJS mock for packages/react-cosmos/src/shared/staticPath.ts
2
+ export function getStaticPath(relPath) {
3
+ return require.resolve(`../static/${relPath}`);
4
+ }
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { Viewport, useSelect, useValue } from 'react-cosmos-renderer/client';
1
+ export { FixtureContext, Viewport, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- export { Viewport, useSelect, useValue } from 'react-cosmos-renderer/client';
1
+ export { FixtureContext, Viewport, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
@@ -1,2 +1,2 @@
1
1
  import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
- export declare const openFileServerPlugin: CosmosServerPlugin;
2
+ export declare const fixtureWatcherPlugin: CosmosServerPlugin;
@@ -1,27 +1,42 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
+ import { pickRendererUrl, } from 'react-cosmos-core';
3
4
  import { getPlaygroundUrl } from '../shared/playgroundUrl.js';
5
+ import { updateFixtureListCache } from '../shared/serverFixtureList.js';
6
+ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
4
7
  import { startFixtureWatcher } from '../userModules/fixtureWatcher.js';
5
8
  import { generateUserImports } from '../userModules/generateUserImports.js';
6
9
  import { moduleExists } from '../utils/fs.js';
7
- export const exposeImportsServerPlugin = {
8
- name: 'exposeImports',
10
+ export const fixtureWatcherPlugin = {
11
+ name: 'fixtureWatcher',
9
12
  async devServer({ cosmosConfig, platform }) {
10
- if (!shouldExposeImports(platform, cosmosConfig))
11
- return;
12
- await generateImportsFile(cosmosConfig);
13
+ const exposeImports = shouldExposeImports(platform, cosmosConfig);
14
+ if (exposeImports) {
15
+ const modulePaths = findUserModulePaths(cosmosConfig);
16
+ await generateImportsFile(cosmosConfig, 'dev', modulePaths);
17
+ }
13
18
  const watcher = await startFixtureWatcher(cosmosConfig, 'all', () => {
14
- generateImportsFile(cosmosConfig);
19
+ const modulePaths = findUserModulePaths(cosmosConfig);
20
+ updateFixtureListCache(cosmosConfig.rootDir, modulePaths.fixturePaths);
21
+ if (exposeImports) {
22
+ generateImportsFile(cosmosConfig, 'dev', modulePaths);
23
+ }
15
24
  });
16
- return () => {
17
- watcher.close();
25
+ return async () => {
26
+ await watcher.close();
18
27
  };
19
28
  },
29
+ async export({ cosmosConfig }) {
30
+ if (shouldExposeImports('web', cosmosConfig)) {
31
+ const modulePaths = findUserModulePaths(cosmosConfig);
32
+ await generateImportsFile(cosmosConfig, 'export', modulePaths);
33
+ }
34
+ },
20
35
  };
21
36
  function shouldExposeImports(platform, cosmosConfig) {
22
37
  return platform === 'native' || Boolean(cosmosConfig.exposeImports);
23
38
  }
24
- async function generateImportsFile(cosmosConfig) {
39
+ async function generateImportsFile(cosmosConfig, command, modulePaths) {
25
40
  const { exposeImports } = cosmosConfig;
26
41
  const filePath = typeof exposeImports === 'string'
27
42
  ? exposeImports
@@ -29,10 +44,11 @@ async function generateImportsFile(cosmosConfig) {
29
44
  const typeScript = /\.tsx?$/.test(filePath);
30
45
  const rendererConfig = {
31
46
  playgroundUrl: getPlaygroundUrl(cosmosConfig),
32
- rendererUrl: cosmosConfig.rendererUrl,
47
+ rendererUrl: pickRendererUrl(cosmosConfig.rendererUrl, command),
33
48
  };
34
49
  const fileSource = generateUserImports({
35
50
  cosmosConfig,
51
+ modulePaths,
36
52
  rendererConfig,
37
53
  relativeToDir: path.dirname(filePath),
38
54
  typeScript,
@@ -0,0 +1,2 @@
1
+ import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
+ export declare const httpProxyPlugin: CosmosServerPlugin;
@@ -1,5 +1,5 @@
1
1
  import { createProxyMiddleware } from 'http-proxy-middleware';
2
- export const httpProxyServerPlugin = {
2
+ export const httpProxyPlugin = {
3
3
  name: 'httpProxy',
4
4
  devServer({ cosmosConfig, platform, expressApp }) {
5
5
  if (platform !== 'web')
@@ -1,12 +1,15 @@
1
- import { exposeImportsServerPlugin } from './exposeImports.js';
2
- import { httpProxyServerPlugin } from './httpProxy.js';
3
- import { openFileServerPlugin } from './openFile.js';
4
- import { pluginEndpointServerPlugin } from './pluginEndpoint.js';
5
- import { portRetryServerPlugin } from './portRetry.js';
1
+ import { fixtureWatcherPlugin } from './fixtureWatcherPlugin.js';
2
+ import { httpProxyPlugin } from './httpProxyPlugin.js';
3
+ import { openFilePlugin } from './openFilePlugin.js';
4
+ import { pluginEndpointPlugin } from './pluginEndpointPlugin.js';
5
+ import { portRetryPlugin } from './portRetryPlugin.js';
6
6
  export const coreServerPlugins = [
7
- portRetryServerPlugin,
8
- exposeImportsServerPlugin,
9
- httpProxyServerPlugin,
10
- openFileServerPlugin,
11
- pluginEndpointServerPlugin,
7
+ portRetryPlugin,
8
+ httpProxyPlugin,
9
+ openFilePlugin,
10
+ pluginEndpointPlugin,
12
11
  ];
12
+ // Omit starting chokidar in Jest tests for performance reasons
13
+ if (process.env.JEST_WORKER_ID === undefined) {
14
+ coreServerPlugins.push(fixtureWatcherPlugin);
15
+ }
@@ -0,0 +1,2 @@
1
+ import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
+ export declare const openFilePlugin: CosmosServerPlugin;
@@ -2,7 +2,7 @@ import launchEditor from '@skidding/launch-editor';
2
2
  import fs from 'fs';
3
3
  import open from 'open';
4
4
  import path from 'path';
5
- export const openFileServerPlugin = {
5
+ export const openFilePlugin = {
6
6
  name: 'openFile',
7
7
  devServer({ cosmosConfig, expressApp }) {
8
8
  expressApp.get('/_open', (req, res) => {
@@ -0,0 +1,2 @@
1
+ import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
+ export declare const pluginEndpointPlugin: CosmosServerPlugin;
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { resolveSilent } from '../utils/resolveSilent.js';
3
- export const pluginEndpointServerPlugin = {
3
+ export const pluginEndpointPlugin = {
4
4
  name: 'pluginEndpoint',
5
5
  devServer({ expressApp }) {
6
6
  expressApp.get('/_plugin/*.js', (req, res) => {
@@ -0,0 +1,2 @@
1
+ import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
+ export declare const portRetryPlugin: CosmosServerPlugin;
@@ -1,5 +1,5 @@
1
1
  import { findNextAvailablePort } from '../shared/findNextAvailablePort.js';
2
- export const portRetryServerPlugin = {
2
+ export const portRetryPlugin = {
3
3
  name: 'portRetry',
4
4
  async config({ cosmosConfig, command }) {
5
5
  if (command === 'export') {
@@ -4,9 +4,8 @@ import { getStaticPath } from '../shared/staticPath.js';
4
4
  import { resolve } from '../utils/resolve.js';
5
5
  export async function createExpressApp(platform, cosmosConfig, pluginConfigs) {
6
6
  const app = express();
7
- const playgroundHtml = await getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs);
8
- app.get('/', (req, res) => {
9
- res.send(playgroundHtml);
7
+ app.get('/', async (req, res) => {
8
+ res.send(await getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs));
10
9
  });
11
10
  app.get('/playground.bundle.js', (req, res) => {
12
11
  res.sendFile(resolve('react-cosmos-ui/dist/playground.bundle.js'));
@@ -1,8 +1,8 @@
1
1
  import path from 'path';
2
- import { coreServerPlugins } from '../corePlugins/index.js';
3
2
  import { detectCosmosConfig, detectCosmosConfigPath, } from '../cosmosConfig/detectCosmosConfig.js';
4
3
  import { getPluginConfigs } from '../cosmosPlugin/pluginConfigs.js';
5
- import { importServerPlugins } from '../shared/importServerPlugins.js';
4
+ import { applyServerConfigPlugins } from '../shared/applyServerConfigPlugins.js';
5
+ import { getServerPlugins } from '../shared/getServerPlugins.js';
6
6
  import { logPluginInfo } from '../shared/logPluginInfo.js';
7
7
  import { serveStaticDir } from '../shared/staticServer.js';
8
8
  import { createExpressApp } from './expressApp.js';
@@ -19,23 +19,13 @@ export async function startDevServer(platform) {
19
19
  relativePaths: false,
20
20
  });
21
21
  logPluginInfo(pluginConfigs);
22
- const userPlugins = await importServerPlugins(pluginConfigs, cosmosConfig.rootDir);
23
- const plugins = [...coreServerPlugins, ...userPlugins];
24
- for (const plugin of plugins) {
25
- if (plugin.config) {
26
- try {
27
- cosmosConfig = await plugin.config({
28
- cosmosConfig,
29
- command: 'dev',
30
- platform,
31
- });
32
- }
33
- catch (err) {
34
- console.log(`[Cosmos][plugin:${plugin.name}] Config hook failed`);
35
- throw err;
36
- }
37
- }
38
- }
22
+ const serverPlugins = await getServerPlugins(pluginConfigs, cosmosConfig.rootDir);
23
+ cosmosConfig = await applyServerConfigPlugins({
24
+ cosmosConfig,
25
+ serverPlugins,
26
+ command: 'dev',
27
+ platform,
28
+ });
39
29
  const app = await createExpressApp(platform, cosmosConfig, pluginConfigs);
40
30
  const httpServer = await createHttpServer(cosmosConfig, app);
41
31
  const msgHandler = createMessageHandler(httpServer.server);
@@ -51,7 +41,7 @@ export async function startDevServer(platform) {
51
41
  msgHandler.close();
52
42
  await httpServer.stop();
53
43
  }
54
- for (const plugin of plugins) {
44
+ for (const plugin of serverPlugins) {
55
45
  try {
56
46
  if (!plugin.devServer)
57
47
  continue;
@@ -63,9 +53,9 @@ export async function startDevServer(platform) {
63
53
  sendMessage: msgHandler.sendMessage,
64
54
  });
65
55
  if (typeof pluginReturn === 'function') {
66
- pluginCleanupCallbacks.push(() => {
56
+ pluginCleanupCallbacks.push(async () => {
67
57
  try {
68
- pluginReturn();
58
+ await pluginReturn();
69
59
  }
70
60
  catch (err) {
71
61
  // Log when a plugin fails to clean up, but continue to attempt
@@ -1,9 +1,9 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'path';
3
- import { coreServerPlugins } from '../corePlugins/index.js';
4
3
  import { detectCosmosConfig } from '../cosmosConfig/detectCosmosConfig.js';
5
4
  import { getPluginConfigs } from '../cosmosPlugin/pluginConfigs.js';
6
- import { importServerPlugins } from '../shared/importServerPlugins.js';
5
+ import { applyServerConfigPlugins } from '../shared/applyServerConfigPlugins.js';
6
+ import { getServerPlugins } from '../shared/getServerPlugins.js';
7
7
  import { logPluginInfo } from '../shared/logPluginInfo.js';
8
8
  import { getExportPlaygroundHtml } from '../shared/playgroundHtml.js';
9
9
  import { getStaticPath } from '../shared/staticPath.js';
@@ -17,23 +17,13 @@ export async function generateExport() {
17
17
  relativePaths: true,
18
18
  });
19
19
  logPluginInfo(pluginConfigs);
20
- const userPlugins = await importServerPlugins(pluginConfigs, cosmosConfig.rootDir);
21
- const plugins = [...coreServerPlugins, ...userPlugins];
22
- for (const plugin of plugins) {
23
- if (plugin.config) {
24
- try {
25
- cosmosConfig = await plugin.config({
26
- cosmosConfig,
27
- command: 'export',
28
- platform: 'web',
29
- });
30
- }
31
- catch (err) {
32
- console.log(`[Cosmos][plugin:${plugin.name}] Config hook failed`);
33
- throw err;
34
- }
35
- }
36
- }
20
+ const serverPlugins = await getServerPlugins(pluginConfigs, cosmosConfig.rootDir);
21
+ cosmosConfig = await applyServerConfigPlugins({
22
+ cosmosConfig,
23
+ serverPlugins,
24
+ command: 'export',
25
+ platform: 'web',
26
+ });
37
27
  // Clear previous export (or other files at export path)
38
28
  const { exportPath } = cosmosConfig;
39
29
  await fs.rm(exportPath, { recursive: true, force: true });
@@ -41,7 +31,7 @@ export async function generateExport() {
41
31
  // Copy static assets first, so that the built index.html overrides the its
42
32
  // template file (in case the static assets are served from the root path)
43
33
  await copyStaticAssets(cosmosConfig);
44
- for (const plugin of plugins) {
34
+ for (const plugin of serverPlugins) {
45
35
  if (!plugin.export)
46
36
  continue;
47
37
  try {
@@ -11,4 +11,8 @@ export type FixtureApi = {
11
11
  rendererUrl: string | null;
12
12
  treePath: string[];
13
13
  };
14
- export declare function getFixtures(cosmosConfig: CosmosConfig): FixtureApi[];
14
+ type Options = {
15
+ rendererUrl?: string;
16
+ };
17
+ export declare function getFixtures(cosmosConfig: CosmosConfig, options?: Options): FixtureApi[];
18
+ export {};
@@ -1,21 +1,16 @@
1
+ import { mapValues } from 'lodash-es';
1
2
  import path from 'path';
2
- import { buildPlaygroundQueryString, createFixtureTree, createRendererUrl, flattenFixtureTree, getFixtureFromExport, getFixtureListFromExports, getSortedDecoratorsForFixturePath, pickRendererUrl, } from 'react-cosmos-core';
3
+ import { buildPlaygroundQueryString, createFixtureTree, createRendererUrl, flattenFixtureTree, getFixtureFromExport, getFixtureListFromExports, getSortedDecoratorsForFixturePath, } from 'react-cosmos-core';
3
4
  import { createFixtureNode, decorateFixture } from 'react-cosmos-renderer';
4
- import { importUserModules } from '../userModules/importUserModules.js';
5
- export function getFixtures(cosmosConfig) {
6
- const { fixturesDir, fixtureFileSuffix, rootDir } = cosmosConfig;
7
- const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, 'dev');
8
- const fixtureInfo = [];
5
+ import { getPlaygroundUrl } from '../shared/playgroundUrl.js';
6
+ import { importUserModules } from './importUserModules.js';
7
+ export function getFixtures(cosmosConfig, options = {}) {
9
8
  const { fixtures, decorators } = importUserModules(cosmosConfig);
10
- const fixtureList = getFixtureListFromExports(fixtures);
11
- const fixtureTree = createFixtureTree({
12
- fixtures: fixtureList,
13
- fixturesDir,
14
- fixtureFileSuffix,
15
- });
16
- const flatFixtureTree = flattenFixtureTree(fixtureTree);
17
- flatFixtureTree.forEach(({ fileName, fixtureId, name, parents }) => {
18
- const fixtureExport = fixtures[fixtureId.path];
9
+ const fixtureExports = mapValues(fixtures, f => f.default);
10
+ const decoratorExports = mapValues(decorators, f => f.default);
11
+ const result = [];
12
+ getFlatFixtureTree(cosmosConfig, fixtureExports).forEach(({ fileName, fixtureId, name, parents }) => {
13
+ const fixtureExport = fixtures[fixtureId.path].default;
19
14
  const fixture = getFixtureFromExport(fixtureExport, fixtureId.name);
20
15
  if (!fixture) {
21
16
  throw new Error(`Could not read fixture: ${JSON.stringify(fixtureId)}`);
@@ -23,27 +18,34 @@ export function getFixtures(cosmosConfig) {
23
18
  const treePath = [...parents, fileName];
24
19
  if (name)
25
20
  treePath.push(name);
26
- fixtureInfo.push({
27
- absoluteFilePath: path.join(rootDir, fixtureId.path),
21
+ result.push({
22
+ absoluteFilePath: path.join(cosmosConfig.rootDir, fixtureId.path),
28
23
  fileName,
29
- getElement: createFixtureElementGetter(fixture, fixtureId.path, decorators),
24
+ getElement: createFixtureElementGetter(fixture, fixtureId.path, decoratorExports),
30
25
  name,
31
26
  parents,
32
- playgroundUrl: getPlaygroundUrl(cosmosConfig, fixtureId),
27
+ playgroundUrl: getPlaygroundFixtureUrl(cosmosConfig, fixtureId),
33
28
  relativeFilePath: fixtureId.path,
34
- rendererUrl: rendererUrl && createRendererUrl(rendererUrl, fixtureId),
29
+ rendererUrl: options.rendererUrl
30
+ ? createRendererUrl(options.rendererUrl, fixtureId)
31
+ : null,
35
32
  treePath,
36
33
  });
37
34
  });
38
- return fixtureInfo;
35
+ return result;
39
36
  }
40
- function getPlaygroundUrl(cosmosConfig, fixtureId) {
41
- const host = getPlaygroundHost(cosmosConfig);
42
- const query = buildPlaygroundQueryString({ fixtureId });
43
- return `${host}/${query}`;
37
+ function getFlatFixtureTree(cosmosConfig, fixtures) {
38
+ const { fixturesDir, fixtureFileSuffix } = cosmosConfig;
39
+ return flattenFixtureTree(createFixtureTree({
40
+ fixtures: getFixtureListFromExports(fixtures),
41
+ fixturesDir,
42
+ fixtureFileSuffix,
43
+ }));
44
44
  }
45
- function getPlaygroundHost({ hostname, port, https }) {
46
- return `${https ? 'https' : 'http'}://${hostname || 'localhost'}:${port}`;
45
+ function getPlaygroundFixtureUrl(cosmosConfig, fixtureId) {
46
+ const baseUrl = getPlaygroundUrl(cosmosConfig);
47
+ const query = buildPlaygroundQueryString({ fixtureId });
48
+ return `${baseUrl}/${query}`;
47
49
  }
48
50
  function createFixtureElementGetter(fixture, fixturePath, decoratorsByPath) {
49
51
  const decorators = getSortedDecoratorsForFixturePath(fixturePath, decoratorsByPath);
@@ -1,8 +1,8 @@
1
- import { ByPath, ReactDecorator, ReactFixtureExport } from 'react-cosmos-core';
1
+ import { ByPath, ReactDecoratorModule, ReactFixtureModule } from 'react-cosmos-core';
2
2
  import { CosmosConfig } from '../cosmosConfig/types.js';
3
3
  type UserModules = {
4
- fixtures: ByPath<ReactFixtureExport>;
5
- decorators: ByPath<ReactDecorator>;
4
+ fixtures: ByPath<ReactFixtureModule>;
5
+ decorators: ByPath<ReactDecoratorModule>;
6
6
  };
7
7
  export declare function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): UserModules;
8
8
  export {};
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
+ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
2
3
  import { slash } from '../utils/slash.js';
3
- import { findUserModulePaths } from './findUserModulePaths.js';
4
4
  export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
5
  const { fixturePaths, decoratorPaths } = findUserModulePaths({
6
6
  rootDir,
@@ -9,18 +9,20 @@ export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ign
9
9
  ignore,
10
10
  });
11
11
  return {
12
- fixtures: getDefaultExports(fixturePaths, rootDir),
13
- decorators: getDefaultExports(decoratorPaths, rootDir),
12
+ fixtures: importModules(fixturePaths, rootDir),
13
+ decorators: importModules(decoratorPaths, rootDir),
14
14
  };
15
15
  }
16
- function getDefaultExports(paths, rootDir) {
17
- const exportsByPath = {};
18
- paths.forEach(p => {
16
+ function importModules(paths, rootDir) {
17
+ const modules = paths.map(p => {
19
18
  // Converting to forward slashes on Windows is important because the
20
19
  // slashes are used for generating a sorted list of fixtures and
21
20
  // decorators.
22
21
  const relPath = slash(path.relative(rootDir, p));
23
- exportsByPath[relPath] = require(p).default;
22
+ return { relPath, module: require(p) };
24
23
  });
25
- return exportsByPath;
24
+ return modules.reduce((acc, { relPath, module }) => ({
25
+ ...acc,
26
+ [relPath]: module,
27
+ }), {});
26
28
  }
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './shared/findNextAvailablePort.js';
10
10
  export * from './shared/playgroundUrl.js';
11
11
  export * from './shared/staticServer.js';
12
12
  export * from './testHelpers/cwd.js';
13
+ export * from './userModules/findUserModulePaths.js';
13
14
  export * from './userModules/fixtureWatcher.js';
14
15
  export * from './userModules/generateUserImports.js';
15
16
  export * from './utils/cli.js';
@@ -18,3 +19,4 @@ export * from './utils/requireSilent.js';
18
19
  export * from './utils/resolve.js';
19
20
  export * from './utils/resolveLoose.js';
20
21
  export * from './utils/resolveSilent.js';
22
+ export * from './utils/slash.js';
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export * from './shared/findNextAvailablePort.js';
10
10
  export * from './shared/playgroundUrl.js';
11
11
  export * from './shared/staticServer.js';
12
12
  export * from './testHelpers/cwd.js';
13
+ export * from './userModules/findUserModulePaths.js';
13
14
  export * from './userModules/fixtureWatcher.js';
14
15
  export * from './userModules/generateUserImports.js';
15
16
  export * from './utils/cli.js';
@@ -18,3 +19,4 @@ export * from './utils/requireSilent.js';
18
19
  export * from './utils/resolve.js';
19
20
  export * from './utils/resolveLoose.js';
20
21
  export * from './utils/resolveSilent.js';
22
+ export * from './utils/slash.js';
package/dist/jest.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  export * from './testHelpers/mockConsole.js';
2
- export * from './testHelpers/mockEsmRequire.js';
3
- export * from './testHelpers/mockEsmResolve.js';
4
- export * from './testHelpers/mockEsmStaticPath.js';
5
2
  export * from './testHelpers/mockFetch.js';
6
3
  export * from './testHelpers/mockFs.js';
7
4
  export * from './testHelpers/mockYargs.js';
package/dist/jest.js CHANGED
@@ -1,7 +1,4 @@
1
1
  export * from './testHelpers/mockConsole.js';
2
- export * from './testHelpers/mockEsmRequire.js';
3
- export * from './testHelpers/mockEsmResolve.js';
4
- export * from './testHelpers/mockEsmStaticPath.js';
5
2
  export * from './testHelpers/mockFetch.js';
6
3
  export * from './testHelpers/mockFs.js';
7
4
  export * from './testHelpers/mockYargs.js';
@@ -0,0 +1,11 @@
1
+ import { CosmosCommand } from 'react-cosmos-core';
2
+ import { CosmosConfig } from '../cosmosConfig/types.js';
3
+ import { CosmosPlatform, CosmosServerPlugin } from '../cosmosPlugin/types.js';
4
+ type Args = {
5
+ cosmosConfig: CosmosConfig;
6
+ serverPlugins: CosmosServerPlugin[];
7
+ command: CosmosCommand;
8
+ platform: CosmosPlatform;
9
+ };
10
+ export declare function applyServerConfigPlugins({ cosmosConfig, serverPlugins, command, platform, }: Args): Promise<CosmosConfig>;
11
+ export {};
@@ -0,0 +1,14 @@
1
+ export async function applyServerConfigPlugins({ cosmosConfig, serverPlugins, command, platform, }) {
2
+ for (const plugin of serverPlugins) {
3
+ if (plugin.config) {
4
+ try {
5
+ cosmosConfig = await plugin.config({ cosmosConfig, command, platform });
6
+ }
7
+ catch (err) {
8
+ console.log(`[Cosmos][plugin:${plugin.name}] Config hook failed`);
9
+ throw err;
10
+ }
11
+ }
12
+ }
13
+ return cosmosConfig;
14
+ }
@@ -0,0 +1,2 @@
1
+ import { CosmosPluginConfig } from 'react-cosmos-core';
2
+ export declare function getServerPlugins(pluginConfigs: CosmosPluginConfig[], rootDir: string): Promise<import("../index.js").CosmosServerPlugin[]>;
@@ -0,0 +1,6 @@
1
+ import { coreServerPlugins } from '../corePlugins/index.js';
2
+ import { importServerPlugins } from './importServerPlugins.js';
3
+ export async function getServerPlugins(pluginConfigs, rootDir) {
4
+ const userPlugins = await importServerPlugins(pluginConfigs, rootDir);
5
+ return [...coreServerPlugins, ...userPlugins];
6
+ }
@@ -1,10 +1,9 @@
1
1
  import fs from 'fs';
2
2
  import { readFile } from 'fs/promises';
3
3
  import path from 'path';
4
- import { pkgUpSync } from 'pkg-up';
5
4
  import { pickRendererUrl, replaceKeys, } from 'react-cosmos-core';
6
- import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
7
- import { importKeyPath } from '../userModules/shared.js';
5
+ import { findUp } from '../utils/findUp.js';
6
+ import { getServerFixtureList } from './serverFixtureList.js';
8
7
  import { getStaticPath } from './staticPath.js';
9
8
  export async function getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs) {
10
9
  const { ui } = cosmosConfig;
@@ -13,7 +12,7 @@ export async function getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs
13
12
  ...ui,
14
13
  core: await getCoreConfig(cosmosConfig, true),
15
14
  rendererCore: {
16
- fixtures: getFixtureList(cosmosConfig),
15
+ fixtures: getServerFixtureList(cosmosConfig),
17
16
  rendererUrl: platform === 'web'
18
17
  ? pickRendererUrl(cosmosConfig.rendererUrl, 'dev')
19
18
  : null,
@@ -29,7 +28,7 @@ export async function getExportPlaygroundHtml(cosmosConfig, pluginConfigs) {
29
28
  ...ui,
30
29
  core: await getCoreConfig(cosmosConfig, false),
31
30
  rendererCore: {
32
- fixtures: getFixtureList(cosmosConfig),
31
+ fixtures: getServerFixtureList(cosmosConfig),
33
32
  rendererUrl: pickRendererUrl(cosmosConfig.rendererUrl, 'export'),
34
33
  },
35
34
  },
@@ -46,7 +45,7 @@ async function getCoreConfig(cosmosConfig, devServerOn) {
46
45
  };
47
46
  }
48
47
  async function getProjectId(rootDir) {
49
- const pkgPath = pkgUpSync({ cwd: rootDir });
48
+ const pkgPath = await findUp('package.json', rootDir);
50
49
  if (!pkgPath) {
51
50
  return rootDir.split(path.sep).pop();
52
51
  }
@@ -68,10 +67,3 @@ function getPlaygroundHtml(playgroundArgs) {
68
67
  function getPlaygroundHtmlTemplate() {
69
68
  return fs.readFileSync(getStaticPath('index.html'), 'utf8');
70
69
  }
71
- function getFixtureList(cosmosConfig) {
72
- const { fixturePaths } = findUserModulePaths(cosmosConfig);
73
- return fixturePaths.reduce((acc, fixturePath) => ({
74
- ...acc,
75
- [importKeyPath(fixturePath, cosmosConfig.rootDir)]: { type: 'single' },
76
- }), {});
77
- }
@@ -0,0 +1,4 @@
1
+ import { FixtureList } from 'react-cosmos-core';
2
+ import { CosmosConfig } from '../cosmosConfig/types.js';
3
+ export declare function getServerFixtureList(cosmosConfig: CosmosConfig): FixtureList;
4
+ export declare function updateFixtureListCache(rootDir: string, fixturePaths: string[]): void;
@@ -0,0 +1,19 @@
1
+ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
2
+ import { importKeyPath } from '../userModules/shared.js';
3
+ let fixtureListCache = null;
4
+ export function getServerFixtureList(cosmosConfig) {
5
+ if (!fixtureListCache) {
6
+ const { fixturePaths } = findUserModulePaths(cosmosConfig);
7
+ fixtureListCache = createFixtureList(cosmosConfig.rootDir, fixturePaths);
8
+ }
9
+ return fixtureListCache;
10
+ }
11
+ export function updateFixtureListCache(rootDir, fixturePaths) {
12
+ fixtureListCache = createFixtureList(rootDir, fixturePaths);
13
+ }
14
+ function createFixtureList(rootDir, fixturePaths) {
15
+ return fixturePaths.reduce((acc, fixturePath) => ({
16
+ ...acc,
17
+ [importKeyPath(fixturePath, rootDir)]: { type: 'single' },
18
+ }), {});
19
+ }
Binary file
@@ -1,12 +1,9 @@
1
+ import { UserModulePaths } from './shared.js';
1
2
  type FindUserModulePathsArgs = {
2
3
  rootDir: string;
3
4
  fixturesDir: string;
4
5
  fixtureFileSuffix: string;
5
6
  ignore: string[];
6
7
  };
7
- type UserModulePaths = {
8
- fixturePaths: string[];
9
- decoratorPaths: string[];
10
- };
11
8
  export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): UserModulePaths;
12
9
  export {};
@@ -1,6 +1,6 @@
1
1
  import { globSync } from 'glob';
2
2
  import micromatch from 'micromatch';
3
- import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
3
+ import { getDecoratorPatterns, getFixturePatterns, } from './shared.js';
4
4
  export function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
5
  const paths = globSync('**/*', {
6
6
  cwd: rootDir,
@@ -1,10 +1,12 @@
1
1
  import { RendererConfig } from 'react-cosmos-core';
2
2
  import { CosmosConfig } from '../cosmosConfig/types.js';
3
+ import { UserModulePaths } from './shared.js';
3
4
  type Args<T extends RendererConfig> = {
4
5
  cosmosConfig: CosmosConfig;
6
+ modulePaths: UserModulePaths;
5
7
  rendererConfig: T;
6
8
  relativeToDir: string | null;
7
9
  typeScript: boolean;
8
10
  };
9
- export declare function generateUserImports<T extends RendererConfig>({ cosmosConfig, rendererConfig, relativeToDir, typeScript, }: Args<T>): string;
11
+ export declare function generateUserImports<T extends RendererConfig>({ cosmosConfig, modulePaths, rendererConfig, relativeToDir, typeScript, }: Args<T>): string;
10
12
  export {};
@@ -1,23 +1,15 @@
1
- import { findUserModulePaths } from './findUserModulePaths.js';
2
1
  import { userImportsLazyTemplate } from './userImportsLazyTemplate.js';
3
2
  import { userImportsTemplate } from './userImportsTemplate.js';
4
- export function generateUserImports({ cosmosConfig, rendererConfig, relativeToDir, typeScript, }) {
5
- const { rootDir, fixturesDir, fixtureFileSuffix, globalImports, ignore } = cosmosConfig;
6
- const { fixturePaths, decoratorPaths } = findUserModulePaths({
7
- rootDir,
8
- fixturesDir,
9
- fixtureFileSuffix,
10
- ignore,
11
- });
3
+ export function generateUserImports({ cosmosConfig, modulePaths, rendererConfig, relativeToDir, typeScript, }) {
4
+ const { rootDir, globalImports } = cosmosConfig;
12
5
  const template = cosmosConfig.lazy
13
6
  ? userImportsLazyTemplate
14
7
  : userImportsTemplate;
15
8
  return template({
9
+ rootDir,
10
+ modulePaths,
16
11
  globalImports,
17
- fixturePaths,
18
- decoratorPaths,
19
12
  rendererConfig,
20
- rootDir,
21
13
  relativeToDir,
22
14
  typeScript,
23
15
  });
@@ -1,10 +1,13 @@
1
1
  import { RendererConfig } from 'react-cosmos-core';
2
- export type UserImportsTemplateArgs = {
3
- globalImports: string[];
2
+ export type UserModulePaths = {
4
3
  fixturePaths: string[];
5
4
  decoratorPaths: string[];
6
- rendererConfig: RendererConfig;
5
+ };
6
+ export type UserImportsTemplateArgs = {
7
7
  rootDir: string;
8
+ modulePaths: UserModulePaths;
9
+ globalImports: string[];
10
+ rendererConfig: RendererConfig;
8
11
  relativeToDir: string | null;
9
12
  typeScript: boolean;
10
13
  };
@@ -1,10 +1,10 @@
1
1
  import path from 'path';
2
2
  import { replaceKeys } from 'react-cosmos-core';
3
3
  import { slash } from '../utils/slash.js';
4
- // NODE: These can be made configurable if a proper need arises
4
+ // NOTE: These can be made configurable if a proper need arises
5
5
  const FIXTURE_PATTERNS = [
6
- '**/<fixturesDir>/**/*.{js,jsx,ts,tsx}',
7
- '**/*.<fixtureFileSuffix>.{js,jsx,ts,tsx}',
6
+ '**/<fixturesDir>/**/*.{js,jsx,ts,tsx,md,mdx}',
7
+ '**/{*.,}<fixtureFileSuffix>.{js,jsx,ts,tsx,md,mdx}',
8
8
  ];
9
9
  const DECORATOR_PATTERNS = ['**/cosmos.decorator.{js,jsx,ts,tsx}'];
10
10
  export function getFixturePatterns(fixturesDir, fixtureFileSuffix) {
@@ -1,2 +1,2 @@
1
1
  import { UserImportsTemplateArgs } from './shared.js';
2
- export declare function userImportsLazyTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, typeScript, }: UserImportsTemplateArgs): string;
2
+ export declare function userImportsLazyTemplate({ globalImports, modulePaths: { fixturePaths, decoratorPaths }, rendererConfig, rootDir, relativeToDir, typeScript, }: UserImportsTemplateArgs): string;
@@ -1,6 +1,6 @@
1
1
  import { flatten } from 'lodash-es';
2
2
  import { createImportMap, importPath, } from './shared.js';
3
- export function userImportsLazyTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, typeScript, }) {
3
+ export function userImportsLazyTemplate({ globalImports, modulePaths: { fixturePaths, decoratorPaths }, rendererConfig, rootDir, relativeToDir, typeScript, }) {
4
4
  function ext(filePath) {
5
5
  // Add compat with projects where allowImportingTsExtensions isn't enabled
6
6
  return typeScript ? filePath.replace(/\.tsx?$/, '') : filePath;
@@ -1,2 +1,2 @@
1
1
  import { UserImportsTemplateArgs } from './shared.js';
2
- export declare function userImportsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, typeScript, }: UserImportsTemplateArgs): string;
2
+ export declare function userImportsTemplate({ globalImports, modulePaths: { fixturePaths, decoratorPaths }, rendererConfig, rootDir, relativeToDir, typeScript, }: UserImportsTemplateArgs): string;
@@ -1,6 +1,6 @@
1
1
  import { flatten } from 'lodash-es';
2
2
  import { createImportMap, importPath, } from './shared.js';
3
- export function userImportsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, typeScript, }) {
3
+ export function userImportsTemplate({ globalImports, modulePaths: { fixturePaths, decoratorPaths }, rendererConfig, rootDir, relativeToDir, typeScript, }) {
4
4
  function ext(filePath) {
5
5
  // Add compat with projects where allowImportingTsExtensions isn't enabled
6
6
  return typeScript ? filePath.replace(/\.tsx?$/, '') : filePath;
@@ -0,0 +1 @@
1
+ export declare function findUp(fileName: string, fromDir: string): Promise<string | null>;
@@ -0,0 +1,19 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ // Code inspired from https://github.com/sindresorhus/find-up-simple/
4
+ export async function findUp(fileName, fromDir) {
5
+ const { root: rootDir } = path.parse(fromDir);
6
+ let currentDir = fromDir;
7
+ while (currentDir && currentDir !== rootDir) {
8
+ const filePath = path.join(currentDir, fileName);
9
+ try {
10
+ const stats = await fs.stat(filePath);
11
+ if (stats.isFile()) {
12
+ return filePath;
13
+ }
14
+ }
15
+ catch { }
16
+ currentDir = path.dirname(currentDir);
17
+ }
18
+ return null;
19
+ }
package/jest.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/jest.js');
1
+ export * from './dist/jest.js';
package/package.json CHANGED
@@ -1,32 +1,31 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.0.0-canary.fdbaa56.0+fdbaa56",
3
+ "version": "6.0.0",
4
4
  "description": "Sandbox for developing and testing UI components in isolation",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "./index.js",
9
9
  "dependencies": {
10
- "@skidding/launch-editor": "^2.2.3",
11
- "chokidar": "^3.5.3",
12
- "express": "^4.18.2",
13
- "glob": "^10.2.2",
14
- "http-proxy-middleware": "^2.0.6",
15
- "lodash-es": "^4.17.21",
16
- "micromatch": "^4.0.5",
17
- "open": "^8.4.2",
18
- "pem": "^1.14.7",
19
- "pkg-up": "^4.0.0",
20
- "react-cosmos-core": "6.0.0-canary.fdbaa56.0+fdbaa56",
21
- "react-cosmos-renderer": "6.0.0-canary.fdbaa56.0+fdbaa56",
22
- "react-cosmos-ui": "6.0.0-canary.fdbaa56.0+fdbaa56",
23
- "ws": "^8.13.0",
24
- "yargs": "^17.7.2"
10
+ "@skidding/launch-editor": "2.2.3",
11
+ "chokidar": "3.5.3",
12
+ "express": "4.18.2",
13
+ "glob": "10.3.10",
14
+ "http-proxy-middleware": "2.0.6",
15
+ "lodash-es": "4.17.21",
16
+ "micromatch": "4.0.5",
17
+ "open": "8.4.2",
18
+ "pem": "1.14.8",
19
+ "react-cosmos-core": "^6.0.0",
20
+ "react-cosmos-renderer": "^6.0.0",
21
+ "react-cosmos-ui": "^6.0.0",
22
+ "ws": "8.16.0",
23
+ "yargs": "17.7.2"
25
24
  },
26
25
  "bin": {
27
26
  "cosmos": "./bin/cosmos.js",
28
27
  "cosmos-export": "./bin/cosmos-export.js",
29
28
  "cosmos-native": "./bin/cosmos-native.js"
30
29
  },
31
- "gitHead": "fdbaa565382e2685f7ac21aecec25f2d78c7b8ab"
30
+ "gitHead": "db4fd8fd917598f1f16d4c291be76217436422ee"
32
31
  }
@@ -1,2 +0,0 @@
1
- import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
- export declare const exposeImportsServerPlugin: CosmosServerPlugin;
@@ -1,2 +0,0 @@
1
- import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
- export declare const httpProxyServerPlugin: CosmosServerPlugin;
@@ -1,2 +0,0 @@
1
- import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
- export declare const pluginEndpointServerPlugin: CosmosServerPlugin;
@@ -1,2 +0,0 @@
1
- import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
- export declare const portRetryServerPlugin: CosmosServerPlugin;
@@ -1 +0,0 @@
1
- export {};
@@ -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 {};