@reactunity/scripts 0.8.1 → 0.9.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/scripts/start.js CHANGED
@@ -8,13 +8,10 @@
8
8
  // @remove-on-eject-end
9
9
  'use strict';
10
10
 
11
- const argv = process.argv.slice(2);
12
- const isTest = argv.indexOf('--test') !== -1;
13
- const defaultConf = isTest ? 'test' : 'development';
14
-
15
11
  // Do this as the first thing so that any code reading it knows the right env.
16
- process.env.BABEL_ENV = process.env.BABEL_ENV || process.env.NODE_ENV || 'development';
17
- process.env.NODE_ENV = process.env.NODE_ENV || 'development';
12
+ process.env.BABEL_ENV = 'development';
13
+ process.env.NODE_ENV = 'development';
14
+
18
15
  // Makes the script crash on unhandled rejections instead of silently
19
16
  // ignoring them. In the future, promise rejections that are not handled will
20
17
  // terminate the Node.js process with a non-zero exit code.
@@ -33,37 +30,37 @@ if (!allowClearingConsole) {
33
30
  require.cache[require.resolve('react-dev-utils/clearConsole')].exports = clearConsole;
34
31
  }
35
32
 
36
- // @remove-on-eject-begin
37
- // Do the preflight check (only happens before eject).
38
- const verifyPackageTree = require('./utils/verifyPackageTree');
39
- if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
40
- verifyPackageTree();
41
- }
42
- const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
43
- verifyTypeScriptSetup();
44
- // @remove-on-eject-end
45
-
46
33
  const fs = require('fs');
47
34
  const chalk = require('react-dev-utils/chalk');
48
35
  const webpack = require('webpack');
49
36
  const WebpackDevServer = require('webpack-dev-server');
50
37
  const clearConsole = require('react-dev-utils/clearConsole');
38
+ const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
51
39
  const {
52
40
  choosePort,
53
41
  createCompiler,
54
42
  prepareProxy,
55
43
  prepareUrls,
56
44
  } = require('react-dev-utils/WebpackDevServerUtils');
45
+ const semver = require('semver');
57
46
  const paths = require('../config/paths');
58
47
  const configFactory = require('../config/webpack.config');
59
48
  const createDevServerConfig = require('../config/webpackDevServer.config');
49
+ const getClientEnvironment = require('../config/env');
50
+ const react = require(require.resolve('react', { paths: [paths.appPath] }));
60
51
 
52
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
61
53
  const useYarn = fs.existsSync(paths.yarnLockFile);
62
54
  const isInteractive = process.stdout.isTTY;
63
55
 
56
+ // Warn and crash if required files are missing
57
+ if (!checkRequiredFiles([paths.appIndexJs])) {
58
+ process.exit(1);
59
+ }
60
+
64
61
  // Tools like Cloud9 rely on this.
65
62
  const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
66
- const host = process.env.HOST || '0.0.0.0';
63
+ const HOST = process.env.HOST || '0.0.0.0';
67
64
 
68
65
  if (process.env.HOST) {
69
66
  console.log(
@@ -82,40 +79,39 @@ if (process.env.HOST) {
82
79
  console.log();
83
80
  }
84
81
 
85
-
86
- choosePort(host, DEFAULT_PORT)
82
+ // We require that you explicitly set browsers and do not fall back to
83
+ // browserslist defaults.
84
+ const checkBrowsers = () => Promise.resolve();
85
+ checkBrowsers(paths.appPath, isInteractive)
86
+ .then(() => {
87
+ // We attempt to use the default port but if it is busy, we offer the user to
88
+ // run on a different port. `choosePort()` Promise resolves to the next free port.
89
+ return choosePort(HOST, DEFAULT_PORT);
90
+ })
87
91
  .then(port => {
88
92
  if (port == null) {
89
93
  // We have not found a port.
90
94
  return;
91
95
  }
92
96
 
93
- const config = configFactory(defaultConf);
97
+ const config = configFactory('development');
94
98
  const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
95
99
  const appName = require(paths.appPackageJson).name;
100
+
96
101
  const useTypeScript = fs.existsSync(paths.appTsConfig);
97
- const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
98
102
  const urls = prepareUrls(
99
103
  protocol,
100
- host,
104
+ HOST,
101
105
  port,
102
106
  paths.publicUrlOrPath.slice(0, -1)
103
107
  );
104
- const devSocket = {
105
- warnings: warnings =>
106
- devServer.sendMessage(devServer.sockets, 'warnings', warnings),
107
- errors: errors =>
108
- devServer.sendMessage(devServer.sockets, 'errors', errors),
109
- };
110
108
  // Create a webpack compiler that is configured with custom messages.
111
109
  const compiler = createCompiler({
112
110
  appName,
113
111
  config,
114
- devSocket,
115
112
  urls,
116
113
  useYarn,
117
114
  useTypeScript,
118
- tscCompileOnError,
119
115
  webpack,
120
116
  });
121
117
  // Load proxy config
@@ -126,22 +122,26 @@ choosePort(host, DEFAULT_PORT)
126
122
  paths.publicUrlOrPath
127
123
  );
128
124
  // Serve webpack assets generated by the compiler over a web server.
129
- const serverConfig = createDevServerConfig(
130
- proxyConfig,
131
- urls.lanUrlForConfig,
132
- host,
125
+ const serverConfig = {
126
+ ...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
127
+ host: HOST,
133
128
  port,
134
- );
129
+ };
135
130
  const devServer = new WebpackDevServer(serverConfig, compiler);
136
- // Launch WebpackDevServer
137
- devServer.startCallback(err => {
138
- if (err) {
139
- return console.log(err);
140
- }
131
+ // Launch WebpackDevServer.
132
+ devServer.startCallback(() => {
141
133
  if (isInteractive) {
142
134
  clearConsole();
143
135
  }
144
136
 
137
+ if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
138
+ console.log(
139
+ chalk.yellow(
140
+ `Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
141
+ )
142
+ );
143
+ }
144
+
145
145
  console.log(chalk.cyan('Starting the development server...\n'));
146
146
  });
147
147
 
@@ -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);
@@ -0,0 +1,152 @@
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
+ const fs = require('fs');
11
+ const chalk = require('react-dev-utils/chalk');
12
+ const paths = require('../../config/paths');
13
+ const modules = require('../../config/modules');
14
+
15
+ module.exports = (resolve, rootDir, isEjecting) => {
16
+ // Use this instead of `paths.testsSetup` to avoid putting
17
+ // an absolute filename into configuration after ejecting.
18
+ const setupTestsMatches = paths.testsSetup.match(/src[/\\]setupTests\.(.+)/);
19
+ const setupTestsFileExtension =
20
+ (setupTestsMatches && setupTestsMatches[1]) || 'js';
21
+ const setupTestsFile = fs.existsSync(paths.testsSetup)
22
+ ? `<rootDir>/src/setupTests.${setupTestsFileExtension}`
23
+ : undefined;
24
+
25
+ const config = {
26
+ roots: ['<rootDir>/src'],
27
+
28
+ collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
29
+
30
+ setupFiles: [
31
+ isEjecting
32
+ ? 'react-app-polyfill/jsdom'
33
+ : require.resolve('react-app-polyfill/jsdom'),
34
+ ],
35
+
36
+ setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [],
37
+ testMatch: [
38
+ '<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
39
+ '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
40
+ ],
41
+ testEnvironment: 'jsdom',
42
+ transform: {
43
+ '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': resolve(
44
+ 'config/jest/babelTransform.js'
45
+ ),
46
+ '^.+\\.css$': resolve('config/jest/cssTransform.js'),
47
+ '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': resolve(
48
+ 'config/jest/fileTransform.js'
49
+ ),
50
+ },
51
+ transformIgnorePatterns: [
52
+ '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
53
+ '^.+\\.module\\.(css|sass|scss)$',
54
+ ],
55
+ modulePaths: modules.additionalModulePaths || [],
56
+ moduleNameMapper: {
57
+ '^react-native$': 'react-native-web',
58
+ '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
59
+ ...(modules.jestAliases || {}),
60
+ },
61
+ moduleFileExtensions: [...paths.moduleFileExtensions, 'node'].filter(
62
+ ext => !ext.includes('mjs')
63
+ ),
64
+ watchPlugins: [
65
+ 'jest-watch-typeahead/filename',
66
+ 'jest-watch-typeahead/testname',
67
+ ],
68
+ resetMocks: true,
69
+ };
70
+ if (rootDir) {
71
+ config.rootDir = rootDir;
72
+ }
73
+ const overrides = Object.assign({}, require(paths.appPackageJson).jest);
74
+ const supportedKeys = [
75
+ 'clearMocks',
76
+ 'collectCoverageFrom',
77
+ 'coveragePathIgnorePatterns',
78
+ 'coverageReporters',
79
+ 'coverageThreshold',
80
+ 'displayName',
81
+ 'extraGlobals',
82
+ 'globalSetup',
83
+ 'globalTeardown',
84
+ 'moduleNameMapper',
85
+ 'resetMocks',
86
+ 'resetModules',
87
+ 'restoreMocks',
88
+ 'snapshotSerializers',
89
+ 'testMatch',
90
+ 'transform',
91
+ 'transformIgnorePatterns',
92
+ 'watchPathIgnorePatterns',
93
+ ];
94
+ if (overrides) {
95
+ supportedKeys.forEach(key => {
96
+ if (Object.prototype.hasOwnProperty.call(overrides, key)) {
97
+ if (Array.isArray(config[key]) || typeof config[key] !== 'object') {
98
+ // for arrays or primitive types, directly override the config key
99
+ config[key] = overrides[key];
100
+ } else {
101
+ // for object types, extend gracefully
102
+ config[key] = Object.assign({}, config[key], overrides[key]);
103
+ }
104
+
105
+ delete overrides[key];
106
+ }
107
+ });
108
+ const unsupportedKeys = Object.keys(overrides);
109
+ if (unsupportedKeys.length) {
110
+ const isOverridingSetupFile =
111
+ unsupportedKeys.indexOf('setupFilesAfterEnv') > -1;
112
+
113
+ if (isOverridingSetupFile) {
114
+ console.error(
115
+ chalk.red(
116
+ 'We detected ' +
117
+ chalk.bold('setupFilesAfterEnv') +
118
+ ' in your package.json.\n\n' +
119
+ 'Remove it from Jest configuration, and put the initialization code in ' +
120
+ chalk.bold('src/setupTests.js') +
121
+ '.\nThis file will be loaded automatically.\n'
122
+ )
123
+ );
124
+ } else {
125
+ console.error(
126
+ chalk.red(
127
+ '\nOut of the box, Create React App only supports overriding ' +
128
+ 'these Jest options:\n\n' +
129
+ supportedKeys
130
+ .map(key => chalk.bold(' \u2022 ' + key))
131
+ .join('\n') +
132
+ '.\n\n' +
133
+ 'These options in your package.json Jest configuration ' +
134
+ 'are not currently supported by Create React App:\n\n' +
135
+ unsupportedKeys
136
+ .map(key => chalk.bold(' \u2022 ' + key))
137
+ .join('\n') +
138
+ '\n\nIf you wish to override other Jest options, you need to ' +
139
+ 'eject from the default setup. You can do so by running ' +
140
+ chalk.bold('npm run eject') +
141
+ ' but remember that this is a one-way operation. ' +
142
+ 'You may also file an issue with Create React App to discuss ' +
143
+ 'supporting more options out of the box.\n'
144
+ )
145
+ );
146
+ }
147
+
148
+ process.exit(1);
149
+ }
150
+ }
151
+ return config;
152
+ };