react-cosmos-plugin-vite 6.0.0-canary.fdbaa56.0 → 6.0.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,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { fileExists,
|
|
2
|
+
import { fileExists, resolveFromSilent, resolveLoose, } from 'react-cosmos';
|
|
3
3
|
export function createCosmosViteConfig(cosmosConfig) {
|
|
4
4
|
const { rootDir } = cosmosConfig;
|
|
5
5
|
const configInput = cosmosConfig.vite || {};
|
|
@@ -24,8 +24,9 @@ function getViteConfigPath({ configPath }, rootDir) {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
if (typeof configPath == 'undefined') {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
return (resolveFromSilent(rootDir, './vite.config.ts') ||
|
|
28
|
+
resolveFromSilent(rootDir, './vite.config.js') ||
|
|
29
|
+
false);
|
|
29
30
|
}
|
|
30
31
|
const absPath = resolveLoose(rootDir, configPath);
|
|
31
32
|
if (!fileExists(absPath)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { generateUserImports, getPlaygroundUrl, } from 'react-cosmos';
|
|
2
|
+
import { findUserModulePaths, generateUserImports, getPlaygroundUrl, slash, } from 'react-cosmos';
|
|
3
3
|
import { createViteRendererIndex } from './createViteRendererIndex.js';
|
|
4
4
|
export const userImportsVirtualModuleId = 'virtual:cosmos-imports';
|
|
5
5
|
export const userImportsResolvedModuleId = '\0' + userImportsVirtualModuleId;
|
|
@@ -17,8 +17,10 @@ export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
|
|
|
17
17
|
},
|
|
18
18
|
load(id) {
|
|
19
19
|
if (id == userImportsResolvedModuleId) {
|
|
20
|
+
const modulePaths = findUserModulePaths(cosmosConfig);
|
|
20
21
|
return generateUserImports({
|
|
21
22
|
cosmosConfig,
|
|
23
|
+
modulePaths,
|
|
22
24
|
rendererConfig: {
|
|
23
25
|
playgroundUrl: getPlaygroundUrl(cosmosConfig),
|
|
24
26
|
containerQuerySelector: cosmosConfig.dom.containerQuerySelector,
|
|
@@ -32,8 +34,10 @@ export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
|
|
|
32
34
|
}
|
|
33
35
|
},
|
|
34
36
|
transform(src, id) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
+
const absPath = cosmosViteConfig.indexPath &&
|
|
38
|
+
absoluteIndexPath(cosmosViteConfig.indexPath, cosmosConfig.rootDir);
|
|
39
|
+
const isRendererIndex = absPath
|
|
40
|
+
? absPath === id
|
|
37
41
|
: path.relative(cosmosConfig.rootDir, id).match(defaultIndexPattern);
|
|
38
42
|
if (isRendererIndex) {
|
|
39
43
|
const relPath = path.relative(process.cwd(), id);
|
|
@@ -49,3 +53,8 @@ export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
|
|
|
49
53
|
},
|
|
50
54
|
};
|
|
51
55
|
}
|
|
56
|
+
function absoluteIndexPath(indexPath, rootDir) {
|
|
57
|
+
return indexPath.startsWith(rootDir)
|
|
58
|
+
? indexPath
|
|
59
|
+
: slash(path.join(rootDir, indexPath));
|
|
60
|
+
}
|
|
@@ -22,6 +22,9 @@ 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
|
+
// Prevent auto opening Cosmos renderer in browser when user has this
|
|
26
|
+
// option enabled in their Vite config
|
|
27
|
+
open: false,
|
|
25
28
|
},
|
|
26
29
|
plugins: [reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig)],
|
|
27
30
|
});
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-plugin-vite",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
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.0.0
|
|
11
|
-
"react-cosmos-dom": "6.0.0
|
|
10
|
+
"react-cosmos-core": "^6.0.0",
|
|
11
|
+
"react-cosmos-dom": "^6.0.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"vite": "*"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "db4fd8fd917598f1f16d4c291be76217436422ee"
|
|
17
17
|
}
|