react-cosmos 6.0.0-alpha.11 → 6.0.0-alpha.13
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 -2
- package/dist/cosmosConfig/createCosmosConfig.js +9 -0
- package/dist/cosmosConfig/types.d.ts +1 -0
- package/dist/testHelpers/mockYargs.js +1 -0
- package/dist/userDeps/generateUserDepsModule.js +3 -1
- package/dist/userDeps/getUserModules.d.ts +3 -3
- package/dist/userDeps/userDepsLazyTemplate.d.ts +2 -0
- package/dist/userDeps/userDepsLazyTemplate.js +37 -0
- package/dist/userDeps/userDepsShared.d.ts +11 -0
- package/dist/userDeps/userDepsShared.js +13 -0
- package/dist/userDeps/userDepsTemplate.d.ts +2 -11
- package/dist/userDeps/userDepsTemplate.js +16 -20
- package/dist/utils/cli.d.ts +1 -0
- package/dist/utils/cli.js +1 -1
- package/package.json +4 -4
package/config.schema.json
CHANGED
|
@@ -65,6 +65,10 @@
|
|
|
65
65
|
},
|
|
66
66
|
"uniqueItems": true
|
|
67
67
|
},
|
|
68
|
+
"lazy": {
|
|
69
|
+
"description": "Dynamically import fixture and decorator modules as they are loaded. When false all fixture and decorator modules are imported statically and bundled together. [default: false]",
|
|
70
|
+
"type": "boolean"
|
|
71
|
+
},
|
|
68
72
|
"userDepsFilePath": {
|
|
69
73
|
"description": "Where to generate a file that contains a map to all fixtures and other Cosmos-related user modules. Only used in setups where Cosmos can't piggyback on the user's build (eg. React Native setups). [default: \"cosmos.userdeps.js\"]",
|
|
70
74
|
"type": "string",
|
|
@@ -83,11 +87,11 @@
|
|
|
83
87
|
"type": "number"
|
|
84
88
|
},
|
|
85
89
|
"https": {
|
|
86
|
-
"description": "Server will be served over HTTPS",
|
|
90
|
+
"description": "Server will be served over HTTPS.",
|
|
87
91
|
"type": "boolean"
|
|
88
92
|
},
|
|
89
93
|
"httpsOptions": {
|
|
90
|
-
"description": "Additional options for HTTPS server",
|
|
94
|
+
"description": "Additional options for HTTPS server.",
|
|
91
95
|
"type": "object",
|
|
92
96
|
"additionalProperties": false,
|
|
93
97
|
"properties": {
|
|
@@ -15,6 +15,7 @@ export function createCosmosConfig(rootDir, cosmosConfigInput = {}) {
|
|
|
15
15
|
https: getHttps(cosmosConfigInput),
|
|
16
16
|
httpsOptions: getHttpsOptions(cosmosConfigInput, rootDir),
|
|
17
17
|
ignore: getIgnore(cosmosConfigInput),
|
|
18
|
+
lazy: getLazy(cosmosConfigInput),
|
|
18
19
|
port: getPort(cosmosConfigInput),
|
|
19
20
|
portRetries: getPortRetries(cosmosConfigInput),
|
|
20
21
|
plugins: getPlugins(cosmosConfigInput, rootDir),
|
|
@@ -97,3 +98,11 @@ function getDomConfig(cosmosConfigInput) {
|
|
|
97
98
|
containerQuerySelector,
|
|
98
99
|
};
|
|
99
100
|
}
|
|
101
|
+
function getLazy(cosmosConfigInput) {
|
|
102
|
+
const cliArgs = getCliArgs();
|
|
103
|
+
if (typeof cliArgs.lazy === 'boolean') {
|
|
104
|
+
return cliArgs.lazy;
|
|
105
|
+
}
|
|
106
|
+
const { lazy = false } = cosmosConfigInput;
|
|
107
|
+
return lazy;
|
|
108
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { findUserModulePaths } from './findUserModulePaths.js';
|
|
2
|
+
import { userDepsLazyTemplate } from './userDepsLazyTemplate.js';
|
|
2
3
|
import { userDepsTemplate } from './userDepsTemplate.js';
|
|
3
4
|
export function generateUserDepsModule({ cosmosConfig, rendererConfig, relativeToDir, }) {
|
|
4
5
|
const { rootDir, fixturesDir, fixtureFileSuffix, globalImports, ignore } = cosmosConfig;
|
|
@@ -8,7 +9,8 @@ export function generateUserDepsModule({ cosmosConfig, rendererConfig, relativeT
|
|
|
8
9
|
fixtureFileSuffix,
|
|
9
10
|
ignore,
|
|
10
11
|
});
|
|
11
|
-
|
|
12
|
+
const template = cosmosConfig.lazy ? userDepsLazyTemplate : userDepsTemplate;
|
|
13
|
+
return template({
|
|
12
14
|
globalImports,
|
|
13
15
|
fixturePaths,
|
|
14
16
|
decoratorPaths,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ByPath, ReactDecorator, ReactFixtureExport } from 'react-cosmos-core';
|
|
2
2
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
3
3
|
type UserModules = {
|
|
4
|
-
fixtures:
|
|
5
|
-
decorators:
|
|
4
|
+
fixtures: ByPath<ReactFixtureExport>;
|
|
5
|
+
decorators: ByPath<ReactDecorator>;
|
|
6
6
|
};
|
|
7
7
|
export declare function getUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): UserModules;
|
|
8
8
|
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { userDepsImportMap, userDepsImportPath, } from './userDepsShared.js';
|
|
2
|
+
export function userDepsLazyTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, }) {
|
|
3
|
+
const fixtures = userDepsImportMap(fixturePaths, rootDir, relativeToDir);
|
|
4
|
+
const fixtureKeys = Object.keys(fixtures);
|
|
5
|
+
const decorators = userDepsImportMap(decoratorPaths, rootDir, relativeToDir);
|
|
6
|
+
const decoratorKeys = Object.keys(decorators);
|
|
7
|
+
return `
|
|
8
|
+
// This file is automatically generated by Cosmos. Add it to .gitignore and
|
|
9
|
+
// only edit if you know what you're doing.
|
|
10
|
+
|
|
11
|
+
// Keeping global imports here is superior to making them bundle entry points
|
|
12
|
+
// because this way they become hot-reloadable.
|
|
13
|
+
${globalImports
|
|
14
|
+
.map(p => `import '${userDepsImportPath(p, relativeToDir)}';`)
|
|
15
|
+
.join(`\n`)}
|
|
16
|
+
|
|
17
|
+
export const rendererConfig = ${JSON.stringify(rendererConfig, null, 2)};
|
|
18
|
+
|
|
19
|
+
const fixtures = {
|
|
20
|
+
${fixtureKeys
|
|
21
|
+
.map(k => ` '${k}': { getModule: () => import('${fixtures[k]}') }`)
|
|
22
|
+
.join(`,\n`)}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const decorators = {
|
|
26
|
+
${decoratorKeys
|
|
27
|
+
.map(k => ` '${k}': { getModule: () => import('${decorators[k]}') }`)
|
|
28
|
+
.join(`,\n`)}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const moduleWrappers = {
|
|
32
|
+
lazy: true,
|
|
33
|
+
fixtures,
|
|
34
|
+
decorators,
|
|
35
|
+
};
|
|
36
|
+
`.trimStart();
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Json } from './shared.js';
|
|
2
|
+
export type UserDepsTemplateArgs = {
|
|
3
|
+
globalImports: string[];
|
|
4
|
+
fixturePaths: string[];
|
|
5
|
+
decoratorPaths: string[];
|
|
6
|
+
rendererConfig: Json;
|
|
7
|
+
rootDir: string;
|
|
8
|
+
relativeToDir: string | null;
|
|
9
|
+
};
|
|
10
|
+
export declare function userDepsImportMap(paths: string[], rootDir: string, relativeToDir: string | null): Record<string, string>;
|
|
11
|
+
export declare function userDepsImportPath(filePath: string, relativeToDir: string | null): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { slash } from '../utils/slash.js';
|
|
3
|
+
export function userDepsImportMap(paths, rootDir, relativeToDir) {
|
|
4
|
+
return paths.reduce((acc, p) => ({
|
|
5
|
+
...acc,
|
|
6
|
+
[slash(path.relative(rootDir, p))]: userDepsImportPath(p, relativeToDir),
|
|
7
|
+
}), {});
|
|
8
|
+
}
|
|
9
|
+
export function userDepsImportPath(filePath, relativeToDir) {
|
|
10
|
+
return slash(relativeToDir
|
|
11
|
+
? `.${path.sep}${path.relative(relativeToDir, filePath)}`
|
|
12
|
+
: filePath);
|
|
13
|
+
}
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
globalImports: string[];
|
|
4
|
-
fixturePaths: string[];
|
|
5
|
-
decoratorPaths: string[];
|
|
6
|
-
rendererConfig: Json;
|
|
7
|
-
rootDir: string;
|
|
8
|
-
relativeToDir: string | null;
|
|
9
|
-
};
|
|
10
|
-
export declare function userDepsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, }: Args): string;
|
|
11
|
-
export {};
|
|
1
|
+
import { UserDepsTemplateArgs } from './userDepsShared.js';
|
|
2
|
+
export declare function userDepsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, }: UserDepsTemplateArgs): string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { slash } from '../utils/slash.js';
|
|
1
|
+
import { userDepsImportMap, userDepsImportPath, } from './userDepsShared.js';
|
|
3
2
|
export function userDepsTemplate({ globalImports, fixturePaths, decoratorPaths, rendererConfig, rootDir, relativeToDir, }) {
|
|
4
|
-
const fixtures =
|
|
3
|
+
const fixtures = userDepsImportMap(fixturePaths, rootDir, relativeToDir);
|
|
5
4
|
const fixtureKeys = Object.keys(fixtures);
|
|
6
|
-
const decorators =
|
|
5
|
+
const decorators = userDepsImportMap(decoratorPaths, rootDir, relativeToDir);
|
|
7
6
|
const decoratorKeys = Object.keys(decorators);
|
|
8
7
|
return `
|
|
9
8
|
// This file is automatically generated by Cosmos. Add it to .gitignore and
|
|
@@ -12,7 +11,7 @@ export function userDepsTemplate({ globalImports, fixturePaths, decoratorPaths,
|
|
|
12
11
|
// Keeping global imports here is superior to making them bundle entry points
|
|
13
12
|
// because this way they become hot-reloadable.
|
|
14
13
|
${globalImports
|
|
15
|
-
.map(p => `import '${
|
|
14
|
+
.map(p => `import '${userDepsImportPath(p, relativeToDir)}';`)
|
|
16
15
|
.join(`\n`)}
|
|
17
16
|
|
|
18
17
|
${fixtureKeys
|
|
@@ -25,25 +24,22 @@ ${decoratorKeys
|
|
|
25
24
|
|
|
26
25
|
export const rendererConfig = ${JSON.stringify(rendererConfig, null, 2)};
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
const fixtures = {
|
|
29
28
|
${fixtureKeys
|
|
30
|
-
.map((k, i) => `
|
|
29
|
+
.map((k, i) => ` '${k}': { module: { default: fixture${i} } }`)
|
|
31
30
|
.join(`,\n`)}
|
|
32
31
|
};
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
${decoratorKeys
|
|
33
|
+
const decorators = {
|
|
34
|
+
${decoratorKeys
|
|
35
|
+
.map((k, i) => ` '${k}': { module: { default: decorator${i} } }`)
|
|
36
|
+
.join(`,\n`)}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const moduleWrappers = {
|
|
40
|
+
lazy: false,
|
|
41
|
+
fixtures,
|
|
42
|
+
decorators,
|
|
36
43
|
};
|
|
37
44
|
`.trimStart();
|
|
38
45
|
}
|
|
39
|
-
function createImportMap(paths, rootDir, relativeToDir) {
|
|
40
|
-
return paths.reduce((acc, p) => ({
|
|
41
|
-
...acc,
|
|
42
|
-
[slash(path.relative(rootDir, p))]: resolveImportPath(p, relativeToDir),
|
|
43
|
-
}), {});
|
|
44
|
-
}
|
|
45
|
-
function resolveImportPath(filePath, relativeToDir) {
|
|
46
|
-
return slash(relativeToDir
|
|
47
|
-
? `.${path.sep}${path.relative(relativeToDir, filePath)}`
|
|
48
|
-
: filePath);
|
|
49
|
-
}
|
package/dist/utils/cli.d.ts
CHANGED
package/dist/utils/cli.js
CHANGED
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.13",
|
|
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,8 +17,8 @@
|
|
|
17
17
|
"open": "^8.4.2",
|
|
18
18
|
"pem": "^1.14.6",
|
|
19
19
|
"pkg-up": "^4.0.0",
|
|
20
|
-
"react-cosmos-core": "
|
|
21
|
-
"react-cosmos-ui": "
|
|
20
|
+
"react-cosmos-core": "6.0.0-alpha.13",
|
|
21
|
+
"react-cosmos-ui": "6.0.0-alpha.13",
|
|
22
22
|
"ws": "^8.12.1",
|
|
23
23
|
"yargs": "^17.7.1"
|
|
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": "cf95e67ce942f6a242f023ecebe45d6916d5b753"
|
|
31
31
|
}
|