@visulima/package 1.5.2 → 1.6.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/CHANGELOG.md +20 -0
- package/dist/chunk-3DGUP62F.cjs +9 -0
- package/dist/chunk-3DGUP62F.cjs.map +1 -0
- package/dist/{chunk-QYGSOB5F.js → chunk-3NJM5HV7.js} +2 -2
- package/dist/{chunk-DCD4MOHC.cjs → chunk-6N3YSMA2.cjs} +3 -3
- package/dist/chunk-6WZZWBWV.js +7 -0
- package/dist/chunk-6WZZWBWV.js.map +1 -0
- package/dist/{chunk-BBGTIP2U.js → chunk-75DR5C7M.js} +2 -2
- package/dist/{chunk-45ZLUVBF.cjs → chunk-AQMSM3GI.cjs} +3 -3
- package/dist/chunk-VGU7UU4D.js +12 -0
- package/dist/chunk-VGU7UU4D.js.map +1 -0
- package/dist/chunk-VH54OLZU.cjs +19 -0
- package/dist/chunk-VH54OLZU.cjs.map +1 -0
- package/dist/error.cjs +14 -0
- package/dist/error.cjs.map +1 -0
- package/dist/error.d.cts +9 -0
- package/dist/error.d.ts +9 -0
- package/dist/error.js +5 -0
- package/dist/error.js.map +1 -0
- package/dist/index.cjs +26 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/monorepo.cjs +3 -3
- package/dist/monorepo.js +2 -2
- package/dist/package-manager.cjs +10 -6
- package/dist/package-manager.d.cts +2 -1
- package/dist/package-manager.d.ts +2 -1
- package/dist/package-manager.js +1 -1
- package/dist/package.cjs +4 -4
- package/dist/package.js +2 -2
- package/package.json +13 -1
- package/dist/chunk-IRDIZG2L.cjs +0 -18
- package/dist/chunk-IRDIZG2L.cjs.map +0 -1
- package/dist/chunk-SUN6RRMM.js +0 -12
- package/dist/chunk-SUN6RRMM.js.map +0 -1
- /package/dist/{chunk-QYGSOB5F.js.map → chunk-3NJM5HV7.js.map} +0 -0
- /package/dist/{chunk-DCD4MOHC.cjs.map → chunk-6N3YSMA2.cjs.map} +0 -0
- /package/dist/{chunk-BBGTIP2U.js.map → chunk-75DR5C7M.js.map} +0 -0
- /package/dist/{chunk-45ZLUVBF.cjs.map → chunk-AQMSM3GI.cjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## @visulima/package [1.6.0](https://github.com/visulima/visulima/compare/@visulima/package@1.5.3...@visulima/package@1.6.0) (2024-04-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **package:** added new findPackageManagerSync and NotFoundPackageError ([8648de4](https://github.com/visulima/visulima/commit/8648de4f4ce1fa4b083646eb1245821a7465e55b))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* extended PackageNotFoundError, added missing tests ([63223c2](https://github.com/visulima/visulima/commit/63223c2cae1e6cefece97c8988c27da3d259a6ec))
|
|
12
|
+
* fixed broken commit ([8917816](https://github.com/visulima/visulima/commit/89178166ff5d18717fd2afb3c1c5d6c2bfb09602))
|
|
13
|
+
|
|
14
|
+
## @visulima/package [1.5.3](https://github.com/visulima/visulima/compare/@visulima/package@1.5.2...@visulima/package@1.5.3) (2024-04-01)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **package:** added missing export ([fa6a9f2](https://github.com/visulima/visulima/commit/fa6a9f2d0d2c4eead9389f937d36efab7d5263fd))
|
|
20
|
+
|
|
1
21
|
## @visulima/package [1.5.2](https://github.com/visulima/visulima/compare/@visulima/package@1.5.1...@visulima/package@1.5.2) (2024-03-30)
|
|
2
22
|
|
|
3
23
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVH54OLZU_cjs = require('./chunk-VH54OLZU.cjs');
|
|
4
|
+
|
|
5
|
+
var t=class extends Error{constructor(n,r){if(typeof n=="string"&&(n=[n]),n.length===0){super("Package was not found.");return}if(r===void 0)try{r=chunkVH54OLZU_cjs.d().packageManager;}catch{}r===void 0&&(r="npm"),super(`Package '${n.join(" ")}' was not found. Please install it using '${r} install ${n.join(" ")}'`);}get code(){return "PACKAGE_NOT_FOUND"}set code(n){throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND")}get name(){return "PackageNotFoundError"}set name(n){throw new Error("Cannot overwrite name of PackageNotFoundError")}},d=t;
|
|
6
|
+
|
|
7
|
+
exports.a = d;
|
|
8
|
+
//# sourceMappingURL=out.js.map
|
|
9
|
+
//# sourceMappingURL=chunk-3DGUP62F.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/error/package-not-found-error.ts"],"names":["PackageNotFoundError","packageName","packageManager","findPackageManagerSync","_name","package_not_found_error_default"],"mappings":"yCAKA,IAAMA,EAAN,cAAmC,KAAM,CAK9B,YAAYC,EAAgCC,EAAyB,CAMxE,GALI,OAAOD,GAAgB,WAEvBA,EAAc,CAACA,CAAW,GAG1BA,EAAY,SAAW,EAAG,CAC1B,MAAM,wBAAwB,EAC9B,MACJ,CAEA,GAAIC,IAAmB,OACnB,GAAI,CAIAA,EAHqBC,EAAuB,EAGd,cAClC,MAAQ,CAER,CAGAD,IAAmB,SAEnBA,EAAiB,OAGrB,MAAM,YAAYD,EAAY,KAAK,GAAG,CAAC,6CAA6CC,CAAc,YAAYD,EAAY,KAAK,GAAG,CAAC,GAAG,CAC1I,CAGA,IAAW,MAAe,CACtB,MAAO,mBACX,CAGA,IAAW,KAAKG,EAAO,CACnB,MAAM,IAAI,MAAM,yCAAyC,CAC7D,CAGA,IAAoB,MAAe,CAC/B,MAAO,sBACX,CAGA,IAAoB,KAAKA,EAAO,CAC5B,MAAM,IAAI,MAAM,+CAA+C,CACnE,CACJ,EAEOC,EAAQL","sourcesContent":["import { findPackageManagerSync } from \"../package-manager\";\n\n/**\n * Error thrown when a package was not found.\n */\nclass PackageNotFoundError extends Error {\n /**\n * @param {string} packageName - The name of the package that was not found.\n * @param {string} packageManager - The package manager used to install the package.\n */\n public constructor(packageName: string[] | string, packageManager?: string) {\n if (typeof packageName === \"string\") {\n // eslint-disable-next-line no-param-reassign\n packageName = [packageName];\n }\n\n if (packageName.length === 0) {\n super(\"Package was not found.\");\n return;\n }\n\n if (packageManager === undefined) {\n try {\n const foundManager = findPackageManagerSync();\n\n // eslint-disable-next-line no-param-reassign\n packageManager = foundManager.packageManager;\n } catch {\n // Empty\n }\n }\n\n if (packageManager === undefined) {\n // eslint-disable-next-line no-param-reassign\n packageManager = \"npm\";\n }\n\n super(`Package '${packageName.join(\" \")}' was not found. Please install it using '${packageManager} install ${packageName.join(\" \")}'`);\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style\n public get code(): string {\n return \"PACKAGE_NOT_FOUND\";\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types\n public set code(_name) {\n throw new Error(\"Cannot overwrite code PACKAGE_NOT_FOUND\");\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style\n public override get name(): string {\n return \"PackageNotFoundError\";\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types\n public override set name(_name) {\n throw new Error(\"Cannot overwrite name of PackageNotFoundError\");\n }\n}\n\nexport default PackageNotFoundError;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c } from './chunk-
|
|
1
|
+
import { c } from './chunk-VGU7UU4D.js';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { findUp, readJson } from '@visulima/fs';
|
|
4
4
|
import { NotFoundError } from '@visulima/fs/error';
|
|
@@ -8,4 +8,4 @@ var x=async n=>{let a=await findUp(["lerna.json","turbo.json"],{type:"file",...n
|
|
|
8
8
|
|
|
9
9
|
export { x as a };
|
|
10
10
|
//# sourceMappingURL=out.js.map
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
11
|
+
//# sourceMappingURL=chunk-3NJM5HV7.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVH54OLZU_cjs = require('./chunk-VH54OLZU.cjs');
|
|
4
4
|
var fs$1 = require('fs');
|
|
5
5
|
var fs = require('@visulima/fs');
|
|
6
6
|
var error = require('@visulima/fs/error');
|
|
7
7
|
var pathe = require('pathe');
|
|
8
8
|
|
|
9
|
-
var w=async n=>{let a=await fs.findUp(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(a?.endsWith("lerna.json")){let o=await fs.readJson(a);if(o.useWorkspaces||o.packages)return {path:pathe.dirname(a),strategy:"lerna"}}let s=a?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await
|
|
9
|
+
var w=async n=>{let a=await fs.findUp(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(a?.endsWith("lerna.json")){let o=await fs.readJson(a);if(o.useWorkspaces||o.packages)return {path:pathe.dirname(a),strategy:"lerna"}}let s=a?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await chunkVH54OLZU_cjs.c(n);if(["npm","yarn"].includes(o)){let t=pathe.join(r,"package.json");if(fs$1.existsSync(t)&&fs$1.readFileSync(pathe.join(r,"package.json"),"utf8").includes("workspaces"))return {path:r,strategy:s?"turbo":o}}else if(o==="pnpm"){let t=pathe.join(r,"pnpm-workspace.yaml");if(fs$1.existsSync(t))return {path:r,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof error.NotFoundError))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)};
|
|
10
10
|
|
|
11
11
|
exports.a = w;
|
|
12
12
|
//# sourceMappingURL=out.js.map
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-6N3YSMA2.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { d } from './chunk-VGU7UU4D.js';
|
|
2
|
+
|
|
3
|
+
var t=class extends Error{constructor(n,r){if(typeof n=="string"&&(n=[n]),n.length===0){super("Package was not found.");return}if(r===void 0)try{r=d().packageManager;}catch{}r===void 0&&(r="npm"),super(`Package '${n.join(" ")}' was not found. Please install it using '${r} install ${n.join(" ")}'`);}get code(){return "PACKAGE_NOT_FOUND"}set code(n){throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND")}get name(){return "PackageNotFoundError"}set name(n){throw new Error("Cannot overwrite name of PackageNotFoundError")}},f=t;
|
|
4
|
+
|
|
5
|
+
export { f as a };
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=chunk-6WZZWBWV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/error/package-not-found-error.ts"],"names":["PackageNotFoundError","packageName","packageManager","findPackageManagerSync","_name","package_not_found_error_default"],"mappings":"wCAKA,IAAMA,EAAN,cAAmC,KAAM,CAK9B,YAAYC,EAAgCC,EAAyB,CAMxE,GALI,OAAOD,GAAgB,WAEvBA,EAAc,CAACA,CAAW,GAG1BA,EAAY,SAAW,EAAG,CAC1B,MAAM,wBAAwB,EAC9B,MACJ,CAEA,GAAIC,IAAmB,OACnB,GAAI,CAIAA,EAHqBC,EAAuB,EAGd,cAClC,MAAQ,CAER,CAGAD,IAAmB,SAEnBA,EAAiB,OAGrB,MAAM,YAAYD,EAAY,KAAK,GAAG,CAAC,6CAA6CC,CAAc,YAAYD,EAAY,KAAK,GAAG,CAAC,GAAG,CAC1I,CAGA,IAAW,MAAe,CACtB,MAAO,mBACX,CAGA,IAAW,KAAKG,EAAO,CACnB,MAAM,IAAI,MAAM,yCAAyC,CAC7D,CAGA,IAAoB,MAAe,CAC/B,MAAO,sBACX,CAGA,IAAoB,KAAKA,EAAO,CAC5B,MAAM,IAAI,MAAM,+CAA+C,CACnE,CACJ,EAEOC,EAAQL","sourcesContent":["import { findPackageManagerSync } from \"../package-manager\";\n\n/**\n * Error thrown when a package was not found.\n */\nclass PackageNotFoundError extends Error {\n /**\n * @param {string} packageName - The name of the package that was not found.\n * @param {string} packageManager - The package manager used to install the package.\n */\n public constructor(packageName: string[] | string, packageManager?: string) {\n if (typeof packageName === \"string\") {\n // eslint-disable-next-line no-param-reassign\n packageName = [packageName];\n }\n\n if (packageName.length === 0) {\n super(\"Package was not found.\");\n return;\n }\n\n if (packageManager === undefined) {\n try {\n const foundManager = findPackageManagerSync();\n\n // eslint-disable-next-line no-param-reassign\n packageManager = foundManager.packageManager;\n } catch {\n // Empty\n }\n }\n\n if (packageManager === undefined) {\n // eslint-disable-next-line no-param-reassign\n packageManager = \"npm\";\n }\n\n super(`Package '${packageName.join(\" \")}' was not found. Please install it using '${packageManager} install ${packageName.join(\" \")}'`);\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style\n public get code(): string {\n return \"PACKAGE_NOT_FOUND\";\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types\n public set code(_name) {\n throw new Error(\"Cannot overwrite code PACKAGE_NOT_FOUND\");\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style\n public override get name(): string {\n return \"PackageNotFoundError\";\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types\n public override set name(_name) {\n throw new Error(\"Cannot overwrite name of PackageNotFoundError\");\n }\n}\n\nexport default PackageNotFoundError;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a, b } from './chunk-
|
|
1
|
+
import { a, b } from './chunk-VGU7UU4D.js';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { findUp, findUpSync, readJsonSync } from '@visulima/fs';
|
|
4
4
|
import { dirname, join } from 'pathe';
|
|
@@ -7,4 +7,4 @@ var g=t=>{if(existsSync(join(t,"package.json"))){let n=readJsonSync(join(t,"pack
|
|
|
7
7
|
|
|
8
8
|
export { P as a, J as b };
|
|
9
9
|
//# sourceMappingURL=out.js.map
|
|
10
|
-
//# sourceMappingURL=chunk-
|
|
10
|
+
//# sourceMappingURL=chunk-75DR5C7M.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVH54OLZU_cjs = require('./chunk-VH54OLZU.cjs');
|
|
4
4
|
var fs$1 = require('fs');
|
|
5
5
|
var fs = require('@visulima/fs');
|
|
6
6
|
var pathe = require('pathe');
|
|
7
7
|
|
|
8
|
-
var g=t=>{if(fs$1.existsSync(pathe.join(t,"package.json"))){let n=fs.readJsonSync(pathe.join(t,"package.json"));if(n.name&&n.private!==!0)return "package.json"}},h=async t=>{try{let i=await
|
|
8
|
+
var g=t=>{if(fs$1.existsSync(pathe.join(t,"package.json"))){let n=fs.readJsonSync(pathe.join(t,"package.json"));if(n.name&&n.private!==!0)return "package.json"}},h=async t=>{try{let i=await chunkVH54OLZU_cjs.a(t);return pathe.dirname(i)}catch{}let n=await fs.findUp(".git/config",{...t&&{cwd:t},type:"file"});if(n)return pathe.dirname(pathe.dirname(n));let r=await fs.findUp(g,{...t&&{cwd:t},type:"file"});if(r)return pathe.dirname(r);throw new Error("Could not find root directory")},P=t=>{try{let i=chunkVH54OLZU_cjs.b(t);return pathe.dirname(i)}catch{}let n=fs.findUpSync(".git/config",{...t&&{cwd:t},type:"file"});if(n)return pathe.dirname(pathe.dirname(n));let r=fs.findUpSync(g,{...t&&{cwd:t},type:"file"});if(r)return pathe.dirname(r);throw new Error("Could not find root directory")};
|
|
9
9
|
|
|
10
10
|
exports.a = h;
|
|
11
11
|
exports.b = P;
|
|
12
12
|
//# sourceMappingURL=out.js.map
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-AQMSM3GI.cjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { e } from './chunk-U4YVB3GU.js';
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { findUp, findUpSync } from '@visulima/fs';
|
|
5
|
+
import { NotFoundError } from '@visulima/fs/error';
|
|
6
|
+
import { join, dirname } from 'pathe';
|
|
7
|
+
|
|
8
|
+
var o=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],m=a=>{let n;if(o.forEach(r=>{!n&&existsSync(join(a,r))&&(n=join(a,r));}),n)return n;let e$1=join(a,"package.json");if(existsSync(e$1)&&e(readFileSync(e$1,"utf8")).packageManager!==void 0)return e$1},f=a=>{if(!a)throw new NotFoundError("Could not find a package manager");if(a.endsWith("package.json")){let n=e(a);if(n.packageManager){let r=["npm","yarn","pnpm","bun"].find(l=>n.packageManager.startsWith(l));if(r)return {packageManager:r,path:dirname(a)}}}if(a.endsWith("yarn.lock"))return {packageManager:"yarn",path:dirname(a)};if(a.endsWith("package-lock.json")||a.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:dirname(a)};if(a.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:dirname(a)};if(a.endsWith("bun.lockb"))return {packageManager:"bun",path:dirname(a)};throw new NotFoundError("Could not find a package manager")},b=async a=>{let n=await findUp(o,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},j=a=>{let n=findUpSync(o,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},U=async a=>{let n=await findUp(m,{...a&&{cwd:a}});return f(n)},W=a=>{let n=findUpSync(m,{...a&&{cwd:a}});return f(n)},L=a=>execSync(`${a} --version`).toString("utf8").trim(),_=async()=>{if(!process.env.npm_config_user_agent)return;let a=process.env.npm_config_user_agent.split(" ")[0],n=a.lastIndexOf("/"),e=a.slice(0,Math.max(0,n));return {name:e==="npminstall"?"cnpm":e,version:a.slice(Math.max(0,n+1))}};
|
|
9
|
+
|
|
10
|
+
export { b as a, j as b, U as c, W as d, L as e, _ as f };
|
|
11
|
+
//# sourceMappingURL=out.js.map
|
|
12
|
+
//# sourceMappingURL=chunk-VGU7UU4D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","findUpSync","NotFoundError","dirname","join","lockFileNames","packageMangerFindUpMatcher","directory","lockFile","lockFileName","packageJsonFilePath","parsePackageJson","findPackageManagerOnFile","foundFile","packageJson","foundPackageManager","prefix","findLockFile","cwd","filePath","findLockFileSync","findPackageManager","findPackageManagerSync","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"wCAAA,OAAS,YAAAA,MAAgB,qBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,UAEzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,eACnC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAEvGC,EAA8BC,GAAsB,CACtD,IAAIC,EASJ,GAPAH,EAAc,QAASI,GAAiB,CAEhC,CAACD,GAAYV,EAAWM,EAAKG,EAAWE,CAAY,CAAC,IACrDD,EAAWJ,EAAKG,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBN,EAAKG,EAAW,cAAc,EAE1D,GAAIT,EAAWY,CAAmB,GAEVC,EAAiBZ,EAAaW,EAAqB,MAAM,CAAC,EAE9D,iBAAmB,OAC/B,OAAOA,CAKnB,EAEME,EAA4BC,GAAwD,CACtF,GAAI,CAACA,EACD,MAAM,IAAIX,EAAc,kCAAkC,EAG9D,GAAIW,EAAU,SAAS,cAAc,EAAG,CACpC,IAAMC,EAAcH,EAAiBE,CAAS,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,EAAWK,EAA4B,CACrD,GAAIY,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,OAAON,EAAyBC,CAAS,CAC7C,EAQaU,EAA4BC,GAAyB3B,EAAS,GAAG2B,CAAI,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK,EAWzGC,EAAmC,SAM3C,CACD,GAAI,CAAC,QAAQ,IAAI,sBACb,OAGJ,IAAMC,EAAS,QAAQ,IAAI,sBAAyB,MAAM,GAAG,EAAE,CAAC,EAC1DC,EAAeD,EAAO,YAAY,GAAG,EACrCF,EAAOE,EAAO,MAAM,EAAG,KAAK,IAAI,EAAGC,CAAY,CAAC,EAEtD,MAAO,CACH,KAAMH,IAAS,aAAe,OAAUA,EACxC,QAASE,EAAO,MAAM,KAAK,IAAI,EAAGC,EAAe,CAAC,CAAC,CACvD,CACJ","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\n\nimport { findUp, findUpSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\n\nconst packageMangerFindUpMatcher = (directory: string) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n};\n\nconst findPackageManagerOnFile = (foundFile: string | undefined): PackageManagerResult => {\n if (!foundFile) {\n throw new NotFoundError(\"Could not find a package manager\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = parsePackageJson(foundFile);\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new NotFoundError(\"Could not find a package manager\");\n};\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `URL | string`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport const findLockFileSync = (cwd?: URL | string): string => {\n const filePath = findUpSync(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\n};\n\n/**\n * An function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n\nexport const findPackageManagerSync = (cwd?: URL | string): PackageManagerResult => {\n const foundFile = findUpSync(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk6KT7465D_cjs = require('./chunk-6KT7465D.cjs');
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var fs$1 = require('fs');
|
|
6
|
+
var fs = require('@visulima/fs');
|
|
7
|
+
var error = require('@visulima/fs/error');
|
|
8
|
+
var pathe = require('pathe');
|
|
9
|
+
|
|
10
|
+
var o=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],m=a=>{let n;if(o.forEach(r=>{!n&&fs$1.existsSync(pathe.join(a,r))&&(n=pathe.join(a,r));}),n)return n;let e=pathe.join(a,"package.json");if(fs$1.existsSync(e)&&chunk6KT7465D_cjs.e(fs$1.readFileSync(e,"utf8")).packageManager!==void 0)return e},f=a=>{if(!a)throw new error.NotFoundError("Could not find a package manager");if(a.endsWith("package.json")){let n=chunk6KT7465D_cjs.e(a);if(n.packageManager){let r=["npm","yarn","pnpm","bun"].find(l=>n.packageManager.startsWith(l));if(r)return {packageManager:r,path:pathe.dirname(a)}}}if(a.endsWith("yarn.lock"))return {packageManager:"yarn",path:pathe.dirname(a)};if(a.endsWith("package-lock.json")||a.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:pathe.dirname(a)};if(a.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:pathe.dirname(a)};if(a.endsWith("bun.lockb"))return {packageManager:"bun",path:pathe.dirname(a)};throw new error.NotFoundError("Could not find a package manager")},S=async a=>{let n=await fs.findUp(o,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},b=a=>{let n=fs.findUpSync(o,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},j=async a=>{let n=await fs.findUp(m,{...a&&{cwd:a}});return f(n)},U=a=>{let n=fs.findUpSync(m,{...a&&{cwd:a}});return f(n)},W=a=>child_process.execSync(`${a} --version`).toString("utf8").trim(),L=async()=>{if(!process.env.npm_config_user_agent)return;let a=process.env.npm_config_user_agent.split(" ")[0],n=a.lastIndexOf("/"),e=a.slice(0,Math.max(0,n));return {name:e==="npminstall"?"cnpm":e,version:a.slice(Math.max(0,n+1))}};
|
|
11
|
+
|
|
12
|
+
exports.a = S;
|
|
13
|
+
exports.b = b;
|
|
14
|
+
exports.c = j;
|
|
15
|
+
exports.d = U;
|
|
16
|
+
exports.e = W;
|
|
17
|
+
exports.f = L;
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=chunk-VH54OLZU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","findUpSync","NotFoundError","dirname","join","lockFileNames","packageMangerFindUpMatcher","directory","lockFile","lockFileName","packageJsonFilePath","parsePackageJson","findPackageManagerOnFile","foundFile","packageJson","foundPackageManager","prefix","findLockFile","cwd","filePath","findLockFileSync","findPackageManager","findPackageManagerSync","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"yCAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KAEzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,eACnC,OAAS,iBAAAC,MAAqB,qBAC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,CAC9D,EAWae,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMnB,EAAOK,EAAe,CACzC,KAAM,OACN,GAAIa,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAEaC,EAAoBF,GAA+B,CAC5D,IAAMC,EAAWlB,EAAWI,EAAe,CACvC,KAAM,OACN,GAAIa,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAoBaE,EAAqB,MAAOH,GAAsD,CAC3F,IAAML,EAAY,MAAMb,EAAOM,EAA4B,CACvD,GAAIY,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,OAAON,EAAyBC,CAAS,CAC7C,EAcaS,EAA0BJ,GAA6C,CAChF,IAAML,EAAYZ,EAAWK,EAA4B,CACrD,GAAIY,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,OAAON,EAAyBC,CAAS,CAC7C,EAQaU,EAA4BC,GAAyB3B,EAAS,GAAG2B,CAAI,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK,EAWzGC,EAAmC,SAM3C,CACD,GAAI,CAAC,QAAQ,IAAI,sBACb,OAGJ,IAAMC,EAAS,QAAQ,IAAI,sBAAyB,MAAM,GAAG,EAAE,CAAC,EAC1DC,EAAeD,EAAO,YAAY,GAAG,EACrCF,EAAOE,EAAO,MAAM,EAAG,KAAK,IAAI,EAAGC,CAAY,CAAC,EAEtD,MAAO,CACH,KAAMH,IAAS,aAAe,OAAUA,EACxC,QAASE,EAAO,MAAM,KAAK,IAAI,EAAGC,EAAe,CAAC,CAAC,CACvD,CACJ","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\n\nimport { findUp, findUpSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\n\nconst packageMangerFindUpMatcher = (directory: string) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n};\n\nconst findPackageManagerOnFile = (foundFile: string | undefined): PackageManagerResult => {\n if (!foundFile) {\n throw new NotFoundError(\"Could not find a package manager\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = parsePackageJson(foundFile);\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new NotFoundError(\"Could not find a package manager\");\n};\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `URL | string`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport const findLockFileSync = (cwd?: URL | string): string => {\n const filePath = findUpSync(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\n};\n\n/**\n * An function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n\nexport const findPackageManagerSync = (cwd?: URL | string): PackageManagerResult => {\n const foundFile = findUpSync(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
|
package/dist/error.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk3DGUP62F_cjs = require('./chunk-3DGUP62F.cjs');
|
|
4
|
+
require('./chunk-VH54OLZU.cjs');
|
|
5
|
+
require('./chunk-6KT7465D.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, 'PackageNotFoundError', {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunk3DGUP62F_cjs.a; }
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=out.js.map
|
|
14
|
+
//# sourceMappingURL=error.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/error.d.cts
ADDED
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk3DGUP62F_cjs = require('./chunk-3DGUP62F.cjs');
|
|
4
|
+
var chunk6N3YSMA2_cjs = require('./chunk-6N3YSMA2.cjs');
|
|
5
|
+
var chunkAQMSM3GI_cjs = require('./chunk-AQMSM3GI.cjs');
|
|
6
|
+
var chunkVH54OLZU_cjs = require('./chunk-VH54OLZU.cjs');
|
|
6
7
|
var chunk6KT7465D_cjs = require('./chunk-6KT7465D.cjs');
|
|
7
8
|
var chunk4K7XWYTT_cjs = require('./chunk-4K7XWYTT.cjs');
|
|
8
9
|
var fs = require('fs');
|
|
@@ -10,35 +11,47 @@ var process = require('process');
|
|
|
10
11
|
var fs$1 = require('@visulima/fs');
|
|
11
12
|
var pathe = require('pathe');
|
|
12
13
|
|
|
13
|
-
var d=(r,e)=>(e?.create&&fs$1.ensureDirSync(r),r),
|
|
14
|
+
var d=(r,e)=>(e?.create&&fs$1.ensureDirSync(r),r),F=async(r,e)=>{if(process.env.CACHE_DIR&&!["0","1","false","true"].includes(process.env.CACHE_DIR))return d(pathe.join(process.env.CACHE_DIR,r),e);let s=await chunkAQMSM3GI_cjs.a(e?.cwd??process.cwd());if(!s)return;let o=pathe.join(s,"node_modules"),t=pathe.join(o,".cache"),i=pathe.join(t,r);if(!(fs.existsSync(i)&&!await fs$1.isAccessible(i,fs$1.W_OK))&&!(fs.existsSync(t)&&!await fs$1.isAccessible(t,fs$1.W_OK))&&!(fs.existsSync(o)&&!await fs$1.isAccessible(o,fs$1.W_OK)))return d(i,e)},L=(r,e)=>{if(process.env.CACHE_DIR&&!["0","1","false","true"].includes(process.env.CACHE_DIR))return d(pathe.join(process.env.CACHE_DIR,r),e);let s=chunkAQMSM3GI_cjs.b(e?.cwd??process.cwd());if(!s)return;let o=pathe.join(s,"node_modules"),t=pathe.join(o,".cache"),i=pathe.join(t,r);if(!(fs.existsSync(i)&&!fs$1.isAccessibleSync(i,fs$1.W_OK))&&!(fs.existsSync(t)&&!fs$1.isAccessibleSync(t,fs$1.W_OK))&&!(fs.existsSync(o)&&!fs$1.isAccessibleSync(o,fs$1.W_OK)))return d(i,e)};
|
|
14
15
|
|
|
16
|
+
Object.defineProperty(exports, 'PackageNotFoundError', {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunk3DGUP62F_cjs.a; }
|
|
19
|
+
});
|
|
15
20
|
Object.defineProperty(exports, 'findMonorepoRoot', {
|
|
16
21
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunk6N3YSMA2_cjs.a; }
|
|
18
23
|
});
|
|
19
24
|
Object.defineProperty(exports, 'findPackageRoot', {
|
|
20
25
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkAQMSM3GI_cjs.a; }
|
|
22
27
|
});
|
|
23
28
|
Object.defineProperty(exports, 'findPackageRootSync', {
|
|
24
29
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkAQMSM3GI_cjs.b; }
|
|
26
31
|
});
|
|
27
32
|
Object.defineProperty(exports, 'findLockFile', {
|
|
28
33
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunkVH54OLZU_cjs.a; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, 'findLockFileSync', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkVH54OLZU_cjs.b; }
|
|
30
39
|
});
|
|
31
40
|
Object.defineProperty(exports, 'findPackageManager', {
|
|
32
41
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunkVH54OLZU_cjs.c; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, 'findPackageManagerSync', {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunkVH54OLZU_cjs.d; }
|
|
34
47
|
});
|
|
35
48
|
Object.defineProperty(exports, 'getPackageManagerVersion', {
|
|
36
49
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
50
|
+
get: function () { return chunkVH54OLZU_cjs.e; }
|
|
38
51
|
});
|
|
39
52
|
Object.defineProperty(exports, 'identifyInitiatingPackageManager', {
|
|
40
53
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunkVH54OLZU_cjs.f; }
|
|
42
55
|
});
|
|
43
56
|
Object.defineProperty(exports, 'findPackageJson', {
|
|
44
57
|
enumerable: true,
|
|
@@ -84,7 +97,7 @@ Object.defineProperty(exports, 'writeTSConfig', {
|
|
|
84
97
|
enumerable: true,
|
|
85
98
|
get: function () { return chunk4K7XWYTT_cjs.g; }
|
|
86
99
|
});
|
|
87
|
-
exports.findCacheDirectory =
|
|
88
|
-
exports.findCacheDirectorySync =
|
|
100
|
+
exports.findCacheDirectory = F;
|
|
101
|
+
exports.findCacheDirectorySync = L;
|
|
89
102
|
//# sourceMappingURL=out.js.map
|
|
90
103
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/find-cache-dir.ts"],"names":["existsSync","cwd","env","ensureDirSync","isAccessible","isAccessibleSync","W_OK","join","useDirectory","directory","options","findCacheDirectory","name","rootDirectory","findPackageRoot","nodeModulesDirectory","cacheDirectory","cacheNameDirectory","findCacheDirectorySync","findPackageRootSync"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/find-cache-dir.ts"],"names":["existsSync","cwd","env","ensureDirSync","isAccessible","isAccessibleSync","W_OK","join","useDirectory","directory","options","findCacheDirectory","name","rootDirectory","findPackageRoot","nodeModulesDirectory","cacheDirectory","cacheNameDirectory","findCacheDirectorySync","findPackageRootSync"],"mappings":"+VACA,OAAS,cAAAA,MAAkB,KAC3B,OAAS,OAAAC,EAAK,OAAAC,MAAW,UAEzB,OAAS,iBAAAC,EAAe,gBAAAC,EAAc,oBAAAC,EAAkB,QAAAC,MAAY,eACpE,OAAS,QAAAC,MAAY,QASrB,IAAMC,EAAe,CAACC,EAAmBC,KACjCA,GAAS,QACTP,EAAcM,CAAS,EAGpBA,GAGEE,EAAqB,MAAOC,EAAcF,IAAmD,CACtG,GAAIR,EAAI,WAAgB,CAAC,CAAC,IAAK,IAAK,QAAS,MAAM,EAAE,SAASA,EAAI,SAAY,EAC1E,OAAOM,EAAaD,EAAKL,EAAI,UAAcU,CAAI,EAAGF,CAAO,EAG7D,IAAMG,EAAgB,MAAMC,EAAgBJ,GAAS,KAAOT,EAAI,CAAC,EAEjE,GAAI,CAACY,EACD,OAGJ,IAAME,EAAuBR,EAAKM,EAAe,cAAc,EACzDG,EAAiBT,EAAKQ,EAAsB,QAAQ,EACpDE,EAAqBV,EAAKS,EAAgBJ,CAAI,EAMpD,GAAI,EAAAZ,EAAWiB,CAAkB,GAAK,CAAE,MAAMb,EAAaa,EAAoBX,CAAI,IAK/E,EAAAN,EAAWgB,CAAc,GAAK,CAAE,MAAMZ,EAAaY,EAAgBV,CAAI,IAKvE,EAAAN,EAAWe,CAAoB,GAAK,CAAE,MAAMX,EAAaW,EAAsBT,CAAI,GAIvF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD,EAEaQ,EAAyB,CAACN,EAAcF,IAA0C,CAC3F,GAAIR,EAAI,WAAgB,CAAC,CAAC,IAAK,IAAK,QAAS,MAAM,EAAE,SAASA,EAAI,SAAY,EAC1E,OAAOM,EAAaD,EAAKL,EAAI,UAAcU,CAAI,EAAGF,CAAO,EAG7D,IAAMG,EAAgBM,EAAoBT,GAAS,KAAOT,EAAI,CAAC,EAE/D,GAAI,CAACY,EACD,OAGJ,IAAME,EAAuBR,EAAKM,EAAe,cAAc,EACzDG,EAAiBT,EAAKQ,EAAsB,QAAQ,EACpDE,EAAqBV,EAAKS,EAAgBJ,CAAI,EAMpD,GAAI,EAAAZ,EAAWiB,CAAkB,GAAK,CAACZ,EAAiBY,EAAoBX,CAAI,IAK5E,EAAAN,EAAWgB,CAAc,GAAK,CAACX,EAAiBW,EAAgBV,CAAI,IAKpE,EAAAN,EAAWe,CAAoB,GAAK,CAACV,EAAiBU,EAAsBT,CAAI,GAIpF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD","sourcesContent":["// eslint-disable-next-line unicorn/prevent-abbreviations\nimport { existsSync } from \"node:fs\";\nimport { cwd, env } from \"node:process\";\n\nimport { ensureDirSync, isAccessible, isAccessibleSync, W_OK } from \"@visulima/fs\";\nimport { join } from \"pathe\";\n\nimport { findPackageRoot, findPackageRootSync } from \"./package\";\n\ntype Options = {\n create?: boolean;\n cwd?: URL | string;\n};\n\nconst useDirectory = (directory: string, options?: Options): string => {\n if (options?.create) {\n ensureDirSync(directory);\n }\n\n return directory;\n};\n\nexport const findCacheDirectory = async (name: string, options?: Options): Promise<string | undefined> => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = await findPackageRoot(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !(await isAccessible(cacheNameDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !(await isAccessible(cacheDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !(await isAccessible(nodeModulesDirectory, W_OK))) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n\nexport const findCacheDirectorySync = (name: string, options?: Options): string | undefined => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = findPackageRootSync(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !isAccessibleSync(cacheNameDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !isAccessibleSync(cacheDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !isAccessibleSync(nodeModulesDirectory, W_OK)) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { PackageNotFoundError } from './error.cjs';
|
|
1
2
|
export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.cjs';
|
|
2
3
|
export { findPackageRoot, findPackageRootSync } from './package.cjs';
|
|
3
4
|
export { NormalizedReadResult, findPackageJson, findPackageJsonSync, parsePackageJson, writePackageJson, writePackageJsonSync } from './package-json.cjs';
|
|
4
|
-
export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.cjs';
|
|
5
|
+
export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.cjs';
|
|
5
6
|
import { T as TsConfigJsonResolved } from './types-hoigZ9HA.cjs';
|
|
6
7
|
export { N as NormalizedPackageJson, P as PackageJson } from './types-hoigZ9HA.cjs';
|
|
7
8
|
export { TsConfigResult, findTSConfig, findTSConfigSync, findTsConfig, findTsConfigSync, writeTSConfig } from './tsconfig.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { PackageNotFoundError } from './error.js';
|
|
1
2
|
export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.js';
|
|
2
3
|
export { findPackageRoot, findPackageRootSync } from './package.js';
|
|
3
4
|
export { NormalizedReadResult, findPackageJson, findPackageJsonSync, parsePackageJson, writePackageJson, writePackageJsonSync } from './package-json.js';
|
|
4
|
-
export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
|
|
5
|
+
export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
|
|
5
6
|
import { T as TsConfigJsonResolved } from './types-hoigZ9HA.js';
|
|
6
7
|
export { N as NormalizedPackageJson, P as PackageJson } from './types-hoigZ9HA.js';
|
|
7
8
|
export { TsConfigResult, findTSConfig, findTSConfigSync, findTsConfig, findTsConfigSync, writeTSConfig } from './tsconfig.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { a as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { a as
|
|
1
|
+
export { a as PackageNotFoundError } from './chunk-6WZZWBWV.js';
|
|
2
|
+
export { a as findMonorepoRoot } from './chunk-3NJM5HV7.js';
|
|
3
|
+
import { a, b } from './chunk-75DR5C7M.js';
|
|
4
|
+
export { a as findPackageRoot, b as findPackageRootSync } from './chunk-75DR5C7M.js';
|
|
5
|
+
export { a as findLockFile, b as findLockFileSync, c as findPackageManager, d as findPackageManagerSync, e as getPackageManagerVersion, f as identifyInitiatingPackageManager } from './chunk-VGU7UU4D.js';
|
|
5
6
|
export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-U4YVB3GU.js';
|
|
6
7
|
export { c as findTSConfig, e as findTSConfigSync, b as findTsConfig, d as findTsConfigSync, a as readTsConfig, g as writeTSConfig } from './chunk-OQ2PTROP.js';
|
|
7
8
|
import { existsSync } from 'node:fs';
|
|
@@ -9,8 +10,8 @@ import { env, cwd } from 'node:process';
|
|
|
9
10
|
import { isAccessible, W_OK, isAccessibleSync, ensureDirSync } from '@visulima/fs';
|
|
10
11
|
import { join } from 'pathe';
|
|
11
12
|
|
|
12
|
-
var d=(r,e)=>(e?.create&&ensureDirSync(r),r),
|
|
13
|
+
var d=(r,e)=>(e?.create&&ensureDirSync(r),r),L=async(r,e)=>{if(env.CACHE_DIR&&!["0","1","false","true"].includes(env.CACHE_DIR))return d(join(env.CACHE_DIR,r),e);let s=await a(e?.cwd??cwd());if(!s)return;let o=join(s,"node_modules"),t=join(o,".cache"),i=join(t,r);if(!(existsSync(i)&&!await isAccessible(i,W_OK))&&!(existsSync(t)&&!await isAccessible(t,W_OK))&&!(existsSync(o)&&!await isAccessible(o,W_OK)))return d(i,e)},j=(r,e)=>{if(env.CACHE_DIR&&!["0","1","false","true"].includes(env.CACHE_DIR))return d(join(env.CACHE_DIR,r),e);let s=b(e?.cwd??cwd());if(!s)return;let o=join(s,"node_modules"),t=join(o,".cache"),i=join(t,r);if(!(existsSync(i)&&!isAccessibleSync(i,W_OK))&&!(existsSync(t)&&!isAccessibleSync(t,W_OK))&&!(existsSync(o)&&!isAccessibleSync(o,W_OK)))return d(i,e)};
|
|
13
14
|
|
|
14
|
-
export {
|
|
15
|
+
export { L as findCacheDirectory, j as findCacheDirectorySync };
|
|
15
16
|
//# sourceMappingURL=out.js.map
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/find-cache-dir.ts"],"names":["existsSync","cwd","env","ensureDirSync","isAccessible","isAccessibleSync","W_OK","join","useDirectory","directory","options","findCacheDirectory","name","rootDirectory","findPackageRoot","nodeModulesDirectory","cacheDirectory","cacheNameDirectory","findCacheDirectorySync","findPackageRootSync"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/find-cache-dir.ts"],"names":["existsSync","cwd","env","ensureDirSync","isAccessible","isAccessibleSync","W_OK","join","useDirectory","directory","options","findCacheDirectory","name","rootDirectory","findPackageRoot","nodeModulesDirectory","cacheDirectory","cacheNameDirectory","findCacheDirectorySync","findPackageRootSync"],"mappings":"yVACA,OAAS,cAAAA,MAAkB,UAC3B,OAAS,OAAAC,EAAK,OAAAC,MAAW,eAEzB,OAAS,iBAAAC,EAAe,gBAAAC,EAAc,oBAAAC,EAAkB,QAAAC,MAAY,eACpE,OAAS,QAAAC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AAiBW,EAAgBV,CAAI,IAKpE,EAAAN,EAAWe,CAAoB,GAAK,CAACV,EAAiBU,EAAsBT,CAAI,GAIpF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD","sourcesContent":["// eslint-disable-next-line unicorn/prevent-abbreviations\nimport { existsSync } from \"node:fs\";\nimport { cwd, env } from \"node:process\";\n\nimport { ensureDirSync, isAccessible, isAccessibleSync, W_OK } from \"@visulima/fs\";\nimport { join } from \"pathe\";\n\nimport { findPackageRoot, findPackageRootSync } from \"./package\";\n\ntype Options = {\n create?: boolean;\n cwd?: URL | string;\n};\n\nconst useDirectory = (directory: string, options?: Options): string => {\n if (options?.create) {\n ensureDirSync(directory);\n }\n\n return directory;\n};\n\nexport const findCacheDirectory = async (name: string, options?: Options): Promise<string | undefined> => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = await findPackageRoot(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !(await isAccessible(cacheNameDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !(await isAccessible(cacheDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !(await isAccessible(nodeModulesDirectory, W_OK))) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n\nexport const findCacheDirectorySync = (name: string, options?: Options): string | undefined => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = findPackageRootSync(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !isAccessibleSync(cacheNameDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !isAccessibleSync(cacheDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !isAccessibleSync(nodeModulesDirectory, W_OK)) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n"]}
|
package/dist/monorepo.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunk6N3YSMA2_cjs = require('./chunk-6N3YSMA2.cjs');
|
|
4
|
+
require('./chunk-VH54OLZU.cjs');
|
|
5
5
|
require('./chunk-6KT7465D.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, 'findMonorepoRoot', {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunk6N3YSMA2_cjs.a; }
|
|
12
12
|
});
|
|
13
13
|
//# sourceMappingURL=out.js.map
|
|
14
14
|
//# sourceMappingURL=monorepo.cjs.map
|
package/dist/monorepo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { a as findMonorepoRoot } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { a as findMonorepoRoot } from './chunk-3NJM5HV7.js';
|
|
2
|
+
import './chunk-VGU7UU4D.js';
|
|
3
3
|
import './chunk-U4YVB3GU.js';
|
|
4
4
|
//# sourceMappingURL=out.js.map
|
|
5
5
|
//# sourceMappingURL=monorepo.js.map
|
package/dist/package-manager.cjs
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVH54OLZU_cjs = require('./chunk-VH54OLZU.cjs');
|
|
4
4
|
require('./chunk-6KT7465D.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, 'findLockFile', {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkVH54OLZU_cjs.a; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, 'findLockFileSync', {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkVH54OLZU_cjs.b; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, 'findPackageManager', {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkVH54OLZU_cjs.c; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, 'findPackageManagerSync', {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkVH54OLZU_cjs.d; }
|
|
19
23
|
});
|
|
20
24
|
Object.defineProperty(exports, 'getPackageManagerVersion', {
|
|
21
25
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkVH54OLZU_cjs.e; }
|
|
23
27
|
});
|
|
24
28
|
Object.defineProperty(exports, 'identifyInitiatingPackageManager', {
|
|
25
29
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkVH54OLZU_cjs.f; }
|
|
27
31
|
});
|
|
28
32
|
//# sourceMappingURL=out.js.map
|
|
29
33
|
//# sourceMappingURL=package-manager.cjs.map
|
|
@@ -6,10 +6,11 @@ type PackageManagerResult = {
|
|
|
6
6
|
path: string;
|
|
7
7
|
};
|
|
8
8
|
declare const findPackageManager: (cwd?: URL | string) => Promise<PackageManagerResult>;
|
|
9
|
+
declare const findPackageManagerSync: (cwd?: URL | string) => PackageManagerResult;
|
|
9
10
|
declare const getPackageManagerVersion: (name: string) => string;
|
|
10
11
|
declare const identifyInitiatingPackageManager: () => Promise<{
|
|
11
12
|
name: PackageManager | "cnpm";
|
|
12
13
|
version: string;
|
|
13
14
|
} | undefined>;
|
|
14
15
|
|
|
15
|
-
export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
|
|
16
|
+
export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, getPackageManagerVersion, identifyInitiatingPackageManager };
|
|
@@ -6,10 +6,11 @@ type PackageManagerResult = {
|
|
|
6
6
|
path: string;
|
|
7
7
|
};
|
|
8
8
|
declare const findPackageManager: (cwd?: URL | string) => Promise<PackageManagerResult>;
|
|
9
|
+
declare const findPackageManagerSync: (cwd?: URL | string) => PackageManagerResult;
|
|
9
10
|
declare const getPackageManagerVersion: (name: string) => string;
|
|
10
11
|
declare const identifyInitiatingPackageManager: () => Promise<{
|
|
11
12
|
name: PackageManager | "cnpm";
|
|
12
13
|
version: string;
|
|
13
14
|
} | undefined>;
|
|
14
15
|
|
|
15
|
-
export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
|
|
16
|
+
export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, getPackageManagerVersion, identifyInitiatingPackageManager };
|
package/dist/package-manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as findLockFile, b as findLockFileSync, c as findPackageManager, d as
|
|
1
|
+
export { a as findLockFile, b as findLockFileSync, c as findPackageManager, d as findPackageManagerSync, e as getPackageManagerVersion, f as identifyInitiatingPackageManager } from './chunk-VGU7UU4D.js';
|
|
2
2
|
import './chunk-U4YVB3GU.js';
|
|
3
3
|
//# sourceMappingURL=out.js.map
|
|
4
4
|
//# sourceMappingURL=package-manager.js.map
|
package/dist/package.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkAQMSM3GI_cjs = require('./chunk-AQMSM3GI.cjs');
|
|
4
|
+
require('./chunk-VH54OLZU.cjs');
|
|
5
5
|
require('./chunk-6KT7465D.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, 'findPackageRoot', {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkAQMSM3GI_cjs.a; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, 'findPackageRootSync', {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkAQMSM3GI_cjs.b; }
|
|
16
16
|
});
|
|
17
17
|
//# sourceMappingURL=out.js.map
|
|
18
18
|
//# sourceMappingURL=package.cjs.map
|
package/dist/package.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { a as findPackageRoot, b as findPackageRootSync } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { a as findPackageRoot, b as findPackageRootSync } from './chunk-75DR5C7M.js';
|
|
2
|
+
import './chunk-VGU7UU4D.js';
|
|
3
3
|
import './chunk-U4YVB3GU.js';
|
|
4
4
|
//# sourceMappingURL=out.js.map
|
|
5
5
|
//# sourceMappingURL=package.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/package",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "One Package to rule them all, finds your root-dir, monorepo, package manager or tsconfig.json",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"find-cache-directory",
|
|
11
11
|
"find-monorepo-root",
|
|
12
12
|
"find-up-pkg",
|
|
13
|
+
"find-package-manager",
|
|
13
14
|
"get-tsconfig",
|
|
14
15
|
"mono-repo",
|
|
15
16
|
"monorepo",
|
|
@@ -114,6 +115,16 @@
|
|
|
114
115
|
"default": "./dist/tsconfig.js"
|
|
115
116
|
}
|
|
116
117
|
},
|
|
118
|
+
"./error": {
|
|
119
|
+
"require": {
|
|
120
|
+
"types": "./dist/error.d.cts",
|
|
121
|
+
"default": "./dist/error.cjs"
|
|
122
|
+
},
|
|
123
|
+
"import": {
|
|
124
|
+
"types": "./dist/error.d.ts",
|
|
125
|
+
"default": "./dist/error.js"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
117
128
|
"./package.json": "./package.json"
|
|
118
129
|
},
|
|
119
130
|
"main": "dist/index.cjs",
|
|
@@ -208,6 +219,7 @@
|
|
|
208
219
|
}
|
|
209
220
|
},
|
|
210
221
|
"sources": [
|
|
222
|
+
"src/error.ts",
|
|
211
223
|
"src/index.ts",
|
|
212
224
|
"src/monorepo.ts",
|
|
213
225
|
"src/package.ts",
|
package/dist/chunk-IRDIZG2L.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunk6KT7465D_cjs = require('./chunk-6KT7465D.cjs');
|
|
4
|
-
var child_process = require('child_process');
|
|
5
|
-
var fs$1 = require('fs');
|
|
6
|
-
var fs = require('@visulima/fs');
|
|
7
|
-
var error = require('@visulima/fs/error');
|
|
8
|
-
var pathe = require('pathe');
|
|
9
|
-
|
|
10
|
-
var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],b=async a=>{let n=await fs.findUp(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},j=a=>{let n=fs.findUpSync(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},F=async a=>{let n=await fs.findUp(e=>{let t;if(g.forEach(o=>{!t&&fs$1.existsSync(pathe.join(e,o))&&(t=pathe.join(e,o));}),t)return t;let r=pathe.join(e,"package.json");if(fs$1.existsSync(r)&&chunk6KT7465D_cjs.e(fs$1.readFileSync(r,"utf8")).packageManager!==void 0)return r},{...a&&{cwd:a}});if(!n)throw new error.NotFoundError("Could not find a package manager");if(n.endsWith("package.json")){let e=chunk6KT7465D_cjs.e(n);if(e.packageManager){let r=["npm","yarn","pnpm","bun"].find(o=>e.packageManager.startsWith(o));if(r)return {packageManager:r,path:pathe.dirname(n)}}}if(n.endsWith("yarn.lock"))return {packageManager:"yarn",path:pathe.dirname(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:pathe.dirname(n)};if(n.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:pathe.dirname(n)};if(n.endsWith("bun.lockb"))return {packageManager:"bun",path:pathe.dirname(n)};throw new Error("Could not find a package manager")},S=a=>child_process.execSync(`${a} --version`).toString("utf8").trim(),W=async()=>{if(!process.env.npm_config_user_agent)return;let a=process.env.npm_config_user_agent.split(" ")[0],n=a.lastIndexOf("/"),e=a.slice(0,Math.max(0,n));return {name:e==="npminstall"?"cnpm":e,version:a.slice(Math.max(0,n+1))}};
|
|
11
|
-
|
|
12
|
-
exports.a = b;
|
|
13
|
-
exports.b = j;
|
|
14
|
-
exports.c = F;
|
|
15
|
-
exports.d = S;
|
|
16
|
-
exports.e = W;
|
|
17
|
-
//# sourceMappingURL=out.js.map
|
|
18
|
-
//# sourceMappingURL=chunk-IRDIZG2L.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","findUpSync","NotFoundError","dirname","join","lockFileNames","findLockFile","cwd","filePath","findLockFileSync","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","parsePackageJson","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"yCAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KAEzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,eACnC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMR,EAAOK,EAAe,CACzC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAEaC,EAAoBF,GAA+B,CAC5D,IAAMC,EAAWP,EAAWI,EAAe,CACvC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaE,EAAqB,MAAOH,GAAsD,CAC3F,IAAMI,EAAY,MAAMX,EAC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M,EAAE,KAAK,EAWzGC,EAAmC,SAM3C,CACD,GAAI,CAAC,QAAQ,IAAI,sBACb,OAGJ,IAAMC,EAAS,QAAQ,IAAI,sBAAyB,MAAM,GAAG,EAAE,CAAC,EAC1DC,EAAeD,EAAO,YAAY,GAAG,EACrCF,EAAOE,EAAO,MAAM,EAAG,KAAK,IAAI,EAAGC,CAAY,CAAC,EAEtD,MAAO,CACH,KAAMH,IAAS,aAAe,OAAUA,EACxC,QAASE,EAAO,MAAM,KAAK,IAAI,EAAGC,EAAe,CAAC,CAAC,CACvD,CACJ","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\n\nimport { findUp, findUpSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `URL | string`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport const findLockFileSync = (cwd?: URL | string): string => {\n const filePath = findUpSync(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory: string) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n },\n );\n\n if (!foundFile) {\n throw new NotFoundError(\"Could not find a package manager\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = parsePackageJson(foundFile);\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find a package manager\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
|
package/dist/chunk-SUN6RRMM.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { e } from './chunk-U4YVB3GU.js';
|
|
2
|
-
import { execSync } from 'node:child_process';
|
|
3
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
-
import { findUp, findUpSync } from '@visulima/fs';
|
|
5
|
-
import { NotFoundError } from '@visulima/fs/error';
|
|
6
|
-
import { join, dirname } from 'pathe';
|
|
7
|
-
|
|
8
|
-
var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],j=async a=>{let n=await findUp(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},F=a=>{let n=findUpSync(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},S=async a=>{let n=await findUp(e$1=>{let t;if(g.forEach(o=>{!t&&existsSync(join(e$1,o))&&(t=join(e$1,o));}),t)return t;let r=join(e$1,"package.json");if(existsSync(r)&&e(readFileSync(r,"utf8")).packageManager!==void 0)return r},{...a&&{cwd:a}});if(!n)throw new NotFoundError("Could not find a package manager");if(n.endsWith("package.json")){let e$1=e(n);if(e$1.packageManager){let r=["npm","yarn","pnpm","bun"].find(o=>e$1.packageManager.startsWith(o));if(r)return {packageManager:r,path:dirname(n)}}}if(n.endsWith("yarn.lock"))return {packageManager:"yarn",path:dirname(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:dirname(n)};if(n.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:dirname(n)};if(n.endsWith("bun.lockb"))return {packageManager:"bun",path:dirname(n)};throw new Error("Could not find a package manager")},W=a=>execSync(`${a} --version`).toString("utf8").trim(),_=async()=>{if(!process.env.npm_config_user_agent)return;let a=process.env.npm_config_user_agent.split(" ")[0],n=a.lastIndexOf("/"),e=a.slice(0,Math.max(0,n));return {name:e==="npminstall"?"cnpm":e,version:a.slice(Math.max(0,n+1))}};
|
|
9
|
-
|
|
10
|
-
export { j as a, F as b, S as c, W as d, _ as e };
|
|
11
|
-
//# sourceMappingURL=out.js.map
|
|
12
|
-
//# sourceMappingURL=chunk-SUN6RRMM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","findUpSync","NotFoundError","dirname","join","lockFileNames","findLockFile","cwd","filePath","findLockFileSync","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","parsePackageJson","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"wCAAA,OAAS,YAAAA,MAAgB,qBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,UAEzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,eACnC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMR,EAAOK,EAAe,CACzC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAEaC,EAAoBF,GAA+B,CAC5D,IAAMC,EAAWP,EAAWI,EAAe,CACvC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaE,EAAqB,MAAOH,GAAsD,CAC3F,IAAMI,EAAY,MAAMX,EACnBY,GAAsB,CACnB,IAAIC,EASJ,GAPAR,EAAc,QAASS,GAAiB,CAEhC,CAACD,GAAYf,EAAWM,EAAKQ,EAAWE,CAAY,CAAC,IACrDD,EAAWT,EAAKQ,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBX,EAAKQ,EAAW,cAAc,EAE1D,GAAId,EAAWiB,CAAmB,GAEVC,EAAiBjB,EAAagB,EAAqB,MAAM,CAAC,EAE9D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIR,GAAO,CAAE,IAAAA,CAAI,CACrB,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process\";\nimport { existsSync, readFileSync } from \"node:fs\";\n\nimport { findUp, findUpSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `URL | string`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport const findLockFileSync = (cwd?: URL | string): string => {\n const filePath = findUpSync(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory: string) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n },\n );\n\n if (!foundFile) {\n throw new NotFoundError(\"Could not find a package manager\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = parsePackageJson(foundFile);\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find a package manager\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|