@vercel/cli-config 0.2.0 → 0.2.2

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.
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { AuthConfig, AuthFileConfig, GlobalConfig } from './types';
3
+ import { getAuthConfigFilePath, getConfigFilePath, getGlobalPathConfig } from './paths';
4
+ export { getAuthConfigFilePath, getConfigFilePath, getGlobalPathConfig };
3
5
  type WriteConfigFileOptions = {
4
6
  indent?: number | string;
5
7
  mode?: number;
@@ -12,9 +14,6 @@ export declare function parseAuthConfig(value: unknown): AuthConfig;
12
14
  export declare function parseAuthFileConfig(value: unknown): AuthFileConfig;
13
15
  export declare function readConfigFile<S extends z.ZodType>(configPath: string, schema: S): z.output<S>;
14
16
  export declare function writeConfigFile<S extends z.ZodType>(configPath: string, schema: S, config: z.output<S>, options?: WriteConfigFileOptions): void;
15
- export declare function getGlobalPathConfig(): string;
16
- export declare function getConfigFilePath(configDir: string): string;
17
- export declare function getAuthConfigFilePath(configDir: string): string;
18
17
  export declare function readGlobalConfigFile(configPath: string): GlobalConfig;
19
18
  export declare function writeGlobalConfigFile(configPath: string, config: GlobalConfig): void;
20
19
  export declare function readAuthConfigFile(configPath: string): AuthConfig;
@@ -25,4 +24,3 @@ export declare function writeAuthConfigFile(configPath: string, authConfig: Auth
25
24
  export declare function writeAuthConfig(configDir: string, authConfig: AuthConfig): void;
26
25
  export declare function deleteAuthConfigFile(configPath: string): void;
27
26
  export declare function deleteAuthConfig(configDir: string): void;
28
- export {};
@@ -3,16 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defaultAuthConfig = exports.defaultGlobalConfig = void 0;
6
+ exports.defaultAuthConfig = exports.defaultGlobalConfig = exports.getGlobalPathConfig = exports.getConfigFilePath = exports.getAuthConfigFilePath = void 0;
7
7
  exports.getDefaultAuthConfig = getDefaultAuthConfig;
8
8
  exports.parseGlobalConfig = parseGlobalConfig;
9
9
  exports.parseAuthConfig = parseAuthConfig;
10
10
  exports.parseAuthFileConfig = parseAuthFileConfig;
11
11
  exports.readConfigFile = readConfigFile;
12
12
  exports.writeConfigFile = writeConfigFile;
13
- exports.getGlobalPathConfig = getGlobalPathConfig;
14
- exports.getConfigFilePath = getConfigFilePath;
15
- exports.getAuthConfigFilePath = getAuthConfigFilePath;
16
13
  exports.readGlobalConfigFile = readGlobalConfigFile;
17
14
  exports.writeGlobalConfigFile = writeGlobalConfigFile;
18
15
  exports.readAuthConfigFile = readAuthConfigFile;
@@ -25,10 +22,12 @@ exports.deleteAuthConfigFile = deleteAuthConfigFile;
25
22
  exports.deleteAuthConfig = deleteAuthConfig;
26
23
  const node_fs_1 = __importDefault(require("node:fs"));
27
24
  const node_path_1 = __importDefault(require("node:path"));
28
- const node_os_1 = require("node:os");
29
- const xdg_app_paths_1 = __importDefault(require("xdg-app-paths"));
30
25
  const zod_1 = require("zod");
31
26
  const schema_1 = require("./schema");
27
+ const paths_1 = require("./paths");
28
+ Object.defineProperty(exports, "getAuthConfigFilePath", { enumerable: true, get: function () { return paths_1.getAuthConfigFilePath; } });
29
+ Object.defineProperty(exports, "getConfigFilePath", { enumerable: true, get: function () { return paths_1.getConfigFilePath; } });
30
+ Object.defineProperty(exports, "getGlobalPathConfig", { enumerable: true, get: function () { return paths_1.getGlobalPathConfig; } });
32
31
  const DOCS_URL = 'https://vercel.com/docs/projects/project-configuration/global-configuration';
33
32
  exports.defaultGlobalConfig = {
34
33
  '// Note': 'This is your Vercel config file. For more information see the global configuration documentation.',
@@ -101,31 +100,6 @@ function writeConfigFile(configPath, schema, config, options) {
101
100
  ...options,
102
101
  });
103
102
  }
104
- function isReadableDirectory(targetPath) {
105
- try {
106
- return node_fs_1.default.lstatSync(targetPath).isDirectory();
107
- }
108
- catch (_) {
109
- // We don't care which kind of error occured, it isn't a readable directory anyway.
110
- return false;
111
- }
112
- }
113
- function getGlobalPathConfig() {
114
- const vercelDirectories = (0, xdg_app_paths_1.default)('com.vercel.cli').dataDirs();
115
- const possibleConfigPaths = [
116
- ...vercelDirectories, // latest vercel directory
117
- node_path_1.default.join((0, node_os_1.homedir)(), '.now'), // legacy config in user's home directory
118
- ...(0, xdg_app_paths_1.default)('now').dataDirs(), // legacy XDG directory
119
- ];
120
- return (possibleConfigPaths.find(configPath => isReadableDirectory(configPath)) ||
121
- vercelDirectories[0]);
122
- }
123
- function getConfigFilePath(configDir) {
124
- return node_path_1.default.join(configDir, 'config.json');
125
- }
126
- function getAuthConfigFilePath(configDir) {
127
- return node_path_1.default.join(configDir, 'auth.json');
128
- }
129
103
  function readGlobalConfigFile(configPath) {
130
104
  try {
131
105
  return readConfigFile(configPath, schema_1.globalConfigSchema);
@@ -144,7 +118,7 @@ function readAuthFileConfig(configPath) {
144
118
  return parseAuthFileConfig(readJsonFileSync(configPath));
145
119
  }
146
120
  function readAuthConfig(configDir) {
147
- return readAuthConfigFile(getAuthConfigFilePath(configDir));
121
+ return readAuthConfigFile((0, paths_1.getAuthConfigFilePath)(configDir));
148
122
  }
149
123
  function tryReadAuthConfig(configDir) {
150
124
  try {
@@ -163,11 +137,11 @@ function writeAuthConfigFile(configPath, authConfig) {
163
137
  });
164
138
  }
165
139
  function writeAuthConfig(configDir, authConfig) {
166
- writeAuthConfigFile(getAuthConfigFilePath(configDir), authConfig);
140
+ writeAuthConfigFile((0, paths_1.getAuthConfigFilePath)(configDir), authConfig);
167
141
  }
168
142
  function deleteAuthConfigFile(configPath) {
169
143
  node_fs_1.default.rmSync(configPath, { force: true });
170
144
  }
171
145
  function deleteAuthConfig(configDir) {
172
- deleteAuthConfigFile(getAuthConfigFilePath(configDir));
146
+ deleteAuthConfigFile((0, paths_1.getAuthConfigFilePath)(configDir));
173
147
  }
@@ -0,0 +1,4 @@
1
+ export declare function getGlobalPathConfig(): string;
2
+ export declare function getConfigFilePath(configDir: string): string;
3
+ export declare function getAuthConfigFilePath(configDir: string): string;
4
+ export declare function readGlobalConfigFlag(configPath: string, key: string): unknown;
package/dist/paths.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getGlobalPathConfig = getGlobalPathConfig;
7
+ exports.getConfigFilePath = getConfigFilePath;
8
+ exports.getAuthConfigFilePath = getAuthConfigFilePath;
9
+ exports.readGlobalConfigFlag = readGlobalConfigFlag;
10
+ // Zod-free path helpers so hot paths (e.g. the `vc.js` shim) can locate and
11
+ // read the global config without loading zod and the config schemas.
12
+ const node_fs_1 = __importDefault(require("node:fs"));
13
+ const node_path_1 = __importDefault(require("node:path"));
14
+ const node_os_1 = require("node:os");
15
+ const xdg_app_paths_1 = __importDefault(require("xdg-app-paths"));
16
+ function isReadableDirectory(targetPath) {
17
+ try {
18
+ return node_fs_1.default.lstatSync(targetPath).isDirectory();
19
+ }
20
+ catch (_) {
21
+ return false;
22
+ }
23
+ }
24
+ function getGlobalPathConfig() {
25
+ const vercelDirectories = (0, xdg_app_paths_1.default)('com.vercel.cli').dataDirs();
26
+ const possibleConfigPaths = [
27
+ ...vercelDirectories, // latest vercel directory
28
+ node_path_1.default.join((0, node_os_1.homedir)(), '.now'), // legacy config in user's home directory
29
+ ...(0, xdg_app_paths_1.default)('now').dataDirs(), // legacy XDG directory
30
+ ];
31
+ return (possibleConfigPaths.find(configPath => isReadableDirectory(configPath)) ||
32
+ vercelDirectories[0]);
33
+ }
34
+ function getConfigFilePath(configDir) {
35
+ return node_path_1.default.join(configDir, 'config.json');
36
+ }
37
+ function getAuthConfigFilePath(configDir) {
38
+ return node_path_1.default.join(configDir, 'auth.json');
39
+ }
40
+ // Reads a single key from the global config file without schema validation,
41
+ // for cheap feature-gate reads on hot paths.
42
+ function readGlobalConfigFlag(configPath, key) {
43
+ try {
44
+ const content = node_fs_1.default.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, '');
45
+ const parsed = JSON.parse(content);
46
+ if (parsed && typeof parsed === 'object') {
47
+ return parsed[key];
48
+ }
49
+ }
50
+ catch {
51
+ // Missing/unreadable/invalid config is treated as "no value".
52
+ }
53
+ return undefined;
54
+ }
@@ -43,4 +43,5 @@ export declare const globalConfigSchema: z.ZodObject<{
43
43
  updates: z.ZodOptional<z.ZodObject<{
44
44
  auto: z.ZodOptional<z.ZodBoolean>;
45
45
  }, z.core.$strip>>;
46
+ useNativeBinary: z.ZodOptional<z.ZodBoolean>;
46
47
  }, z.core.$strip>;
@@ -39,4 +39,5 @@ exports.globalConfigSchema = zod_1.z.object({
39
39
  telemetry: exports.telemetryConfigSchema.optional(),
40
40
  guidance: exports.guidanceConfigSchema.optional(),
41
41
  updates: exports.updatesConfigSchema.optional(),
42
+ useNativeBinary: zod_1.z.boolean().optional(),
42
43
  });
package/dist/types.d.ts CHANGED
@@ -38,4 +38,6 @@ export interface GlobalConfig {
38
38
  telemetry?: TelemetryConfig;
39
39
  guidance?: GuidanceConfig;
40
40
  updates?: UpdatesConfig;
41
+ /** Opt-in to running the native Vercel CLI binary when one is installed. */
42
+ useNativeBinary?: boolean;
41
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/cli-config",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Shared core utilities for Vercel global configuration",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/projects/project-configuration/global-configuration",
@@ -12,7 +12,8 @@
12
12
  "main": "dist/index.js",
13
13
  "types": "dist/index.d.ts",
14
14
  "exports": {
15
- ".": "./dist/index.js"
15
+ ".": "./dist/index.js",
16
+ "./paths": "./dist/paths.js"
16
17
  },
17
18
  "private": false,
18
19
  "files": [