@reactunity/scripts 0.7.0 → 0.9.1

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,36 @@ 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');
60
50
 
51
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
61
52
  const useYarn = fs.existsSync(paths.yarnLockFile);
62
53
  const isInteractive = process.stdout.isTTY;
63
54
 
55
+ // Warn and crash if required files are missing
56
+ if (!checkRequiredFiles([paths.appIndexJs])) {
57
+ process.exit(1);
58
+ }
59
+
64
60
  // Tools like Cloud9 rely on this.
65
61
  const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
66
- const host = process.env.HOST || '0.0.0.0';
62
+ const HOST = process.env.HOST || '0.0.0.0';
67
63
 
68
64
  if (process.env.HOST) {
69
65
  console.log(
@@ -82,40 +78,39 @@ if (process.env.HOST) {
82
78
  console.log();
83
79
  }
84
80
 
85
-
86
- choosePort(host, DEFAULT_PORT)
81
+ // We require that you explicitly set browsers and do not fall back to
82
+ // browserslist defaults.
83
+ const checkBrowsers = () => Promise.resolve();
84
+ checkBrowsers(paths.appPath, isInteractive)
85
+ .then(() => {
86
+ // We attempt to use the default port but if it is busy, we offer the user to
87
+ // run on a different port. `choosePort()` Promise resolves to the next free port.
88
+ return choosePort(HOST, DEFAULT_PORT);
89
+ })
87
90
  .then(port => {
88
91
  if (port == null) {
89
92
  // We have not found a port.
90
93
  return;
91
94
  }
92
95
 
93
- const config = configFactory(defaultConf);
96
+ const config = configFactory('development');
94
97
  const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
95
98
  const appName = require(paths.appPackageJson).name;
99
+
96
100
  const useTypeScript = fs.existsSync(paths.appTsConfig);
97
- const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
98
101
  const urls = prepareUrls(
99
102
  protocol,
100
- host,
103
+ HOST,
101
104
  port,
102
105
  paths.publicUrlOrPath.slice(0, -1)
103
106
  );
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
107
  // Create a webpack compiler that is configured with custom messages.
111
108
  const compiler = createCompiler({
112
109
  appName,
113
110
  config,
114
- devSocket,
115
111
  urls,
116
112
  useYarn,
117
113
  useTypeScript,
118
- tscCompileOnError,
119
114
  webpack,
120
115
  });
121
116
  // Load proxy config
@@ -126,18 +121,14 @@ choosePort(host, DEFAULT_PORT)
126
121
  paths.publicUrlOrPath
127
122
  );
128
123
  // Serve webpack assets generated by the compiler over a web server.
129
- const serverConfig = createDevServerConfig(
130
- proxyConfig,
131
- urls.lanUrlForConfig,
132
- host,
124
+ const serverConfig = {
125
+ ...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
126
+ host: HOST,
133
127
  port,
134
- );
128
+ };
135
129
  const devServer = new WebpackDevServer(serverConfig, compiler);
136
- // Launch WebpackDevServer
137
- devServer.startCallback(err => {
138
- if (err) {
139
- return console.log(err);
140
- }
130
+ // Launch WebpackDevServer.
131
+ devServer.startCallback(() => {
141
132
  if (isInteractive) {
142
133
  clearConsole();
143
134
  }
@@ -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
+ };