opk-pm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +201 -0
- package/README.md +52 -0
- package/dist/cli.js +66 -0
- package/package.json +43 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 OPK Team, ash (@a35hie)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
## Opk CLI
|
|
2
|
+
|
|
3
|
+
**Opk** is a unified package management workflow that sits on top of existing ecosystems like npm, Bun, pnpm, Yarn, and Deno.
|
|
4
|
+
It provides a consistent interface for installing, managing, and orchestrating dependencies across different runtimes and environments.
|
|
5
|
+
|
|
6
|
+
Rather than replacing existing package managers, Opk acts as a meta layer that standardizes tooling, simplifies configuration, and enables reproducible, cross-manager workflows.
|
|
7
|
+
It focuses on developer experience, deterministic installs, and ecosystem interoperability.
|
|
8
|
+
|
|
9
|
+
### Key Goals
|
|
10
|
+
|
|
11
|
+
- Unified package management across multiple ecosystems
|
|
12
|
+
- Consistent dependency and script workflows
|
|
13
|
+
- Cross-manager compatibility and migration
|
|
14
|
+
- Type-safe configuration and extensibility
|
|
15
|
+
- Reproducible and deterministic environments
|
|
16
|
+
|
|
17
|
+
Opk enables developers to manage packages once and run them anywhere.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
Opk CLI is an npm package that should be installed globally.
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
npm i -g opk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
- `opk init` - Prompt for project metadata, write `package.ts`, run ts-pkg sync+generate
|
|
29
|
+
- `opk add <pkg...>` - Add packages via selected package manager, then sync+generate
|
|
30
|
+
- `opk remove <pkg...>` - Remove packages via selected package manager, then sync+generate
|
|
31
|
+
- `opk install` - Install via selected package manager, then sync+generate
|
|
32
|
+
- `opk update [pkg...]` - Update via selected package manager, then sync+generate
|
|
33
|
+
- `opk audit` - Audit via selected package manager, then sync+generate
|
|
34
|
+
- `opk run <script> [args...]` - Run scripts via selected package manager
|
|
35
|
+
- `opk exec <cmd> [args...]` - Execute binaries via selected package manager
|
|
36
|
+
- `opk list` - Show dependencies in a native opk UI
|
|
37
|
+
- `opk generate [configPath] [packageJsonPath]` - Generate `package.json` from ts-pkg config
|
|
38
|
+
- `opk sync [configPath] [packageJsonPath]` - Sync and regenerate using ts-pkg APIs
|
|
39
|
+
|
|
40
|
+
## package.ts
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { definePackage, BunPm } from '@opk/ts-pkg'
|
|
44
|
+
|
|
45
|
+
export default definePackage({
|
|
46
|
+
pm: BunPm,
|
|
47
|
+
name: 'my-awesome-project',
|
|
48
|
+
description: 'this is an amazing project',
|
|
49
|
+
license: 'MIT',
|
|
50
|
+
type: 'module',
|
|
51
|
+
})
|
|
52
|
+
```
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import{createRequire as te}from"node:module";var ie=te(import.meta.url);import{createRequire as re}from"node:module";import{readFile as P,writeFile as ue}from"node:fs/promises";import{resolve as I}from"node:path";var Re=re(import.meta.url),h={name:"Bun",description:"Lightning-fast, modern package manager",install:"bun install",add:"bun add",remove:"bun rm",update:"bun update",audit:"bun audit",list:"bun pm ls",run:"bun run",exec:"bunx"},B={name:"npm",description:"The default Node.js package manager",install:"npm install",add:"npm install",remove:"npm uninstall",update:"npm update",audit:"npm audit",list:"npm ls --depth=0",run:"npm run",exec:"npx"},L={name:"pnpm",description:"Fast, disk-efficient package manager",install:"pnpm install",add:"pnpm add",remove:"pnpm remove",update:"pnpm update",audit:"pnpm audit",list:"pnpm list --depth=0",run:"pnpm run",exec:"pnpm dlx"},q={name:"Yarn",description:"Reliable package manager with workspaces support",install:"yarn install",add:"yarn add",remove:"yarn remove",update:"yarn upgrade",audit:"yarn npm audit",list:"yarn list --depth=0",run:"yarn",exec:"yarn dlx"},M={name:"Deno",description:"Secure runtime with first-class TypeScript support",install:"deno install",add:"deno add",remove:"deno remove",update:"deno outdated --update",audit:"deno audit",list:"deno info",run:"deno task",exec:"deno run"},se={typescript:{build:"tsc","build:watch":"tsc --watch",typecheck:"tsc --noEmit"},react:{dev:"vite",build:"vite build",preview:"vite preview"},node:{start:"node dist/index.js",dev:"tsx watch src/index.ts",build:"tsup src/index.ts --format esm,cjs --dts"},testing:{test:"vitest","test:watch":"vitest watch","test:coverage":"vitest --coverage"},prettier:{format:"prettier --write .","format:check":"prettier --check ."},eslint:{lint:"eslint .","lint:fix":"eslint . --fix"}};function oe(e){let t={};for(let i of e){let n=se[i];if(n)Object.assign(t,n)}return t}function ae(e,t){return{...e,...t}}function pe(e){if(typeof e==="string"){let n=e.lastIndexOf("@");if(n>0)return{name:e.slice(0,n),version:e.slice(n+1)};return{name:e}}let[t,i]=Object.entries(e)[0];return{name:t,version:i}}async function ce(e){let t=`https://registry.npmjs.org/${encodeURIComponent(e)}`,i=await fetch(t,{headers:{Accept:"application/json"}});if(!i.ok)throw Error(`Failed to fetch ${e}: ${i.statusText}`);return(await i.json())["dist-tags"].latest}var R=new Map;async function j(e){if(!e)return{};if(!Array.isArray(e))return e;if(e.length===0)return{};let t=[];for(let i of e){let{name:n,version:r}=pe(i);if(r){t.push([n,r]);continue}let o=R.get(n);if(!o)o=`^${await ce(n)}`,R.set(n,o);t.push([n,o])}return Object.fromEntries(t)}function Y(e,t){let i={...e};for(let n of Object.keys(t)){let r=t[n],o=e[n];if(r===void 0)continue;if(typeof r==="object"&&r!==null&&!Array.isArray(r)&&typeof o==="object"&&o!==null&&!Array.isArray(o))i[n]=Y(o,r);else i[n]=r}return i}function D(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;if(Array.isArray(e)&&Array.isArray(t))return[...e,...t];if(!Array.isArray(e)&&!Array.isArray(t))return{...e,...t};let i=Array.isArray(e)?{}:e,n=Array.isArray(t)?{}:t,r=Array.isArray(e)?e:[],o=Array.isArray(t)?t:[];return[...r,...o,{...i,...n}]}async function F(e){if(!e.extends)return e;let t;if(typeof e.extends==="string"){let r=await import(e.extends);t=r.default??r}else t=e.extends;t=await F(t);let{extends:i,...n}=e;return{...t,...n,dependencies:D(t.dependencies,n.dependencies),devDependencies:D(t.devDependencies,n.devDependencies),peerDependencies:D(t.peerDependencies,n.peerDependencies),scripts:{...t.scripts,...n.scripts},scriptPresets:[...t.scriptPresets??[],...n.scriptPresets??[]]}}function $e(){return{env:"development",platform:process.platform,nodeVersion:process.version,ci:process.env.CI==="true"||process.env.CI==="1"}}function me(e,t){if(e.env!==void 0&&t.env!==e.env)return!1;if(e.platform!==void 0&&t.platform!==e.platform)return!1;if(e.ci!==void 0&&t.ci!==e.ci)return!1;if(e.nodeVersion!==void 0){if(!t.nodeVersion.startsWith(e.nodeVersion))return!1}return!0}function le(e,t){if(!t||t.length===0)return e;let i=$e(),n={...e};for(let r of t)if(me(r.when,i))n=Y(n,r.set);return n}async function de(e,t={}){let{indent:i=2}=t,n=await F(e),r=n.scriptPresets?oe(n.scriptPresets):{},o=ae(r,n.scripts),[m,p,c]=await Promise.all([j(n.dependencies),j(n.devDependencies),j(n.peerDependencies)]),g={name:n.name,...n.version&&{version:n.version},...n.description&&{description:n.description},...n.keywords?.length&&{keywords:n.keywords},...n.homepage&&{homepage:n.homepage},...n.bugs&&{bugs:n.bugs},...n.license&&{license:n.license},...n.author&&{author:n.author},...n.contributors?.length&&{contributors:n.contributors},...n.repository&&{repository:n.repository},...n.type&&{type:n.type},...n.main&&{main:n.main},...n.module&&{module:n.module},...n.types&&{types:n.types},...n.exports&&{exports:n.exports},...n.bin&&{bin:n.bin},...n.files?.length&&{files:n.files},...Object.keys(o).length&&{scripts:o},...Object.keys(m).length&&{dependencies:m},...Object.keys(p).length&&{devDependencies:p},...Object.keys(c).length&&{peerDependencies:c},...n.optionalDependencies&&{optionalDependencies:n.optionalDependencies},...n.engines&&{engines:n.engines},...n.os?.length&&{os:n.os},...n.cpu?.length&&{cpu:n.cpu},...n.private!==void 0&&{private:n.private},...n.publishConfig&&{publishConfig:n.publishConfig},...n.workspaces?.length&&{workspaces:n.workspaces}},k=le(g,n.conditions);return JSON.stringify(k,null,i)}async function w(e,t={}){let{outputPath:i="package.json"}=t,n=await de(e,t),{writeFile:r}=await import("node:fs/promises");await r(i,n+`
|
|
3
|
+
`),console.log(`✨ Generated ${i}`)}function A(e){if(!e)return[];return Object.keys(e).sort()}function J(e,t=" "){if(e.length===0)return"[]";if(e.length===1)return`['${e[0]}']`;return`[
|
|
4
|
+
${e.map((i)=>`${t}'${i}',`).join(`
|
|
5
|
+
`)}
|
|
6
|
+
]`}function fe(e,t=" "){let i=Object.entries(e).sort(([n],[r])=>n.localeCompare(r));if(i.length===0)return"{}";return`{
|
|
7
|
+
${i.map(([n,r])=>`${t}'${n}': '${r}',`).join(`
|
|
8
|
+
`)}
|
|
9
|
+
}`}async function G(e={}){let{packageJsonPath:t="package.json",configPath:i="package.ts",quiet:n=!1,delay:r=0}=e;if(r>0)await new Promise((l)=>setTimeout(l,r));let o=I(process.cwd(),t),m=I(process.cwd(),i),p;try{let l=await P(o,"utf-8");p=JSON.parse(l)}catch(l){if(l.code==="ENOENT")console.error(`× package.json not found: ${t}`),process.exit(1);throw l}let c;try{c=await P(m,"utf-8")}catch(l){if(l.code==="ENOENT")console.error(`× Config file not found: ${i}`),console.error("Run ts-pkg init first to create a package.ts"),process.exit(1);throw l}let g=A(p.dependencies),k=A(p.devDependencies),u=A(p.peerDependencies),d=c;if(d=N(d,"dependencies",g,p.dependencies),d=N(d,"devDependencies",k,p.devDependencies),d=N(d,"peerDependencies",u,p.peerDependencies),await ue(m,d),!n){if(console.log(`✨ Synced dependencies to ${i}`),g.length)console.log(` dependencies: ${g.length} packages`);if(k.length)console.log(` devDependencies: ${k.length} packages`);if(u.length)console.log(` peerDependencies: ${u.length} packages`)}}function C(e,t,i,n){let r=0;for(let o=t;o<e.length;o++)if(e[o]===i)r++;else if(e[o]===n){if(r--,r===0)return o}return-1}function N(e,t,i,n){let r=new RegExp(`(${t}:\\s*)\\[`).exec(e);if(r&&r[1]){let m=J(i),p=r.index+r[1].length,c=C(e,p,"[","]");if(c!==-1)return e.slice(0,p)+m+e.slice(c+1)}let o=new RegExp(`(${t}:\\s*)\\{`).exec(e);if(o&&o[1]){let m=fe(n||{}),p=o.index+o[1].length,c=C(e,p,"{","}");if(c!==-1)return e.slice(0,p)+m+e.slice(c+1)}if(i.length>0){let m=J(i),p=[{pattern:/peerDependencies:\s*[\[{]/,after:!0},{pattern:/devDependencies:\s*[\[{]/,after:!0},{pattern:/dependencies:\s*[\[{]/,after:!0},{pattern:/(\n\s*)(conditions:\s*\[)/,before:!0},{pattern:/(\n\s*)(engines:\s*\{)/,before:!0}];for(let{pattern:c,after:g,before:k}of p){let u=c.exec(e);if(u){if(g){let d=e[u.index+u[0].length-1]==="[",l=u.index+u[0].length-1,E=C(e,l,d?"[":"{",d?"]":"}");if(E!==-1){let f=E+1,b=e[f];while(f<e.length&&b&&/[,\s]/.test(b)&&b!==`
|
|
10
|
+
`)f++,b=e[f];if(e[f]===`
|
|
11
|
+
`)f++;return e.slice(0,f)+`
|
|
12
|
+
${t}: ${m},
|
|
13
|
+
`+e.slice(f)}}else if(k)return e.replace(c,`$1${t}: ${m},
|
|
14
|
+
$1$2`)}}}return e}function W(e){return e}import{resolve as z}from"node:path";import{pathToFileURL as ke}from"node:url";import{access as ge}from"node:fs/promises";async function x(e){try{return await ge(e),!0}catch{return!1}}async function y(e="package.ts"){let t=z(process.cwd(),e),i=await import(ke(t).href),n=i.default??i;if(!n.pm)throw Error(`Missing required pm field in ${e}. Import a PM from @opk/ts-pkg and assign pm`);return n}async function v(e="package.ts",t="package.json"){await G({configPath:e,packageJsonPath:t,quiet:!0});let i=await y(e);await w(i,{outputPath:t})}async function V(){let e=[{lockfile:"bun.lock",select:{importName:"BunPm",manager:h}},{lockfile:"bun.lockb",select:{importName:"BunPm",manager:h}},{lockfile:"pnpm-lock.yaml",select:{importName:"PnpmPm",manager:L}},{lockfile:"yarn.lock",select:{importName:"YarnPm",manager:q}},{lockfile:"package-lock.json",select:{importName:"NpmPm",manager:B}},{lockfile:"deno.lock",select:{importName:"DenoPm",manager:M}}];for(let t of e)if(await x(z(process.cwd(),t.lockfile)))return t.select;return{importName:"BunPm",manager:h}}function ye(e){return`'${e.replace(/'/g,"'\\''")}'`}function S(e){return e.trim().split(/\s+/).filter(Boolean)}async function U(e,t=[]){let i=[e,...t.map(ye)].join(" "),r=await Bun.spawn(["sh","-lc",i],{stdin:"inherit",stdout:"inherit",stderr:"inherit"}).exited;if(r!==0)process.exit(r)}async function H(e,t,i="package.ts",n="package.json"){let r=S(e);if(r.length===0)throw Error("Invalid package manager command");let[o,...m]=r;await U(o,[...m,...t]),await v(i,n)}async function Q(e,t){let i=S(e);if(i.length===0)throw Error("Invalid package manager command");let[n,...r]=i;await U(n,[...r,...t])}import{writeFile as he}from"node:fs/promises";import{resolve as K}from"node:path";import{createInterface as we}from"node:readline/promises";import{stdin as ve,stdout as be}from"node:process";var s={reset:"\x1B[0m",pink:"\x1B[38;5;213m",purple:"\x1B[38;5;99m",lavender:"\x1B[38;5;183m",dim:"\x1B[2m",bold:"\x1B[1m"};function a(e,t){return`${t}${e}${s.reset}`}function T(e){return e.replace(/'/g,"\\'")}async function xe(){let e=we({input:ve,output:be});try{let t=(await e.question("Package name: ")).trim()||"my-project",i=(await e.question("Description: ")).trim(),n=(await e.question("License (MIT): ")).trim()||"MIT",o=((await e.question("Module type (module/commonjs) [module]: ")).trim()||"module").toLowerCase()==="commonjs"?"commonjs":"module";return{name:t,description:i,license:n,moduleType:o}}finally{e.close()}}async function X(){let e=K(process.cwd(),"package.ts");if(await x(e))throw Error("package.ts already exists");let t=await xe(),i=await V(),n=`import { definePackage, ${i.importName} } from '@opk/ts-pkg'
|
|
15
|
+
|
|
16
|
+
export default definePackage({
|
|
17
|
+
pm: ${i.importName},
|
|
18
|
+
name: '${T(t.name)}',
|
|
19
|
+
description: '${T(t.description)}',
|
|
20
|
+
license: '${T(t.license)}',
|
|
21
|
+
type: '${t.moduleType}',
|
|
22
|
+
private: false,
|
|
23
|
+
})
|
|
24
|
+
`;await he(e,n),console.log(`${a("Initialized",s.pink)} package.ts with ${a(i.manager.name,s.purple)}`);let r=await y("package.ts");await w(r,{outputPath:K(process.cwd(),"package.json")}),await v("package.ts","package.json")}import{readFile as je}from"node:fs/promises";import{resolve as De}from"node:path";function Ae(e,t){if(e.length<=t)return e;if(t<=1)return e.slice(0,t);return`${e.slice(0,t-1)}…`}function Ce(e,t){let n=a(`╭${"─".repeat(36)}╮`,s.purple),r=a(`╰${"─".repeat(36)}╯`,s.purple),o=t?`${e} ${t}`:e,p=` ${Ae(o,34)}`.padEnd(36," "),c=a("│",s.purple)+a(p,s.bold+s.pink)+a("│",s.purple);return[n,c,r]}function O(e,t){if(!t||Object.keys(t).length===0)return[];return[a(`${e}:`,s.purple),...Object.entries(t).sort(([i],[n])=>i.localeCompare(n)).map(([i,n])=>` ${a("•",s.pink)} ${i} ${a(n,s.dim)}`)]}async function Z(e="package.json"){let t=De(process.cwd(),e),i=await je(t,"utf-8"),n=JSON.parse(i),r=[...Ce(n.name??"unnamed-project",n.version??""),"",...O("dependencies",n.dependencies),...O("devDependencies",n.devDependencies),...O("peerDependencies",n.peerDependencies)];if(r[r.length-1]==="")r.pop();if(r.length<=4)r.push(a("No dependencies found",s.dim));console.log(r.join(`
|
|
25
|
+
`))}var _=`
|
|
26
|
+
$$$$$$$$$$$$$$
|
|
27
|
+
$$$$$$$$$$$$$$$$$$$$
|
|
28
|
+
$$$$$$$$$$ $$$$$$$$$
|
|
29
|
+
$$$$$$$$$$$ $$$$$$
|
|
30
|
+
$$$$$$ $$$$$ $$$$$$
|
|
31
|
+
$$$$$$ $$$$$ $$$$$$
|
|
32
|
+
$$$$$ $$$$$ $$$$$
|
|
33
|
+
$$$$$ $$$$$$$$ $$$$$$$
|
|
34
|
+
$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$
|
|
35
|
+
$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$
|
|
36
|
+
$$$$$ $$$$$ $$$$$$$$$$ $$$$$
|
|
37
|
+
$$$$$ $$$$$ $$$$$$$ $$$$$
|
|
38
|
+
$$$$$$ $$$$$ $$$$$$$$$$$$
|
|
39
|
+
$$$$$$ $$$$$ $$$$$$$$$$
|
|
40
|
+
$$$$$$$$$$$ $$$$$$
|
|
41
|
+
$$$$$$$$$$ $$$$$$$$$
|
|
42
|
+
$$$$$$$$$$$$$$$$$$$$
|
|
43
|
+
$$$$$$$$$$$$$$
|
|
44
|
+
`,$=W({pm:h,name:"opk",description:"The universal package manager for JS/TS.",version:"0.1.0",license:"Apache-2.0",keywords:["opk","typescript","package-json","npm","bun","monorepo-tooling","nodejs"],type:"module",main:"dist/cli.js",module:"dist/cli.js",bin:{opk:"./dist/cli.js"},files:["dist"],scriptPresets:["typescript","prettier"],scripts:{build:"bun run build.ts",dev:"bun run src/cli.ts help"},devDependencies:{"@types/bun":"latest"},peerDependencies:{typescript:"^5"},dependencies:{"@opk/ts-pkg":"^0.5.0"},private:!1});function ee(){console.log(`
|
|
45
|
+
${a(_,s.bold+s.purple)}
|
|
46
|
+
${a($.name,s.bold+s.pink)} ${a("- "+$.description,s.lavender)}
|
|
47
|
+
${a("Version: "+$.version,s.dim)}
|
|
48
|
+
|
|
49
|
+
Usage:
|
|
50
|
+
${a($.name,s.dim)} init
|
|
51
|
+
${a($.name,s.dim)} add <pkg...>
|
|
52
|
+
${a($.name,s.dim)} remove <pkg...>
|
|
53
|
+
${a($.name,s.dim)} install
|
|
54
|
+
${a($.name,s.dim)} update [pkg...]
|
|
55
|
+
${a($.name,s.dim)} audit
|
|
56
|
+
${a($.name,s.dim)} run <pkg script> [args...]
|
|
57
|
+
${a($.name,s.dim)} exec <cmd> [args...]
|
|
58
|
+
${a($.name,s.dim)} list
|
|
59
|
+
${a($.name,s.dim)} sync [configPath] [packageJsonPath]
|
|
60
|
+
${a($.name,s.dim)} generate [configPath] [packageJsonPath]
|
|
61
|
+
${a($.name,s.dim)} help
|
|
62
|
+
|
|
63
|
+
Notes:
|
|
64
|
+
${a("∙",s.dim)} PM-backed commands use the package manager selected in package.ts (pm field)
|
|
65
|
+
${a("∙",s.dim)} Opk automatically keeps your package.ts up to date
|
|
66
|
+
`)}async function ne(e){let t=e[0]??"generate";if(t==="help"||t==="--help"||t==="-h"){ee();return}if(t==="init"){await X();return}if(t==="list"){await Z(e[1]??"package.json");return}if(t==="sync"){await v(e[1]??"package.ts",e[2]??"package.json");return}if(t==="generate"){let n=await y(e[1]??"package.ts");await w(n,{outputPath:e[2]??"package.json"});return}if(t==="run"||t==="exec"){let n=await y("package.ts"),r=e.slice(1);if(r.length===0)throw Error(`opk ${t} requires at least one argument`);await Q(t==="run"?n.pm.run:n.pm.exec,r);return}if(new Set(["add","remove","install","update","audit"]).has(t)){let n=await y("package.ts"),r=e.slice(1);if((t==="add"||t==="remove")&&r.length===0)throw Error(`opk ${t} requires at least one package`);let o=t==="add"?n.pm.add:t==="remove"?n.pm.remove:t==="install"?n.pm.install:t==="update"?n.pm.update:n.pm.audit;await H(o,r);return}throw Error(`Unknown command: ${t}`)}async function Ne(){await ne(process.argv.slice(2))}Ne().catch((e)=>{let t=e instanceof Error?e.message:String(e);console.error(`${a("opk error:",s.pink)} ${t}`),process.exit(1)});export{Ne as main};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opk-pm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The universal package manager for JS/TS.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"opk",
|
|
7
|
+
"typescript",
|
|
8
|
+
"package-json",
|
|
9
|
+
"npm",
|
|
10
|
+
"bun",
|
|
11
|
+
"monorepo-tooling",
|
|
12
|
+
"nodejs"
|
|
13
|
+
],
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"repository": "https://github.com/opk-pm/Cli.git",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "dist/cli.js",
|
|
18
|
+
"module": "dist/cli.js",
|
|
19
|
+
"bin": {
|
|
20
|
+
"opk": "./dist/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "bun run build.ts",
|
|
27
|
+
"build:watch": "tsc --watch",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"format": "prettier --write .",
|
|
30
|
+
"format:check": "prettier --check .",
|
|
31
|
+
"dev": "bun run src/cli.ts help"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@opk/ts-pkg": "^0.5.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/bun": "latest"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"typescript": "^5"
|
|
41
|
+
},
|
|
42
|
+
"private": false
|
|
43
|
+
}
|