Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions chompfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ version = 0.1
[[task]]
name = 'build'
run = 'tsup src/loader.ts --format esm,cjs --dts'
deps = 'npm:install'
dep = 'src/loader.ts'
target = 'dist/loader.js'

[[task]]
name = 'npm:install'
run = 'npm install'
dep = 'package.json'
target = 'package-lock.json'

[[task]]
name = 'clean'
Expand All @@ -21,14 +28,10 @@ run = 'commitlint --edit $1'
name = 'default'
run = 'npm install --no-save [email protected] @teleporthq/[email protected] @teleporthq/[email protected] chalk express morgan [email protected] [email protected] && node tests/e2e/test.js'

[[task]]
name = 'npm:install'
run = 'npm install'
deps = ['package.json']

[[task]]
name = 'lint'
run = 'eslint src --ext .ts'
deps = ['src/#.ts', 'tests/loader.test.ts']

[[task]]
name = 'lint-fix'
Expand All @@ -37,6 +40,9 @@ run = 'chomp lint --fix'
[[task]]
name = 'pre-commit'
run = 'lint-staged'
deps = ['src/#.ts', 'tests/loader.test.ts']

[[task]]

[[task]]
name = 'prepare'
Expand Down Expand Up @@ -77,3 +83,4 @@ run = 'vitest run'
[[task]]
name = 'typecheck'
run = 'tsc --noEmit'
deps = ['src/#.ts']
2 changes: 1 addition & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const cacheMap = new Map();
* @description a convenience function to ensure a file exists
* @param path
*/
function ensureFileSync(path: string) {
export function ensureFileSync(path: string) {
try {
accessSync(path);
} catch (err) {
Expand Down
13 changes: 13 additions & 0 deletions tests/loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as global from "node:fs";
import { join } from "node:path";
import { vi, test, expect } from 'vitest'
import { ImportMap } from "@jspm/import-map";

Expand All @@ -9,6 +11,8 @@ import {
getLastPart,
getPackageNameVersionFromUrl,
getVersion,
parseModule,
ensureFileSync,
} from "../src/loader"

vi.mock('url', () => ({
Expand Down Expand Up @@ -74,3 +78,12 @@ test('getPackageNameVersionFromUrl', () => {
version: '1.10.0',
});
});


test('should return the specifier if the module path is a node or file protocol', async () => {
const specifier = 'my-module';
const modulePath1 = 'node:fs';
const modulePath2 = 'file:///path/to/my/module.js';
expect(await parseModule(specifier, modulePath1)).toEqual(specifier);
expect(await parseModule(specifier, modulePath2)).toEqual(specifier);
});