package-management 0.0.7 → 0.0.9
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/dist/index.cjs +30 -0
- package/dist/index.d.cts +21 -1
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.mjs +31 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ const gitignoreParser = require('parse-gitignore');
|
|
|
15
15
|
const WST = require('workspace-tools');
|
|
16
16
|
const utils = require('pathe/utils');
|
|
17
17
|
const os = require('node:os');
|
|
18
|
+
const jsoncParser = require('jsonc-parser');
|
|
18
19
|
|
|
19
20
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
20
21
|
|
|
@@ -973,6 +974,34 @@ function getGitRootFolder(options) {
|
|
|
973
974
|
return path__default$1.normalize(output.stdout);
|
|
974
975
|
}
|
|
975
976
|
|
|
977
|
+
function modifyJSONCFileSync({
|
|
978
|
+
edits,
|
|
979
|
+
filepath,
|
|
980
|
+
autoCommit = true
|
|
981
|
+
}) {
|
|
982
|
+
const jsoncContent = node_fs.readFileSync(filepath, "utf-8");
|
|
983
|
+
const modifiers = Array.isArray(edits) ? edits : [edits];
|
|
984
|
+
const editResult = modifiers.flatMap(
|
|
985
|
+
(edit) => jsoncParser.modify(jsoncContent, edit.paths, edit.update, {
|
|
986
|
+
formattingOptions: { tabSize: 0, insertSpaces: false }
|
|
987
|
+
})
|
|
988
|
+
);
|
|
989
|
+
const updatedFileContent = jsoncParser.applyEdits(jsoncContent, editResult);
|
|
990
|
+
const commit = () => node_fs.writeFileSync(filepath, updatedFileContent);
|
|
991
|
+
if (autoCommit) {
|
|
992
|
+
commit();
|
|
993
|
+
}
|
|
994
|
+
return {
|
|
995
|
+
updatedFileContent,
|
|
996
|
+
commit
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
const jsonc = (filepath) => {
|
|
1000
|
+
return {
|
|
1001
|
+
modify: (edits, options) => modifyJSONCFileSync({ edits, filepath, ...options })
|
|
1002
|
+
};
|
|
1003
|
+
};
|
|
1004
|
+
|
|
976
1005
|
exports._dirname = _dirname;
|
|
977
1006
|
exports._filename = _filename;
|
|
978
1007
|
exports.definePackage = definePackage;
|
|
@@ -997,6 +1026,7 @@ exports.importer = importer;
|
|
|
997
1026
|
exports.isDependencyInPackageJson = isDependencyInPackageJson;
|
|
998
1027
|
exports.isPackageDependency = isPackageDependency;
|
|
999
1028
|
exports.isPackageModuleFound = isPackageModuleFound;
|
|
1029
|
+
exports.jsonc = jsonc;
|
|
1000
1030
|
exports.packageManagerConfigs = packageManagerConfigs;
|
|
1001
1031
|
exports.predefinedPathAliases = predefinedPathAliases;
|
|
1002
1032
|
exports.project = project;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ import { InstallPackageOptions as InstallPackageOptions$1 } from '@antfu/install
|
|
|
5
5
|
import { ResolveOptions } from 'mlly';
|
|
6
6
|
import * as parse_gitignore from 'parse-gitignore';
|
|
7
7
|
import * as WST from 'workspace-tools';
|
|
8
|
+
import { JSONPath } from 'jsonc-parser';
|
|
8
9
|
|
|
9
10
|
type __<T> = {
|
|
10
11
|
[K in keyof T]: T[K];
|
|
@@ -719,4 +720,23 @@ declare const workspace: {
|
|
|
719
720
|
};
|
|
720
721
|
};
|
|
721
722
|
|
|
722
|
-
|
|
723
|
+
interface JSONCEdit {
|
|
724
|
+
paths: JSONPath;
|
|
725
|
+
update: unknown;
|
|
726
|
+
}
|
|
727
|
+
interface WriteJSONCFileOptions {
|
|
728
|
+
edits: JSONCEdit[] | JSONCEdit;
|
|
729
|
+
filepath: string;
|
|
730
|
+
autoCommit?: boolean;
|
|
731
|
+
}
|
|
732
|
+
type JSONCEdits = JSONCEdit[] | JSONCEdit;
|
|
733
|
+
declare const jsonc: (filepath: string) => {
|
|
734
|
+
modify: (edits: JSONCEdits, options?: {
|
|
735
|
+
filepath?: string | undefined;
|
|
736
|
+
} | undefined) => {
|
|
737
|
+
updatedFileContent: string;
|
|
738
|
+
commit: () => void;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
export { type AliasDefinition, type AliasDefinitionMap, type AliasMap, type AsyncCacheFn, type Awaitable, type DefinePackageFn, type DetectPackageManagerOptions, type Entry, type EntryOf, type EnumToLiteral, type ExtractImportOptionModule, type FindDependencyInPackageJsonOptions, type FromEntries, type Func, type GetPathOptions, type GetWorkspaceFolderOptions, type ImportCallback, type ImportList, type ImportMap, type ImportMapFn, type ImportMapOptions, type ImportModuleData, type ImportModuleFn, type ImportOption, type ImportOptionData, type ImportPackageData, type ImporterOptions, type InstallPackageOptions, type InstallerFn, type IsExactBoolean, type IsUnion, type JSONCEdit, type KeyOf, type KeyOfValue, type KnownPackageJson, type MergeObject, type Module, type NoInfer, type OmitByValue, type OmitIndexSignature, type OmitNever, type PackageDependencyItem, type PackageDependencyType, type PackageInfo, type PackageInfoList, type PackageInfoMap, type PackageJson, type PackageJsonPerson, type PackageManagerCommandName, type PackageManagerCommandSpec, type PackageManagerCommands, type PackageManagerConfig, type PackageManagerId, type PackageManagerScriptOptions, type PackageName, type PathAlias, type PathOptions, type PathTo, type PickByValue, type PickKeyOf, type PickPathAlias, type PredefinedPathAliases, type ProjectParams, type RequireExactlyOne, type ResolveModulePathOptions, type ResolvedImportList, type ResolvedImportListPromise, type ResolvedImportMap, type ResolvedImportMapPromise, type ResolvedImportOption, type ResolvedPromise, type Select, type SelectionMap, type StringLiteral, type UninstallPackageOptions, type ValueOf, type WriteJSONCFileOptions, type __, _dirname, _filename, definePackage, definePackageManagerClient, definePathAliases, dependencyTypeMap, detectGlobalPackageManagers, detectLockfilePackageManagers, detectPackageManagers, filterPackageManagers, findDependencyInPackageJson, findPackageManager, findPackageManagerSafely, findResolvedModulePath, getAliasMap, getFolderByPackageName, getGitRootFolder, getPackageFolder, getPath, getWorkspaceFolder, importMap, importer, isDependencyInPackageJson, isPackageDependency, isPackageModuleFound, jsonc, packageManagerConfigs, predefinedPathAliases, project, resolveModule, resolveModulePath, resolvePackageModulePath, workspace };
|
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ import { InstallPackageOptions as InstallPackageOptions$1 } from '@antfu/install
|
|
|
5
5
|
import { ResolveOptions } from 'mlly';
|
|
6
6
|
import * as parse_gitignore from 'parse-gitignore';
|
|
7
7
|
import * as WST from 'workspace-tools';
|
|
8
|
+
import { JSONPath } from 'jsonc-parser';
|
|
8
9
|
|
|
9
10
|
type __<T> = {
|
|
10
11
|
[K in keyof T]: T[K];
|
|
@@ -719,4 +720,23 @@ declare const workspace: {
|
|
|
719
720
|
};
|
|
720
721
|
};
|
|
721
722
|
|
|
722
|
-
|
|
723
|
+
interface JSONCEdit {
|
|
724
|
+
paths: JSONPath;
|
|
725
|
+
update: unknown;
|
|
726
|
+
}
|
|
727
|
+
interface WriteJSONCFileOptions {
|
|
728
|
+
edits: JSONCEdit[] | JSONCEdit;
|
|
729
|
+
filepath: string;
|
|
730
|
+
autoCommit?: boolean;
|
|
731
|
+
}
|
|
732
|
+
type JSONCEdits = JSONCEdit[] | JSONCEdit;
|
|
733
|
+
declare const jsonc: (filepath: string) => {
|
|
734
|
+
modify: (edits: JSONCEdits, options?: {
|
|
735
|
+
filepath?: string | undefined;
|
|
736
|
+
} | undefined) => {
|
|
737
|
+
updatedFileContent: string;
|
|
738
|
+
commit: () => void;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
export { type AliasDefinition, type AliasDefinitionMap, type AliasMap, type AsyncCacheFn, type Awaitable, type DefinePackageFn, type DetectPackageManagerOptions, type Entry, type EntryOf, type EnumToLiteral, type ExtractImportOptionModule, type FindDependencyInPackageJsonOptions, type FromEntries, type Func, type GetPathOptions, type GetWorkspaceFolderOptions, type ImportCallback, type ImportList, type ImportMap, type ImportMapFn, type ImportMapOptions, type ImportModuleData, type ImportModuleFn, type ImportOption, type ImportOptionData, type ImportPackageData, type ImporterOptions, type InstallPackageOptions, type InstallerFn, type IsExactBoolean, type IsUnion, type JSONCEdit, type KeyOf, type KeyOfValue, type KnownPackageJson, type MergeObject, type Module, type NoInfer, type OmitByValue, type OmitIndexSignature, type OmitNever, type PackageDependencyItem, type PackageDependencyType, type PackageInfo, type PackageInfoList, type PackageInfoMap, type PackageJson, type PackageJsonPerson, type PackageManagerCommandName, type PackageManagerCommandSpec, type PackageManagerCommands, type PackageManagerConfig, type PackageManagerId, type PackageManagerScriptOptions, type PackageName, type PathAlias, type PathOptions, type PathTo, type PickByValue, type PickKeyOf, type PickPathAlias, type PredefinedPathAliases, type ProjectParams, type RequireExactlyOne, type ResolveModulePathOptions, type ResolvedImportList, type ResolvedImportListPromise, type ResolvedImportMap, type ResolvedImportMapPromise, type ResolvedImportOption, type ResolvedPromise, type Select, type SelectionMap, type StringLiteral, type UninstallPackageOptions, type ValueOf, type WriteJSONCFileOptions, type __, _dirname, _filename, definePackage, definePackageManagerClient, definePathAliases, dependencyTypeMap, detectGlobalPackageManagers, detectLockfilePackageManagers, detectPackageManagers, filterPackageManagers, findDependencyInPackageJson, findPackageManager, findPackageManagerSafely, findResolvedModulePath, getAliasMap, getFolderByPackageName, getGitRootFolder, getPackageFolder, getPath, getWorkspaceFolder, importMap, importer, isDependencyInPackageJson, isPackageDependency, isPackageModuleFound, jsonc, packageManagerConfigs, predefinedPathAliases, project, resolveModule, resolveModulePath, resolvePackageModulePath, workspace };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { InstallPackageOptions as InstallPackageOptions$1 } from '@antfu/install
|
|
|
5
5
|
import { ResolveOptions } from 'mlly';
|
|
6
6
|
import * as parse_gitignore from 'parse-gitignore';
|
|
7
7
|
import * as WST from 'workspace-tools';
|
|
8
|
+
import { JSONPath } from 'jsonc-parser';
|
|
8
9
|
|
|
9
10
|
type __<T> = {
|
|
10
11
|
[K in keyof T]: T[K];
|
|
@@ -719,4 +720,23 @@ declare const workspace: {
|
|
|
719
720
|
};
|
|
720
721
|
};
|
|
721
722
|
|
|
722
|
-
|
|
723
|
+
interface JSONCEdit {
|
|
724
|
+
paths: JSONPath;
|
|
725
|
+
update: unknown;
|
|
726
|
+
}
|
|
727
|
+
interface WriteJSONCFileOptions {
|
|
728
|
+
edits: JSONCEdit[] | JSONCEdit;
|
|
729
|
+
filepath: string;
|
|
730
|
+
autoCommit?: boolean;
|
|
731
|
+
}
|
|
732
|
+
type JSONCEdits = JSONCEdit[] | JSONCEdit;
|
|
733
|
+
declare const jsonc: (filepath: string) => {
|
|
734
|
+
modify: (edits: JSONCEdits, options?: {
|
|
735
|
+
filepath?: string | undefined;
|
|
736
|
+
} | undefined) => {
|
|
737
|
+
updatedFileContent: string;
|
|
738
|
+
commit: () => void;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
export { type AliasDefinition, type AliasDefinitionMap, type AliasMap, type AsyncCacheFn, type Awaitable, type DefinePackageFn, type DetectPackageManagerOptions, type Entry, type EntryOf, type EnumToLiteral, type ExtractImportOptionModule, type FindDependencyInPackageJsonOptions, type FromEntries, type Func, type GetPathOptions, type GetWorkspaceFolderOptions, type ImportCallback, type ImportList, type ImportMap, type ImportMapFn, type ImportMapOptions, type ImportModuleData, type ImportModuleFn, type ImportOption, type ImportOptionData, type ImportPackageData, type ImporterOptions, type InstallPackageOptions, type InstallerFn, type IsExactBoolean, type IsUnion, type JSONCEdit, type KeyOf, type KeyOfValue, type KnownPackageJson, type MergeObject, type Module, type NoInfer, type OmitByValue, type OmitIndexSignature, type OmitNever, type PackageDependencyItem, type PackageDependencyType, type PackageInfo, type PackageInfoList, type PackageInfoMap, type PackageJson, type PackageJsonPerson, type PackageManagerCommandName, type PackageManagerCommandSpec, type PackageManagerCommands, type PackageManagerConfig, type PackageManagerId, type PackageManagerScriptOptions, type PackageName, type PathAlias, type PathOptions, type PathTo, type PickByValue, type PickKeyOf, type PickPathAlias, type PredefinedPathAliases, type ProjectParams, type RequireExactlyOne, type ResolveModulePathOptions, type ResolvedImportList, type ResolvedImportListPromise, type ResolvedImportMap, type ResolvedImportMapPromise, type ResolvedImportOption, type ResolvedPromise, type Select, type SelectionMap, type StringLiteral, type UninstallPackageOptions, type ValueOf, type WriteJSONCFileOptions, type __, _dirname, _filename, definePackage, definePackageManagerClient, definePathAliases, dependencyTypeMap, detectGlobalPackageManagers, detectLockfilePackageManagers, detectPackageManagers, filterPackageManagers, findDependencyInPackageJson, findPackageManager, findPackageManagerSafely, findResolvedModulePath, getAliasMap, getFolderByPackageName, getGitRootFolder, getPackageFolder, getPath, getWorkspaceFolder, importMap, importer, isDependencyInPackageJson, isPackageDependency, isPackageModuleFound, jsonc, packageManagerConfigs, predefinedPathAliases, project, resolveModule, resolveModulePath, resolvePackageModulePath, workspace };
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import ErrorStackParser from 'error-stack-parser';
|
|
|
2
2
|
import path$1, { normalize, basename, dirname, relative } from 'pathe';
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
5
|
+
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import { execa, execaSync } from 'execa';
|
|
7
7
|
import { asyncCacheFn } from 'async-cache-fn';
|
|
8
8
|
import { findUp } from 'find-up';
|
|
@@ -13,6 +13,7 @@ import gitignoreParser from 'parse-gitignore';
|
|
|
13
13
|
import * as WST from 'workspace-tools';
|
|
14
14
|
import { resolveAlias } from 'pathe/utils';
|
|
15
15
|
import os from 'node:os';
|
|
16
|
+
import { modify, applyEdits } from 'jsonc-parser';
|
|
16
17
|
|
|
17
18
|
const toArray = (data) => Array.isArray(data) ? data : [data];
|
|
18
19
|
const entriesOf = (o) => Object.entries(o);
|
|
@@ -949,4 +950,32 @@ function getGitRootFolder(options) {
|
|
|
949
950
|
return path$1.normalize(output.stdout);
|
|
950
951
|
}
|
|
951
952
|
|
|
952
|
-
|
|
953
|
+
function modifyJSONCFileSync({
|
|
954
|
+
edits,
|
|
955
|
+
filepath,
|
|
956
|
+
autoCommit = true
|
|
957
|
+
}) {
|
|
958
|
+
const jsoncContent = readFileSync(filepath, "utf-8");
|
|
959
|
+
const modifiers = Array.isArray(edits) ? edits : [edits];
|
|
960
|
+
const editResult = modifiers.flatMap(
|
|
961
|
+
(edit) => modify(jsoncContent, edit.paths, edit.update, {
|
|
962
|
+
formattingOptions: { tabSize: 0, insertSpaces: false }
|
|
963
|
+
})
|
|
964
|
+
);
|
|
965
|
+
const updatedFileContent = applyEdits(jsoncContent, editResult);
|
|
966
|
+
const commit = () => writeFileSync(filepath, updatedFileContent);
|
|
967
|
+
if (autoCommit) {
|
|
968
|
+
commit();
|
|
969
|
+
}
|
|
970
|
+
return {
|
|
971
|
+
updatedFileContent,
|
|
972
|
+
commit
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
const jsonc = (filepath) => {
|
|
976
|
+
return {
|
|
977
|
+
modify: (edits, options) => modifyJSONCFileSync({ edits, filepath, ...options })
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
export { _dirname, _filename, definePackage, definePackageManagerClient, definePathAliases, detectGlobalPackageManagers, detectLockfilePackageManagers, detectPackageManagers, filterPackageManagers, findDependencyInPackageJson, findPackageManager, findPackageManagerSafely, findResolvedModulePath, getAliasMap, getFolderByPackageName, getGitRootFolder, getPackageFolder, getPath, getWorkspaceFolder, importMap, importer, isDependencyInPackageJson, isPackageDependency, isPackageModuleFound, jsonc, packageManagerConfigs, predefinedPathAliases, project, resolveModule, resolveModulePath, resolvePackageModulePath, workspace };
|