@visulima/package 5.0.0-alpha.2 → 5.0.0-alpha.20
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 +251 -0
- package/LICENSE.md +1 -1
- package/dist/error.d.ts +15 -1
- package/dist/error.js +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.js +1 -1
- package/dist/lockfile.d.ts +114 -0
- package/dist/lockfile.js +1 -0
- package/dist/monorepo.d.ts +23 -22
- package/dist/monorepo.js +1 -1
- package/dist/package-json.d.ts +7 -138
- package/dist/package-json.js +3 -3
- package/dist/package-manager.d.ts +63 -63
- package/dist/package-manager.js +7 -7
- package/dist/package.d.ts +11 -10
- package/dist/package.js +1 -1
- package/dist/packem_shared/PackageNotFoundError--qHnCLzN.js +1 -0
- package/dist/packem_shared/package-json.d-R9WIRfmM.d.ts +173 -0
- package/dist/pnpm.d.ts +12 -11
- package/dist/pnpm.js +1 -1
- package/package.json +39 -36
- package/dist/error/package-not-found-error.d.ts +0 -15
- package/dist/packem_shared/PackageNotFoundError-BictYTIA.js +0 -1
- package/dist/types.d.ts +0 -37
- package/dist/utils/confirm.d.ts +0 -11
- package/dist/utils/is-node.d.ts +0 -2
package/dist/package-json.d.ts
CHANGED
|
@@ -1,138 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
resolveCatalogs?: boolean;
|
|
9
|
-
strict?: boolean;
|
|
10
|
-
yaml?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export type FindPackageJsonCache = Cache<NormalizedReadResult>;
|
|
13
|
-
export type NormalizedReadResult = {
|
|
14
|
-
packageJson: NormalizedPackageJson;
|
|
15
|
-
path: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* An asynchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
19
|
-
* @param cwd The current working directory.
|
|
20
|
-
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
21
|
-
* @returns A `Promise` that resolves to an object containing the parsed package data and the file path.
|
|
22
|
-
* The type of the returned promise is `Promise<NormalizedReadResult>`.
|
|
23
|
-
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
24
|
-
*/
|
|
25
|
-
export declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
|
|
26
|
-
/**
|
|
27
|
-
* A synchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
28
|
-
* @param cwd The current working directory.
|
|
29
|
-
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
30
|
-
* @returns An object containing the parsed package data and the file path.
|
|
31
|
-
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
32
|
-
*/
|
|
33
|
-
export declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
|
|
34
|
-
/**
|
|
35
|
-
* An asynchronous function to write the package.json file with the given data.
|
|
36
|
-
* @param data The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.
|
|
37
|
-
* @param options Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.
|
|
38
|
-
* This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options["cwd"]`.
|
|
39
|
-
* `cwd` represents the current working directory. If not specified, the default working directory will be used.
|
|
40
|
-
* @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.
|
|
41
|
-
*/
|
|
42
|
-
export declare const writePackageJson: <T = PackageJson>(data: T, options?: WriteJsonOptions & {
|
|
43
|
-
cwd?: URL | string;
|
|
44
|
-
}) => Promise<void>;
|
|
45
|
-
export declare const writePackageJsonSync: <T = PackageJson>(data: T, options?: WriteJsonOptions & {
|
|
46
|
-
cwd?: URL | string;
|
|
47
|
-
}) => void;
|
|
48
|
-
/**
|
|
49
|
-
* A synchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
50
|
-
* @param packageFile
|
|
51
|
-
* @param options
|
|
52
|
-
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
53
|
-
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
54
|
-
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
55
|
-
* @param options.strict Whether to throw errors on normalization warnings
|
|
56
|
-
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
57
|
-
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
58
|
-
* @returns
|
|
59
|
-
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
60
|
-
*/
|
|
61
|
-
export declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
|
|
62
|
-
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
63
|
-
ignoreWarnings?: (RegExp | string)[];
|
|
64
|
-
json5?: boolean;
|
|
65
|
-
resolveCatalogs?: boolean;
|
|
66
|
-
strict?: boolean;
|
|
67
|
-
yaml?: boolean;
|
|
68
|
-
}) => NormalizedPackageJson;
|
|
69
|
-
/**
|
|
70
|
-
* An asynchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
71
|
-
* @param packageFile
|
|
72
|
-
* @param options
|
|
73
|
-
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
74
|
-
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
75
|
-
* @param options.strict Whether to throw errors on normalization warnings
|
|
76
|
-
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
77
|
-
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
78
|
-
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
79
|
-
* @returns
|
|
80
|
-
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
81
|
-
*/
|
|
82
|
-
export declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
|
|
83
|
-
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
84
|
-
ignoreWarnings?: (RegExp | string)[];
|
|
85
|
-
json5?: boolean;
|
|
86
|
-
resolveCatalogs?: boolean;
|
|
87
|
-
strict?: boolean;
|
|
88
|
-
yaml?: boolean;
|
|
89
|
-
}) => Promise<NormalizedPackageJson>;
|
|
90
|
-
/**
|
|
91
|
-
* An asynchronous function to get the value of a property from the package.json file.
|
|
92
|
-
* @param packageJson
|
|
93
|
-
* @param property
|
|
94
|
-
* @param defaultValue
|
|
95
|
-
* @returns
|
|
96
|
-
*/
|
|
97
|
-
export declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
|
|
98
|
-
/**
|
|
99
|
-
* An asynchronous function to check if a property exists in the package.json file.
|
|
100
|
-
* @param packageJson
|
|
101
|
-
* @param property
|
|
102
|
-
* @returns
|
|
103
|
-
*/
|
|
104
|
-
export declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
|
|
105
|
-
/**
|
|
106
|
-
* An asynchronous function to check if any of the specified dependencies exist in the package.json file.
|
|
107
|
-
* @param packageJson
|
|
108
|
-
* @param arguments_
|
|
109
|
-
* @param options
|
|
110
|
-
* @param options.peerDeps Whether to include peer dependencies
|
|
111
|
-
* @returns
|
|
112
|
-
*/
|
|
113
|
-
export declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
|
|
114
|
-
peerDeps?: boolean;
|
|
115
|
-
}) => boolean;
|
|
116
|
-
/**
|
|
117
|
-
* An asynchronous function to ensure that the specified packages are installed in the package.json file.
|
|
118
|
-
* If the packages are not installed, the user will be prompted to install them.
|
|
119
|
-
* If the user agrees, the packages will be installed.
|
|
120
|
-
* If the user declines, the function will return without installing the packages.
|
|
121
|
-
* If the user does not respond, the function will return without installing the packages.
|
|
122
|
-
* @param packageJson
|
|
123
|
-
* @param packages
|
|
124
|
-
* @param installKey
|
|
125
|
-
* @param options
|
|
126
|
-
* @param options.deps Whether to include regular dependencies
|
|
127
|
-
* @param options.devDeps Whether to include development dependencies
|
|
128
|
-
* @param options.peerDeps Whether to include peer dependencies
|
|
129
|
-
* @param options.throwOnWarn Whether to throw an error when warnings are logged instead of just logging them
|
|
130
|
-
* @param options.logger Whether to use a custom logger
|
|
131
|
-
* @param options.confirm Whether to use a custom confirmation prompt
|
|
132
|
-
* @param options.installPackage Whether to use a custom installation package
|
|
133
|
-
* @param options.cwd Whether to use a custom current working directory
|
|
134
|
-
* @param options.dev Whether to use a custom installation key
|
|
135
|
-
* @returns
|
|
136
|
-
*/
|
|
137
|
-
export declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
|
|
138
|
-
export {};
|
|
1
|
+
import '@visulima/fs';
|
|
2
|
+
import 'type-fest';
|
|
3
|
+
export { F as FindPackageJsonCache, a as NormalizedReadResult, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, c as hasPackageJsonProperty, p as parsePackageJson, d as parsePackageJsonSync, w as writePackageJson, i as writePackageJsonSync } from "./packem_shared/package-json.d-R9WIRfmM.js";
|
|
4
|
+
import '@antfu/install-pkg';
|
|
5
|
+
import '@inquirer/core';
|
|
6
|
+
import '@inquirer/type';
|
|
7
|
+
import 'normalize-package-data';
|
package/dist/package-json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
${g(["gray"],"→")} ${s(r)}`),a(r)})})},"confirm"),
|
|
1
|
+
var V=Object.defineProperty;var f=(e,r)=>V(e,"name",{value:r,configurable:!0});import{createRequire as L}from"node:module";import{installPackage as X}from"@antfu/install-pkg";import{readJsonSync as H,readFileSync as Q,findUp as Z,findUpSync as ee,writeJson as re,writeJsonSync as ne,readJson as te,readFile as oe}from"@visulima/fs";import{NotFoundError as I}from"@visulima/fs/error";import{parseJson as T,toPath as A}from"@visulima/fs/utils";import{readYamlSync as se,readYaml as ae}from"@visulima/fs/yaml";import{join as _}from"@visulima/path";import F from"json5";import ie from"normalize-package-data";import{readPnpmCatalogsSync as D,resolveCatalogReferences as E,readPnpmCatalogs as C}from"./pnpm.js";const U=L(import.meta.url),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,J=f(e=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[r,t]=w.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return w.getBuiltinModule(e)}return U(e)},"__cjs_getBuiltinModule"),{existsSync:N}=J("node:fs"),{createInterface:ce}=J("node:readline"),{styleText:g}=J("node:util");var fe=Object.defineProperty,l=f((e,r)=>fe(e,"name",{value:r,configurable:!0}),"f");const d=l(e=>{const r=typeof e;return e!==null&&(r==="object"||r==="function")},"isObject"),pe=l(e=>{if(!d(e))return!1;for(const r in e)if(Object.hasOwn(e,r))return!1;return!0},"isEmptyObject"),O=new Set(["__proto__","prototype","constructor"]),W=1e6,le=l(e=>e>="0"&&e<="9","isDigit");function b(e){if(e==="0")return!0;if(/^[1-9]\d*$/.test(e)){const r=Number.parseInt(e,10);return r<=Number.MAX_SAFE_INTEGER&&r<=W}return!1}f(b,"p$1");l(b,"shouldCoerceToNumber");function P(e,r){return O.has(e)?!1:(e&&b(e)?r.push(Number.parseInt(e,10)):r.push(e),!0)}f(P,"y");l(P,"processSegment");function B(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);const r=[];let t="",n="start",o=!1,s=0;for(const a of e){if(s++,o){t+=a,o=!1;continue}if(a==="\\"){if(n==="index")throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(n==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);o=!0,n=n==="start"?"property":n;continue}switch(a){case".":{if(n==="index")throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(n==="indexEnd"){n="property";break}if(!P(t,r))return[];t="",n="property";break}case"[":{if(n==="index")throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(n==="indexEnd"){n="index";break}if(n==="property"||n==="start"){if((t||n==="property")&&!P(t,r))return[];t=""}n="index";break}case"]":{if(n==="index"){if(t==="")t=(r.pop()||"")+"[]",n="property";else{const i=Number.parseInt(t,10);!Number.isNaN(i)&&Number.isFinite(i)&&i>=0&&i<=Number.MAX_SAFE_INTEGER&&i<=W&&t===String(i)?r.push(i):r.push(t),t="",n="indexEnd"}break}if(n==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);t+=a;break}default:{if(n==="index"&&!le(a))throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(n==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);n==="start"&&(n="property"),t+=a}}}switch(o&&(t+="\\"),n){case"property":{if(!P(t,r))return[];break}case"index":throw new Error("Index was not closed");case"start":{r.push("");break}}return r}f(B,"parsePath");l(B,"parsePath");function k(e){if(typeof e=="string")return B(e);if(Array.isArray(e)){const r=[];for(const[t,n]of e.entries()){if(typeof n!="string"&&typeof n!="number")throw new TypeError(`Expected a string or number for path segment at index ${t}, got ${typeof n}`);if(typeof n=="number"&&!Number.isFinite(n))throw new TypeError(`Path segment at index ${t} must be a finite number, got ${n}`);if(O.has(n))return[];typeof n=="string"&&b(n)?r.push(Number.parseInt(n,10)):r.push(n)}return r}return[]}f(k,"d");l(k,"normalizePath");function h(e,r,t){if(!d(e)||typeof r!="string"&&!Array.isArray(r))return t===void 0?e:t;const n=k(r);if(n.length===0)return t;for(let o=0;o<n.length;o++){const s=n[o];if(e=e[s],e==null){if(o!==n.length-1)return t;break}}return e===void 0?t:e}f(h,"getProperty");l(h,"getProperty");function M(e,r,t){if(!d(e)||typeof r!="string"&&!Array.isArray(r))return e;const n=e,o=k(r);if(o.length===0)return e;for(let s=0;s<o.length;s++){const a=o[s];if(s===o.length-1)e[a]=t;else if(!d(e[a])){const i=typeof o[s+1]=="number";e[a]=i?[]:{}}e=e[a]}return n}f(M,"setProperty");l(M,"setProperty");function ue(e,r){if(!d(e)||typeof r!="string"&&!Array.isArray(r))return!1;const t=k(r);if(t.length===0)return!1;for(let n=0;n<t.length;n++){const o=t[n];if(n===t.length-1)return Object.hasOwn(e,o)?(delete e[o],!0):!1;if(e=e[o],!d(e))return!1}}f(ue,"deleteProperty");l(ue,"deleteProperty");function y(e,r){if(!d(e)||typeof r!="string"&&!Array.isArray(r))return!1;const t=k(r);if(t.length===0)return!1;for(const n of t){if(!d(e)||!(n in e))return!1;e=e[n]}return!0}f(y,"hasProperty");l(y,"hasProperty");function x(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}f(x,"escapePath");l(x,"escapePath");function R(e){const r=Object.entries(e);return Array.isArray(e)?r.map(([t,n])=>[b(t)?Number.parseInt(t,10):t,n]):r}f(R,"m$2");l(R,"normalizeEntries");function Y(e,r={}){if(!Array.isArray(e))throw new TypeError(`Expected an array, got ${typeof e}`);const{preferDotForIndices:t=!1}=r,n=[];for(const[o,s]of e.entries()){if(typeof s!="string"&&typeof s!="number")throw new TypeError(`Expected a string or number for path segment at index ${o}, got ${typeof s}`);if(typeof s=="number")if(!Number.isInteger(s)||s<0){const a=x(String(s));n.push(o===0?a:`.${a}`)}else t&&o>0?n.push(`.${s}`):n.push(`[${s}]`);else if(typeof s=="string")if(s==="")o===0||n.push(".");else if(b(s)){const a=Number.parseInt(s,10);t&&o>0?n.push(`.${a}`):n.push(`[${a}]`)}else{const a=x(s);n.push(o===0?a:`.${a}`)}}return n.join("")}f(Y,"stringifyPath");l(Y,"stringifyPath");function*S(e,r=[],t=new Set){if(!d(e)||pe(e)){r.length>0&&(yield Y(r));return}if(!t.has(e)){t.add(e);for(const[n,o]of R(e))r.push(n),yield*S(o,r,t),r.pop();t.delete(e)}}f(S,"x");l(S,"deepKeysIterator");function ge(e){return[...S(e)]}f(ge,"deepKeys");l(ge,"deepKeys");function de(e){const r={};if(!d(e))return r;for(const[t,n]of Object.entries(e))M(r,t,n);return r}f(de,"unflatten");l(de,"unflatten");var he=Object.defineProperty,j=f((e,r)=>he(e,"name",{value:r,configurable:!0}),"i");const ye=j(async e=>{const{default:r=!1,message:t,transformer:n}=e,o=j(a=>{const i=g(["cyan","bold"],"?"),c=g(["bold"],a),u=r?`${g(["greenBright"],"Y")}${g(["gray"],"/n")}`:`y/${g(["yellowBright"],"N")}`;return`${i} ${c} ${g(["gray"],`(${u})`)}`},"formatMessage"),s=j(a=>n?n(a):a?g(["greenBright"],"Yes"):g(["yellowBright"],"No"),"formatAnswer");return new Promise(a=>{const i=ce({input:process.stdin,output:process.stdout}),c=o(t);i.question(c,u=>{i.close();const m=u.trim().toLowerCase();if(m===""){a(r);return}if(m==="y"||m==="yes"){console.log(`${g(["greenBright"],"✓")} ${s(!0)}`),a(!0);return}if(m==="n"||m==="no"){console.log(`${g(["yellowBright"],"✗")} ${s(!1)}`),a(!1);return}console.log(`${g(["gray"],"→")} ${s(r)}`),a(r)}),i.on("SIGINT",()=>{i.close(),console.log(`
|
|
2
|
+
${g(["gray"],"→")} ${s(r)}`),a(r)})})},"confirm"),me=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window;var we=Object.defineProperty,p=f((e,r)=>we(e,"name",{value:r,configurable:!0}),"l");const q=/, ([^,]*)$/,$=new Map,z=new Map;class be extends Error{static{f(this,"M")}static{p(this,"PackageJsonValidationError")}constructor(r){super(`The following warnings were encountered while normalizing package data:
|
|
3
3
|
- ${r.join(`
|
|
4
|
-
- `)}`),this.name="PackageJsonValidationError"}}const v=p((e,r,t=[])=>{const n=[];if(
|
|
4
|
+
- `)}`),this.name="PackageJsonValidationError"}}const v=p((e,r,t=[])=>{const n=[];if(ie(e,o=>{n.push(o)},r),r&&n.length>0){const o=n.filter(s=>!t.some(a=>a instanceof RegExp?a.test(s):a===s));if(o.length>0)throw new be(o)}return e},"normalizeInput"),ke=p(async e=>await ae(e),"parseYamlFile"),Pe=p(e=>se(e),"parseYamlFileSync"),$e=p(async e=>{const r=await oe(e);return F.parse(r)},"parseJson5File"),Ee=p(e=>{const r=Q(e);return F.parse(r)},"parseJson5FileSync"),G=p(async(e,r)=>r?.yaml!==!1&&(e.endsWith(".yaml")||e.endsWith(".yml"))?ke(e):r?.json5!==!1&&e.endsWith(".json5")?$e(e):te(e),"parsePackageFile"),K=p((e,r)=>r?.yaml!==!1&&(e.endsWith(".yaml")||e.endsWith(".yml"))?Pe(e):r?.json5!==!1&&e.endsWith(".json5")?Ee(e):H(e),"parsePackageFileSync"),De=p(async(e,r={})=>{const t={type:"file"};e&&(t.cwd=e);const n=["package.json"];r.yaml!==!1&&n.push("package.yaml","package.yml"),r.json5!==!1&&n.push("package.json5");let o;for(const c of n)if(o=await Z(c,t),o)break;if(!o)throw new I(`No such file or directory, for ${n.join(", ").replace(q," or $1")} found.`);const s=r.cache&&typeof r.cache!="boolean"?r.cache:z;if(r.cache&&s.has(o))return s.get(o);const a=await G(o,r);if(r.resolveCatalogs){const c=await C(o);c&&E(a,c)}v(a,r.strict??!1,r.ignoreWarnings);const i={packageJson:a,path:o};return r.cache&&s.set(o,i),i},"findPackageJson"),Ce=p((e,r={})=>{const t={type:"file"};e&&(t.cwd=e);const n=["package.json"];r.yaml!==!1&&n.push("package.yaml","package.yml"),r.json5!==!1&&n.push("package.json5");let o;for(const c of n)if(o=ee(c,t),o)break;if(!o)throw new I(`No such file or directory, for ${n.join(", ").replace(q," or $1")} found.`);const s=r.cache&&typeof r.cache!="boolean"?r.cache:z;if(r.cache&&s.has(o))return s.get(o);const a=K(o,r);if(r.resolveCatalogs){const c=D(o);c&&E(a,c)}v(a,r.strict??!1,r.ignoreWarnings);const i={packageJson:a,path:o};return r.cache&&s.set(o,i),i},"findPackageJsonSync"),Oe=p(async(e,r={})=>{const{cwd:t,...n}=r,o=A(t??process.cwd());await re(_(o,"package.json"),e,n)},"writePackageJson"),We=p((e,r={})=>{const{cwd:t,...n}=r,o=A(t??process.cwd());ne(_(o,"package.json"),e,n)},"writePackageJsonSync"),Be=p((e,r)=>{const t=typeof e=="object"&&!Array.isArray(e);if(!t&&typeof e!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let n,o=!1,s;if(t)n=structuredClone(e);else if(N(e)){s=e;const i=r?.cache&&typeof r.cache!="boolean"?r.cache:$;if(r?.cache&&i.has(s))return i.get(s);n=K(s,r),o=!0}else n=T(e);if(r?.resolveCatalogs)if(o){const i=D(e);i&&E(n,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");v(n,r?.strict??!1,r?.ignoreWarnings);const a=n;return o&&r?.cache&&(typeof r.cache=="boolean"?$:r.cache).set(s,a),a},"parsePackageJsonSync"),Me=p(async(e,r)=>{const t=typeof e=="object"&&!Array.isArray(e);if(!t&&typeof e!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let n,o=!1,s;if(t)n=structuredClone(e);else if(N(e)){s=e;const i=r?.cache&&typeof r.cache!="boolean"?r.cache:$;if(r?.cache&&i.has(s))return i.get(s);n=await G(s,r),o=!0}else n=T(e);if(r?.resolveCatalogs)if(o){const i=await C(e);i&&E(n,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");v(n,r?.strict??!1,r?.ignoreWarnings);const a=n;return o&&r?.cache&&(typeof r.cache=="boolean"?$:r.cache).set(s,a),a},"parsePackageJson"),Re=p((e,r,t)=>h(e,r,t),"getPackageJsonProperty"),Ye=p((e,r)=>y(e,r),"hasPackageJsonProperty"),qe=p((e,r,t)=>{const n=h(e,"dependencies",{}),o=h(e,"devDependencies",{}),s=h(e,"peerDependencies",{}),a={...n,...o,...t?.peerDeps===!1?{}:s};for(const i of r)if(y(a,i))return!0;return!1},"hasPackageJsonAnyDependency"),ze=p(async(e,r,t="dependencies",n={})=>{const o=h(e,"dependencies",{}),s=h(e,"devDependencies",{}),a=h(e,"peerDependencies",{}),i=[],c={deps:!0,devDeps:!0,peerDeps:!1,...n};for(const u of r)c.deps&&y(o,u)||c.devDeps&&y(s,u)||c.peerDeps&&y(a,u)||i.push(u);if(i.length!==0){if(process.env.CI||me&&!process.stdout.isTTY){const u=`Skipping package installation for [${r.join(", ")}] because the process is not interactive.`;if(n.throwOnWarn)throw new Error(u);n.logger?.warn?n.logger.warn(u):console.warn(u);return}if(typeof c.confirm?.message=="function"&&(c.confirm.message=c.confirm.message(i)),c.confirm?.message===void 0){const u=`${i.length===1?"Package is":"Packages are"} required for this config: ${i.join(", ")}. Do you want to install them?`;c.confirm===void 0?c.confirm={message:u}:c.confirm.message=u}await ye(c.confirm)&&await X(i,{...c.installPackage,cwd:c.cwd?A(c.cwd):void 0,dev:t==="devDependencies"})}},"ensurePackages");export{ze as ensurePackages,De as findPackageJson,Ce as findPackageJsonSync,Re as getPackageJsonProperty,qe as hasPackageJsonAnyDependency,Ye as hasPackageJsonProperty,Me as parsePackageJson,Be as parsePackageJsonSync,Oe as writePackageJson,We as writePackageJsonSync};
|
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
* An asynchronous function that finds a lock file in the specified directory or any of its parent directories.
|
|
3
|
+
* @param cwd Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,
|
|
4
|
+
* specifically `URL | string`. Defaults to the current working directory.
|
|
5
|
+
* @returns A `Promise` that resolves with the path of the found lock file.
|
|
6
|
+
* The type of the returned promise is `Promise<string>`.
|
|
7
|
+
* @throws An `Error` if no lock file is found.
|
|
8
|
+
*/
|
|
9
|
+
declare const findLockFile: (cwd?: URL | string) => Promise<string>;
|
|
10
|
+
declare const findLockFileSync: (cwd?: URL | string) => string;
|
|
11
|
+
type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
|
|
12
|
+
type PackageManagerResult = {
|
|
13
|
+
packageManager: PackageManager;
|
|
14
|
+
path: string;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
* An asynchronous function that finds the package manager used in a project based on the presence of lock files
|
|
18
|
+
* or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.
|
|
19
|
+
* Throws an error if no lock file or package.json is found.
|
|
20
|
+
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`
|
|
21
|
+
* type, specifically `URL | string`.
|
|
22
|
+
* @returns A `Promise` that resolves to an object containing the package manager and path.
|
|
23
|
+
* The return type of the function is `Promise<PackageManagerResult>`.
|
|
24
|
+
* @throws An `Error` if no lock file or package.json is found.
|
|
25
|
+
*/
|
|
26
|
+
declare const findPackageManager: (cwd?: URL | string) => Promise<PackageManagerResult>;
|
|
27
27
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
* An function that finds the package manager used in a project based on the presence of lock files
|
|
29
|
+
* or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.
|
|
30
|
+
* Throws an error if no lock file or package.json is found.
|
|
31
|
+
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`
|
|
32
|
+
* type, specifically `URL | string`.
|
|
33
|
+
* @returns A `Promise` that resolves to an object containing the package manager and path.
|
|
34
|
+
* The return type of the function is `Promise<PackageManagerResult>`.
|
|
35
|
+
* @throws An `Error` if no lock file or package.json is found.
|
|
36
|
+
*/
|
|
37
|
+
declare const findPackageManagerSync: (cwd?: URL | string) => PackageManagerResult;
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
* Function that retrieves the version of the specified package manager.
|
|
40
|
+
* @param name The name of the package manager. The type of `name` is `string`.
|
|
41
|
+
* @returns The version of the package manager. The return type of the function is `string`.
|
|
42
|
+
*/
|
|
43
|
+
declare const getPackageManagerVersion: (name: string) => string;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} | undefined>;
|
|
45
|
+
* An asynchronous function that detects what package manager executes the process.
|
|
46
|
+
*
|
|
47
|
+
* Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.
|
|
48
|
+
* @returns An object containing the name and version of the package manager,
|
|
49
|
+
* or undefined if the package manager information cannot be determined.
|
|
50
|
+
*/
|
|
51
|
+
declare const identifyInitiatingPackageManager: () => {
|
|
52
|
+
name: PackageManager | "cnpm";
|
|
53
|
+
version: string;
|
|
54
|
+
} | undefined;
|
|
56
55
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
* Function that generates a message to install missing packages.
|
|
57
|
+
* @param packageName The name of the package that requires the missing packages.
|
|
58
|
+
* @param missingPackages An array of missing package names.
|
|
59
|
+
* @param options An object containing optional parameters:
|
|
60
|
+
* @param options.packageManagers An array of package managers to include in the message. Defaults to \["npm", "pnpm", "yarn"\].
|
|
61
|
+
* @param options.postMessage A string to append to the end of the message.
|
|
62
|
+
* @param options.preMessage A string to prepend to the beginning of the message.
|
|
63
|
+
* @returns A string message with instructions to install the missing packages using the specified package managers.
|
|
64
|
+
* @throws An `Error` if no package managers are provided in the options.
|
|
65
|
+
*/
|
|
66
|
+
declare const generateMissingPackagesInstallMessage: (packageName: string, missingPackages: string[], options: {
|
|
67
|
+
packageManagers?: PackageManager[];
|
|
68
|
+
postMessage?: string;
|
|
69
|
+
preMessage?: string;
|
|
71
70
|
}) => string;
|
|
71
|
+
export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager };
|
package/dist/package-manager.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
3
|
-
${
|
|
1
|
+
var b=Object.defineProperty;var g=(e,a)=>b(e,"name",{value:a,configurable:!0});import{createRequire as P}from"node:module";import{findUpSync as u,findUp as h}from"@visulima/fs";import{NotFoundError as k}from"@visulima/fs/error";import{join as l,dirname as i}from"@visulima/path";import{parsePackageJsonSync as M}from"./package-json.js";const $=P(import.meta.url),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,m=g(e=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[a,n]=s.versions.node.split(".").map(Number);if(a>22||a===22&&n>=3||a===20&&n>=16)return s.getBuiltinModule(e)}return $(e)},"__cjs_getBuiltinModule"),{execSync:S}=m("node:child_process"),{existsSync:f,readFileSync:F}=m("node:fs");var E=Object.defineProperty,r=g((e,a)=>E(e,"name",{value:a,configurable:!0}),"r");const d=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],y=r(e=>{let a;if(d.forEach(t=>{!a&&f(l(e,t))&&(a=l(e,t))}),a)return a;const n=l(e,"package.json");if(f(n)&&M(F(n,"utf8")).packageManager!==void 0)return n},"packageMangerFindUpMatcher"),w=r(e=>{if(!e)throw new k("Could not find a package manager");if(e.endsWith("package.json")){const a=M(e);if(a.packageManager){const n=["npm","yarn","pnpm","bun"].find(t=>a.packageManager.startsWith(t));if(n)return{packageManager:n,path:i(e)}}}if(e.endsWith("yarn.lock"))return{packageManager:"yarn",path:i(e)};if(e.endsWith("package-lock.json")||e.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:i(e)};if(e.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:i(e)};if(e.endsWith("bun.lockb"))return{packageManager:"bun",path:i(e)};throw new k("Could not find a package manager")},"resolvePackageManagerFromFile"),T=r(async e=>{const a=await h(d,{type:"file",...e&&{cwd:e}});if(!a)throw new Error("Could not find lock file");return a},"findLockFile"),U=r(e=>{const a=u(d,{type:"file",...e&&{cwd:e}});if(!a)throw new Error("Could not find lock file");return a},"findLockFileSync"),q=r(async e=>{const a=await h(y,{...e&&{cwd:e}});return w(a)},"findPackageManager"),B=r(e=>{const a=u(y,{...e&&{cwd:e}});return w(a)},"findPackageManagerSync"),D=r(e=>S(`${e} --version`).toString("utf8").trim(),"getPackageManagerVersion"),O=r(()=>{if(!process.env.npm_config_user_agent)return;const e=process.env.npm_config_user_agent.split(" ")[0],a=e.lastIndexOf("/"),n=e.slice(0,Math.max(0,a));return{name:n==="npminstall"?"cnpm":n,version:e.slice(Math.max(0,a+1))}},"identifyInitiatingPackageManager"),R=r((e,a,n)=>{const t=a.length===1?"":"s";if(n.packageManagers??=["npm","pnpm","yarn"],n.packageManagers.length===0)throw new Error("No package managers provided, please provide at least one package manager");if(a.length===0)throw new Error("No missing packages provided, please provide at least one missing package");let p=`
|
|
2
|
+
${n.preMessage??""}
|
|
3
|
+
${e} could not find the following package${t}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${a.join(`
|
|
6
6
|
`)}
|
|
7
7
|
|
|
8
|
-
To install the missing package${
|
|
9
|
-
`;const
|
|
8
|
+
To install the missing package${t}, please run the following command:
|
|
9
|
+
`;const v=r(o=>o.split("@").includes("@")?o:`${o}@latest`,"atLatest"),_=n.packageManagers.map(o=>{const c=a.map(j=>v(j)).join(" ");switch(o){case"bun":return` bun add ${c} -D`;case"npm":return` npm install ${c} --save-dev`;case"pnpm":return` pnpm add ${c} -D`;case"yarn":return` yarn add ${c} --dev`;default:throw new Error("Unknown package manager")}});return p+=_.join(`
|
|
10
10
|
|
|
11
11
|
or
|
|
12
12
|
|
|
13
|
-
`),
|
|
13
|
+
`),n.postMessage&&(p+=n.postMessage),p},"generateMissingPackagesInstallMessage");export{T as findLockFile,U as findLockFileSync,q as findPackageManager,B as findPackageManagerSync,R as generateMissingPackagesInstallMessage,D as getPackageManagerVersion,O as identifyInitiatingPackageManager};
|
package/dist/package.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
* An asynchronous function that finds the root directory of a project based on certain lookup criteria.
|
|
3
|
+
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is `string`.
|
|
4
|
+
* @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.
|
|
5
|
+
* @throws An `Error` if the root directory could not be found.
|
|
6
|
+
* @example
|
|
7
|
+
* const rootDirectory = await findPackageRoot();
|
|
8
|
+
* console.log(rootDirectory); // '/path/to/project'
|
|
9
|
+
*/
|
|
10
|
+
declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
|
|
11
|
+
declare const findPackageRootSync: (cwd?: URL | string) => string;
|
|
12
|
+
export { findPackageRoot, findPackageRootSync };
|
package/dist/package.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=Object.defineProperty;var c=(e,o)=>u(e,"name",{value:o,configurable:!0});import{createRequire as l}from"node:module";import{findUp as a,findUpSync as f,readJsonSync as _}from"@visulima/fs";import{dirname as r,join as d}from"@visulima/path";import{findLockFile as w,findLockFileSync as j}from"./package-manager.js";const g=l(import.meta.url),
|
|
1
|
+
var u=Object.defineProperty;var c=(e,o)=>u(e,"name",{value:o,configurable:!0});import{createRequire as l}from"node:module";import{findUp as a,findUpSync as f,readJsonSync as _}from"@visulima/fs";import{dirname as r,join as d}from"@visulima/path";import{findLockFile as w,findLockFileSync as j}from"./package-manager.js";const g=l(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=c(e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[o,t]=n.versions.node.split(".").map(Number);if(o>22||o===22&&t>=3||o===20&&t>=16)return n.getBuiltinModule(e)}return g(e)},"__cjs_getBuiltinModule"),{existsSync:m}=y("node:fs");var k=Object.defineProperty,s=c((e,o)=>k(e,"name",{value:o,configurable:!0}),"r");const p=s(e=>{if(m(d(e,"package.json"))){const o=_(d(e,"package.json"));if(o.name&&o.private!==!0)return"package.json"}},"packageJsonMatcher"),S=s(async e=>{try{const i=await w(e);return r(i)}catch{}const o=await a(".git/config",{...e&&{cwd:e},type:"file"});if(o)return r(r(o));const t=await a(p,{...e&&{cwd:e},type:"file"});if(t)return r(t);throw new Error("Could not find root directory")},"findPackageRoot"),q=s(e=>{try{const i=j(e);return r(i)}catch{}const o=f(".git/config",{...e&&{cwd:e},type:"file"});if(o)return r(r(o));const t=f(p,{...e&&{cwd:e},type:"file"});if(t)return r(t);throw new Error("Could not find root directory")},"findPackageRootSync");export{S as findPackageRoot,q as findPackageRootSync};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var a=(r,e)=>o(r,"name",{value:e,configurable:!0});import{findPackageManagerSync as n}from"../package-manager.js";var c=Object.defineProperty,s=a((r,e)=>c(r,"name",{value:e,configurable:!0}),"t");class g extends Error{static{a(this,"s")}static{s(this,"PackageNotFoundError")}constructor(e,t){if(typeof e=="string"&&(e=[e]),e.length===0){super("Package was not found.");return}if(t===void 0)try{t=n().packageManager}catch{}t??="npm",super(`Package '${e.join(" ")}' was not found. Please install it using '${t} install ${e.join(" ")}'`)}get code(){return"PACKAGE_NOT_FOUND"}set code(e){throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND")}get name(){return"PackageNotFoundError"}set name(e){throw new Error("Cannot overwrite name of PackageNotFoundError")}}export{g as default};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { WriteJsonOptions } from '@visulima/fs';
|
|
2
|
+
import { PackageJson as PackageJson$1, Paths, JsonObject } from 'type-fest';
|
|
3
|
+
import { InstallPackageOptions } from '@antfu/install-pkg';
|
|
4
|
+
import { Theme } from '@inquirer/core';
|
|
5
|
+
import { PartialDeep } from '@inquirer/type';
|
|
6
|
+
import { Package } from 'normalize-package-data';
|
|
7
|
+
type NormalizedPackageJson = Package & PackageJson;
|
|
8
|
+
type PackageJson = PackageJson$1;
|
|
9
|
+
type Cache<T = unknown> = Map<string, T>;
|
|
10
|
+
type EnsurePackagesOptions = {
|
|
11
|
+
/** Configuration for user confirmation prompts when installing packages */
|
|
12
|
+
confirm?: {
|
|
13
|
+
/** Default value for the confirmation prompt */
|
|
14
|
+
default?: boolean;
|
|
15
|
+
/** Message to display in the confirmation prompt, or a function that receives packages array */
|
|
16
|
+
message: string | ((packages: string[]) => string);
|
|
17
|
+
/** Theme configuration for the prompt interface */
|
|
18
|
+
theme?: PartialDeep<Theme>;
|
|
19
|
+
/** Function to transform the boolean value for display */
|
|
20
|
+
transformer?: (value: boolean) => string;
|
|
21
|
+
};
|
|
22
|
+
/** Current working directory for package operations */
|
|
23
|
+
cwd?: URL | string;
|
|
24
|
+
/** Whether to include regular dependencies in the operation */
|
|
25
|
+
deps?: boolean;
|
|
26
|
+
/** Whether to include development dependencies in the operation */
|
|
27
|
+
devDeps?: boolean;
|
|
28
|
+
/** Additional options for package installation (excluding cwd and dev which are handled separately) */
|
|
29
|
+
installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
|
|
30
|
+
/** Custom logger interface for warning messages */
|
|
31
|
+
logger?: {
|
|
32
|
+
warn: (message: string) => void;
|
|
33
|
+
};
|
|
34
|
+
/** Whether to include peer dependencies in the operation */
|
|
35
|
+
peerDeps?: boolean;
|
|
36
|
+
/** Whether to throw an error when warnings are logged instead of just logging them */
|
|
37
|
+
throwOnWarn?: boolean;
|
|
38
|
+
};
|
|
39
|
+
type ReadOptions = {
|
|
40
|
+
cache?: FindPackageJsonCache | boolean;
|
|
41
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
42
|
+
json5?: boolean;
|
|
43
|
+
resolveCatalogs?: boolean;
|
|
44
|
+
strict?: boolean;
|
|
45
|
+
yaml?: boolean;
|
|
46
|
+
};
|
|
47
|
+
type FindPackageJsonCache = Cache<NormalizedReadResult>;
|
|
48
|
+
type NormalizedReadResult = {
|
|
49
|
+
packageJson: NormalizedPackageJson;
|
|
50
|
+
path: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* An asynchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
54
|
+
* @param cwd The current working directory.
|
|
55
|
+
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
56
|
+
* @returns A `Promise` that resolves to an object containing the parsed package data and the file path.
|
|
57
|
+
* The type of the returned promise is `Promise<NormalizedReadResult>`.
|
|
58
|
+
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
59
|
+
*/
|
|
60
|
+
declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
|
|
61
|
+
/**
|
|
62
|
+
* A synchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
63
|
+
* @param cwd The current working directory.
|
|
64
|
+
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
65
|
+
* @returns An object containing the parsed package data and the file path.
|
|
66
|
+
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
67
|
+
*/
|
|
68
|
+
declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
|
|
69
|
+
/**
|
|
70
|
+
* An asynchronous function to write the package.json file with the given data.
|
|
71
|
+
* @param data The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.
|
|
72
|
+
* @param options Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.
|
|
73
|
+
* This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options["cwd"]`.
|
|
74
|
+
* `cwd` represents the current working directory. If not specified, the default working directory will be used.
|
|
75
|
+
* @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.
|
|
76
|
+
*/
|
|
77
|
+
declare const writePackageJson: (data: PackageJson, options?: WriteJsonOptions & {
|
|
78
|
+
cwd?: URL | string;
|
|
79
|
+
}) => Promise<void>;
|
|
80
|
+
declare const writePackageJsonSync: (data: PackageJson, options?: WriteJsonOptions & {
|
|
81
|
+
cwd?: URL | string;
|
|
82
|
+
}) => void;
|
|
83
|
+
/**
|
|
84
|
+
* A synchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
85
|
+
* @param packageFile
|
|
86
|
+
* @param options
|
|
87
|
+
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
88
|
+
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
89
|
+
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
90
|
+
* @param options.strict Whether to throw errors on normalization warnings
|
|
91
|
+
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
92
|
+
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
93
|
+
* @returns
|
|
94
|
+
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
95
|
+
*/
|
|
96
|
+
declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
|
|
97
|
+
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
98
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
99
|
+
json5?: boolean;
|
|
100
|
+
resolveCatalogs?: boolean;
|
|
101
|
+
strict?: boolean;
|
|
102
|
+
yaml?: boolean;
|
|
103
|
+
}) => NormalizedPackageJson;
|
|
104
|
+
/**
|
|
105
|
+
* An asynchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
106
|
+
* @param packageFile
|
|
107
|
+
* @param options
|
|
108
|
+
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
109
|
+
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
110
|
+
* @param options.strict Whether to throw errors on normalization warnings
|
|
111
|
+
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
112
|
+
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
113
|
+
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
114
|
+
* @returns
|
|
115
|
+
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
116
|
+
*/
|
|
117
|
+
declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
|
|
118
|
+
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
119
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
120
|
+
json5?: boolean;
|
|
121
|
+
resolveCatalogs?: boolean;
|
|
122
|
+
strict?: boolean;
|
|
123
|
+
yaml?: boolean;
|
|
124
|
+
}) => Promise<NormalizedPackageJson>;
|
|
125
|
+
/**
|
|
126
|
+
* An asynchronous function to get the value of a property from the package.json file.
|
|
127
|
+
* @param packageJson
|
|
128
|
+
* @param property
|
|
129
|
+
* @param defaultValue
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
|
|
133
|
+
/**
|
|
134
|
+
* An asynchronous function to check if a property exists in the package.json file.
|
|
135
|
+
* @param packageJson
|
|
136
|
+
* @param property
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
|
|
140
|
+
/**
|
|
141
|
+
* An asynchronous function to check if any of the specified dependencies exist in the package.json file.
|
|
142
|
+
* @param packageJson
|
|
143
|
+
* @param arguments_
|
|
144
|
+
* @param options
|
|
145
|
+
* @param options.peerDeps Whether to include peer dependencies
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
|
|
149
|
+
peerDeps?: boolean;
|
|
150
|
+
}) => boolean;
|
|
151
|
+
/**
|
|
152
|
+
* An asynchronous function to ensure that the specified packages are installed in the package.json file.
|
|
153
|
+
* If the packages are not installed, the user will be prompted to install them.
|
|
154
|
+
* If the user agrees, the packages will be installed.
|
|
155
|
+
* If the user declines, the function will return without installing the packages.
|
|
156
|
+
* If the user does not respond, the function will return without installing the packages.
|
|
157
|
+
* @param packageJson
|
|
158
|
+
* @param packages
|
|
159
|
+
* @param installKey
|
|
160
|
+
* @param options
|
|
161
|
+
* @param options.deps Whether to include regular dependencies
|
|
162
|
+
* @param options.devDeps Whether to include development dependencies
|
|
163
|
+
* @param options.peerDeps Whether to include peer dependencies
|
|
164
|
+
* @param options.throwOnWarn Whether to throw an error when warnings are logged instead of just logging them
|
|
165
|
+
* @param options.logger Whether to use a custom logger
|
|
166
|
+
* @param options.confirm Whether to use a custom confirmation prompt
|
|
167
|
+
* @param options.installPackage Whether to use a custom installation package
|
|
168
|
+
* @param options.cwd Whether to use a custom current working directory
|
|
169
|
+
* @param options.dev Whether to use a custom installation key
|
|
170
|
+
* @returns
|
|
171
|
+
*/
|
|
172
|
+
declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
|
|
173
|
+
export { EnsurePackagesOptions as E, FindPackageJsonCache as F, NormalizedPackageJson as N, PackageJson as P, NormalizedReadResult as a, findPackageJsonSync as b, hasPackageJsonProperty as c, parsePackageJsonSync as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, writePackageJsonSync as i, parsePackageJson as p, writePackageJson as w };
|