@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.
- package/bin/react-unity-scripts.js +11 -31
- package/config/babel-preset-extended.js +3 -3
- package/config/env.js +10 -20
- package/config/getHttpsConfig.js +7 -23
- package/config/jest/babelTransform.js +1 -9
- package/config/jest/cssTransform.js +1 -9
- package/config/jest/fileTransform.js +2 -2
- package/config/modules.js +11 -17
- package/config/paths.js +10 -37
- package/config/unityMiddleware.js +2 -2
- package/config/webpack/persistentCache/createEnvironmentHash.js +3 -3
- package/config/webpack.config.js +132 -211
- package/config/webpackDevServer.config.js +7 -16
- package/lib/types/base.d.ts +1 -3
- package/package.json +32 -42
- package/scripts/build.js +19 -63
- package/scripts/clean.js +2 -3
- package/scripts/eject.js +40 -109
- package/scripts/init.js +33 -102
- package/scripts/start.js +18 -43
- package/scripts/test.js +9 -29
- package/scripts/utils/cleanBuildDirectory.js +14 -15
- package/scripts/utils/createJestConfig.js +16 -61
- package/scripts/utils/verifyTypeScriptSetup.js +49 -100
- package/tsconfig.json +1 -3
- package/config/eslint/base.js +0 -43
- package/config/eslint/config.js +0 -252
- package/config/eslint/jest.js +0 -59
- package/config/eslintConfig.js +0 -31
- package/scripts/lint.js +0 -46
package/scripts/init.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
// @remove-file-on-eject
|
|
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
|
-
'use strict';
|
|
9
|
-
|
|
10
1
|
// Makes the script crash on unhandled rejections instead of silently
|
|
11
2
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
12
3
|
// terminate the Node.js process with a non-zero exit code.
|
|
13
|
-
process.on('unhandledRejection', err => {
|
|
4
|
+
process.on('unhandledRejection', (err) => {
|
|
14
5
|
throw err;
|
|
15
6
|
});
|
|
16
7
|
|
|
17
8
|
const fs = require('fs-extra');
|
|
18
|
-
const path = require('path');
|
|
9
|
+
const path = require('node:path');
|
|
19
10
|
const chalk = require('react-dev-utils/chalk');
|
|
20
|
-
const execSync = require('child_process').execSync;
|
|
11
|
+
const execSync = require('node:child_process').execSync;
|
|
21
12
|
const spawn = require('react-dev-utils/crossSpawn');
|
|
22
13
|
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
|
|
23
|
-
const os = require('os');
|
|
14
|
+
const os = require('node:os');
|
|
24
15
|
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
|
|
25
16
|
|
|
26
17
|
function isInGitRepository() {
|
|
@@ -81,41 +72,25 @@ function tryGitCommit(appPath) {
|
|
|
81
72
|
}
|
|
82
73
|
}
|
|
83
74
|
|
|
84
|
-
module.exports =
|
|
85
|
-
appPath,
|
|
86
|
-
appName,
|
|
87
|
-
verbose,
|
|
88
|
-
originalDirectory,
|
|
89
|
-
templateName
|
|
90
|
-
) {
|
|
75
|
+
module.exports = (appPath, appName, verbose, originalDirectory, templateName) => {
|
|
91
76
|
const appPackage = require(path.join(appPath, 'package.json'));
|
|
92
77
|
const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock'));
|
|
93
78
|
|
|
94
79
|
if (!templateName) {
|
|
95
80
|
console.log('');
|
|
96
81
|
console.error(
|
|
97
|
-
`A template was not provided. This is likely because you're using an outdated version of ${chalk.cyan(
|
|
98
|
-
'create-react-unity'
|
|
99
|
-
)}.`
|
|
100
|
-
);
|
|
101
|
-
console.error(
|
|
102
|
-
`Please note that global installs of ${chalk.cyan(
|
|
103
|
-
'create-react-unity'
|
|
104
|
-
)} are no longer supported.`
|
|
82
|
+
`A template was not provided. This is likely because you're using an outdated version of ${chalk.cyan('create-react-unity')}.`,
|
|
105
83
|
);
|
|
84
|
+
console.error(`Please note that global installs of ${chalk.cyan('create-react-unity')} are no longer supported.`);
|
|
106
85
|
console.error(
|
|
107
|
-
`You can fix this by running ${chalk.cyan(
|
|
108
|
-
'
|
|
109
|
-
)}
|
|
110
|
-
'yarn global remove create-react-unity'
|
|
111
|
-
)} before using ${chalk.cyan('create-react-unity')} again.`
|
|
86
|
+
`You can fix this by running ${chalk.cyan('npm uninstall -g create-react-unity')} or ${chalk.cyan(
|
|
87
|
+
'yarn global remove create-react-unity',
|
|
88
|
+
)} before using ${chalk.cyan('create-react-unity')} again.`,
|
|
112
89
|
);
|
|
113
90
|
return;
|
|
114
91
|
}
|
|
115
92
|
|
|
116
|
-
const templatePath = path.dirname(
|
|
117
|
-
require.resolve(`${templateName}/package.json`, { paths: [appPath] })
|
|
118
|
-
);
|
|
93
|
+
const templatePath = path.dirname(require.resolve(`${templateName}/package.json`, { paths: [appPath] }));
|
|
119
94
|
|
|
120
95
|
const templateJsonPath = path.join(templatePath, 'template.json');
|
|
121
96
|
|
|
@@ -132,8 +107,8 @@ module.exports = function (
|
|
|
132
107
|
console.log(
|
|
133
108
|
chalk.red(
|
|
134
109
|
'Root-level `dependencies` and `scripts` keys in `template.json` were deprecated for Create React App 5.\n' +
|
|
135
|
-
|
|
136
|
-
)
|
|
110
|
+
'This template needs to be updated to use the new `package` key.',
|
|
111
|
+
),
|
|
137
112
|
);
|
|
138
113
|
console.log('For more information, visit https://cra.link/templates');
|
|
139
114
|
}
|
|
@@ -170,11 +145,8 @@ module.exports = function (
|
|
|
170
145
|
|
|
171
146
|
// Keys from templatePackage that will be added to appPackage,
|
|
172
147
|
// replacing any existing entries.
|
|
173
|
-
const templatePackageToReplace = Object.keys(templatePackage).filter(key => {
|
|
174
|
-
return (
|
|
175
|
-
!templatePackageBlacklist.includes(key) &&
|
|
176
|
-
!templatePackageToMerge.includes(key)
|
|
177
|
-
);
|
|
148
|
+
const templatePackageToReplace = Object.keys(templatePackage).filter((key) => {
|
|
149
|
+
return !templatePackageBlacklist.includes(key) && !templatePackageToMerge.includes(key);
|
|
178
150
|
});
|
|
179
151
|
|
|
180
152
|
// Copy over some of the devDependencies
|
|
@@ -188,46 +160,30 @@ module.exports = function (
|
|
|
188
160
|
build: 'react-unity-scripts build',
|
|
189
161
|
test: 'react-unity-scripts test',
|
|
190
162
|
eject: 'react-unity-scripts eject',
|
|
191
|
-
lint: 'react-unity-scripts lint',
|
|
192
163
|
},
|
|
193
|
-
templateScripts
|
|
164
|
+
templateScripts,
|
|
194
165
|
);
|
|
195
166
|
|
|
196
167
|
// Update scripts for Yarn users
|
|
197
168
|
if (useYarn) {
|
|
198
|
-
appPackage.scripts = Object.
|
|
199
|
-
(acc, [key, value]) => (
|
|
200
|
-
...acc,
|
|
201
|
-
[key]: value.replace(/(npm run |npm )/, 'yarn '),
|
|
202
|
-
}),
|
|
203
|
-
{}
|
|
169
|
+
appPackage.scripts = Object.fromEntries(
|
|
170
|
+
Object.entries(appPackage.scripts).map((acc, [key, value]) => [key, value.replace(/(npm run |npm )/, 'yarn ')]),
|
|
204
171
|
);
|
|
205
172
|
}
|
|
206
173
|
|
|
207
|
-
// Setup the eslint config
|
|
208
|
-
appPackage.eslintConfig = {
|
|
209
|
-
extends: 'react-app',
|
|
210
|
-
};
|
|
211
|
-
|
|
212
174
|
// Setup the browsers list
|
|
213
175
|
appPackage.browserslist = defaultBrowsers;
|
|
214
176
|
|
|
215
177
|
// Add templatePackage keys/values to appPackage, replacing existing entries
|
|
216
|
-
templatePackageToReplace.forEach(key => {
|
|
178
|
+
templatePackageToReplace.forEach((key) => {
|
|
217
179
|
appPackage[key] = templatePackage[key];
|
|
218
180
|
});
|
|
219
181
|
|
|
220
|
-
fs.writeFileSync(
|
|
221
|
-
path.join(appPath, 'package.json'),
|
|
222
|
-
JSON.stringify(appPackage, null, 2) + os.EOL
|
|
223
|
-
);
|
|
182
|
+
fs.writeFileSync(path.join(appPath, 'package.json'), JSON.stringify(appPackage, null, 2) + os.EOL);
|
|
224
183
|
|
|
225
184
|
const readmeExists = fs.existsSync(path.join(appPath, 'README.md'));
|
|
226
185
|
if (readmeExists) {
|
|
227
|
-
fs.renameSync(
|
|
228
|
-
path.join(appPath, 'README.md'),
|
|
229
|
-
path.join(appPath, 'README.old.md')
|
|
230
|
-
);
|
|
186
|
+
fs.renameSync(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md'));
|
|
231
187
|
}
|
|
232
188
|
|
|
233
189
|
// Copy the files for the user
|
|
@@ -235,9 +191,7 @@ module.exports = function (
|
|
|
235
191
|
if (fs.existsSync(templateDir)) {
|
|
236
192
|
fs.copySync(templateDir, appPath);
|
|
237
193
|
} else {
|
|
238
|
-
console.error(
|
|
239
|
-
`Could not locate supplied template: ${chalk.green(templateDir)}`
|
|
240
|
-
);
|
|
194
|
+
console.error(`Could not locate supplied template: ${chalk.green(templateDir)}`);
|
|
241
195
|
return;
|
|
242
196
|
}
|
|
243
197
|
|
|
@@ -245,11 +199,7 @@ module.exports = function (
|
|
|
245
199
|
if (useYarn) {
|
|
246
200
|
try {
|
|
247
201
|
const readme = fs.readFileSync(path.join(appPath, 'README.md'), 'utf8');
|
|
248
|
-
fs.writeFileSync(
|
|
249
|
-
path.join(appPath, 'README.md'),
|
|
250
|
-
readme.replace(/(npm run |npm )/g, 'yarn '),
|
|
251
|
-
'utf8'
|
|
252
|
-
);
|
|
202
|
+
fs.writeFileSync(path.join(appPath, 'README.md'), readme.replace(/(npm run |npm )/g, 'yarn '), 'utf8');
|
|
253
203
|
} catch (err) {
|
|
254
204
|
// Silencing the error. As it fall backs to using default npm commands.
|
|
255
205
|
}
|
|
@@ -264,11 +214,7 @@ module.exports = function (
|
|
|
264
214
|
} else {
|
|
265
215
|
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
|
|
266
216
|
// See: https://github.com/npm/npm/issues/1862
|
|
267
|
-
fs.moveSync(
|
|
268
|
-
path.join(appPath, 'gitignore'),
|
|
269
|
-
path.join(appPath, '.gitignore'),
|
|
270
|
-
[]
|
|
271
|
-
);
|
|
217
|
+
fs.moveSync(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), []);
|
|
272
218
|
}
|
|
273
219
|
|
|
274
220
|
// Initialize git repo
|
|
@@ -296,7 +242,7 @@ module.exports = function (
|
|
|
296
242
|
'--no-audit', // https://github.com/facebook/create-react-app/issues/11174
|
|
297
243
|
'--save',
|
|
298
244
|
verbose && '--verbose',
|
|
299
|
-
].filter(e => e);
|
|
245
|
+
].filter((e) => e);
|
|
300
246
|
}
|
|
301
247
|
|
|
302
248
|
// Install additional template dependencies, if present.
|
|
@@ -308,7 +254,7 @@ module.exports = function (
|
|
|
308
254
|
args = args.concat(
|
|
309
255
|
dependenciesToInstall.map(([dependency, version]) => {
|
|
310
256
|
return `${dependency}@${version}`;
|
|
311
|
-
})
|
|
257
|
+
}),
|
|
312
258
|
);
|
|
313
259
|
}
|
|
314
260
|
|
|
@@ -330,7 +276,7 @@ module.exports = function (
|
|
|
330
276
|
}
|
|
331
277
|
}
|
|
332
278
|
|
|
333
|
-
if (args.find(arg => arg.includes('typescript'))) {
|
|
279
|
+
if (args.find((arg) => arg.includes('typescript'))) {
|
|
334
280
|
console.log();
|
|
335
281
|
verifyTypeScriptSetup();
|
|
336
282
|
}
|
|
@@ -373,23 +319,15 @@ module.exports = function (
|
|
|
373
319
|
console.log(chalk.cyan(` ${displayedCommand} start`));
|
|
374
320
|
console.log(' Starts the development server.');
|
|
375
321
|
console.log();
|
|
376
|
-
console.log(
|
|
377
|
-
chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}build`)
|
|
378
|
-
);
|
|
322
|
+
console.log(chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}build`));
|
|
379
323
|
console.log(' Bundles the app into static files for production.');
|
|
380
324
|
console.log();
|
|
381
325
|
console.log(chalk.cyan(` ${displayedCommand} test`));
|
|
382
326
|
console.log(' Starts the test runner.');
|
|
383
327
|
console.log();
|
|
384
|
-
console.log(
|
|
385
|
-
|
|
386
|
-
);
|
|
387
|
-
console.log(
|
|
388
|
-
' Removes this tool and copies build dependencies, configuration files'
|
|
389
|
-
);
|
|
390
|
-
console.log(
|
|
391
|
-
' and scripts into the app directory. If you do this, you can’t go back!'
|
|
392
|
-
);
|
|
328
|
+
console.log(chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}eject`));
|
|
329
|
+
console.log(' Removes this tool and copies build dependencies, configuration files');
|
|
330
|
+
console.log(' and scripts into the app directory. If you do this, you can’t go back!');
|
|
393
331
|
console.log();
|
|
394
332
|
console.log('We suggest that you begin by typing:');
|
|
395
333
|
console.log();
|
|
@@ -397,11 +335,7 @@ module.exports = function (
|
|
|
397
335
|
console.log(` ${chalk.cyan(`${displayedCommand} start`)}`);
|
|
398
336
|
if (readmeExists) {
|
|
399
337
|
console.log();
|
|
400
|
-
console.log(
|
|
401
|
-
chalk.yellow(
|
|
402
|
-
'You had a `README.md` file, we renamed it to `README.old.md`'
|
|
403
|
-
)
|
|
404
|
-
);
|
|
338
|
+
console.log(chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`'));
|
|
405
339
|
}
|
|
406
340
|
console.log();
|
|
407
341
|
console.log('Happy hacking!');
|
|
@@ -410,8 +344,5 @@ module.exports = function (
|
|
|
410
344
|
function isReactInstalled(appPackage) {
|
|
411
345
|
const dependencies = appPackage.dependencies || {};
|
|
412
346
|
|
|
413
|
-
return
|
|
414
|
-
typeof dependencies.react !== 'undefined' &&
|
|
415
|
-
typeof dependencies['@reactunity/renderer'] !== 'undefined'
|
|
416
|
-
);
|
|
347
|
+
return typeof dependencies.react !== 'undefined' && typeof dependencies['@reactunity/renderer'] !== 'undefined';
|
|
417
348
|
}
|
package/scripts/start.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
// @remove-on-eject-end
|
|
9
|
-
'use strict';
|
|
10
9
|
|
|
11
10
|
// Do this as the first thing so that any code reading it knows the right env.
|
|
12
11
|
process.env.BABEL_ENV = 'development';
|
|
@@ -15,7 +14,7 @@ process.env.NODE_ENV = 'development';
|
|
|
15
14
|
// Makes the script crash on unhandled rejections instead of silently
|
|
16
15
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
17
16
|
// terminate the Node.js process with a non-zero exit code.
|
|
18
|
-
process.on('unhandledRejection', err => {
|
|
17
|
+
process.on('unhandledRejection', (err) => {
|
|
19
18
|
throw err;
|
|
20
19
|
});
|
|
21
20
|
|
|
@@ -26,22 +25,17 @@ require('../config/env');
|
|
|
26
25
|
const allowClearingConsole = !process.env.SKIP_CLEAR_CONSOLE;
|
|
27
26
|
if (!allowClearingConsole) {
|
|
28
27
|
require('react-dev-utils/clearConsole');
|
|
29
|
-
const clearConsole = () => {
|
|
28
|
+
const clearConsole = () => {};
|
|
30
29
|
require.cache[require.resolve('react-dev-utils/clearConsole')].exports = clearConsole;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
const fs = require('fs');
|
|
32
|
+
const fs = require('node:fs');
|
|
34
33
|
const chalk = require('react-dev-utils/chalk');
|
|
35
34
|
const webpack = require('webpack');
|
|
36
35
|
const WebpackDevServer = require('webpack-dev-server');
|
|
37
36
|
const clearConsole = require('react-dev-utils/clearConsole');
|
|
38
37
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
39
|
-
const {
|
|
40
|
-
choosePort,
|
|
41
|
-
createCompiler,
|
|
42
|
-
prepareProxy,
|
|
43
|
-
prepareUrls,
|
|
44
|
-
} = require('react-dev-utils/WebpackDevServerUtils');
|
|
38
|
+
const { choosePort, createCompiler, prepareProxy, prepareUrls } = require('react-dev-utils/WebpackDevServerUtils');
|
|
45
39
|
const semver = require('semver');
|
|
46
40
|
const paths = require('../config/paths');
|
|
47
41
|
const configFactory = require('../config/webpack.config');
|
|
@@ -58,23 +52,13 @@ if (!checkRequiredFiles([paths.appIndexJs])) {
|
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
// Tools like Cloud9 rely on this.
|
|
61
|
-
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
|
55
|
+
const DEFAULT_PORT = Number.parseInt(process.env.PORT, 10) || 3000;
|
|
62
56
|
const HOST = process.env.HOST || '0.0.0.0';
|
|
63
57
|
|
|
64
58
|
if (process.env.HOST) {
|
|
65
|
-
console.log(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
chalk.bold(process.env.HOST)
|
|
69
|
-
)}`
|
|
70
|
-
)
|
|
71
|
-
);
|
|
72
|
-
console.log(
|
|
73
|
-
`If this was unintentional, check that you haven't mistakenly set it in your shell.`
|
|
74
|
-
);
|
|
75
|
-
console.log(
|
|
76
|
-
`Learn more here: ${chalk.yellow('https://cra.link/advanced-config')}`
|
|
77
|
-
);
|
|
59
|
+
console.log(chalk.cyan(`Attempting to bind to HOST environment variable: ${chalk.yellow(chalk.bold(process.env.HOST))}`));
|
|
60
|
+
console.log(`If this was unintentional, check that you haven't mistakenly set it in your shell.`);
|
|
61
|
+
console.log(`Learn more here: ${chalk.yellow('https://cra.link/advanced-config')}`);
|
|
78
62
|
console.log();
|
|
79
63
|
}
|
|
80
64
|
|
|
@@ -87,7 +71,7 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
87
71
|
// run on a different port. `choosePort()` Promise resolves to the next free port.
|
|
88
72
|
return choosePort(HOST, DEFAULT_PORT);
|
|
89
73
|
})
|
|
90
|
-
.then(port => {
|
|
74
|
+
.then((port) => {
|
|
91
75
|
if (port == null) {
|
|
92
76
|
// We have not found a port.
|
|
93
77
|
return;
|
|
@@ -98,12 +82,7 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
98
82
|
const appName = require(paths.appPackageJson).name;
|
|
99
83
|
|
|
100
84
|
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
|
101
|
-
const urls = prepareUrls(
|
|
102
|
-
protocol,
|
|
103
|
-
HOST,
|
|
104
|
-
port,
|
|
105
|
-
paths.publicUrlOrPath.slice(0, -1)
|
|
106
|
-
);
|
|
85
|
+
const urls = prepareUrls(protocol, HOST, port, paths.publicUrlOrPath.slice(0, -1));
|
|
107
86
|
// Create a webpack compiler that is configured with custom messages.
|
|
108
87
|
const compiler = createCompiler({
|
|
109
88
|
appName,
|
|
@@ -115,11 +94,7 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
115
94
|
});
|
|
116
95
|
// Load proxy config
|
|
117
96
|
const proxySetting = require(paths.appPackageJson).proxy;
|
|
118
|
-
const proxyConfig = prepareProxy(
|
|
119
|
-
proxySetting,
|
|
120
|
-
paths.appPublic,
|
|
121
|
-
paths.publicUrlOrPath
|
|
122
|
-
);
|
|
97
|
+
const proxyConfig = prepareProxy(proxySetting, paths.appPublic, paths.publicUrlOrPath);
|
|
123
98
|
// Serve webpack assets generated by the compiler over a web server.
|
|
124
99
|
const serverConfig = {
|
|
125
100
|
...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
|
|
@@ -136,23 +111,23 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
136
111
|
console.log(chalk.cyan('Starting the development server...\n'));
|
|
137
112
|
});
|
|
138
113
|
|
|
139
|
-
['SIGINT', 'SIGTERM'].forEach(
|
|
140
|
-
process.on(sig,
|
|
141
|
-
devServer.close();
|
|
114
|
+
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
115
|
+
process.on(sig, () => {
|
|
116
|
+
devServer.close?.();
|
|
142
117
|
process.exit();
|
|
143
118
|
});
|
|
144
119
|
});
|
|
145
120
|
|
|
146
121
|
if (process.env.CI !== 'true') {
|
|
147
122
|
// Gracefully exit when stdin ends
|
|
148
|
-
process.stdin.on('end',
|
|
149
|
-
devServer.close();
|
|
123
|
+
process.stdin.on('end', () => {
|
|
124
|
+
devServer.close?.();
|
|
150
125
|
process.exit();
|
|
151
126
|
});
|
|
152
127
|
}
|
|
153
128
|
})
|
|
154
|
-
.catch(err => {
|
|
155
|
-
if (err
|
|
129
|
+
.catch((err) => {
|
|
130
|
+
if (err?.message) {
|
|
156
131
|
console.log(err.message);
|
|
157
132
|
}
|
|
158
133
|
process.exit(1);
|
package/scripts/test.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
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
|
-
|
|
11
1
|
// Do this as the first thing so that any code reading it knows the right env.
|
|
12
2
|
process.env.BABEL_ENV = 'test';
|
|
13
3
|
process.env.NODE_ENV = 'test';
|
|
@@ -16,7 +6,7 @@ process.env.PUBLIC_URL = '';
|
|
|
16
6
|
// Makes the script crash on unhandled rejections instead of silently
|
|
17
7
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
18
8
|
// terminate the Node.js process with a non-zero exit code.
|
|
19
|
-
process.on('unhandledRejection', err => {
|
|
9
|
+
process.on('unhandledRejection', (err) => {
|
|
20
10
|
throw err;
|
|
21
11
|
});
|
|
22
12
|
|
|
@@ -24,7 +14,7 @@ process.on('unhandledRejection', err => {
|
|
|
24
14
|
require('../config/env');
|
|
25
15
|
|
|
26
16
|
const jest = require('jest');
|
|
27
|
-
const execSync = require('child_process').execSync;
|
|
17
|
+
const execSync = require('node:child_process').execSync;
|
|
28
18
|
let argv = process.argv.slice(2);
|
|
29
19
|
|
|
30
20
|
function isInGitRepository() {
|
|
@@ -46,11 +36,7 @@ function isInMercurialRepository() {
|
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
// Watch unless on CI or explicitly running all tests
|
|
49
|
-
if (
|
|
50
|
-
!process.env.CI &&
|
|
51
|
-
argv.indexOf('--watchAll') === -1 &&
|
|
52
|
-
argv.indexOf('--watchAll=false') === -1
|
|
53
|
-
) {
|
|
39
|
+
if (!process.env.CI && argv.indexOf('--watchAll') === -1 && argv.indexOf('--watchAll=false') === -1) {
|
|
54
40
|
// https://github.com/facebook/create-react-app/issues/5210
|
|
55
41
|
const hasSourceControl = isInGitRepository() || isInMercurialRepository();
|
|
56
42
|
argv.push(hasSourceControl ? '--watch' : '--watchAll');
|
|
@@ -59,17 +45,11 @@ if (
|
|
|
59
45
|
// @remove-on-eject-begin
|
|
60
46
|
// This is not necessary after eject because we embed config into package.json.
|
|
61
47
|
const createJestConfig = require('./utils/createJestConfig');
|
|
62
|
-
const path = require('path');
|
|
48
|
+
const path = require('node:path');
|
|
63
49
|
const paths = require('../config/paths');
|
|
64
50
|
argv.push(
|
|
65
51
|
'--config',
|
|
66
|
-
JSON.stringify(
|
|
67
|
-
createJestConfig(
|
|
68
|
-
relativePath => path.resolve(__dirname, '..', relativePath),
|
|
69
|
-
path.resolve(paths.appSrc, '..'),
|
|
70
|
-
false
|
|
71
|
-
)
|
|
72
|
-
)
|
|
52
|
+
JSON.stringify(createJestConfig((relativePath) => path.resolve(__dirname, '..', relativePath), path.resolve(paths.appSrc, '..'), false)),
|
|
73
53
|
);
|
|
74
54
|
|
|
75
55
|
// This is a very dirty workaround for https://github.com/facebook/jest/issues/5913.
|
|
@@ -80,23 +60,23 @@ function resolveJestDefaultEnvironment(name) {
|
|
|
80
60
|
const jestDir = path.dirname(
|
|
81
61
|
resolve.sync('jest', {
|
|
82
62
|
basedir: __dirname,
|
|
83
|
-
})
|
|
63
|
+
}),
|
|
84
64
|
);
|
|
85
65
|
const jestCLIDir = path.dirname(
|
|
86
66
|
resolve.sync('jest-cli', {
|
|
87
67
|
basedir: jestDir,
|
|
88
|
-
})
|
|
68
|
+
}),
|
|
89
69
|
);
|
|
90
70
|
const jestConfigDir = path.dirname(
|
|
91
71
|
resolve.sync('jest-config', {
|
|
92
72
|
basedir: jestCLIDir,
|
|
93
|
-
})
|
|
73
|
+
}),
|
|
94
74
|
);
|
|
95
75
|
return resolve.sync(name, {
|
|
96
76
|
basedir: jestConfigDir,
|
|
97
77
|
});
|
|
98
78
|
}
|
|
99
|
-
|
|
79
|
+
const cleanArgv = [];
|
|
100
80
|
let env = 'jsdom';
|
|
101
81
|
let next;
|
|
102
82
|
do {
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
// @remove-on-eject-end
|
|
9
|
-
'use strict';
|
|
10
9
|
|
|
11
|
-
const path = require('path');
|
|
10
|
+
const path = require('node:path');
|
|
12
11
|
const fs = require('fs-extra');
|
|
13
12
|
const paths = require('../../config/paths');
|
|
14
13
|
|
|
@@ -26,7 +25,7 @@ function cleanBuildDirectory(cleanMetaFiles = false) {
|
|
|
26
25
|
for (const key of keys) {
|
|
27
26
|
const file = manifest.files[key];
|
|
28
27
|
const filePath = path.join(paths.appBuild, file);
|
|
29
|
-
const metaFile = filePath
|
|
28
|
+
const metaFile = `${filePath}.meta`;
|
|
30
29
|
|
|
31
30
|
fs.removeSync(filePath);
|
|
32
31
|
|
|
@@ -36,7 +35,7 @@ function cleanBuildDirectory(cleanMetaFiles = false) {
|
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
const manifestMeta = paths.appManifest
|
|
38
|
+
const manifestMeta = `${paths.appManifest}.meta`;
|
|
40
39
|
fs.removeSync(paths.appManifest);
|
|
41
40
|
|
|
42
41
|
if (fs.existsSync(manifestMeta)) {
|
|
@@ -49,7 +48,9 @@ function cleanBuildDirectory(cleanMetaFiles = false) {
|
|
|
49
48
|
return metaFiles;
|
|
50
49
|
}
|
|
51
50
|
} catch (err) {
|
|
52
|
-
console.log(
|
|
51
|
+
console.log(
|
|
52
|
+
'Skipped clearing output directory because asset manifest was not found. Please clean the output directory manually if necessary.',
|
|
53
|
+
);
|
|
53
54
|
return [];
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -65,23 +66,21 @@ function cleanUnusedMetaFiles(metaFiles) {
|
|
|
65
66
|
|
|
66
67
|
fs.removeSync(metaFile);
|
|
67
68
|
} catch (err) {
|
|
68
|
-
console.log(
|
|
69
|
+
console.log(`Error while cleaning meta file: ${metaFile}`);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
}
|
|
72
|
+
} catch (err) {}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
76
75
|
function cleanEmptyFoldersRecursively(parent, folder, skipFirst) {
|
|
77
76
|
if (!fs.existsSync(folder)) return;
|
|
78
|
-
|
|
77
|
+
const isDir = fs.statSync(folder).isDirectory();
|
|
79
78
|
if (!isDir) return;
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
let files = fs.readdirSync(folder);
|
|
82
81
|
if (files.length > 0) {
|
|
83
|
-
files.forEach(
|
|
84
|
-
|
|
82
|
+
files.forEach((file) => {
|
|
83
|
+
const fullPath = path.join(folder, file);
|
|
85
84
|
cleanEmptyFoldersRecursively(folder, fullPath, false);
|
|
86
85
|
});
|
|
87
86
|
|
|
@@ -90,12 +89,12 @@ function cleanEmptyFoldersRecursively(parent, folder, skipFirst) {
|
|
|
90
89
|
files = fs.readdirSync(folder);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
if (!skipFirst && files.length
|
|
92
|
+
if (!skipFirst && !files.length) {
|
|
94
93
|
fs.rmdirSync(folder);
|
|
95
94
|
|
|
96
95
|
if (parent) {
|
|
97
96
|
const folderName = path.basename(folder);
|
|
98
|
-
const dirMeta = path.join(parent, folderName
|
|
97
|
+
const dirMeta = path.join(parent, `${folderName}.meta`);
|
|
99
98
|
fs.removeSync(dirMeta);
|
|
100
99
|
}
|
|
101
100
|
return;
|