Skip to content

Commit e077d8b

Browse files
committed
chore: add tests for clarity & shave 7b
1 parent 2a42804 commit e077d8b

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0.0-next.0",
33
"name": "resolve.exports",
44
"repository": "lukeed/resolve.exports",
5-
"description": "A tiny (959b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance",
5+
"description": "A tiny (952b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance",
66
"module": "dist/index.mjs",
77
"main": "dist/index.js",
88
"types": "index.d.ts",

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# resolve.exports [![CI](https://github.com/lukeed/resolve.exports/workflows/CI/badge.svg)](https://github.com/lukeed/resolve.exports/actions) [![codecov](https://codecov.io/gh/lukeed/resolve.exports/branch/master/graph/badge.svg?token=4P7d4Omw2h)](https://codecov.io/gh/lukeed/resolve.exports)
22

3-
> A tiny (959b), correct, general-purpose, and configurable `"exports"` and `"imports"` resolver without file-system reliance
3+
> A tiny (952b), correct, general-purpose, and configurable `"exports"` and `"imports"` resolver without file-system reliance
44
55
***Why?***
66

src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function resolve(pkg: t.Package, input?: string, options?: t.Options): st
2828
// let entry = input && input !== '.'
2929
// ? toEntry(pkg.name, input)
3030
// : '.';
31-
let entry = toEntry(pkg.name, input || '.');
32-
if (entry[0] === '#') return imports(pkg, entry, options);
33-
if (entry[0] === '.') return exports(pkg, entry, options);
31+
input = toEntry(pkg.name, input || '.');
32+
return input[0] === '#'
33+
? imports(pkg, input, options)
34+
: exports(pkg, input, options);
3435
}

test/index.ts

+36
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,42 @@ describe('$.resolve', it => {
9696
assert.is((err as Error).message, `Missing "#bar" specifier in "foobar" package`);
9797
}
9898
});
99+
100+
it('should run `$.export` if given "external" identifier', () => {
101+
let pkg: Package = {
102+
"name": "foobar",
103+
"exports": {
104+
".": "./foo.mjs"
105+
}
106+
};
107+
108+
try {
109+
lib.resolve(pkg, 'external');
110+
assert.unreachable();
111+
} catch (err) {
112+
assert.instance(err, Error);
113+
// IMPORTANT: treats "external" as "./external"
114+
assert.is((err as Error).message, `Missing "./external" specifier in "foobar" package`);
115+
}
116+
});
117+
118+
it('should run `$.export` if given "external/subpath" identifier', () => {
119+
let pkg: Package = {
120+
"name": "foobar",
121+
"exports": {
122+
".": "./foo.mjs"
123+
}
124+
};
125+
126+
try {
127+
lib.resolve(pkg, 'external/subpath');
128+
assert.unreachable();
129+
} catch (err) {
130+
assert.instance(err, Error);
131+
// IMPORTANT: treats "external/subpath" as "./external/subpath"
132+
assert.is((err as Error).message, `Missing "./external/subpath" specifier in "foobar" package`);
133+
}
134+
});
99135
});
100136

101137
describe('$.imports', it => {

0 commit comments

Comments
 (0)