-
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.
- Loading branch information
0 parents
commit 9a5a0b0
Showing
28 changed files
with
5,514 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = false | ||
insert_final_newline = true |
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,68 @@ | ||
const requiredExtensions = ["plugin:unicorn/recommended", "prettier"]; | ||
const requiredPlugins = ["unicorn", "prettier"]; | ||
const mainRules = { | ||
"unicorn/prevent-abbreviations": [ | ||
"error", | ||
{ | ||
checkFilenames: false, | ||
allowList: { | ||
props: true, | ||
}, | ||
}, | ||
], | ||
"unicorn/filename-case": [ | ||
"error", | ||
{ | ||
case: "kebabCase", | ||
}, | ||
], | ||
"unicorn/no-null": "off", | ||
}; | ||
|
||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
env: { | ||
es2023: true, | ||
node: true, | ||
}, | ||
|
||
overrides: [ | ||
{ | ||
files: ["**/*.ts", "**/*.{test,spec,d}.ts"], | ||
parser: "@typescript-eslint/parser", | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"standard-with-typescript", | ||
...requiredExtensions, | ||
], | ||
plugins: ["@typescript-eslint", ...requiredPlugins], | ||
rules: { | ||
"@typescript-eslint/strict-boolean-expressions": "off", | ||
...mainRules, | ||
}, | ||
}, | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: [".eslintrc.{js,cjs}"], | ||
parserOptions: { | ||
sourceType: "script", | ||
}, | ||
}, | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
extends: ["eslint:recommended", "plugin:package-json/recommended"], | ||
files: ["package.json"], | ||
plugins: ["package-json"], | ||
}, | ||
], | ||
parserOptions: { | ||
sourceType: "module", | ||
ecmaVersion: "latest", | ||
}, | ||
ignorePatterns: ["*.md"], | ||
}; |
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,34 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 21.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: latest | ||
|
||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile --ignore-scripts | ||
|
||
- name: Run tests | ||
run: pnpm run test |
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,61 @@ | ||
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig | ||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### macOS Patch ### | ||
# iCloud generated files | ||
*.icloud | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
!.vscode/*.code-snippets | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
### VisualStudioCode Patch ### | ||
# Ignore all local history of files | ||
.history | ||
.ionide | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos | ||
|
||
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) | ||
|
||
build |
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,3 @@ | ||
{ | ||
"testing.automaticallyOpenPeekView": "never" | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Pilaton | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,167 @@ | ||
<!-- markdownlint-configure-file { | ||
"MD033": false, | ||
"MD041": false, | ||
} --> | ||
|
||
<div align="center"> | ||
<img src="./public/logo.svg" alt="PMJS logo" width="500"> | ||
</div> | ||
|
||
# PMJS <!-- omit from toc --> | ||
|
||
![npm](https://img.shields.io/npm/v/pmjs?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837&color=CB3837) | ||
![Static Badge](<https://img.shields.io/badge/Coverage%20(istanbul)-100%25-green?style=for-the-badge&logo=vitest&logoColor=black&labelColor=298D46&color=298D46>) | ||
|
||
Asynchronous library with built-in caching to identify available package managers. | ||
|
||
## Table of contents <!-- omit from toc --> | ||
|
||
- [📡 Features](#-features) | ||
- [🕹️ Install](#️-install) | ||
- [🏄♀️ Usage](#️-usage) | ||
- [Example of defining a package manager for the current project](#example-of-defining-a-package-manager-for-the-current-project) | ||
- [Example of detecting all globally installed package managers](#example-of-detecting-all-globally-installed-package-managers) | ||
- [Clearing PMJS cache](#clearing-pmjs-cache) | ||
- [📜 API](#-api) | ||
- [defineManager()](#definemanager) | ||
- [defineGlobalManagers()](#defineglobalmanagers) | ||
- [clearCache()](#clearcache) | ||
|
||
## 📡 Features | ||
|
||
- [x] Defines the package manager that manages your application. | ||
- [x] Identifies all available globally installed package managers and their versions. | ||
- [x] Can detect package managers such as: **`npm`**, **`yarn`**, **`pnpm`** and **`bun`**. | ||
- [x] **Uses cache** at all stages, which can be forcibly cleared. | ||
- [x] ESM and CommonJS available. | ||
|
||
<!-- markdownlint-disable --> | ||
<div align="right">...</div> | ||
<!-- markdownlint-restore --> | ||
|
||
## 🕹️ Install | ||
|
||
```bash | ||
npm install pmjs | ||
``` | ||
|
||
PMJS offers several import options - default import, or named import. | ||
|
||
```js | ||
// default import | ||
import pmjs from 'pmjs'; | ||
|
||
// or named import. Recommended! | ||
import { defineManager, defineGlobalManagers } from 'pmjs'; | ||
``` | ||
|
||
Or if you want to use CommonJS: | ||
|
||
```js | ||
const pmjs = require('pmjs'); | ||
// or | ||
const { defineManager, defineGlobalManagers } = require('pmjs'); | ||
``` | ||
|
||
<!-- markdownlint-disable --> | ||
<div align="right">...</div> | ||
<!-- markdownlint-restore --> | ||
|
||
## 🏄♀️ Usage | ||
|
||
### Example of defining a package manager for the current project | ||
|
||
```js | ||
import { defineManager } from 'pmjs'; | ||
|
||
async function demoFunction() { | ||
const packageManager = await defineManager('/path/to/project'); | ||
|
||
console.log(packageManager); // npm | yarn | pnpm | bun | ||
} | ||
|
||
demoFunction(); | ||
``` | ||
|
||
### Example of detecting all globally installed package managers | ||
|
||
```js | ||
import { defineGlobalManagers } from 'pmjs'; | ||
|
||
async function demoFunction() { | ||
const globalManagers = await defineGlobalManagers(); | ||
|
||
console.log(globalManagers); | ||
// [ | ||
// { | ||
// manager: 'pnpm'; | ||
// version: '8.11.0'; | ||
// }, | ||
// { | ||
// manager: 'bun'; | ||
// version: '1.0.14'; | ||
// }, | ||
// ... | ||
// ] | ||
} | ||
|
||
demoFunction(); | ||
``` | ||
|
||
### Clearing PMJS cache | ||
|
||
Since all PMJS operations are cached in order to optimize speed, sometimes you may need to clear the cache manually. | ||
|
||
```js | ||
import { clearCache } from 'pmjs'; | ||
|
||
clearCache(); | ||
``` | ||
|
||
<!-- markdownlint-disable --> | ||
<div align="right">...</div> | ||
<!-- markdownlint-restore --> | ||
|
||
## 📜 API | ||
|
||
### defineManager() | ||
|
||
Defines the package manager used in a given directory. | ||
Checks for the presence of characteristic files (e.g., package-lock.json for npm) for each known package manager. | ||
|
||
Supported package managers: **`npm`**, **`yarn`**, **`pnpm`**, **`bun`** | ||
|
||
```js | ||
type PackageManager = "npm" | "yarn" | "pnpm" | "bun" | ||
|
||
defineManager: (path?: string) => Promise<PackageManager | null> | ||
``` | ||
|
||
| Argument | Type | Default value | Description | | ||
| -------- | -------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | ||
| `path` | `string` | [`process.cwd()`](https://nodejs.org/api/process.html#processcwd) | The path to the directory to check. If not provided, defaults to the current working directory. | | ||
|
||
**Return**: A promise that resolves to the type of package manager used or `null` if no package manager can be defined. | ||
|
||
### defineGlobalManagers() | ||
|
||
```js | ||
interface IGlobalManagerData { | ||
manager: PackageManager; | ||
version: string; | ||
} | ||
|
||
defineGlobalManagers: () => Promise<IGlobalManagerData[] | null> | ||
``` | ||
|
||
**Return:** A promise that resolves to an array of global manager data, including the name and version of each installed package manager, or `null` if none is installed. | ||
|
||
### clearCache() | ||
|
||
Clears the entire cache. | ||
This function removes all cached data related to package manager checks. | ||
Useful for resetting the state to ensure fresh data is fetched. | ||
|
||
```js | ||
clearCache: () => void | ||
``` |
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,12 @@ | ||
/** @type import('dts-bundle-generator/config-schema').BundlerConfig */ | ||
module.exports = { | ||
entries: [ | ||
{ | ||
filePath: './src/index.ts', | ||
outFile: './build/index.d.ts', | ||
output: { | ||
sortNodes: true, | ||
}, | ||
}, | ||
], | ||
}; |
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,7 @@ | ||
/** @type {import("knip").KnipConfig} */ | ||
const config = { | ||
entry: ['./src/index.ts'], | ||
project: ['./src/**/*.ts'], | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.