@reactunity/scripts 0.15.2 → 0.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactunity/scripts",
3
- "version": "0.15.2",
3
+ "version": "0.16.1",
4
4
  "description": "Configuration and scripts for React Unity.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,6 @@
18
18
  "config",
19
19
  "lib",
20
20
  "scripts",
21
- "utils",
22
21
  "tsconfig.json"
23
22
  ],
24
23
  "bin": {
@@ -46,73 +45,73 @@
46
45
  },
47
46
  "tsconfig": "./tsconfig.json",
48
47
  "dependencies": {
49
- "@babel/core": "^7.21.3",
50
- "@babel/eslint-parser": "^7.21.3",
51
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
52
- "@svgr/webpack": "^7.0.0",
53
- "@types/react": "^18.0.31",
54
- "@types/webpack-env": "^1.18.0",
55
- "@typescript-eslint/eslint-plugin": "^5.57.0",
56
- "@typescript-eslint/parser": "^5.57.0",
57
- "babel-jest": "^29.5.0",
58
- "babel-loader": "^9.1.2",
48
+ "@babel/core": "^7.22.17",
49
+ "@babel/eslint-parser": "^7.22.15",
50
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
51
+ "@svgr/webpack": "^8.1.0",
52
+ "@types/react": "^18.2.21",
53
+ "@types/webpack-env": "^1.18.1",
54
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
55
+ "@typescript-eslint/parser": "^6.7.0",
56
+ "babel-jest": "^29.6.4",
57
+ "babel-loader": "^9.1.3",
59
58
  "babel-plugin-named-asset-import": "^0.3.8",
60
59
  "babel-preset-react-app": "^10.0.1",
61
- "bfj": "^7.0.2",
62
- "camelcase": "^7.0.1",
60
+ "bfj": "^8.0.0",
61
+ "camelcase": "^8.0.0",
63
62
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
64
63
  "confusing-browser-globals": "^1.0.11",
65
- "css-loader": "^6.7.3",
66
- "dotenv": "^16.0.3",
64
+ "css-loader": "^6.8.1",
65
+ "dotenv": "^16.3.1",
67
66
  "dotenv-expand": "^10.0.0",
68
- "eslint": "^8.37.0",
69
- "eslint-plugin-import": "^2.27.5",
70
- "eslint-plugin-jest": "^27.2.1",
71
- "eslint-plugin-react": "^7.32.2",
67
+ "eslint": "^8.49.0",
68
+ "eslint-plugin-import": "^2.28.1",
69
+ "eslint-plugin-jest": "^27.2.3",
70
+ "eslint-plugin-react": "^7.33.2",
72
71
  "eslint-plugin-react-hooks": "^4.6.0",
73
- "eslint-plugin-testing-library": "^5.10.2",
74
- "eslint-webpack-plugin": "^4.0.0",
72
+ "eslint-plugin-testing-library": "^6.0.1",
73
+ "eslint-webpack-plugin": "^4.0.1",
75
74
  "file-loader": "^6.2.0",
76
- "fork-ts-checker-webpack-plugin": "^6.5.3",
75
+ "fork-ts-checker-webpack-plugin": "^8.0.0",
77
76
  "fs-extra": "^11.1.1",
78
77
  "identity-obj-proxy": "^3.0.0",
79
- "jest": "^29.5.0",
80
- "jest-resolve": "^29.5.0",
78
+ "jest": "^29.6.4",
79
+ "jest-resolve": "^29.6.4",
81
80
  "jest-watch-typeahead": "^2.2.2",
82
- "mini-css-extract-plugin": "^2.7.5",
81
+ "mini-css-extract-plugin": "^2.7.6",
83
82
  "null-loader": "^4.0.1",
84
- "postcss": "^8.4.21",
85
- "postcss-loader": "^7.1.0",
83
+ "postcss": "^8.4.29",
84
+ "postcss-loader": "^7.3.3",
86
85
  "prompts": "^2.4.2",
87
86
  "raw-loader": "^4.0.2",
88
87
  "react-app-polyfill": "^3.0.0",
89
88
  "react-dev-utils": "^12.0.1",
90
89
  "react-refresh": "^0.14.0",
91
- "resolve": "^1.22.1",
90
+ "resolve": "^1.22.4",
92
91
  "resolve-url-loader": "^5.0.0",
93
- "sass": "^1.60.0",
94
- "sass-loader": "^13.2.2",
95
- "semver": "^7.3.8",
92
+ "sass": "^1.66.1",
93
+ "sass-loader": "^13.3.2",
94
+ "semver": "^7.5.4",
96
95
  "source-map-loader": "^4.0.1",
97
- "style-loader": "^3.3.2",
98
- "tailwindcss": "^3.3.0",
99
- "terser-webpack-plugin": "^5.3.7",
96
+ "style-loader": "^3.3.3",
97
+ "tailwindcss": "^3.3.3",
98
+ "terser-webpack-plugin": "^5.3.9",
100
99
  "url-loader": "^4.1.1",
101
- "webpack": "^5.77.0",
102
- "webpack-dev-server": "^4.13.1",
100
+ "webpack": "^5.88.2",
101
+ "webpack-dev-server": "^4.15.1",
103
102
  "webpack-manifest-plugin": "^5.0.0"
104
103
  },
105
104
  "devDependencies": {
106
- "typescript": "^5.0.2"
105
+ "typescript": "^5.2.2"
107
106
  },
108
107
  "optionalDependencies": {
109
- "fsevents": "^2.3.2"
108
+ "fsevents": "^2.3.3"
110
109
  },
111
110
  "peerDependencies": {
112
111
  "@reactunity/previewer": "*",
113
- "@reactunity/renderer": "^0.15.0",
112
+ "@reactunity/renderer": "^0.16.1",
114
113
  "react": "^18.0.0",
115
- "typescript": ">=4"
114
+ "typescript": ">=5"
116
115
  },
117
116
  "peerDependenciesMeta": {
118
117
  "@reactunity/previewer": {
package/scripts/lint.js CHANGED
@@ -30,8 +30,14 @@ const formatter = require('react-dev-utils/eslintFormatter');
30
30
  const { ESLint } = require('eslint');
31
31
 
32
32
  (async function main() {
33
- const eslint = new ESLint(eslintConfig);
33
+ const fix = process.argv.includes('--fix');
34
+
35
+ const eslint = new ESLint({
36
+ ...eslintConfig,
37
+ fix,
38
+ });
34
39
  const results = await eslint.lintFiles([paths.appSrc]);
40
+ if(fix) await ESLint.outputFixes(results);
35
41
  const resultText = formatter(results);
36
42
  console.log(resultText);
37
43
  })().catch(error => {
@@ -6,309 +6,309 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- 'use strict';
10
-
11
- const chalk = require('react-dev-utils/chalk');
12
- const fs = require('fs');
13
- const resolve = require('resolve');
14
- const path = require('path');
15
- const paths = require('../../config/paths');
16
- const os = require('os');
17
- const semver = require('semver');
18
- const immer = require('react-dev-utils/immer').produce;
19
- const globby = require('react-dev-utils/globby').sync;
20
-
21
- const hasJsxRuntime = (() => {
22
- if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
23
- return false;
24
- }
25
-
26
- try {
27
- require.resolve('react/jsx-runtime', { paths: [paths.appPath] });
28
- return true;
29
- } catch (e) {
30
- return false;
31
- }
32
- })();
33
-
34
- function writeJson(fileName, object) {
35
- fs.writeFileSync(
36
- fileName,
37
- JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL
38
- );
39
- }
40
-
41
- function verifyNoTypeScript() {
42
- const typescriptFiles = globby(
43
- ['**/*.(ts|tsx)', '!**/node_modules', '!**/*.d.ts'],
44
- { cwd: paths.appSrc }
45
- );
46
- if (typescriptFiles.length > 0) {
47
- console.warn(
48
- chalk.yellow(
49
- `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
- )
53
- );
54
- console.warn();
55
- return false;
56
- }
57
- return true;
58
- }
59
-
60
- function verifyTypeScriptSetup() {
61
- let firstTimeSetup = false;
62
-
63
- if (!fs.existsSync(paths.appTsConfig)) {
64
- if (verifyNoTypeScript()) {
65
- return;
66
- }
67
- writeJson(paths.appTsConfig, {});
68
- firstTimeSetup = true;
69
- }
70
-
71
- const isYarn = fs.existsSync(paths.yarnLockFile);
72
-
73
- // Ensure typescript is installed
74
- let ts;
75
- try {
76
- // TODO: Remove this hack once `globalThis` issue is resolved
77
- // https://github.com/jsdom/jsdom/issues/2961
78
- const globalThisWasDefined = !!global.globalThis;
79
-
80
- ts = require(resolve.sync('typescript', {
81
- basedir: paths.appNodeModules,
82
- }));
83
-
84
- if (!globalThisWasDefined && !!global.globalThis) {
85
- delete global.globalThis;
86
- }
87
- } 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
- );
95
- console.error(
96
- chalk.bold(
97
- 'Please install',
98
- chalk.cyan.bold('typescript'),
99
- 'by running',
100
- chalk.cyan.bold(
101
- isYarn ? 'yarn add typescript' : 'npm install typescript'
102
- ) + '.'
103
- )
104
- );
105
- console.error(
106
- 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
- )
111
- );
112
- console.error();
113
- process.exit(1);
114
- }
115
-
116
- const compilerOptions = {
117
- // These are suggested values and will be set when not present in the
118
- // tsconfig.json
119
- // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent()
120
- target: {
121
- parsedValue: ts.ScriptTarget.ES5,
122
- suggested: 'es5',
123
- },
124
- lib: { suggested: ['dom', 'dom.iterable', 'esnext'] },
125
- allowJs: { suggested: true },
126
- skipLibCheck: { suggested: true },
127
- esModuleInterop: { suggested: true },
128
- allowSyntheticDefaultImports: { suggested: true },
129
- strict: { suggested: true },
130
- forceConsistentCasingInFileNames: { suggested: true },
131
- noFallthroughCasesInSwitch: { suggested: true },
132
-
133
- // These values are required and cannot be changed by the user
134
- // Keep this in sync with the webpack config
135
- module: {
136
- parsedValue: ts.ModuleKind.ESNext,
137
- value: 'esnext',
138
- reason: 'for import() and import/export',
139
- },
140
- moduleResolution: {
141
- parsedValue: ts.ModuleResolutionKind.NodeJs,
142
- value: 'node',
143
- reason: 'to match webpack resolution',
144
- },
145
- resolveJsonModule: { value: true, reason: 'to match webpack loader' },
146
- isolatedModules: { value: true, reason: 'implementation limitation' },
147
- noEmit: { value: true },
148
- 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',
157
- reason: 'to support the new JSX transform in React 17',
158
- },
159
- paths: { value: undefined, reason: 'aliased imports are not supported' },
160
- };
161
-
162
- const formatDiagnosticHost = {
163
- getCanonicalFileName: fileName => fileName,
164
- getCurrentDirectory: ts.sys.getCurrentDirectory,
165
- getNewLine: () => os.EOL,
166
- };
167
-
168
- const messages = [];
169
- let appTsConfig;
170
- let parsedTsConfig;
171
- let parsedCompilerOptions;
172
- try {
173
- const { config: readTsConfig, error } = ts.readConfigFile(
174
- paths.appTsConfig,
175
- ts.sys.readFile
176
- );
177
-
178
- if (error) {
179
- throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
180
- }
181
-
182
- appTsConfig = readTsConfig;
183
-
184
- // Get TS to parse and resolve any "extends"
185
- // Calling this function also mutates the tsconfig above,
186
- // adding in "include" and "exclude", but the compilerOptions remain untouched
187
- let result;
188
- parsedTsConfig = immer(readTsConfig, config => {
189
- result = ts.parseJsonConfigFileContent(
190
- config,
191
- ts.sys,
192
- path.dirname(paths.appTsConfig)
193
- );
194
- });
195
-
196
- if (result.errors && result.errors.length) {
197
- throw new Error(
198
- ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
199
- );
200
- }
201
-
202
- parsedCompilerOptions = result.options;
203
- } catch (e) {
204
- if (e && e.name === 'SyntaxError') {
205
- 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
- )
211
- );
212
- }
213
-
214
- console.log(e && e.message ? `${e.message}` : '');
215
- process.exit(1);
216
- }
217
-
218
- if (appTsConfig.compilerOptions == null) {
219
- appTsConfig.compilerOptions = {};
220
- firstTimeSetup = true;
221
- }
222
-
223
- for (const option of Object.keys(compilerOptions)) {
224
- const { parsedValue, value, suggested, reason } = compilerOptions[option];
225
-
226
- const valueToCheck = parsedValue === undefined ? value : parsedValue;
227
- const coloredOption = chalk.cyan('compilerOptions.' + option);
228
-
229
- if (suggested != null) {
230
- if (parsedCompilerOptions[option] === undefined) {
231
- appTsConfig = immer(appTsConfig, config => {
232
- config.compilerOptions[option] = suggested;
233
- });
234
- messages.push(
235
- `${coloredOption} to be ${chalk.bold(
236
- 'suggested'
237
- )} value: ${chalk.cyan.bold(suggested)} (this can be changed)`
238
- );
239
- }
240
- } else if (parsedCompilerOptions[option] !== valueToCheck) {
241
- appTsConfig = immer(appTsConfig, config => {
242
- config.compilerOptions[option] = value;
243
- });
244
- messages.push(
245
- `${coloredOption} ${chalk.bold(
246
- valueToCheck == null ? 'must not' : 'must'
247
- )} be ${valueToCheck == null ? 'set' : chalk.cyan.bold(value)}` +
248
- (reason != null ? ` (${reason})` : '')
249
- );
250
- }
251
- }
252
-
253
- // tsconfig will have the merged "include" and "exclude" by this point
254
- if (parsedTsConfig.include == null) {
255
- appTsConfig = immer(appTsConfig, config => {
256
- config.include = ['src'];
257
- });
258
- messages.push(
259
- `${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`
260
- );
261
- }
262
-
263
- const types = appTsConfig.compilerOptions.types || (appTsConfig.compilerOptions.types = []);
264
-
265
- if (!types.includes('@reactunity/scripts/main')) {
266
- types.push('@reactunity/scripts/main');
267
- messages.push(
268
- `${chalk.cyan('types')} should include ${chalk.cyan.bold('@reactunity/scripts/main')}`
269
- );
270
- }
271
-
272
- if (!types.includes('@reactunity/scripts/ugui') && !types.includes('@reactunity/scripts/uitoolkit')
273
- && !types.includes('@reactunity/scripts/editor') && !types.includes('@reactunity/scripts/tests')) {
274
- types.push('@reactunity/scripts/ugui');
275
- messages.push(
276
- `${chalk.cyan('types')} should include a valid platform target. Assuming ${chalk.cyan.bold('@reactunity/scripts/ugui')}`
277
- );
278
- }
279
-
280
- // Deprecate `react-unity-scripts` types
281
- if (fs.existsSync(paths.appTypeDeclarations)) {
282
- 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.`
284
- );
285
- }
286
-
287
- if (messages.length > 0) {
288
- if (firstTimeSetup) {
289
- console.log(
290
- chalk.bold(
291
- 'Your',
292
- chalk.cyan('tsconfig.json'),
293
- 'has been populated with default values.'
294
- )
295
- );
296
- console.log();
297
- } 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);
307
- });
308
- console.warn();
309
- }
310
- writeJson(paths.appTsConfig, appTsConfig);
311
- }
312
- }
313
-
314
- module.exports = verifyTypeScriptSetup;
9
+ 'use strict';
10
+
11
+ const chalk = require('react-dev-utils/chalk');
12
+ const fs = require('fs');
13
+ const resolve = require('resolve');
14
+ const path = require('path');
15
+ const paths = require('../../config/paths');
16
+ const os = require('os');
17
+ const semver = require('semver');
18
+ const immer = require('react-dev-utils/immer').produce;
19
+ const globby = require('react-dev-utils/globby').sync;
20
+
21
+ const hasJsxRuntime = (() => {
22
+ if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
23
+ return false;
24
+ }
25
+
26
+ try {
27
+ require.resolve('react/jsx-runtime', { paths: [paths.appPath] });
28
+ return true;
29
+ } catch (e) {
30
+ return false;
31
+ }
32
+ })();
33
+
34
+ function writeJson(fileName, object) {
35
+ fs.writeFileSync(
36
+ fileName,
37
+ JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL
38
+ );
39
+ }
40
+
41
+ function verifyNoTypeScript() {
42
+ const typescriptFiles = globby(
43
+ ['**/*.(ts|tsx)', '!**/node_modules', '!**/*.d.ts'],
44
+ { cwd: paths.appSrc }
45
+ );
46
+ if (typescriptFiles.length > 0) {
47
+ console.warn(
48
+ chalk.yellow(
49
+ `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
+ )
53
+ );
54
+ console.warn();
55
+ return false;
56
+ }
57
+ return true;
58
+ }
59
+
60
+ function verifyTypeScriptSetup() {
61
+ let firstTimeSetup = false;
62
+
63
+ if (!fs.existsSync(paths.appTsConfig)) {
64
+ if (verifyNoTypeScript()) {
65
+ return;
66
+ }
67
+ writeJson(paths.appTsConfig, {});
68
+ firstTimeSetup = true;
69
+ }
70
+
71
+ const isYarn = fs.existsSync(paths.yarnLockFile);
72
+
73
+ // Ensure typescript is installed
74
+ let ts;
75
+ try {
76
+ // TODO: Remove this hack once `globalThis` issue is resolved
77
+ // https://github.com/jsdom/jsdom/issues/2961
78
+ const globalThisWasDefined = !!global.globalThis;
79
+
80
+ ts = require(resolve.sync('typescript', {
81
+ basedir: paths.appNodeModules,
82
+ }));
83
+
84
+ if (!globalThisWasDefined && !!global.globalThis) {
85
+ delete global.globalThis;
86
+ }
87
+ } 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
+ );
95
+ console.error(
96
+ chalk.bold(
97
+ 'Please install',
98
+ chalk.cyan.bold('typescript'),
99
+ 'by running',
100
+ chalk.cyan.bold(
101
+ isYarn ? 'yarn add typescript' : 'npm install typescript'
102
+ ) + '.'
103
+ )
104
+ );
105
+ console.error(
106
+ 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
+ )
111
+ );
112
+ console.error();
113
+ process.exit(1);
114
+ }
115
+
116
+ const compilerOptions = {
117
+ // These are suggested values and will be set when not present in the
118
+ // tsconfig.json
119
+ // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent()
120
+ target: {
121
+ parsedValue: ts.ScriptTarget.ES5,
122
+ suggested: 'es5',
123
+ },
124
+ lib: { suggested: ['dom', 'dom.iterable', 'esnext'] },
125
+ allowJs: { suggested: true },
126
+ skipLibCheck: { suggested: true },
127
+ esModuleInterop: { suggested: true },
128
+ allowSyntheticDefaultImports: { suggested: true },
129
+ strict: { suggested: true },
130
+ forceConsistentCasingInFileNames: { suggested: true },
131
+ noFallthroughCasesInSwitch: { suggested: true },
132
+
133
+ // These values are required and cannot be changed by the user
134
+ // Keep this in sync with the webpack config
135
+ module: {
136
+ parsedValue: ts.ModuleKind.ESNext,
137
+ value: 'esnext',
138
+ reason: 'for import() and import/export',
139
+ },
140
+ moduleResolution: {
141
+ parsedValue: ts.ModuleResolutionKind.NodeJs,
142
+ value: 'node',
143
+ reason: 'to match webpack resolution',
144
+ },
145
+ resolveJsonModule: { value: true, reason: 'to match webpack loader' },
146
+ isolatedModules: { value: true, reason: 'implementation limitation' },
147
+ noEmit: { value: true },
148
+ 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',
157
+ reason: 'to support the new JSX transform in React 17',
158
+ },
159
+ paths: { value: undefined, reason: 'aliased imports are not supported' },
160
+ };
161
+
162
+ const formatDiagnosticHost = {
163
+ getCanonicalFileName: fileName => fileName,
164
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
165
+ getNewLine: () => os.EOL,
166
+ };
167
+
168
+ const messages = [];
169
+ let appTsConfig;
170
+ let parsedTsConfig;
171
+ let parsedCompilerOptions;
172
+ try {
173
+ const { config: readTsConfig, error } = ts.readConfigFile(
174
+ paths.appTsConfig,
175
+ ts.sys.readFile
176
+ );
177
+
178
+ if (error) {
179
+ throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
180
+ }
181
+
182
+ appTsConfig = readTsConfig;
183
+
184
+ // Get TS to parse and resolve any "extends"
185
+ // Calling this function also mutates the tsconfig above,
186
+ // adding in "include" and "exclude", but the compilerOptions remain untouched
187
+ let result;
188
+ parsedTsConfig = immer(readTsConfig, config => {
189
+ result = ts.parseJsonConfigFileContent(
190
+ config,
191
+ ts.sys,
192
+ path.dirname(paths.appTsConfig)
193
+ );
194
+ });
195
+
196
+ if (result.errors && result.errors.length) {
197
+ throw new Error(
198
+ ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
199
+ );
200
+ }
201
+
202
+ parsedCompilerOptions = result.options;
203
+ } catch (e) {
204
+ if (e && e.name === 'SyntaxError') {
205
+ 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
+ )
211
+ );
212
+ }
213
+
214
+ console.log(e && e.message ? `${e.message}` : '');
215
+ process.exit(1);
216
+ }
217
+
218
+ if (appTsConfig.compilerOptions == null) {
219
+ appTsConfig.compilerOptions = {};
220
+ firstTimeSetup = true;
221
+ }
222
+
223
+ for (const option of Object.keys(compilerOptions)) {
224
+ const { parsedValue, value, suggested, reason } = compilerOptions[option];
225
+
226
+ const valueToCheck = parsedValue === undefined ? value : parsedValue;
227
+ const coloredOption = chalk.cyan('compilerOptions.' + option);
228
+
229
+ if (suggested != null) {
230
+ if (parsedCompilerOptions[option] === undefined) {
231
+ appTsConfig = immer(appTsConfig, config => {
232
+ config.compilerOptions[option] = suggested;
233
+ });
234
+ messages.push(
235
+ `${coloredOption} to be ${chalk.bold(
236
+ 'suggested'
237
+ )} value: ${chalk.cyan.bold(suggested)} (this can be changed)`
238
+ );
239
+ }
240
+ } else if (parsedCompilerOptions[option] !== valueToCheck) {
241
+ appTsConfig = immer(appTsConfig, config => {
242
+ config.compilerOptions[option] = value;
243
+ });
244
+ messages.push(
245
+ `${coloredOption} ${chalk.bold(
246
+ valueToCheck == null ? 'must not' : 'must'
247
+ )} be ${valueToCheck == null ? 'set' : chalk.cyan.bold(value)}` +
248
+ (reason != null ? ` (${reason})` : '')
249
+ );
250
+ }
251
+ }
252
+
253
+ // tsconfig will have the merged "include" and "exclude" by this point
254
+ if (parsedTsConfig.include == null) {
255
+ appTsConfig = immer(appTsConfig, config => {
256
+ config.include = ['src'];
257
+ });
258
+ messages.push(
259
+ `${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`
260
+ );
261
+ }
262
+
263
+ const types = appTsConfig.compilerOptions.types || (appTsConfig.compilerOptions.types = []);
264
+ const importSource = appTsConfig.compilerOptions.jsxImportSource;
265
+
266
+ if (!types.includes('@reactunity/scripts/main')) {
267
+ types.push('@reactunity/scripts/main');
268
+ messages.push(
269
+ `${chalk.cyan('types')} should include ${chalk.cyan.bold('@reactunity/scripts/main')}`
270
+ );
271
+ }
272
+
273
+ if (!['@reactunity/scripts/ugui', '@reactunity/scripts/uitoolkit', '@reactunity/scripts/editor', '@reactunity/scripts/tests'].includes(importSource)) {
274
+ appTsConfig.compilerOptions.jsxImportSource = '@reactunity/scripts/ugui';
275
+ messages.push(
276
+ `${chalk.cyan('jsxImportSource')} should include a valid platform target. Assuming ${chalk.cyan.bold('@reactunity/scripts/ugui')}`
277
+ );
278
+ }
279
+
280
+ // Deprecate `react-unity-scripts` types
281
+ if (fs.existsSync(paths.appTypeDeclarations)) {
282
+ 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.`
284
+ );
285
+ }
286
+
287
+ if (messages.length > 0) {
288
+ if (firstTimeSetup) {
289
+ console.log(
290
+ chalk.bold(
291
+ 'Your',
292
+ chalk.cyan('tsconfig.json'),
293
+ 'has been populated with default values.'
294
+ )
295
+ );
296
+ console.log();
297
+ } 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);
307
+ });
308
+ console.warn();
309
+ }
310
+ writeJson(paths.appTsConfig, appTsConfig);
311
+ }
312
+ }
313
+
314
+ module.exports = verifyTypeScriptSetup;
package/tsconfig.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "pretty": true,
7
7
  "declaration": false,
8
8
  "module": "esnext",
9
- "moduleResolution": "node",
9
+ "moduleResolution": "nodenext",
10
10
  "preserveSymlinks": true,
11
11
  "importHelpers": false,
12
12
  "strict": true,