Skip to content

Conversation

@caisq
Copy link
Contributor

@caisq caisq commented Mar 14, 2020

  • Motivation for features / changes

    • DebuggerV2 will feature a source-code viewing component. As we've discussed, we will use monaco-editor for this purpose.
  • Technical description of changes

    • Add filegroup_external blocks to third_party/js.bzl and the consuming BUILD targets to tensorboard/components/tf_imports/BUILD for:
      • monaco-editor-core (core editor) assets: including .js, .css and .ttf files
      • monaco-languages (language parser and syntax-highlighter) assets: .js files
      • require.js: which is needed for dynamic loading of monaco-editor and monaco-languages assets
  • Detailed steps to verify changes work correctly (as executed by you)

    • Added a unit test for the loadMonaco() method from load_monaco_shim.ts by using fake objects.
  • Alternate designs / implementations considered

    • Discussed alternatives during internal meeting
    • Pulling in monaco-editor instead of monaco-editor-core
      • Con: Language definition files for 30+ languages will end up being downloaded dynamically. We need only Python support for the V1 of DebuggerV2.

@caisq caisq changed the title Dbg2 source code monaco require 2 [DebuggerV2] Add shim for loadMonaco() method and supporting external libraries Mar 14, 2020
@caisq caisq requested a review from stephanwlee March 16, 2020 14:13
@caisq caisq marked this pull request as ready for review March 16, 2020 14:13
Copy link
Contributor

@stephanwlee stephanwlee left a 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"],
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@caisq caisq left a 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:

  1. 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.
  2. I added proper strip_prefix args 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".
  3. I like your requireP function. 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:

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"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@caisq caisq requested a review from stephanwlee March 17, 2020 14:12
*
* @param paths
*/
async function requireAsPromise(paths: string[]): Promise<void> {
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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
});

Copy link
Contributor Author

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();
Copy link
Contributor

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

Copy link
Contributor Author

@caisq caisq Mar 17, 2020

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) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove fit please

Copy link
Contributor Author

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.

Copy link
Contributor Author

@caisq caisq left a 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> {
Copy link
Contributor Author

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();
Copy link
Contributor Author

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) => {
Copy link
Contributor Author

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();
Copy link
Contributor Author

@caisq caisq Mar 17, 2020

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.

@caisq caisq requested a review from stephanwlee March 17, 2020 19:24
@caisq
Copy link
Contributor Author

caisq commented Mar 17, 2020

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.

@caisq caisq merged commit 5b88e94 into tensorflow:master Mar 18, 2020
caisq added a commit that referenced this pull request Mar 18, 2020
…external libraries (#3374)" (#3396)

This reverts commit 5b88e94.

* Motivation for features / changes
  * Sync'ing requires more work. In order to avoid blocking other people, let's roll this back first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants