Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SSR not supports node 14.x optional chaining #4980

Merged
merged 5 commits into from Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: [8.x, 10.x, 12.x]
node_version: [8.x, 10.x, 12.x, 14.x]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-umi/package.json
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "7.10.4",
"@babel/plugin-proposal-optional-chaining": "7.10.4",
"@babel/plugin-proposal-decorators": "7.10.4",
"@babel/plugin-proposal-do-expressions": "7.10.4",
"@babel/plugin-proposal-export-default-from": "7.10.4",
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-preset-umi/src/index.ts
Expand Up @@ -66,6 +66,10 @@ export default (context: any, opts: IOpts = {}) => {
],
].filter(Boolean),
plugins: [
[
require('@babel/plugin-proposal-optional-chaining').default,
ycjcl868 marked this conversation as resolved.
Show resolved Hide resolved
{ loose: false },
],
require('@babel/plugin-syntax-top-level-await').default,
// Necessary to include regardless of the environment because
// in practice some other transforms (such as object-rest-spread)
Expand Down
Expand Up @@ -57,5 +57,5 @@ test('ssr', () => {
expect(targets).toEqual({
node: 6,
});
expect(browserslist).toEqual(['node >= 6']);
expect(browserslist).toEqual(['ie >= 10', 'chrome >= 0', 'firefox >= 0']);
});
39 changes: 30 additions & 9 deletions packages/bundler-utils/src/getTargetsAndBrowsersList.ts
Expand Up @@ -10,25 +10,46 @@ interface IOpts {
type: IBundlerConfigType;
}

/**
* set default browserslist using `targets` config
* client bundle: without node
* server bundle: `targets` with node, `browserslist` without node
*
* @param param0
*/
export default function ({ config, type }: IOpts) {
ycjcl868 marked this conversation as resolved.
Show resolved Hide resolved
let targets: ITargets = config.targets || {};
const configTargets: ITargets = config.targets || {};

targets = Object.keys(targets)
const targets = Object.keys(configTargets)
.filter((key) => {
// filter false and 0 targets
if (targets[key] === false) return false;
if (type === BundlerConfigType.ssr) return key === 'node';
else return key !== 'node';
if (configTargets[key] === false) return false;
if (type === BundlerConfigType.ssr) {
return key === 'node';
}
return key !== 'node';
})
.reduce((memo, key) => {
memo[key] = targets[key];
memo[key] = configTargets[key];
return memo;
}, {} as any);

const browserTargets = Object.keys(configTargets)
.filter((key) => {
// filter false and 0 targets
if (configTargets[key] === false) return false;
return key !== 'node';
})
.reduce((memo, key) => {
memo[key] = configTargets[key];
return memo;
}, {} as any);
const browserslist =
targets.browsers ||
Object.keys(targets).map((key) => {
return `${key} >= ${targets[key] === true ? '0' : targets[key]}`;
configTargets.browsers ||
Object.keys(browserTargets).map((key) => {
return `${key} >= ${
browserTargets[key] === true ? '0' : browserTargets[key]
}`;
});

return {
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Expand Up @@ -787,6 +787,14 @@
"@babel/helper-plugin-utils" "^7.8.3"
"@babel/plugin-syntax-optional-catch-binding" "^7.8.0"

"@babel/plugin-proposal-optional-chaining@7.10.4", "@babel/plugin-proposal-optional-chaining@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.10.4.tgz#750f1255e930a1f82d8cdde45031f81a0d0adff7"
integrity sha512-ZIhQIEeavTgouyMSdZRap4VPPHqJJ3NEs2cuHs5p0erH+iz6khB0qfgU8g7UuJkG88+fBMy23ZiU+nuHvekJeQ==
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-optional-chaining" "^7.8.0"

"@babel/plugin-proposal-optional-chaining@7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.7.4.tgz#3f04c2de1a942cbd3008324df8144b9cbc0ca0ba"
Expand All @@ -795,14 +803,6 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-chaining" "^7.7.4"

"@babel/plugin-proposal-optional-chaining@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.10.4.tgz#750f1255e930a1f82d8cdde45031f81a0d0adff7"
integrity sha512-ZIhQIEeavTgouyMSdZRap4VPPHqJJ3NEs2cuHs5p0erH+iz6khB0qfgU8g7UuJkG88+fBMy23ZiU+nuHvekJeQ==
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-optional-chaining" "^7.8.0"

"@babel/plugin-proposal-optional-chaining@^7.9.0":
version "7.9.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.9.0.tgz#31db16b154c39d6b8a645292472b98394c292a58"
Expand Down