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

deps: update jsonld to latest #12257

Merged
merged 1 commit into from
Mar 18, 2021
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
14 changes: 7 additions & 7 deletions lighthouse-core/lib/sd-validation/json-expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ const SCHEMA_ORG_HOST = 'schema.org';
* Custom loader that prevents network calls and allows us to return local version of the
* schema.org document
* @param {string} schemaUrl
* @param {(err: null|Error, value?: any) => void} callback
* @return {Promise<import('jsonld').RemoteDocument>}
*/
function documentLoader(schemaUrl, callback) {
async function documentLoader(schemaUrl) {
let urlObj = null;

try {
// Give a dummy base URL so relative URLs will be considered valid.
urlObj = new URL(schemaUrl, 'http://example.com');
} catch (e) {
return callback(new Error('Error parsing URL: ' + schemaUrl), undefined);
throw new Error('Error parsing URL: ' + schemaUrl);
}

if (urlObj.host === SCHEMA_ORG_HOST && urlObj.pathname === '/') {
callback(null, {
return {
document: schemaOrgContext,
});
};
} else {
// We only process schema.org, for other schemas we return an empty object
callback(null, {
return {
document: {},
});
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/lib/sd-validation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('JSON-LD validation', () => {
const errors = await validateJSONLD(`{
"@context": {
"image": {
"@id": "@error"
"@id": "/error/"
Copy link
Member Author

@brendankenny brendankenny Mar 18, 2021

Choose a reason for hiding this comment

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

'@error' here became a warning, so this uses a different invalid value

}
}
}`);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
"intl-pluralrules": "^1.0.3",
"jpeg-js": "^0.4.1",
"js-library-detector": "^6.4.0",
"jsonld": "^1.5.0",
"jsonlint-mod": "^1.7.5",
"jsonld": "^4.0.1",
"jsonlint-mod": "^1.7.6",
Copy link
Member Author

Choose a reason for hiding this comment

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

why not

"lighthouse-logger": "^1.2.0",
"lighthouse-stack-packs": "^1.4.0",
"lodash.get": "^4.4.2",
Expand Down
10 changes: 7 additions & 3 deletions types/jsonld/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
*/

declare module 'jsonld' {
type CallbackFn = (err: null|Error, result?: any) => void
interface RemoteDocument {
contextUrl?: string;
documentUrl?: string;
document: unknown;
}

interface JsonldOptions {
documentLoader: (url: string, callback: CallbackFn) => void
documentLoader: (url: string) => Promise<RemoteDocument>;
}

export function expand(object: any, options: JsonldOptions): Promise<any>;
export function expand(object: unknown, options: JsonldOptions): Promise<any>;
Copy link
Member Author

Choose a reason for hiding this comment

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

there are definitelytyped types for jsonld now, but expand() still has the old callback-based documentLoader, so easier to still just maintain types for our own tiny corner of the library. It would be nice to eventually switch and not rely on LH.StructuredData.ExpandedSchemaRepresentation being the source of truth, though.

}
Loading