react-cosmos 6.0.0-beta.1 → 6.0.0-beta.11

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 (39) hide show
  1. package/README.md +37 -3
  2. package/config.schema.json +10 -10
  3. package/dist/client.d.ts +1 -1
  4. package/dist/client.js +1 -1
  5. package/dist/corePlugins/{openFile.d.ts → fixtureWatcherPlugin.d.ts} +1 -1
  6. package/dist/corePlugins/{exposeImports.js → fixtureWatcherPlugin.js} +20 -10
  7. package/dist/corePlugins/httpProxyPlugin.d.ts +2 -0
  8. package/dist/corePlugins/{httpProxy.js → httpProxyPlugin.js} +1 -1
  9. package/dist/corePlugins/index.js +13 -10
  10. package/dist/corePlugins/openFilePlugin.d.ts +2 -0
  11. package/dist/corePlugins/{openFile.js → openFilePlugin.js} +1 -1
  12. package/dist/corePlugins/pluginEndpointPlugin.d.ts +2 -0
  13. package/dist/corePlugins/{pluginEndpoint.js → pluginEndpointPlugin.js} +1 -1
  14. package/dist/corePlugins/portRetryPlugin.d.ts +2 -0
  15. package/dist/corePlugins/{portRetry.js → portRetryPlugin.js} +1 -1
  16. package/dist/devServer/expressApp.js +2 -3
  17. package/dist/devServer/startDevServer.js +2 -2
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +2 -0
  20. package/dist/shared/playgroundHtml.js +3 -11
  21. package/dist/shared/serverFixtureList.d.ts +4 -0
  22. package/dist/shared/serverFixtureList.js +19 -0
  23. package/dist/static/favicon.ico +0 -0
  24. package/dist/userModules/findUserModulePaths.d.ts +1 -4
  25. package/dist/userModules/findUserModulePaths.js +1 -1
  26. package/dist/userModules/generateUserImports.d.ts +3 -1
  27. package/dist/userModules/generateUserImports.js +4 -12
  28. package/dist/userModules/shared.d.ts +6 -3
  29. package/dist/userModules/shared.js +3 -3
  30. package/dist/userModules/userImportsLazyTemplate.d.ts +1 -1
  31. package/dist/userModules/userImportsLazyTemplate.js +1 -1
  32. package/dist/userModules/userImportsTemplate.d.ts +1 -1
  33. package/dist/userModules/userImportsTemplate.js +1 -1
  34. package/jest.js +1 -1
  35. package/package.json +17 -17
  36. package/dist/corePlugins/exposeImports.d.ts +0 -2
  37. package/dist/corePlugins/httpProxy.d.ts +0 -2
  38. package/dist/corePlugins/pluginEndpoint.d.ts +0 -2
  39. package/dist/corePlugins/portRetry.d.ts +0 -2
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": {
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;
@@ -2,32 +2,41 @@ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { pickRendererUrl, } from 'react-cosmos-core';
4
4
  import { getPlaygroundUrl } from '../shared/playgroundUrl.js';
5
+ import { updateFixtureListCache } from '../shared/serverFixtureList.js';
6
+ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
5
7
  import { startFixtureWatcher } from '../userModules/fixtureWatcher.js';
6
8
  import { generateUserImports } from '../userModules/generateUserImports.js';
7
9
  import { moduleExists } from '../utils/fs.js';
8
- export const exposeImportsServerPlugin = {
9
- name: 'exposeImports',
10
+ export const fixtureWatcherPlugin = {
11
+ name: 'fixtureWatcher',
10
12
  async devServer({ cosmosConfig, platform }) {
11
- if (!shouldExposeImports(platform, cosmosConfig))
12
- return;
13
- await generateImportsFile(cosmosConfig, 'dev');
13
+ const exposeImports = shouldExposeImports(platform, cosmosConfig);
14
+ if (exposeImports) {
15
+ const modulePaths = findUserModulePaths(cosmosConfig);
16
+ await generateImportsFile(cosmosConfig, 'dev', modulePaths);
17
+ }
14
18
  const watcher = await startFixtureWatcher(cosmosConfig, 'all', () => {
15
- generateImportsFile(cosmosConfig, 'dev');
19
+ const modulePaths = findUserModulePaths(cosmosConfig);
20
+ updateFixtureListCache(cosmosConfig.rootDir, modulePaths.fixturePaths);
21
+ if (exposeImports) {
22
+ generateImportsFile(cosmosConfig, 'dev', modulePaths);
23
+ }
16
24
  });
17
- return () => {
18
- watcher.close();
25
+ return async () => {
26
+ await watcher.close();
19
27
  };
20
28
  },
21
29
  async export({ cosmosConfig }) {
22
30
  if (shouldExposeImports('web', cosmosConfig)) {
23
- await generateImportsFile(cosmosConfig, 'export');
31
+ const modulePaths = findUserModulePaths(cosmosConfig);
32
+ await generateImportsFile(cosmosConfig, 'export', modulePaths);
24
33
  }
25
34
  },
26
35
  };
27
36
  function shouldExposeImports(platform, cosmosConfig) {
28
37
  return platform === 'native' || Boolean(cosmosConfig.exposeImports);
29
38
  }
30
- async function generateImportsFile(cosmosConfig, command) {
39
+ async function generateImportsFile(cosmosConfig, command, modulePaths) {
31
40
  const { exposeImports } = cosmosConfig;
32
41
  const filePath = typeof exposeImports === 'string'
33
42
  ? exposeImports
@@ -39,6 +48,7 @@ async function generateImportsFile(cosmosConfig, command) {
39
48
  };
40
49
  const fileSource = generateUserImports({
41
50
  cosmosConfig,
51
+ modulePaths,
42
52
  rendererConfig,
43
53
  relativeToDir: path.dirname(filePath),
44
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'));
@@ -53,9 +53,9 @@ export async function startDevServer(platform) {
53
53
  sendMessage: msgHandler.sendMessage,
54
54
  });
55
55
  if (typeof pluginReturn === 'function') {
56
- pluginCleanupCallbacks.push(() => {
56
+ pluginCleanupCallbacks.push(async () => {
57
57
  try {
58
- pluginReturn();
58
+ await pluginReturn();
59
59
  }
60
60
  catch (err) {
61
61
  // Log when a plugin fails to clean up, but continue to attempt
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';
@@ -3,8 +3,7 @@ import { readFile } from 'fs/promises';
3
3
  import path from 'path';
4
4
  import { pkgUpSync } from 'pkg-up';
5
5
  import { pickRendererUrl, replaceKeys, } from 'react-cosmos-core';
6
- import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
7
- import { importKeyPath } from '../userModules/shared.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
  },
@@ -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;
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,32 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.0.0-beta.1",
3
+ "version": "6.0.0-beta.11",
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-beta.1",
21
- "react-cosmos-renderer": "6.0.0-beta.1",
22
- "react-cosmos-ui": "6.0.0-beta.1",
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
+ "pkg-up": "4.0.0",
20
+ "react-cosmos-core": "6.0.0-beta.11",
21
+ "react-cosmos-renderer": "6.0.0-beta.11",
22
+ "react-cosmos-ui": "6.0.0-beta.11",
23
+ "ws": "8.14.2",
24
+ "yargs": "17.7.2"
25
25
  },
26
26
  "bin": {
27
27
  "cosmos": "./bin/cosmos.js",
28
28
  "cosmos-export": "./bin/cosmos-export.js",
29
29
  "cosmos-native": "./bin/cosmos-native.js"
30
30
  },
31
- "gitHead": "960ef665baa732f71ac8dd6cf19e4500d9cff8b8"
31
+ "gitHead": "53cb725c41af2e513a6f76eac2b0a4027d2afaea"
32
32
  }
@@ -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;