-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[DebuggerV2] Add shim for loadMonaco() method and supporting external libraries #3374
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
[DebuggerV2] Add shim for loadMonaco() method and supporting external libraries #3374
Conversation
stephanwlee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent about 5 hours thinking I could get everything working via cjs using rollup but it seems to be a little bit involved than that. I know I can get everything to work if I tried but bazel wrapper around rollup makes it even more painful and it definitely is not worth the effort.
I do not have large objection to this approach anymore but can you consider https://github.com/caisq/tensorboard/pull/30? Also, can you show me how these packages will be actually used?
| "@com_microsoft_monaco_editor//:vs/editor/editor.main.nls.js", | ||
| ], | ||
| path = "/tf-imports", | ||
| visibility = ["//visibility:public"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this, and others, private please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
caisq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time investigating and playing with it and reaching a conclusion compatible with him. Thanks for sending caisq#30. I adopted your changes with the following changes:
- We do need the three files from monaco-languages (_.contribution.js, python.contribution.js and python.js) for Python syntax highlighting to work, as it turns out. So I added them.
- I added proper
strip_prefixargs to the tf_web_library targets that wrap around the three new npm packages, so that the web paths don't include strings like "node_moduels/requirejs". - I like your
requirePfunction. I renamed it to make it clearer and added a doc string to it.
The usage example can be seen in another branch of mine:
- https://github.com/caisq/tensorboard/blob/dbg2-source-code-monaco-require/tensorboard/webapp/index.html#L33
- https://github.com/caisq/tensorboard/blob/dbg2-source-code-monaco-require/tensorboard/webapp/BUILD#L114
- https://github.com/caisq/tensorboard/blob/dbg2-source-code-monaco-require/tensorboard/plugins/debugger_v2/tf_debugger_v2_plugin/views/stack_trace/stack_trace_container.ts#L65
As such, I've listed you as a co-author for this PR in the PR description.
Note that the pattern in the last link above is only for demo purposes. In an actual PR to be sent after this PR, I will create a separate ng component (SourceCodeComponent) to call loadMonaco() from.
| "@com_microsoft_monaco_editor//:vs/editor/editor.main.nls.js", | ||
| ], | ||
| path = "/tf-imports", | ||
| visibility = ["//visibility:public"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| * | ||
| * @param paths | ||
| */ | ||
| async function requireAsPromise(paths: string[]): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for async in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| let requireSpy: jasmine.Spy; | ||
| beforeEach(() => { | ||
| windowWithRequireAndMonaco.require = createFakeRequire(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper jasmine API?
spyOnProperty(window, 'require').and.returnValue({
theRequireMethodWithWeirdProperties
});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that and it didn't work, because window.require doesn't exist or have an accessor type.
| fit('rejects if require.js is unavailable', async (done) => { | ||
| delete windowWithRequireAndMonaco.require; | ||
| try { | ||
| await loadMonaco(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget which version of jasmine we are using but you should be able to use: toBeRejectedWithError https://jasmine.github.io/api/3.5/async-matchers.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking to use the same thing, but it turns out that the version of jasmine we're using (@bazel/jasmine, 0.32.2) doesn't have async matchers such as toBeRejected(), toBeRejectedWith() or toBeRejectedWithError(). I've added a TODO item here.
| expect(requireSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| fit('rejects if require.js is unavailable', async (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove fit please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. Sorry. Thanks for the catch.
caisq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| * | ||
| * @param paths | ||
| */ | ||
| async function requireAsPromise(paths: string[]): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| let requireSpy: jasmine.Spy; | ||
| beforeEach(() => { | ||
| windowWithRequireAndMonaco.require = createFakeRequire(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that and it didn't work, because window.require doesn't exist or have an accessor type.
| expect(requireSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| fit('rejects if require.js is unavailable', async (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. Sorry. Thanks for the catch.
| fit('rejects if require.js is unavailable', async (done) => { | ||
| delete windowWithRequireAndMonaco.require; | ||
| try { | ||
| await loadMonaco(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking to use the same thing, but it turns out that the version of jasmine we're using (@bazel/jasmine, 0.32.2) doesn't have async matchers such as toBeRejected(), toBeRejectedWith() or toBeRejectedWithError(). I've added a TODO item here.
|
Thanks, @stephanwlee . Note that I'll need to hold off merging this PR a little bit given that internal copybara change needs to happen before this PR is synced and because there is a parallel effort on the tbdev uploader side that requires fast sync'ing. |
Motivation for features / changes
Technical description of changes
filegroup_externalblocks to third_party/js.bzl and the consuming BUILD targets to tensorboard/components/tf_imports/BUILD for:Detailed steps to verify changes work correctly (as executed by you)
loadMonaco()method from load_monaco_shim.ts by using fake objects.Alternate designs / implementations considered