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(localize): do not expose NodeJS typings in $localize runtime code #38700

Conversation

petebacondarwin
Copy link
Member

A recent change to @angular/localize brought in the AbsoluteFsPath type
from the @angular/compiler-cli. But this brought along with it a reference
to NodeJS typings - specifically the FileSystem interface refers to the
Buffer type from NodeJS.

This affects compilation of @angular/localize code that will be run in
the browser - for example projects that reference loadTranslations().
The compilation breaks if the NodeJS typings are not included in the build.
Clearly it is not desirable to have these typings included when the project
is not targeting NodeJS.

This commit replaces references to the NodeJS Buffer type with Uint8Array,
which is available across all platforms and is actually the super-class of
Buffer.

Fixes #38692

A recent change to `@angular/localize` brought in the `AbsoluteFsPath` type
from the `@angular/compiler-cli`. But this brought along with it a reference
to NodeJS typings - specifically the `FileSystem` interface refers to the
`Buffer` type from NodeJS.

This affects compilation of `@angular/localize` code that will be run in
the browser - for example projects that reference `loadTranslations()`.
The compilation breaks if the NodeJS typings are not included in the build.
Clearly it is not desirable to have these typings included when the project
is not targeting NodeJS.

This commit replaces references to the NodeJS `Buffer` type with `Uint8Array`,
which is available across all platforms and is actually the super-class of
`Buffer`.

Fixes angular#38692
@petebacondarwin petebacondarwin added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer refactoring Issue that involves refactoring or code-cleanup area: i18n target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Sep 3, 2020
@ngbot ngbot bot added this to the needsTriage milestone Sep 3, 2020
@pullapprove pullapprove bot requested a review from alxhub September 3, 2020 19:25
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix @petebacondarwin 👍

Quick question: I believe there is a chance that similar situation may happen in the future (with Buffer or other types). I was thinking if we can somehow test (as a part of a separate PR) that everything works as expected without NodeJS typings available?

@petebacondarwin
Copy link
Member Author

@AndrewKushnir

I was thinking if we can somehow test (as a part of a separate PR) that everything works as expected without NodeJS typings available?

I was wondering if we could remove NodeJS typings from the file_system package altogether (i.e. via the Bazel.build file). This would be nice but of course we can't do that because of the NodeJsFileSystem which does indeed require NodeJS.

@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Sep 3, 2020

Presubmit.

@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Sep 3, 2020
@AndrewKushnir AndrewKushnir removed action: review The PR is still awaiting reviews from at least one requested reviewer action: presubmit The PR is in need of a google3 presubmit labels Sep 4, 2020
@AndrewKushnir
Copy link
Contributor

@petebacondarwin FYI presubmit went well, plz add the "merge" label if PR is ready to go and no additional changes are needed/planned. Thank you.

@petebacondarwin petebacondarwin added the action: merge The PR is ready for merge by the caretaker label Sep 4, 2020
atscott pushed a commit that referenced this pull request Sep 8, 2020
…#38700)

A recent change to `@angular/localize` brought in the `AbsoluteFsPath` type
from the `@angular/compiler-cli`. But this brought along with it a reference
to NodeJS typings - specifically the `FileSystem` interface refers to the
`Buffer` type from NodeJS.

This affects compilation of `@angular/localize` code that will be run in
the browser - for example projects that reference `loadTranslations()`.
The compilation breaks if the NodeJS typings are not included in the build.
Clearly it is not desirable to have these typings included when the project
is not targeting NodeJS.

This commit replaces references to the NodeJS `Buffer` type with `Uint8Array`,
which is available across all platforms and is actually the super-class of
`Buffer`.

Fixes #38692

PR Close #38700
@atscott atscott closed this in 2c4a98a Sep 8, 2020
@petebacondarwin petebacondarwin deleted the ngtsc-filesystem-refactor branch September 8, 2020 20:41
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: i18n cla: yes refactoring Issue that involves refactoring or code-cleanup target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loadTranslations from @angular/localize dependes on Node.js
5 participants