react-cosmos 6.0.0-alpha.5 → 6.0.0-alpha.7
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/config.schema.json +6 -0
- package/dist/server/cosmosConfig/createCosmosConfig.js +4 -0
- package/dist/server/cosmosConfig/types.d.ts +1 -0
- package/dist/server/cosmosPlugin/pluginConfigs.js +1 -1
- package/dist/server/devServer/startDevServer.js +3 -1
- package/dist/server/getFixtures/getFixtures.js +3 -3
- package/dist/server/shared/playgroundHtml.js +3 -3
- package/dist/server/shared/resolveRendererUrl.d.ts +1 -0
- package/dist/server/shared/resolveRendererUrl.js +7 -0
- package/dist/server/userDeps/findUserModulePaths.d.ts +2 -1
- package/dist/server/userDeps/findUserModulePaths.js +3 -3
- package/dist/server/userDeps/fixtureWatcher.js +3 -3
- package/dist/server/userDeps/generateUserDepsModule.js +2 -1
- package/dist/server/userDeps/getUserModules.d.ts +1 -1
- package/dist/server/userDeps/getUserModules.js +2 -1
- package/dist/server/userDeps/shared.d.ts +0 -1
- package/dist/server/userDeps/shared.js +0 -4
- package/package.json +5 -5
- package/dist/server/shared/resolveUrlPath.d.ts +0 -1
- package/dist/server/shared/resolveUrlPath.js +0 -12
package/config.schema.json
CHANGED
|
@@ -50,6 +50,12 @@
|
|
|
50
50
|
"type": "string",
|
|
51
51
|
"minLength": 1
|
|
52
52
|
},
|
|
53
|
+
"ignore": {
|
|
54
|
+
"description": "Patterns for ignoring fixture and decorator files (eg. [\"**/dist/**\"]]).",
|
|
55
|
+
"type": "array",
|
|
56
|
+
"items": { "type": "string", "minLength": 1 },
|
|
57
|
+
"uniqueItems": true
|
|
58
|
+
},
|
|
53
59
|
"watchDirs": {
|
|
54
60
|
"description": "Directories where the Cosmos server watches for fixture files changes while running. [default: [\".\"]]",
|
|
55
61
|
"type": "array",
|
|
@@ -14,6 +14,7 @@ export function createCosmosConfig(rootDir, cosmosConfigInput = {}) {
|
|
|
14
14
|
hostname: getHostname(cosmosConfigInput),
|
|
15
15
|
https: getHttps(cosmosConfigInput),
|
|
16
16
|
httpsOptions: getHttpsOptions(cosmosConfigInput, rootDir),
|
|
17
|
+
ignore: getIgnore(cosmosConfigInput),
|
|
17
18
|
port: getPort(cosmosConfigInput),
|
|
18
19
|
plugins: getPlugins(cosmosConfigInput, rootDir),
|
|
19
20
|
publicUrl: getPublicUrl(cosmosConfigInput),
|
|
@@ -46,6 +47,9 @@ function getHttpsOptions(cosmosConfigInput, rootDir) {
|
|
|
46
47
|
}
|
|
47
48
|
return null;
|
|
48
49
|
}
|
|
50
|
+
function getIgnore({ ignore = [] }) {
|
|
51
|
+
return ['**/node_modules/**', ...ignore];
|
|
52
|
+
}
|
|
49
53
|
function getPublicUrl({ publicUrl = '/' }) {
|
|
50
54
|
return publicUrl;
|
|
51
55
|
}
|
|
@@ -9,7 +9,7 @@ export async function getPluginConfigs({ cosmosConfig, relativePaths, }) {
|
|
|
9
9
|
return moduleConfigs;
|
|
10
10
|
const localConfigs = await findCosmosPluginConfigs({
|
|
11
11
|
rootDir,
|
|
12
|
-
ignore: [`${exportPath}/**`],
|
|
12
|
+
ignore: ['**/node_modules/**', `${exportPath}/**`],
|
|
13
13
|
relativePaths,
|
|
14
14
|
});
|
|
15
15
|
return [...moduleConfigs, ...localConfigs];
|
|
@@ -31,6 +31,9 @@ export async function startDevServer(platformType) {
|
|
|
31
31
|
const app = await createExpressApp(platformType, cosmosConfig, pluginConfigs);
|
|
32
32
|
const httpServer = await createHttpServer(cosmosConfig, app);
|
|
33
33
|
const msgHandler = createMessageHandler(httpServer.server);
|
|
34
|
+
// Make Playground available as soon as possible and show a loading screen
|
|
35
|
+
// while plugins are initializing
|
|
36
|
+
await httpServer.start();
|
|
34
37
|
const pluginCleanupCallbacks = [];
|
|
35
38
|
async function cleanUp() {
|
|
36
39
|
await Promise.all(pluginCleanupCallbacks.map(cleanup => cleanup()));
|
|
@@ -72,7 +75,6 @@ export async function startDevServer(platformType) {
|
|
|
72
75
|
if (cosmosConfig.staticPath) {
|
|
73
76
|
serveStaticDir(app, cosmosConfig.staticPath, cosmosConfig.publicUrl);
|
|
74
77
|
}
|
|
75
|
-
await httpServer.start();
|
|
76
78
|
return cleanUp;
|
|
77
79
|
}
|
|
78
80
|
function logCosmosConfigInfo() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { createFixtureTree, flattenFixtureTree, getDecoratedFixtureElement, getFixtureListFromExports, getSortedDecoratorsForFixturePath, stringifyPlaygroundUrlQuery, stringifyRendererUrlQuery, } from 'react-cosmos-core';
|
|
3
3
|
import { RENDERER_FILENAME } from '../shared/playgroundHtml.js';
|
|
4
|
-
import {
|
|
4
|
+
import { resolveRendererUrl } from '../shared/resolveRendererUrl.js';
|
|
5
5
|
import { getUserModules } from '../userDeps/getUserModules.js';
|
|
6
6
|
export function getFixtures(cosmosConfig) {
|
|
7
7
|
const { fixturesDir, fixtureFileSuffix, rootDir } = cosmosConfig;
|
|
@@ -47,8 +47,8 @@ function getRendererUrl(cosmosConfig, fixtureId) {
|
|
|
47
47
|
if (rendererUrl)
|
|
48
48
|
return `${rendererUrl}?${query}`;
|
|
49
49
|
const host = getPlaygroundHost(cosmosConfig);
|
|
50
|
-
const urlPath =
|
|
51
|
-
return `${
|
|
50
|
+
const urlPath = resolveRendererUrl(publicUrl, RENDERER_FILENAME);
|
|
51
|
+
return new URL(`${urlPath}?${query}`, host).toString();
|
|
52
52
|
}
|
|
53
53
|
function getPlaygroundHost({ hostname, port, https }) {
|
|
54
54
|
return `${https ? 'https' : 'http'}://${hostname || 'localhost'}:${port}`;
|
|
@@ -3,7 +3,7 @@ import { readFile } from 'fs/promises';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { pkgUpSync } from 'pkg-up';
|
|
5
5
|
import { replaceKeys } from 'react-cosmos-core';
|
|
6
|
-
import {
|
|
6
|
+
import { resolveRendererUrl } from './resolveRendererUrl.js';
|
|
7
7
|
import { getStaticPath } from './staticPath.js';
|
|
8
8
|
export const RENDERER_FILENAME = '_renderer.html';
|
|
9
9
|
export async function getDevPlaygroundHtml(platformType, cosmosConfig, pluginConfigs) {
|
|
@@ -39,7 +39,7 @@ async function getDevCoreConfig(platformType, cosmosConfig) {
|
|
|
39
39
|
...(await getSharedCoreConfig(cosmosConfig)),
|
|
40
40
|
devServerOn: true,
|
|
41
41
|
webRendererUrl: cosmosConfig.rendererUrl ||
|
|
42
|
-
|
|
42
|
+
resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME),
|
|
43
43
|
};
|
|
44
44
|
default:
|
|
45
45
|
throw new Error(`Invalid platform type: ${platformType}`);
|
|
@@ -49,7 +49,7 @@ async function getExportCoreConfig(cosmosConfig) {
|
|
|
49
49
|
return {
|
|
50
50
|
...(await getSharedCoreConfig(cosmosConfig)),
|
|
51
51
|
devServerOn: false,
|
|
52
|
-
webRendererUrl:
|
|
52
|
+
webRendererUrl: resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME),
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
async function getSharedCoreConfig(cosmosConfig) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveRendererUrl(publicUrl: string, filename: string): string;
|
|
@@ -2,10 +2,11 @@ type FindUserModulePathsArgs = {
|
|
|
2
2
|
rootDir: string;
|
|
3
3
|
fixturesDir: string;
|
|
4
4
|
fixtureFileSuffix: string;
|
|
5
|
+
ignore: string[];
|
|
5
6
|
};
|
|
6
7
|
type UserModulePaths = {
|
|
7
8
|
fixturePaths: string[];
|
|
8
9
|
decoratorPaths: string[];
|
|
9
10
|
};
|
|
10
|
-
export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, }: FindUserModulePathsArgs): UserModulePaths;
|
|
11
|
+
export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): UserModulePaths;
|
|
11
12
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import glob from 'glob';
|
|
2
2
|
import micromatch from 'micromatch';
|
|
3
|
-
import { getDecoratorPatterns, getFixturePatterns
|
|
4
|
-
export function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, }) {
|
|
3
|
+
import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
|
|
4
|
+
export function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
|
|
5
5
|
const paths = glob.sync('**/*', {
|
|
6
6
|
cwd: rootDir,
|
|
7
7
|
absolute: true,
|
|
8
|
-
ignore
|
|
8
|
+
ignore,
|
|
9
9
|
});
|
|
10
10
|
const fixturePatterns = getFixturePatterns(fixturesDir, fixtureFileSuffix);
|
|
11
11
|
const fixturePaths = getMatchingPaths(paths, fixturePatterns);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { watch } from 'chokidar';
|
|
2
2
|
import { debounce } from 'lodash-es';
|
|
3
|
-
import { getDecoratorPatterns, getFixturePatterns
|
|
3
|
+
import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
|
|
4
4
|
const DEBOUNCE_INTERVAL = 50;
|
|
5
5
|
export async function startFixtureWatcher(cosmosConfig, event, callback) {
|
|
6
|
-
const { fixturesDir, fixtureFileSuffix } = cosmosConfig;
|
|
6
|
+
const { fixturesDir, fixtureFileSuffix, ignore } = cosmosConfig;
|
|
7
7
|
const FILE_PATTERNS = [
|
|
8
8
|
...getFixturePatterns(fixturesDir, fixtureFileSuffix),
|
|
9
9
|
...getDecoratorPatterns(),
|
|
10
10
|
];
|
|
11
11
|
return new Promise(resolve => {
|
|
12
12
|
const watcher = watch(FILE_PATTERNS, {
|
|
13
|
-
ignored:
|
|
13
|
+
ignored: ignore,
|
|
14
14
|
ignoreInitial: true,
|
|
15
15
|
cwd: cosmosConfig.rootDir,
|
|
16
16
|
})
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { findUserModulePaths } from './findUserModulePaths.js';
|
|
2
2
|
import { userDepsTemplate } from './userDepsTemplate.js';
|
|
3
3
|
export function generateUserDepsModule({ cosmosConfig, rendererConfig, relativeToDir, }) {
|
|
4
|
-
const { rootDir, fixturesDir, fixtureFileSuffix, globalImports } = cosmosConfig;
|
|
4
|
+
const { rootDir, fixturesDir, fixtureFileSuffix, globalImports, ignore } = cosmosConfig;
|
|
5
5
|
const { fixturePaths, decoratorPaths } = findUserModulePaths({
|
|
6
6
|
rootDir,
|
|
7
7
|
fixturesDir,
|
|
8
8
|
fixtureFileSuffix,
|
|
9
|
+
ignore,
|
|
9
10
|
});
|
|
10
11
|
return userDepsTemplate({
|
|
11
12
|
globalImports,
|
|
@@ -4,5 +4,5 @@ type UserModules = {
|
|
|
4
4
|
fixtures: ReactFixtureExports;
|
|
5
5
|
decorators: ReactDecorators;
|
|
6
6
|
};
|
|
7
|
-
export declare function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, }: CosmosConfig): UserModules;
|
|
7
|
+
export declare function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): UserModules;
|
|
8
8
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { slash } from '../utils/slash.js';
|
|
3
3
|
import { findUserModulePaths } from './findUserModulePaths.js';
|
|
4
|
-
export function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, }) {
|
|
4
|
+
export function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
|
|
5
5
|
const { fixturePaths, decoratorPaths } = findUserModulePaths({
|
|
6
6
|
rootDir,
|
|
7
7
|
fixturesDir,
|
|
8
8
|
fixtureFileSuffix,
|
|
9
|
+
ignore,
|
|
9
10
|
});
|
|
10
11
|
return {
|
|
11
12
|
fixtures: getDefaultExports(fixturePaths, rootDir),
|
|
@@ -3,4 +3,3 @@ export type Json = string | number | boolean | null | {
|
|
|
3
3
|
} | Json[];
|
|
4
4
|
export declare function getFixturePatterns(fixturesDir: string, fixtureFileSuffix: string): string[];
|
|
5
5
|
export declare function getDecoratorPatterns(): string[];
|
|
6
|
-
export declare function getIgnorePatterns(): string[];
|
|
@@ -5,7 +5,6 @@ const FIXTURE_PATTERNS = [
|
|
|
5
5
|
'**/*.<fixtureFileSuffix>.{js,jsx,ts,tsx}',
|
|
6
6
|
];
|
|
7
7
|
const DECORATOR_PATTERNS = ['**/cosmos.decorator.{js,jsx,ts,tsx}'];
|
|
8
|
-
const IGNORE_PATTERNS = ['**/node_modules/**'];
|
|
9
8
|
export function getFixturePatterns(fixturesDir, fixtureFileSuffix) {
|
|
10
9
|
return FIXTURE_PATTERNS.map(pattern => replaceKeys(pattern, {
|
|
11
10
|
'<fixturesDir>': fixturesDir,
|
|
@@ -15,6 +14,3 @@ export function getFixturePatterns(fixturesDir, fixtureFileSuffix) {
|
|
|
15
14
|
export function getDecoratorPatterns() {
|
|
16
15
|
return DECORATOR_PATTERNS;
|
|
17
16
|
}
|
|
18
|
-
export function getIgnorePatterns() {
|
|
19
|
-
return IGNORE_PATTERNS;
|
|
20
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.7",
|
|
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,15 +17,15 @@
|
|
|
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.
|
|
21
|
-
"react-cosmos-ui": "^6.0.0-alpha.
|
|
20
|
+
"react-cosmos-core": "^6.0.0-alpha.6",
|
|
21
|
+
"react-cosmos-ui": "^6.0.0-alpha.7",
|
|
22
22
|
"ws": "^8.12.1",
|
|
23
|
-
"yargs": "^17.7.
|
|
23
|
+
"yargs": "^17.7.1"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
26
|
"cosmos": "./bin/cosmos.js",
|
|
27
27
|
"cosmos-export": "./bin/cosmos-export.js",
|
|
28
28
|
"cosmos-native": "./bin/cosmos-native.js"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "f4702e164485966e21a8b3ec4cac8377914ee3dc"
|
|
31
31
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function resolveUrlPath(base: string, urlPath: string): string;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// resolveUrlPath('/', '_renderer.html') => '/_renderer.html'
|
|
2
|
-
// resolveUrlPath('./', '_renderer.html') => '/_renderer.html'
|
|
3
|
-
// resolveUrlPath('http://localhost:5000', '_renderer.html') => 'http://localhost:5000/_renderer.html'
|
|
4
|
-
export function resolveUrlPath(base, urlPath) {
|
|
5
|
-
// The 'resolve://' protocol is only added when base is a relative URL.
|
|
6
|
-
const resolvedUrl = new URL(urlPath, new URL(base, 'resolve://'));
|
|
7
|
-
if (resolvedUrl.protocol === 'resolve:') {
|
|
8
|
-
const { pathname, search, hash } = resolvedUrl;
|
|
9
|
-
return pathname + search + hash;
|
|
10
|
-
}
|
|
11
|
-
return resolvedUrl.toString();
|
|
12
|
-
}
|