Skip to content

Commit

Permalink
fix: repeat matched "*" substring in value;
Browse files Browse the repository at this point in the history
- Closes #9
  • Loading branch information
lukeed committed Jan 11, 2023
1 parent 0bae61e commit af93bda
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -102,7 +102,7 @@ export function resolve(pkg, entry='.', options={}) {
// do not trigger if no *content* to inject
if (target.substring(key.length - 1).length > 0) {
return (tmp = loop(exports[key], allows))
? tmp.replace('*', target.substring(key.length - 1))
? tmp.replace(/[*]/g, target.substring(key.length - 1))
: bail(name, target, 1);
}
}
Expand Down
62 changes: 61 additions & 1 deletion test/resolve.js
Expand Up @@ -275,7 +275,67 @@ resolve('exports["./*"]', () => {
pass(pkg, './cheese/hello/world.js.mjs', './hello/world.js');
});

// https://nodejs.org/api/packages.html#packages_subpath_folder_mappings
resolve('exports["./dir*"]', () => {
let pkg = {
"name": "foobar",
"exports": {
"./dir*": "./cheese/*.mjs"
}
};

fail(pkg, '.', ".");
fail(pkg, '.', "foobar");

pass(pkg, './cheese/test.mjs', 'dirtest');
pass(pkg, './cheese/test.mjs', 'foobar/dirtest');

pass(pkg, './cheese/test/wheel.mjs', 'dirtest/wheel');
pass(pkg, './cheese/test/wheel.mjs', 'foobar/dirtest/wheel');
});

// https://github.com/lukeed/resolve.exports/issues/9
resolve('exports["./dir*"] :: repeat "*" value', () => {
let pkg = {
"name": "foobar",
"exports": {
"./dir*": "./*sub/dir*/file.js"
}
};

fail(pkg, '.', ".");
fail(pkg, '.', "foobar");

pass(pkg, './testsub/dirtest/file.js', 'dirtest');
pass(pkg, './testsub/dirtest/file.js', 'foobar/dirtest');

pass(pkg, './test/innersub/dirtest/inner/file.js', 'dirtest/inner');
pass(pkg, './test/innersub/dirtest/inner/file.js', 'foobar/dirtest/inner');
});

resolve('exports["./dir*"] :: share "name" start', () => {
let pkg = {
"name": "director",
"exports": {
"./dir*": "./*sub/dir*/file.js"
}
};

fail(pkg, '.', ".");
fail(pkg, '.', "director");

pass(pkg, './testsub/dirtest/file.js', 'dirtest');
pass(pkg, './testsub/dirtest/file.js', 'director/dirtest');

pass(pkg, './test/innersub/dirtest/inner/file.js', 'dirtest/inner');
pass(pkg, './test/innersub/dirtest/inner/file.js', 'director/dirtest/inner');
});

/**
* @deprecated Documentation-only deprecation in Node 14.13
* @deprecated Runtime deprecation in Node 16.0
* @removed Removed in Node 18.0
* @see https://nodejs.org/docs/latest-v16.x/api/packages.html#subpath-folder-mappings
*/
resolve('exports["./features/"]', () => {
let pkg = {
"name": "foobar",
Expand Down

0 comments on commit af93bda

Please sign in to comment.