@evadata/react-scripts 5.0.2
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/LICENSE +22 -0
- package/README.md +9 -0
- package/bin/react-scripts.js +58 -0
- package/config/env.js +112 -0
- package/config/getHttpsConfig.js +74 -0
- package/config/jest/babelTransform.js +37 -0
- package/config/jest/cssTransform.js +22 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +142 -0
- package/config/paths.js +153 -0
- package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
- package/config/webpack.config.js +771 -0
- package/config/webpackDevServer.config.js +137 -0
- package/lib/react-app.d.ts +71 -0
- package/package.json +100 -0
- package/scripts/build.js +225 -0
- package/scripts/eject.js +340 -0
- package/scripts/init.js +416 -0
- package/scripts/start.js +162 -0
- package/scripts/test.js +129 -0
- package/scripts/utils/createJestConfig.js +152 -0
- package/scripts/utils/verifyTypeScriptSetup.js +298 -0
package/scripts/init.js
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
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
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
11
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
12
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
13
|
+
process.on('unhandledRejection', err => {
|
|
14
|
+
throw err;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const fs = require('fs-extra');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const chalk = require('react-dev-utils/chalk');
|
|
20
|
+
const execSync = require('child_process').execSync;
|
|
21
|
+
const spawn = require('react-dev-utils/crossSpawn');
|
|
22
|
+
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
|
|
23
|
+
const os = require('os');
|
|
24
|
+
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
|
|
25
|
+
|
|
26
|
+
function isInGitRepository() {
|
|
27
|
+
try {
|
|
28
|
+
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
|
|
29
|
+
return true;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isInMercurialRepository() {
|
|
36
|
+
try {
|
|
37
|
+
execSync('hg --cwd . root', { stdio: 'ignore' });
|
|
38
|
+
return true;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function tryGitInit() {
|
|
45
|
+
try {
|
|
46
|
+
execSync('git --version', { stdio: 'ignore' });
|
|
47
|
+
if (isInGitRepository() || isInMercurialRepository()) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
execSync('git init', { stdio: 'ignore' });
|
|
52
|
+
return true;
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.warn('Git repo not initialized', e);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function tryGitCommit(appPath) {
|
|
60
|
+
try {
|
|
61
|
+
execSync('git add -A', { stdio: 'ignore' });
|
|
62
|
+
execSync('git commit -m "Initialize project using Create React App"', {
|
|
63
|
+
stdio: 'ignore'
|
|
64
|
+
});
|
|
65
|
+
return true;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// We couldn't commit in already initialized git repo,
|
|
68
|
+
// maybe the commit author config is not set.
|
|
69
|
+
// In the future, we might supply our own committer
|
|
70
|
+
// like Ember CLI does, but for now, let's just
|
|
71
|
+
// remove the Git files to avoid a half-done state.
|
|
72
|
+
console.warn('Git commit not created', e);
|
|
73
|
+
console.warn('Removing .git directory...');
|
|
74
|
+
try {
|
|
75
|
+
// unlinkSync() doesn't work on directories.
|
|
76
|
+
fs.removeSync(path.join(appPath, '.git'));
|
|
77
|
+
} catch (removeErr) {
|
|
78
|
+
// Ignore.
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = function (
|
|
85
|
+
appPath,
|
|
86
|
+
appName,
|
|
87
|
+
verbose,
|
|
88
|
+
originalDirectory,
|
|
89
|
+
templateName
|
|
90
|
+
) {
|
|
91
|
+
const appPackage = require(path.join(appPath, 'package.json'));
|
|
92
|
+
const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock'));
|
|
93
|
+
|
|
94
|
+
if (!templateName) {
|
|
95
|
+
console.log('');
|
|
96
|
+
console.error(
|
|
97
|
+
`A template was not provided. This is likely because you're using an outdated version of ${chalk.cyan(
|
|
98
|
+
'create-react-app'
|
|
99
|
+
)}.`
|
|
100
|
+
);
|
|
101
|
+
console.error(
|
|
102
|
+
`Please note that global installs of ${chalk.cyan(
|
|
103
|
+
'create-react-app'
|
|
104
|
+
)} are no longer supported.`
|
|
105
|
+
);
|
|
106
|
+
console.error(
|
|
107
|
+
`You can fix this by running ${chalk.cyan(
|
|
108
|
+
'npm uninstall -g create-react-app'
|
|
109
|
+
)} or ${chalk.cyan(
|
|
110
|
+
'yarn global remove create-react-app'
|
|
111
|
+
)} before using ${chalk.cyan('create-react-app')} again.`
|
|
112
|
+
);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const templatePath = path.dirname(
|
|
117
|
+
require.resolve(`${templateName}/package.json`, { paths: [appPath] })
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const templateJsonPath = path.join(templatePath, 'template.json');
|
|
121
|
+
|
|
122
|
+
let templateJson = {};
|
|
123
|
+
if (fs.existsSync(templateJsonPath)) {
|
|
124
|
+
templateJson = require(templateJsonPath);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const templatePackage = templateJson.package || {};
|
|
128
|
+
|
|
129
|
+
// This was deprecated in CRA v5.
|
|
130
|
+
if (templateJson.dependencies || templateJson.scripts) {
|
|
131
|
+
console.log();
|
|
132
|
+
console.log(
|
|
133
|
+
chalk.red(
|
|
134
|
+
'Root-level `dependencies` and `scripts` keys in `template.json` were deprecated for Create React App 5.\n' +
|
|
135
|
+
'This template needs to be updated to use the new `package` key.'
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
console.log('For more information, visit https://cra.link/templates');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Keys to ignore in templatePackage
|
|
142
|
+
const templatePackageBlacklist = [
|
|
143
|
+
'name',
|
|
144
|
+
'version',
|
|
145
|
+
'description',
|
|
146
|
+
'keywords',
|
|
147
|
+
'bugs',
|
|
148
|
+
'license',
|
|
149
|
+
'author',
|
|
150
|
+
'contributors',
|
|
151
|
+
'files',
|
|
152
|
+
'browser',
|
|
153
|
+
'bin',
|
|
154
|
+
'man',
|
|
155
|
+
'directories',
|
|
156
|
+
'repository',
|
|
157
|
+
'peerDependencies',
|
|
158
|
+
'bundledDependencies',
|
|
159
|
+
'optionalDependencies',
|
|
160
|
+
'engineStrict',
|
|
161
|
+
'os',
|
|
162
|
+
'cpu',
|
|
163
|
+
'preferGlobal',
|
|
164
|
+
'private',
|
|
165
|
+
'publishConfig'
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
// Keys from templatePackage that will be merged with appPackage
|
|
169
|
+
const templatePackageToMerge = ['dependencies', 'scripts'];
|
|
170
|
+
|
|
171
|
+
// Keys from templatePackage that will be added to appPackage,
|
|
172
|
+
// replacing any existing entries.
|
|
173
|
+
const templatePackageToReplace = Object.keys(templatePackage).filter(key => {
|
|
174
|
+
return (
|
|
175
|
+
!templatePackageBlacklist.includes(key) &&
|
|
176
|
+
!templatePackageToMerge.includes(key)
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Copy over some of the devDependencies
|
|
181
|
+
appPackage.dependencies = appPackage.dependencies || {};
|
|
182
|
+
|
|
183
|
+
// Setup the script rules
|
|
184
|
+
const templateScripts = templatePackage.scripts || {};
|
|
185
|
+
appPackage.scripts = Object.assign(
|
|
186
|
+
{
|
|
187
|
+
start: 'react-scripts start',
|
|
188
|
+
build: 'react-scripts build',
|
|
189
|
+
test: 'react-scripts test',
|
|
190
|
+
eject: 'react-scripts eject'
|
|
191
|
+
},
|
|
192
|
+
templateScripts
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Update scripts for Yarn users
|
|
196
|
+
if (useYarn) {
|
|
197
|
+
appPackage.scripts = Object.entries(appPackage.scripts).reduce(
|
|
198
|
+
(acc, [key, value]) => ({
|
|
199
|
+
...acc,
|
|
200
|
+
[key]: value.replace(/(npm run |npm )/, 'yarn ')
|
|
201
|
+
}),
|
|
202
|
+
{}
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Setup the eslint config
|
|
207
|
+
appPackage.eslintConfig = {
|
|
208
|
+
extends: 'react-app'
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// Setup the browsers list
|
|
212
|
+
appPackage.browserslist = defaultBrowsers;
|
|
213
|
+
|
|
214
|
+
// Add templatePackage keys/values to appPackage, replacing existing entries
|
|
215
|
+
templatePackageToReplace.forEach(key => {
|
|
216
|
+
appPackage[key] = templatePackage[key];
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
fs.writeFileSync(
|
|
220
|
+
path.join(appPath, 'package.json'),
|
|
221
|
+
JSON.stringify(appPackage, null, 2) + os.EOL
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const readmeExists = fs.existsSync(path.join(appPath, 'README.md'));
|
|
225
|
+
if (readmeExists) {
|
|
226
|
+
fs.renameSync(
|
|
227
|
+
path.join(appPath, 'README.md'),
|
|
228
|
+
path.join(appPath, 'README.old.md')
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Copy the files for the user
|
|
233
|
+
const templateDir = path.join(templatePath, 'template');
|
|
234
|
+
if (fs.existsSync(templateDir)) {
|
|
235
|
+
fs.copySync(templateDir, appPath);
|
|
236
|
+
} else {
|
|
237
|
+
console.error(
|
|
238
|
+
`Could not locate supplied template: ${chalk.green(templateDir)}`
|
|
239
|
+
);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// modifies README.md commands based on user used package manager.
|
|
244
|
+
if (useYarn) {
|
|
245
|
+
try {
|
|
246
|
+
const readme = fs.readFileSync(path.join(appPath, 'README.md'), 'utf8');
|
|
247
|
+
fs.writeFileSync(
|
|
248
|
+
path.join(appPath, 'README.md'),
|
|
249
|
+
readme.replace(/(npm run |npm )/g, 'yarn '),
|
|
250
|
+
'utf8'
|
|
251
|
+
);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
// Silencing the error. As it fall backs to using default npm commands.
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const gitignoreExists = fs.existsSync(path.join(appPath, '.gitignore'));
|
|
258
|
+
if (gitignoreExists) {
|
|
259
|
+
// Append if there's already a `.gitignore` file there
|
|
260
|
+
const data = fs.readFileSync(path.join(appPath, 'gitignore'));
|
|
261
|
+
fs.appendFileSync(path.join(appPath, '.gitignore'), data);
|
|
262
|
+
fs.unlinkSync(path.join(appPath, 'gitignore'));
|
|
263
|
+
} else {
|
|
264
|
+
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
|
|
265
|
+
// See: https://github.com/npm/npm/issues/1862
|
|
266
|
+
fs.moveSync(
|
|
267
|
+
path.join(appPath, 'gitignore'),
|
|
268
|
+
path.join(appPath, '.gitignore'),
|
|
269
|
+
[]
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Initialize git repo
|
|
274
|
+
let initializedGit = false;
|
|
275
|
+
|
|
276
|
+
if (tryGitInit()) {
|
|
277
|
+
initializedGit = true;
|
|
278
|
+
console.log();
|
|
279
|
+
console.log('Initialized a git repository.');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let command;
|
|
283
|
+
let remove;
|
|
284
|
+
let args;
|
|
285
|
+
|
|
286
|
+
if (useYarn) {
|
|
287
|
+
command = 'yarnpkg';
|
|
288
|
+
remove = 'remove';
|
|
289
|
+
args = ['add'];
|
|
290
|
+
} else {
|
|
291
|
+
command = 'npm';
|
|
292
|
+
remove = 'uninstall';
|
|
293
|
+
args = [
|
|
294
|
+
'install',
|
|
295
|
+
'--no-audit', // https://github.com/facebook/create-react-app/issues/11174
|
|
296
|
+
'--save',
|
|
297
|
+
verbose && '--verbose'
|
|
298
|
+
].filter(e => e);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Install additional template dependencies, if present.
|
|
302
|
+
const dependenciesToInstall = Object.entries({
|
|
303
|
+
...templatePackage.dependencies,
|
|
304
|
+
...templatePackage.devDependencies
|
|
305
|
+
});
|
|
306
|
+
if (dependenciesToInstall.length) {
|
|
307
|
+
args = args.concat(
|
|
308
|
+
dependenciesToInstall.map(([dependency, version]) => {
|
|
309
|
+
return `${dependency}@${version}`;
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Install react and react-dom for backward compatibility with old CRA cli
|
|
315
|
+
// which doesn't install react and react-dom along with react-scripts
|
|
316
|
+
if (!isReactInstalled(appPackage)) {
|
|
317
|
+
args = args.concat(['react', 'react-dom']);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Install template dependencies, and react and react-dom if missing.
|
|
321
|
+
if ((!isReactInstalled(appPackage) || templateName) && args.length > 1) {
|
|
322
|
+
console.log();
|
|
323
|
+
console.log(`Installing template dependencies using ${command}...`);
|
|
324
|
+
|
|
325
|
+
const proc = spawn.sync(command, args, { stdio: 'inherit' });
|
|
326
|
+
if (proc.status !== 0) {
|
|
327
|
+
console.error(`\`${command} ${args.join(' ')}\` failed`);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (args.find(arg => arg.includes('typescript'))) {
|
|
333
|
+
console.log();
|
|
334
|
+
verifyTypeScriptSetup();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Remove template
|
|
338
|
+
console.log(`Removing template package using ${command}...`);
|
|
339
|
+
console.log();
|
|
340
|
+
|
|
341
|
+
const proc = spawn.sync(command, [remove, templateName], {
|
|
342
|
+
stdio: 'inherit'
|
|
343
|
+
});
|
|
344
|
+
if (proc.status !== 0) {
|
|
345
|
+
console.error(`\`${command} ${args.join(' ')}\` failed`);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Create git commit if git repo was initialized
|
|
350
|
+
if (initializedGit && tryGitCommit(appPath)) {
|
|
351
|
+
console.log();
|
|
352
|
+
console.log('Created git commit.');
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Display the most elegant way to cd.
|
|
356
|
+
// This needs to handle an undefined originalDirectory for
|
|
357
|
+
// backward compatibility with old global-cli's.
|
|
358
|
+
let cdpath;
|
|
359
|
+
if (originalDirectory && path.join(originalDirectory, appName) === appPath) {
|
|
360
|
+
cdpath = appName;
|
|
361
|
+
} else {
|
|
362
|
+
cdpath = appPath;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Change displayed command to yarn instead of yarnpkg
|
|
366
|
+
const displayedCommand = useYarn ? 'yarn' : 'npm';
|
|
367
|
+
|
|
368
|
+
console.log();
|
|
369
|
+
console.log(`Success! Created ${appName} at ${appPath}`);
|
|
370
|
+
console.log('Inside that directory, you can run several commands:');
|
|
371
|
+
console.log();
|
|
372
|
+
console.log(chalk.cyan(` ${displayedCommand} start`));
|
|
373
|
+
console.log(' Starts the development server.');
|
|
374
|
+
console.log();
|
|
375
|
+
console.log(
|
|
376
|
+
chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}build`)
|
|
377
|
+
);
|
|
378
|
+
console.log(' Bundles the app into static files for production.');
|
|
379
|
+
console.log();
|
|
380
|
+
console.log(chalk.cyan(` ${displayedCommand} test`));
|
|
381
|
+
console.log(' Starts the test runner.');
|
|
382
|
+
console.log();
|
|
383
|
+
console.log(
|
|
384
|
+
chalk.cyan(` ${displayedCommand} ${useYarn ? '' : 'run '}eject`)
|
|
385
|
+
);
|
|
386
|
+
console.log(
|
|
387
|
+
' Removes this tool and copies build dependencies, configuration files'
|
|
388
|
+
);
|
|
389
|
+
console.log(
|
|
390
|
+
' and scripts into the app directory. If you do this, you can’t go back!'
|
|
391
|
+
);
|
|
392
|
+
console.log();
|
|
393
|
+
console.log('We suggest that you begin by typing:');
|
|
394
|
+
console.log();
|
|
395
|
+
console.log(chalk.cyan(' cd'), cdpath);
|
|
396
|
+
console.log(` ${chalk.cyan(`${displayedCommand} start`)}`);
|
|
397
|
+
if (readmeExists) {
|
|
398
|
+
console.log();
|
|
399
|
+
console.log(
|
|
400
|
+
chalk.yellow(
|
|
401
|
+
'You had a `README.md` file, we renamed it to `README.old.md`'
|
|
402
|
+
)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
console.log();
|
|
406
|
+
console.log('Happy hacking!');
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
function isReactInstalled(appPackage) {
|
|
410
|
+
const dependencies = appPackage.dependencies || {};
|
|
411
|
+
|
|
412
|
+
return (
|
|
413
|
+
typeof dependencies.react !== 'undefined' &&
|
|
414
|
+
typeof dependencies['react-dom'] !== 'undefined'
|
|
415
|
+
);
|
|
416
|
+
}
|
package/scripts/start.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
// Do this as the first thing so that any code reading it knows the right env.
|
|
12
|
+
process.env.BABEL_ENV = 'development';
|
|
13
|
+
process.env.NODE_ENV = 'development';
|
|
14
|
+
|
|
15
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
16
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
17
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
18
|
+
process.on('unhandledRejection', err => {
|
|
19
|
+
throw err;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Ensure environment variables are read.
|
|
23
|
+
require('../config/env');
|
|
24
|
+
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const chalk = require('react-dev-utils/chalk');
|
|
27
|
+
const webpack = require('webpack');
|
|
28
|
+
const WebpackDevServer = require('webpack-dev-server');
|
|
29
|
+
const clearConsole = require('react-dev-utils/clearConsole');
|
|
30
|
+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
31
|
+
const {
|
|
32
|
+
choosePort,
|
|
33
|
+
createCompiler,
|
|
34
|
+
prepareProxy,
|
|
35
|
+
prepareUrls
|
|
36
|
+
} = require('react-dev-utils/WebpackDevServerUtils');
|
|
37
|
+
const openBrowser = require('react-dev-utils/openBrowser');
|
|
38
|
+
const semver = require('semver');
|
|
39
|
+
const paths = require('../config/paths');
|
|
40
|
+
const configFactory = require('../config/webpack.config');
|
|
41
|
+
const createDevServerConfig = require('../config/webpackDevServer.config');
|
|
42
|
+
const getClientEnvironment = require('../config/env');
|
|
43
|
+
const react = require(require.resolve('react', { paths: [paths.appPath] }));
|
|
44
|
+
|
|
45
|
+
const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
|
|
46
|
+
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
47
|
+
const isInteractive = process.stdout.isTTY;
|
|
48
|
+
|
|
49
|
+
// Warn and crash if required files are missing
|
|
50
|
+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Tools like Cloud9 rely on this.
|
|
55
|
+
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
|
56
|
+
const HOST = process.env.HOST || '0.0.0.0';
|
|
57
|
+
|
|
58
|
+
if (process.env.HOST) {
|
|
59
|
+
console.log(
|
|
60
|
+
chalk.cyan(
|
|
61
|
+
`Attempting to bind to HOST environment variable: ${chalk.yellow(
|
|
62
|
+
chalk.bold(process.env.HOST)
|
|
63
|
+
)}`
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
console.log(
|
|
67
|
+
`If this was unintentional, check that you haven't mistakenly set it in your shell.`
|
|
68
|
+
);
|
|
69
|
+
console.log(
|
|
70
|
+
`Learn more here: ${chalk.yellow('https://cra.link/advanced-config')}`
|
|
71
|
+
);
|
|
72
|
+
console.log();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// We require that you explicitly set browsers and do not fall back to
|
|
76
|
+
// browserslist defaults.
|
|
77
|
+
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
|
|
78
|
+
checkBrowsers(paths.appPath, isInteractive)
|
|
79
|
+
.then(() => {
|
|
80
|
+
// We attempt to use the default port but if it is busy, we offer the user to
|
|
81
|
+
// run on a different port. `choosePort()` Promise resolves to the next free port.
|
|
82
|
+
return choosePort(HOST, DEFAULT_PORT);
|
|
83
|
+
})
|
|
84
|
+
.then(port => {
|
|
85
|
+
if (port == null) {
|
|
86
|
+
// We have not found a port.
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const config = configFactory('development');
|
|
91
|
+
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
92
|
+
const appName = require(paths.appPackageJson).name;
|
|
93
|
+
|
|
94
|
+
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
|
95
|
+
const urls = prepareUrls(
|
|
96
|
+
protocol,
|
|
97
|
+
HOST,
|
|
98
|
+
port,
|
|
99
|
+
paths.publicUrlOrPath.slice(0, -1)
|
|
100
|
+
);
|
|
101
|
+
// Create a webpack compiler that is configured with custom messages.
|
|
102
|
+
const compiler = createCompiler({
|
|
103
|
+
appName,
|
|
104
|
+
config,
|
|
105
|
+
urls,
|
|
106
|
+
useYarn,
|
|
107
|
+
useTypeScript,
|
|
108
|
+
webpack
|
|
109
|
+
});
|
|
110
|
+
// Load proxy config
|
|
111
|
+
const proxySetting = require(paths.appPackageJson).proxy;
|
|
112
|
+
const proxyConfig = prepareProxy(
|
|
113
|
+
proxySetting,
|
|
114
|
+
paths.appPublic,
|
|
115
|
+
paths.publicUrlOrPath
|
|
116
|
+
);
|
|
117
|
+
// Serve webpack assets generated by the compiler over a web server.
|
|
118
|
+
const serverConfig = {
|
|
119
|
+
...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
|
|
120
|
+
host: HOST,
|
|
121
|
+
port
|
|
122
|
+
};
|
|
123
|
+
const devServer = new WebpackDevServer(serverConfig, compiler);
|
|
124
|
+
// Launch WebpackDevServer.
|
|
125
|
+
devServer.startCallback(() => {
|
|
126
|
+
if (isInteractive) {
|
|
127
|
+
clearConsole();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
|
|
131
|
+
console.log(
|
|
132
|
+
chalk.yellow(
|
|
133
|
+
`Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
console.log(chalk.cyan('Starting the development server...\n'));
|
|
139
|
+
openBrowser(urls.localUrlForBrowser);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
['SIGINT', 'SIGTERM'].forEach(function (sig) {
|
|
143
|
+
process.on(sig, function () {
|
|
144
|
+
devServer.stop();
|
|
145
|
+
process.exit();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (process.env.CI !== 'true') {
|
|
150
|
+
// Gracefully exit when stdin ends
|
|
151
|
+
process.stdin.on('end', function () {
|
|
152
|
+
devServer.stop();
|
|
153
|
+
process.exit();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
.catch(err => {
|
|
158
|
+
if (err && err.message) {
|
|
159
|
+
console.log(err.message);
|
|
160
|
+
}
|
|
161
|
+
process.exit(1);
|
|
162
|
+
});
|
package/scripts/test.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
// Do this as the first thing so that any code reading it knows the right env.
|
|
12
|
+
process.env.BABEL_ENV = 'test';
|
|
13
|
+
process.env.NODE_ENV = 'test';
|
|
14
|
+
process.env.PUBLIC_URL = '';
|
|
15
|
+
|
|
16
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
17
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
18
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
19
|
+
process.on('unhandledRejection', err => {
|
|
20
|
+
throw err;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Ensure environment variables are read.
|
|
24
|
+
require('../config/env');
|
|
25
|
+
|
|
26
|
+
const jest = require('jest');
|
|
27
|
+
const execSync = require('child_process').execSync;
|
|
28
|
+
let argv = process.argv.slice(2);
|
|
29
|
+
|
|
30
|
+
function isInGitRepository() {
|
|
31
|
+
try {
|
|
32
|
+
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
|
|
33
|
+
return true;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isInMercurialRepository() {
|
|
40
|
+
try {
|
|
41
|
+
execSync('hg --cwd . root', { stdio: 'ignore' });
|
|
42
|
+
return true;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 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
|
+
) {
|
|
54
|
+
// https://github.com/facebook/create-react-app/issues/5210
|
|
55
|
+
const hasSourceControl = isInGitRepository() || isInMercurialRepository();
|
|
56
|
+
argv.push(hasSourceControl ? '--watch' : '--watchAll');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// @remove-on-eject-begin
|
|
60
|
+
// This is not necessary after eject because we embed config into package.json.
|
|
61
|
+
const createJestConfig = require('./utils/createJestConfig');
|
|
62
|
+
const path = require('path');
|
|
63
|
+
const paths = require('../config/paths');
|
|
64
|
+
argv.push(
|
|
65
|
+
'--config',
|
|
66
|
+
JSON.stringify(
|
|
67
|
+
createJestConfig(
|
|
68
|
+
relativePath => path.resolve(__dirname, '..', relativePath),
|
|
69
|
+
path.resolve(paths.appSrc, '..'),
|
|
70
|
+
false
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// This is a very dirty workaround for https://github.com/facebook/jest/issues/5913.
|
|
76
|
+
// We're trying to resolve the environment ourselves because Jest does it incorrectly.
|
|
77
|
+
// TODO: remove this as soon as it's fixed in Jest.
|
|
78
|
+
const resolve = require('resolve');
|
|
79
|
+
function resolveJestDefaultEnvironment(name) {
|
|
80
|
+
const jestDir = path.dirname(
|
|
81
|
+
resolve.sync('jest', {
|
|
82
|
+
basedir: __dirname
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
const jestCLIDir = path.dirname(
|
|
86
|
+
resolve.sync('jest-cli', {
|
|
87
|
+
basedir: jestDir
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
const jestConfigDir = path.dirname(
|
|
91
|
+
resolve.sync('jest-config', {
|
|
92
|
+
basedir: jestCLIDir
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
return resolve.sync(name, {
|
|
96
|
+
basedir: jestConfigDir
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
let cleanArgv = [];
|
|
100
|
+
let env = 'jsdom';
|
|
101
|
+
let next;
|
|
102
|
+
do {
|
|
103
|
+
next = argv.shift();
|
|
104
|
+
if (next === '--env') {
|
|
105
|
+
env = argv.shift();
|
|
106
|
+
} else if (next.indexOf('--env=') === 0) {
|
|
107
|
+
env = next.substring('--env='.length);
|
|
108
|
+
} else {
|
|
109
|
+
cleanArgv.push(next);
|
|
110
|
+
}
|
|
111
|
+
} while (argv.length > 0);
|
|
112
|
+
argv = cleanArgv;
|
|
113
|
+
let resolvedEnv;
|
|
114
|
+
try {
|
|
115
|
+
resolvedEnv = resolveJestDefaultEnvironment(`jest-environment-${env}`);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
// ignore
|
|
118
|
+
}
|
|
119
|
+
if (!resolvedEnv) {
|
|
120
|
+
try {
|
|
121
|
+
resolvedEnv = resolveJestDefaultEnvironment(env);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
// ignore
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const testEnvironment = resolvedEnv || env;
|
|
127
|
+
argv.push('--env', testEnvironment);
|
|
128
|
+
// @remove-on-eject-end
|
|
129
|
+
jest.run(argv);
|