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

Framework: Use WHATWG URL in place of legacy url module #19823

Merged
merged 4 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { parse, resolve } from 'url';
gziolo marked this conversation as resolved.
Show resolved Hide resolved

/**
* Return `true` if the given path is http/https.
*
Expand Down Expand Up @@ -62,10 +57,7 @@ function isValidURL( meta ) {
* @return {string} the full path to the file
*/
function getResourcePath( str, baseURL ) {
const pathname = parse( str ).pathname;
const filePath = resolve( baseURL, pathname );

return filePath;
return new URL( str, baseURL ).toString();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"lodash": "^4.17.15",
"memize": "^1.0.5",
"moment": "^2.22.1",
"tinycolor2": "^1.4.1",
"url": "^0.11.0"
"tinycolor2": "^1.4.1"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getPhotoHtml } from './util';
/**
* External dependencies
*/
import { parse } from 'url';
import { includes } from 'lodash';
import classnames from 'classnames/dedupe';

Expand Down Expand Up @@ -69,7 +68,7 @@ class EmbedPreview extends Component {
const { interactive } = this.state;

const html = 'photo' === type ? getPhotoHtml( preview ) : preview.html;
const parsedHost = parse( url ).host.split( '.' );
const parsedHost = new URL( url ).host.split( '.' );
aduth marked this conversation as resolved.
Show resolved Hide resolved
const parsedHostBaseUrl = parsedHost
.splice( parsedHost.length - 2, parsedHost.length - 1 )
.join( '.' );
Expand Down
1 change: 0 additions & 1 deletion packages/e2e-test-utils/src/create-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { join } from 'path';
import { URL } from 'url';

/**
* Internal dependencies
Expand Down
5 changes: 0 additions & 5 deletions packages/e2e-test-utils/src/is-current-url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { URL } from 'url';

/**
* Internal dependencies
*/
Expand Down
7 changes: 3 additions & 4 deletions packages/e2e-tests/specs/editor/various/preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { last } from 'lodash';
import { parse } from 'url';

/**
* WordPress dependencies
Expand Down Expand Up @@ -187,9 +186,9 @@ describe( 'Preview', () => {
expect( previewTitle ).toBe( 'Hello World! And more.' );

// Published preview URL should include ID and nonce parameters.
const { query } = parse( previewPage.url(), true );
expect( query ).toHaveProperty( 'preview_id' );
expect( query ).toHaveProperty( 'preview_nonce' );
const { searchParams } = new URL( previewPage.url() );
aduth marked this conversation as resolved.
Show resolved Hide resolved
expect( searchParams.has( 'preview_id' ) ).toBe( true );
expect( searchParams.has( 'preview_nonce' ) ).toBe( true );

// Return to editor. Previewing already-autosaved preview tab should
// reuse the opened tab, skipping interstitial. This resolves an edge
Expand Down