@reactunity/scripts 0.19.2 → 0.20.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.
@@ -5,9 +5,8 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- 'use strict';
9
8
 
10
- const fs = require('fs');
9
+ const fs = require('node:fs');
11
10
  const chalk = require('react-dev-utils/chalk');
12
11
  const paths = require('../../config/paths');
13
12
  const modules = require('../../config/modules');
@@ -16,55 +15,33 @@ module.exports = (resolve, rootDir, isEjecting) => {
16
15
  // Use this instead of `paths.testsSetup` to avoid putting
17
16
  // an absolute filename into configuration after ejecting.
18
17
  const setupTestsMatches = paths.testsSetup.match(/src[/\\]setupTests\.(.+)/);
19
- const setupTestsFileExtension =
20
- (setupTestsMatches && setupTestsMatches[1]) || 'js';
21
- const setupTestsFile = fs.existsSync(paths.testsSetup)
22
- ? `<rootDir>/src/setupTests.${setupTestsFileExtension}`
23
- : undefined;
18
+ const setupTestsFileExtension = setupTestsMatches?.[1] || 'js';
19
+ const setupTestsFile = fs.existsSync(paths.testsSetup) ? `<rootDir>/src/setupTests.${setupTestsFileExtension}` : undefined;
24
20
 
25
21
  const config = {
26
22
  roots: ['<rootDir>/src'],
27
23
 
28
24
  collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
29
25
 
30
- setupFiles: [
31
- isEjecting
32
- ? 'react-app-polyfill/jsdom'
33
- : require.resolve('react-app-polyfill/jsdom'),
34
- ],
26
+ setupFiles: [isEjecting ? 'react-app-polyfill/jsdom' : require.resolve('react-app-polyfill/jsdom')],
35
27
 
36
28
  setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [],
37
- testMatch: [
38
- '<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
39
- '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
40
- ],
29
+ testMatch: ['<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
41
30
  testEnvironment: 'jsdom',
42
31
  transform: {
43
- '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': resolve(
44
- 'config/jest/babelTransform.js'
45
- ),
32
+ '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': resolve('config/jest/babelTransform.js'),
46
33
  '^.+\\.css$': resolve('config/jest/cssTransform.js'),
47
- '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': resolve(
48
- 'config/jest/fileTransform.js'
49
- ),
34
+ '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': resolve('config/jest/fileTransform.js'),
50
35
  },
51
- transformIgnorePatterns: [
52
- '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
53
- '^.+\\.module\\.(css|sass|scss)$',
54
- ],
36
+ transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$', '^.+\\.module\\.(css|sass|scss)$'],
55
37
  modulePaths: modules.additionalModulePaths || [],
56
38
  moduleNameMapper: {
57
39
  '^react-native$': 'react-native-web',
58
40
  '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
59
41
  ...(modules.jestAliases || {}),
60
42
  },
61
- moduleFileExtensions: [...paths.moduleFileExtensions, 'node'].filter(
62
- ext => !ext.includes('mjs')
63
- ),
64
- watchPlugins: [
65
- 'jest-watch-typeahead/filename',
66
- 'jest-watch-typeahead/testname',
67
- ],
43
+ moduleFileExtensions: [...paths.moduleFileExtensions, 'node'].filter((ext) => !ext.includes('mjs')),
44
+ watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
68
45
  resetMocks: true,
69
46
  };
70
47
  if (rootDir) {
@@ -92,7 +69,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
92
69
  'watchPathIgnorePatterns',
93
70
  ];
94
71
  if (overrides) {
95
- supportedKeys.forEach(key => {
72
+ supportedKeys.forEach((key) => {
96
73
  if (Object.prototype.hasOwnProperty.call(overrides, key)) {
97
74
  if (Array.isArray(config[key]) || typeof config[key] !== 'object') {
98
75
  // for arrays or primitive types, directly override the config key
@@ -107,41 +84,19 @@ module.exports = (resolve, rootDir, isEjecting) => {
107
84
  });
108
85
  const unsupportedKeys = Object.keys(overrides);
109
86
  if (unsupportedKeys.length) {
110
- const isOverridingSetupFile =
111
- unsupportedKeys.indexOf('setupFilesAfterEnv') > -1;
87
+ const isOverridingSetupFile = unsupportedKeys.indexOf('setupFilesAfterEnv') > -1;
112
88
 
113
89
  if (isOverridingSetupFile) {
114
90
  console.error(
115
91
  chalk.red(
116
- 'We detected ' +
117
- chalk.bold('setupFilesAfterEnv') +
118
- ' in your package.json.\n\n' +
119
- 'Remove it from Jest configuration, and put the initialization code in ' +
120
- chalk.bold('src/setupTests.js') +
121
- '.\nThis file will be loaded automatically.\n'
122
- )
92
+ `We detected ${chalk.bold('setupFilesAfterEnv')} in your package.json.\n\nRemove it from Jest configuration, and put the initialization code in ${chalk.bold('src/setupTests.js')}.\nThis file will be loaded automatically.\n`,
93
+ ),
123
94
  );
124
95
  } else {
125
96
  console.error(
126
97
  chalk.red(
127
- '\nOut of the box, Create React App only supports overriding ' +
128
- 'these Jest options:\n\n' +
129
- supportedKeys
130
- .map(key => chalk.bold(' \u2022 ' + key))
131
- .join('\n') +
132
- '.\n\n' +
133
- 'These options in your package.json Jest configuration ' +
134
- 'are not currently supported by Create React App:\n\n' +
135
- unsupportedKeys
136
- .map(key => chalk.bold(' \u2022 ' + key))
137
- .join('\n') +
138
- '\n\nIf you wish to override other Jest options, you need to ' +
139
- 'eject from the default setup. You can do so by running ' +
140
- chalk.bold('npm run eject') +
141
- ' but remember that this is a one-way operation. ' +
142
- 'You may also file an issue with Create React App to discuss ' +
143
- 'supporting more options out of the box.\n'
144
- )
98
+ `\nOut of the box, Create React App only supports overriding these Jest options:\n\n${supportedKeys.map((key) => chalk.bold(` \u2022 ${key}`)).join('\n')}.\n\nThese options in your package.json Jest configuration are not currently supported by Create React App:\n\n${unsupportedKeys.map((key) => chalk.bold(` \u2022 ${key}`)).join('\n')}\n\nIf you wish to override other Jest options, you need to eject from the default setup. You can do so by running ${chalk.bold('npm run eject')} but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.\n`,
99
+ ),
145
100
  );
146
101
  }
147
102
 
@@ -6,14 +6,12 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- 'use strict';
10
-
11
9
  const chalk = require('react-dev-utils/chalk');
12
- const fs = require('fs');
10
+ const fs = require('node:fs');
13
11
  const resolve = require('resolve');
14
- const path = require('path');
12
+ const path = require('node:path');
15
13
  const paths = require('../../config/paths');
16
- const os = require('os');
14
+ const os = require('node:os');
17
15
  const semver = require('semver');
18
16
  const immer = require('react-dev-utils/immer').produce;
19
17
  const globby = require('react-dev-utils/globby').sync;
@@ -32,24 +30,18 @@ const hasJsxRuntime = (() => {
32
30
  })();
33
31
 
34
32
  function writeJson(fileName, object) {
35
- fs.writeFileSync(
36
- fileName,
37
- JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL
38
- );
33
+ fs.writeFileSync(fileName, JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL);
39
34
  }
40
35
 
41
36
  function verifyNoTypeScript() {
42
- const typescriptFiles = globby(
43
- ['**/*.(ts|tsx)', '!**/node_modules', '!**/*.d.ts'],
44
- { cwd: paths.appSrc }
45
- );
37
+ const typescriptFiles = globby(['**/*.(ts|tsx)', '!**/node_modules', '!**/*.d.ts'], { cwd: paths.appSrc });
46
38
  if (typescriptFiles.length > 0) {
47
39
  console.warn(
48
40
  chalk.yellow(
49
41
  `We detected TypeScript in your project (${chalk.bold(
50
- `src${path.sep}${typescriptFiles[0]}`
51
- )}) and created a ${chalk.bold('tsconfig.json')} file for you.`
52
- )
42
+ `src${path.sep}${typescriptFiles[0]}`,
43
+ )}) and created a ${chalk.bold('tsconfig.json')} file for you.`,
44
+ ),
53
45
  );
54
46
  console.warn();
55
47
  return false;
@@ -77,37 +69,30 @@ function verifyTypeScriptSetup() {
77
69
  // https://github.com/jsdom/jsdom/issues/2961
78
70
  const globalThisWasDefined = !!global.globalThis;
79
71
 
80
- ts = require(resolve.sync('typescript', {
81
- basedir: paths.appNodeModules,
82
- }));
72
+ ts = require(
73
+ resolve.sync('typescript', {
74
+ basedir: paths.appNodeModules,
75
+ }),
76
+ );
83
77
 
84
78
  if (!globalThisWasDefined && !!global.globalThis) {
79
+ // biome-ignore lint/performance/noDelete: <explanation>
85
80
  delete global.globalThis;
86
81
  }
87
82
  } catch (_) {
88
- console.error(
89
- chalk.bold.red(
90
- `It looks like you're trying to use TypeScript but do not have ${chalk.bold(
91
- 'typescript'
92
- )} installed.`
93
- )
94
- );
83
+ console.error(chalk.bold.red(`It looks like you're trying to use TypeScript but do not have ${chalk.bold('typescript')} installed.`));
95
84
  console.error(
96
85
  chalk.bold(
97
86
  'Please install',
98
87
  chalk.cyan.bold('typescript'),
99
88
  'by running',
100
- chalk.cyan.bold(
101
- isYarn ? 'yarn add typescript' : 'npm install typescript'
102
- ) + '.'
103
- )
89
+ `${chalk.cyan.bold(isYarn ? 'yarn add typescript' : 'npm install typescript')}.`,
90
+ ),
104
91
  );
105
92
  console.error(
106
93
  chalk.bold(
107
- 'If you are not trying to use TypeScript, please remove the ' +
108
- chalk.cyan('tsconfig.json') +
109
- ' file from your package root (and any TypeScript files).'
110
- )
94
+ `If you are not trying to use TypeScript, please remove the ${chalk.cyan('tsconfig.json')} file from your package root (and any TypeScript files).`,
95
+ ),
111
96
  );
112
97
  console.error();
113
98
  process.exit(1);
@@ -146,21 +131,15 @@ function verifyTypeScriptSetup() {
146
131
  isolatedModules: { value: true, reason: 'implementation limitation' },
147
132
  noEmit: { value: true },
148
133
  jsx: {
149
- parsedValue:
150
- hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
151
- ? ts.JsxEmit.ReactJSX
152
- : ts.JsxEmit.React,
153
- value:
154
- hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
155
- ? 'react-jsx'
156
- : 'react',
134
+ parsedValue: hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta') ? ts.JsxEmit.ReactJSX : ts.JsxEmit.React,
135
+ value: hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta') ? 'react-jsx' : 'react',
157
136
  reason: 'to support the new JSX transform in React 17',
158
137
  },
159
138
  paths: { value: undefined, reason: 'aliased imports are not supported' },
160
139
  };
161
140
 
162
141
  const formatDiagnosticHost = {
163
- getCanonicalFileName: fileName => fileName,
142
+ getCanonicalFileName: (fileName) => fileName,
164
143
  getCurrentDirectory: ts.sys.getCurrentDirectory,
165
144
  getNewLine: () => os.EOL,
166
145
  };
@@ -170,10 +149,7 @@ function verifyTypeScriptSetup() {
170
149
  let parsedTsConfig;
171
150
  let parsedCompilerOptions;
172
151
  try {
173
- const { config: readTsConfig, error } = ts.readConfigFile(
174
- paths.appTsConfig,
175
- ts.sys.readFile
176
- );
152
+ const { config: readTsConfig, error } = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile);
177
153
 
178
154
  if (error) {
179
155
  throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
@@ -185,33 +161,23 @@ function verifyTypeScriptSetup() {
185
161
  // Calling this function also mutates the tsconfig above,
186
162
  // adding in "include" and "exclude", but the compilerOptions remain untouched
187
163
  let result;
188
- parsedTsConfig = immer(readTsConfig, config => {
189
- result = ts.parseJsonConfigFileContent(
190
- config,
191
- ts.sys,
192
- path.dirname(paths.appTsConfig)
193
- );
164
+ parsedTsConfig = immer(readTsConfig, (config) => {
165
+ result = ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(paths.appTsConfig));
194
166
  });
195
167
 
196
- if (result.errors && result.errors.length) {
197
- throw new Error(
198
- ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
199
- );
168
+ if (result.errors?.length) {
169
+ throw new Error(ts.formatDiagnostic(result.errors[0], formatDiagnosticHost));
200
170
  }
201
171
 
202
172
  parsedCompilerOptions = result.options;
203
173
  } catch (e) {
204
174
  if (e && e.name === 'SyntaxError') {
205
175
  console.error(
206
- chalk.red.bold(
207
- 'Could not parse',
208
- chalk.cyan('tsconfig.json') + '.',
209
- 'Please make sure it contains syntactically correct JSON.'
210
- )
176
+ chalk.red.bold('Could not parse', `${chalk.cyan('tsconfig.json')}.`, 'Please make sure it contains syntactically correct JSON.'),
211
177
  );
212
178
  }
213
179
 
214
- console.log(e && e.message ? `${e.message}` : '');
180
+ console.log(e?.message ? `${e.message}` : '');
215
181
  process.exit(1);
216
182
  }
217
183
 
@@ -224,40 +190,33 @@ function verifyTypeScriptSetup() {
224
190
  const { parsedValue, value, suggested, reason } = compilerOptions[option];
225
191
 
226
192
  const valueToCheck = parsedValue === undefined ? value : parsedValue;
227
- const coloredOption = chalk.cyan('compilerOptions.' + option);
193
+ const coloredOption = chalk.cyan(`compilerOptions.${option}`);
228
194
 
229
195
  if (suggested != null) {
230
196
  if (parsedCompilerOptions[option] === undefined) {
231
- appTsConfig = immer(appTsConfig, config => {
197
+ appTsConfig = immer(appTsConfig, (config) => {
232
198
  config.compilerOptions[option] = suggested;
233
199
  });
234
- messages.push(
235
- `${coloredOption} to be ${chalk.bold(
236
- 'suggested'
237
- )} value: ${chalk.cyan.bold(suggested)} (this can be changed)`
238
- );
200
+ messages.push(`${coloredOption} to be ${chalk.bold('suggested')} value: ${chalk.cyan.bold(suggested)} (this can be changed)`);
239
201
  }
240
202
  } else if (parsedCompilerOptions[option] !== valueToCheck) {
241
- appTsConfig = immer(appTsConfig, config => {
203
+ appTsConfig = immer(appTsConfig, (config) => {
242
204
  config.compilerOptions[option] = value;
243
205
  });
244
206
  messages.push(
245
207
  `${coloredOption} ${chalk.bold(
246
- valueToCheck == null ? 'must not' : 'must'
247
- )} be ${valueToCheck == null ? 'set' : chalk.cyan.bold(value)}` +
248
- (reason != null ? ` (${reason})` : '')
208
+ valueToCheck == null ? 'must not' : 'must',
209
+ )} be ${valueToCheck == null ? 'set' : chalk.cyan.bold(value)}${reason != null ? ` (${reason})` : ''}`,
249
210
  );
250
211
  }
251
212
  }
252
213
 
253
214
  // tsconfig will have the merged "include" and "exclude" by this point
254
215
  if (parsedTsConfig.include == null) {
255
- appTsConfig = immer(appTsConfig, config => {
216
+ appTsConfig = immer(appTsConfig, (config) => {
256
217
  config.include = ['src'];
257
218
  });
258
- messages.push(
259
- `${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`
260
- );
219
+ messages.push(`${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`);
261
220
  }
262
221
 
263
222
  const types = appTsConfig.compilerOptions.types || (appTsConfig.compilerOptions.types = []);
@@ -265,45 +224,35 @@ function verifyTypeScriptSetup() {
265
224
 
266
225
  if (!types.includes('@reactunity/scripts/main')) {
267
226
  types.push('@reactunity/scripts/main');
268
- messages.push(
269
- `${chalk.cyan('types')} should include ${chalk.cyan.bold('@reactunity/scripts/main')}`
270
- );
227
+ messages.push(`${chalk.cyan('types')} should include ${chalk.cyan.bold('@reactunity/scripts/main')}`);
271
228
  }
272
229
 
273
- if (!['@reactunity/scripts/ugui', '@reactunity/scripts/uitoolkit', '@reactunity/scripts/editor', '@reactunity/scripts/tests'].includes(importSource)) {
230
+ if (
231
+ !['@reactunity/scripts/ugui', '@reactunity/scripts/uitoolkit', '@reactunity/scripts/editor', '@reactunity/scripts/tests'].includes(
232
+ importSource,
233
+ )
234
+ ) {
274
235
  appTsConfig.compilerOptions.jsxImportSource = '@reactunity/scripts/ugui';
275
236
  messages.push(
276
- `${chalk.cyan('jsxImportSource')} should include a valid platform target. Assuming ${chalk.cyan.bold('@reactunity/scripts/ugui')}`
237
+ `${chalk.cyan('jsxImportSource')} should include a valid platform target. Assuming ${chalk.cyan.bold('@reactunity/scripts/ugui')}`,
277
238
  );
278
239
  }
279
240
 
280
241
  // Deprecate `react-unity-scripts` types
281
242
  if (fs.existsSync(paths.appTypeDeclarations)) {
282
243
  messages.push(
283
- `References to ${chalk.cyan('@reactunity/scripts')} does not have to be in ${chalk.cyan.bold('react-unity.d.ts')} anymore. It can be removed.`
244
+ `References to ${chalk.cyan('@reactunity/scripts')} does not have to be in ${chalk.cyan.bold('react-unity.d.ts')} anymore. It can be removed.`,
284
245
  );
285
246
  }
286
247
 
287
248
  if (messages.length > 0) {
288
249
  if (firstTimeSetup) {
289
- console.log(
290
- chalk.bold(
291
- 'Your',
292
- chalk.cyan('tsconfig.json'),
293
- 'has been populated with default values.'
294
- )
295
- );
250
+ console.log(chalk.bold('Your', chalk.cyan('tsconfig.json'), 'has been populated with default values.'));
296
251
  console.log();
297
252
  } else {
298
- console.warn(
299
- chalk.bold(
300
- 'The following changes are being made to your',
301
- chalk.cyan('tsconfig.json'),
302
- 'file:'
303
- )
304
- );
305
- messages.forEach(message => {
306
- console.warn(' - ' + message);
253
+ console.warn(chalk.bold('The following changes are being made to your', chalk.cyan('tsconfig.json'), 'file:'));
254
+ messages.forEach((message) => {
255
+ console.warn(` - ${message}`);
307
256
  });
308
257
  console.warn();
309
258
  }
package/tsconfig.json CHANGED
@@ -24,8 +24,6 @@
24
24
  "resolveJsonModule": true,
25
25
  "isolatedModules": true,
26
26
  "noEmit": true,
27
- "types": [
28
- "@reactunity/scripts/main"
29
- ]
27
+ "types": ["@reactunity/scripts/main"]
30
28
  }
31
29
  }
@@ -1,43 +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
-
8
- 'use strict';
9
-
10
- module.exports = {
11
- root: true,
12
-
13
- parser: '@babel/eslint-parser',
14
-
15
- plugins: ['react'],
16
-
17
- env: {
18
- browser: true,
19
- commonjs: true,
20
- es6: true,
21
- jest: true,
22
- node: true,
23
- },
24
-
25
- parserOptions: {
26
- sourceType: 'module',
27
- requireConfigFile: false,
28
- babelOptions: {
29
- presets: [require.resolve('babel-preset-react-app/prod')],
30
- },
31
- },
32
-
33
- settings: {
34
- react: {
35
- version: 'detect',
36
- },
37
- },
38
-
39
- rules: {
40
- 'react/jsx-uses-vars': 'warn',
41
- 'react/jsx-uses-react': 'warn',
42
- },
43
- };