forked from OctoLinker/OctoLinker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve
__dirname + '/some/relative/path'
(OctoLinker#364)
* Resolve `__dirname + '/some/relative/path'` Fixes OctoLinker#359 Demos: * https://github.com/pegjs/website/blob/5924ede36795192b77f2cb9bfe25a56e8e8b6f90/app.js#L12 * https://github.com/antoninlanglade/totopack/blob/055a725660a11d9c765434198edc7bb538ec5ccf/config/paths.js#L6 * Document Node.js relative path support * Dedupe JS/TS patterns/classes in relative path resolver * Match literal dot in `path.join`
- Loading branch information
1 parent
cbb53a0
commit a3ec0f9
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { join, dirname } from 'path'; | ||
import { NODEJS_RELATIVE_PATH, NODEJS_RELATIVE_PATH_JOIN } from '../../packages/helper-grammar-regex-collection/index.js'; | ||
import JavaScript from './javascript'; | ||
import TypeScript from './typescript'; | ||
|
||
export default { | ||
name: 'NodejsRelativePath', | ||
|
||
resolve({ target, path }) { | ||
return `{BASE_URL}${join(dirname(path), target)}`; | ||
}, | ||
|
||
getPattern() { | ||
const jsPatterns = JavaScript.getPattern().pathPatterns; | ||
const tsPatterns = TypeScript.getPattern().pathPatterns; | ||
|
||
const jsClasses = JavaScript.getPattern().githubClasses; | ||
const tsClasses = TypeScript.getPattern().githubClasses; | ||
|
||
return { | ||
pathPatterns: jsPatterns.concat(tsPatterns), | ||
githubClasses: jsClasses.concat(tsClasses), | ||
}; | ||
}, | ||
|
||
getLinkRegexes() { | ||
return [NODEJS_RELATIVE_PATH, NODEJS_RELATIVE_PATH_JOIN]; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import assert from 'assert'; | ||
import plugin from '../../lib/plugins/nodejs-relative-path.js'; | ||
|
||
describe('nodejs-relative-path', () => { | ||
it('resolves `__dirname + "/views"` relative to the current directory', () => { | ||
assert.deepEqual( | ||
plugin.resolve({ | ||
target: '/views', | ||
path: '/pegjs/website/blob/5924ede36795192b77f2cb9bfe25a56e8e8b6f90/app.js#L12', | ||
}), | ||
'{BASE_URL}/pegjs/website/blob/5924ede36795192b77f2cb9bfe25a56e8e8b6f90/views', | ||
); | ||
}); | ||
}); |