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

Ensure generation and related utils are sync #9692

Merged
merged 1 commit into from Jul 6, 2021

Conversation

pgrzesik
Copy link
Contributor

@pgrzesik pgrzesik commented Jul 5, 2021

Discussed internally, the reason behind this change is to ensure that both storeLocally and generatePayload utils are sync, which makes them safe to be executed as a part of process.on handler without interfering with asynchronously running operations in the backgorund.

Related to: #9367

@codecov
Copy link

codecov bot commented Jul 5, 2021

Codecov Report

Merging #9692 (dbe4f78) into master (cc24bc2) will increase coverage by 0.01%.
The diff coverage is 87.64%.

❗ Current head dbe4f78 differs from pull request most recent head b19a7ff. Consider uploading reports for the commit b19a7ff to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9692      +/-   ##
==========================================
+ Coverage   86.11%   86.13%   +0.01%     
==========================================
  Files         327      327              
  Lines       12512    12548      +36     
==========================================
+ Hits        10775    10808      +33     
- Misses       1737     1740       +3     
Impacted Files Coverage Δ
lib/classes/PluginManager.js 95.13% <0.00%> (ø)
lib/cli/commands-schema/aws-service.js 100.00% <ø> (ø)
lib/configSchema.js 100.00% <ø> (ø)
scripts/postinstall.js 0.00% <0.00%> (ø)
scripts/serverless.js 52.78% <66.66%> (+0.53%) ⬆️
lib/cli/handle-error.js 87.91% <85.71%> (+0.27%) ⬆️
lib/utils/npmPackage/isGlobal.js 90.90% <87.50%> (ø)
lib/utils/logDeprecation.js 95.58% <90.90%> (-4.42%) ⬇️
lib/utils/telemetry/generatePayload.js 90.98% <92.30%> (ø)
lib/Serverless.js 71.84% <100.00%> (+0.55%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc24bc2...b19a7ff. Read the comment docs.

@pgrzesik pgrzesik force-pushed the refactor-telemetry-generation-to-sync branch from 1735803 to 9dec03c Compare July 5, 2021 20:21
@pgrzesik pgrzesik changed the title [WIP] Ensure generation and related utils are sync Ensure generation and related utils are sync Jul 5, 2021
@pgrzesik pgrzesik requested a review from medikoo July 5, 2021 20:37
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

That looks great @pgrzesik ! I've spotted just few omissions

module.exports = memoizee(() => {
const npmPackagesRoot = (() => {
try {
return String(spawnSync('npm', ['root', '-g']).stdoutBuffer).trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

In spawnSync it's stdout that's stdout buffer not stdoutBuffer (in child-process-ext/spawn, stdout is a stream, while stdoutBuffer is a buffer)

https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch, thank you

@@ -22,7 +22,7 @@ const isNpmGlobalPackage = require('../lib/utils/npmPackage/isGlobal');
messageTokens.push('To start your first project run “serverless”.');
}

if ((isStandaloneExecutable && !isWindows) || (await isNpmGlobalPackage())) {
if ((isStandaloneExecutable && !isWindows) || isNpmGlobalPackage()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I see correctly, we can drop async func wrapper now

Copy link
Contributor

Choose a reason for hiding this comment

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

This wrapper was introduced only for sake of using await, so now can be dropped entirely

@@ -697,14 +697,14 @@ const processSpanPromise = (async () => {
hasTelemetryBeenReported = true;
if (!isTelemetryDisabled && !isHelpRequest && serverless.isTelemetryReportedExternally) {
await storeTelemetryLocally({
Copy link
Contributor

Choose a reason for hiding this comment

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

This await can also be dropped

@pgrzesik pgrzesik force-pushed the refactor-telemetry-generation-to-sync branch from 9dec03c to a021ba7 Compare July 6, 2021 08:10
@pgrzesik pgrzesik requested a review from medikoo July 6, 2021 08:18
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks great. I've noticed just one minor style leftover

@@ -22,7 +22,7 @@ const isNpmGlobalPackage = require('../lib/utils/npmPackage/isGlobal');
messageTokens.push('To start your first project run “serverless”.');
}

if ((isStandaloneExecutable && !isWindows) || (await isNpmGlobalPackage())) {
if ((isStandaloneExecutable && !isWindows) || isNpmGlobalPackage()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This wrapper was introduced only for sake of using await, so now can be dropped entirely

@pgrzesik pgrzesik force-pushed the refactor-telemetry-generation-to-sync branch from a021ba7 to b19a7ff Compare July 6, 2021 08:34
@pgrzesik pgrzesik requested a review from medikoo July 6, 2021 08:40
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@pgrzesik pgrzesik merged commit e65199c into master Jul 6, 2021
@pgrzesik pgrzesik deleted the refactor-telemetry-generation-to-sync branch July 6, 2021 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants