react-cosmos 6.0.0-beta.3 → 6.0.0-beta.5

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 (32) hide show
  1. package/dist/corePlugins/{openFile.d.ts → fixtureWatcherPlugin.d.ts} +1 -1
  2. package/dist/corePlugins/{exposeImports.js → fixtureWatcherPlugin.js} +18 -8
  3. package/dist/corePlugins/httpProxyPlugin.d.ts +2 -0
  4. package/dist/corePlugins/{httpProxy.js → httpProxyPlugin.js} +1 -1
  5. package/dist/corePlugins/index.js +13 -10
  6. package/dist/corePlugins/openFilePlugin.d.ts +2 -0
  7. package/dist/corePlugins/{openFile.js → openFilePlugin.js} +1 -1
  8. package/dist/corePlugins/pluginEndpointPlugin.d.ts +2 -0
  9. package/dist/corePlugins/{pluginEndpoint.js → pluginEndpointPlugin.js} +1 -1
  10. package/dist/corePlugins/portRetryPlugin.d.ts +2 -0
  11. package/dist/corePlugins/{portRetry.js → portRetryPlugin.js} +1 -1
  12. package/dist/devServer/expressApp.js +2 -3
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/shared/playgroundHtml.js +3 -11
  16. package/dist/shared/serverFixtureList.d.ts +4 -0
  17. package/dist/shared/serverFixtureList.js +19 -0
  18. package/dist/userModules/findUserModulePaths.d.ts +1 -4
  19. package/dist/userModules/findUserModulePaths.js +1 -1
  20. package/dist/userModules/generateUserImports.d.ts +3 -1
  21. package/dist/userModules/generateUserImports.js +4 -12
  22. package/dist/userModules/shared.d.ts +6 -3
  23. package/dist/userModules/shared.js +2 -2
  24. package/dist/userModules/userImportsLazyTemplate.d.ts +1 -1
  25. package/dist/userModules/userImportsLazyTemplate.js +1 -1
  26. package/dist/userModules/userImportsTemplate.d.ts +1 -1
  27. package/dist/userModules/userImportsTemplate.js +1 -1
  28. package/package.json +5 -5
  29. package/dist/corePlugins/exposeImports.d.ts +0 -2
  30. package/dist/corePlugins/httpProxy.d.ts +0 -2
  31. package/dist/corePlugins/pluginEndpoint.d.ts +0 -2
  32. package/dist/corePlugins/portRetry.d.ts +0 -2
@@ -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,17 +2,25 @@ 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
25
  return () => {
18
26
  watcher.close();
@@ -20,14 +28,15 @@ export const exposeImportsServerPlugin = {
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'));
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';
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';
@@ -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
+ }
@@ -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
  };
@@ -3,8 +3,8 @@ import { replaceKeys } from 'react-cosmos-core';
3
3
  import { slash } from '../utils/slash.js';
4
4
  // NODE: 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.0.0-beta.3",
3
+ "version": "6.0.0-beta.5",
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",
@@ -17,9 +17,9 @@
17
17
  "open": "^8.4.2",
18
18
  "pem": "^1.14.7",
19
19
  "pkg-up": "^4.0.0",
20
- "react-cosmos-core": "6.0.0-beta.3",
21
- "react-cosmos-renderer": "6.0.0-beta.3",
22
- "react-cosmos-ui": "6.0.0-beta.3",
20
+ "react-cosmos-core": "6.0.0-beta.5",
21
+ "react-cosmos-renderer": "6.0.0-beta.5",
22
+ "react-cosmos-ui": "6.0.0-beta.5",
23
23
  "ws": "^8.13.0",
24
24
  "yargs": "^17.7.2"
25
25
  },
@@ -28,5 +28,5 @@
28
28
  "cosmos-export": "./bin/cosmos-export.js",
29
29
  "cosmos-native": "./bin/cosmos-native.js"
30
30
  },
31
- "gitHead": "7f33cc2b818523978ef6c7fe574bf1fd8d15b50a"
31
+ "gitHead": "43919661a2ceb070ebc958bb7f6e52d5422ddc65"
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;