react-cosmos 5.7.2 → 6.0.0-alpha.10
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/bin/cosmos-export.js +4 -3
- package/bin/cosmos-native.js +4 -3
- package/bin/cosmos.js +5 -4
- package/config.schema.json +20 -4
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -70
- package/dist/jest.d.ts +7 -0
- package/dist/jest.js +7 -0
- package/dist/{config → server/cosmosConfig}/createCosmosConfig.d.ts +1 -1
- package/dist/server/cosmosConfig/createCosmosConfig.js +88 -0
- package/dist/server/cosmosConfig/detectCosmosConfig.d.ts +2 -0
- package/dist/server/cosmosConfig/detectCosmosConfig.js +38 -0
- package/dist/{config → server/cosmosConfig}/getCosmosConfigAtPath.d.ts +1 -1
- package/dist/server/cosmosConfig/getCosmosConfigAtPath.js +12 -0
- package/dist/server/cosmosConfig/shared.d.ts +2 -0
- package/dist/server/cosmosConfig/shared.js +7 -0
- package/dist/{config/shared.d.ts → server/cosmosConfig/types.d.ts} +6 -5
- package/dist/server/cosmosPlugin/findCosmosPluginConfigs.d.ts +8 -0
- package/dist/server/cosmosPlugin/findCosmosPluginConfigs.js +14 -0
- package/dist/server/cosmosPlugin/pluginConfigs.d.ts +8 -0
- package/dist/server/cosmosPlugin/pluginConfigs.js +16 -0
- package/dist/server/cosmosPlugin/readCosmosPluginConfig.d.ts +8 -0
- package/dist/server/cosmosPlugin/readCosmosPluginConfig.js +31 -0
- package/dist/server/cosmosPlugin/types.d.ts +21 -0
- package/dist/server/devServer/corePlugins/httpProxy.d.ts +2 -0
- package/dist/server/devServer/corePlugins/httpProxy.js +18 -0
- package/dist/server/devServer/corePlugins/openFile.d.ts +2 -0
- package/dist/server/devServer/corePlugins/openFile.js +53 -0
- package/dist/server/devServer/corePlugins/pluginEndpoint.d.ts +2 -0
- package/dist/server/devServer/corePlugins/pluginEndpoint.js +17 -0
- package/dist/server/devServer/corePlugins/userDepsFile.d.ts +2 -0
- package/dist/server/devServer/corePlugins/userDepsFile.js +37 -0
- package/dist/server/devServer/expressApp.d.ts +5 -0
- package/dist/server/devServer/expressApp.js +21 -0
- package/dist/server/devServer/httpServer.d.ts +12 -0
- package/dist/server/devServer/httpServer.js +42 -0
- package/dist/{devServer → server/devServer}/messageHandler.d.ts +2 -2
- package/dist/server/devServer/messageHandler.js +29 -0
- package/dist/server/devServer/startDevServer.d.ts +2 -0
- package/dist/server/devServer/startDevServer.js +93 -0
- package/dist/server/export/generateExport.d.ts +1 -0
- package/dist/server/export/generateExport.js +97 -0
- package/dist/server/getFixtures/getFixtures.d.ts +14 -0
- package/dist/server/getFixtures/getFixtures.js +63 -0
- package/dist/server/shared/logPluginInfo.d.ts +2 -0
- package/dist/server/shared/logPluginInfo.js +8 -0
- package/dist/server/shared/playgroundHtml.d.ts +6 -0
- package/dist/server/shared/playgroundHtml.js +85 -0
- package/dist/server/shared/playgroundUrl.d.ts +2 -0
- package/dist/server/shared/playgroundUrl.js +6 -0
- package/dist/server/shared/requirePluginModule.d.ts +2 -0
- package/dist/server/shared/requirePluginModule.js +10 -0
- package/dist/server/shared/resolveRendererUrl.d.ts +1 -0
- package/dist/server/shared/resolveRendererUrl.js +7 -0
- package/dist/server/shared/staticPath.d.ts +1 -0
- package/dist/server/shared/staticPath.js +4 -0
- package/dist/{shared/static.d.ts → server/shared/staticServer.d.ts} +0 -1
- package/dist/server/shared/staticServer.js +12 -0
- package/dist/{shared → server}/static/index.html +1 -1
- package/dist/server/testHelpers/cwd.d.ts +1 -0
- package/dist/server/testHelpers/cwd.js +4 -0
- package/dist/server/testHelpers/mockConsole.d.ts +5 -0
- package/dist/server/testHelpers/mockConsole.js +11 -0
- package/dist/server/testHelpers/mockEsmRequire.js +13 -0
- package/dist/server/testHelpers/mockEsmResolve.d.ts +1 -0
- package/dist/server/testHelpers/mockEsmResolve.js +13 -0
- package/dist/server/testHelpers/mockEsmStaticPath.d.ts +1 -0
- package/dist/server/testHelpers/mockEsmStaticPath.js +7 -0
- package/dist/server/testHelpers/mockFetch.d.ts +2 -0
- package/dist/server/testHelpers/mockFetch.js +7 -0
- package/dist/server/testHelpers/mockFs.d.ts +5 -0
- package/dist/server/testHelpers/mockFs.js +64 -0
- package/dist/server/testHelpers/mockYargs.d.ts +2 -0
- package/dist/server/testHelpers/mockYargs.js +21 -0
- package/dist/{userDeps → server/userDeps}/findUserModulePaths.d.ts +4 -3
- package/dist/server/userDeps/findUserModulePaths.js +20 -0
- package/dist/server/userDeps/fixtureWatcher.d.ts +3 -0
- package/dist/server/userDeps/fixtureWatcher.js +20 -0
- package/dist/{userDeps → server/userDeps}/generateUserDepsModule.d.ts +3 -3
- package/dist/server/userDeps/generateUserDepsModule.js +19 -0
- package/dist/{userDeps → server/userDeps}/getUserModules.d.ts +4 -4
- package/dist/server/userDeps/getUserModules.js +26 -0
- package/dist/{userDeps → server/userDeps}/shared.d.ts +1 -2
- package/dist/server/userDeps/shared.js +16 -0
- package/dist/{userDeps → server/userDeps}/userDepsTemplate.d.ts +2 -2
- package/dist/server/userDeps/userDepsTemplate.js +49 -0
- package/dist/server/utils/cli.js +4 -0
- package/dist/server/utils/fs.d.ts +4 -0
- package/dist/server/utils/fs.js +24 -0
- package/dist/server/utils/isNodeError.d.ts +2 -0
- package/dist/server/utils/isNodeError.js +3 -0
- package/dist/server/utils/requireModule.d.ts +2 -0
- package/dist/server/utils/requireModule.js +13 -0
- package/dist/server/utils/requireSilent.d.ts +1 -0
- package/dist/server/utils/requireSilent.js +11 -0
- package/dist/server/utils/resolve.d.ts +2 -0
- package/dist/server/utils/resolve.js +14 -0
- package/dist/server/utils/resolveLoose.d.ts +1 -0
- package/dist/server/utils/resolveLoose.js +12 -0
- package/dist/server/utils/resolveSilent.d.ts +2 -0
- package/dist/server/utils/resolveSilent.js +22 -0
- package/dist/server/utils/slash.d.ts +1 -0
- package/dist/server/utils/slash.js +5 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +20 -0
- package/index.d.ts +1 -1
- package/index.js +1 -2
- package/jest.d.ts +1 -0
- package/jest.js +1 -0
- package/package.json +17 -28
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/dist/config/createCosmosConfig.js +0 -133
- package/dist/config/detectCosmosConfig.d.ts +0 -2
- package/dist/config/detectCosmosConfig.js +0 -57
- package/dist/config/getCosmosConfigAtPath.js +0 -28
- package/dist/config/resolveModule.d.ts +0 -1
- package/dist/config/resolveModule.js +0 -20
- package/dist/config/shared.js +0 -17
- package/dist/devServer/app.d.ts +0 -5
- package/dist/devServer/app.js +0 -51
- package/dist/devServer/httpServer.d.ts +0 -11
- package/dist/devServer/httpServer.js +0 -183
- package/dist/devServer/messageHandler.js +0 -42
- package/dist/devServer/startDevServer.d.ts +0 -18
- package/dist/devServer/startDevServer.js +0 -209
- package/dist/dom/DomFixtureLoader.d.ts +0 -9
- package/dist/dom/DomFixtureLoader.js +0 -38
- package/dist/dom/ErrorCatch.d.ts +0 -15
- package/dist/dom/ErrorCatch.js +0 -117
- package/dist/dom/container.d.ts +0 -1
- package/dist/dom/container.js +0 -32
- package/dist/dom/globalErrorHandler.js +0 -14
- package/dist/dom/index.d.ts +0 -13
- package/dist/dom/index.js +0 -47
- package/dist/dom/renderMessage.d.ts +0 -4
- package/dist/dom/renderMessage.js +0 -30
- package/dist/dom/rendererConnect.d.ts +0 -1
- package/dist/dom/rendererConnect.js +0 -18
- package/dist/dom/rendererId.d.ts +0 -1
- package/dist/dom/rendererId.js +0 -26
- package/dist/dom/selectedFixtureId.d.ts +0 -2
- package/dist/dom/selectedFixtureId.js +0 -41
- package/dist/dom/shared.d.ts +0 -1
- package/dist/dom/shared.js +0 -14
- package/dist/export/generateExport.d.ts +0 -6
- package/dist/export/generateExport.js +0 -137
- package/dist/fixture.d.ts +0 -1
- package/dist/fixture.js +0 -31
- package/dist/generateWebExport.d.ts +0 -1
- package/dist/generateWebExport.js +0 -37
- package/dist/getFixtureUrls.d.ts +0 -8
- package/dist/getFixtureUrls.js +0 -97
- package/dist/getFixtures.d.ts +0 -13
- package/dist/getFixtures.js +0 -89
- package/dist/getFixtures2.d.ts +0 -14
- package/dist/getFixtures2.js +0 -117
- package/dist/native/NativeFixtureLoader.d.ts +0 -12
- package/dist/native/NativeFixtureLoader.js +0 -67
- package/dist/native/index.d.ts +0 -1
- package/dist/native/index.js +0 -25
- package/dist/plugins/httpProxy.d.ts +0 -2
- package/dist/plugins/httpProxy.js +0 -31
- package/dist/plugins/openFile.d.ts +0 -2
- package/dist/plugins/openFile.js +0 -87
- package/dist/plugins/userDepsFile.d.ts +0 -2
- package/dist/plugins/userDepsFile.js +0 -166
- package/dist/plugins/webpack/client/errorOverlay/index.d.ts +0 -1
- package/dist/plugins/webpack/client/errorOverlay/index.js +0 -16
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.d.ts +0 -2
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.js +0 -63
- package/dist/plugins/webpack/client/hmrErrorHandler.js +0 -16
- package/dist/plugins/webpack/client/index.d.ts +0 -6
- package/dist/plugins/webpack/client/index.js +0 -43
- package/dist/plugins/webpack/client/reactDevtoolsHook.d.ts +0 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.js +0 -19
- package/dist/plugins/webpack/client/userDeps.d.ts +0 -5
- package/dist/plugins/webpack/client/userDeps.js +0 -15
- package/dist/plugins/webpack/cosmosConfig/dom.d.ts +0 -6
- package/dist/plugins/webpack/cosmosConfig/dom.js +0 -19
- package/dist/plugins/webpack/cosmosConfig/webpack.d.ts +0 -10
- package/dist/plugins/webpack/cosmosConfig/webpack.js +0 -95
- package/dist/plugins/webpack/devServer.d.ts +0 -2
- package/dist/plugins/webpack/devServer.js +0 -168
- package/dist/plugins/webpack/export.d.ts +0 -2
- package/dist/plugins/webpack/export.js +0 -139
- package/dist/plugins/webpack/index.d.ts +0 -2
- package/dist/plugins/webpack/index.js +0 -21
- package/dist/plugins/webpack/shared.d.ts +0 -2
- package/dist/plugins/webpack/shared.js +0 -22
- package/dist/plugins/webpack/webpackConfig/getDefaultWebpackConfig.d.ts +0 -2
- package/dist/plugins/webpack/webpackConfig/getDefaultWebpackConfig.js +0 -152
- package/dist/plugins/webpack/webpackConfig/getDevWebpackConfig.d.ts +0 -3
- package/dist/plugins/webpack/webpackConfig/getDevWebpackConfig.js +0 -146
- package/dist/plugins/webpack/webpackConfig/getExportWebpackConfig.d.ts +0 -3
- package/dist/plugins/webpack/webpackConfig/getExportWebpackConfig.js +0 -111
- package/dist/plugins/webpack/webpackConfig/getUserWebpackConfig.d.ts +0 -3
- package/dist/plugins/webpack/webpackConfig/getUserWebpackConfig.js +0 -136
- package/dist/plugins/webpack/webpackConfig/getWebpackConfigModule.d.ts +0 -2
- package/dist/plugins/webpack/webpackConfig/getWebpackConfigModule.js +0 -45
- package/dist/plugins/webpack/webpackConfig/getWebpackConfigResolve.d.ts +0 -4
- package/dist/plugins/webpack/webpackConfig/getWebpackConfigResolve.js +0 -107
- package/dist/plugins/webpack/webpackConfig/getWebpackNodeEnv.d.ts +0 -1
- package/dist/plugins/webpack/webpackConfig/getWebpackNodeEnv.js +0 -12
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.d.ts +0 -16
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.js +0 -80
- package/dist/plugins/webpack/webpackConfig/plugins.d.ts +0 -5
- package/dist/plugins/webpack/webpackConfig/plugins.js +0 -37
- package/dist/plugins/webpack/webpackConfig/resolveWebpackClientPath.d.ts +0 -1
- package/dist/plugins/webpack/webpackConfig/resolveWebpackClientPath.js +0 -10
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.js +0 -36
- package/dist/shared/cli.js +0 -14
- package/dist/shared/fs.d.ts +0 -4
- package/dist/shared/fs.js +0 -37
- package/dist/shared/playgroundHtml.d.ts +0 -6
- package/dist/shared/playgroundHtml.js +0 -116
- package/dist/shared/pluginConfigs.d.ts +0 -2
- package/dist/shared/pluginConfigs.js +0 -15
- package/dist/shared/rendererConfig.d.ts +0 -6
- package/dist/shared/rendererConfig.js +0 -5
- package/dist/shared/static.js +0 -30
- package/dist/shared/types.d.ts +0 -1
- package/dist/shared/types.js +0 -5
- package/dist/shared/utils.d.ts +0 -5
- package/dist/shared/utils.js +0 -22
- package/dist/startNativeServer.d.ts +0 -1
- package/dist/startNativeServer.js +0 -39
- package/dist/startWebServer.d.ts +0 -1
- package/dist/startWebServer.js +0 -43
- package/dist/userDeps/findUserModulePaths.js +0 -45
- package/dist/userDeps/generateUserDepsModule.js +0 -37
- package/dist/userDeps/getUserModules.js +0 -45
- package/dist/userDeps/shared.js +0 -32
- package/dist/userDeps/userDepsTemplate.js +0 -52
- package/dom.d.ts +0 -1
- package/dom.js +0 -2
- package/fixture.d.ts +0 -1
- package/fixture.js +0 -2
- package/native.d.ts +0 -1
- package/native.js +0 -2
- package/yarn-error.log +0 -13450
- /package/dist/{dom/globalErrorHandler.d.ts → server/cosmosConfig/types.js} +0 -0
- /package/dist/{plugins/webpack/client/hmrErrorHandler.d.ts → server/cosmosPlugin/types.js} +0 -0
- /package/dist/{shared → server}/static/favicon.ico +0 -0
- /package/dist/{plugins/webpack/webpackConfig/userDepsLoader.d.ts → server/testHelpers/mockEsmRequire.d.ts} +0 -0
- /package/dist/{shared → server/utils}/cli.d.ts +0 -0
package/bin/cosmos-export.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// Set the env before any code reads it
|
|
4
4
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const { generateExport } = await import(
|
|
7
|
+
'../dist/server/export/generateExport.js'
|
|
8
|
+
);
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
generateExport().catch(err => {
|
|
10
11
|
console.log('[Cosmos] Export failed...');
|
|
11
12
|
console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
|
|
12
13
|
console.log(err);
|
package/bin/cosmos-native.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// Set the env before any code reads it
|
|
4
4
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const { startDevServer } = await import(
|
|
7
|
+
'../dist/server/devServer/startDevServer.js'
|
|
8
|
+
);
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
startDevServer('native').catch(err => {
|
|
10
11
|
console.log('[Cosmos] Server crashed...');
|
|
11
12
|
console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
|
|
12
13
|
console.log(err);
|
package/bin/cosmos.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
// Set the env before any code reads it
|
|
4
4
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
5
5
|
|
|
6
|
+
const { startDevServer } = await import(
|
|
7
|
+
'../dist/server/devServer/startDevServer.js'
|
|
8
|
+
);
|
|
9
|
+
|
|
6
10
|
// Auto disable Fast Refresh in CRA 4 until integration is implemented
|
|
7
11
|
// https://github.com/react-cosmos/react-cosmos/issues/1272
|
|
8
12
|
process.env.FAST_REFRESH = process.env.FAST_REFRESH || false;
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
const { startWebServer } = require('../dist/startWebServer');
|
|
12
|
-
|
|
13
|
-
startWebServer().catch(err => {
|
|
14
|
+
startDevServer('web').catch(err => {
|
|
14
15
|
console.log('[Cosmos] Server crashed...');
|
|
15
16
|
console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
|
|
16
17
|
console.log(err);
|
package/config.schema.json
CHANGED
|
@@ -17,8 +17,12 @@
|
|
|
17
17
|
"type": "string",
|
|
18
18
|
"minLength": 1
|
|
19
19
|
},
|
|
20
|
+
"detectLocalPlugins": {
|
|
21
|
+
"description": "Automatically detect and load local plugins",
|
|
22
|
+
"type": "boolean"
|
|
23
|
+
},
|
|
20
24
|
"disablePlugins": {
|
|
21
|
-
"description": "Disable plugins",
|
|
25
|
+
"description": "Disable all plugins 3rd party plugins",
|
|
22
26
|
"type": "boolean"
|
|
23
27
|
},
|
|
24
28
|
"staticPath": {
|
|
@@ -26,6 +30,12 @@
|
|
|
26
30
|
"type": "string",
|
|
27
31
|
"minLength": 1
|
|
28
32
|
},
|
|
33
|
+
"plugins": {
|
|
34
|
+
"description": "Module IDs of Cosmos plugins (eg. \"react-cosmos-plugin-open-fixture\" or \"../path/to/my-plugin\").",
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": { "type": "string", "minLength": 1 },
|
|
37
|
+
"uniqueItems": true
|
|
38
|
+
},
|
|
29
39
|
"publicUrl": {
|
|
30
40
|
"description": "Base URL for static assets. [default: \"/\"]",
|
|
31
41
|
"type": "string"
|
|
@@ -40,6 +50,12 @@
|
|
|
40
50
|
"type": "string",
|
|
41
51
|
"minLength": 1
|
|
42
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
|
+
},
|
|
43
59
|
"watchDirs": {
|
|
44
60
|
"description": "Directories where the Cosmos server watches for fixture files changes while running. [default: [\".\"]]",
|
|
45
61
|
"type": "array",
|
|
@@ -117,8 +133,8 @@
|
|
|
117
133
|
"items": { "type": "string", "minLength": 1 },
|
|
118
134
|
"uniqueItems": true
|
|
119
135
|
},
|
|
120
|
-
"
|
|
121
|
-
"description": "
|
|
136
|
+
"rendererUrl": {
|
|
137
|
+
"description": "Required when renderer doesn't run on the same port (or host) as the Playground. Useful for integrations with build tools. [default: null]",
|
|
122
138
|
"anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
|
|
123
139
|
},
|
|
124
140
|
"dom": {
|
|
@@ -154,7 +170,7 @@
|
|
|
154
170
|
"type": "boolean"
|
|
155
171
|
},
|
|
156
172
|
"reloadOnFail": {
|
|
157
|
-
"description": "When using webpack's Hot Module Replacement, enable automatic location reload after webpack fails to update modules. [default:
|
|
173
|
+
"description": "When using webpack's Hot Module Replacement, enable automatic location reload after webpack fails to update modules. [default: false]",
|
|
158
174
|
"type": "boolean"
|
|
159
175
|
}
|
|
160
176
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { createCosmosConfig } from './config/createCosmosConfig';
|
|
2
|
-
export { detectCosmosConfig } from './config/detectCosmosConfig';
|
|
3
|
-
export { getCosmosConfigAtPath } from './config/getCosmosConfigAtPath';
|
|
4
|
-
export { getFixtures, getFixturesSync } from './getFixtures';
|
|
5
|
-
export { FixtureApi, getFixtures2 } from './getFixtures2';
|
|
6
|
-
export { getFixtureUrls, getFixtureUrlsSync } from './getFixtureUrls';
|
package/dist/index.js
CHANGED
|
@@ -1,71 +1 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "FixtureApi", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _getFixtures2.FixtureApi;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "createCosmosConfig", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _createCosmosConfig.createCosmosConfig;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "detectCosmosConfig", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return _detectCosmosConfig.detectCosmosConfig;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "getCosmosConfigAtPath", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function get() {
|
|
27
|
-
return _getCosmosConfigAtPath.getCosmosConfigAtPath;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "getFixtureUrls", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function get() {
|
|
33
|
-
return _getFixtureUrls.getFixtureUrls;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "getFixtureUrlsSync", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function get() {
|
|
39
|
-
return _getFixtureUrls.getFixtureUrlsSync;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "getFixtures", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function get() {
|
|
45
|
-
return _getFixtures.getFixtures;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "getFixtures2", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function get() {
|
|
51
|
-
return _getFixtures2.getFixtures2;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "getFixturesSync", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function get() {
|
|
57
|
-
return _getFixtures.getFixturesSync;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
var _createCosmosConfig = require("./config/createCosmosConfig");
|
|
62
|
-
|
|
63
|
-
var _detectCosmosConfig = require("./config/detectCosmosConfig");
|
|
64
|
-
|
|
65
|
-
var _getCosmosConfigAtPath = require("./config/getCosmosConfigAtPath");
|
|
66
|
-
|
|
67
|
-
var _getFixtures = require("./getFixtures");
|
|
68
|
-
|
|
69
|
-
var _getFixtures2 = require("./getFixtures2");
|
|
70
|
-
|
|
71
|
-
var _getFixtureUrls = require("./getFixtureUrls");
|
package/dist/jest.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './server/testHelpers/mockConsole.js';
|
|
2
|
+
export * from './server/testHelpers/mockEsmRequire.js';
|
|
3
|
+
export * from './server/testHelpers/mockEsmResolve.js';
|
|
4
|
+
export * from './server/testHelpers/mockEsmStaticPath.js';
|
|
5
|
+
export * from './server/testHelpers/mockFetch.js';
|
|
6
|
+
export * from './server/testHelpers/mockFs.js';
|
|
7
|
+
export * from './server/testHelpers/mockYargs.js';
|
package/dist/jest.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './server/testHelpers/mockConsole.js';
|
|
2
|
+
export * from './server/testHelpers/mockEsmRequire.js';
|
|
3
|
+
export * from './server/testHelpers/mockEsmResolve.js';
|
|
4
|
+
export * from './server/testHelpers/mockEsmStaticPath.js';
|
|
5
|
+
export * from './server/testHelpers/mockFetch.js';
|
|
6
|
+
export * from './server/testHelpers/mockFs.js';
|
|
7
|
+
export * from './server/testHelpers/mockYargs.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CosmosConfig, CosmosConfigInput } from './
|
|
1
|
+
import { CosmosConfig, CosmosConfigInput } from './types.js';
|
|
2
2
|
export declare function createCosmosConfig(rootDir: string, cosmosConfigInput?: CosmosConfigInput): CosmosConfig;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getCliArgs } from '../utils/cli.js';
|
|
3
|
+
import { resolveLoose } from '../utils/resolveLoose.js';
|
|
4
|
+
export function createCosmosConfig(rootDir, cosmosConfigInput = {}) {
|
|
5
|
+
return {
|
|
6
|
+
...cosmosConfigInput,
|
|
7
|
+
rootDir,
|
|
8
|
+
exportPath: getExportPath(cosmosConfigInput, rootDir),
|
|
9
|
+
detectLocalPlugins: cosmosConfigInput.detectLocalPlugins ?? true,
|
|
10
|
+
disablePlugins: cosmosConfigInput.disablePlugins ?? false,
|
|
11
|
+
fixtureFileSuffix: getFixtureFileSuffix(cosmosConfigInput),
|
|
12
|
+
fixturesDir: getFixturesDir(cosmosConfigInput),
|
|
13
|
+
globalImports: getGlobalImports(cosmosConfigInput, rootDir),
|
|
14
|
+
hostname: getHostname(cosmosConfigInput),
|
|
15
|
+
https: getHttps(cosmosConfigInput),
|
|
16
|
+
httpsOptions: getHttpsOptions(cosmosConfigInput, rootDir),
|
|
17
|
+
ignore: getIgnore(cosmosConfigInput),
|
|
18
|
+
port: getPort(cosmosConfigInput),
|
|
19
|
+
plugins: getPlugins(cosmosConfigInput, rootDir),
|
|
20
|
+
publicUrl: getPublicUrl(cosmosConfigInput),
|
|
21
|
+
staticPath: getStaticPath(cosmosConfigInput, rootDir),
|
|
22
|
+
userDepsFilePath: getUserDepsFilePath(cosmosConfigInput, rootDir),
|
|
23
|
+
watchDirs: getWatchDirs(cosmosConfigInput, rootDir),
|
|
24
|
+
rendererUrl: cosmosConfigInput.rendererUrl ?? null,
|
|
25
|
+
ui: cosmosConfigInput.ui || {},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getExportPath(cosmosConfigInput, rootDir) {
|
|
29
|
+
const { exportPath = 'cosmos-export' } = cosmosConfigInput;
|
|
30
|
+
return path.resolve(rootDir, exportPath);
|
|
31
|
+
}
|
|
32
|
+
function getStaticPath(cosmosConfigInput, rootDir) {
|
|
33
|
+
const { staticPath = null } = cosmosConfigInput;
|
|
34
|
+
return staticPath && path.resolve(rootDir, staticPath);
|
|
35
|
+
}
|
|
36
|
+
function getHttps(cosmosConfigInput) {
|
|
37
|
+
const { https = false } = cosmosConfigInput;
|
|
38
|
+
return https;
|
|
39
|
+
}
|
|
40
|
+
function getHttpsOptions(cosmosConfigInput, rootDir) {
|
|
41
|
+
if (cosmosConfigInput.httpsOptions?.keyPath &&
|
|
42
|
+
cosmosConfigInput.httpsOptions?.certPath) {
|
|
43
|
+
return {
|
|
44
|
+
keyPath: path.resolve(rootDir, cosmosConfigInput.httpsOptions.keyPath),
|
|
45
|
+
certPath: path.resolve(rootDir, cosmosConfigInput.httpsOptions.certPath),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function getIgnore({ ignore = [] }) {
|
|
51
|
+
return ['**/node_modules/**', ...ignore];
|
|
52
|
+
}
|
|
53
|
+
function getPublicUrl({ publicUrl = '/' }) {
|
|
54
|
+
return publicUrl;
|
|
55
|
+
}
|
|
56
|
+
function getFixturesDir({ fixturesDir = '__fixtures__' }) {
|
|
57
|
+
return fixturesDir;
|
|
58
|
+
}
|
|
59
|
+
function getFixtureFileSuffix({ fixtureFileSuffix = 'fixture', }) {
|
|
60
|
+
return fixtureFileSuffix;
|
|
61
|
+
}
|
|
62
|
+
function getWatchDirs(cosmosConfigInput, rootDir) {
|
|
63
|
+
const { watchDirs = ['.'] } = cosmosConfigInput;
|
|
64
|
+
return watchDirs.map(watchDir => path.resolve(rootDir, watchDir));
|
|
65
|
+
}
|
|
66
|
+
function getUserDepsFilePath(cosmosConfigInput, rootDir) {
|
|
67
|
+
const { userDepsFilePath = 'cosmos.userdeps.js' } = cosmosConfigInput;
|
|
68
|
+
return path.resolve(rootDir, userDepsFilePath);
|
|
69
|
+
}
|
|
70
|
+
function getHostname({ hostname = null }) {
|
|
71
|
+
return hostname;
|
|
72
|
+
}
|
|
73
|
+
function getPort(cosmosConfigInput) {
|
|
74
|
+
const cliArgs = getCliArgs();
|
|
75
|
+
if (typeof cliArgs.port === 'number') {
|
|
76
|
+
return cliArgs.port;
|
|
77
|
+
}
|
|
78
|
+
const { port = 5000 } = cosmosConfigInput;
|
|
79
|
+
return port;
|
|
80
|
+
}
|
|
81
|
+
function getGlobalImports(cosmosConfigInput, rootDir) {
|
|
82
|
+
const { globalImports = [] } = cosmosConfigInput;
|
|
83
|
+
return globalImports.map(globalImport => resolveLoose(rootDir, globalImport));
|
|
84
|
+
}
|
|
85
|
+
function getPlugins(cosmosConfigInput, rootDir) {
|
|
86
|
+
const { plugins = [] } = cosmosConfigInput;
|
|
87
|
+
return plugins.map(plugin => resolveLoose(rootDir, plugin));
|
|
88
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getCliArgs } from '../utils/cli.js';
|
|
3
|
+
import { dirExists, fileExists, moduleExists } from '../utils/fs.js';
|
|
4
|
+
import { createCosmosConfig } from './createCosmosConfig.js';
|
|
5
|
+
import { getCosmosConfigAtPath } from './getCosmosConfigAtPath.js';
|
|
6
|
+
import { getCurrentDir } from './shared.js';
|
|
7
|
+
export async function detectCosmosConfig() {
|
|
8
|
+
const cosmosConfigPath = detectCosmosConfigPath();
|
|
9
|
+
return cosmosConfigPath
|
|
10
|
+
? getCosmosConfigAtPath(cosmosConfigPath)
|
|
11
|
+
: createCosmosConfig(detectRootDir());
|
|
12
|
+
}
|
|
13
|
+
export function detectCosmosConfigPath() {
|
|
14
|
+
const rootDir = detectRootDir();
|
|
15
|
+
const cliArgs = getCliArgs();
|
|
16
|
+
// CLI support for --config path/to/cosmos.config.json
|
|
17
|
+
if (typeof cliArgs.config === 'string') {
|
|
18
|
+
if (path.extname(cliArgs.config) !== '.json')
|
|
19
|
+
throw new Error(`[Cosmos] Invalid config file type: ${cliArgs.config} (must be .json)`);
|
|
20
|
+
const absPath = path.resolve(rootDir, cliArgs.config);
|
|
21
|
+
if (!fileExists(absPath))
|
|
22
|
+
throw new Error(`[Cosmos] Config not found at path: ${cliArgs.config}`);
|
|
23
|
+
return absPath;
|
|
24
|
+
}
|
|
25
|
+
const defaultConfigPath = path.join(rootDir, 'cosmos.config.json');
|
|
26
|
+
return moduleExists(defaultConfigPath) ? defaultConfigPath : null;
|
|
27
|
+
}
|
|
28
|
+
function detectRootDir() {
|
|
29
|
+
const cliArgs = getCliArgs();
|
|
30
|
+
// CLI support for --root-dir path/to/project
|
|
31
|
+
if (typeof cliArgs.rootDir === 'string') {
|
|
32
|
+
const absPath = path.resolve(getCurrentDir(), cliArgs.rootDir);
|
|
33
|
+
if (!dirExists(absPath))
|
|
34
|
+
throw new Error(`[Cosmos] Dir not found at path: ${cliArgs.rootDir}`);
|
|
35
|
+
return absPath;
|
|
36
|
+
}
|
|
37
|
+
return getCurrentDir();
|
|
38
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getCosmosConfigAtPath(cosmosConfigPath: string): import("./
|
|
1
|
+
export declare function getCosmosConfigAtPath(cosmosConfigPath: string): Promise<import("./types.js").CosmosConfig>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { createCosmosConfig } from './createCosmosConfig.js';
|
|
3
|
+
import { importConfigFile } from './shared.js';
|
|
4
|
+
export async function getCosmosConfigAtPath(cosmosConfigPath) {
|
|
5
|
+
const cosmosConfigInput = await importConfigFile(cosmosConfigPath);
|
|
6
|
+
const rootDir = deriveRootDir(cosmosConfigPath, cosmosConfigInput);
|
|
7
|
+
return createCosmosConfig(rootDir, cosmosConfigInput);
|
|
8
|
+
}
|
|
9
|
+
function deriveRootDir(cosmosConfigPath, { rootDir }) {
|
|
10
|
+
const configDir = path.dirname(cosmosConfigPath);
|
|
11
|
+
return rootDir ? path.resolve(configDir, rootDir) : configDir;
|
|
12
|
+
}
|
|
@@ -2,8 +2,9 @@ interface HttpsOptions {
|
|
|
2
2
|
keyPath: string;
|
|
3
3
|
certPath: string;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export type CosmosConfig = {
|
|
6
6
|
exportPath: string;
|
|
7
|
+
detectLocalPlugins: boolean;
|
|
7
8
|
disablePlugins: boolean;
|
|
8
9
|
fixtureFileSuffix: string;
|
|
9
10
|
fixturesDir: string;
|
|
@@ -11,19 +12,19 @@ export declare type CosmosConfig = {
|
|
|
11
12
|
hostname: null | string;
|
|
12
13
|
https: boolean;
|
|
13
14
|
httpsOptions: null | HttpsOptions;
|
|
15
|
+
ignore: string[];
|
|
14
16
|
port: number;
|
|
17
|
+
plugins: string[];
|
|
15
18
|
publicUrl: string;
|
|
19
|
+
rendererUrl: string | null;
|
|
16
20
|
rootDir: string;
|
|
17
21
|
staticPath: null | string;
|
|
18
22
|
userDepsFilePath: string;
|
|
19
23
|
watchDirs: string[];
|
|
20
|
-
experimentalRendererUrl: string | null;
|
|
21
24
|
[option: string]: unknown;
|
|
22
25
|
ui: {
|
|
23
26
|
[pluginName: string]: {};
|
|
24
27
|
};
|
|
25
28
|
};
|
|
26
|
-
export
|
|
27
|
-
export declare function getCurrentDir(): string;
|
|
28
|
-
export declare function requireConfigFile(cosmosConfigPath: string): CosmosConfigInput;
|
|
29
|
+
export type CosmosConfigInput = Partial<CosmosConfig>;
|
|
29
30
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CosmosPluginConfig } from 'react-cosmos-core';
|
|
2
|
+
type Args = {
|
|
3
|
+
rootDir: string;
|
|
4
|
+
relativePaths: boolean;
|
|
5
|
+
ignore?: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function findCosmosPluginConfigs({ rootDir, relativePaths, ignore, }: Args): Promise<CosmosPluginConfig[]>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import glob from 'glob';
|
|
2
|
+
import { readCosmosPluginConfig } from './readCosmosPluginConfig.js';
|
|
3
|
+
export async function findCosmosPluginConfigs({ rootDir, relativePaths, ignore, }) {
|
|
4
|
+
const configPaths = findCosmosPluginConfigPaths(rootDir, ignore);
|
|
5
|
+
return Promise.all(configPaths.map(configPath => readCosmosPluginConfig({ rootDir, configPath, relativePaths })));
|
|
6
|
+
}
|
|
7
|
+
const defaultIgnore = ['**/node_modules/**'];
|
|
8
|
+
function findCosmosPluginConfigPaths(rootDir, ignore = defaultIgnore) {
|
|
9
|
+
return glob.sync('**/cosmos.plugin.json', {
|
|
10
|
+
cwd: rootDir,
|
|
11
|
+
absolute: true,
|
|
12
|
+
ignore,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CosmosPluginConfig } from 'react-cosmos-core';
|
|
2
|
+
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
3
|
+
type GetPluginConfigArgs = {
|
|
4
|
+
cosmosConfig: CosmosConfig;
|
|
5
|
+
relativePaths: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function getPluginConfigs({ cosmosConfig, relativePaths, }: GetPluginConfigArgs): Promise<CosmosPluginConfig[]>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { findCosmosPluginConfigs } from './findCosmosPluginConfigs.js';
|
|
2
|
+
import { readCosmosPluginConfig } from './readCosmosPluginConfig.js';
|
|
3
|
+
export async function getPluginConfigs({ cosmosConfig, relativePaths, }) {
|
|
4
|
+
const { rootDir, detectLocalPlugins, disablePlugins, plugins, exportPath } = cosmosConfig;
|
|
5
|
+
if (disablePlugins)
|
|
6
|
+
return [];
|
|
7
|
+
const moduleConfigs = await Promise.all(plugins.map(configPath => readCosmosPluginConfig({ rootDir, configPath, relativePaths })));
|
|
8
|
+
if (!detectLocalPlugins)
|
|
9
|
+
return moduleConfigs;
|
|
10
|
+
const localConfigs = await findCosmosPluginConfigs({
|
|
11
|
+
rootDir,
|
|
12
|
+
ignore: ['**/node_modules/**', `${exportPath}/**`],
|
|
13
|
+
relativePaths,
|
|
14
|
+
});
|
|
15
|
+
return [...moduleConfigs, ...localConfigs];
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CosmosPluginConfig } from 'react-cosmos-core';
|
|
2
|
+
type ReadCosmosPluginConfigArgs = {
|
|
3
|
+
rootDir: string;
|
|
4
|
+
configPath: string;
|
|
5
|
+
relativePaths: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function readCosmosPluginConfig({ rootDir, configPath, relativePaths, }: ReadCosmosPluginConfigArgs): Promise<CosmosPluginConfig>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { importModule } from '../utils/fs.js';
|
|
3
|
+
import { resolveSilent } from '../utils/resolveSilent.js';
|
|
4
|
+
export async function readCosmosPluginConfig({ rootDir, configPath, relativePaths, }) {
|
|
5
|
+
const rawConfig = await importModule(configPath);
|
|
6
|
+
const pluginRootDir = path.dirname(configPath);
|
|
7
|
+
const config = {
|
|
8
|
+
name: rawConfig.name,
|
|
9
|
+
rootDir: relativePaths
|
|
10
|
+
? path.relative(rootDir, pluginRootDir)
|
|
11
|
+
: pluginRootDir,
|
|
12
|
+
};
|
|
13
|
+
if (rawConfig.ui) {
|
|
14
|
+
config.ui = resolvePluginPath(config.name, rootDir, pluginRootDir, rawConfig.ui, relativePaths);
|
|
15
|
+
}
|
|
16
|
+
if (rawConfig.devServer) {
|
|
17
|
+
config.devServer = resolvePluginPath(config.name, rootDir, pluginRootDir, rawConfig.devServer, relativePaths);
|
|
18
|
+
}
|
|
19
|
+
if (rawConfig.export) {
|
|
20
|
+
config.export = resolvePluginPath(config.name, rootDir, pluginRootDir, rawConfig.export, relativePaths);
|
|
21
|
+
}
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
function resolvePluginPath(pluginName, rootDir, pluginRootDir, filePath, relativePath) {
|
|
25
|
+
const absolutePath = path.join(pluginRootDir, filePath);
|
|
26
|
+
const resolvedPath = resolveSilent(absolutePath);
|
|
27
|
+
if (!resolvedPath) {
|
|
28
|
+
throw new Error(`Invalid path in plugin "${pluginName}": ${filePath}`);
|
|
29
|
+
}
|
|
30
|
+
return relativePath ? path.relative(rootDir, resolvedPath) : resolvedPath;
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import { MessageType } from 'react-cosmos-core';
|
|
5
|
+
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
6
|
+
export type PlatformType = 'web' | 'native';
|
|
7
|
+
export type DevServerPluginArgs = {
|
|
8
|
+
cosmosConfig: CosmosConfig;
|
|
9
|
+
platformType: PlatformType;
|
|
10
|
+
httpServer: http.Server;
|
|
11
|
+
expressApp: express.Express;
|
|
12
|
+
sendMessage(msg: MessageType): unknown;
|
|
13
|
+
};
|
|
14
|
+
export type DevServerPluginCleanupCallback = () => unknown;
|
|
15
|
+
export type DevServerPluginReturnValue = void | null | DevServerPluginCleanupCallback;
|
|
16
|
+
export type DevServerPluginReturn = DevServerPluginReturnValue | Promise<DevServerPluginReturnValue>;
|
|
17
|
+
export type DevServerPlugin = (args: DevServerPluginArgs) => DevServerPluginReturn;
|
|
18
|
+
export type ExportPluginArgs = {
|
|
19
|
+
cosmosConfig: CosmosConfig;
|
|
20
|
+
};
|
|
21
|
+
export type ExportPlugin = (args: ExportPluginArgs) => unknown;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
2
|
+
export function httpProxyDevServerPlugin({ platformType, cosmosConfig, expressApp, }) {
|
|
3
|
+
if (platformType !== 'web')
|
|
4
|
+
return;
|
|
5
|
+
const httpProxyConfig = getHttpProxyCosmosConfig(cosmosConfig);
|
|
6
|
+
Object.keys(httpProxyConfig).forEach(context => {
|
|
7
|
+
const config = httpProxyConfig[context];
|
|
8
|
+
if (typeof config === 'string') {
|
|
9
|
+
expressApp.use(context, createProxyMiddleware(context, { target: config }));
|
|
10
|
+
}
|
|
11
|
+
else if (typeof config === 'object') {
|
|
12
|
+
expressApp.use(context, createProxyMiddleware(context, config));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function getHttpProxyCosmosConfig(cosmosConfig) {
|
|
17
|
+
return (cosmosConfig.httpProxy || {});
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import launchEditor from '@skidding/launch-editor';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import open from 'open';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
export default function openFileDevServerPlugin({ cosmosConfig, expressApp, }) {
|
|
6
|
+
expressApp.get('/_open', (req, res) => {
|
|
7
|
+
const { filePath, line, column } = getReqQuery(req);
|
|
8
|
+
if (!filePath) {
|
|
9
|
+
res.status(400).send(`File path missing`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const absFilePath = resolveFilePath(cosmosConfig.rootDir, filePath);
|
|
13
|
+
if (!fs.existsSync(absFilePath)) {
|
|
14
|
+
res.status(404).send(`File not found at path: ${absFilePath}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
new Promise((resolve, reject) => {
|
|
18
|
+
const file = `${absFilePath}:${line}:${column}`;
|
|
19
|
+
launchEditor(file, (fileName, errorMsg) => reject(errorMsg));
|
|
20
|
+
// If launchEditor doesn't report error within 500ms we assume it worked
|
|
21
|
+
setTimeout(resolve, 500);
|
|
22
|
+
})
|
|
23
|
+
// Fall back to open in case launchEditor fails. launchEditor only works
|
|
24
|
+
// when the editor app is already open, but is favorable because it can
|
|
25
|
+
// open a code file on a specific line & column.
|
|
26
|
+
.catch(err => open(absFilePath))
|
|
27
|
+
.catch(err => res.status(500).send('Failed to open file'))
|
|
28
|
+
.then(() => res.send());
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function getReqQuery(req) {
|
|
32
|
+
const { filePath, line, column } = req.query;
|
|
33
|
+
if (typeof filePath !== 'string')
|
|
34
|
+
throw new Error('filePath missing');
|
|
35
|
+
return {
|
|
36
|
+
filePath,
|
|
37
|
+
line: typeof line === 'string' ? parseInt(line, 10) : 1,
|
|
38
|
+
column: typeof column === 'string' ? parseInt(column, 10) : 1,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function resolveFilePath(rootDir, filePath) {
|
|
42
|
+
// This heuristic is needed because the open file endpoint is used for
|
|
43
|
+
// multiple applications, which provide different file path types:
|
|
44
|
+
// 1. Edit fixture button: Sends path relative to Cosmos rootDir
|
|
45
|
+
// 2. react-error-overlay runtime error: Sends absolute path
|
|
46
|
+
// 3. react-error-overlay compile error: Sends path relative to CWD
|
|
47
|
+
if (path.isAbsolute(filePath)) {
|
|
48
|
+
return filePath;
|
|
49
|
+
}
|
|
50
|
+
const cosmosRelPath = path.join(rootDir, filePath);
|
|
51
|
+
const cwdRelPath = path.join(process.cwd(), filePath);
|
|
52
|
+
return fs.existsSync(cosmosRelPath) ? cosmosRelPath : cwdRelPath;
|
|
53
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolveFromSilent, resolveSilent } from '../../utils/resolveSilent.js';
|
|
2
|
+
export default function pluginEndpointDevServerPlugin({ cosmosConfig, expressApp, }) {
|
|
3
|
+
expressApp.get('/_plugin/*.js', (req, res) => {
|
|
4
|
+
const moduleId = req.params['0'];
|
|
5
|
+
if (!moduleId) {
|
|
6
|
+
res.sendStatus(404);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const resolvedPath = resolveSilent(`/${moduleId}`) ||
|
|
10
|
+
resolveFromSilent(cosmosConfig.rootDir, moduleId);
|
|
11
|
+
if (!resolvedPath) {
|
|
12
|
+
res.sendStatus(404);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
res.sendFile(resolvedPath);
|
|
16
|
+
});
|
|
17
|
+
}
|