Skip to content

build(all): use es2019 target to support on Node12 #925

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

Merged
merged 15 commits into from
Jun 1, 2022

Conversation

ijemmy
Copy link
Contributor

@ijemmy ijemmy commented May 31, 2022

Description of your changes

See issue #899 on the bug description.

In target es2020, it support ?. so the TS transpiler will not transform this syntax.

For example:

//in target 2020
subsegment?.close();

will be:

//in target 2019
subsegment === null || subsegment === void 0 ? void 0 : subsegment.close();

Previously, we have been building our packages on target es2020. When customers consume our modules, it will still have ?.. If customers use NodeJS12 (which is es2019), it will throw an error SyntaxError: Unexpected token '.'. The . is the second character of ?. syntax.

To fix this, we change all of the target to 2019. However, this cause a lot of breaks in our current code.

  1. Branch coverage will drop as ?. is broken into a conditional statement. We need to add new test cases or tell TS that the value does exist by adding !. This is really case by case as the value cannot really be undefined in some case.
  2. NodeJS12 doesn't have crypto.randomUUID that we use in e2e tests. So we have to add uuid as a devDependency

Important note Notice that one of the pr-lint-and-test fails. This is intentional. I added the additional checks on NodeJS12 and NodeJS14. (We tested only on Node16). The failing one is Node12, and it fails on examples/sam package. This package uses the npm published version of our library. And it really should fail as the currently published library is target 2020. Once we publish a new version, this should be fixed automatically.

How to verify this change

Switch to NodeJS 12 and run all tests

nvm use lts/erbium #NodeJS 12 LTS
npm install # There will be some warnings about CDK only support NodeJS14+. But everything still works.
npm run lerna-test

# Switch AWS profile to run e2e test
npm run lerna-test:e2e

Related issues, RFCs

#899

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published in downstream module
  • The PR title follows the conventional commit semantics

Breaking change checklist

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines +18 to +25
const createCaptureAsyncFuncMock = function(provider: ProviderServiceInterface): CaptureAsyncFuncMock {
return jest.spyOn(provider, 'captureAsyncFunc')
.mockImplementation((methodName, callBackFn) => {
const subsegment = new Subsegment(`### ${methodName}`);
jest.spyOn(subsegment, 'flush').mockImplementation(() => null);
callBackFn(subsegment);
});
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to @dreamorosi

I found that we missed the case that the subsegment IS defined in our test. So I add this to get coverage back to 100%

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note and good spot.

Comment on lines +10 to 20
strategy:
matrix:
version: [12, 14, 16]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: "Use NodeJS 16"
- name: "Use NodeJS"
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: ${{ matrix.version }}
- name: Install [email protected]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unit tests fail in NodeJS12, so I make use of matrix strategy here to make sure that we don't introduce any issue later.

@ijemmy
Copy link
Contributor Author

ijemmy commented May 31, 2022

@ijemmy ijemmy marked this pull request as ready for review May 31, 2022 18:26
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

Thanks for diving deep into this, I really really appreciate it.

Copy link
Contributor

@flochaz flochaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job !

@flochaz
Copy link
Contributor

flochaz commented Jun 1, 2022

node 12 tests failing :/

@ijemmy
Copy link
Contributor Author

ijemmy commented Jun 1, 2022

node 12 tests failing :/

@flochaz It should fail until we release a new version that supports node12.

@flochaz
Copy link
Contributor

flochaz commented Jun 1, 2022

node 12 tests failing :/

@flochaz It should fail until we release a new version that supports node12.

Ah yeah true :)

@ijemmy ijemmy merged commit 8e2551e into main Jun 1, 2022
@ijemmy ijemmy deleted the ijemmy/build-on-all-node-versions branch June 1, 2022 13:41
@ijemmy ijemmy restored the ijemmy/build-on-all-node-versions branch June 1, 2022 13:42
@ijemmy ijemmy deleted the ijemmy/build-on-all-node-versions branch June 1, 2022 13:42
@dreamorosi dreamorosi mentioned this pull request Jun 2, 2022
8 tasks
dreamorosi pushed a commit that referenced this pull request Aug 2, 2022
Switching to target 2019 to support Node12

Previously, we have been building our packages on target es2020. When customers consume our modules, it will still have ?.. If customers use NodeJS12 (which is es2019), it will throw an error SyntaxError: Unexpected token '.'. The . is the second character of ?. syntax.

To fix this, we change all of the target to 2019. However, this cause a lot of breaks in our current code.

1. Branch coverage will drop as ?. is broken into a conditional statement. We need to add new test cases or tell TS that the value does exist by adding !. This is really case by case as the value cannot really be undefined in some case.
2. NodeJS12 doesn't have crypto.randomUUID that we use in e2e tests. So we have to add uuid as a devDependency

This commit also adds the additional checks on NodeJS12 and NodeJS14. (We tested only on Node16). The failing one is Node12, and it fails on examples/sam package. This package uses the npm published version of our library. And it really should fail as the currently published library is target 2020. Once we publish a new version, this should be fixed automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: lib not working for node12 if not bundled with tools like esbuild
3 participants