{"id":16759145,"url":"https://github.com/alcalzone/pak","last_synced_at":"2025-03-17T02:31:12.686Z","repository":{"id":43399143,"uuid":"360488585","full_name":"AlCalzone/pak","owner":"AlCalzone","description":"Programmatic wrapper around popular Node.js package managers","archived":false,"fork":false,"pushed_at":"2024-06-21T09:22:06.000Z","size":3107,"stargazers_count":4,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T16:43:40.749Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlCalzone.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"AlCalzone","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-04-22T11:03:34.000Z","updated_at":"2024-06-21T09:22:09.000Z","dependencies_parsed_at":"2024-04-17T07:46:15.098Z","dependency_job_id":"8bbcd679-46ac-4e3a-bbb7-beb2d9a58f77","html_url":"https://github.com/AlCalzone/pak","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.07692307692307687,"last_synced_commit":"2255ef7fefb061df6b2957c193ffdc0548d2ad3b"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fpak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fpak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fpak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fpak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlCalzone","download_url":"https://codeload.github.com/AlCalzone/pak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243837009,"owners_count":20355813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T04:07:25.943Z","updated_at":"2025-03-17T02:31:11.923Z","avatar_url":"https://github.com/AlCalzone.png","language":"TypeScript","funding_links":["https://github.com/sponsors/AlCalzone"],"categories":[],"sub_categories":[],"readme":"# pak\n\nProgrammatic wrapper around popular Node.js package managers\n\nSupports:\n\n-   [x] `npm`\n-   [x] `Yarn Classic`\n-   [x] `Yarn Berry`\n\n_(not all features are available for all package managers)_\n\n## Usage\n\n### Auto-detect the correct package-manager to use\n\n```ts\nimport { detectPackageManager } from \"pak\";\n\nasync function main() {\n\t// Use the current working directory\n\tconst pak = await detectPackageManager();\n\n\t// Or use a different directory. The package manager will default to that dir\n\tconst pak = await detectPackageManager({ cwd: \"/path/to/dir\" });\n}\n```\n\n`detectPackageManager` takes an options object with the following properties:\n\n```ts\n{\n\t/** The working directory for the package manager. Detection will start from here upwards. */\n\tcwd?: string;\n\t/** Whether to change the `cwd` to operate in the package's root directory instead of the current one. */\n\tsetCwdToPackageRoot?: boolean;\n\t/** If this is `false` and no package manager with a matching lockfile was found, another pass is done without requiring one */\n\trequireLockfile?: boolean;\n}\n```\n\n### Create an instance of a specific package manager\n\n```ts\nimport { packageManagers } from \"pak\";\nconst pak = new packageManagers.npm();\n```\n\n### Package manager properties\n\nAll package managers share the following properties:\n| Property | Type | Description |\n---------------------------------------------------------------- | -------- | --------- |\n| `cwd` | `string` | The directory to run the package manager commands in. Defaults to `process.cwd()` |\n| `loglevel` | `\"info\" \\| \"verbose\" \\| \"warn\" \\| \"error\" \\| \"silent\"` | Which loglevel to pass to the package manager. **Note:** Not every package manager supports every loglevel. |\n| `stdout` | `WritableStream` | A stream to pipe the command's `stdout` into. |\n| `stderr` | `WritableStream` | A stream to pipe the command's `stderr` into. |\n| `stdall` | `WritableStream` | A stream to pipe the command's `stdout` and `stderr` into in the order the output comes. |\n| `environment`| `\"production\" | \"development\"` | In an production environment, `pak` avoids accidentally pulling in `devDependencies` during `install` commands. |\n\n### Install one or more packages\n\n```ts\nconst result = await pak.install(packages, options);\n```\n\n-   `packages` is an array of package specifiers, like `[\"pak\", \"fs-extra\"]` or `[\"semver@1.2.3\"]`\n-   `options`: See [common options](#common-options) for details.\n\nIf `packages` is empty or `undefined`, this will install the packages that are defined in `package.json` in the `cwd`.\n\n### Uninstall one or more packages\n\n```ts\nconst result = await pak.uninstall(packages, options);\n```\n\n-   `packages` is an array of package specifiers, like `[\"pak\", \"fs-extra\"]` or `[\"semver@1.2.3\"]`\n-   `options`: See [common options](#common-options) for details.\n\n### Update one or more packages\n\n```ts\nconst result = await pak.update(packages, options);\n```\n\n-   `packages` is an array of package names, like `[\"pak\", \"fs-extra\"]`. If no packages are given, all packages in the current workspace are updated.\n-   `options`: See [common options](#common-options) for details.\n\n### Recompile native packages\n\n```ts\nconst result = await pak.rebuild(packages, options);\n```\n\n-   `packages` is an array of package names, like `[\"pak\", \"fs-extra\"]`. If no packages are given, all packages in the current workspace are rebuilt.\n-   `options`: See [common options](#common-options) for details.\n\n### Pin transitive dependencies to a fixed version\n\n```ts\nconst result = await pak.overrideDependencies(overrides);\n```\n\n-   `overrides` is an object of packages and exact versions, like `{\"pak\": \"1.2.3\"}`\n\nSometimes it is necessary to update transitive dependencies, meaning dependencies of dependencies. This command changes all occurences of the given overridden dependencies in the current `node_modules` tree so that the packages have the specified versions. How it works depends on the package manager:\n\n-   `yarn` uses the built-in `\"resolutions\"` property for `package.json`\n-   `npm` patches the root `package-lock.json` and `package.json` for all dependents of the overridden packages\n\n**Note:** This command does not support version ranges and it does not check whether the overrides are compatible with the version specified in `package.json`.\n\n### Result object\n\nThe returned value is an object with the following properties:\n\n```ts\ninterface CommandResult {\n\t/** Whether the command execution was successful */\n\tsuccess: boolean;\n\t/** The exit code of the command execution */\n\texitCode: number;\n\t/** The captured stdout */\n\tstdout: string;\n\t/** The captured stderr */\n\tstderr: string;\n}\n```\n\n### Common options\n\nThese options are used to influence the commands' behavior. All options are optional:\n\n| Option           | Type              | Description                                                                                                            | Default  | Commands               |\n| ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------- |\n| `dependencyType` | `\"prod\" \\| \"dev\"` | Whether to install a production or dev dependency.                                                                     | `\"prod\"` | all                    |\n| `global`         | `boolean`         | Whether to install the package globally.                                                                               | `false`  | all                    |\n| `exact`          | `boolean`         | Whether exact versions should be used instead of `\"^ver.si.on\"`.                                                       | `false`  | `install`              |\n| `ignoreScripts`  | `boolean`         | Prevent execution of pre/post/install scripts.                                                                         | `false`  | `install`              |\n| `force`          | `boolean`         | Pass the `--force` flag to the package manager where applicable. The specific behavior depends on the package manager. | `false`  | `install`              |\n| `additionalArgs` | `string[]`        | Additional command line args to pass to the underlying package manager.                                                | none     | `install`, `uninstall` |\n\n### Find the nearest parent directory with a `package.json`\n\n```ts\nawait pak.findRoot();\nawait pak.findRoot(\"lockfile.json\");\n```\n\nReturns a string with a path to the nearest parent directory (including `cwd`) that contains a `package.json` (and a lockfile if one was specified). Throws if none was found.\n\n### Stream the command output\n\nYou can stream the command output (`stdout`, `stderr` or both) during the command execution, as opposed to getting the entire output at the end. To do so,\nset the `stdout`, `stderr` and/or `stdall` properties of the package manager instance to a writable stream. Example:\n\n```ts\nimport { PassThrough } from \"stream\";\nimport { packageManagers } from \"../../src/index\";\n\nconst pak = new packageManagers.npm(); // or the automatically detected one\npak.stdall = new PassThrough().on(\"data\", (data) =\u003e {\n\t// For example, log to console - or do something else with the data\n\tconsole.log(data.toString(\"utf8\"));\n});\n\n// execute commands\n```\n\n### Get the version of the package manager\n\n```ts\nconst version = await pak.version();\n```\n\nReturns a string with the package manager's version.\n\n### Get the paths of all workspaces in the current monorepo\n\n```ts\nconst workspaces = await pak.workspaces();\n```\n\nReturns an array of strings including the paths of all workspaces in the current monorepo. This will return an empty array if the current directory is not part of a monorepo.\nA folder will be considered a workspace if it contains a file `package.json` and it is referenced in the `workspaces` property of the root `package.json`.\n\n### Pack a project or monorepo package into an installable tarball\n\n```ts\nconst result = await pak.pack(options);\n```\n\n`options` are optional and control what gets packed where and has the following shape:\n\n```ts\ninterface PackOptions {\n\t/**\n\t * In monorepos, this determines which workspace to pack. Defaults to the current working directory.\n\t * This must be a path relative to the repo root.\n\t */\n\tworkspace?: string;\n\t/** Where to save the packed tarball. Defaults to the current working directory */\n\ttargetDir?: string;\n}\n```\n\n`result` is a `CommandResult` (see above) where the `stdout` contains the absolute path of the packed tarball.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falcalzone%2Fpak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falcalzone%2Fpak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falcalzone%2Fpak/lists"}