react-cosmos 6.0.0-alpha.19 → 6.0.0-alpha.21

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.
package/bin/cosmos.js CHANGED
@@ -5,10 +5,6 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
5
5
 
6
6
  const { startDevServer } = await import('../dist/devServer/startDevServer.js');
7
7
 
8
- // Auto disable Fast Refresh in CRA 4 until integration is implemented
9
- // https://github.com/react-cosmos/react-cosmos/issues/1272
10
- process.env.FAST_REFRESH = process.env.FAST_REFRESH || false;
11
-
12
8
  startDevServer('web').catch(err => {
13
9
  console.log('[Cosmos] Server crashed...');
14
10
  console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
@@ -1,7 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/draft-04/schema",
3
- "title": "JSON schema for React Cosmos configs",
4
- "type": "object",
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
5
3
  "additionalProperties": false,
6
4
  "properties": {
7
5
  "$schema": {
@@ -22,7 +20,7 @@
22
20
  "type": "boolean"
23
21
  },
24
22
  "disablePlugins": {
25
- "description": "Disable all plugins 3rd party plugins",
23
+ "description": "Disable plugins",
26
24
  "type": "boolean"
27
25
  },
28
26
  "staticPath": {
@@ -37,7 +35,7 @@
37
35
  "uniqueItems": true
38
36
  },
39
37
  "publicUrl": {
40
- "description": "Base URL for static assets. [default: \"/\"]",
38
+ "description": "Base URL for static assets. [default: \"\"]",
41
39
  "type": "string"
42
40
  },
43
41
  "fixturesDir": {
@@ -142,7 +140,19 @@
142
140
  },
143
141
  "rendererUrl": {
144
142
  "description": "Required when renderer doesn't run on the same port (or host) as the Playground. Useful for integrations with build tools. [default: null]",
145
- "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
143
+ "anyOf": [
144
+ { "type": "string", "minLength": 1 },
145
+ {
146
+ "type": "object",
147
+ "additionalProperties": false,
148
+ "required": ["dev", "export"],
149
+ "properties": {
150
+ "dev": { "type": "string", "minLength": 1 },
151
+ "export": { "type": "string", "minLength": 1 }
152
+ }
153
+ },
154
+ { "type": "null" }
155
+ ]
146
156
  },
147
157
  "dom": {
148
158
  "description": "DOM-related options",
@@ -228,5 +238,7 @@
228
238
  }
229
239
  }
230
240
  }
231
- }
241
+ },
242
+ "title": "JSON schema for React Cosmos configs",
243
+ "type": "object"
232
244
  }
@@ -1,27 +1,33 @@
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';
4
5
  import { startFixtureWatcher } from '../userModules/fixtureWatcher.js';
5
6
  import { generateUserImports } from '../userModules/generateUserImports.js';
6
7
  import { moduleExists } from '../utils/fs.js';
7
8
  export const exposeImportsServerPlugin = {
8
9
  name: 'exposeImports',
9
- async devServer({ cosmosConfig, platformType }) {
10
- if (!shouldExposeImports(platformType, cosmosConfig))
10
+ async devServer({ cosmosConfig, platform }) {
11
+ if (!shouldExposeImports(platform, cosmosConfig))
11
12
  return;
12
- await generateImportsFile(cosmosConfig);
13
+ await generateImportsFile(cosmosConfig, 'dev');
13
14
  const watcher = await startFixtureWatcher(cosmosConfig, 'all', () => {
14
- generateImportsFile(cosmosConfig);
15
+ generateImportsFile(cosmosConfig, 'dev');
15
16
  });
16
17
  return () => {
17
18
  watcher.close();
18
19
  };
19
20
  },
21
+ async export({ cosmosConfig }) {
22
+ if (shouldExposeImports('web', cosmosConfig)) {
23
+ await generateImportsFile(cosmosConfig, 'export');
24
+ }
25
+ },
20
26
  };
21
- function shouldExposeImports(platformType, cosmosConfig) {
22
- return platformType === 'native' || Boolean(cosmosConfig.exposeImports);
27
+ function shouldExposeImports(platform, cosmosConfig) {
28
+ return platform === 'native' || Boolean(cosmosConfig.exposeImports);
23
29
  }
24
- async function generateImportsFile(cosmosConfig) {
30
+ async function generateImportsFile(cosmosConfig, command) {
25
31
  const { exposeImports } = cosmosConfig;
26
32
  const filePath = typeof exposeImports === 'string'
27
33
  ? exposeImports
@@ -29,6 +35,7 @@ async function generateImportsFile(cosmosConfig) {
29
35
  const typeScript = /\.tsx?$/.test(filePath);
30
36
  const rendererConfig = {
31
37
  playgroundUrl: getPlaygroundUrl(cosmosConfig),
38
+ rendererUrl: pickRendererUrl(cosmosConfig.rendererUrl, command),
32
39
  };
33
40
  const fileSource = generateUserImports({
34
41
  cosmosConfig,
@@ -42,5 +49,5 @@ async function generateImportsFile(cosmosConfig) {
42
49
  }
43
50
  function getDefaultFilePath(rootDir) {
44
51
  const ext = moduleExists('typescript') ? 'ts' : 'js';
45
- return path.resolve(rootDir, `cosmos.imports.${ext}`);
52
+ return path.join(rootDir, `cosmos.imports.${ext}`);
46
53
  }
@@ -1,8 +1,8 @@
1
1
  import { createProxyMiddleware } from 'http-proxy-middleware';
2
2
  export const httpProxyServerPlugin = {
3
3
  name: 'httpProxy',
4
- devServer({ platformType, cosmosConfig, expressApp }) {
5
- if (platformType !== 'web')
4
+ devServer({ cosmosConfig, platform, expressApp }) {
5
+ if (platform !== 'web')
6
6
  return;
7
7
  const httpProxyConfig = getHttpProxyCosmosConfig(cosmosConfig);
8
8
  Object.keys(httpProxyConfig).forEach(context => {
@@ -1,7 +1,10 @@
1
1
  import { findNextAvailablePort } from '../shared/findNextAvailablePort.js';
2
2
  export const portRetryServerPlugin = {
3
3
  name: 'portRetry',
4
- async config({ cosmosConfig }) {
4
+ async config({ cosmosConfig, command }) {
5
+ if (command === 'export') {
6
+ return cosmosConfig;
7
+ }
5
8
  const { port, portRetries } = cosmosConfig;
6
9
  return {
7
10
  ...cosmosConfig,
@@ -20,7 +20,7 @@ export function createCosmosConfig(rootDir, cosmosConfigInput = {}) {
20
20
  plugins: getPlugins(cosmosConfigInput, rootDir),
21
21
  port: getPort(cosmosConfigInput),
22
22
  portRetries: getPortRetries(cosmosConfigInput),
23
- publicUrl: getPublicUrl(cosmosConfigInput),
23
+ publicUrl: cosmosConfigInput.publicUrl ?? '',
24
24
  rendererUrl: cosmosConfigInput.rendererUrl ?? null,
25
25
  staticPath: getStaticPath(cosmosConfigInput, rootDir),
26
26
  watchDirs: getWatchDirs(cosmosConfigInput, rootDir),
@@ -53,9 +53,6 @@ function getHttpsOptions(cosmosConfigInput, rootDir) {
53
53
  function getIgnore({ ignore = [] }) {
54
54
  return ['**/node_modules/**', ...ignore];
55
55
  }
56
- function getPublicUrl({ publicUrl = '/' }) {
57
- return publicUrl;
58
- }
59
56
  function getFixturesDir({ fixturesDir = '__fixtures__' }) {
60
57
  return fixturesDir;
61
58
  }
@@ -23,7 +23,10 @@ export type CosmosConfig = {
23
23
  portRetries: number;
24
24
  plugins: string[];
25
25
  publicUrl: string;
26
- rendererUrl: string | null;
26
+ rendererUrl: null | string | {
27
+ dev: string;
28
+ export: string;
29
+ };
27
30
  rootDir: string;
28
31
  staticPath: null | string;
29
32
  watchDirs: string[];
@@ -1,17 +1,18 @@
1
1
  /// <reference types="node" />
2
2
  import express from 'express';
3
3
  import http from 'http';
4
- import { MessageType } from 'react-cosmos-core';
4
+ import { CosmosCommand, MessageType } from 'react-cosmos-core';
5
5
  import { CosmosConfig } from '../cosmosConfig/types.js';
6
- export type PlatformType = 'web' | 'native';
6
+ export type CosmosPlatform = 'web' | 'native';
7
7
  export type CosmosConfigPluginArgs = {
8
8
  cosmosConfig: CosmosConfig;
9
- platformType: PlatformType;
9
+ command: CosmosCommand;
10
+ platform: CosmosPlatform;
10
11
  };
11
12
  export type CosmosConfigPlugin = (args: CosmosConfigPluginArgs) => Promise<CosmosConfig> | CosmosConfig;
12
13
  export type DevServerPluginArgs = {
13
14
  cosmosConfig: CosmosConfig;
14
- platformType: PlatformType;
15
+ platform: CosmosPlatform;
15
16
  httpServer: http.Server;
16
17
  expressApp: express.Express;
17
18
  sendMessage(msg: MessageType): unknown;
@@ -1,5 +1,5 @@
1
1
  import express from 'express';
2
2
  import { CosmosPluginConfig } from 'react-cosmos-core';
3
3
  import { CosmosConfig } from '../cosmosConfig/types.js';
4
- import { PlatformType } from '../cosmosPlugin/types.js';
5
- export declare function createExpressApp(platformType: PlatformType, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<express.Express>;
4
+ import { CosmosPlatform } from '../cosmosPlugin/types.js';
5
+ export declare function createExpressApp(platform: CosmosPlatform, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<express.Express>;
@@ -2,9 +2,9 @@ import express from 'express';
2
2
  import { getDevPlaygroundHtml } from '../shared/playgroundHtml.js';
3
3
  import { getStaticPath } from '../shared/staticPath.js';
4
4
  import { resolve } from '../utils/resolve.js';
5
- export async function createExpressApp(platformType, cosmosConfig, pluginConfigs) {
5
+ export async function createExpressApp(platform, cosmosConfig, pluginConfigs) {
6
6
  const app = express();
7
- const playgroundHtml = await getDevPlaygroundHtml(platformType, cosmosConfig, pluginConfigs);
7
+ const playgroundHtml = await getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs);
8
8
  app.get('/', (req, res) => {
9
9
  res.send(playgroundHtml);
10
10
  });
@@ -1,2 +1,2 @@
1
- import { PlatformType } from '../cosmosPlugin/types.js';
2
- export declare function startDevServer(platformType: PlatformType): Promise<() => Promise<void>>;
1
+ import { CosmosPlatform } from '../cosmosPlugin/types.js';
2
+ export declare function startDevServer(platform: CosmosPlatform): Promise<() => Promise<void>>;
@@ -8,7 +8,7 @@ import { serveStaticDir } from '../shared/staticServer.js';
8
8
  import { createExpressApp } from './expressApp.js';
9
9
  import { createHttpServer } from './httpServer.js';
10
10
  import { createMessageHandler } from './messageHandler.js';
11
- export async function startDevServer(platformType) {
11
+ export async function startDevServer(platform) {
12
12
  let cosmosConfig = await detectCosmosConfig();
13
13
  logCosmosConfigInfo();
14
14
  const pluginConfigs = await getPluginConfigs({
@@ -24,7 +24,11 @@ export async function startDevServer(platformType) {
24
24
  for (const plugin of plugins) {
25
25
  if (plugin.config) {
26
26
  try {
27
- cosmosConfig = await plugin.config({ cosmosConfig, platformType });
27
+ cosmosConfig = await plugin.config({
28
+ cosmosConfig,
29
+ command: 'dev',
30
+ platform,
31
+ });
28
32
  }
29
33
  catch (err) {
30
34
  console.log(`[Cosmos][plugin:${plugin.name}] Config hook failed`);
@@ -32,7 +36,7 @@ export async function startDevServer(platformType) {
32
36
  }
33
37
  }
34
38
  }
35
- const app = await createExpressApp(platformType, cosmosConfig, pluginConfigs);
39
+ const app = await createExpressApp(platform, cosmosConfig, pluginConfigs);
36
40
  const httpServer = await createHttpServer(cosmosConfig, app);
37
41
  const msgHandler = createMessageHandler(httpServer.server);
38
42
  if (cosmosConfig.staticPath) {
@@ -53,7 +57,7 @@ export async function startDevServer(platformType) {
53
57
  continue;
54
58
  const pluginReturn = await plugin.devServer({
55
59
  cosmosConfig,
56
- platformType,
60
+ platform,
57
61
  httpServer: httpServer.server,
58
62
  expressApp: app,
59
63
  sendMessage: msgHandler.sendMessage,
@@ -1,6 +1,5 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'path';
3
- import { removeLeadingSlash, } from 'react-cosmos-core';
4
3
  import { coreServerPlugins } from '../corePlugins/index.js';
5
4
  import { detectCosmosConfig } from '../cosmosConfig/detectCosmosConfig.js';
6
5
  import { getPluginConfigs } from '../cosmosPlugin/pluginConfigs.js';
@@ -10,7 +9,6 @@ import { getExportPlaygroundHtml } from '../shared/playgroundHtml.js';
10
9
  import { getStaticPath } from '../shared/staticPath.js';
11
10
  import { resolve } from '../utils/resolve.js';
12
11
  export async function generateExport() {
13
- const platformType = 'web';
14
12
  let cosmosConfig = await detectCosmosConfig();
15
13
  const pluginConfigs = await getPluginConfigs({
16
14
  cosmosConfig,
@@ -24,7 +22,11 @@ export async function generateExport() {
24
22
  for (const plugin of plugins) {
25
23
  if (plugin.config) {
26
24
  try {
27
- cosmosConfig = await plugin.config({ cosmosConfig, platformType });
25
+ cosmosConfig = await plugin.config({
26
+ cosmosConfig,
27
+ command: 'export',
28
+ platform: 'web',
29
+ });
28
30
  }
29
31
  catch (err) {
30
32
  console.log(`[Cosmos][plugin:${plugin.name}] Config hook failed`);
@@ -72,7 +74,7 @@ async function copyStaticAssets(cosmosConfig) {
72
74
  return;
73
75
  }
74
76
  const { publicUrl } = cosmosConfig;
75
- const exportStaticPath = path.resolve(exportPath, removeLeadingSlash(publicUrl));
77
+ const exportStaticPath = path.join(exportPath, publicUrl);
76
78
  fs.cp(staticPath, exportStaticPath, { recursive: true });
77
79
  }
78
80
  async function exportPlaygroundFiles(cosmosConfig, pluginConfigs) {
@@ -81,11 +83,11 @@ async function exportPlaygroundFiles(cosmosConfig, pluginConfigs) {
81
83
  // with updated paths
82
84
  const uiPlugins = pluginConfigs.filter(isUiPlugin);
83
85
  const copiedUiPlugins = await Promise.all(uiPlugins.map(p => exportUiPlugin(cosmosConfig, p)));
84
- await fs.copyFile(resolve('react-cosmos-ui/dist/playground.bundle.js'), path.resolve(exportPath, 'playground.bundle.js'));
85
- await fs.copyFile(resolve('react-cosmos-ui/dist/playground.bundle.js.map'), path.resolve(exportPath, 'playground.bundle.js.map'));
86
- await fs.copyFile(getStaticPath('favicon.ico'), path.resolve(exportPath, '_cosmos.ico'));
86
+ await fs.copyFile(resolve('react-cosmos-ui/dist/playground.bundle.js'), path.join(exportPath, 'playground.bundle.js'));
87
+ await fs.copyFile(resolve('react-cosmos-ui/dist/playground.bundle.js.map'), path.join(exportPath, 'playground.bundle.js.map'));
88
+ await fs.copyFile(getStaticPath('favicon.ico'), path.join(exportPath, '_cosmos.ico'));
87
89
  const playgroundHtml = await getExportPlaygroundHtml(cosmosConfig, copiedUiPlugins);
88
- await fs.writeFile(path.resolve(exportPath, 'index.html'), playgroundHtml);
90
+ await fs.writeFile(path.join(exportPath, 'index.html'), playgroundHtml);
89
91
  }
90
92
  async function exportUiPlugin(cosmosConfig, pluginConfig) {
91
93
  const { rootDir, exportPath } = cosmosConfig;
@@ -8,7 +8,7 @@ export type FixtureApi = {
8
8
  parents: string[];
9
9
  playgroundUrl: string;
10
10
  relativeFilePath: string;
11
- rendererUrl: string;
11
+ rendererUrl: string | null;
12
12
  treePath: string[];
13
13
  };
14
14
  export declare function getFixtures(cosmosConfig: CosmosConfig): FixtureApi[];
@@ -1,11 +1,10 @@
1
1
  import path from 'path';
2
- import { buildPlaygroundQueryString, buildRendererQueryString, createFixtureTree, flattenFixtureTree, getFixtureFromExport, getFixtureListFromExports, getSortedDecoratorsForFixturePath, } from 'react-cosmos-core';
2
+ import { buildPlaygroundQueryString, createFixtureTree, createRendererUrl, flattenFixtureTree, getFixtureFromExport, getFixtureListFromExports, getSortedDecoratorsForFixturePath, pickRendererUrl, } from 'react-cosmos-core';
3
3
  import { createFixtureNode, decorateFixture } from 'react-cosmos-renderer';
4
- import { RENDERER_FILENAME } from '../shared/playgroundHtml.js';
5
- import { resolveRendererUrl } from '../shared/resolveRendererUrl.js';
6
4
  import { importUserModules } from '../userModules/importUserModules.js';
7
5
  export function getFixtures(cosmosConfig) {
8
6
  const { fixturesDir, fixtureFileSuffix, rootDir } = cosmosConfig;
7
+ const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, 'dev');
9
8
  const fixtureInfo = [];
10
9
  const { fixtures, decorators } = importUserModules(cosmosConfig);
11
10
  const fixtureList = getFixtureListFromExports(fixtures);
@@ -32,7 +31,7 @@ export function getFixtures(cosmosConfig) {
32
31
  parents,
33
32
  playgroundUrl: getPlaygroundUrl(cosmosConfig, fixtureId),
34
33
  relativeFilePath: fixtureId.path,
35
- rendererUrl: getRendererUrl(cosmosConfig, fixtureId),
34
+ rendererUrl: rendererUrl && createRendererUrl(rendererUrl, fixtureId),
36
35
  treePath,
37
36
  });
38
37
  });
@@ -43,15 +42,6 @@ function getPlaygroundUrl(cosmosConfig, fixtureId) {
43
42
  const query = buildPlaygroundQueryString({ fixtureId });
44
43
  return `${host}/${query}`;
45
44
  }
46
- function getRendererUrl(cosmosConfig, fixtureId) {
47
- const { publicUrl, rendererUrl } = cosmosConfig;
48
- const query = buildRendererQueryString({ fixtureId });
49
- if (rendererUrl)
50
- return rendererUrl + query;
51
- const host = getPlaygroundHost(cosmosConfig);
52
- const urlPath = resolveRendererUrl(publicUrl, RENDERER_FILENAME);
53
- return new URL(urlPath + query, host).toString();
54
- }
55
45
  function getPlaygroundHost({ hostname, port, https }) {
56
46
  return `${https ? 'https' : 'http'}://${hostname || 'localhost'}:${port}`;
57
47
  }
package/dist/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from './cosmosPlugin/pluginConfigs.js';
7
7
  export * from './cosmosPlugin/types.js';
8
8
  export * from './getFixtures/getFixtures.js';
9
9
  export * from './shared/findNextAvailablePort.js';
10
- export { RENDERER_FILENAME } from './shared/playgroundHtml.js';
11
10
  export * from './shared/playgroundUrl.js';
12
11
  export * from './shared/staticServer.js';
13
12
  export * from './testHelpers/cwd.js';
package/dist/index.js CHANGED
@@ -7,7 +7,6 @@ export * from './cosmosPlugin/pluginConfigs.js';
7
7
  export * from './cosmosPlugin/types.js';
8
8
  export * from './getFixtures/getFixtures.js';
9
9
  export * from './shared/findNextAvailablePort.js';
10
- export { RENDERER_FILENAME } from './shared/playgroundHtml.js';
11
10
  export * from './shared/playgroundUrl.js';
12
11
  export * from './shared/staticServer.js';
13
12
  export * from './testHelpers/cwd.js';
@@ -1,6 +1,5 @@
1
1
  import { CosmosPluginConfig } from 'react-cosmos-core';
2
2
  import { CosmosConfig } from '../cosmosConfig/types.js';
3
- import { PlatformType } from '../cosmosPlugin/types.js';
4
- export declare const RENDERER_FILENAME = "_renderer.html";
5
- export declare function getDevPlaygroundHtml(platformType: PlatformType, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<string>;
3
+ import { CosmosPlatform } from '../cosmosPlugin/types.js';
4
+ export declare function getDevPlaygroundHtml(platform: CosmosPlatform, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<string>;
6
5
  export declare function getExportPlaygroundHtml(cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<string>;
@@ -2,13 +2,11 @@ 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 { pickRendererUrl, replaceKeys, } from 'react-cosmos-core';
6
6
  import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
7
7
  import { importKeyPath } from '../userModules/shared.js';
8
- import { resolveRendererUrl } from './resolveRendererUrl.js';
9
8
  import { getStaticPath } from './staticPath.js';
10
- export const RENDERER_FILENAME = '_renderer.html';
11
- export async function getDevPlaygroundHtml(platformType, cosmosConfig, pluginConfigs) {
9
+ export async function getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs) {
12
10
  const { ui } = cosmosConfig;
13
11
  return getPlaygroundHtml({
14
12
  playgroundConfig: {
@@ -16,7 +14,9 @@ export async function getDevPlaygroundHtml(platformType, cosmosConfig, pluginCon
16
14
  core: await getCoreConfig(cosmosConfig, true),
17
15
  rendererCore: {
18
16
  fixtures: getFixtureList(cosmosConfig),
19
- webRendererUrl: getDevServerWebRendereUrl(platformType, cosmosConfig),
17
+ rendererUrl: platform === 'web'
18
+ ? pickRendererUrl(cosmosConfig.rendererUrl, 'dev')
19
+ : null,
20
20
  },
21
21
  },
22
22
  pluginConfigs,
@@ -30,7 +30,7 @@ export async function getExportPlaygroundHtml(cosmosConfig, pluginConfigs) {
30
30
  core: await getCoreConfig(cosmosConfig, false),
31
31
  rendererCore: {
32
32
  fixtures: getFixtureList(cosmosConfig),
33
- webRendererUrl: getExportWebRendereUrl(cosmosConfig),
33
+ rendererUrl: pickRendererUrl(cosmosConfig.rendererUrl, 'export'),
34
34
  },
35
35
  },
36
36
  pluginConfigs,
@@ -45,20 +45,6 @@ async function getCoreConfig(cosmosConfig, devServerOn) {
45
45
  devServerOn,
46
46
  };
47
47
  }
48
- function getDevServerWebRendereUrl(platformType, cosmosConfig) {
49
- switch (platformType) {
50
- case 'native':
51
- return null;
52
- case 'web':
53
- return (cosmosConfig.rendererUrl ||
54
- resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME));
55
- default:
56
- throw new Error(`Invalid platform type: ${platformType}`);
57
- }
58
- }
59
- function getExportWebRendereUrl(cosmosConfig) {
60
- return resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME);
61
- }
62
48
  async function getProjectId(rootDir) {
63
49
  const pkgPath = pkgUpSync({ cwd: rootDir });
64
50
  if (!pkgPath) {
@@ -1,6 +1,5 @@
1
1
  import express from 'express';
2
2
  import path from 'path';
3
- import { removeLeadingDot } from 'react-cosmos-core';
4
3
  export function serveStaticDir(app, staticPath, publicUrl) {
5
4
  const relStaticPath = path.relative(process.cwd(), staticPath);
6
5
  console.log(`[Cosmos] Serving static files from ${relStaticPath}`);
@@ -10,3 +9,6 @@ export function serveStaticDir(app, staticPath, publicUrl) {
10
9
  index: false,
11
10
  }));
12
11
  }
12
+ function removeLeadingDot(fromPath) {
13
+ return fromPath.indexOf('.') === 0 ? fromPath.slice(1) : fromPath;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "6.0.0-alpha.19",
3
+ "version": "6.0.0-alpha.21",
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-alpha.19",
21
- "react-cosmos-renderer": "6.0.0-alpha.19",
22
- "react-cosmos-ui": "6.0.0-alpha.19",
20
+ "react-cosmos-core": "6.0.0-alpha.21",
21
+ "react-cosmos-renderer": "6.0.0-alpha.21",
22
+ "react-cosmos-ui": "6.0.0-alpha.21",
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": "e2ac66d70184f04b23853c3f57b2ec31c5684eb0"
31
+ "gitHead": "1b7472f75075853e5eaf9a427a4c3138818fbcd0"
32
32
  }
@@ -1 +0,0 @@
1
- export declare function resolveRendererUrl(publicUrl: string, filename: string): string;
@@ -1,7 +0,0 @@
1
- export function resolveRendererUrl(publicUrl, filename) {
2
- if (publicUrl === './')
3
- return filename;
4
- if (publicUrl.endsWith('/'))
5
- return publicUrl + filename;
6
- return `${publicUrl}/${filename}`;
7
- }