Skip to content

Commit 0ca20c6

Browse files
committed
update to latest cra branch
1 parent e4d5ac7 commit 0ca20c6

27 files changed

+1355
-1347
lines changed

bin/react-unity-scripts.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ const spawn = require('react-dev-utils/crossSpawn');
1919
const args = process.argv.slice(2);
2020

2121
const scriptIndex = args.findIndex(
22-
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' || x === 'lint'
22+
x =>
23+
x === 'build' ||
24+
x === 'eject' ||
25+
x === 'start' ||
26+
x === 'test' ||
27+
x === 'lint'
2328
);
2429
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
2530
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];

config/env.js

-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ function getClientEnvironment(publicUrl) {
9494
WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
9595
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
9696
// Whether or not react-refresh is enabled.
97-
// react-refresh is not 100% stable at this time,
98-
// which is why it's disabled by default.
9997
// It is defined here so it is available in the webpackHotDevClient.
10098
FAST_REFRESH: process.env.FAST_REFRESH || false,
10199
}

config/eslintConfig.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ const baseConfig = {
2929
...(!modules.hasJsxRuntime && {
3030
'react/react-in-jsx-scope': 'error',
3131
}),
32-
'no-restricted-globals': ['error'].concat(restrictedGlobals.filter(x => x !== 'location')),
32+
'no-restricted-globals': ['error'].concat(restrictedGlobals),
3333
},
3434
};
3535

3636
module.exports = {
3737
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
3838
cache: true,
39-
cacheLocation: path.resolve(
40-
paths.appNodeModules,
41-
'.cache/.eslintcache'
42-
),
39+
cacheLocation: path.resolve(paths.appNodeModules, '.cache/.eslintcache'),
4340
cwd: paths.appPath,
4441
resolvePluginsRelativeTo: __dirname,
4542
baseConfig,

config/jest/babelTransform.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 babelJest = require('babel-jest').default;
12+
13+
const hasJsxRuntime = (() => {
14+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
15+
return false;
16+
}
17+
18+
try {
19+
require.resolve('react/jsx-runtime');
20+
return true;
21+
} catch (e) {
22+
return false;
23+
}
24+
})();
25+
26+
module.exports = babelJest.createTransformer({
27+
presets: [
28+
[
29+
require.resolve('babel-preset-react-app'),
30+
{
31+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
32+
},
33+
],
34+
],
35+
babelrc: false,
36+
configFile: false,
37+
});

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/en/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

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const camelcase = require('camelcase');
5+
6+
// This is a custom Jest transformer turning file imports into filenames.
7+
// http://facebook.github.io/jest/docs/en/webpack.html
8+
9+
module.exports = {
10+
process(src, filename) {
11+
const assetFilename = JSON.stringify(path.basename(filename));
12+
13+
if (filename.match(/\.svg$/)) {
14+
// Based on how SVGR generates a component name:
15+
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
16+
const pascalCaseFilename = camelcase(path.parse(filename).name, {
17+
pascalCase: true,
18+
});
19+
const componentName = `Svg${pascalCaseFilename}`;
20+
return `const React = require('react');
21+
module.exports = {
22+
__esModule: true,
23+
default: ${assetFilename},
24+
ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
25+
return {
26+
$$typeof: Symbol.for('react.element'),
27+
type: 'svg',
28+
ref: ref,
29+
key: null,
30+
props: Object.assign({}, props, {
31+
children: ${assetFilename}
32+
})
33+
};
34+
}),
35+
};`;
36+
}
37+
38+
return `module.exports = ${assetFilename};`;
39+
},
40+
};

config/paths.js

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ module.exports = {
7474
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
7575
proxySetup: resolveApp('src/setupProxy.js'),
7676
appNodeModules: resolveApp('node_modules'),
77+
appWebpackCache: resolveApp('node_modules/.cache'),
78+
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
7779
swSrc: resolveModule(resolveApp, 'src/service-worker'),
7880
publicUrlOrPath,
7981
};
@@ -97,6 +99,8 @@ module.exports = {
9799
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
98100
proxySetup: resolveApp('src/setupProxy.js'),
99101
appNodeModules: resolveApp('node_modules'),
102+
appWebpackCache: resolveApp('node_modules/.cache'),
103+
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
100104
swSrc: resolveModule(resolveApp, 'src/service-worker'),
101105
publicUrlOrPath,
102106
// These properties only exist before ejecting:
@@ -133,6 +137,8 @@ if (
133137
testsSetup: resolveModule(resolveOwn, `${templatePath}/src/setupTests`),
134138
proxySetup: resolveOwn(`${templatePath}/src/setupProxy.js`),
135139
appNodeModules: resolveOwn('node_modules'),
140+
appWebpackCache: resolveOwn('node_modules/.cache'),
141+
appTsBuildInfoFile: resolveOwn('node_modules/.cache/tsconfig.tsbuildinfo'),
136142
swSrc: resolveModule(resolveOwn, `${templatePath}/src/service-worker`),
137143
publicUrlOrPath,
138144
// These properties only exist before ejecting:

config/pnpTs.js

-43
This file was deleted.

config/react-error-overlay.js

-9
This file was deleted.

config/refreshOverlayInterop.js

-4
This file was deleted.

config/unityMiddleware.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function registerUnityMiddleware(app) {
2+
// Allow serving Unity builds
3+
function contentEncodingShorthand(pattern, encoding) {
4+
app.get(pattern, function (req, res, next) {
5+
res.set('Content-Encoding', encoding);
6+
next();
7+
});
8+
}
9+
10+
function contentTypeShorthand(pattern, type) {
11+
app.get(pattern, function (req, res, next) {
12+
res.set('Content-Type', type);
13+
next();
14+
});
15+
}
16+
17+
contentEncodingShorthand('*.unityweb', 'gzip');
18+
contentEncodingShorthand('*.gz', 'gzip');
19+
contentEncodingShorthand('*.br', 'br');
20+
contentTypeShorthand('*.js.gz', 'application/javascript');
21+
contentTypeShorthand('*.js.br', 'application/javascript');
22+
contentTypeShorthand('*.wasm', 'application/wasm');
23+
contentTypeShorthand('*.wasm.gz', 'application/wasm');
24+
contentTypeShorthand('*.wasm.br', 'application/wasm');
25+
}
26+
27+
module.exports = {
28+
registerUnityMiddleware,
29+
};

0 commit comments

Comments
 (0)