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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): prevent renaming global providers and modules in the repl #9720

Merged
merged 4 commits into from Jun 15, 2022

Conversation

micalevisk
Copy link
Member

@micalevisk micalevisk commented Jun 2, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

image

and I believe the above shouldn't be allowed as there's no way (I guess) to recover those classes references

What is the new behavior?

image

mark those injected classes as a read-only properties on replServer.context obj. There's no need to use globalThis anymore 馃帀 as of now ReplContext isn't aware of the server context that it will be used. Instead, replServer must pollute their global scope

The goal here is to improve UX. Now users couldn't change those references accidentally

Does this PR introduce a breaking change?

  • Yes
  • No

@micalevisk micalevisk changed the title fix(core): prevents renaming global providers and modules in the repl fix(core): prevent renaming global providers and modules in the repl Jun 2, 2022
by marking them as a read-only properties of `globalThis` obj
@micalevisk
Copy link
Member Author

micalevisk commented Jun 3, 2022

I'm thinking if is't possible to implement this while keeping the test suite healthy as they need to touch globalThis 馃 I believe we would need to avoid changing globalThis if we want to make this testable.

image

(due to those delete globalThis lines)

Close this if you know how to handle that

@coveralls
Copy link

coveralls commented Jun 3, 2022

Pull Request Test Coverage Report for Build 60be6c3c-e300-4424-82bf-b2b719b4098f

  • 16 of 17 (94.12%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.03%) to 94.096%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/core/repl/repl-context.ts 16 17 94.12%
Files with Coverage Reduction New Missed Lines %
packages/core/repl/repl-context.ts 1 85.0%
Totals Coverage Status
Change from base Build 4a8a1b6f-764e-4b26-b38f-67999333e1a0: -0.03%
Covered Lines: 5897
Relevant Lines: 6267

馃挍 - Coveralls

@micalevisk micalevisk force-pushed the feat/repl-fix-injections branch 2 times, most recently from bf25d6b to ed766bb Compare June 4, 2022 22:44
import { ReplContext } from './repl-context';
import { ReplLogger } from './repl-logger';

function copyInto(target, source): void {
Copy link
Member Author

@micalevisk micalevisk Jun 4, 2022

Choose a reason for hiding this comment

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

we need this utility because Object.assign won't copy property's descriptors

I could extract this to another file

@kamilmysliwiec kamilmysliwiec merged commit 6843117 into nestjs:feat/repl Jun 15, 2022
@kamilmysliwiec
Copy link
Member

LGTM

@kamilmysliwiec
Copy link
Member

Great job @micalevisk!

@micalevisk micalevisk deleted the feat/repl-fix-injections branch June 15, 2022 12:49
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

4 participants