@hanseltime/esm-interop-tools 1.0.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.
Files changed (64) hide show
  1. package/README.md +115 -0
  2. package/dist/bin/get-esm-packages.js +17 -0
  3. package/dist/bin/get-esm-packages.js.map +1 -0
  4. package/dist/cjs/bin/get-esm-packages.js +73 -0
  5. package/dist/cjs/bin/get-esm-packages.js.map +1 -0
  6. package/dist/cjs/index.js +21 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/cjs/operations/getESMPackages.js +105 -0
  9. package/dist/cjs/operations/getESMPackages.js.map +1 -0
  10. package/dist/cjs/operations/index.js +21 -0
  11. package/dist/cjs/operations/index.js.map +1 -0
  12. package/dist/cjs/operations/jest.js +52 -0
  13. package/dist/cjs/operations/jest.js.map +1 -0
  14. package/dist/cjs/packageGraphs/Graph.js +130 -0
  15. package/dist/cjs/packageGraphs/Graph.js.map +1 -0
  16. package/dist/cjs/packageGraphs/PackageGraph.js +42 -0
  17. package/dist/cjs/packageGraphs/PackageGraph.js.map +1 -0
  18. package/dist/cjs/packageGraphs/getYarnInfoPackageGraph.js +128 -0
  19. package/dist/cjs/packageGraphs/getYarnInfoPackageGraph.js.map +1 -0
  20. package/dist/cjs/packageGraphs/index.js +23 -0
  21. package/dist/cjs/packageGraphs/index.js.map +1 -0
  22. package/dist/cjs/packageGraphs/types.js +6 -0
  23. package/dist/cjs/packageGraphs/types.js.map +1 -0
  24. package/dist/esm/bin/get-esm-packages.mjs +86 -0
  25. package/dist/esm/bin/get-esm-packages.mjs.map +1 -0
  26. package/dist/esm/index.mjs +4 -0
  27. package/dist/esm/index.mjs.map +1 -0
  28. package/dist/esm/operations/getESMPackages.mjs +118 -0
  29. package/dist/esm/operations/getESMPackages.mjs.map +1 -0
  30. package/dist/esm/operations/index.mjs +4 -0
  31. package/dist/esm/operations/index.mjs.map +1 -0
  32. package/dist/esm/operations/jest.mjs +45 -0
  33. package/dist/esm/operations/jest.mjs.map +1 -0
  34. package/dist/esm/packageGraphs/Graph.mjs +173 -0
  35. package/dist/esm/packageGraphs/Graph.mjs.map +1 -0
  36. package/dist/esm/packageGraphs/PackageGraph.mjs +28 -0
  37. package/dist/esm/packageGraphs/PackageGraph.mjs.map +1 -0
  38. package/dist/esm/packageGraphs/getYarnInfoPackageGraph.mjs +142 -0
  39. package/dist/esm/packageGraphs/getYarnInfoPackageGraph.mjs.map +1 -0
  40. package/dist/esm/packageGraphs/index.mjs +6 -0
  41. package/dist/esm/packageGraphs/index.mjs.map +1 -0
  42. package/dist/esm/packageGraphs/types.mjs +8 -0
  43. package/dist/esm/packageGraphs/types.mjs.map +1 -0
  44. package/dist/types/bin/get-esm-packages.d.ts +2 -0
  45. package/dist/types/bin/get-esm-packages.d.ts.map +1 -0
  46. package/dist/types/index.d.ts +3 -0
  47. package/dist/types/index.d.ts.map +1 -0
  48. package/dist/types/operations/getESMPackages.d.ts +8 -0
  49. package/dist/types/operations/getESMPackages.d.ts.map +1 -0
  50. package/dist/types/operations/index.d.ts +3 -0
  51. package/dist/types/operations/index.d.ts.map +1 -0
  52. package/dist/types/operations/jest.d.ts +40 -0
  53. package/dist/types/operations/jest.d.ts.map +1 -0
  54. package/dist/types/packageGraphs/Graph.d.ts +72 -0
  55. package/dist/types/packageGraphs/Graph.d.ts.map +1 -0
  56. package/dist/types/packageGraphs/PackageGraph.d.ts +19 -0
  57. package/dist/types/packageGraphs/PackageGraph.d.ts.map +1 -0
  58. package/dist/types/packageGraphs/getYarnInfoPackageGraph.d.ts +9 -0
  59. package/dist/types/packageGraphs/getYarnInfoPackageGraph.d.ts.map +1 -0
  60. package/dist/types/packageGraphs/index.d.ts +5 -0
  61. package/dist/types/packageGraphs/index.d.ts.map +1 -0
  62. package/dist/types/packageGraphs/types.d.ts +9 -0
  63. package/dist/types/packageGraphs/types.d.ts.map +1 -0
  64. package/package.json +64 -0
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @hanseltime/esm-interop-tools
2
+
3
+ Have you run into the dreaded "Cannot require a module" error from the interoperability nightmare that is the ES Module cut over?
4
+ If not, you sweet child, leave this repo and keep your innocence and joy. If you are already jaded, then please, read on and maybe
5
+ benefit from what this repo has.
6
+
7
+ ## Use Cases
8
+
9
+ ### Knowing what you have
10
+
11
+ When one of these esm module failures pops up, it's often times not just 1 module. You'll find yourself doing some dependency fix for 1, then 2, etc.
12
+ modules that got dragged into the dependency tree by an innocuous `yarn add` or `npm install`.
13
+
14
+ In those cases, there are some binary scripts that you can use to debug this:
15
+
16
+ ```
17
+ yarn get-esm-packages --recurse --pkgManager yarnv2+
18
+ ```
19
+
20
+ __TODO: This currently only supports yarn v2 non-plug'n'play. If anyone would like to write a package Graph adapter, please feel free__
21
+
22
+ ### Jest
23
+
24
+ If you're like me, you either have a massive repo of jest tests with mocks, or want to use jest because of it's rather comprehensive tooling.
25
+ However, one of the most comprehensive parts of jest (in my opinion) is its ability to do mock hoisting with a simple syntax. Combine that with
26
+ typescript's use of imports and you get a relatively familiar way of declaring imports, then mocks, then tests.
27
+
28
+ If you've played with jest's [esm module suppport](https://jestjs.io/docs/ecmascript-modules), you may have come to realize that there are lots of
29
+ restrictions and nuances to working with the traditional jest transforms. As of now, if you'd like to use jest with its main features, commonjs
30
+ transpilation is the best way to go.
31
+
32
+ Per [this lengthy discussion on transpiling third party libraries](https://stackoverflow.com/questions/58613492/how-to-resolve-cannot-use-import-statement-outside-a-module-from-jest-when-run?page=1&tab=scoredesc#tab-top),
33
+ you will need to:
34
+
35
+ 1. Transpile .js files in third party libraries that are ESM modules with a correct setup (like ts-jest or babel-jest configured correctly)
36
+ 2. Get jest to not ignore those node_modules entries
37
+
38
+ #### Looking up esm modules
39
+
40
+ I recommend that you keep a git-committed file that you write to on `install` of yarn/npm. Once you have that set up, you can then
41
+ read in the same file in your jest config and use our programmatic API to construct a `node_modules` transformIgnore regex.
42
+
43
+ First: set up the install script:
44
+
45
+ ```json
46
+ // For npm and yarn v1 projects
47
+ // package.json
48
+ {
49
+ "scripts": {
50
+ "postinstall": "npm run get-esm-packages -p npm --recurse --file esm-modules.json --quiet"
51
+ }
52
+ }
53
+
54
+ ```
55
+
56
+ ```yaml
57
+ # For yarn v2+
58
+ # This assumes you've installed the after-install plugin: https://github.com/mhassan1/yarn-plugin-after-install
59
+
60
+ # For a single repo project:
61
+ afterInstall: yarn get-esm-packages -p yarnv2+ -r --file esm-packages.json --quiet
62
+
63
+ # For Monorepos - this allows you to update the esm-packages.json on new installs
64
+ afterInstall: yarn workspaces foreach --all -pt run get-esm-packages -p yarnv2+ -r --file esm-packages.json --quiet
65
+
66
+ # Installed plugin for after-install calls
67
+ plugins:
68
+ - checksum: 0a2a35fbed2f33f0df1ceb1db51bf72554201f994eaecb86cbc62a295c3d05f7cc44fa8be8e64fc5e1c0bee4f529a17a0cc429ea9e3486ad467443291d5a8e3b
69
+ path: .yarn/plugins/@yarnpkg/plugin-after-install.cjs
70
+ spec: "https://raw.githubusercontent.com/mhassan1/yarn-plugin-after-install/refs/tags/v0.6.0/bundles/%40yarnpkg/plugin-after-install.js"
71
+ ```
72
+
73
+ With the post install scripts set up, you can now modify your jest config file to do a lookup of the files.
74
+
75
+ ```typescript
76
+ import { getJestNodeModulesTransformIgnore } from '@hanseltime/esm-interop-tools'
77
+
78
+ export default config = {
79
+
80
+ transformIgnorePatterns: [
81
+ getJestNodeModulesTransformIgnore({
82
+ file: 'esm-packages.json'
83
+ }),
84
+ // Any other ignore patterns that you want
85
+ ],
86
+ }
87
+ ```
88
+ ##### Doing it solo
89
+
90
+ As an exercise, if you really want to not use the higher level abstractions, you could use some of the composite
91
+ functions from the programmatic API to get the same transform information.
92
+
93
+ Note - this will make your tests run a fair bit slower since it does the dependency analysis every time you run tests.
94
+
95
+ ```typescript
96
+ import { getYarnInfoPackageGraph, getESMPackages } from '@hanseltime/esm-interop-tools'
97
+
98
+ export default async () => {
99
+ const packageGraph = await getYarnInfoPackageGraph(__dirname, true)
100
+ packageGraph.validate()
101
+
102
+ const packages = await getESMPackages(packageGraph)
103
+
104
+ return {
105
+ transformIgnorePatterns: [
106
+ // This exempts all package paths in a large regex
107
+ `node_modules/(?!${packages.map((p) => `${p}/`).join('|')})`
108
+ ],
109
+ }
110
+ }
111
+ ```
112
+
113
+ # TODO: Unit/Integration testing
114
+
115
+ This tool has been tested via use in various projects, but would benefit from integration tests with a list of known dependencies, etc.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ (()=>{var e={606:function(e){"use strict";e.exports=function(){return/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?/}},863:function(e,t,i){"use strict";var r=i(606);e.exports=function(e){if("string"!=typeof e)throw TypeError("expected a string");var t=r().exec(e);if(t)return t[0]}},164:function(e,t,i){"use strict";let r=i(926);e.exports=class{constructor(){this.MODULE_ENTRY=new r,this.PATH=new r,this.REAL_FILE_PATH=new r,this.REAL_DIRECTORY_PATH=new r,Object.freeze(this)}}},926:function(e){"use strict";e.exports=class{constructor(){this._store=function(){let e=Object.create(null);return e._cache=1,delete e._cache,e}()}set(e,t){return this._store[e]=t}get(e){return this._store[e]}has(e){return e in this._store}delete(e){delete this._store[e]}get size(){return Object.keys(this._store).length}}},554:function(e,t,i){"use strict";let r;var n,s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};let o=s(i(17)),a=s(i(57)),l=s(i(586)),h=["MODULE_NOT_FOUND","UNDECLARED_DEPENDENCY","MISSING_PEER_DEPENDENCY","MISSING_DEPENDENCY"],u=i(164),c=i(926),p=a.default._getRealFilePath,d=a.default._getRealDirectoryPath,m=a.default._findUpPackagePath,f=new u,g=new c;try{r=i(125)}catch(e){}function _(e,t){let i;return m(i=null==t||!0===t?g:!1===t?new c:t,o.default.resolve(e))}function O(e,t,i){let n,s;n=null==i||!0===i?f:!1===i?new u:i,t.charAt(t.length-1)!==o.default.sep&&(t=`${t}${o.default.sep}`);let c=e+"\0"+t;if(n.PATH.has(c))s=n.PATH.get(c);else{try{s=r?r.resolveToUnqualified(e+"/package.json",t):(0,a.default)(n,e,t)}catch(e){(0,l.default)(e,...h),s=null}n.PATH.set(c,s)}return s}O._resetCache=function(){f=new u,g=new c},(n=O||(O={}))._FIND_UP_CACHE=g,n.findUpPackagePath=_,Object.defineProperty(O,"_CACHE",{get:function(){return f}}),Object.defineProperty(O,"_FIND_UP_CACHE",{get:function(){return g}}),O.getRealFilePath=function(e){return p(f.REAL_FILE_PATH,e)},O.getRealDirectoryPath=function(e){return d(f.REAL_DIRECTORY_PATH,e)},e.exports=O},57:function(e,t,i){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};let n=i(147),s=i(17),o=i(863),a=r(i(586)),l=/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/,h=i(873)(process);function u(e,t){if(e.has(t))return e.get(t);let i=null;try{let e=n.statSync(t);(e.isFile()||e.isFIFO())&&(i=h?t:n.realpathSync(t))}catch(e){(0,a.default)(e,"ENOENT")}return e.set(t,i),i}function c(e,t){if(e.has(t))return e.get(t);let i=null;try{n.statSync(t).isDirectory()&&(i=h?t:n.realpathSync(t))}catch(e){(0,a.default)(e,"ENOENT","ENOTDIR")}return e.set(t,i),i}function p(e,t,i){let r=o(i),n=i;for(;n!==r;){let i="node_modules"===s.basename(n).toLowerCase(),r=u(e,s.join(n,i?"":"node_modules",t));if(r)return r;i&&(n=s.dirname(n)),n=s.dirname(n)}return null}function d(e,t,i){if("string"!=typeof t||0===t.length)throw TypeError("resolvePackagePath: 'name' must be a non-zero-length string.");let r=i||__dirname,n=s.resolve(r);for(;null===c(e.REAL_DIRECTORY_PATH,n);)n=s.dirname(n);if(!n){let e=TypeError("resolvePackagePath: 'dir' or one of the parent directories in its path must refer to a valid directory.");throw e.code="MODULE_NOT_FOUND",e}if(!l.test(t))return p(e.REAL_FILE_PATH,s.join(t,"package.json"),n);{let i=s.resolve(n,t);return u(e.REAL_FILE_PATH,s.join(i,"package.json"))}}d._findPackagePath=p,d._findUpPackagePath=function(e,t){let i,r;let o=t,a=null;do{if(e.has(o)){a=e.get(o);break}if(r=s.join(o,"package.json"),n.existsSync(r)){a=r;break}i=o,o=s.dirname(o)}while(o!==i);return e.set(t,a),a},d._getRealFilePath=u,d._getRealDirectoryPath=c,e.exports=d},586:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e,...t){if(null!==e&&"object"==typeof e){let i=e.code;for(let e of t)if(i===e)return}throw e}},873:function(e){"use strict";e.exports=function(e){return!!e.env.NODE_PRESERVE_SYMLINKS||function(e,t){for(let i=0;i<e.length;i++)if(e[i]===t)return!0;return!1}(e.execArgv,"--preserve-symlinks")}},907:function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"getESMPackages",{enumerable:!0,get:function(){return o}});let r=i(292),n=function(e){return e&&e.__esModule?e:{default:e}}(i(554)),s=i(17);async function o(e){let t={};async function i(i,o){let a=function(e,t,i){let{optionalDepsFromParent:r,isPatch:o,isRoot:a}=i,l=(0,n.default)(t,e);if(!l&&!r?.[t]&&!o){if(a)return(0,s.join)(e,"package.json");throw Error(`Non-optional dependency could not be found: ${t} when looking from ${e}`)}return l}(o?.parentPkgPath??e.pkgDir,i.value.name,{optionalDepsFromParent:o?.optionalDependencies,isPatch:i.value.isPatch,isRoot:i.value.isRoot});if(!a)return[{},!0];let l=t[i.value.name];if(l){if(l.some(e=>e.packageJsonPath===a))return[{},!1]}else l=[],t[i.value.name]=l;let h=JSON.parse((await (0,r.readFile)(a)).toString());return l.push({packageJsonPath:a,isModule:"module"===h.type}),[{optionalDependencies:h.optionalDependencies,parentPkgPath:a},!1]}return await e.topDownVisitAsync(i),Array.from(Object.keys(t).reduce((e,i)=>(t[i].forEach(t=>{t.isModule&&e.add(i)}),e),new Set))}},749:function(e,t,i){"use strict";function r(e,t){return Object.keys(e).forEach(function(i){"default"!==i&&!Object.prototype.hasOwnProperty.call(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[i]}})}),e}Object.defineProperty(t,"__esModule",{value:!0}),r(i(907),t),r(i(834),t)},834:function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e,t){for(var i in t)Object.defineProperty(e,i,{enumerable:!0,get:t[i]})}(t,{createNodeModulesTransformIgnore:function(){return s},getJestNodeModulesTransformIgnore:function(){return n}});let r=i(147);function n(e){let{file:t,extraExceptions:i=[]}=e;return s(Array.from(new Set([...function(e){try{let t=JSON.parse((0,r.readFileSync)(e).toString());if(!t.packages||!Array.isArray(t.packages))throw Error("Esm packages file object is missing the expected packages field!");return t.packages}catch(t){throw console.error(`Malformed esm modules file: ${e}`),t}}(t),...i])))}function s(e){return`node_modules/(?!${e.map(e=>`${e}/`).join("|")})`}},600:function(e,t){"use strict";function i(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"Graph",{enumerable:!0,get:function(){return r}});let r=class{getNodeKeyStr(e){return this.keySerializer?this.keySerializer(e):e}addDownstreamNode(e){let t=this.getNodeKeyStr(e.self);if(this.map.has(t)){let i=this.map.get(t);if(void 0!==i.value)throw Error(`Already added a downstream node of same key: ${t} - Can't add ${JSON.stringify(e)}`);i.to.push(...e.to),i.value=e.value}else this.map.set(t,{from:[],...e}),this.noFrom.add(t);e.to.forEach(t=>{let i=this.getNodeKeyStr(t);if(this.map.has(i)){let t=this.map.get(i);t.from.push(e.self),1===t.from.length&&this.noFrom.delete(i)}else this.map.set(i,{self:t,from:[e.self],to:[],value:void 0})})}validate(){let e=[];for(let[t,i]of this.map.entries())!i.value&&e.push(`Unregistered node: ${t}! Node was pointed to by: ${JSON.stringify(i.from)}`);if(e.length>0)throw Error(e.join("\n"))}async topDownVisitAsync(e,t){let i=t?new Set:void 0;for(let t of this.noFrom){let r=this.map.get(t);await this.visitDownNodeAsync(r,e,i)}}async visitDownNodeAsync(e,t,i,r){if(i?.has(this.getNodeKeyStr(e.self)))return;let[n,s]=await t(e,r);if(!s)await Promise.all(e.to.map(e=>this.visitDownNodeAsync(this.map.get(this.getNodeKeyStr(e)),t,i,n)))}constructor(e){i(this,"map",new Map),i(this,"noFrom",new Set),i(this,"keySerializer",void 0),this.keySerializer=e}}},278:function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"PackageGraph",{enumerable:!0,get:function(){return s}});let r=i(17),n=i(600),s=class extends n.Graph{constructor(e){var t,i,n;if(super(e=>`${e.name}@${e.version}`),t=this,n=void 0,(i="pkgDir")in t?Object.defineProperty(t,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[i]=n,!e)throw Error("Must supply a pkgDir!");this.pkgDir=(0,r.resolve)(e)}}},914:function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"getYarnInfoPackageGraph",{enumerable:!0,get:function(){return a}});let r=i(81),n=i(278),s=i(147),o=i(17);async function a(e,t){let i=(0,r.execSync)(`yarn info ${t?"-R":""} --json`,{cwd:e,stdio:"pipe"}),a=function e(t,i){let r=i??t,n=(0,o.join)(r,"package.json");if((0,s.existsSync)(n))return n;let a=(0,o.dirname)(r);if(!a)throw Error(`Could not find package.json traveling up from start dir at ${t}`);return e(t,a)}(e),h="";try{h=JSON.parse((0,s.readFileSync)(a).toString()).name}catch(e){throw console.error("Error retrieving root package name!"),e}let u=new n.PackageGraph(e),c=new Set;return i.toString().split("\n").reduce((e,i)=>{if(i.trim()){let e=JSON.parse(i),{name:r,version:n,isPatch:s}=l(e.value),o=u.keySerializer({name:r,version:n});if(!c.has(o)){let i;c.add(o),i=t?e.children?.Dependencies?.map(e=>{let t=l(e.locator);return{name:t.name,version:t.version}})??[]:[],u.addDownstreamNode({self:{name:r,version:n},value:{name:r,version:n,isPatch:s,isRoot:r===h},to:i??[]})}}return e},u)}function l(e){let t=e.indexOf("@",1);if(t<0)throw Error(`could not find version from name: ${e}`);let i=e.substring(t+1);if(i.startsWith("virtual:")){let e=i.lastIndexOf("#");if(e<1)throw Error("could not find the expected # for virtual locator information");i=i.substring(e+1)}return{name:e.substring(0,t),version:i,isPatch:i.includes("patch")}}},421:function(e,t,i){"use strict";function r(e,t){return Object.keys(e).forEach(function(i){"default"!==i&&!Object.prototype.hasOwnProperty.call(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[i]}})}),e}Object.defineProperty(t,"__esModule",{value:!0}),r(i(845),t),r(i(600),t),r(i(278),t),r(i(914),t)},845:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0})},81:function(e){"use strict";e.exports=require("child_process")},147:function(e){"use strict";e.exports=require("fs")},292:function(e){"use strict";e.exports=require("fs/promises")},718:function(e){"use strict";e.exports=require("node:child_process")},254:function(e){"use strict";e.exports=require("node:events")},561:function(e){"use strict";e.exports=require("node:fs")},411:function(e){"use strict";e.exports=require("node:path")},742:function(e){"use strict";e.exports=require("node:process")},17:function(e){"use strict";e.exports=require("path")},125:function(e){"use strict";e.exports=require("pnpapi")},673:function(e,t,i){let{Argument:r}=i(626),{Command:n}=i(306),{CommanderError:s,InvalidArgumentError:o}=i(649),{Help:a}=i(721),{Option:l}=i(533);t.program=new n,t.createCommand=e=>new n(e),t.createOption=(e,t)=>new l(e,t),t.createArgument=(e,t)=>new r(e,t),t.Command=n,t.Option=l,t.Argument=r,t.Help=a,t.CommanderError=s,t.InvalidArgumentError=o,t.InvalidOptionArgumentError=o},626:function(e,t,i){let{InvalidArgumentError:r}=i(649);t.Argument=class e{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e}this._name.length>3&&"..."===this._name.slice(-3)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(e,t){return t!==this.defaultValue&&Array.isArray(t)?t.concat(e):[e]}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new r(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},t.humanReadableArgName=function(e){let t=e.name()+(!0===e.variadic?"...":"");return e.required?"<"+t+">":"["+t+"]"}},306:function(e,t,i){let r=i(254).EventEmitter,n=i(718),s=i(411),o=i(561),a=i(742),{Argument:l,humanReadableArgName:h}=i(626),{CommanderError:u}=i(649),{Help:c}=i(721),{Option:p,DualOptions:d}=i(533),{suggestSimilar:m}=i(109);class f extends r{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._outputConfiguration={writeOut:e=>a.stdout.write(e),writeErr:e=>a.stderr.write(e),getOutHelpWidth:()=>a.stdout.isTTY?a.stdout.columns:void 0,getErrHelpWidth:()=>a.stderr.isTTY?a.stderr.columns:void 0,outputError:(e,t)=>t(e)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,i){let r=t,n=i;"object"==typeof r&&null!==r&&(n=r,r=null),n=n||{};let[,s,o]=e.match(/([^ ]+) *(.*)/),a=this.createCommand(s);return(r&&(a.description(r),a._executableHandler=!0),n.isDefault&&(this._defaultCommandName=a._name),a._hidden=!!(n.noHelp||n.hidden),a._executableFile=n.executableFile||null,o&&a.arguments(o),this._registerCommand(a),a.parent=this,a.copyInheritedSettings(this),r)?this:a}createCommand(e){return new f(e)}createHelp(){return Object.assign(new c,this.configureHelp())}configureHelp(e){return void 0===e?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return void 0===e?this._outputConfiguration:(Object.assign(this._outputConfiguration,e),this)}showHelpAfterError(e=!0){return"string"!=typeof e&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw Error(`Command passed to .addCommand() must have a name
3
+ - specify the name in Command constructor or using .name()`);return(t=t||{}).isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new l(e,t)}argument(e,t,i,r){let n=this.createArgument(e,t);return"function"==typeof i?n.default(r).argParser(i):n.default(i),this.addArgument(n),this}arguments(e){return e.trim().split(/ +/).forEach(e=>{this.argument(e)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t&&t.variadic)throw Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&void 0!==e.defaultValue&&void 0===e.parseArg)throw Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if("boolean"==typeof e)return this._addImplicitHelpCommand=e,this;let[,i,r]=(e=e??"help [command]").match(/([^ ]+) *(.*)/),n=t??"display help for command",s=this.createCommand(i);return s.helpOption(!1),r&&s.arguments(r),n&&s.description(n),this._addImplicitHelpCommand=!0,this._helpCommand=s,this}addHelpCommand(e,t){return"object"!=typeof e?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(void 0===this._helpCommand&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let i=["preSubcommand","preAction","postAction"];if(!i.includes(e))throw Error(`Unexpected value for event passed to hook : '${e}'.
4
+ Expecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=e=>{if("commander.executeSubCommandAsync"!==e.code)throw e},this}_exit(e,t,i){this._exitCallback&&this._exitCallback(new u(e,t,i)),a.exit(e)}action(e){return this._actionHandler=t=>{let i=this.registeredArguments.length,r=t.slice(0,i);return this._storeOptionsAsProperties?r[i]=this:r[i]=this.opts(),r.push(this),e.apply(this,r)},this}createOption(e,t){return new p(e,t)}_callParseArg(e,t,i,r){try{return e.parseArg(t,i)}catch(e){if("commander.invalidArgument"===e.code){let t=`${r} ${e.message}`;this.error(t,{exitCode:e.exitCode,code:e.code})}throw e}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let i=e.long&&this._findOption(e.long)?e.long:e.short;throw Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'
5
+ - already used by option '${t.flags}'`)}this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),i=t(e).find(e=>this._findCommand(e));if(i){let r=t(this._findCommand(i)).join("|"),n=t(e).join("|");throw Error(`cannot add command '${n}' as already have command '${r}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),i=e.attributeName();if(e.negate){let t=e.long.replace(/^--no-/,"--");!this._findOption(t)&&this.setOptionValueWithSource(i,void 0===e.defaultValue||e.defaultValue,"default")}else void 0!==e.defaultValue&&this.setOptionValueWithSource(i,e.defaultValue,"default");let r=(t,r,n)=>{null==t&&void 0!==e.presetArg&&(t=e.presetArg);let s=this.getOptionValue(i);null!==t&&e.parseArg?t=this._callParseArg(e,t,s,r):null!==t&&e.variadic&&(t=e._concatValue(t,s)),null==t&&(t=!e.negate&&(!!e.isBoolean()||!!e.optional||"")),this.setOptionValueWithSource(i,t,n)};return this.on("option:"+t,t=>{let i=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,i,"cli")}),e.envVar&&this.on("optionEnv:"+t,t=>{let i=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,i,"env")}),this}_optionEx(e,t,i,r,n){if("object"==typeof t&&t instanceof p)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let s=this.createOption(t,i);if(s.makeOptionMandatory(!!e.mandatory),"function"==typeof r)s.default(n).argParser(r);else if(r instanceof RegExp){let e=r;r=(t,i)=>{let r=e.exec(t);return r?r[0]:i},s.default(n).argParser(r)}else s.default(r);return this.addOption(s)}option(e,t,i,r){return this._optionEx({},e,t,i,r)}requiredOption(e,t,i,r){return this._optionEx({mandatory:!0},e,t,i,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,i){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=i,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(i=>{void 0!==i.getOptionValueSource(e)&&(t=i.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){let i;if(void 0!==e&&!Array.isArray(e))throw Error("first parameter to parse must be array or undefined");if(t=t||{},void 0===e&&void 0===t.from){a.versions?.electron&&(t.from="electron");let e=a.execArgv??[];(e.includes("-e")||e.includes("--eval")||e.includes("-p")||e.includes("--print"))&&(t.from="eval")}switch(void 0===e&&(e=a.argv),this.rawArgs=e.slice(),t.from){case void 0:case"node":this._scriptPath=e[1],i=e.slice(2);break;case"electron":a.defaultApp?(this._scriptPath=e[1],i=e.slice(2)):i=e.slice(1);break;case"user":i=e.slice(0);break;case"eval":i=e.slice(1);break;default:throw Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",i}parse(e,t){let i=this._prepareUserArgs(e,t);return this._parseCommand([],i),this}async parseAsync(e,t){let i=this._prepareUserArgs(e,t);return await this._parseCommand([],i),this}_executeSubCommand(e,t){let i;t=t.slice();let r=!1,l=[".js",".ts",".tsx",".mjs",".cjs"];function h(e,t){let i=s.resolve(e,t);if(o.existsSync(i))return i;if(l.includes(s.extname(t)))return;let r=l.find(e=>o.existsSync(`${i}${e}`));if(r)return`${i}${r}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let c=e._executableFile||`${this._name}-${e._name}`,p=this._executableDir||"";if(this._scriptPath){let e;try{e=o.realpathSync(this._scriptPath)}catch(t){e=this._scriptPath}p=s.resolve(s.dirname(e),p)}if(p){let t=h(p,c);if(!t&&!e._executableFile&&this._scriptPath){let i=s.basename(this._scriptPath,s.extname(this._scriptPath));i!==this._name&&(t=h(p,`${i}-${e._name}`))}c=t||c}r=l.includes(s.extname(c)),"win32"!==a.platform?r?(t.unshift(c),t=g(a.execArgv).concat(t),i=n.spawn(a.argv[0],t,{stdio:"inherit"})):i=n.spawn(c,t,{stdio:"inherit"}):(t.unshift(c),t=g(a.execArgv).concat(t),i=n.spawn(a.execPath,t,{stdio:"inherit"})),!i.killed&&["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(e=>{a.on(e,()=>{!1===i.killed&&null===i.exitCode&&i.kill(e)})});let d=this._exitCallback;i.on("close",e=>{e=e??1,d?d(new u(e,"commander.executeSubCommandAsync","(close)")):a.exit(e)}),i.on("error",t=>{if("ENOENT"===t.code){let t=p?`searched for local subcommand relative to directory '${p}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory";throw Error(`'${c}' does not exist
6
+ - if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
7
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
8
+ - ${t}`)}if("EACCES"===t.code)throw Error(`'${c}' not executable`);if(d){let e=new u(1,"commander.executeSubCommandAsync","(error)");e.nestedError=t,d(e)}else a.exit(1)}),this.runningCommand=i}_dispatchSubcommand(e,t,i){let r;let n=this._findCommand(e);return!n&&this.help({error:!0}),r=this._chainOrCallSubCommandHook(r,n,"preSubcommand"),r=this._chainOrCall(r,()=>{if(!n._executableHandler)return n._parseCommand(t,i);this._executeSubCommand(n,t.concat(i))})}_dispatchHelpCommand(e){!e&&this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((e,t)=>{e.required&&null==this.args[t]&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0)||!this.registeredArguments[this.registeredArguments.length-1].variadic)this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,i)=>{let r=t;if(null!==t&&e.parseArg){let n=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,i,n)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((i,r)=>{let n=i.defaultValue;i.variadic?r<this.args.length?(n=this.args.slice(r),i.parseArg&&(n=n.reduce((t,r)=>e(i,r,t),i.defaultValue))):void 0===n&&(n=[]):r<this.args.length&&(n=this.args[r],i.parseArg&&(n=e(i,n,i.defaultValue))),t[r]=n}),this.processedArgs=t}_chainOrCall(e,t){return e&&e.then&&"function"==typeof e.then?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let i=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>void 0!==e._lifeCycleHooks[t]).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),"postAction"===t&&r.reverse(),r.forEach(e=>{i=this._chainOrCall(i,()=>e.callback(e.hookedCommand,this))}),i}_chainOrCallSubCommandHook(e,t,i){let r=e;return void 0!==this._lifeCycleHooks[i]&&this._lifeCycleHooks[i].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let i=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(i.operands),t=i.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&0===this.args.length&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(i.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0])},n=`command:${this.name()}`;if(this._actionHandler){let i;return r(),this._processArguments(),i=this._chainOrCallHooks(i,"preAction"),i=this._chainOrCall(i,()=>this._actionHandler(this.processedArgs)),this.parent&&(i=this._chainOrCall(i,()=>{this.parent.emit(n,e,t)})),i=this._chainOrCallHooks(i,"postAction")}if(this.parent&&this.parent.listenerCount(n))r(),this._processArguments(),this.parent.emit(n,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&void 0===e.getOptionValue(t.attributeName())&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return void 0!==this.getOptionValue(t)&&"default"!==this.getOptionValueSource(t)});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let i=e.find(e=>t.conflictsWith.includes(e.attributeName()));i&&this._conflictingOption(t,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],i=[],r=t,n=e.slice();function s(e){return e.length>1&&"-"===e[0]}let o=null;for(;n.length;){let e=n.shift();if("--"===e){r===i&&r.push(e),r.push(...n);break}if(o&&!s(e)){this.emit(`option:${o.name()}`,e);continue}if(o=null,s(e)){let t=this._findOption(e);if(t){if(t.required){let e=n.shift();void 0===e&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,e)}else if(t.optional){let e=null;n.length>0&&!s(n[0])&&(e=n.shift()),this.emit(`option:${t.name()}`,e)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(e.length>2&&"-"===e[0]&&"-"!==e[1]){let t=this._findOption(`-${e[1]}`);if(t){t.required||t.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${t.name()}`,e.slice(2)):(this.emit(`option:${t.name()}`),n.unshift(`-${e.slice(2)}`));continue}}if(/^--[^=]+=/.test(e)){let t=e.indexOf("="),i=this._findOption(e.slice(0,t));if(i&&(i.required||i.optional)){this.emit(`option:${i.name()}`,e.slice(t+1));continue}}if(s(e)&&(r=i),(this._enablePositionalOptions||this._passThroughOptions)&&0===t.length&&0===i.length){if(this._findCommand(e)){t.push(e),n.length>0&&i.push(...n);break}if(this._getHelpCommand()&&e===this._getHelpCommand().name()){t.push(e),n.length>0&&t.push(...n);break}else if(this._defaultCommandName){i.push(e),n.length>0&&i.push(...n);break}}if(this._passThroughOptions){r.push(e),n.length>0&&r.push(...n);break}r.push(e)}return{operands:t,unknown:i}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let i=0;i<t;i++){let t=this.options[i].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
9
+ `,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
10
+ `):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));let i=t||{},r=i.exitCode||1,n=i.code||"commander.error";this._exit(r,n,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in a.env){let t=e.attributeName();(void 0===this.getOptionValue(t)||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,a.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new d(this.options),t=e=>void 0!==this.getOptionValue(e)&&!["default","implied"].includes(this.getOptionValueSource(e));this.options.filter(i=>void 0!==i.implied&&t(i.attributeName())&&e.valueFromOption(this.getOptionValue(i.attributeName()),i)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let i=e=>{let t=e.attributeName(),i=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),n=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(void 0===r.presetArg&&!1===i||void 0!==r.presetArg&&i===r.presetArg)?r:n||e},r=e=>{let t=i(e),r=t.attributeName();return"env"===this.getOptionValueSource(r)?`environment variable '${t.envVar}'`:`option '${t.flags}'`},n=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(n,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);i=i.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=m(e,i)}let i=`error: unknown option '${e}'${t}`;this.error(i,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,i=this.parent?` for '${this.name()}'`:"",r=`error: too many arguments${i}. Expected ${t} argument${1===t?"":"s"} but got ${e.length}.`;this.error(r,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(e=>{i.push(e.name()),e.alias()&&i.push(e.alias())}),t=m(e,i)}let i=`error: unknown command '${e}'${t}`;this.error(i,{code:"commander.unknownCommand"})}version(e,t,i){if(void 0===e)return this._version;this._version=e,t=t||"-V, --version",i=i||"output the version number";let r=this.createOption(t,i);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on("option:"+r.name(),()=>{this._outputConfiguration.writeOut(`${e}
11
+ `),this._exit(0,"commander.version",e)}),this}description(e,t){return void 0===e&&void 0===t?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return void 0===e?this._summary:(this._summary=e,this)}alias(e){if(void 0===e)return this._aliases[0];let t=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error("Command alias can't be the same as its name");let i=this.parent?._findCommand(e);if(i){let t=[i.name()].concat(i.aliases()).join("|");throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return void 0===e?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(void 0===e){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>h(e));return[].concat(this.options.length||null!==this._helpOption?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?e:[]).join(" ")}return this._usage=e,this}name(e){return void 0===e?this._name:(this._name=e,this)}nameFromFilename(e){return this._name=s.basename(e,s.extname(e)),this}executableDir(e){return void 0===e?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp();return void 0===t.helpWidth&&(t.helpWidth=e&&e.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),t.formatHelp(this,t)}_getHelpContext(e){let t;let i={error:!!(e=e||{}).error};return t=i.error?e=>this._outputConfiguration.writeErr(e):e=>this._outputConfiguration.writeOut(e),i.write=e.write||t,i.command=this,i}outputHelp(e){let t;"function"==typeof e&&(t=e,e=void 0);let i=this._getHelpContext(e);this._getCommandAndAncestors().reverse().forEach(e=>e.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let r=this.helpInformation(i);if(t&&"string"!=typeof(r=t(r))&&!Buffer.isBuffer(r))throw Error("outputHelp callback must return a string or a Buffer");i.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(e=>e.emit("afterAllHelp",i))}helpOption(e,t){return"boolean"==typeof e?(e?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(e=e??"-h, --help",t=t??"display help for command",this._helpOption=this.createOption(e,t),this)}_getHelpOption(){return void 0===this._helpOption&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this}help(e){this.outputHelp(e);let t=a.exitCode||0;0===t&&e&&"function"!=typeof e&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let i=["beforeAll","before","after","afterAll"];if(!i.includes(e))throw Error(`Unexpected value for position to addHelpText.
12
+ Expecting one of '${i.join("', '")}'`);let r=`${e}Help`;return this.on(r,e=>{let i;(i="function"==typeof t?t({error:e.error,command:e.command}):t)&&e.write(`${i}
13
+ `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function g(e){return e.map(e=>{let t,i;if(!e.startsWith("--inspect"))return e;let r="127.0.0.1",n="9229";return(null!==(i=e.match(/^(--inspect(-brk)?)$/))?t=i[1]:null!==(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(t=i[1],/^\d+$/.test(i[3])?n=i[3]:r=i[3]):null!==(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(t=i[1],r=i[3],n=i[4]),t&&"0"!==n)?`${t}=${r}:${parseInt(n)+1}`:e})}t.Command=f},649:function(e,t){class i extends Error{constructor(e,t,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}}t.CommanderError=i,t.InvalidArgumentError=class e extends i{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}},721:function(e,t,i){let{humanReadableArgName:r}=i(626);t.Help=class e{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),i=e._getHelpCommand();return i&&!i._hidden&&t.push(i),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let i=e=>e.short?e.short.replace(/^-/,""):e.long.replace(/^--/,"");return i(e).localeCompare(i(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),i=e._getHelpOption();if(i&&!i.hidden){let r=i.short&&e._findOption(i.short),n=i.long&&e._findOption(i.long);r||n?i.long&&!n?t.push(e.createOption(i.long,i.description)):i.short&&!r&&t.push(e.createOption(i.short,i.description)):t.push(i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let i=e.parent;i;i=i.parent){let e=i.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return(e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(e=>e.description))?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>r(e)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,i)=>Math.max(e,t.subcommandTerm(i).length),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,i)=>Math.max(e,t.optionTerm(i).length),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,i)=>Math.max(e,t.optionTerm(i).length),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,i)=>Math.max(e,t.argumentTerm(i).length),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let i="";for(let t=e.parent;t;t=t.parent)i=t.name()+" "+i;return i+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];return(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(", ")}`),void 0!==e.defaultValue&&(e.required||e.optional||e.isBoolean()&&"boolean"==typeof e.defaultValue)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),void 0!==e.presetArg&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),void 0!==e.envVar&&t.push(`env: ${e.envVar}`),t.length>0)?`${e.description} (${t.join(", ")})`:e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(", ")}`),void 0!==e.defaultValue&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let i=`(${t.join(", ")})`;return e.description?`${e.description} ${i}`:i}return e.description}formatHelp(e,t){let i=t.padWidth(e,t),r=t.helpWidth||80;function n(e,n){if(n){let s=`${e.padEnd(i+2)}${n}`;return t.wrap(s,r-2,i+2)}return e}function s(e){return e.join("\n").replace(/^/gm," ".repeat(2))}let o=[`Usage: ${t.commandUsage(e)}`,""],a=t.commandDescription(e);a.length>0&&(o=o.concat([t.wrap(a,r,0),""]));let l=t.visibleArguments(e).map(e=>n(t.argumentTerm(e),t.argumentDescription(e)));l.length>0&&(o=o.concat(["Arguments:",s(l),""]));let h=t.visibleOptions(e).map(e=>n(t.optionTerm(e),t.optionDescription(e)));if(h.length>0&&(o=o.concat(["Options:",s(h),""])),this.showGlobalOptions){let i=t.visibleGlobalOptions(e).map(e=>n(t.optionTerm(e),t.optionDescription(e)));i.length>0&&(o=o.concat(["Global Options:",s(i),""]))}let u=t.visibleCommands(e).map(e=>n(t.subcommandTerm(e),t.subcommandDescription(e)));return u.length>0&&(o=o.concat(["Commands:",s(u),""])),o.join("\n")}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}wrap(e,t,i,r=40){let n=RegExp(`[\\n][ \\f\\t\\v\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+`);if(e.match(n))return e;let s=t-i;if(s<r)return e;let o=e.slice(0,i),a=e.slice(i).replace("\r\n","\n"),l=" ".repeat(i),h=`\\s\u200B`,u=RegExp(`
14
+ |.{1,${s-1}}([${h}]|$)|[^${h}]+?([${h}]|$)`,"g");return o+(a.match(u)||[]).map((e,t)=>"\n"===e?"":(t>0?l:"")+e.trimEnd()).join("\n")}}},533:function(e,t,i){let{InvalidArgumentError:r}=i(649);t.Option=class e{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let i=function(e){let t,i;let r=e.split(/[ |,]+/);return r.length>1&&!/^[[<]/.test(r[1])&&(t=r.shift()),i=r.shift(),!t&&/^-[^-]$/.test(i)&&(t=i,i=void 0),{shortFlag:t,longFlag:i}}(e);this.short=i.shortFlag,this.long=i.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return"string"==typeof e&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_concatValue(e,t){return t!==this.defaultValue&&Array.isArray(t)?t.concat(e):[e]}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new r(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(e,t):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return function(e){return e.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},t.DualOptions=class e{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e)}),this.negativeOptions.forEach((e,t)=>{this.positiveOptions.has(t)&&this.dualOptions.add(t)})}valueFromOption(e,t){let i=t.attributeName();if(!this.dualOptions.has(i))return!0;let r=this.negativeOptions.get(i).presetArg;return t.negate===((void 0!==r&&r)===e)}}},109:function(e,t){t.suggestSimilar=function(e,t){if(!t||0===t.length)return"";t=Array.from(new Set(t));let i=e.startsWith("--");i&&(e=e.slice(2),t=t.map(e=>e.slice(2)));let r=[],n=3;return(t.forEach(t=>{if(t.length<=1)return;let i=function(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let i=[];for(let t=0;t<=e.length;t++)i[t]=[t];for(let e=0;e<=t.length;e++)i[0][e]=e;for(let r=1;r<=t.length;r++)for(let n=1;n<=e.length;n++){let s=1;s=e[n-1]===t[r-1]?0:1,i[n][r]=Math.min(i[n-1][r]+1,i[n][r-1]+1,i[n-1][r-1]+s),n>1&&r>1&&e[n-1]===t[r-2]&&e[n-2]===t[r-1]&&(i[n][r]=Math.min(i[n][r],i[n-2][r-2]+1))}return i[e.length][t.length]}(e,t),s=Math.max(e.length,t.length);(s-i)/s>.4&&(i<n?(n=i,r=[t]):i===n&&r.push(t))}),r.sort((e,t)=>e.localeCompare(t)),i&&(r=r.map(e=>`--${e}`)),r.length>1)?`
15
+ (Did you mean one of ${r.join(", ")}?)`:1===r.length?`
16
+ (Did you mean ${r[0]}?)`:""}}},t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,i),s.exports}i.rv=function(){return"1.1.6"},i.ruid="bundler=rspack@1.1.6";var r={};(()=>{"use strict";var e;let t=i(673),r=i(749),n=i(421),s=i(147);function o(e,t){(0,s.writeFileSync)(t,JSON.stringify({description:`This is a programmatically created file via ${process.argv.join(" ")}`,packages:e},null,4))}t.program.addOption(new t.Option("-p, --pkgManager <pkgManager>","The package manager that you are running under - will be used to resolve modules").choices(["yarnv2+"]).makeOptionMandatory()).addOption(new t.Option("-o, --output <output>","How to output the package info").choices(["json","console","none"]).default("console","writes each package to the a line")).option("--cwd <cwd>").option("-r, --recurse","get all dependencies and not just direct ones",!1).option("-f, --file <file>","the file to output json to").option("-q, --quiet","if we should not output any values",!1),(async function e(e){let t;let{pkgManager:i,cwd:s=process.cwd(),recurse:a,output:l,file:h,quiet:u}=e;if("yarnv2+"===i)t=await (0,n.getYarnInfoPackageGraph)(s,a);else throw Error("Unimplemented package manager GetPackagesGraphFn mapping!");t.validate();let c=(await (0,r.getESMPackages)(t)).sort();if(!u)switch(l){case"json":console.log(JSON.stringify(c));break;case"console":console.log(c.join("\n"))}h&&o(c,h)})(t.program.parse(process.argv).opts()).then(()=>{process.exit()}).catch(e=>{console.error(e),process.exit(5)})})()})();
17
+ //# sourceMappingURL=get-esm-packages.js.map