Skip to content

Commit

Permalink
deps: update jsonld to latest (#12257)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Mar 18, 2021
1 parent b571ab6 commit 8e32e49
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 85 deletions.
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/"
}
}
}`);
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",
"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>;
}
Loading

0 comments on commit 8e32e49

Please sign in to comment.