@reactunity/scripts 0.19.2 → 0.20.1

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.
@@ -1,64 +1,44 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- 'use strict';
10
2
 
11
3
  // Makes the script crash on unhandled rejections instead of silently
12
4
  // ignoring them. In the future, promise rejections that are not handled will
13
5
  // terminate the Node.js process with a non-zero exit code.
14
- process.on('unhandledRejection', err => {
6
+ process.on('unhandledRejection', (err) => {
15
7
  throw err;
16
8
  });
17
9
 
18
10
  const spawn = require('react-dev-utils/crossSpawn');
19
11
  const args = process.argv.slice(2);
20
12
 
21
- const scriptIndex = args.findIndex(
22
- x =>
23
- x === 'build' ||
24
- x === 'eject' ||
25
- x === 'start' ||
26
- x === 'test' ||
27
- x === 'clean' ||
28
- x === 'lint'
29
- );
13
+ const scriptIndex = args.findIndex((x) => x === 'build' || x === 'eject' || x === 'start' || x === 'test' || x === 'clean');
30
14
  const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
31
15
  const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
32
16
 
33
- if (['build', 'eject', 'start', 'test', 'clean', 'lint'].includes(script)) {
17
+ if (['build', 'eject', 'start', 'test', 'clean'].includes(script)) {
34
18
  const result = spawn.sync(
35
19
  process.execPath,
36
- nodeArgs
37
- .concat(require.resolve('../scripts/' + script))
38
- .concat(args.slice(scriptIndex + 1)),
39
- { stdio: 'inherit' }
20
+ nodeArgs.concat(require.resolve(`../scripts/${script}`)).concat(args.slice(scriptIndex + 1)),
21
+ { stdio: 'inherit' },
40
22
  );
41
23
  if (result.signal) {
42
24
  if (result.signal === 'SIGKILL') {
43
25
  console.log(
44
26
  'The build failed because the process exited too early. ' +
45
- 'This probably means the system ran out of memory or someone called ' +
46
- '`kill -9` on the process.'
27
+ 'This probably means the system ran out of memory or someone called ' +
28
+ '`kill -9` on the process.',
47
29
  );
48
30
  } else if (result.signal === 'SIGTERM') {
49
31
  console.log(
50
32
  'The build failed because the process exited too early. ' +
51
- 'Someone might have called `kill` or `killall`, or the system could ' +
52
- 'be shutting down.'
33
+ 'Someone might have called `kill` or `killall`, or the system could ' +
34
+ 'be shutting down.',
53
35
  );
54
36
  }
55
37
  process.exit(1);
56
38
  }
57
39
  process.exit(result.status);
58
40
  } else {
59
- console.log('Unknown script "' + script + '".');
41
+ console.log(`Unknown script "${script}".`);
60
42
  console.log('Perhaps you need to update react-unity-scripts?');
61
- console.log(
62
- 'See: https://github.com/KurtGokhan/react-unity-scripts.git'
63
- );
43
+ console.log('See: https://github.com/KurtGokhan/react-unity-scripts.git');
64
44
  }
@@ -3,14 +3,14 @@ const babelPresetReactApp = require('babel-preset-react-app');
3
3
 
4
4
  // Extend babel-preset-react-app to accept custom jsxImportSource. This is required for things like @emotion/react
5
5
 
6
- module.exports = function (api, opts) {
6
+ module.exports = (api, opts) => {
7
7
  const original = babelPresetReactApp(api, opts);
8
8
  const jsxImportSource = process.env.JSX_IMPORT_SOURCE;
9
9
 
10
10
  if (jsxImportSource) {
11
- const preset = original.presets.find(x => x[0] === babelPresetReact);
11
+ const preset = original.presets.find((x) => x[0] === babelPresetReact);
12
12
 
13
- if (preset && preset[1]) {
13
+ if (preset?.[1]) {
14
14
  preset[1].importSource = jsxImportSource;
15
15
  }
16
16
  }
package/config/env.js CHANGED
@@ -1,15 +1,7 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
10
1
 
11
- const fs = require('fs');
12
- const path = require('path');
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
13
5
  const paths = require('./paths');
14
6
 
15
7
  // Make sure that including paths.js after env.js will read .env variables.
@@ -17,9 +9,7 @@ delete require.cache[require.resolve('./paths')];
17
9
 
18
10
  const NODE_ENV = process.env.NODE_ENV;
19
11
  if (!NODE_ENV) {
20
- throw new Error(
21
- 'The NODE_ENV environment variable is required but was not specified.'
22
- );
12
+ throw new Error('The NODE_ENV environment variable is required but was not specified.');
23
13
  }
24
14
 
25
15
  // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
@@ -38,12 +28,12 @@ const dotenvFiles = [
38
28
  // that have already been set. Variable expansion is supported in .env files.
39
29
  // https://github.com/motdotla/dotenv
40
30
  // https://github.com/motdotla/dotenv-expand
41
- dotenvFiles.forEach(dotenvFile => {
31
+ dotenvFiles.forEach((dotenvFile) => {
42
32
  if (fs.existsSync(dotenvFile)) {
43
33
  require('dotenv-expand').expand(
44
34
  require('dotenv').config({
45
35
  path: dotenvFile,
46
- })
36
+ }),
47
37
  );
48
38
  }
49
39
  });
@@ -60,8 +50,8 @@ dotenvFiles.forEach(dotenvFile => {
60
50
  const appDirectory = fs.realpathSync(process.cwd());
61
51
  process.env.NODE_PATH = (process.env.NODE_PATH || '')
62
52
  .split(path.delimiter)
63
- .filter(folder => folder && !path.isAbsolute(folder))
64
- .map(folder => path.resolve(appDirectory, folder))
53
+ .filter((folder) => folder && !path.isAbsolute(folder))
54
+ .map((folder) => path.resolve(appDirectory, folder))
65
55
  .join(path.delimiter);
66
56
 
67
57
  // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
@@ -70,7 +60,7 @@ const REACT_APP = /^REACT_APP_/i;
70
60
 
71
61
  function getClientEnvironment(publicUrl) {
72
62
  const raw = Object.keys(process.env)
73
- .filter(key => REACT_APP.test(key))
63
+ .filter((key) => REACT_APP.test(key))
74
64
  .reduce(
75
65
  (env, key) => {
76
66
  env[key] = process.env[key];
@@ -96,7 +86,7 @@ function getClientEnvironment(publicUrl) {
96
86
  // Whether or not react-refresh is enabled.
97
87
  // It is defined here so it is available in the webpackHotDevClient.
98
88
  FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
99
- }
89
+ },
100
90
  );
101
91
  // Stringify all values so we can feed into webpack DefinePlugin
102
92
  const stringified = {
@@ -1,16 +1,8 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
10
1
 
11
- const fs = require('fs');
12
- const path = require('path');
13
- const crypto = require('crypto');
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const crypto = require('node:crypto');
14
6
  const chalk = require('react-dev-utils/chalk');
15
7
  const paths = require('./paths');
16
8
 
@@ -22,29 +14,21 @@ function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
22
14
  // publicEncrypt will throw an error with an invalid cert
23
15
  encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
24
16
  } catch (err) {
25
- throw new Error(
26
- `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
27
- );
17
+ throw new Error(`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`);
28
18
  }
29
19
 
30
20
  try {
31
21
  // privateDecrypt will throw an error with an invalid key
32
22
  crypto.privateDecrypt(key, encrypted);
33
23
  } catch (err) {
34
- throw new Error(
35
- `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${err.message}`
36
- );
24
+ throw new Error(`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${err.message}`);
37
25
  }
38
26
  }
39
27
 
40
28
  // Read file and throw an error if it doesn't exist
41
29
  function readEnvFile(file, type) {
42
30
  if (!fs.existsSync(file)) {
43
- throw new Error(
44
- `You specified ${chalk.cyan(
45
- type
46
- )} in your env, but the file "${chalk.yellow(file)}" can't be found.`
47
- );
31
+ throw new Error(`You specified ${chalk.cyan(type)} in your env, but the file "${chalk.yellow(file)}" can't be found.`);
48
32
  }
49
33
  return fs.readFileSync(file);
50
34
  }
@@ -1,12 +1,4 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2014-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
1
+
10
2
 
11
3
  const babelJest = require('babel-jest').default;
12
4
 
@@ -1,12 +1,4 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2014-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
1
+
10
2
 
11
3
  // This is a custom Jest transformer turning style imports into empty objects.
12
4
  // http://facebook.github.io/jest/docs/en/webpack.html
@@ -1,6 +1,6 @@
1
- 'use strict';
2
1
 
3
- const path = require('path');
2
+
3
+ const path = require('node:path');
4
4
  const camelcase = require('camelcase');
5
5
 
6
6
  // This is a custom Jest transformer turning file imports into filenames.
package/config/modules.js CHANGED
@@ -1,15 +1,7 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
10
1
 
11
- const fs = require('fs');
12
- const path = require('path');
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
13
5
  const paths = require('./paths');
14
6
  const chalk = require('react-dev-utils/chalk');
15
7
  const resolve = require('resolve');
@@ -52,8 +44,8 @@ function getAdditionalModulePaths(options = {}) {
52
44
  throw new Error(
53
45
  chalk.red.bold(
54
46
  "Your project's `baseUrl` can only be set to `src` or `node_modules`." +
55
- ' Create React App does not support other values at this time.'
56
- )
47
+ ' Create React App does not support other values at this time.',
48
+ ),
57
49
  );
58
50
  }
59
51
 
@@ -106,7 +98,7 @@ function getModules() {
106
98
 
107
99
  if (hasTsConfig && hasJsConfig) {
108
100
  throw new Error(
109
- 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
101
+ 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.',
110
102
  );
111
103
  }
112
104
 
@@ -116,9 +108,11 @@ function getModules() {
116
108
  // TypeScript project and set up the config
117
109
  // based on tsconfig.json
118
110
  if (hasTsConfig) {
119
- const ts = require(resolve.sync('typescript', {
120
- basedir: paths.appNodeModules,
121
- }));
111
+ const ts = require(
112
+ resolve.sync('typescript', {
113
+ basedir: paths.appNodeModules,
114
+ }),
115
+ );
122
116
  config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config;
123
117
  // Otherwise we'll check if there is jsconfig.json
124
118
  // for non TS projects.
package/config/paths.js CHANGED
@@ -1,21 +1,13 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
10
1
 
11
- const path = require('path');
12
- const fs = require('fs');
2
+
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
13
5
  const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
14
6
 
15
7
  // Make sure any symlinks in the project folder are resolved:
16
8
  // https://github.com/facebook/create-react-app/issues/637
17
9
  const appDirectory = fs.realpathSync(process.cwd());
18
- const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
10
+ const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
19
11
 
20
12
  // We use `PUBLIC_URL` environment variable or "homepage" field to infer
21
13
  // "public path" at which the app is served.
@@ -26,31 +18,17 @@ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
26
18
  const publicUrlOrPath = getPublicUrlOrPath(
27
19
  process.env.NODE_ENV === 'development',
28
20
  require(resolveApp('package.json')).homepage,
29
- process.env.PUBLIC_URL
21
+ process.env.PUBLIC_URL,
30
22
  );
31
23
 
32
24
  const buildPath = process.env.BUILD_PATH || '../Assets/Resources/react';
33
25
  const manifestPath = path.join(buildPath, 'asset-manifest.json');
34
26
 
35
- const moduleFileExtensions = [
36
- 'web.mjs',
37
- 'mjs',
38
- 'web.js',
39
- 'js',
40
- 'web.ts',
41
- 'ts',
42
- 'web.tsx',
43
- 'tsx',
44
- 'json',
45
- 'web.jsx',
46
- 'jsx',
47
- ];
27
+ const moduleFileExtensions = ['web.mjs', 'mjs', 'web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx'];
48
28
 
49
29
  // Resolve file paths in the same order as webpack
50
30
  const resolveModule = (resolveFn, filePath) => {
51
- const extension = moduleFileExtensions.find(extension =>
52
- fs.existsSync(resolveFn(`${filePath}.${extension}`))
53
- );
31
+ const extension = moduleFileExtensions.find((extension) => fs.existsSync(resolveFn(`${filePath}.${extension}`)));
54
32
 
55
33
  if (extension) {
56
34
  return resolveFn(`${filePath}.${extension}`);
@@ -85,7 +63,7 @@ module.exports = {
85
63
  };
86
64
 
87
65
  // @remove-on-eject-begin
88
- const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
66
+ const resolveOwn = (relativePath) => path.resolve(__dirname, '..', relativePath);
89
67
 
90
68
  // config before eject: we're in ./node_modules/react-unity-scripts/config/
91
69
  module.exports = {
@@ -119,15 +97,10 @@ module.exports = {
119
97
 
120
98
  const ownPackageJson = require('../package.json');
121
99
  const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
122
- const reactScriptsLinked =
123
- fs.existsSync(reactScriptsPath) &&
124
- fs.lstatSync(reactScriptsPath).isSymbolicLink();
100
+ const reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
125
101
 
126
102
  // config before publish: we're in ./packages/react-unity-scripts/config/
127
- if (
128
- !reactScriptsLinked &&
129
- __dirname.indexOf(path.join('packages', 'react-unity-scripts', 'config')) !== -1
130
- ) {
103
+ if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-unity-scripts', 'config')) !== -1) {
131
104
  const templatePath = '../cra-template/template';
132
105
  module.exports = {
133
106
  dotenv: resolveOwn(`${templatePath}/.env`),
@@ -1,14 +1,14 @@
1
1
  function registerUnityMiddleware(app) {
2
2
  // Allow serving Unity builds
3
3
  function contentEncodingShorthand(pattern, encoding) {
4
- app.get(pattern, function (req, res, next) {
4
+ app.get(pattern, (req, res, next) => {
5
5
  res.set('Content-Encoding', encoding);
6
6
  next();
7
7
  });
8
8
  }
9
9
 
10
10
  function contentTypeShorthand(pattern, type) {
11
- app.get(pattern, function (req, res, next) {
11
+ app.get(pattern, (req, res, next) => {
12
12
  res.set('Content-Type', type);
13
13
  next();
14
14
  });
@@ -1,7 +1,7 @@
1
- 'use strict';
2
- const { createHash } = require('crypto');
3
1
 
4
- module.exports = env => {
2
+ const { createHash } = require('node:crypto');
3
+
4
+ module.exports = (env) => {
5
5
  const hash = createHash('md5');
6
6
  hash.update(JSON.stringify(env));
7
7