Skip to content

Commit

Permalink
feat: @yarn-tool/require-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jun 5, 2021
1 parent 06dbb45 commit 232d8c8
Show file tree
Hide file tree
Showing 10 changed files with 761 additions and 0 deletions.
136 changes: 136 additions & 0 deletions packages/@yarn-tool/require-resolve/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

/.*/
.idea
node_modules
~ci.list.txt
~ci.log.txt
~ci.errors.txt
*.stackdump
*.bak
*.old
package-lock.json
test/**/*.js
test/**/*.d.ts
test/*.js
test/*.d.ts
test/temp*
test/**/*.map
tests/**/*.js
tests/**/*.d.ts
tests/*.js
tests/*.d.ts
tests/temp*
tests/**/*.map
bin/*.d.ts
bin/**/*.d.ts
/packages/*/bin/*.d.ts
/packages/*/test/**/*.js
/packages/*/test/**/*.d.ts
/packages/*/test/*.js
/packages/*/test/*.d.ts
/packages/*/test/temp*
/packages/*/tests/**/*.js
/packages/*/tests/**/*.d.ts
/packages/*/tests/*.js
/packages/*/tests/*.d.ts
/packages/*/tests/temp*
**/node_modules
*.tgz
/tsconfig.json.tpl
/.eslintrc.json.tpl
!tsconfig.json
!.eslintrc.json
yarn-error.log
*.log
.git
yarn.lock
.env.local
.env.*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.vue.js
*.vue.d.ts
*.vue.js.map
vue.config.d.ts
vue.config.js.map
.nyc_output
coverage
/*.tpl
!.forestry
!.vuepress
!.github
!.gitee
!.gitlab
.git

*.tsbuildinfo
tsconfig.esm.json.tpl

.browserslistrc
.nvmrc

/.eslintignore
/package.d.ts
.nycrc
.mocharc.yml
#jest.config.js
node_modules/.cache
.yarn-integrity
jest.config.d.ts
jest.config.js.map
/report.*.json
*.js.map
/now.json
.nyc_output
.coverage-cache
.reify-cache
*.spec.d.ts
*.spec.js
.nowignore
*/**/.github
!/.github
!npm-shrinkwrap.json
*.stat
.vercel

86 changes: 86 additions & 0 deletions packages/@yarn-tool/require-resolve/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/.pnp
.pnp.js
.idea
~ci.list.txt
~ci.log.txt
~ci.errors.txt
*.stackdump
*.bak
*.old
*.log
tsconfig.json
package-lock.json
test
.github
.gitkeep
/.*/
/.*
tests
/~*
__test__
__tests__
node_modules
/node_modules/
**/node_modules/
*.ts
!*.d.ts
/bin/**/*.d.ts
/bin/*.d.ts
*.tgz
/tsconfig.json.tpl
yarn-error.log
.git
yarn.lock
.env.local
.env.*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.vue.js
*.vue.d.ts
*.vue.js.map
.nyc_output
coverage
/*.tpl
webpack.config.js
vue.config.js
/jestconfig.json
/tslint.json
.git
webpack.*.config.js
webpack.*.config.d.ts
webpack.*.config.js.map
webpack.*.config.ts
karma.conf.js
/_config.yml
intellij-style-guide.xml
jest.config.js
*.tsbuildinfo
tsconfig.*.json
tsconfig.esm.json.tpl
/package.d.ts
.mocharc.yml
jest.config.js
jest.config.*
/report.*.json
now.json
/Makefile
*.spec.d.ts
*.spec.js
*.spec.ts
*.spec.tsx
__mocks__
__tests__
__snapshots__
*.snap
npm-shrinkwrap.json
/example/
*.stat
.vercel
tsdx.config.js
26 changes: 26 additions & 0 deletions packages/@yarn-tool/require-resolve/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# README.md

require.resolve with search on extra paths

## install

```bash
yarn add @yarn-tool/require-resolve
yarn-tool add @yarn-tool/require-resolve
yt add @yarn-tool/require-resolve
```

```typescript
const tsdx_path = requireResolveExtra('tsdx').result;

let actual = requireResolveExtra('ts-jest', {
includeGlobal: true,
includeCurrentDirectory: true,
paths: [
tsdx_path,
],
});

console.dir(actual);
```

32 changes: 32 additions & 0 deletions packages/@yarn-tool/require-resolve/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference types="node" />
export declare const SymbolCurrentDirectory: unique symbol;
export declare const SymbolGlobal: unique symbol;
export declare const SymbolGlobalNpm: unique symbol;
export declare const SymbolGlobalYarn: unique symbol;
export declare const SymbolModuleMain: unique symbol;
declare type IPathItem = typeof SymbolCurrentDirectory | typeof SymbolGlobal | typeof SymbolGlobalNpm | typeof SymbolGlobalYarn | typeof SymbolModuleMain;
export interface IOptionsCore {
paths?: (string | IPathItem)[];
}
export interface IOptions extends IOptionsCore {
map?: Record<string, string>;
require?: NodeRequire;
includeGlobal?: boolean | IPathItem[];
includeCurrentDirectory?: boolean;
cwd?: string;
}
export declare function requireResolveCore(name: string, options?: IOptions): string;
export declare type IErrorModuleNotFound<E> = E & {
code: string | 'MODULE_NOT_FOUND';
requireStack: string[];
};
export declare function handleOptionsPaths(paths: IOptionsCore["paths"], cwd?: string): string[];
export declare function isErrorModuleNotFound<T extends Error>(error: T): error is IErrorModuleNotFound<T>;
export declare function requireExtra<T extends any>(name: string, options?: IOptions): T;
export declare function importExtra<T extends any>(name: string, options?: IOptions): Promise<T>;
export declare function requireResolveExtra(name: string, options?: IOptions): {
result: string;
error: IErrorModuleNotFound<Error>;
};
export declare function _unshiftArray<T extends any>(array: T[], item: T): T[];
export default requireResolveExtra;
Loading

0 comments on commit 232d8c8

Please sign in to comment.