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

Remove use of momentjs #1652

Merged
merged 5 commits into from Sep 17, 2019
Merged

Remove use of momentjs #1652

merged 5 commits into from Sep 17, 2019

Conversation

lcampos
Copy link
Contributor

@lcampos lcampos commented Sep 17, 2019

What does this PR do?

This PR replaces momentjs by using the native locale methods and other date formatting utilities. This is part of the changes needed to reduce the size of the extensions. By removing momentjs, we remove a dependency on a module that is not tree-shakeable.

What issues does this PR fix or reference?

@W-6587405@

'YYYYMMDDhhmmss'
);
const localUTCDate = new Date(response.data.startTime);
const date = getYYYYMMddHHmmssDateFormat(localUTCDate);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used in naming the debug log that gets downloaded when running SFDX: Get Debug Logs

@@ -135,16 +137,17 @@ export class LogFileSelector
if (logInfos.length > 0) {
const logItems = logInfos.map(logInfo => {
const icon = '$(file-text) ';
const localUTCDate = new Date(logInfo.StartTime);
const localDateFormatted = localUTCDate.toLocaleDateString(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used for listing the available debug log records when running SFDX: Get Debug Logs
debug_log_list

@@ -5,7 +5,10 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as moment from 'moment';
import {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes on this file control the formatting of time and date showed in the footer text added after running SFDX: Turn On Apex Debug Log for Replay Debuger
replay_debugger_footer

@codecov
Copy link

codecov bot commented Sep 17, 2019

Codecov Report

Merging #1652 into develop will increase coverage by 12.38%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #1652       +/-   ##
============================================
+ Coverage    71.57%   83.95%   +12.38%     
============================================
  Files          190       68      -122     
  Lines         7373     3098     -4275     
  Branches       842      294      -548     
============================================
- Hits          5277     2601     -2676     
+ Misses        1920      439     -1481     
+ Partials       176       58      -118
Impacted Files Coverage Δ
.../src/commands/templates/forceLightningAppCreate.ts
...s/salesforcedx-vscode-core/src/orgBrowser/index.ts
.../salesforcedx-vscode-core/src/diagnostics/index.ts
...ommands/templates/forceLightningInterfaceCreate.ts
...pex/src/languageClientUtils/languageClientUtils.ts
...orcedx-vscode-core/src/commands/templates/index.ts
...vscode-core/src/traceflag/developerLogTraceFlag.ts
...x-replay-debugger/test/integration/goldFileUtil.ts
...forcedx-vscode-core/src/commands/forceOrgCreate.ts
...-vscode-core/src/decorators/demo-mode-decorator.ts
... and 110 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 15b27df...e227a36. Read the comment docs.

expect(doubleDigit).to.equal('09');
});

it('Should return a the same two character string when provided a double digit number', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in test description

Copy link
Collaborator

@AnanyaJha AnanyaJha left a comment

Choose a reason for hiding this comment

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

Changes look good! What made the momentjs module not be compatible with tree-shaking?

@lcampos
Copy link
Contributor Author

lcampos commented Sep 17, 2019

Changes look good! What made the momentjs module not be compatible with tree-shaking?

@AnanyaJha this thread (moment/moment#2373) goes a bit more in depth into the challenges of breaking it into smaller pieces using tools like webpack but it boils down to the way the library is structured.

@lcampos lcampos merged commit 8a4af5f into develop Sep 17, 2019
@lcampos lcampos deleted the lcampos/remove-momentjs branch September 17, 2019 17:06
optionYYYYMMddHHmmss
);

const dateTimeFormatRegex = /([0-9]{2})(\/)([0-9]{2})(\/)([0-9]{4})(\,)\s([0-9])(:)([0-9]{2})(:)([0-9]{2})\s(AM|PM)/;
Copy link
Contributor

Choose a reason for hiding this comment

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

@lcampos This test fails locally for me because the conversion from utc to mst causes the time stamp to be 10:34 instead of 9:34. The regex needs to be updated to:
([0-9]{2})(/)([0-9]{2})(/)([0-9]{4})(,)\s([0-9]{1,2})(:)([0-9]{2})(:)([0-9]{2})\s(AM|PM)

optionHHmm
);

const timeFormatRegex = /([0-9])(:)([0-9]{2})\s(AM|PM)/;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we update the last example, we should really update this one to ([0-9]{1,2})(:)([0-9]{2})\s(AM|PM). This one passes for me locally, but only because we beginning the regex at the start of the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, I'll open a follow up PR to take care of these failures.

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.

None yet

3 participants