react-cosmos-plugin-vite 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.
@@ -1,6 +1,7 @@
1
1
  import { CosmosConfig } from 'react-cosmos';
2
+ import { CosmosMode } from 'react-cosmos-core';
2
3
  import { Plugin } from 'rollup';
3
4
  import { CosmosViteConfig } from './createCosmosViteConfig.js';
4
5
  export declare const userImportsVirtualModuleId = "virtual:cosmos-imports";
5
6
  export declare const userImportsResolvedModuleId: string;
6
- export declare function reactCosmosViteRollupPlugin(cosmosConfig: CosmosConfig, cosmosViteConfig: CosmosViteConfig): Plugin;
7
+ export declare function reactCosmosViteRollupPlugin(cosmosConfig: CosmosConfig, cosmosViteConfig: CosmosViteConfig, mode: CosmosMode): Plugin;
@@ -4,7 +4,7 @@ import { createViteRendererIndex } from './createViteRendererIndex.js';
4
4
  export const userImportsVirtualModuleId = 'virtual:cosmos-imports';
5
5
  export const userImportsResolvedModuleId = '\0' + userImportsVirtualModuleId;
6
6
  const defaultIndexPattern = new RegExp(`^(src\\${path.sep})?(index|main)\.(js|ts)x?$`);
7
- export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
7
+ export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig, mode) {
8
8
  return {
9
9
  name: 'react-cosmos-vite-renderer',
10
10
  resolveId(id) {
@@ -22,7 +22,7 @@ export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
22
22
  cosmosConfig,
23
23
  modulePaths,
24
24
  rendererConfig: {
25
- webSocketUrl: getWebSocketUrl(cosmosConfig, false),
25
+ webSocketUrl: mode === 'dev' ? getWebSocketUrl(cosmosConfig) : null,
26
26
  rendererUrl: null,
27
27
  containerQuerySelector: cosmosConfig.dom.containerQuerySelector,
28
28
  },
@@ -1,2 +1,2 @@
1
1
  import { CosmosConfig, CosmosConfigPluginArgs } from 'react-cosmos';
2
- export declare function viteConfigPlugin({ cosmosConfig, command, }: CosmosConfigPluginArgs): Promise<CosmosConfig>;
2
+ export declare function viteConfigPlugin({ cosmosConfig, mode, }: CosmosConfigPluginArgs): Promise<CosmosConfig>;
@@ -2,11 +2,11 @@ import path from 'node:path';
2
2
  import { findNextAvailablePort, } from 'react-cosmos';
3
3
  import { RENDERER_FILENAME } from './constants.js';
4
4
  import { getCosmosVitePort } from './createCosmosViteConfig.js';
5
- export async function viteConfigPlugin({ cosmosConfig, command, }) {
5
+ export async function viteConfigPlugin({ cosmosConfig, mode, }) {
6
6
  if (cosmosConfig.rendererUrl) {
7
7
  return cosmosConfig;
8
8
  }
9
- if (command === 'export') {
9
+ if (mode === 'export') {
10
10
  return {
11
11
  ...cosmosConfig,
12
12
  rendererUrl: path.join(cosmosConfig.publicUrl, RENDERER_FILENAME),
@@ -14,9 +14,10 @@ export async function viteConfigPlugin({ cosmosConfig, command, }) {
14
14
  }
15
15
  const cosmosViteConfig = cosmosConfig.vite || {};
16
16
  const port = await findNextAvailablePort(getCosmosVitePort(cosmosViteConfig), cosmosConfig.portRetries);
17
+ const protocol = cosmosConfig.https ? 'https' : 'http';
17
18
  return {
18
19
  ...cosmosConfig,
19
- rendererUrl: `http://localhost:${port}`,
20
+ rendererUrl: `${protocol}://localhost:${port}`,
20
21
  vite: {
21
22
  ...cosmosViteConfig,
22
23
  port: port,
@@ -1,4 +1,4 @@
1
- import { startFixtureWatcher } from 'react-cosmos';
1
+ import { getHttpsCreds, startFixtureWatcher, } from 'react-cosmos';
2
2
  import { pickRendererUrl } from 'react-cosmos-core';
3
3
  import { createServer } from 'vite';
4
4
  import { createCosmosViteConfig } from './createCosmosViteConfig.js';
@@ -22,11 +22,14 @@ export async function viteDevServerPlugin({ cosmosConfig, platform, }) {
22
22
  // https://vitejs.dev/config/server-options.html#server-host
23
23
  host: '0.0.0.0',
24
24
  port: parseInt(new URL(rendererUrl).port, 10),
25
+ https: cosmosConfig.https ? await getHttpsCreds(cosmosConfig) : undefined,
25
26
  // Prevent auto opening Cosmos renderer in browser when user has this
26
27
  // option enabled in their Vite config
27
28
  open: false,
28
29
  },
29
- plugins: [reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig)],
30
+ plugins: [
31
+ reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig, 'dev'),
32
+ ],
30
33
  });
31
34
  await server.listen();
32
35
  const watcher = await startFixtureWatcher(cosmosConfig, 'add', () => {
@@ -17,7 +17,9 @@ export async function viteExportPlugin({ cosmosConfig }) {
17
17
  emptyOutDir: false,
18
18
  minify: false,
19
19
  },
20
- plugins: [reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig)],
20
+ plugins: [
21
+ reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig, 'export'),
22
+ ],
21
23
  });
22
24
  await rename(path.join(outDir, 'index.html'), path.join(outDir, RENDERER_FILENAME));
23
25
  }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "react-cosmos-plugin-vite",
3
- "version": "6.2.4-canary.b5c8a03.0+b5c8a03",
3
+ "version": "6.2.4-canary.cd2cc87.0+cd2cc87",
4
4
  "description": "Vite plugin for React Cosmos",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-plugin-vite",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "cosmos.plugin.json",
9
9
  "dependencies": {
10
- "react-cosmos-core": "6.2.4-canary.b5c8a03.0+b5c8a03",
11
- "react-cosmos-dom": "6.2.4-canary.b5c8a03.0+b5c8a03"
10
+ "react-cosmos-core": "6.2.4-canary.cd2cc87.0+cd2cc87",
11
+ "react-cosmos-dom": "6.2.4-canary.cd2cc87.0+cd2cc87"
12
12
  },
13
13
  "peerDependencies": {
14
14
  "vite": "*"
15
15
  },
16
- "gitHead": "b5c8a035146467474bb975c2ae92f7b1631731c0"
16
+ "gitHead": "cd2cc87ee7c5272ebbe4ca8eab423fb77eadf2b6"
17
17
  }