Skip to content

Commit 2b01430

Browse files
Add react scripts
0 parents  commit 2b01430

File tree

117 files changed

+6969
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+6969
-0
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/fixtures

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# react-scripts
2+
3+
This package includes scripts and configuration used by [Create React App](https://github.com/facebookincubator/create-react-app).<br>
4+
Please refer to its documentation:
5+
6+
* [Getting Started](https://github.com/facebookincubator/create-react-app/blob/master/README.md#getting-started) – How to create a new app.
7+
* [User Guide](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App.

bin/react-scripts-ts.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
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+
9+
'use strict';
10+
11+
const spawn = require('react-dev-utils/crossSpawn');
12+
const args = process.argv.slice(2);
13+
14+
const scriptIndex = args.findIndex(
15+
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
16+
);
17+
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
18+
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
19+
20+
switch (script) {
21+
case 'build':
22+
case 'eject':
23+
case 'start':
24+
case 'test': {
25+
const result = spawn.sync(
26+
'node',
27+
nodeArgs
28+
.concat(require.resolve('../scripts/' + script))
29+
.concat(args.slice(scriptIndex + 1)),
30+
{ stdio: 'inherit' }
31+
);
32+
if (result.signal) {
33+
if (result.signal === 'SIGKILL') {
34+
console.log(
35+
'The build failed because the process exited too early. ' +
36+
'This probably means the system ran out of memory or someone called ' +
37+
'`kill -9` on the process.'
38+
);
39+
} else if (result.signal === 'SIGTERM') {
40+
console.log(
41+
'The build failed because the process exited too early. ' +
42+
'Someone might have called `kill` or `killall`, or the system could ' +
43+
'be shutting down.'
44+
);
45+
}
46+
process.exit(1);
47+
}
48+
process.exit(result.status);
49+
break;
50+
}
51+
default:
52+
console.log('Unknown script "' + script + '".');
53+
console.log('Perhaps you need to update react-scripts-ts?');
54+
break;
55+
}

config/env.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
const fs = require('fs');
12+
const path = require('path');
13+
const paths = require('./paths');
14+
15+
// Make sure that including paths.js after env.js will read .env variables.
16+
delete require.cache[require.resolve('./paths')];
17+
18+
const NODE_ENV = process.env.NODE_ENV;
19+
if (!NODE_ENV) {
20+
throw new Error(
21+
'The NODE_ENV environment variable is required but was not specified.'
22+
);
23+
}
24+
25+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
26+
var dotenvFiles = [
27+
`${paths.dotenv}.${NODE_ENV}.local`,
28+
`${paths.dotenv}.${NODE_ENV}`,
29+
// Don't include `.env.local` for `test` environment
30+
// since normally you expect tests to produce the same
31+
// results for everyone
32+
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
33+
paths.dotenv,
34+
].filter(Boolean);
35+
36+
// Load environment variables from .env* files. Suppress warnings using silent
37+
// if this file is missing. dotenv will never modify any environment variables
38+
// that have already been set.
39+
// https://github.com/motdotla/dotenv
40+
dotenvFiles.forEach(dotenvFile => {
41+
if (fs.existsSync(dotenvFile)) {
42+
require('dotenv').config({
43+
path: dotenvFile,
44+
});
45+
}
46+
});
47+
48+
// We support resolving modules according to `NODE_PATH`.
49+
// This lets you use absolute paths in imports inside large monorepos:
50+
// https://github.com/facebookincubator/create-react-app/issues/253.
51+
// It works similar to `NODE_PATH` in Node itself:
52+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
53+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
54+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
55+
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
56+
// We also resolve them to make sure all tools using them work consistently.
57+
const appDirectory = fs.realpathSync(process.cwd());
58+
process.env.NODE_PATH = (process.env.NODE_PATH || '')
59+
.split(path.delimiter)
60+
.filter(folder => folder && !path.isAbsolute(folder))
61+
.map(folder => path.resolve(appDirectory, folder))
62+
.join(path.delimiter);
63+
64+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
65+
// injected into the application via DefinePlugin in Webpack configuration.
66+
const REACT_APP = /^REACT_APP_/i;
67+
68+
function getClientEnvironment(publicUrl) {
69+
const raw = Object.keys(process.env)
70+
.filter(key => REACT_APP.test(key))
71+
.reduce(
72+
(env, key) => {
73+
env[key] = process.env[key];
74+
return env;
75+
},
76+
{
77+
// Useful for determining whether we’re running in production mode.
78+
// Most importantly, it switches React into the correct mode.
79+
NODE_ENV: process.env.NODE_ENV || 'development',
80+
// Useful for resolving the correct path to static assets in `public`.
81+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
82+
// This should only be used as an escape hatch. Normally you would put
83+
// images into the `src` and `import` them in code to get their paths.
84+
PUBLIC_URL: publicUrl,
85+
}
86+
);
87+
// Stringify all values so we can feed into Webpack DefinePlugin
88+
const stringified = {
89+
'process.env': Object.keys(raw).reduce((env, key) => {
90+
env[key] = JSON.stringify(raw[key]);
91+
return env;
92+
}, {}),
93+
};
94+
95+
return { raw, stringified };
96+
}
97+
98+
module.exports = getClientEnvironment;

config/jest/babelTransform.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @remove-file-on-eject
2+
/**
3+
* Copyright (c) 2014-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+
const babelJest = require('babel-jest');
11+
12+
module.exports = babelJest.createTransformer({
13+
presets: [require.resolve('babel-preset-react-app')],
14+
babelrc: false,
15+
});

config/jest/cssTransform.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2014-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+
// This is a custom Jest transformer turning style imports into empty objects.
12+
// http://facebook.github.io/jest/docs/tutorial-webpack.html
13+
14+
module.exports = {
15+
process() {
16+
return 'module.exports = {};';
17+
},
18+
getCacheKey() {
19+
// The output is always the same.
20+
return 'cssTransform';
21+
},
22+
};

config/jest/fileTransform.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2014-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+
const path = require('path');
12+
13+
// This is a custom Jest transformer turning file imports into filenames.
14+
// http://facebook.github.io/jest/docs/tutorial-webpack.html
15+
16+
module.exports = {
17+
process(src, filename) {
18+
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
19+
},
20+
};

config/jest/typescriptTransform.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
3+
'use strict';
4+
5+
const tsJestPreprocessor = require('ts-jest/preprocessor');
6+
7+
module.exports = tsJestPreprocessor;

config/paths.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
const path = require('path');
12+
const fs = require('fs');
13+
const url = require('url');
14+
15+
// Make sure any symlinks in the project folder are resolved:
16+
// https://github.com/facebookincubator/create-react-app/issues/637
17+
const appDirectory = fs.realpathSync(process.cwd());
18+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
19+
20+
const envPublicUrl = process.env.PUBLIC_URL;
21+
22+
function ensureSlash(path, needsSlash) {
23+
const hasSlash = path.endsWith('/');
24+
if (hasSlash && !needsSlash) {
25+
return path.substr(path, path.length - 1);
26+
} else if (!hasSlash && needsSlash) {
27+
return `${path}/`;
28+
} else {
29+
return path;
30+
}
31+
}
32+
33+
const getPublicUrl = appPackageJson =>
34+
envPublicUrl || require(appPackageJson).homepage;
35+
36+
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
37+
// "public path" at which the app is served.
38+
// Webpack needs to know it to put the right <script> hrefs into HTML even in
39+
// single-page apps that may serve index.html for nested URLs like /todos/42.
40+
// We can't use a relative path in HTML because we don't want to load something
41+
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
42+
function getServedPath(appPackageJson) {
43+
const publicUrl = getPublicUrl(appPackageJson);
44+
const servedUrl =
45+
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
46+
return ensureSlash(servedUrl, true);
47+
}
48+
49+
// config after eject: we're in ./config/
50+
module.exports = {
51+
dotenv: resolveApp('.env'),
52+
appBuild: resolveApp('build'),
53+
appPublic: resolveApp('public'),
54+
appHtml: resolveApp('public/index.html'),
55+
appIndexJs: resolveApp('src/index.tsx'),
56+
appPackageJson: resolveApp('package.json'),
57+
appSrc: resolveApp('src'),
58+
yarnLockFile: resolveApp('yarn.lock'),
59+
testsSetup: resolveApp('src/setupTests.ts'),
60+
appNodeModules: resolveApp('node_modules'),
61+
appTsConfig: resolveApp('tsconfig.json'),
62+
publicUrl: getPublicUrl(resolveApp('package.json')),
63+
servedPath: getServedPath(resolveApp('package.json')),
64+
};
65+
66+
// @remove-on-eject-begin
67+
const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
68+
69+
// config before eject: we're in ./node_modules/react-scripts/config/
70+
module.exports = {
71+
dotenv: resolveApp('.env'),
72+
appPath: resolveApp('.'),
73+
appBuild: resolveApp('build'),
74+
appPublic: resolveApp('public'),
75+
appHtml: resolveApp('public/index.html'),
76+
appIndexJs: resolveApp('src/index.tsx'),
77+
appPackageJson: resolveApp('package.json'),
78+
appSrc: resolveApp('src'),
79+
yarnLockFile: resolveApp('yarn.lock'),
80+
testsSetup: resolveApp('src/setupTests.ts'),
81+
appNodeModules: resolveApp('node_modules'),
82+
appTsConfig: resolveApp('tsconfig.json'),
83+
appTsTestConfig: resolveApp('tsconfig.test.json'),
84+
publicUrl: getPublicUrl(resolveApp('package.json')),
85+
servedPath: getServedPath(resolveApp('package.json')),
86+
// These properties only exist before ejecting:
87+
ownPath: resolveOwn('.'),
88+
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
89+
};
90+
91+
const ownPackageJson = require('../package.json');
92+
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
93+
const reactScriptsLinked =
94+
fs.existsSync(reactScriptsPath) &&
95+
fs.lstatSync(reactScriptsPath).isSymbolicLink();
96+
97+
// config before publish: we're in ./packages/react-scripts/config/
98+
if (
99+
!reactScriptsLinked &&
100+
__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
101+
) {
102+
module.exports = {
103+
dotenv: resolveOwn('template/.env'),
104+
appPath: resolveApp('.'),
105+
appBuild: resolveOwn('../../build'),
106+
appPublic: resolveOwn('template/public'),
107+
appHtml: resolveOwn('template/public/index.html'),
108+
appIndexJs: resolveOwn('template/src/index.tsx'),
109+
appPackageJson: resolveOwn('package.json'),
110+
appSrc: resolveOwn('template/src'),
111+
yarnLockFile: resolveOwn('template/yarn.lock'),
112+
testsSetup: resolveOwn('template/src/setupTests.ts'),
113+
appNodeModules: resolveOwn('node_modules'),
114+
appTsConfig: resolveOwn('template/tsconfig.json'),
115+
appTsTestConfig: resolveOwn('template/tsconfig.test.json'),
116+
publicUrl: getPublicUrl(resolveOwn('package.json')),
117+
servedPath: getServedPath(resolveOwn('package.json')),
118+
// These properties only exist before ejecting:
119+
ownPath: resolveOwn('.'),
120+
ownNodeModules: resolveOwn('node_modules'),
121+
};
122+
}
123+
// @remove-on-eject-end

config/polyfills.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
if (typeof Promise === 'undefined') {
12+
// Rejection tracking prevents a common issue where React gets into an
13+
// inconsistent state due to an error, but it gets swallowed by a Promise,
14+
// and the user has no idea what causes React's erratic future behavior.
15+
require('promise/lib/rejection-tracking').enable();
16+
window.Promise = require('promise/lib/es6-extensions.js');
17+
}
18+
19+
// fetch() polyfill for making API calls.
20+
require('whatwg-fetch');
21+
22+
// Object.assign() is commonly used with React.
23+
// It will use the native implementation if it's present and isn't buggy.
24+
Object.assign = require('object-assign');
25+
26+
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
27+
// We don't polyfill it in the browser--this is user's responsibility.
28+
if (process.env.NODE_ENV === 'test') {
29+
require('raf').polyfill(global);
30+
}

0 commit comments

Comments
 (0)