react-cosmos 6.2.4-canary.b5c8a03.0 → 6.2.4-canary.cd2cc87.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.
- package/dist/corePlugins/fixtureWatcherPlugin.js +4 -4
- package/dist/corePlugins/fixturesJsonPlugin.js +4 -4
- package/dist/corePlugins/httpProxyPlugin.js +3 -3
- package/dist/corePlugins/index.js +2 -0
- package/dist/corePlugins/openFilePlugin.js +2 -2
- package/dist/corePlugins/pluginEndpointPlugin.js +2 -2
- package/dist/corePlugins/portRetryPlugin.js +2 -2
- package/dist/corePlugins/remoteRendererUrlPlugin.d.ts +2 -0
- package/dist/corePlugins/remoteRendererUrlPlugin.js +9 -0
- package/dist/cosmosPlugin/types.d.ts +4 -4
- package/dist/devServer/expressApp.d.ts +2 -2
- package/dist/devServer/expressApp.js +4 -4
- package/dist/devServer/httpServer.js +5 -21
- package/dist/devServer/httpsCreds.d.ts +7 -0
- package/dist/devServer/httpsCreds.js +24 -0
- package/dist/devServer/startDevServer.js +2 -2
- package/dist/export/generateExport.js +1 -1
- package/dist/getFixtures/getFixtures.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/shared/applyServerConfigPlugins.d.ts +3 -3
- package/dist/shared/applyServerConfigPlugins.js +2 -2
- package/dist/shared/playgroundUrl.d.ts +1 -1
- package/dist/shared/playgroundUrl.js +10 -5
- package/dist/shared/remoteRendererUrl.d.ts +2 -0
- package/dist/shared/remoteRendererUrl.js +21 -0
- package/dist/shared/serverAddress.d.ts +3 -0
- package/dist/shared/serverAddress.js +23 -0
- package/dist/shared/staticServer.d.ts +2 -2
- package/dist/shared/webSocketUrl.d.ts +1 -1
- package/dist/shared/webSocketUrl.js +3 -20
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { pickRendererUrl
|
|
3
|
+
import { pickRendererUrl } from 'react-cosmos-core';
|
|
4
4
|
import { updateFixtureListCache } from '../shared/serverFixtureList.js';
|
|
5
5
|
import { getWebSocketUrl } from '../shared/webSocketUrl.js';
|
|
6
6
|
import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
|
|
@@ -36,16 +36,16 @@ export const fixtureWatcherPlugin = {
|
|
|
36
36
|
function shouldExposeImports(platform, cosmosConfig) {
|
|
37
37
|
return platform === 'native' || Boolean(cosmosConfig.exposeImports);
|
|
38
38
|
}
|
|
39
|
-
async function generateImportsFile(platform, cosmosConfig,
|
|
39
|
+
async function generateImportsFile(platform, cosmosConfig, mode, modulePaths) {
|
|
40
40
|
const { exposeImports } = cosmosConfig;
|
|
41
41
|
const filePath = typeof exposeImports === 'string'
|
|
42
42
|
? exposeImports
|
|
43
43
|
: getDefaultFilePath(cosmosConfig.rootDir);
|
|
44
44
|
const typeScript = /\.tsx?$/.test(filePath);
|
|
45
45
|
const rendererConfig = {
|
|
46
|
-
webSocketUrl:
|
|
46
|
+
webSocketUrl: mode === 'dev' ? getWebSocketUrl(cosmosConfig) : null,
|
|
47
47
|
rendererUrl: platform === 'web'
|
|
48
|
-
? pickRendererUrl(cosmosConfig.rendererUrl,
|
|
48
|
+
? pickRendererUrl(cosmosConfig.rendererUrl, mode)
|
|
49
49
|
: null,
|
|
50
50
|
};
|
|
51
51
|
const fileSource = generateUserImports({
|
|
@@ -6,8 +6,8 @@ import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
|
|
|
6
6
|
import { importKeyPath } from '../userModules/shared.js';
|
|
7
7
|
export const fixturesJsonPlugin = {
|
|
8
8
|
name: 'fixturesJson',
|
|
9
|
-
devServer({ cosmosConfig,
|
|
10
|
-
|
|
9
|
+
devServer({ cosmosConfig, app }) {
|
|
10
|
+
app.get('/cosmos.fixtures.json', async (req, res) => {
|
|
11
11
|
res.json(await createFixtureItems(cosmosConfig, 'dev'));
|
|
12
12
|
});
|
|
13
13
|
},
|
|
@@ -17,8 +17,8 @@ export const fixturesJsonPlugin = {
|
|
|
17
17
|
await fs.writeFile(path.join(exportPath, 'cosmos.fixtures.json'), JSON.stringify(json, null, 2));
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
|
-
async function createFixtureItems(cosmosConfig,
|
|
21
|
-
const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl,
|
|
20
|
+
async function createFixtureItems(cosmosConfig, mode) {
|
|
21
|
+
const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, mode);
|
|
22
22
|
if (!rendererUrl) {
|
|
23
23
|
return {
|
|
24
24
|
rendererUrl: null,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
2
2
|
export const httpProxyPlugin = {
|
|
3
3
|
name: 'httpProxy',
|
|
4
|
-
devServer({ cosmosConfig, platform,
|
|
4
|
+
devServer({ cosmosConfig, platform, app }) {
|
|
5
5
|
if (platform !== 'web')
|
|
6
6
|
return;
|
|
7
7
|
const httpProxyConfig = getHttpProxyCosmosConfig(cosmosConfig);
|
|
8
8
|
Object.keys(httpProxyConfig).forEach(context => {
|
|
9
9
|
const config = httpProxyConfig[context];
|
|
10
10
|
if (typeof config === 'string') {
|
|
11
|
-
|
|
11
|
+
app.use(context, createProxyMiddleware(context, { target: config }));
|
|
12
12
|
}
|
|
13
13
|
else if (typeof config === 'object') {
|
|
14
|
-
|
|
14
|
+
app.use(context, createProxyMiddleware(context, config));
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
},
|
|
@@ -4,12 +4,14 @@ import { httpProxyPlugin } from './httpProxyPlugin.js';
|
|
|
4
4
|
import { openFilePlugin } from './openFilePlugin.js';
|
|
5
5
|
import { pluginEndpointPlugin } from './pluginEndpointPlugin.js';
|
|
6
6
|
import { portRetryPlugin } from './portRetryPlugin.js';
|
|
7
|
+
import { remoteRendererUrlPlugin } from './remoteRendererUrlPlugin.js';
|
|
7
8
|
export const coreServerPlugins = [
|
|
8
9
|
portRetryPlugin,
|
|
9
10
|
fixturesJsonPlugin,
|
|
10
11
|
httpProxyPlugin,
|
|
11
12
|
openFilePlugin,
|
|
12
13
|
pluginEndpointPlugin,
|
|
14
|
+
remoteRendererUrlPlugin,
|
|
13
15
|
];
|
|
14
16
|
// Omit starting chokidar in unit tests for performance reasons
|
|
15
17
|
if (process.env.VITEST_WORKER_ID === undefined) {
|
|
@@ -4,8 +4,8 @@ import open from 'open';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
export const openFilePlugin = {
|
|
6
6
|
name: 'openFile',
|
|
7
|
-
devServer({ cosmosConfig,
|
|
8
|
-
|
|
7
|
+
devServer({ cosmosConfig, app }) {
|
|
8
|
+
app.get('/_open', (req, res) => {
|
|
9
9
|
const { filePath, line, column } = getReqQuery(req);
|
|
10
10
|
if (!filePath) {
|
|
11
11
|
res.status(400).send(`File path missing`);
|
|
@@ -2,8 +2,8 @@ import path from 'node:path';
|
|
|
2
2
|
import { resolveSilent } from '../utils/resolveSilent.js';
|
|
3
3
|
export const pluginEndpointPlugin = {
|
|
4
4
|
name: 'pluginEndpoint',
|
|
5
|
-
devServer({
|
|
6
|
-
|
|
5
|
+
devServer({ app }) {
|
|
6
|
+
app.get('/_plugin/*.js', (req, res) => {
|
|
7
7
|
const modulePath = req.params['0'];
|
|
8
8
|
if (!modulePath) {
|
|
9
9
|
res.sendStatus(404);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { findNextAvailablePort } from '../shared/findNextAvailablePort.js';
|
|
2
2
|
export const portRetryPlugin = {
|
|
3
3
|
name: 'portRetry',
|
|
4
|
-
async config({ cosmosConfig,
|
|
5
|
-
if (
|
|
4
|
+
async config({ cosmosConfig, mode }) {
|
|
5
|
+
if (mode === 'export') {
|
|
6
6
|
return cosmosConfig;
|
|
7
7
|
}
|
|
8
8
|
const { port, portRetries } = cosmosConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getRemoteRendererUrl } from '../shared/remoteRendererUrl.js';
|
|
2
|
+
export const remoteRendererUrlPlugin = {
|
|
3
|
+
name: 'remoteRendererUrlPlugin',
|
|
4
|
+
devServer({ cosmosConfig, app }) {
|
|
5
|
+
app.get('/_cosmos/remote-renderer-url', (_, res) => {
|
|
6
|
+
res.send({ url: getRemoteRendererUrl(cosmosConfig) });
|
|
7
|
+
});
|
|
8
|
+
},
|
|
9
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Express } from 'express';
|
|
2
2
|
import http from 'http';
|
|
3
|
-
import {
|
|
3
|
+
import { CosmosMode, MessageType } from 'react-cosmos-core';
|
|
4
4
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
5
5
|
export type CosmosPlatform = 'web' | 'native';
|
|
6
6
|
export type CosmosConfigPluginArgs = {
|
|
7
7
|
cosmosConfig: CosmosConfig;
|
|
8
|
-
|
|
8
|
+
mode: CosmosMode;
|
|
9
9
|
platform: CosmosPlatform;
|
|
10
10
|
};
|
|
11
11
|
export type CosmosConfigPlugin = (args: CosmosConfigPluginArgs) => Promise<CosmosConfig> | CosmosConfig;
|
|
@@ -13,7 +13,7 @@ export type DevServerPluginArgs = {
|
|
|
13
13
|
cosmosConfig: CosmosConfig;
|
|
14
14
|
platform: CosmosPlatform;
|
|
15
15
|
httpServer: http.Server;
|
|
16
|
-
|
|
16
|
+
app: Express;
|
|
17
17
|
sendMessage(msg: MessageType): unknown;
|
|
18
18
|
};
|
|
19
19
|
export type DevServerPluginCleanupCallback = () => unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Express } from 'express';
|
|
2
2
|
import { CosmosPluginConfig } from 'react-cosmos-core';
|
|
3
3
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
4
4
|
import { CosmosPlatform } from '../cosmosPlugin/types.js';
|
|
5
|
-
export declare function createExpressApp(platform: CosmosPlatform, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<
|
|
5
|
+
export declare function createExpressApp(platform: CosmosPlatform, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): Promise<Express>;
|
|
@@ -4,16 +4,16 @@ 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
|
-
app.get('/', async (
|
|
7
|
+
app.get('/', async (_, res) => {
|
|
8
8
|
res.send(await getDevPlaygroundHtml(platform, cosmosConfig, pluginConfigs));
|
|
9
9
|
});
|
|
10
|
-
app.get('/playground.bundle.js', (
|
|
10
|
+
app.get('/playground.bundle.js', (_, res) => {
|
|
11
11
|
res.sendFile(resolve('react-cosmos-ui/dist/playground.bundle.js'));
|
|
12
12
|
});
|
|
13
|
-
app.get('/playground.bundle.js.map', (
|
|
13
|
+
app.get('/playground.bundle.js.map', (_, res) => {
|
|
14
14
|
res.sendFile(resolve('react-cosmos-ui/dist/playground.bundle.js.map'));
|
|
15
15
|
});
|
|
16
|
-
app.get('/_cosmos.ico', (
|
|
16
|
+
app.get('/_cosmos.ico', (_, res) => {
|
|
17
17
|
res.sendFile(getStaticPath('favicon.ico'));
|
|
18
18
|
});
|
|
19
19
|
return app;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import http from 'http';
|
|
3
2
|
import https from 'https';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
3
|
+
import { getPlaygroundUrls } from '../shared/playgroundUrl.js';
|
|
4
|
+
import { getHttpsCreds } from './httpsCreds.js';
|
|
6
5
|
export async function createHttpServer(config, requestListener) {
|
|
7
6
|
const server = config.https
|
|
8
|
-
? https.createServer(await
|
|
7
|
+
? https.createServer(await getHttpsCreds(config), requestListener)
|
|
9
8
|
: http.createServer(requestListener);
|
|
10
9
|
async function start() {
|
|
11
10
|
await new Promise(resolve => {
|
|
@@ -16,26 +15,11 @@ export async function createHttpServer(config, requestListener) {
|
|
|
16
15
|
server.listen(config.port, config.host, resolve);
|
|
17
16
|
}
|
|
18
17
|
});
|
|
19
|
-
|
|
18
|
+
const urls = getPlaygroundUrls(config);
|
|
19
|
+
console.log(`[Cosmos] See you at ${urls.join(' or ')}`);
|
|
20
20
|
}
|
|
21
21
|
async function stop() {
|
|
22
22
|
await new Promise(resolve => server.close(resolve));
|
|
23
23
|
}
|
|
24
24
|
return { server, start, stop };
|
|
25
25
|
}
|
|
26
|
-
async function getHttpsOpts(cosmosConfig) {
|
|
27
|
-
const { httpsOptions } = cosmosConfig;
|
|
28
|
-
if (httpsOptions)
|
|
29
|
-
return {
|
|
30
|
-
key: fs.readFileSync(httpsOptions.keyPath, 'utf8'),
|
|
31
|
-
cert: fs.readFileSync(httpsOptions.certPath, 'utf8'),
|
|
32
|
-
};
|
|
33
|
-
console.log('[Cosmos] Generating HTTPS certificate');
|
|
34
|
-
return await new Promise((resolve, reject) => {
|
|
35
|
-
pem.createCertificate({ days: 1000, selfSigned: true }, (err, keys) => {
|
|
36
|
-
if (err)
|
|
37
|
-
return reject(err);
|
|
38
|
-
return resolve({ key: keys.serviceKey, cert: keys.certificate });
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import pem from 'pem';
|
|
3
|
+
let _cache;
|
|
4
|
+
export async function getHttpsCreds(config) {
|
|
5
|
+
const { httpsOptions } = config;
|
|
6
|
+
if (httpsOptions)
|
|
7
|
+
return {
|
|
8
|
+
key: fs.readFileSync(httpsOptions.keyPath, 'utf8'),
|
|
9
|
+
cert: fs.readFileSync(httpsOptions.certPath, 'utf8'),
|
|
10
|
+
};
|
|
11
|
+
if (_cache)
|
|
12
|
+
return _cache;
|
|
13
|
+
console.log('[Cosmos] Generating HTTPS certificate');
|
|
14
|
+
return await new Promise((resolve, reject) => {
|
|
15
|
+
pem.createCertificate({ days: 1000, selfSigned: true }, (err, keys) => {
|
|
16
|
+
if (err)
|
|
17
|
+
reject(err);
|
|
18
|
+
else {
|
|
19
|
+
_cache = { key: keys.serviceKey, cert: keys.certificate };
|
|
20
|
+
resolve(_cache);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -23,7 +23,7 @@ export async function startDevServer(platform) {
|
|
|
23
23
|
cosmosConfig = await applyServerConfigPlugins({
|
|
24
24
|
cosmosConfig,
|
|
25
25
|
serverPlugins,
|
|
26
|
-
|
|
26
|
+
mode: 'dev',
|
|
27
27
|
platform,
|
|
28
28
|
});
|
|
29
29
|
const app = await createExpressApp(platform, cosmosConfig, pluginConfigs);
|
|
@@ -49,7 +49,7 @@ export async function startDevServer(platform) {
|
|
|
49
49
|
cosmosConfig,
|
|
50
50
|
platform,
|
|
51
51
|
httpServer: httpServer.server,
|
|
52
|
-
|
|
52
|
+
app,
|
|
53
53
|
sendMessage: msgHandler.sendMessage,
|
|
54
54
|
});
|
|
55
55
|
if (typeof pluginReturn === 'function') {
|
|
@@ -2,7 +2,7 @@ import { mapValues } from 'lodash-es';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { buildPlaygroundQueryString, createFixtureTree, createRendererUrl, flattenFixtureTree, getFixtureFromExport, getFixtureListFromExports, getSortedDecoratorsForFixturePath, } from 'react-cosmos-core';
|
|
4
4
|
import { createFixtureNode, decorateFixture } from 'react-cosmos-renderer';
|
|
5
|
-
import {
|
|
5
|
+
import { getPlaygroundUrls } from '../shared/playgroundUrl.js';
|
|
6
6
|
import { importUserModules } from './importUserModules.js';
|
|
7
7
|
export async function getFixtures(cosmosConfig, options = {}) {
|
|
8
8
|
const { fixtures, decorators } = await importUserModules(cosmosConfig);
|
|
@@ -44,7 +44,7 @@ function getFlatFixtureTree(cosmosConfig, fixtures) {
|
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
46
|
function getPlaygroundFixtureUrl(cosmosConfig, fixtureId) {
|
|
47
|
-
const baseUrl =
|
|
47
|
+
const [baseUrl] = getPlaygroundUrls(cosmosConfig);
|
|
48
48
|
const query = buildPlaygroundQueryString({ fixture: fixtureId });
|
|
49
49
|
return `${baseUrl}/${query}`;
|
|
50
50
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,11 @@ export * from './cosmosConfig/types.js';
|
|
|
6
6
|
export * from './cosmosPlugin/findCosmosPluginConfigs.js';
|
|
7
7
|
export * from './cosmosPlugin/pluginConfigs.js';
|
|
8
8
|
export * from './cosmosPlugin/types.js';
|
|
9
|
+
export * from './devServer/httpsCreds.js';
|
|
9
10
|
export * from './getFixtures/getFixtures.js';
|
|
10
11
|
export * from './shared/findNextAvailablePort.js';
|
|
11
12
|
export * from './shared/playgroundUrl.js';
|
|
13
|
+
export * from './shared/serverAddress.js';
|
|
12
14
|
export * from './shared/staticServer.js';
|
|
13
15
|
export * from './shared/webSocketUrl.js';
|
|
14
16
|
export * from './testHelpers/cwd.js';
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,11 @@ export * from './cosmosConfig/types.js';
|
|
|
5
5
|
export * from './cosmosPlugin/findCosmosPluginConfigs.js';
|
|
6
6
|
export * from './cosmosPlugin/pluginConfigs.js';
|
|
7
7
|
export * from './cosmosPlugin/types.js';
|
|
8
|
+
export * from './devServer/httpsCreds.js';
|
|
8
9
|
export * from './getFixtures/getFixtures.js';
|
|
9
10
|
export * from './shared/findNextAvailablePort.js';
|
|
10
11
|
export * from './shared/playgroundUrl.js';
|
|
12
|
+
export * from './shared/serverAddress.js';
|
|
11
13
|
export * from './shared/staticServer.js';
|
|
12
14
|
export * from './shared/webSocketUrl.js';
|
|
13
15
|
export * from './testHelpers/cwd.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CosmosMode } from 'react-cosmos-core';
|
|
2
2
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
3
3
|
import { CosmosPlatform, CosmosServerPlugin } from '../cosmosPlugin/types.js';
|
|
4
4
|
type Args = {
|
|
5
5
|
cosmosConfig: CosmosConfig;
|
|
6
6
|
serverPlugins: CosmosServerPlugin[];
|
|
7
|
-
|
|
7
|
+
mode: CosmosMode;
|
|
8
8
|
platform: CosmosPlatform;
|
|
9
9
|
};
|
|
10
|
-
export declare function applyServerConfigPlugins({ cosmosConfig, serverPlugins,
|
|
10
|
+
export declare function applyServerConfigPlugins({ cosmosConfig, serverPlugins, mode, platform, }: Args): Promise<CosmosConfig>;
|
|
11
11
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export async function applyServerConfigPlugins({ cosmosConfig, serverPlugins,
|
|
1
|
+
export async function applyServerConfigPlugins({ cosmosConfig, serverPlugins, mode, platform, }) {
|
|
2
2
|
for (const plugin of serverPlugins) {
|
|
3
3
|
if (plugin.config) {
|
|
4
4
|
try {
|
|
5
|
-
cosmosConfig = await plugin.config({ cosmosConfig,
|
|
5
|
+
cosmosConfig = await plugin.config({ cosmosConfig, mode, platform });
|
|
6
6
|
}
|
|
7
7
|
catch (err) {
|
|
8
8
|
console.log(`[Cosmos][plugin:${plugin.name}] Config hook failed`);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function getPlaygroundUrls(config: CosmosConfig): string[];
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const protocol =
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { getServerHost } from './serverAddress.js';
|
|
2
|
+
export function getPlaygroundUrls(config) {
|
|
3
|
+
const protocol = config.https ? 'https' : 'http';
|
|
4
|
+
if (config.host) {
|
|
5
|
+
return [`${protocol}://${config.host}:${config.port}`];
|
|
6
|
+
}
|
|
7
|
+
return [
|
|
8
|
+
`${protocol}://localhost:${config.port}`,
|
|
9
|
+
`${protocol}://${getServerHost(config)}:${config.port}`,
|
|
10
|
+
];
|
|
6
11
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRendererUrl, pickRendererUrl } from 'react-cosmos-core';
|
|
2
|
+
import { getServerAddress, getServerHost } from './serverAddress.js';
|
|
3
|
+
export function getRemoteRendererUrl(config) {
|
|
4
|
+
const rendererUrl = pickRendererUrl(config.rendererUrl, 'dev');
|
|
5
|
+
return rendererUrl
|
|
6
|
+
? fullServerUrl(config, createRendererUrl(rendererUrl)).toString()
|
|
7
|
+
: null;
|
|
8
|
+
}
|
|
9
|
+
function fullServerUrl(config, rendererUrl) {
|
|
10
|
+
// Renderer URL can be absolute or relative, depending on whether the renderer
|
|
11
|
+
// is running on the same host/port as the Cosmos UI.
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(rendererUrl);
|
|
14
|
+
url.hostname = getServerHost(config);
|
|
15
|
+
return url;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
const protocol = config.https ? 'https' : 'http';
|
|
19
|
+
return new URL(rendererUrl, `${protocol}://${getServerAddress(config)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as os from 'node:os';
|
|
2
|
+
export function getServerHost(config) {
|
|
3
|
+
return config.host ?? getIpAddress();
|
|
4
|
+
}
|
|
5
|
+
export function getServerAddress(config) {
|
|
6
|
+
return `${getServerHost(config)}:${config.port}`;
|
|
7
|
+
}
|
|
8
|
+
function getIpAddress() {
|
|
9
|
+
const nets = os.networkInterfaces();
|
|
10
|
+
for (const name of Object.keys(nets)) {
|
|
11
|
+
if (nets[name]) {
|
|
12
|
+
for (const net of nets[name]) {
|
|
13
|
+
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
|
14
|
+
// 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
|
|
15
|
+
const familyV4Value = typeof net.family === 'string' ? 'IPv4' : 4;
|
|
16
|
+
if (net.family === familyV4Value && !net.internal) {
|
|
17
|
+
return net.address;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return '127.0.0.1';
|
|
23
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function serveStaticDir(app:
|
|
1
|
+
import { Application } from 'express';
|
|
2
|
+
export declare function serveStaticDir(app: Application, staticPath: string, publicUrl: string): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
2
|
-
export declare function getWebSocketUrl(config: CosmosConfig
|
|
2
|
+
export declare function getWebSocketUrl(config: CosmosConfig): string;
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function getWebSocketUrl(config
|
|
1
|
+
import { getServerAddress } from './serverAddress.js';
|
|
2
|
+
export function getWebSocketUrl(config) {
|
|
3
3
|
const protocol = config.https ? 'wss' : 'ws';
|
|
4
|
-
|
|
5
|
-
return `${protocol}://${host}:${config.port}`;
|
|
6
|
-
}
|
|
7
|
-
function getIpAddress() {
|
|
8
|
-
const nets = os.networkInterfaces();
|
|
9
|
-
for (const name of Object.keys(nets)) {
|
|
10
|
-
if (nets[name]) {
|
|
11
|
-
for (const net of nets[name]) {
|
|
12
|
-
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
|
13
|
-
// 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
|
|
14
|
-
const familyV4Value = typeof net.family === 'string' ? 'IPv4' : 4;
|
|
15
|
-
if (net.family === familyV4Value && !net.internal) {
|
|
16
|
-
return net.address;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return '127.0.0.1';
|
|
4
|
+
return `${protocol}://${getServerAddress(config)}`;
|
|
22
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/client.ts","../src/index.ts","../src/vitest.ts","../src/@types/launch-editor.d.ts","../src/@types/mdx.d.ts","../src/@types/yargs.d.ts","../src/corePlugins/fixtureWatcherPlugin.ts","../src/corePlugins/fixturesJsonPlugin.ts","../src/corePlugins/httpProxyPlugin.ts","../src/corePlugins/index.ts","../src/corePlugins/openFilePlugin.ts","../src/corePlugins/pluginEndpointPlugin.ts","../src/corePlugins/portRetryPlugin.ts","../src/cosmosConfig/createCosmosConfig.ts","../src/cosmosConfig/detectCosmosConfig.ts","../src/cosmosConfig/getCosmosConfigAtPath.ts","../src/cosmosConfig/shared.ts","../src/cosmosConfig/types.ts","../src/cosmosPlugin/findCosmosPluginConfigs.ts","../src/cosmosPlugin/pluginConfigs.ts","../src/cosmosPlugin/readCosmosPluginConfig.ts","../src/cosmosPlugin/types.ts","../src/devServer/expressApp.ts","../src/devServer/httpServer.ts","../src/devServer/messageHandler.ts","../src/devServer/startDevServer.ts","../src/export/generateExport.ts","../src/getFixtures/getFixtures.ts","../src/getFixtures/importUserModules.ts","../src/shared/applyServerConfigPlugins.ts","../src/shared/findNextAvailablePort.ts","../src/shared/getServerPlugins.ts","../src/shared/importServerPlugins.ts","../src/shared/logPluginInfo.ts","../src/shared/playgroundHtml.ts","../src/shared/playgroundUrl.ts","../src/shared/serverFixtureList.ts","../src/shared/staticPath.ts","../src/shared/staticServer.ts","../src/shared/webSocketUrl.ts","../src/userModules/findUserModulePaths.ts","../src/userModules/fixtureWatcher.ts","../src/userModules/generateUserImports.ts","../src/userModules/shared.ts","../src/userModules/userImportsLazyTemplate.ts","../src/userModules/userImportsTemplate.ts","../src/utils/cli.ts","../src/utils/findUp.ts","../src/utils/fs.ts","../src/utils/isNodeError.ts","../src/utils/json.ts","../src/utils/requireModule.ts","../src/utils/resolve.ts","../src/utils/resolveLoose.ts","../src/utils/resolveSilent.ts","../src/utils/slash.ts"],"version":"5.7.3"}
|
|
1
|
+
{"root":["../src/client.ts","../src/index.ts","../src/vitest.ts","../src/@types/launch-editor.d.ts","../src/@types/mdx.d.ts","../src/@types/yargs.d.ts","../src/corePlugins/fixtureWatcherPlugin.ts","../src/corePlugins/fixturesJsonPlugin.ts","../src/corePlugins/httpProxyPlugin.ts","../src/corePlugins/index.ts","../src/corePlugins/openFilePlugin.ts","../src/corePlugins/pluginEndpointPlugin.ts","../src/corePlugins/portRetryPlugin.ts","../src/corePlugins/remoteRendererUrlPlugin.ts","../src/cosmosConfig/createCosmosConfig.ts","../src/cosmosConfig/detectCosmosConfig.ts","../src/cosmosConfig/getCosmosConfigAtPath.ts","../src/cosmosConfig/shared.ts","../src/cosmosConfig/types.ts","../src/cosmosPlugin/findCosmosPluginConfigs.ts","../src/cosmosPlugin/pluginConfigs.ts","../src/cosmosPlugin/readCosmosPluginConfig.ts","../src/cosmosPlugin/types.ts","../src/devServer/expressApp.ts","../src/devServer/httpServer.ts","../src/devServer/httpsCreds.ts","../src/devServer/messageHandler.ts","../src/devServer/startDevServer.ts","../src/export/generateExport.ts","../src/getFixtures/getFixtures.ts","../src/getFixtures/importUserModules.ts","../src/shared/applyServerConfigPlugins.ts","../src/shared/findNextAvailablePort.ts","../src/shared/getServerPlugins.ts","../src/shared/importServerPlugins.ts","../src/shared/logPluginInfo.ts","../src/shared/playgroundHtml.ts","../src/shared/playgroundUrl.ts","../src/shared/remoteRendererUrl.ts","../src/shared/serverAddress.ts","../src/shared/serverFixtureList.ts","../src/shared/staticPath.ts","../src/shared/staticServer.ts","../src/shared/webSocketUrl.ts","../src/userModules/findUserModulePaths.ts","../src/userModules/fixtureWatcher.ts","../src/userModules/generateUserImports.ts","../src/userModules/shared.ts","../src/userModules/userImportsLazyTemplate.ts","../src/userModules/userImportsTemplate.ts","../src/utils/cli.ts","../src/utils/findUp.ts","../src/utils/fs.ts","../src/utils/isNodeError.ts","../src/utils/json.ts","../src/utils/requireModule.ts","../src/utils/resolve.ts","../src/utils/resolveLoose.ts","../src/utils/resolveSilent.ts","../src/utils/slash.ts"],"version":"5.7.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos",
|
|
3
|
-
"version": "6.2.4-canary.
|
|
3
|
+
"version": "6.2.4-canary.cd2cc87.0+cd2cc87",
|
|
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.8",
|
|
17
17
|
"open": "10.1.0",
|
|
18
18
|
"pem": "1.15.1",
|
|
19
|
-
"react-cosmos-core": "6.2.4-canary.
|
|
20
|
-
"react-cosmos-renderer": "6.2.4-canary.
|
|
21
|
-
"react-cosmos-ui": "6.2.4-canary.
|
|
19
|
+
"react-cosmos-core": "6.2.4-canary.cd2cc87.0+cd2cc87",
|
|
20
|
+
"react-cosmos-renderer": "6.2.4-canary.cd2cc87.0+cd2cc87",
|
|
21
|
+
"react-cosmos-ui": "6.2.4-canary.cd2cc87.0+cd2cc87",
|
|
22
22
|
"ws": "8.18.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": "
|
|
30
|
+
"gitHead": "cd2cc87ee7c5272ebbe4ca8eab423fb77eadf2b6"
|
|
31
31
|
}
|