react-cosmos 6.0.0-alpha.13 → 6.0.0-alpha.15

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.
@@ -156,17 +156,36 @@
156
156
  }
157
157
  }
158
158
  },
159
+ "vite": {
160
+ "description": "Vite-related options",
161
+ "type": "object",
162
+ "additionalProperties": false,
163
+ "properties": {
164
+ "configPath": {
165
+ "description": "Path to Vite config. Set to false to disable reading it from the default path. [default: \"vite.config.js\"]",
166
+ "anyOf": [{ "type": "string", "minLength": 1 }, { "enum": [false] }]
167
+ },
168
+ "indexPath": {
169
+ "description": "Path to index module (eg. \"src/my-index.tsx\"). [default: matches common index/main module paths]",
170
+ "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
171
+ },
172
+ "port": {
173
+ "description": "Vite renderer port. [default: 5050]",
174
+ "type": "number"
175
+ }
176
+ }
177
+ },
159
178
  "webpack": {
160
179
  "description": "Webpack-related options",
161
180
  "type": "object",
162
181
  "additionalProperties": false,
163
182
  "properties": {
164
183
  "configPath": {
165
- "description": "Path to an existing webpack config, which Cosmos will reuse to build your code. Set to null to disable this behavior. [default \"webpack.config.js\"]",
184
+ "description": "Path to an existing webpack config, which Cosmos will reuse to build your code. Set to null to disable this behavior. [default: \"webpack.config.js\"]",
166
185
  "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
167
186
  },
168
187
  "overridePath": {
169
- "description": "Path to a user module that customizes the webpack config used by Cosmos. Set to null to disable this behavior. [default \"webpack.override.js\"]",
188
+ "description": "Path to a user module that customizes the webpack config used by Cosmos. Set to null to disable this behavior. [default: \"webpack.override.js\"]",
170
189
  "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
171
190
  },
172
191
  "includeHashInOutputFilename": {
@@ -35,6 +35,9 @@ export async function startDevServer(platformType) {
35
35
  const app = await createExpressApp(platformType, cosmosConfig, pluginConfigs);
36
36
  const httpServer = await createHttpServer(cosmosConfig, app);
37
37
  const msgHandler = createMessageHandler(httpServer.server);
38
+ if (cosmosConfig.staticPath) {
39
+ serveStaticDir(app, cosmosConfig.staticPath, cosmosConfig.publicUrl);
40
+ }
38
41
  // Make Playground available as soon as possible and show a loading screen
39
42
  // while plugins are initializing
40
43
  await httpServer.start();
@@ -77,9 +80,6 @@ export async function startDevServer(platformType) {
77
80
  throw err;
78
81
  }
79
82
  }
80
- if (cosmosConfig.staticPath) {
81
- serveStaticDir(app, cosmosConfig.staticPath, cosmosConfig.publicUrl);
82
- }
83
83
  return cleanUp;
84
84
  }
85
85
  function logCosmosConfigInfo() {
@@ -2,7 +2,9 @@ import fs from 'fs';
2
2
  import { readFile } from 'fs/promises';
3
3
  import path from 'path';
4
4
  import { pkgUpSync } from 'pkg-up';
5
- import { replaceKeys } from 'react-cosmos-core';
5
+ import { replaceKeys, } from 'react-cosmos-core';
6
+ import { findUserModulePaths } from '../userDeps/findUserModulePaths.js';
7
+ import { userDepsKeyPath } from '../userDeps/userDepsShared.js';
6
8
  import { resolveRendererUrl } from './resolveRendererUrl.js';
7
9
  import { getStaticPath } from './staticPath.js';
8
10
  export const RENDERER_FILENAME = '_renderer.html';
@@ -12,6 +14,7 @@ export async function getDevPlaygroundHtml(platformType, cosmosConfig, pluginCon
12
14
  playgroundConfig: {
13
15
  ...ui,
14
16
  core: await getDevCoreConfig(platformType, cosmosConfig),
17
+ rendererCore: { fixtures: getFixtureList(cosmosConfig) },
15
18
  },
16
19
  pluginConfigs,
17
20
  });
@@ -22,6 +25,7 @@ export async function getExportPlaygroundHtml(cosmosConfig, pluginConfigs) {
22
25
  playgroundConfig: {
23
26
  ...ui,
24
27
  core: await getExportCoreConfig(cosmosConfig),
28
+ rendererCore: { fixtures: getFixtureList(cosmosConfig) },
25
29
  },
26
30
  pluginConfigs,
27
31
  });
@@ -83,3 +87,10 @@ function getPlaygroundHtml(playgroundArgs) {
83
87
  function getPlaygroundHtmlTemplate() {
84
88
  return fs.readFileSync(getStaticPath('index.html'), 'utf8');
85
89
  }
90
+ function getFixtureList(cosmosConfig) {
91
+ const { fixturePaths } = findUserModulePaths(cosmosConfig);
92
+ return fixturePaths.reduce((acc, fixturePath) => ({
93
+ ...acc,
94
+ [userDepsKeyPath(fixturePath, cosmosConfig.rootDir)]: { type: 'single' },
95
+ }), {});
96
+ }
@@ -8,4 +8,5 @@ export type UserDepsTemplateArgs = {
8
8
  relativeToDir: string | null;
9
9
  };
10
10
  export declare function userDepsImportMap(paths: string[], rootDir: string, relativeToDir: string | null): Record<string, string>;
11
+ export declare function userDepsKeyPath(filePath: string, rootDir: string): string;
11
12
  export declare function userDepsImportPath(filePath: string, relativeToDir: string | null): string;
@@ -3,9 +3,12 @@ import { slash } from '../utils/slash.js';
3
3
  export function userDepsImportMap(paths, rootDir, relativeToDir) {
4
4
  return paths.reduce((acc, p) => ({
5
5
  ...acc,
6
- [slash(path.relative(rootDir, p))]: userDepsImportPath(p, relativeToDir),
6
+ [userDepsKeyPath(p, rootDir)]: userDepsImportPath(p, relativeToDir),
7
7
  }), {});
8
8
  }
9
+ export function userDepsKeyPath(filePath, rootDir) {
10
+ return slash(path.relative(rootDir, filePath));
11
+ }
9
12
  export function userDepsImportPath(filePath, relativeToDir) {
10
13
  return slash(relativeToDir
11
14
  ? `.${path.sep}${path.relative(relativeToDir, filePath)}`
@@ -1,5 +1,5 @@
1
1
  export declare function importModule<T>(filePath: string): Promise<T>;
2
2
  export declare function importJson<T>(filePath: string): Promise<T>;
3
- export declare function moduleExists(moduleId: string): boolean | "";
3
+ export declare function moduleExists(moduleId: string): boolean;
4
4
  export declare function fileExists(filePath: string): boolean;
5
5
  export declare function dirExists(dirPath: string): boolean;
package/dist/utils/fs.js CHANGED
@@ -13,7 +13,8 @@ export async function importJson(filePath) {
13
13
  // Better than fs.exists because it works for module paths without an extension
14
14
  export function moduleExists(moduleId) {
15
15
  try {
16
- return resolve(moduleId) && true;
16
+ resolve(moduleId);
17
+ return true;
17
18
  }
18
19
  catch (err) {
19
20
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.0.0-alpha.13",
3
+ "version": "6.0.0-alpha.15",
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,8 +17,8 @@
17
17
  "open": "^8.4.2",
18
18
  "pem": "^1.14.6",
19
19
  "pkg-up": "^4.0.0",
20
- "react-cosmos-core": "6.0.0-alpha.13",
21
- "react-cosmos-ui": "6.0.0-alpha.13",
20
+ "react-cosmos-core": "6.0.0-alpha.14",
21
+ "react-cosmos-ui": "6.0.0-alpha.15",
22
22
  "ws": "^8.12.1",
23
23
  "yargs": "^17.7.1"
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": "cf95e67ce942f6a242f023ecebe45d6916d5b753"
30
+ "gitHead": "1de8663ae24b3e8c6b24590583718222d31b24c8"
31
31
  }