Skip to content

Commit

Permalink
chore(exports): remove unused export from fetch-utils (#3463)
Browse files Browse the repository at this point in the history
This removes an unused export from src/compiler/sys/fetch/fetch-utils.ts
and inlines a function which was used in only one place. A JSDoc is
added for the function that is changed.
  • Loading branch information
alicewriteswrongs authored Jul 8, 2022
1 parent 2756107 commit 9b6d0ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
33 changes: 22 additions & 11 deletions src/compiler/sys/fetch/fetch-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import type * as d from '../../../declarations';
import { isCommonDirModuleFile, isTsFile, isTsxFile } from '../resolve/resolve-utils';
import { isFunction, normalizePath } from '@utils';

/**
* A fetch wrapper which dispatches to `sys.fetch` if present, and otherwise
* uses `global.fetch`.
*
* @param sys a compiler system object
* @param input a `RequestInfo` object
* @param init an optional `RequestInit` object
* @returns a Promise wrapping a response
*/
export const httpFetch = (sys: d.CompilerSystem, input: RequestInfo, init?: RequestInit): Promise<Response> => {
console.trace(input);
if (sys && isFunction(sys.fetch)) {
return sys.fetch(input, init);
}
Expand All @@ -13,11 +21,16 @@ export const httpFetch = (sys: d.CompilerSystem, input: RequestInfo, init?: Requ
export const packageVersions = new Map<string, string>();
export const known404Urls = new Set<string>();

export const getStencilRootUrl = (compilerExe: string) => new URL('../', compilerExe).href;

export const getStencilModuleUrl = (compilerExe: string, p: string) => {
p = normalizePath(p);
let parts = p.split('/');
/**
* Get the URL for a Stencil module given the path to the compiler
*
* @param compilerExe the path to the compiler executable
* @param path the path to the module or file in question
* @returns a URL for the file of interest
*/
export const getStencilModuleUrl = (compilerExe: string, path: string): string => {
path = normalizePath(path);
let parts = path.split('/');
const nmIndex = parts.lastIndexOf('node_modules');
if (nmIndex > -1 && nmIndex < parts.length - 1) {
parts = parts.slice(nmIndex + 1);
Expand All @@ -26,14 +39,12 @@ export const getStencilModuleUrl = (compilerExe: string, p: string) => {
} else {
parts = parts.slice(1);
}
p = parts.join('/');
path = parts.join('/');
}
return new URL('./' + p, getStencilRootUrl(compilerExe)).href;
const stencilRootUrl = new URL('../', compilerExe).href;
return new URL('./' + path, stencilRootUrl).href;
};

export const getStencilInternalDtsUrl = (compilerExe: string) =>
getStencilModuleUrl(compilerExe, 'internal/index.d.ts');

export const getCommonDirUrl = (
sys: d.CompilerSystem,
pkgVersions: Map<string, string>,
Expand Down
9 changes: 1 addition & 8 deletions src/compiler/sys/fetch/tests/fetch-module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as d from '../../../../declarations';
import { getNodeModuleFetchUrl, getStencilModuleUrl, getStencilRootUrl, skipFilePathFetch } from '../fetch-utils';
import { getNodeModuleFetchUrl, getStencilModuleUrl, skipFilePathFetch } from '../fetch-utils';
import { createSystem } from '../../stencil-sys';

describe('fetch module', () => {
Expand All @@ -9,13 +9,6 @@ describe('fetch module', () => {
compilerExe = 'http://localhost:3333/@stencil/core/compiler/stencil.js';
});

it('getStencilRootUrl', () => {
expect(getStencilRootUrl(compilerExe)).toBe('http://localhost:3333/@stencil/core/');

compilerExe = 'https://cdn.stenciljs.com/npm/@stencil/[email protected]/compiler/stencil.js';
expect(getStencilRootUrl(compilerExe)).toBe('https://cdn.stenciljs.com/npm/@stencil/[email protected]/');
});

describe('getStencilModulePath', () => {
it('cdn w/ version w/out node_module prefix', () => {
compilerExe = 'https://cdn.stenciljs.com/npm/@stencil/[email protected]/compiler/stencil.js';
Expand Down

0 comments on commit 9b6d0ea

Please sign in to comment.