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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20, 22, 24]
node: [20, 22, 24]

steps:
- name: Clone repository
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ npm install resolve-dependency-path

## Usage

### ESM

```js
const resolvePath = require('resolve-dependency-path');
import resolvePath from 'resolve-dependency-path';

const resolved = resolvePath({
dependency: './foobar',
Expand All @@ -22,6 +24,12 @@ const resolved = resolvePath({
});
```

### CommonJS

```js
const { default: resolvePath } = require('resolve-dependency-path');
```

### Options

| Option | Type | Required | Description |
Expand Down
15 changes: 15 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Resolve a dependency specifier to an absolute file path.
*
* @param {object} options
* @param {string} options.dependency - The dependency specifier (e.g. `'./bar'` or `'lodash'`)
* @param {string} options.filename - Absolute or relative path of the file that contains the dependency
* @param {string} options.directory - Root directory used to resolve non-relative dependencies
* @returns {string} Resolved absolute path including the inferred file extension
* @throws {Error} When any of the required options is missing or falsy
*/
export default function resolveDependencyPath({ dependency, filename, directory }?: {
dependency: string;
filename: string;
directory: string;
}): string;
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const path = require('path');
import path from 'node:path';

/**
* Resolve a dependency specifier to an absolute file path.
Expand All @@ -12,7 +10,7 @@ const path = require('path');
* @returns {string} Resolved absolute path including the inferred file extension
* @throws {Error} When any of the required options is missing or falsy
*/
module.exports = function({ dependency, filename, directory } = {}) {
export default function resolveDependencyPath({ dependency, filename, directory } = {}) {
if (!dependency) throw new Error('dependency path not given');
if (!filename) throw new Error('filename not given');
if (!directory) throw new Error('directory not given');
Expand All @@ -21,7 +19,7 @@ module.exports = function({ dependency, filename, directory } = {}) {
const extension = getDependencyExtension(dependency, filename);

return filepath + extension;
};
}

/**
* @param {string} dependency
Expand Down Expand Up @@ -61,7 +59,7 @@ function getDependencyExtension(dependency, filename) {

// If using a SystemJS style plugin
if (dependencyExtension.includes('!')) {
return dependencyExtension.substring(0, dependencyExtension.indexOf('!'));
return dependencyExtension.slice(0, dependencyExtension.indexOf('!'));
}

return '';
Expand Down
Loading
Loading