Skip to content

Commit bea5ebd

Browse files
committed
feat: minor path updates
1 parent 0a0ec68 commit bea5ebd

File tree

3 files changed

+5
-43
lines changed

3 files changed

+5
-43
lines changed

src/__tests__/utils.test.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ImportMap } from "@jspm/import-map";
44

55
import {
66
constructPath,
7-
constructUrlPath,
87
constructImportMap,
98
createCacheMap,
109
parseNodeModuleCachePath,
@@ -36,7 +35,7 @@ jest.mock("@jspm/import-map", () => {
3635
});
3736

3837
test("constructPath minimal", () => {
39-
const result = constructPath("foo");
38+
const result = constructPath("foo", './');
4039
expect(result).toStrictEqual("./foo");
4140
});
4241

@@ -45,22 +44,6 @@ test("constructPath with root", () => {
4544
expect(result).toStrictEqual("./bar/foo");
4645
});
4746

48-
test("constructUrlPath minimal", () => {
49-
const result = constructUrlPath();
50-
expect(result).toStrictEqual("");
51-
});
52-
53-
test("constructUrlPath with base url", () => {
54-
const result = constructUrlPath("bar.txt", "file:///bin/foo/biz");
55-
expect(result).toStrictEqual("/bin/foo/bar.txt");
56-
});
57-
58-
test("constructUrlPath with base url and no debug", () => {
59-
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
60-
constructUrlPath("bar.txt", "bin/foo/biz");
61-
expect(spy).toHaveBeenCalled();
62-
});
63-
6447
test("constructImportMap minimal", () => {
6548
const result = constructImportMap();
6649
expect(result).toBeInstanceOf(ImportMap);
@@ -81,7 +64,7 @@ test("constructImportMap should return ImportMap instance if path exists", () =>
8164
test("constructImportMap should use cwd if no path provided", () => {
8265
constructImportMap();
8366
expect(ImportMap).toHaveBeenCalledWith({
84-
rootUrl: process.cwd(),
67+
rootUrl: `file://${process.cwd()}`,
8568
map: {},
8669
});
8770
});
@@ -101,7 +84,7 @@ test("createCacheMap.get should return cachePath if defined", () => {
10184

10285
test("createCacheMap.get should return undefined if cachePath is not defined", () => {
10386
const cacheMap = createCacheMap();
104-
expect(cacheMap.get("foo")).toBeUndefined();
87+
expect(cacheMap.get("foo")).toEqual("foo");
10588
});
10689

10790
test("createCacheMap.set should set cachePath and modulePath", () => {

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IS_DEBUGGING } from "src/constants";
2-
import { constructPath, constructUrlPath, createCacheMap } from "src/utils";
2+
import { constructPath, createCacheMap } from "src/utils";
33

44
/**
55
* ******************************************************
@@ -12,5 +12,5 @@ import { constructPath, constructUrlPath, createCacheMap } from "src/utils";
1212
*/
1313
const root = process.cwd();
1414
export const cacheMap = createCacheMap(IS_DEBUGGING);
15-
export const cache = constructPath('.cache', root);
15+
export const cache = constructPath(".cache", root);
1616
export const nodeImportMapPath = constructPath("node.importmap", root);

src/utils.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
22
import { dirname, join } from "node:path";
3-
import { fileURLToPath } from "node:url";
43
import fetch from "node-fetch";
54
import { ImportMap } from "@jspm/import-map";
65
import { CreateCacheMapFactory } from "src/types";
@@ -33,25 +32,6 @@ const cwd = process.cwd();
3332
export const constructPath = (path: string, root = cwd) => {
3433
const out = join(root, path);
3534
return out;
36-
}
37-
38-
/**
39-
* constructUrlPath
40-
* @description a convenience function to construct a url path
41-
* @param {string} file
42-
* @param {string} url
43-
* @param {boolean} debug
44-
* @returns {string}
45-
*/
46-
export const constructUrlPath = (file = '', url: string = cwd) => {
47-
try {
48-
const path = new URL(`file://${url}/${file}`);
49-
const out = fileURLToPath(path.href);
50-
return out;
51-
} catch (err) {
52-
log.error("constructUrlPath:error:", { err });
53-
return "";
54-
}
5535
};
5636

5737
/**
@@ -118,7 +98,6 @@ export const parseNodeModuleCachePath = async (modulePath: string, cachePath: st
11898
try {
11999
if (existsSync(cachePath)) return cachePath;
120100
const resp = await fetch(modulePath);
121-
console.log({ resp });
122101
if (!resp.ok) throw Error(`404: Module not found: ${modulePath}`);
123102
const nodeModuleCode = await resp.text();
124103
const dirPath = dirname(cachePath);

0 commit comments

Comments
 (0)