@reactunity/scripts 0.8.1 → 0.9.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.
@@ -9,20 +9,23 @@
9
9
  'use strict';
10
10
 
11
11
  const fs = require('fs');
12
- const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
12
+ const path = require('path');
13
13
  const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
14
14
  const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
15
15
  const ignoredFiles = require('react-dev-utils/ignoredFiles');
16
16
  const redirectServedPath = require('react-dev-utils/redirectServedPathMiddleware');
17
17
  const paths = require('./paths');
18
18
  const getHttpsConfig = require('./getHttpsConfig');
19
- const path = require('path');
19
+ const { registerUnityMiddleware } = require('./unityMiddleware');
20
20
 
21
+ const host = process.env.HOST || '0.0.0.0';
21
22
  const sockHost = process.env.WDS_SOCKET_HOST;
22
- const sockPath = process.env.WDS_SOCKET_PATH; // default: '/sockjs-node'
23
+ const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
23
24
  const sockPort = process.env.WDS_SOCKET_PORT;
24
25
 
25
- module.exports = function (proxy, allowedHost, host, port) {
26
+ module.exports = function (proxy, allowedHost) {
27
+ const disableFirewall =
28
+ !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
26
29
  return {
27
30
  // WebpackDevServer 2.4.3 introduced a security fix that prevents remote
28
31
  // websites from potentially accessing local content through DNS rebinding:
@@ -40,26 +43,16 @@ module.exports = function (proxy, allowedHost, host, port) {
40
43
  // So we will disable the host check normally, but enable it if you have
41
44
  // specified the `proxy` setting. Finally, we let you override it if you
42
45
  // really know what you're doing with a special environment variable.
43
- allowedHosts: !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true' ? 'all' : allowedHost,
46
+ // Note: ["localhost", ".localhost"] will support subdomains - but we might
47
+ // want to allow setting the allowedHosts manually for more complex setups
48
+ allowedHosts: disableFirewall ? 'all' : [allowedHost],
49
+ headers: {
50
+ 'Access-Control-Allow-Origin': '*',
51
+ 'Access-Control-Allow-Methods': '*',
52
+ 'Access-Control-Allow-Headers': '*',
53
+ },
44
54
  // Enable gzip compression of generated files.
45
55
  compress: true,
46
- // Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
47
- // for the WebpackDevServer client so it can learn when the files were
48
- // updated. The WebpackDevServer client is included as an entry point
49
- // in the webpack development configuration. Note that only changes
50
- // to CSS are currently hot reloaded. JS changes will refresh the browser.
51
- hot: true,
52
- // Use 'ws' instead of 'sockjs-node' on server since we're using native
53
- // websockets in `webpackHotDevClient`.
54
- webSocketServer: 'ws',
55
- devMiddleware: {
56
- index: 'index.html',
57
- // It is important to tell WebpackDevServer to use the same "publicPath" path as
58
- // we specified in the webpack config. When homepage is '.', default to serving
59
- // from the root.
60
- // remove last slash so user can land on `/test` instead of `/test/`
61
- publicPath: paths.publicUrlOrPath.slice(0, -1),
62
- },
63
56
  static: [
64
57
  // Serve React Unity Web Inspector as the index page
65
58
  { directory: path.join(__dirname, 'web-inspector'), },
@@ -79,29 +72,19 @@ module.exports = function (proxy, allowedHost, host, port) {
79
72
  // for some reason broken when imported through webpack. If you just want to
80
73
  // use an image, put it in `src` and `import` it from JavaScript instead.
81
74
  directory: paths.appPublic,
82
- publicPath: paths.publicUrlOrPath,
83
- serveIndex: true,
84
- staticOptions: {},
85
- // Reportedly, this avoids CPU overload on some systems.
86
- // https://github.com/facebook/create-react-app/issues/293
87
- // src/node_modules is not ignored to support absolute imports
88
- // https://github.com/facebook/create-react-app/issues/1065
75
+ publicPath: [paths.publicUrlOrPath],
76
+ // By default files from `contentBase` will not trigger a page reload.
89
77
  watch: {
78
+ // Reportedly, this avoids CPU overload on some systems.
79
+ // https://github.com/facebook/create-react-app/issues/293
80
+ // src/node_modules is not ignored to support absolute imports
81
+ // https://github.com/facebook/create-react-app/issues/1065
90
82
  ignored: ignoredFiles(paths.appSrc),
91
83
  },
92
84
  },
93
85
  ],
94
- headers: {
95
- 'Access-Control-Allow-Origin': '*',
96
- },
97
- https: getHttpsConfig(),
98
- host,
99
- port,
86
+
100
87
  client: {
101
- overlay: false,
102
- // Silence WebpackDevServer's own logs since they're generally not useful.
103
- // It will still show compile warnings and errors with this setting.
104
- logging: 'none',
105
88
  webSocketURL: {
106
89
  // Enable custom sockjs pathname for websocket connection to hot reloading server.
107
90
  // Enable custom sockjs hostname, pathname and port for websocket connection
@@ -110,7 +93,21 @@ module.exports = function (proxy, allowedHost, host, port) {
110
93
  pathname: sockPath,
111
94
  port: sockPort,
112
95
  },
96
+ overlay: {
97
+ errors: true,
98
+ warnings: false,
99
+ },
113
100
  },
101
+ devMiddleware: {
102
+ // It is important to tell WebpackDevServer to use the same "publicPath" path as
103
+ // we specified in the webpack config. When homepage is '.', default to serving
104
+ // from the root.
105
+ // remove last slash so user can land on `/test` instead of `/test/`
106
+ publicPath: paths.publicUrlOrPath.slice(0, -1),
107
+ },
108
+
109
+ https: getHttpsConfig(),
110
+ host,
114
111
  historyApiFallback: {
115
112
  // Paths with dots should still use the history fallback.
116
113
  // See https://github.com/facebook/create-react-app/issues/387.
@@ -119,57 +116,30 @@ module.exports = function (proxy, allowedHost, host, port) {
119
116
  },
120
117
  // `proxy` is run between `before` and `after` `webpack-dev-server` hooks
121
118
  proxy,
122
- onBeforeSetupMiddleware(devServer) {
123
- const app = devServer.app;
119
+ setupMiddlewares(middlewares, devServer) {
120
+ if (!devServer) {
121
+ throw new Error('webpack-dev-server is not defined');
122
+ }
124
123
 
125
- // Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
124
+ // Keep `evalSourceMapMiddleware`
126
125
  // middlewares before `redirectServedPath` otherwise will not have any effect
127
126
  // This lets us fetch source contents from webpack for the error overlay
128
- app.use(evalSourceMapMiddleware(devServer));
129
- // This lets us open files from the runtime error overlay.
130
- app.use(errorOverlayMiddleware());
127
+ devServer.app.use(evalSourceMapMiddleware(devServer));
131
128
 
132
129
  if (fs.existsSync(paths.proxySetup)) {
133
130
  // This registers user provided middleware for proxy reasons
134
- require(paths.proxySetup)(app);
135
- }
136
-
137
- // Allow serving Unity builds
138
- function contentEncodingShorthand(pattern, encoding) {
139
- app.get(pattern, function (req, res, next) {
140
- res.set('Content-Encoding', encoding);
141
- next();
142
- });
143
- }
144
-
145
- function contentTypeShorthand(pattern, type) {
146
- app.get(pattern, function (req, res, next) {
147
- res.set('Content-Type', type);
148
- next();
149
- });
131
+ require(paths.proxySetup)(devServer.app);
150
132
  }
151
133
 
152
- contentEncodingShorthand('*.unityweb', 'gzip');
153
- contentEncodingShorthand('*.gz', 'gzip');
154
- contentEncodingShorthand('*.br', 'br');
155
- contentTypeShorthand('*.js.gz', 'application/javascript');
156
- contentTypeShorthand('*.js.br', 'application/javascript');
157
- contentTypeShorthand('*.wasm', 'application/wasm');
158
- contentTypeShorthand('*.wasm.gz', 'application/wasm');
159
- contentTypeShorthand('*.wasm.br', 'application/wasm');
160
- },
161
- onAfterSetupMiddleware(devServer) {
162
- const app = devServer.app;
134
+ registerUnityMiddleware(devServer.app);
163
135
 
164
136
  // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
165
- app.use(redirectServedPath(paths.publicUrlOrPath));
137
+ middlewares.push({
138
+ name: 'public-urls',
139
+ middleware: redirectServedPath(paths.publicUrlOrPath),
140
+ });
166
141
 
167
- // This service worker file is effectively a 'no-op' that will reset any
168
- // previous service worker registered for the same host:port combination.
169
- // We do this in development to avoid hitting the production cache if
170
- // it used the same host and port.
171
- // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
172
- app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
142
+ return middlewares;
173
143
  },
174
144
  };
175
145
  };
@@ -10,6 +10,11 @@ declare namespace NodeJS {
10
10
  }
11
11
  }
12
12
 
13
+ declare module '*.avif' {
14
+ const src: string;
15
+ export default src;
16
+ }
17
+
13
18
  declare module '*.bmp' {
14
19
  const src: string;
15
20
  export default src;
@@ -41,8 +46,14 @@ declare module '*.webp' {
41
46
  }
42
47
 
43
48
  declare module '*.svg' {
44
- const sizes: { readonly [key: string]: string };
45
- export default sizes;
49
+ import * as React from 'react';
50
+
51
+ export const ReactComponent: React.FunctionComponent<React.SVGProps<
52
+ SVGSVGElement
53
+ > & { title?: string }>;
54
+
55
+ const src: string;
56
+ export default src;
46
57
  }
47
58
 
48
59
  declare module '*.module.css' {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactunity/scripts",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Configuration and scripts for React Unity.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "license": "MIT",
10
10
  "engines": {
11
- "node": "^10.12.0 || >=12.0.0"
11
+ "node": ">=14.0.0"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/ReactUnity/scripts/issues"
@@ -44,69 +44,83 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@babel/core": "7.16.0",
48
- "@pmmmwh/react-refresh-webpack-plugin": "0.5.1",
49
- "@types/react": "^17.0.33",
50
- "@types/webpack-env": "1.16.3",
51
- "@typescript-eslint/eslint-plugin": "^5.2.0",
52
- "@typescript-eslint/parser": "^5.2.0",
53
- "babel-eslint": "^10.1.0",
54
- "babel-loader": "8.2.3",
55
- "babel-plugin-named-asset-import": "^0.3.7",
56
- "babel-preset-react-app": "^10.0.0",
47
+ "@babel/core": "^7.16.7",
48
+ "@babel/eslint-parser": "^7.16.5",
49
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
50
+ "@types/react": "^17.0.38",
51
+ "@types/webpack-env": "^1.16.3",
52
+ "@typescript-eslint/eslint-plugin": "^5.9.1",
53
+ "@typescript-eslint/parser": "^5.9.1",
54
+ "babel-jest": "^27.4.6",
55
+ "babel-loader": "^8.2.3",
56
+ "babel-plugin-named-asset-import": "^0.3.8",
57
+ "babel-preset-react-app": "^10.0.1",
57
58
  "bfj": "^7.0.2",
58
- "camelcase": "^6.2.0",
59
- "case-sensitive-paths-webpack-plugin": "2.4.0",
60
- "confusing-browser-globals": "^1.0.10",
61
- "css-loader": "6.5.0",
62
- "dotenv": "10.0.0",
63
- "dotenv-expand": "5.1.0",
64
- "eslint": "^7.32.0",
65
- "eslint-config-react-app": "^6.0.0",
66
- "eslint-plugin-import": "^2.25.2",
67
- "eslint-plugin-react": "^7.26.1",
68
- "eslint-plugin-react-hooks": "^4.2.0",
69
- "eslint-plugin-testing-library": "^4.12.4",
70
- "eslint-webpack-plugin": "^3.1.0",
71
- "file-loader": "6.2.0",
59
+ "camelcase": "^6.3.0",
60
+ "case-sensitive-paths-webpack-plugin": "^2.4.0",
61
+ "confusing-browser-globals": "^1.0.11",
62
+ "css-loader": "^6.5.1",
63
+ "dotenv": "^11.0.0",
64
+ "dotenv-expand": "^5.1.0",
65
+ "eslint": "^8.6.0",
66
+ "eslint-plugin-import": "^2.25.4",
67
+ "eslint-plugin-jest": "^25.3.4",
68
+ "eslint-plugin-react": "^7.28.0",
69
+ "eslint-plugin-react-hooks": "^4.3.0",
70
+ "eslint-plugin-testing-library": "^5.0.3",
71
+ "eslint-webpack-plugin": "^3.1.1",
72
+ "file-loader": "^6.2.0",
72
73
  "fs-extra": "^10.0.0",
73
- "identity-obj-proxy": "3.0.0",
74
+ "identity-obj-proxy": "^3.0.0",
75
+ "jest": "^27.4.7",
76
+ "jest-resolve": "^27.4.6",
77
+ "jest-watch-typeahead": "^1.0.0",
78
+ "mini-css-extract-plugin": "^2.4.7",
74
79
  "null-loader": "^4.0.1",
75
- "pnp-webpack-plugin": "1.7.0",
76
- "prompts": "2.4.2",
80
+ "postcss": "^8.4.5",
81
+ "postcss-loader": "^6.2.1",
82
+ "prompts": "^2.4.2",
77
83
  "raw-loader": "^4.0.2",
78
- "react-app-polyfill": "^2.0.0",
79
- "react-dev-utils": "https://github.com/ReactUnity/scripts/raw/main/temp/react-dev-utils-11.0.3-hotfix.tgz",
80
- "react-refresh": "^0.10.0",
81
- "resolve": "1.20.0",
84
+ "react-app-polyfill": "^3.0.0",
85
+ "react-dev-utils": "^12.0.0",
86
+ "react-refresh": "^0.11.0",
87
+ "resolve": "^1.21.0",
82
88
  "resolve-url-loader": "^4.0.0",
83
- "sass-loader": "^12.3.0",
84
- "semver": "7.3.5",
85
- "style-loader": "3.3.1",
86
- "terser-webpack-plugin": "5.2.4",
87
- "ts-pnp": "1.2.0",
88
- "url-loader": "4.1.1",
89
- "webpack": "5.61.0",
90
- "webpack-dev-server": "4.4.0"
89
+ "sass": "^1.48.0",
90
+ "sass-loader": "^12.4.0",
91
+ "semver": "^7.3.5",
92
+ "source-map-loader": "^3.0.1",
93
+ "style-loader": "^3.3.1",
94
+ "tailwindcss": "^3.0.13",
95
+ "terser-webpack-plugin": "^5.3.0",
96
+ "url-loader": "^4.1.1",
97
+ "webpack": "^5.66.0",
98
+ "webpack-dev-server": "^4.7.3",
99
+ "webpack-manifest-plugin": "^4.1.1"
91
100
  },
92
101
  "devDependencies": {
93
102
  "react": "^17.0.2",
94
- "typescript": "^4.4.4"
103
+ "typescript": "^4.5.4"
95
104
  },
96
105
  "optionalDependencies": {
97
- "fsevents": "^2.3.2",
98
- "sass": "^1.43.4"
106
+ "fsevents": "^2.3.2"
99
107
  },
100
108
  "peerDependencies": {
101
109
  "@reactunity/renderer": "^0.8.0",
102
- "typescript": "^4.4.4"
110
+ "react": ">= 16",
111
+ "typescript": "^4.5.4"
103
112
  },
104
113
  "peerDependenciesMeta": {
105
114
  "typescript": {
106
115
  "optional": true
107
116
  }
108
117
  },
109
- "resolutions": {
110
- "react-dev-utils": "https://github.com/ReactUnity/scripts/raw/main/temp/react-dev-utils-11.0.3-hotfix.tgz"
111
- }
118
+ "bundledDependencies": [
119
+ "@typescript-eslint/eslint-plugin",
120
+ "eslint-plugin-import",
121
+ "eslint-plugin-jest",
122
+ "eslint-plugin-react",
123
+ "eslint-plugin-react-hooks",
124
+ "eslint-plugin-testing-library"
125
+ ]
112
126
  }
package/scripts/build.js CHANGED
@@ -9,8 +9,8 @@
9
9
  'use strict';
10
10
 
11
11
  // Do this as the first thing so that any code reading it knows the right env.
12
- process.env.BABEL_ENV = process.env.BABEL_ENV || process.env.NODE_ENV || 'production';
13
- process.env.NODE_ENV = process.env.NODE_ENV || 'production';
12
+ process.env.BABEL_ENV = 'production';
13
+ process.env.NODE_ENV = 'production';
14
14
 
15
15
  // Makes the script crash on unhandled rejections instead of silently
16
16
  // ignoring them. In the future, promise rejections that are not handled will
@@ -21,15 +21,6 @@ process.on('unhandledRejection', err => {
21
21
 
22
22
  // Ensure environment variables are read.
23
23
  require('../config/env');
24
- // @remove-on-eject-begin
25
- // Do the preflight checks (only happens before eject).
26
- const verifyPackageTree = require('./utils/verifyPackageTree');
27
- if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
28
- verifyPackageTree();
29
- }
30
- const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
31
- verifyTypeScriptSetup();
32
- // @remove-on-eject-end
33
24
 
34
25
  const path = require('path');
35
26
  const chalk = require('react-dev-utils/chalk');
@@ -38,13 +29,16 @@ const bfj = require('bfj');
38
29
  const webpack = require('webpack');
39
30
  const configFactory = require('../config/webpack.config');
40
31
  const paths = require('../config/paths');
32
+ const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
41
33
  const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
34
+ const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
42
35
  const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
43
36
  const printBuildError = require('react-dev-utils/printBuildError');
44
37
 
45
38
  const measureFileSizesBeforeBuild =
46
39
  FileSizeReporter.measureFileSizesBeforeBuild;
47
40
  const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
41
+ const useYarn = fs.existsSync(paths.yarnLockFile);
48
42
 
49
43
  // These sizes are pretty large. We'll warn for bundles exceeding them.
50
44
  const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
@@ -52,13 +46,26 @@ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
52
46
 
53
47
  const isInteractive = process.stdout.isTTY;
54
48
 
49
+ // Warn and crash if required files are missing
50
+ if (!checkRequiredFiles([paths.appIndexJs])) {
51
+ process.exit(1);
52
+ }
53
+
55
54
  const argv = process.argv.slice(2);
56
55
  const writeStatsJson = argv.indexOf('--stats') !== -1;
57
56
 
58
57
  // Generate configuration
59
58
  const config = configFactory('production');
60
59
 
61
- measureFileSizesBeforeBuild(paths.appBuild)
60
+ // We require that you explicitly set browsers and do not fall back to
61
+ // browserslist defaults.
62
+ const checkBrowsers = () => Promise.resolve();
63
+ checkBrowsers(paths.appPath, isInteractive)
64
+ .then(() => {
65
+ // First, read the current file sizes in build directory.
66
+ // This lets us display how much they changed later.
67
+ return measureFileSizesBeforeBuild(paths.appBuild);
68
+ })
62
69
  .then(previousFileSizes => {
63
70
  // Remove all content but keep the directory so that
64
71
  // if you're in it, you don't end up in Trash
@@ -97,8 +104,17 @@ measureFileSizesBeforeBuild(paths.appBuild)
97
104
  );
98
105
  console.log();
99
106
 
107
+ const appPackage = require(paths.appPackageJson);
108
+ const publicUrl = paths.publicUrlOrPath;
109
+ const publicPath = config.output.publicPath;
100
110
  const buildFolder = path.relative(process.cwd(), paths.appBuild);
101
- console.log(chalk.cyan(buildFolder) + ' is ready to be used in React Unity');
111
+ printHostingInstructions(
112
+ appPackage,
113
+ publicUrl,
114
+ publicPath,
115
+ buildFolder,
116
+ useYarn
117
+ );
102
118
  },
103
119
  err => {
104
120
  const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
@@ -168,13 +184,19 @@ function build(previousFileSizes) {
168
184
  process.env.CI.toLowerCase() !== 'false') &&
169
185
  messages.warnings.length
170
186
  ) {
171
- console.log(
172
- chalk.yellow(
173
- '\nTreating warnings as errors because process.env.CI = true.\n' +
174
- 'Most CI servers set it automatically.\n'
175
- )
187
+ // Ignore sourcemap warnings in CI builds. See #8227 for more info.
188
+ const filteredWarnings = messages.warnings.filter(
189
+ w => !/Failed to parse source map/.test(w)
176
190
  );
177
- return reject(new Error(messages.warnings.join('\n\n')));
191
+ if (filteredWarnings.length) {
192
+ console.log(
193
+ chalk.yellow(
194
+ '\nTreating warnings as errors because process.env.CI = true.\n' +
195
+ 'Most CI servers set it automatically.\n'
196
+ )
197
+ );
198
+ return reject(new Error(filteredWarnings.join('\n\n')));
199
+ }
178
200
  }
179
201
 
180
202
  const resolveArgs = {