react-cosmos 6.1.1 → 6.1.2-canary.4cc91ba.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.
@@ -0,0 +1,11 @@
1
+ import { CosmosServerPlugin } from '../cosmosPlugin/types.js';
2
+ export type CosmosFixtureJson = {
3
+ filePath: string;
4
+ cleanPath: string[];
5
+ rendererUrl: string;
6
+ };
7
+ export type CosmosFixturesJson = {
8
+ rendererUrl: string | null;
9
+ fixtures: CosmosFixtureJson[];
10
+ };
11
+ export declare const fixturesJsonPlugin: CosmosServerPlugin;
@@ -0,0 +1,48 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { createRendererUrl, pickRendererUrl, removeFixtureNameExtension, removeFixtureNameSuffix, } from 'react-cosmos-core';
4
+ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
5
+ import { importKeyPath } from '../userModules/shared.js';
6
+ export const fixturesJsonPlugin = {
7
+ name: 'fixturesJson',
8
+ devServer({ cosmosConfig, expressApp }) {
9
+ expressApp.get('/cosmos.fixtures.json', (req, res) => {
10
+ res.json(createFixtureItems(cosmosConfig, 'dev'));
11
+ });
12
+ },
13
+ async export({ cosmosConfig }) {
14
+ const { exportPath } = cosmosConfig;
15
+ const json = createFixtureItems(cosmosConfig, 'export');
16
+ await fs.writeFile(path.join(exportPath, 'cosmos.fixtures.json'), JSON.stringify(json, null, 2));
17
+ },
18
+ };
19
+ function createFixtureItems(cosmosConfig, command) {
20
+ const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, command);
21
+ if (!rendererUrl) {
22
+ return {
23
+ rendererUrl: null,
24
+ fixtures: [],
25
+ };
26
+ }
27
+ const { fixturesDir, fixtureFileSuffix } = cosmosConfig;
28
+ const { fixturePaths } = findUserModulePaths(cosmosConfig);
29
+ return {
30
+ rendererUrl,
31
+ fixtures: fixturePaths.map(filePath => {
32
+ const relPath = importKeyPath(filePath, cosmosConfig.rootDir);
33
+ const fixtureId = { path: relPath };
34
+ return {
35
+ filePath: relPath,
36
+ cleanPath: cleanFixturePath(relPath, fixturesDir, fixtureFileSuffix),
37
+ rendererUrl: createRendererUrl(rendererUrl, fixtureId, true),
38
+ };
39
+ }),
40
+ };
41
+ }
42
+ function cleanFixturePath(filePath, fixturesDir, fixtureSuffix) {
43
+ const paths = filePath.split('/').filter(p => p !== fixturesDir);
44
+ return [
45
+ ...paths.slice(0, -1),
46
+ removeFixtureNameSuffix(removeFixtureNameExtension(paths[paths.length - 1]), fixtureSuffix),
47
+ ];
48
+ }
@@ -1,10 +1,12 @@
1
1
  import { fixtureWatcherPlugin } from './fixtureWatcherPlugin.js';
2
+ import { fixturesJsonPlugin } from './fixturesJsonPlugin.js';
2
3
  import { httpProxyPlugin } from './httpProxyPlugin.js';
3
4
  import { openFilePlugin } from './openFilePlugin.js';
4
5
  import { pluginEndpointPlugin } from './pluginEndpointPlugin.js';
5
6
  import { portRetryPlugin } from './portRetryPlugin.js';
6
7
  export const coreServerPlugins = [
7
8
  portRetryPlugin,
9
+ fixturesJsonPlugin,
8
10
  httpProxyPlugin,
9
11
  openFilePlugin,
10
12
  pluginEndpointPlugin,
@@ -1,3 +1,4 @@
1
+ import { CosmosRendererUrl } from 'react-cosmos-core';
1
2
  interface HttpsOptions {
2
3
  keyPath: string;
3
4
  certPath: string;
@@ -23,10 +24,7 @@ export type CosmosConfig = {
23
24
  portRetries: number;
24
25
  plugins: string[];
25
26
  publicUrl: string;
26
- rendererUrl: null | string | {
27
- dev: string;
28
- export: string;
29
- };
27
+ rendererUrl: CosmosRendererUrl;
30
28
  rootDir: string;
31
29
  staticPath: null | string;
32
30
  watchDirs: string[];
@@ -1,6 +1,5 @@
1
- import path from 'path';
2
1
  import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
3
- import { slash } from '../utils/slash.js';
2
+ import { importKeyPath } from '../userModules/shared.js';
4
3
  export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
5
4
  const { fixturePaths, decoratorPaths } = findUserModulePaths({
6
5
  rootDir,
@@ -15,10 +14,7 @@ export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ign
15
14
  }
16
15
  function importModules(paths, rootDir) {
17
16
  const modules = paths.map(p => {
18
- // Converting to forward slashes on Windows is important because the
19
- // slashes are used for generating a sorted list of fixtures and
20
- // decorators.
21
- const relPath = slash(path.relative(rootDir, p));
17
+ const relPath = importKeyPath(p, rootDir);
22
18
  return { relPath, module: require(p) };
23
19
  });
24
20
  return modules.reduce((acc, { relPath, module }) => ({
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { CosmosFixtureJson, CosmosFixturesJson, } from './corePlugins/fixturesJsonPlugin.js';
1
2
  export * from './cosmosConfig/createCosmosConfig.js';
2
3
  export * from './cosmosConfig/detectCosmosConfig.js';
3
4
  export * from './cosmosConfig/getCosmosConfigAtPath.js';
@@ -23,6 +23,9 @@ export function createImportMap(paths, rootDir, relativeToDir) {
23
23
  }), {});
24
24
  }
25
25
  export function importKeyPath(filePath, rootDir) {
26
+ // Converting to forward slashes on Windows is important because the
27
+ // slashes are used for generating a sorted list of fixtures and
28
+ // decorators.
26
29
  return slash(path.relative(rootDir, filePath));
27
30
  }
28
31
  export function importPath(filePath, relativeToDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.1.1",
3
+ "version": "6.1.2-canary.4cc91ba.0+4cc91ba",
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",
@@ -16,9 +16,9 @@
16
16
  "micromatch": "4.0.5",
17
17
  "open": "8.4.2",
18
18
  "pem": "1.14.8",
19
- "react-cosmos-core": "^6.1.1",
20
- "react-cosmos-renderer": "^6.1.1",
21
- "react-cosmos-ui": "^6.1.1",
19
+ "react-cosmos-core": "6.1.2-canary.4cc91ba.0+4cc91ba",
20
+ "react-cosmos-renderer": "6.1.2-canary.4cc91ba.0+4cc91ba",
21
+ "react-cosmos-ui": "6.1.2-canary.4cc91ba.0+4cc91ba",
22
22
  "ws": "8.16.0",
23
23
  "yargs": "17.7.2"
24
24
  },
@@ -27,5 +27,5 @@
27
27
  "cosmos-export": "./bin/cosmos-export.js",
28
28
  "cosmos-native": "./bin/cosmos-native.js"
29
29
  },
30
- "gitHead": "f83799a26584a3f34914ce4ebf5c427df1df3c25"
30
+ "gitHead": "4cc91ba199e81a366a8bf8100c26a60d630f2a4e"
31
31
  }