Skip to content

Commit ef02cef

Browse files
committed
fix: simplifies loader more
1 parent c9890b5 commit ef02cef

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/__tests__/loader.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jest.mock("src/config", () => {
5050
}
5151
});
5252

53-
const errorSpy = jest.spyOn(console, "error");
5453
const nextResolve = jest.fn();
5554
const specifier = "specifier";
5655
describe('loader', () => {

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { join } from 'node:path';
2-
import { fileURLToPath } from 'node:url';
1+
import { join } from "node:path";
2+
import { fileURLToPath } from "node:url";
33
/**
44
* ******************************************************
55
* CONFIG
@@ -10,6 +10,6 @@ import { fileURLToPath } from 'node:url';
1010
* ******************************************************
1111
*/
1212
export const root = fileURLToPath(`file://${process.cwd()}`);
13-
export const cacheMap = new Map()
13+
export const cacheMap = new Map();
1414
export const nodeImportMapPath = join(root, "node.importmap");
15-
export const cache = join(root, '.cache')
15+
export const cache = join(root, ".cache");

src/loader.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { join } from 'node:path';
1+
import { join } from "node:path";
22
import { parseUrlPkg } from "@jspm/generator";
33
import { cache, cacheMap, nodeImportMapPath } from "./config";
44
import { constructImportMap } from "./utils";
5-
import { parseNodeModuleCachePath } from './parser';
5+
import { parseNodeModuleCachePath } from "./parser";
66
import { IS_DEBUGGING } from "./constants";
77
import { logger } from "./logger";
88
import { Context, NextResolve } from "./types";
99

10-
1110
/**
1211
* ******************************************************
1312
* LOADER
@@ -23,7 +22,7 @@ import { Context, NextResolve } from "./types";
2322
* * https://nodejs.org/api/esm.html#esm_experimental_loaders
2423
* * https://github.com/nodejs/loaders-test
2524
* ******************************************************
26-
*/
25+
*/
2726

2827
const log = logger({ file: "loader" });
2928
log.setLogger(IS_DEBUGGING);
@@ -64,8 +63,10 @@ export const resolve = async (specifier: string, { parentURL }: Context, nextRes
6463
if (!moduleMetadata) return nextResolve(specifier);
6564

6665
// construct node module cache path
67-
const { pkg: { name, version } } = moduleMetadata;
68-
const moduleFile = modulePath.split("/").reverse()[0] || '';
66+
const {
67+
pkg: { name, version },
68+
} = moduleMetadata;
69+
const moduleFile = modulePath.split("/").reverse()[0] || "";
6970
const nodeModuleCachePath = join(cache, `${name}@${version}`, moduleFile);
7071
cacheMap.set(`file://${nodeModuleCachePath}`, modulePath);
7172
const parsedNodeModuleCachePath = await parseNodeModuleCachePath(modulePath, nodeModuleCachePath);

src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync, writeFileSync } from "node:fs";
22
import fetch from "node-fetch";
3-
import { ensureDirSync } from 'src/utils';
3+
import { ensureDirSync } from "src/utils";
44
import { logger } from "src/logger";
55

66
const log = logger({ file: "utils" });

src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ import { ImportMap } from "@jspm/import-map";
1313
* ******************************************************
1414
*/
1515

16-
1716
/**
1817
* ensureDirSync
1918
* @description a function to ensure the dis exists
2019
* @param dirPath
21-
*/
20+
*/
2221
export const ensureDirSync = (dirPath: string) => {
2322
if (existsSync(dirPath)) return;
2423
const parentDir = dirname(dirPath);
2524
if (parentDir !== dirPath) ensureDirSync(parentDir);
2625
mkdirSync(dirPath);
27-
}
26+
};
2827

2928
/**
3029
* constructImportMap

0 commit comments

Comments
 (0)