Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

releases : use native URL class - #6678

Merged
jasonLaster merged 5 commits into
masterfrom
unknown repository
Aug 3, 2018
Merged

releases : use native URL class#6678
jasonLaster merged 5 commits into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jul 22, 2018

Copy link
Copy Markdown

Fixes Issue: #6645

Summary of Changes

  • Remove references to url in vendors.js and transform-mc.js
  • Use webpack externals to exclude it from the bundles

Test Plan

I'm not sure I am doing it right. Please add a comment if you see something is missing, I'll take it into account.

@jasonLaster

Copy link
Copy Markdown
Contributor

looks good, not sure if the build worked though - https://travis-ci.org/devtools-html/debugger.html/builds/406901630?utm_source=github_status&utm_medium=notification.

I can help take a look tomorrow

@darkwing

Copy link
Copy Markdown
Contributor

I just pushed a small update that adds a utility for "safely" using new URL(). I'm getting an odd error locally and want to see if Travis sees the same.

@darkwing

darkwing commented Jul 31, 2018

Copy link
Copy Markdown
Contributor

OK, so I figured out the build issues that's been blocking me:

https://github.com/devtools-html/devtools-core/blob/master/packages/devtools-launchpad/src/tools/mc/make-bundle.js

This file expects the export from webpack.config.js to be the webpack config, and this PR moves that to a property of what's returned, thus bin/copy-assets.js fails with:

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration misses the property 'entry'.
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
   -> The entry point(s) of the compilation.

@darkwing

darkwing commented Jul 31, 2018

Copy link
Copy Markdown
Contributor

I started making some changes here but still no dice:

https://gist.github.com/darkwing/1d15a4af7eadd9dcf8278b606cb79f57

Will get back to this later today or tomorrow.

Comment thread webpack.config.js Outdated
}
},
webpackConfig: buildConfig(envConfig)
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems weird. wouldn't we want to do externals in buildConfig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, it needs to be moved there, per my gist

Comment thread src/utils/url.js
try {
return new URL(url);
} catch (err) {
return defaultUrl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

at this point, we should know we have URL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using new URL(input) is dangerous, as it can throw an error which would brick out our panel. It's the same bug I fixed for NetMonitor. Unless we have a URL validation process, I think this is a decent bet

@darkwing darkwing Jul 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also comes to mind: #5102, which would avoid having to do the default URL fields

@jasonLaster jasonLaster Jul 31, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

got it. then maybe we should do something like new URL(<minimal viable url>) which would help us avoid the default URL fields

@jasonLaster

Copy link
Copy Markdown
Contributor

I was thinking about this and I bet we can do two things here:

  1. launchpad & panel just use new URL in some places
  2. jest in tests-setup do global.URL = require("url")

basically, we don't need any webpack stuff

Comment thread src/utils/url.js
export function parse(url: string): URL | object {
try {
const urlObj = new URL(url);
urlObj.path = urlObj.pathname + urlObj.search;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"path" isn't a native URL property -- I found this in URL's readme

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice find

@jasonLaster jasonLaster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great!

path: "/foo/bar/baz.js"
});
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, it'd still nice to make sure we don't parse too often.

perhaps we need to spy on ./utils/url parse. Jest has pretty good module mocking

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Normally when I do this kind of mocking I use jest.mock('module') and if I need to specifically mock one of its exports I can do const mockSpy = jest.fn(); jest.mock('module', () => ({ theExport: mockSpy }));

@jasonLaster

Copy link
Copy Markdown
Contributor

hmm, seeing some mochitest fails that might be worth digging in locally

@darkwing

darkwing commented Aug 1, 2018

Copy link
Copy Markdown
Contributor

@wldcordeiro @bomsy Do you have any ideas here for restoring Jest spy functionality? I've tried a variety of items here (https://stackoverflow.com/questions/40465047/how-can-i-mock-an-es6-module-import-using-jest) and none seem to work.

group: "file://"
};
} else if (host === null) {
} else if (!host) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The url lib returned null when info didn't exist, whereas the native URL returns "". TIL.

@jasonLaster
jasonLaster merged commit 4fb0660 into firefox-devtools:master Aug 3, 2018
jasonLaster pushed a commit that referenced this pull request Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants