ezuikit-js 0.5.8-beta.2 → 0.5.8

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 (39) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/demos/base-demo/ezuikit.js +2 -2
  3. package/demos/base-demo/index.html +2 -2
  4. package/demos/nginx-demo/conf/nginx.conf +0 -2
  5. package/demos/nginx-demo/html/ezuikit5/ezuikit.js +31 -31
  6. package/demos/nginx-demo/html/ezuikit5/server.js +1 -1
  7. package/demos/react-demo/README.md +68 -0
  8. package/demos/react-demo/config/env.js +101 -0
  9. package/demos/react-demo/config/getHttpsConfig.js +66 -0
  10. package/demos/react-demo/config/jest/cssTransform.js +14 -0
  11. package/demos/react-demo/config/jest/fileTransform.js +40 -0
  12. package/demos/react-demo/config/modules.js +141 -0
  13. package/demos/react-demo/config/paths.js +72 -0
  14. package/demos/react-demo/config/pnpTs.js +35 -0
  15. package/demos/react-demo/config/webpack.config.js +669 -0
  16. package/demos/react-demo/config/webpackDevServer.config.js +134 -0
  17. package/demos/react-demo/package-lock.json +13893 -0
  18. package/demos/react-demo/package.json +141 -0
  19. package/demos/react-demo/public/favicon.ico +0 -0
  20. package/demos/react-demo/public/index.html +43 -0
  21. package/demos/react-demo/public/logo192.png +0 -0
  22. package/demos/react-demo/public/logo512.png +0 -0
  23. package/demos/react-demo/public/manifest.json +25 -0
  24. package/demos/react-demo/public/robots.txt +3 -0
  25. package/demos/react-demo/scripts/build.js +211 -0
  26. package/demos/react-demo/scripts/start.js +166 -0
  27. package/demos/react-demo/scripts/test.js +53 -0
  28. package/demos/react-demo/src/App.css +38 -0
  29. package/demos/react-demo/src/App.js +54 -0
  30. package/demos/react-demo/src/App.test.js +9 -0
  31. package/demos/react-demo/src/ezuikit/index.js +1113 -0
  32. package/demos/react-demo/src/ezuikit/package.json +12 -0
  33. package/demos/react-demo/src/index.css +13 -0
  34. package/demos/react-demo/src/index.js +17 -0
  35. package/demos/react-demo/src/logo.svg +7 -0
  36. package/demos/react-demo/src/serviceWorker.js +141 -0
  37. package/demos/react-demo/src/setupTests.js +5 -0
  38. package/ezuikit.js +16391 -22695
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ v 0.5.8
2
+ [feta-beta]支持多线程解码视频-beta
3
+
1
4
  v 0.5.7
2
5
  [feta]新增对讲成功回调,用于国标对讲成功,开启视频声音
3
6
 
@@ -31916,7 +31916,7 @@ var EZUIKitPlayer = /*#__PURE__*/function () {
31916
31916
  this.env = {
31917
31917
  domain: "https://open.ys7.com"
31918
31918
  };
31919
- this.staticPath = "https://open.ys7.com/assets/ezuikit_v4.0";
31919
+ this.staticPath = !!window.SharedArrayBuffer ? "https://open.ys7.com/assets/ezuikit_v5.0" : "https://open.ys7.com/assets/ezuikit_v4.0";
31920
31920
 
31921
31921
  if (typeof params.staticPath === 'string') {
31922
31922
  this.staticPath = params.staticPath;
@@ -31934,7 +31934,7 @@ var EZUIKitPlayer = /*#__PURE__*/function () {
31934
31934
 
31935
31935
  if (!!window.SharedArrayBuffer) {
31936
31936
  console.log("启用多线程解析视频");
31937
- pluginUrl = "https://jianboyu.top/2.0/jsPlugin-2.0.0.min.js";
31937
+ pluginUrl = "".concat(this.staticPath, "/jsPlugin-2.0.0.min.js");
31938
31938
  }
31939
31939
 
31940
31940
  addJs(pluginUrl, function () {
@@ -36,8 +36,8 @@
36
36
  var accessToken = res.data.accessToken;
37
37
  playr = new EZUIKit.EZUIKitPlayer({
38
38
  id: 'video-container', // 视频容器ID
39
- accessToken: "at.5so0lluc89r4jjj45waik5viainzozd6-67wi5b5fgx-07ahxuy-nzfgd8qn0",
40
- url: 'ezopen://open.ys7.com/D88600067/1.live',
39
+ accessToken: accessToken,
40
+ url: 'ezopen://open.ys7.com/G39444019/1.live',
41
41
  template: 'simple', // simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版; theme-可配置主题;
42
42
  plugin: ['talk'], // 加载插件,talk-对讲
43
43
  width: 600,
@@ -47,8 +47,6 @@ http {
47
47
  location ~/ezuikit5 {
48
48
  add_header 'Cross-Origin-Embedder-Policy' 'require-corp';
49
49
  add_header 'Cross-Origin-Opener-Policy' 'same-origin';
50
- # root html;
51
- # index index.html index.htm;
52
50
  }
53
51
 
54
52
  #error_page 404 /404.html;
@@ -15834,8 +15834,8 @@ var TimeLine$1 = function TimeLine(jsPlugin) {
15834
15834
  // 只画一次线
15835
15835
  that.drawSolidLine(i * that.canvasWidth / dotNum, 8, i * that.canvasWidth / dotNum, that.canvasHeight / 5 * 0.5 + 8, 1, lineColor);
15836
15836
  }
15837
- /**
15838
- * 偏移距离超过60,setSeconds会每次累加1到分钟,因此绘图完成后需要复原到当前分钟,再次计算偏移
15837
+ /**
15838
+ * 偏移距离超过60,setSeconds会每次累加1到分钟,因此绘图完成后需要复原到当前分钟,再次计算偏移
15839
15839
  */
15840
15840
 
15841
15841
 
@@ -31531,8 +31531,8 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31531
31531
  this.initTextures();
31532
31532
  }
31533
31533
  }
31534
- /**
31535
- * 初始化WebGL上下文
31534
+ /**
31535
+ * 初始化WebGL上下文
31536
31536
  */
31537
31537
 
31538
31538
  RenderManager.prototype.initContextGL = function () {
@@ -31552,10 +31552,10 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31552
31552
  this.contextGL = gl;
31553
31553
  console.log("WebGL1.0");
31554
31554
  };
31555
- /**
31556
- * 初始化着色器程序
31557
- * @param vertexShaderScript 顶点着色器脚本
31558
- * @param fragmentShaderScript 片段着色器脚本
31555
+ /**
31556
+ * 初始化着色器程序
31557
+ * @param vertexShaderScript 顶点着色器脚本
31558
+ * @param fragmentShaderScript 片段着色器脚本
31559
31559
  */
31560
31560
 
31561
31561
 
@@ -31591,8 +31591,8 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31591
31591
  gl.deleteShader(fragmentShader);
31592
31592
  return program;
31593
31593
  };
31594
- /**
31595
- * 初始化数据缓存
31594
+ /**
31595
+ * 初始化数据缓存
31596
31596
  */
31597
31597
 
31598
31598
 
@@ -31609,8 +31609,8 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31609
31609
  this.vertexPosBuffer = vertexPosBuffer;
31610
31610
  this.texturePosBuffer = texturePosBuffer;
31611
31611
  };
31612
- /**
31613
- * 创建纹理
31612
+ /**
31613
+ * 创建纹理
31614
31614
  */
31615
31615
 
31616
31616
 
@@ -31625,8 +31625,8 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31625
31625
  gl.bindTexture(gl.TEXTURE_2D, null);
31626
31626
  return textureRef;
31627
31627
  };
31628
- /**
31629
- * 初始化YUV纹理
31628
+ /**
31629
+ * 初始化YUV纹理
31630
31630
  */
31631
31631
 
31632
31632
 
@@ -31648,11 +31648,11 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31648
31648
  this.vTextureRef = vTextureRef;
31649
31649
  gl.useProgram(null);
31650
31650
  };
31651
- /**
31652
- * 显示帧数据
31653
- * @param nWidth 宽度
31654
- * @param nHeight 高度
31655
- * @param nHeight 帧数据
31651
+ /**
31652
+ * 显示帧数据
31653
+ * @param nWidth 宽度
31654
+ * @param nHeight 高度
31655
+ * @param nHeight 帧数据
31656
31656
  */
31657
31657
 
31658
31658
 
@@ -31697,11 +31697,11 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31697
31697
  gl.disableVertexAttribArray(texturePosRef);
31698
31698
  gl.useProgram(null);
31699
31699
  };
31700
- /**
31701
- * 上传YUV数据到纹理
31702
- * @param nWidth 宽度
31703
- * @param nHeight 高度
31704
- * @param nHeight 帧数据
31700
+ /**
31701
+ * 上传YUV数据到纹理
31702
+ * @param nWidth 宽度
31703
+ * @param nHeight 高度
31704
+ * @param nHeight 帧数据
31705
31705
  */
31706
31706
 
31707
31707
 
@@ -31781,9 +31781,9 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31781
31781
  crSonData = null;
31782
31782
  }
31783
31783
  };
31784
- /**
31785
- * 设置显示区域
31786
- * @param stDisplayRect 显示区域
31784
+ /**
31785
+ * 设置显示区域
31786
+ * @param stDisplayRect 显示区域
31787
31787
  */
31788
31788
 
31789
31789
 
@@ -31808,8 +31808,8 @@ var fragmentYUVShader = ['precision highp float;', 'varying highp vec2 textureCo
31808
31808
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, texturePosValues);
31809
31809
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
31810
31810
  };
31811
- /**
31812
- * 释放显示资源
31811
+ /**
31812
+ * 释放显示资源
31813
31813
  */
31814
31814
 
31815
31815
 
@@ -31916,7 +31916,7 @@ var EZUIKitPlayer = /*#__PURE__*/function () {
31916
31916
  this.env = {
31917
31917
  domain: "https://open.ys7.com"
31918
31918
  };
31919
- this.staticPath = "https://open.ys7.com/assets/ezuikit_v4.0";
31919
+ this.staticPath = !!window.SharedArrayBuffer ? "https://open.ys7.com/assets/ezuikit_v5.0" : "https://open.ys7.com/assets/ezuikit_v4.0";
31920
31920
 
31921
31921
  if (typeof params.staticPath === 'string') {
31922
31922
  this.staticPath = params.staticPath;
@@ -31934,7 +31934,7 @@ var EZUIKitPlayer = /*#__PURE__*/function () {
31934
31934
 
31935
31935
  if (!!window.SharedArrayBuffer) {
31936
31936
  console.log("启用多线程解析视频");
31937
- pluginUrl = "https://open.ys7.com/assets/ezuikit_v5.0/jsPlugin-2.0.0.min.js";
31937
+ pluginUrl = "".concat(this.staticPath, "/jsPlugin-2.0.0.min.js");
31938
31938
  }
31939
31939
 
31940
31940
  addJs(pluginUrl, function () {
@@ -40,7 +40,7 @@ httpServer.on('request', (req, res) => {
40
40
  if (ext === 'html' || ext === 'xhtml'|| ext === 'js') {
41
41
  //跨域隔离
42
42
  res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
43
- res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
43
+ res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
44
44
  res.setHeader('Access-Control-Allow-Origin', 'https://resource.eziot.com')
45
45
  //影响报告
46
46
  //res.setHeader('Cross-Origin-Embedder-Policy-Report-Only', 'require-corp')
@@ -0,0 +1,68 @@
1
+ This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2
+
3
+ ## Available Scripts
4
+
5
+ In the project directory, you can run:
6
+
7
+ ### `npm start`
8
+
9
+ Runs the app in the development mode.<br />
10
+ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11
+
12
+ The page will reload if you make edits.<br />
13
+ You will also see any lint errors in the console.
14
+
15
+ ### `npm test`
16
+
17
+ Launches the test runner in the interactive watch mode.<br />
18
+ See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19
+
20
+ ### `npm run build`
21
+
22
+ Builds the app for production to the `build` folder.<br />
23
+ It correctly bundles React in production mode and optimizes the build for the best performance.
24
+
25
+ The build is minified and the filenames include the hashes.<br />
26
+ Your app is ready to be deployed!
27
+
28
+ See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29
+
30
+ ### `npm run eject`
31
+
32
+ **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33
+
34
+ If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35
+
36
+ Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37
+
38
+ You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39
+
40
+ ## Learn More
41
+
42
+ You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43
+
44
+ To learn React, check out the [React documentation](https://reactjs.org/).
45
+
46
+ ### Code Splitting
47
+
48
+ This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49
+
50
+ ### Analyzing the Bundle Size
51
+
52
+ This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53
+
54
+ ### Making a Progressive Web App
55
+
56
+ This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57
+
58
+ ### Advanced Configuration
59
+
60
+ This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61
+
62
+ ### Deployment
63
+
64
+ This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65
+
66
+ ### `npm run build` fails to minify
67
+
68
+ This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const paths = require('./paths');
6
+
7
+ // Make sure that including paths.js after env.js will read .env variables.
8
+ delete require.cache[require.resolve('./paths')];
9
+
10
+ const NODE_ENV = process.env.NODE_ENV;
11
+ if (!NODE_ENV) {
12
+ throw new Error(
13
+ 'The NODE_ENV environment variable is required but was not specified.'
14
+ );
15
+ }
16
+
17
+ // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18
+ const dotenvFiles = [
19
+ `${paths.dotenv}.${NODE_ENV}.local`,
20
+ `${paths.dotenv}.${NODE_ENV}`,
21
+ // Don't include `.env.local` for `test` environment
22
+ // since normally you expect tests to produce the same
23
+ // results for everyone
24
+ NODE_ENV !== 'test' && `${paths.dotenv}.local`,
25
+ paths.dotenv,
26
+ ].filter(Boolean);
27
+
28
+ // Load environment variables from .env* files. Suppress warnings using silent
29
+ // if this file is missing. dotenv will never modify any environment variables
30
+ // that have already been set. Variable expansion is supported in .env files.
31
+ // https://github.com/motdotla/dotenv
32
+ // https://github.com/motdotla/dotenv-expand
33
+ dotenvFiles.forEach(dotenvFile => {
34
+ if (fs.existsSync(dotenvFile)) {
35
+ require('dotenv-expand')(
36
+ require('dotenv').config({
37
+ path: dotenvFile,
38
+ })
39
+ );
40
+ }
41
+ });
42
+
43
+ // We support resolving modules according to `NODE_PATH`.
44
+ // This lets you use absolute paths in imports inside large monorepos:
45
+ // https://github.com/facebook/create-react-app/issues/253.
46
+ // It works similar to `NODE_PATH` in Node itself:
47
+ // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
48
+ // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
49
+ // Otherwise, we risk importing Node.js core modules into an app instead of webpack shims.
50
+ // https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
51
+ // We also resolve them to make sure all tools using them work consistently.
52
+ const appDirectory = fs.realpathSync(process.cwd());
53
+ process.env.NODE_PATH = (process.env.NODE_PATH || '')
54
+ .split(path.delimiter)
55
+ .filter(folder => folder && !path.isAbsolute(folder))
56
+ .map(folder => path.resolve(appDirectory, folder))
57
+ .join(path.delimiter);
58
+
59
+ // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
60
+ // injected into the application via DefinePlugin in webpack configuration.
61
+ const REACT_APP = /^REACT_APP_/i;
62
+
63
+ function getClientEnvironment(publicUrl) {
64
+ const raw = Object.keys(process.env)
65
+ .filter(key => REACT_APP.test(key))
66
+ .reduce(
67
+ (env, key) => {
68
+ env[key] = process.env[key];
69
+ return env;
70
+ },
71
+ {
72
+ // Useful for determining whether we’re running in production mode.
73
+ // Most importantly, it switches React into the correct mode.
74
+ NODE_ENV: process.env.NODE_ENV || 'development',
75
+ // Useful for resolving the correct path to static assets in `public`.
76
+ // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
77
+ // This should only be used as an escape hatch. Normally you would put
78
+ // images into the `src` and `import` them in code to get their paths.
79
+ PUBLIC_URL: publicUrl,
80
+ // We support configuring the sockjs pathname during development.
81
+ // These settings let a developer run multiple simultaneous projects.
82
+ // They are used as the connection `hostname`, `pathname` and `port`
83
+ // in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
84
+ // and `sockPort` options in webpack-dev-server.
85
+ WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST,
86
+ WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
87
+ WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
88
+ }
89
+ );
90
+ // Stringify all values so we can feed into webpack DefinePlugin
91
+ const stringified = {
92
+ 'process.env': Object.keys(raw).reduce((env, key) => {
93
+ env[key] = JSON.stringify(raw[key]);
94
+ return env;
95
+ }, {}),
96
+ };
97
+
98
+ return { raw, stringified };
99
+ }
100
+
101
+ module.exports = getClientEnvironment;
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const crypto = require('crypto');
6
+ const chalk = require('react-dev-utils/chalk');
7
+ const paths = require('./paths');
8
+
9
+ // Ensure the certificate and key provided are valid and if not
10
+ // throw an easy to debug error
11
+ function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
12
+ let encrypted;
13
+ try {
14
+ // publicEncrypt will throw an error with an invalid cert
15
+ encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
16
+ } catch (err) {
17
+ throw new Error(
18
+ `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
19
+ );
20
+ }
21
+
22
+ try {
23
+ // privateDecrypt will throw an error with an invalid key
24
+ crypto.privateDecrypt(key, encrypted);
25
+ } catch (err) {
26
+ throw new Error(
27
+ `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
28
+ err.message
29
+ }`
30
+ );
31
+ }
32
+ }
33
+
34
+ // Read file and throw an error if it doesn't exist
35
+ function readEnvFile(file, type) {
36
+ if (!fs.existsSync(file)) {
37
+ throw new Error(
38
+ `You specified ${chalk.cyan(
39
+ type
40
+ )} in your env, but the file "${chalk.yellow(file)}" can't be found.`
41
+ );
42
+ }
43
+ return fs.readFileSync(file);
44
+ }
45
+
46
+ // Get the https config
47
+ // Return cert files if provided in env, otherwise just true or false
48
+ function getHttpsConfig() {
49
+ const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
50
+ const isHttps = HTTPS === 'true';
51
+
52
+ if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
53
+ const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
54
+ const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
55
+ const config = {
56
+ cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
57
+ key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
58
+ };
59
+
60
+ validateKeyAndCerts({ ...config, keyFile, crtFile });
61
+ return config;
62
+ }
63
+ return isHttps;
64
+ }
65
+
66
+ module.exports = getHttpsConfig;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ // This is a custom Jest transformer turning style imports into empty objects.
4
+ // http://facebook.github.io/jest/docs/en/webpack.html
5
+
6
+ module.exports = {
7
+ process() {
8
+ return 'module.exports = {};';
9
+ },
10
+ getCacheKey() {
11
+ // The output is always the same.
12
+ return 'cssTransform';
13
+ },
14
+ };
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const camelcase = require('camelcase');
5
+
6
+ // This is a custom Jest transformer turning file imports into filenames.
7
+ // http://facebook.github.io/jest/docs/en/webpack.html
8
+
9
+ module.exports = {
10
+ process(src, filename) {
11
+ const assetFilename = JSON.stringify(path.basename(filename));
12
+
13
+ if (filename.match(/\.svg$/)) {
14
+ // Based on how SVGR generates a component name:
15
+ // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
16
+ const pascalCaseFilename = camelcase(path.parse(filename).name, {
17
+ pascalCase: true,
18
+ });
19
+ const componentName = `Svg${pascalCaseFilename}`;
20
+ return `const React = require('react');
21
+ module.exports = {
22
+ __esModule: true,
23
+ default: ${assetFilename},
24
+ ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
25
+ return {
26
+ $$typeof: Symbol.for('react.element'),
27
+ type: 'svg',
28
+ ref: ref,
29
+ key: null,
30
+ props: Object.assign({}, props, {
31
+ children: ${assetFilename}
32
+ })
33
+ };
34
+ }),
35
+ };`;
36
+ }
37
+
38
+ return `module.exports = ${assetFilename};`;
39
+ },
40
+ };
@@ -0,0 +1,141 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const paths = require('./paths');
6
+ const chalk = require('react-dev-utils/chalk');
7
+ const resolve = require('resolve');
8
+
9
+ /**
10
+ * Get additional module paths based on the baseUrl of a compilerOptions object.
11
+ *
12
+ * @param {Object} options
13
+ */
14
+ function getAdditionalModulePaths(options = {}) {
15
+ const baseUrl = options.baseUrl;
16
+
17
+ // We need to explicitly check for null and undefined (and not a falsy value) because
18
+ // TypeScript treats an empty string as `.`.
19
+ if (baseUrl == null) {
20
+ // If there's no baseUrl set we respect NODE_PATH
21
+ // Note that NODE_PATH is deprecated and will be removed
22
+ // in the next major release of create-react-app.
23
+
24
+ const nodePath = process.env.NODE_PATH || '';
25
+ return nodePath.split(path.delimiter).filter(Boolean);
26
+ }
27
+
28
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
29
+
30
+ // We don't need to do anything if `baseUrl` is set to `node_modules`. This is
31
+ // the default behavior.
32
+ if (path.relative(paths.appNodeModules, baseUrlResolved) === '') {
33
+ return null;
34
+ }
35
+
36
+ // Allow the user set the `baseUrl` to `appSrc`.
37
+ if (path.relative(paths.appSrc, baseUrlResolved) === '') {
38
+ return [paths.appSrc];
39
+ }
40
+
41
+ // If the path is equal to the root directory we ignore it here.
42
+ // We don't want to allow importing from the root directly as source files are
43
+ // not transpiled outside of `src`. We do allow importing them with the
44
+ // absolute path (e.g. `src/Components/Button.js`) but we set that up with
45
+ // an alias.
46
+ if (path.relative(paths.appPath, baseUrlResolved) === '') {
47
+ return null;
48
+ }
49
+
50
+ // Otherwise, throw an error.
51
+ throw new Error(
52
+ chalk.red.bold(
53
+ "Your project's `baseUrl` can only be set to `src` or `node_modules`." +
54
+ ' Create React App does not support other values at this time.'
55
+ )
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Get webpack aliases based on the baseUrl of a compilerOptions object.
61
+ *
62
+ * @param {*} options
63
+ */
64
+ function getWebpackAliases(options = {}) {
65
+ const baseUrl = options.baseUrl;
66
+
67
+ if (!baseUrl) {
68
+ return {};
69
+ }
70
+
71
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
72
+
73
+ if (path.relative(paths.appPath, baseUrlResolved) === '') {
74
+ return {
75
+ src: paths.appSrc,
76
+ };
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Get jest aliases based on the baseUrl of a compilerOptions object.
82
+ *
83
+ * @param {*} options
84
+ */
85
+ function getJestAliases(options = {}) {
86
+ const baseUrl = options.baseUrl;
87
+
88
+ if (!baseUrl) {
89
+ return {};
90
+ }
91
+
92
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
93
+
94
+ if (path.relative(paths.appPath, baseUrlResolved) === '') {
95
+ return {
96
+ '^src/(.*)$': '<rootDir>/src/$1',
97
+ };
98
+ }
99
+ }
100
+
101
+ function getModules() {
102
+ // Check if TypeScript is setup
103
+ const hasTsConfig = fs.existsSync(paths.appTsConfig);
104
+ const hasJsConfig = fs.existsSync(paths.appJsConfig);
105
+
106
+ if (hasTsConfig && hasJsConfig) {
107
+ throw new Error(
108
+ 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
109
+ );
110
+ }
111
+
112
+ let config;
113
+
114
+ // If there's a tsconfig.json we assume it's a
115
+ // TypeScript project and set up the config
116
+ // based on tsconfig.json
117
+ if (hasTsConfig) {
118
+ const ts = require(resolve.sync('typescript', {
119
+ basedir: paths.appNodeModules,
120
+ }));
121
+ config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config;
122
+ // Otherwise we'll check if there is jsconfig.json
123
+ // for non TS projects.
124
+ } else if (hasJsConfig) {
125
+ config = require(paths.appJsConfig);
126
+ }
127
+
128
+ config = config || {};
129
+ const options = config.compilerOptions || {};
130
+
131
+ const additionalModulePaths = getAdditionalModulePaths(options);
132
+
133
+ return {
134
+ additionalModulePaths: additionalModulePaths,
135
+ webpackAliases: getWebpackAliases(options),
136
+ jestAliases: getJestAliases(options),
137
+ hasTsConfig,
138
+ };
139
+ }
140
+
141
+ module.exports = getModules();