@shijiu/jsview 2.3.0 → 3.0.0-next-vue.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.
Files changed (78) hide show
  1. package/dom/bin/jsview-dom-browser-engine-core.min.js +1 -1
  2. package/dom/bin/jsview-dom-browser-engine-modules.min.js +1 -1
  3. package/dom/bin/{jsview-dom-browser-forge.1436.54c9.wasm → jsview-dom-browser-forge.1760.0e35.wasm} +0 -0
  4. package/dom/bin/jsview-dom-browser-forge.min.js +1 -1
  5. package/dom/bin/jsview-dom-browser-forge.worker.min.js +1 -1
  6. package/dom/bin/jsview-dom-browser.min.js +1 -1
  7. package/dom/bin/jsview-dom-native.min.js +1 -1
  8. package/dom/bin/jsview-engine-js-native.min.js +1 -1
  9. package/dom/target_core_revision.mjs +2 -2
  10. package/loader/jsv-core-api/jsview-core-api-glue.js +10 -1
  11. package/loader/jsv-core-api/wasm/core-api.js +87 -1
  12. package/loader/jsv-core-api/wasm/wasm-extension.js +5 -0
  13. package/loader/jsview-loader.js +7 -0
  14. package/loader/jsview-main.mjs +2 -1
  15. package/loader/jsview.config.default.js +4 -0
  16. package/package.json +7 -5
  17. package/patches/@vitejs+plugin-vue+4.0.0.patch +51 -0
  18. package/patches/@vitejs+plugin-vue+6.0.6.patch +54 -0
  19. package/patches/@vue+compiler-dom+3.2.45.patch +22 -0
  20. package/patches/@vue+compiler-dom+3.6.0-beta.10.patch +22 -0
  21. package/patches/@vue+compiler-sfc+3.2.45.patch +1986 -0
  22. package/patches/@vue+compiler-sfc+3.6.0-beta.10.patch +69 -0
  23. package/patches/@vue+runtime-core+3.2.45.patch +353 -0
  24. package/patches/@vue+runtime-core+3.6.0-beta.10.patch +196 -0
  25. package/patches/@vue+runtime-dom+3.2.45.patch +81 -0
  26. package/patches/@vue+runtime-dom+3.6.0-beta.10.patch +47 -0
  27. package/patches/postcss-js+5.1.0.patch +20 -0
  28. package/patches/vite+4.0.0.patch +117 -0
  29. package/patches/vite+8.0.9.patch +77 -0
  30. package/patches/vue-router+4.1.6.patch +17 -0
  31. package/patches/vue-router+5.0.6.patch +0 -0
  32. package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js → thirdparty/@vue/compiler-sfc/jsview-css-to-js.cjs} +15 -10
  33. package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-checker.js → thirdparty/@vue/compiler-sfc/jsview-style-checker.cjs} +6 -1
  34. package/{patches/node_modules/@vue/compiler-sfc/dist/jsview-style-formator.cjs.js → thirdparty/@vue/compiler-sfc/jsview-style-formator.cjs} +3 -0
  35. package/thirdparty/@vue/runtime-core/jsview-render-break.mjs +189 -0
  36. package/thirdparty/vite/jsview-vite-extension.mjs +336 -0
  37. package/tools/jsview-build-zip.mjs +7 -2
  38. package/tools/jsview-common.mjs +18 -4
  39. package/tools/{jsview-logger.js → jsview-logger.cjs} +1 -1
  40. package/tools/jsview-post-build.mjs +88 -6
  41. package/tools/jsview-post-install.mjs +110 -103
  42. package/tools/jsview-run-tool.mjs +3 -6
  43. package/tools/jsview-vue-devtools.mjs +1 -1
  44. package/loader/jsview-react-main.js +0 -37
  45. package/loader/jsview-react-script-loader.js +0 -134
  46. package/patches/node_modules/@vitejs/plugin-react/dist/index.cjs +0 -520
  47. package/patches/node_modules/@vitejs/plugin-react/package.json +0 -55
  48. package/patches/node_modules/@vitejs/plugin-vue/dist/index.mjs +0 -2756
  49. package/patches/node_modules/@vitejs/plugin-vue/package.json +0 -51
  50. package/patches/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js +0 -3152
  51. package/patches/node_modules/@vue/compiler-dom/package.json +0 -43
  52. package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -17730
  53. package/patches/node_modules/@vue/compiler-sfc/package.json +0 -59
  54. package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +0 -8154
  55. package/patches/node_modules/@vue/runtime-core/package.json +0 -38
  56. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.d.ts +0 -1531
  57. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1740
  58. package/patches/node_modules/@vue/runtime-dom/package.json +0 -42
  59. package/patches/node_modules/postcss-js/objectifier.js +0 -94
  60. package/patches/node_modules/postcss-js/package.json +0 -42
  61. package/patches/node_modules/react-dev-utils/WebpackDevServerUtils.js +0 -450
  62. package/patches/node_modules/react-dev-utils/package.json +0 -88
  63. package/patches/node_modules/react-dom/cjs/react-dom.development.js +0 -29868
  64. package/patches/node_modules/react-dom/cjs/react-dom.production.min.js +0 -323
  65. package/patches/node_modules/react-dom/package.json +0 -62
  66. package/patches/node_modules/react-scripts/config/paths.js +0 -179
  67. package/patches/node_modules/react-scripts/config/webpack.config.js +0 -858
  68. package/patches/node_modules/react-scripts/package.json +0 -108
  69. package/patches/node_modules/vite/dist/node/chunks/dep-ed9cb113.js +0 -63182
  70. package/patches/node_modules/vite/dist/node/constants.js +0 -125
  71. package/patches/node_modules/vite/dist/node/jsview-vite-extension.js +0 -245
  72. package/patches/node_modules/vite/package.json +0 -153
  73. package/patches/node_modules/vue-router/dist/vue-router.mjs +0 -3613
  74. package/patches/node_modules/vue-router/package.json +0 -114
  75. package/patches/node_modules/webpack-dev-server/client/utils/reloadApp.js +0 -76
  76. package/patches/node_modules/webpack-dev-server/client/utils/sendMessage.js +0 -21
  77. package/patches/node_modules/webpack-dev-server/package.json +0 -141
  78. /package/patches/{node_modules/@originjs/vite-plugin-federation/1.3.4/@originjs+vite-plugin-federation+1.3.4.patch → @originjs+vite-plugin-federation+1.3.4.patch} +0 -0
@@ -1,42 +0,0 @@
1
- {
2
- "name": "@vue/runtime-dom",
3
- "version": "3.2.45",
4
- "description": "@vue/runtime-dom",
5
- "main": "index.js",
6
- "module": "dist/runtime-dom.esm-bundler.js",
7
- "types": "dist/runtime-dom.d.ts",
8
- "unpkg": "dist/runtime-dom.global.js",
9
- "files": [
10
- "index.js",
11
- "dist"
12
- ],
13
- "sideEffects": false,
14
- "buildOptions": {
15
- "name": "VueRuntimeDOM",
16
- "formats": [
17
- "esm-bundler",
18
- "esm-browser",
19
- "cjs",
20
- "global"
21
- ]
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/vuejs/core.git",
26
- "directory": "packages/runtime-dom"
27
- },
28
- "keywords": [
29
- "vue"
30
- ],
31
- "author": "Evan You",
32
- "license": "MIT",
33
- "bugs": {
34
- "url": "https://github.com/vuejs/core/issues"
35
- },
36
- "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-dom#readme",
37
- "dependencies": {
38
- "@vue/shared": "3.2.45",
39
- "@vue/runtime-core": "3.2.45",
40
- "csstype": "^2.6.8"
41
- }
42
- }
@@ -1,94 +0,0 @@
1
- let camelcase = require('camelcase-css')
2
-
3
- let UNITLESS = {
4
- // JsView Added >>>
5
- // 添加将px转为int的属性,用于Css转为Js。
6
- height: true,
7
- left: true,
8
- top: true,
9
- width: true,
10
-
11
- fontSize: true,
12
- lineHeight: true,
13
- // JsView Added <<<
14
-
15
- boxFlex: true,
16
- boxFlexGroup: true,
17
- columnCount: true,
18
- flex: true,
19
- flexGrow: true,
20
- flexPositive: true,
21
- flexShrink: true,
22
- flexNegative: true,
23
- fontWeight: true,
24
- lineClamp: true,
25
- lineHeight: true,
26
- opacity: true,
27
- order: true,
28
- orphans: true,
29
- tabSize: true,
30
- widows: true,
31
- zIndex: true,
32
- zoom: true,
33
- fillOpacity: true,
34
- strokeDashoffset: true,
35
- strokeOpacity: true,
36
- strokeWidth: true
37
- }
38
-
39
- function atRule(node) {
40
- if (typeof node.nodes === 'undefined') {
41
- return true
42
- } else {
43
- return process(node)
44
- }
45
- }
46
-
47
- function process(node) {
48
- let name
49
- let result = {}
50
-
51
- node.each(child => {
52
- if (child.type === 'atrule') {
53
- name = '@' + child.name
54
- if (child.params) name += ' ' + child.params
55
- if (typeof result[name] === 'undefined') {
56
- result[name] = atRule(child)
57
- } else if (Array.isArray(result[name])) {
58
- result[name].push(atRule(child))
59
- } else {
60
- result[name] = [result[name], atRule(child)]
61
- }
62
- } else if (child.type === 'rule') {
63
- let body = process(child)
64
- if (result[child.selector]) {
65
- for (let i in body) {
66
- result[child.selector][i] = body[i]
67
- }
68
- } else {
69
- result[child.selector] = body
70
- }
71
- } else if (child.type === 'decl') {
72
- if (child.prop[0] === '-' && child.prop[1] === '-') {
73
- name = child.prop
74
- } else {
75
- name = camelcase(child.prop)
76
- }
77
- let value = child.value
78
- if (!isNaN(child.value) && UNITLESS[name]) {
79
- value = parseFloat(child.value)
80
- }
81
- if (child.important) value += ' !important'
82
- if (typeof result[name] === 'undefined') {
83
- result[name] = value
84
- } else if (Array.isArray(result[name])) {
85
- result[name].push(value)
86
- } else {
87
- result[name] = [result[name], value]
88
- }
89
- }
90
- })
91
- return result
92
- }
93
-
94
- module.exports = process
@@ -1,42 +0,0 @@
1
- {
2
- "name": "postcss-js",
3
- "version": "4.0.0",
4
- "description": "PostCSS for CSS-in-JS and styles in JS objects",
5
- "keywords": [
6
- "postcss",
7
- "postcss-runner",
8
- "js",
9
- "inline",
10
- "react",
11
- "css",
12
- "cssinjs"
13
- ],
14
- "author": "Andrey Sitnik <andrey@sitnik.ru>",
15
- "license": "MIT",
16
- "repository": "postcss/postcss-js",
17
- "engines": {
18
- "node": "^12 || ^14 || >= 16"
19
- },
20
- "exports": {
21
- ".": {
22
- "require": "./index.js",
23
- "import": "./index.mjs"
24
- },
25
- "./package.json": "./package.json",
26
- "./async": "./async.js",
27
- "./objectifier": "./objectifier.js",
28
- "./parser": "./parser.js",
29
- "./process-result": "./process-result.js",
30
- "./sync": "./sync.js"
31
- },
32
- "funding": {
33
- "type": "opencollective",
34
- "url": "https://opencollective.com/postcss/"
35
- },
36
- "peerDependencies": {
37
- "postcss": "^8.3.3"
38
- },
39
- "dependencies": {
40
- "camelcase-css": "^2.0.1"
41
- }
42
- }
@@ -1,450 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
- 'use strict';
8
-
9
- const address = require('address');
10
- const fs = require('fs');
11
- const path = require('path');
12
- const url = require('url');
13
- const chalk = require('chalk');
14
- const detect = require('detect-port-alt');
15
- const isRoot = require('is-root');
16
- const prompts = require('prompts');
17
- const clearConsole = require('./clearConsole');
18
- const formatWebpackMessages = require('./formatWebpackMessages');
19
- const getProcessForPort = require('./getProcessForPort');
20
- const forkTsCheckerWebpackPlugin = require('./ForkTsCheckerWebpackPlugin');
21
-
22
- const isInteractive = process.stdout.isTTY;
23
-
24
- function prepareUrls(protocol, host, port, pathname = '/') {
25
- const formatUrl = hostname =>
26
- url.format({
27
- protocol,
28
- hostname,
29
- port,
30
- pathname,
31
- });
32
- const prettyPrintUrl = hostname =>
33
- url.format({
34
- protocol,
35
- hostname,
36
- port: chalk.bold(port),
37
- pathname,
38
- });
39
-
40
- const isUnspecifiedHost = host === '0.0.0.0' || host === '::';
41
- let prettyHost, lanUrlForConfig, lanUrlForTerminal;
42
- if (isUnspecifiedHost) {
43
- prettyHost = 'localhost';
44
- try {
45
- // This can only return an IPv4 address
46
- lanUrlForConfig = address.ip();
47
- if (lanUrlForConfig) {
48
- // Check if the address is a private ip
49
- // https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
50
- if (
51
- /^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
52
- lanUrlForConfig
53
- )
54
- ) {
55
- // Address is private, format it for later use
56
- lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
57
- } else {
58
- // Address is not private, so we will discard it
59
- lanUrlForConfig = undefined;
60
- }
61
- }
62
- } catch (_e) {
63
- // ignored
64
- }
65
- } else {
66
- prettyHost = host;
67
- }
68
- const localUrlForTerminal = prettyPrintUrl(prettyHost);
69
- const localUrlForBrowser = formatUrl(prettyHost);
70
- return {
71
- lanUrlForConfig,
72
- lanUrlForTerminal,
73
- localUrlForTerminal,
74
- localUrlForBrowser,
75
- };
76
- }
77
-
78
- function printInstructions(appName, urls, useYarn) {
79
- console.log();
80
- console.log(`You can now view ${chalk.bold(appName)} in the browser.`);
81
- console.log();
82
-
83
- if (urls.lanUrlForTerminal) {
84
- console.log(
85
- ` ${chalk.bold('Local:')} ${urls.localUrlForTerminal}`
86
- );
87
- console.log(
88
- ` ${chalk.bold('On Your Network:')} ${urls.lanUrlForTerminal}`
89
- );
90
- // JsView Added >>>
91
- // 将url写入network.mjs文件,用于npm run android。
92
- const urlCacheDir = path.resolve(process.cwd(), 'node_modules', '.cache', 'jsview')
93
- const urlCacheFilePath = path.resolve(urlCacheDir, 'network.mjs')
94
- fs.mkdirSync(urlCacheDir, { recursive: true });
95
- fs.writeFileSync(urlCacheFilePath, `export default "${urls.lanUrlForTerminal}/"`)
96
- // JsView Added <<<
97
- } else {
98
- console.log(` ${urls.localUrlForTerminal}`);
99
- }
100
-
101
- console.log();
102
- console.log('Note that the development build is not optimized.');
103
- console.log(
104
- `To create a production build, use ` +
105
- `${chalk.cyan(`${useYarn ? 'yarn' : 'npm run'} build`)}.`
106
- );
107
- console.log();
108
- }
109
-
110
- function createCompiler({
111
- appName,
112
- config,
113
- urls,
114
- useYarn,
115
- useTypeScript,
116
- webpack,
117
- }) {
118
- // "Compiler" is a low-level interface to webpack.
119
- // It lets us listen to some events and provide our own custom messages.
120
- let compiler;
121
- try {
122
- compiler = webpack(config);
123
- } catch (err) {
124
- console.log(chalk.red('Failed to compile.'));
125
- console.log();
126
- console.log(err.message || err);
127
- console.log();
128
- process.exit(1);
129
- }
130
-
131
- // "invalid" event fires when you have changed a file, and webpack is
132
- // recompiling a bundle. WebpackDevServer takes care to pause serving the
133
- // bundle, so if you refresh, it'll wait instead of serving the old one.
134
- // "invalid" is short for "bundle invalidated", it doesn't imply any errors.
135
- compiler.hooks.invalid.tap('invalid', () => {
136
- if (isInteractive) {
137
- clearConsole();
138
- }
139
- console.log('Compiling...');
140
- });
141
-
142
- let isFirstCompile = true;
143
- let tsMessagesPromise;
144
-
145
- if (useTypeScript) {
146
- forkTsCheckerWebpackPlugin
147
- .getCompilerHooks(compiler)
148
- .waiting.tap('awaitingTypeScriptCheck', () => {
149
- console.log(
150
- chalk.yellow(
151
- 'Files successfully emitted, waiting for typecheck results...'
152
- )
153
- );
154
- });
155
- }
156
-
157
- // "done" event fires when webpack has finished recompiling the bundle.
158
- // Whether or not you have warnings or errors, you will get this event.
159
- compiler.hooks.done.tap('done', async stats => {
160
- if (isInteractive) {
161
- clearConsole();
162
- }
163
-
164
- // We have switched off the default webpack output in WebpackDevServer
165
- // options so we are going to "massage" the warnings and errors and present
166
- // them in a readable focused way.
167
- // We only construct the warnings and errors for speed:
168
- // https://github.com/facebook/create-react-app/issues/4492#issuecomment-421959548
169
- const statsData = stats.toJson({
170
- all: false,
171
- warnings: true,
172
- errors: true,
173
- });
174
-
175
- const messages = formatWebpackMessages(statsData);
176
- const isSuccessful = !messages.errors.length && !messages.warnings.length;
177
- if (isSuccessful) {
178
- console.log(chalk.green('Compiled successfully!'));
179
- }
180
- if (isSuccessful && (isInteractive || isFirstCompile)) {
181
- printInstructions(appName, urls, useYarn);
182
- }
183
- isFirstCompile = false;
184
-
185
- // If errors exist, only show errors.
186
- if (messages.errors.length) {
187
- // Only keep the first error. Others are often indicative
188
- // of the same problem, but confuse the reader with noise.
189
- if (messages.errors.length > 1) {
190
- messages.errors.length = 1;
191
- }
192
- console.log(chalk.red('Failed to compile.\n'));
193
- console.log(messages.errors.join('\n\n'));
194
- return;
195
- }
196
-
197
- // Show warnings if no errors were found.
198
- if (messages.warnings.length) {
199
- console.log(chalk.yellow('Compiled with warnings.\n'));
200
- console.log(messages.warnings.join('\n\n'));
201
-
202
- // Teach some ESLint tricks.
203
- console.log(
204
- '\nSearch for the ' +
205
- chalk.underline(chalk.yellow('keywords')) +
206
- ' to learn more about each warning.'
207
- );
208
- console.log(
209
- 'To ignore, add ' +
210
- chalk.cyan('// eslint-disable-next-line') +
211
- ' to the line before.\n'
212
- );
213
- }
214
- });
215
-
216
- // You can safely remove this after ejecting.
217
- // We only use this block for testing of Create React App itself:
218
- const isSmokeTest = process.argv.some(
219
- arg => arg.indexOf('--smoke-test') > -1
220
- );
221
- if (isSmokeTest) {
222
- compiler.hooks.failed.tap('smokeTest', async () => {
223
- await tsMessagesPromise;
224
- process.exit(1);
225
- });
226
- compiler.hooks.done.tap('smokeTest', async stats => {
227
- await tsMessagesPromise;
228
- if (stats.hasErrors() || stats.hasWarnings()) {
229
- process.exit(1);
230
- } else {
231
- process.exit(0);
232
- }
233
- });
234
- }
235
-
236
- return compiler;
237
- }
238
-
239
- function resolveLoopback(proxy) {
240
- const o = url.parse(proxy);
241
- o.host = undefined;
242
- if (o.hostname !== 'localhost') {
243
- return proxy;
244
- }
245
- // Unfortunately, many languages (unlike node) do not yet support IPv6.
246
- // This means even though localhost resolves to ::1, the application
247
- // must fall back to IPv4 (on 127.0.0.1).
248
- // We can re-enable this in a few years.
249
- /*try {
250
- o.hostname = address.ipv6() ? '::1' : '127.0.0.1';
251
- } catch (_ignored) {
252
- o.hostname = '127.0.0.1';
253
- }*/
254
-
255
- try {
256
- // Check if we're on a network; if we are, chances are we can resolve
257
- // localhost. Otherwise, we can just be safe and assume localhost is
258
- // IPv4 for maximum compatibility.
259
- if (!address.ip()) {
260
- o.hostname = '127.0.0.1';
261
- }
262
- } catch (_ignored) {
263
- o.hostname = '127.0.0.1';
264
- }
265
- return url.format(o);
266
- }
267
-
268
- // We need to provide a custom onError function for httpProxyMiddleware.
269
- // It allows us to log custom error messages on the console.
270
- function onProxyError(proxy) {
271
- return (err, req, res) => {
272
- const host = req.headers && req.headers.host;
273
- console.log(
274
- chalk.red('Proxy error:') +
275
- ' Could not proxy request ' +
276
- chalk.cyan(req.url) +
277
- ' from ' +
278
- chalk.cyan(host) +
279
- ' to ' +
280
- chalk.cyan(proxy) +
281
- '.'
282
- );
283
- console.log(
284
- 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
285
- chalk.cyan(err.code) +
286
- ').'
287
- );
288
- console.log();
289
-
290
- // And immediately send the proper error response to the client.
291
- // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
292
- if (res.writeHead && !res.headersSent) {
293
- res.writeHead(500);
294
- }
295
- res.end(
296
- 'Proxy error: Could not proxy request ' +
297
- req.url +
298
- ' from ' +
299
- host +
300
- ' to ' +
301
- proxy +
302
- ' (' +
303
- err.code +
304
- ').'
305
- );
306
- };
307
- }
308
-
309
- function prepareProxy(proxy, appPublicFolder, servedPathname) {
310
- // `proxy` lets you specify alternate servers for specific requests.
311
- if (!proxy) {
312
- return undefined;
313
- }
314
- if (typeof proxy !== 'string') {
315
- console.log(
316
- chalk.red('When specified, "proxy" in package.json must be a string.')
317
- );
318
- console.log(
319
- chalk.red('Instead, the type of "proxy" was "' + typeof proxy + '".')
320
- );
321
- console.log(
322
- chalk.red('Either remove "proxy" from package.json, or make it a string.')
323
- );
324
- process.exit(1);
325
- }
326
-
327
- // If proxy is specified, let it handle any request except for
328
- // files in the public folder and requests to the WebpackDevServer socket endpoint.
329
- // https://github.com/facebook/create-react-app/issues/6720
330
- const sockPath = process.env.WDS_SOCKET_PATH || '/ws';
331
- const isDefaultSockHost = !process.env.WDS_SOCKET_HOST;
332
- function mayProxy(pathname) {
333
- const maybePublicPath = path.resolve(
334
- appPublicFolder,
335
- pathname.replace(new RegExp('^' + servedPathname), '')
336
- );
337
- const isPublicFileRequest = fs.existsSync(maybePublicPath);
338
- // used by webpackHotDevClient
339
- const isWdsEndpointRequest =
340
- isDefaultSockHost && pathname.startsWith(sockPath);
341
- return !(isPublicFileRequest || isWdsEndpointRequest);
342
- }
343
-
344
- if (!/^http(s)?:\/\//.test(proxy)) {
345
- console.log(
346
- chalk.red(
347
- 'When "proxy" is specified in package.json it must start with either http:// or https://'
348
- )
349
- );
350
- process.exit(1);
351
- }
352
-
353
- let target;
354
- if (process.platform === 'win32') {
355
- target = resolveLoopback(proxy);
356
- } else {
357
- target = proxy;
358
- }
359
- return [
360
- {
361
- target,
362
- logLevel: 'silent',
363
- // For single page apps, we generally want to fallback to /index.html.
364
- // However we also want to respect `proxy` for API calls.
365
- // So if `proxy` is specified as a string, we need to decide which fallback to use.
366
- // We use a heuristic: We want to proxy all the requests that are not meant
367
- // for static assets and as all the requests for static assets will be using
368
- // `GET` method, we can proxy all non-`GET` requests.
369
- // For `GET` requests, if request `accept`s text/html, we pick /index.html.
370
- // Modern browsers include text/html into `accept` header when navigating.
371
- // However API calls like `fetch()` won’t generally accept text/html.
372
- // If this heuristic doesn’t work well for you, use `src/setupProxy.js`.
373
- context: function (pathname, req) {
374
- return (
375
- req.method !== 'GET' ||
376
- (mayProxy(pathname) &&
377
- req.headers.accept &&
378
- req.headers.accept.indexOf('text/html') === -1)
379
- );
380
- },
381
- onProxyReq: proxyReq => {
382
- // Browsers may send Origin headers even with same-origin
383
- // requests. To prevent CORS issues, we have to change
384
- // the Origin to match the target URL.
385
- if (proxyReq.getHeader('origin')) {
386
- proxyReq.setHeader('origin', target);
387
- }
388
- },
389
- onError: onProxyError(target),
390
- secure: false,
391
- changeOrigin: true,
392
- ws: true,
393
- xfwd: true,
394
- },
395
- ];
396
- }
397
-
398
- function choosePort(host, defaultPort) {
399
- return detect(defaultPort, host).then(
400
- port =>
401
- new Promise(resolve => {
402
- if (port === defaultPort) {
403
- return resolve(port);
404
- }
405
- const message =
406
- process.platform !== 'win32' && defaultPort < 1024 && !isRoot()
407
- ? `Admin permissions are required to run a server on a port below 1024.`
408
- : `Something is already running on port ${defaultPort}.`;
409
- if (isInteractive) {
410
- clearConsole();
411
- const existingProcess = getProcessForPort(defaultPort);
412
- const question = {
413
- type: 'confirm',
414
- name: 'shouldChangePort',
415
- message:
416
- chalk.yellow(
417
- message +
418
- `${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
419
- ) + '\n\nWould you like to run the app on another port instead?',
420
- initial: true,
421
- };
422
- prompts(question).then(answer => {
423
- if (answer.shouldChangePort) {
424
- resolve(port);
425
- } else {
426
- resolve(null);
427
- }
428
- });
429
- } else {
430
- console.log(chalk.red(message));
431
- resolve(null);
432
- }
433
- }),
434
- err => {
435
- throw new Error(
436
- chalk.red(`Could not find an open port at ${chalk.bold(host)}.`) +
437
- '\n' +
438
- ('Network error message: ' + err.message || err) +
439
- '\n'
440
- );
441
- }
442
- );
443
- }
444
-
445
- module.exports = {
446
- choosePort,
447
- createCompiler,
448
- prepareProxy,
449
- prepareUrls,
450
- };