Skip to content

Commit

Permalink
Remove deprecation warning on old CJS context URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Mar 5, 2024
1 parent fb353e1 commit b3160e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 0 additions & 7 deletions lib/rdf/PrefetchedDocumentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export class PrefetchedDocumentLoader extends FetchDocumentLoader {
}

public async load(url: string): Promise<IJsonLdContext> {
// Warn on deprecated context usage
// eslint-disable-next-line max-len
const match = PrefetchedDocumentLoader.CONTEXT_PATTERN.exec(url);
if (this.logger && match && Number.parseInt(match[1], 10) < PrefetchedDocumentLoader.CJS_MAJOR_VERSION) {
this.logger.warn(`Detected deprecated context URL '${url}'${this.path ? ` in ${this.path}` : ''}. Prefer using version '^${PrefetchedDocumentLoader.CJS_MAJOR_VERSION}.0.0' instead.`);
}

// Load prefetched contexts
if (url in this.contexts) {
return this.contexts[url];
Expand Down
6 changes: 3 additions & 3 deletions test/unit/rdf/PrefetchedDocumentLoader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('PrefetchedDocumentLoader', () => {
});
expect(await loader.load(`https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld`))
.toEqual(JSON.parse(fs.readFileSync(`${__dirname}/../../../components/context.jsonld`, 'utf8')));
expect(logger.warn).toHaveBeenCalledWith(`Detected deprecated context URL 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld' in PATH. Prefer using version '^${PrefetchedDocumentLoader.CJS_MAJOR_VERSION}.0.0' instead.`);
expect(logger.warn).not.toHaveBeenCalled();
});

it('for the built-in prefetched 4.0.0 context that is deprecated with a logger', async() => {
Expand All @@ -60,7 +60,7 @@ describe('PrefetchedDocumentLoader', () => {
});
expect(await loader.load(`https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld`))
.toEqual(JSON.parse(fs.readFileSync(`${__dirname}/../../../components/context.jsonld`, 'utf8')));
expect(logger.warn).toHaveBeenCalledWith(`Detected deprecated context URL 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld' in PATH. Prefer using version '^${PrefetchedDocumentLoader.CJS_MAJOR_VERSION}.0.0' instead.`);
expect(logger.warn).not.toHaveBeenCalled();
});

it('for the built-in prefetched latest context that is not deprecated with a logger', async() => {
Expand All @@ -87,7 +87,7 @@ describe('PrefetchedDocumentLoader', () => {
});
expect(await loader.load(`https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld`))
.toEqual(JSON.parse(fs.readFileSync(`${__dirname}/../../../components/context.jsonld`, 'utf8')));
expect(logger.warn).toHaveBeenCalledWith(`Detected deprecated context URL 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld'. Prefer using version '^${PrefetchedDocumentLoader.CJS_MAJOR_VERSION}.0.0' instead.`);
expect(logger.warn).not.toHaveBeenCalled();
});

it('for a non-prefetched context', async() => {
Expand Down

0 comments on commit b3160e5

Please sign in to comment.