MCPcopy Index your code
hub / github.com/react/create-react-app / checkBrowsers

Function checkBrowsers

packages/react-dev-utils/browsersHelper.js:44–93  ·  view source on GitHub ↗
(dir, isInteractive, retry = true)

Source from the content-addressed store, hash-verified

42}
43
44function checkBrowsers(dir, isInteractive, retry = true) {
45 const current = browserslist.loadConfig({ path: dir });
46 if (current != null) {
47 return Promise.resolve(current);
48 }
49
50 if (!retry) {
51 return Promise.reject(
52 new Error(
53 chalk.red(
54 'As of react-scripts >=2 you must specify targeted browsers.'
55 ) +
56 os.EOL +
57 `Please add a ${chalk.underline(
58 'browserslist'
59 )} key to your ${chalk.bold('package.json')}.`
60 )
61 );
62 }
63
64 return shouldSetBrowsers(isInteractive).then(shouldSetBrowsers => {
65 if (!shouldSetBrowsers) {
66 return checkBrowsers(dir, isInteractive, false);
67 }
68
69 return (
70 pkgUp({ cwd: dir })
71 .then(filePath => {
72 if (filePath == null) {
73 return Promise.reject();
74 }
75 const pkg = JSON.parse(fs.readFileSync(filePath));
76 pkg['browserslist'] = defaultBrowsers;
77 fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + os.EOL);
78
79 browserslist.clearCaches();
80 console.log();
81 console.log(
82 `${chalk.green('Set target browsers:')} ${chalk.cyan(
83 defaultBrowsers.join(', ')
84 )}`
85 );
86 console.log();
87 })
88 // Swallow any error
89 .catch(() => {})
90 .then(() => checkBrowsers(dir, isInteractive, false))
91 );
92 });
93}
94
95module.exports = { defaultBrowsers, checkBrowsers };

Callers 2

start.jsFile · 0.85
build.jsFile · 0.85

Calls 1

shouldSetBrowsersFunction · 0.85

Tested by

no test coverage detected