@vercel/cli-config 0.1.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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @vercel/cli-config
2
+
3
+ Shared utilities for Vercel [global configuration files](https://vercel.com/docs/project-configuration/global-configuration).
4
+
5
+ This package contains the pure config-path, parsing, defaulting, and file read/write helpers used by packages that need access to global configration.
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ import type { AuthConfig, GlobalConfig } from './types';
3
+ type WriteConfigFileOptions = {
4
+ indent?: number | string;
5
+ mode?: number;
6
+ };
7
+ export declare const defaultGlobalConfig: GlobalConfig;
8
+ export declare function getDefaultAuthConfig(): AuthConfig;
9
+ export declare const defaultAuthConfig: AuthConfig;
10
+ export declare function parseGlobalConfig(value: unknown): GlobalConfig;
11
+ export declare function parseAuthConfig(value: unknown): AuthConfig;
12
+ export declare function readConfigFile<S extends z.ZodType>(configPath: string, schema: S): z.output<S>;
13
+ export declare function writeConfigFile<S extends z.ZodType>(configPath: string, schema: S, config: z.output<S>, options?: WriteConfigFileOptions): void;
14
+ export declare function getGlobalPathConfig(): string;
15
+ export declare function getConfigFilePath(configDir: string): string;
16
+ export declare function getAuthConfigFilePath(configDir: string): string;
17
+ export declare function readGlobalConfigFile(configPath: string): GlobalConfig;
18
+ export declare function writeGlobalConfigFile(configPath: string, config: GlobalConfig): void;
19
+ export declare function readAuthConfigFile(configPath: string): AuthConfig;
20
+ export declare function writeAuthConfigFile(configPath: string, authConfig: AuthConfig): void;
21
+ export {};
@@ -0,0 +1,120 @@
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.defaultAuthConfig = exports.defaultGlobalConfig = void 0;
7
+ exports.getDefaultAuthConfig = getDefaultAuthConfig;
8
+ exports.parseGlobalConfig = parseGlobalConfig;
9
+ exports.parseAuthConfig = parseAuthConfig;
10
+ exports.readConfigFile = readConfigFile;
11
+ exports.writeConfigFile = writeConfigFile;
12
+ exports.getGlobalPathConfig = getGlobalPathConfig;
13
+ exports.getConfigFilePath = getConfigFilePath;
14
+ exports.getAuthConfigFilePath = getAuthConfigFilePath;
15
+ exports.readGlobalConfigFile = readGlobalConfigFile;
16
+ exports.writeGlobalConfigFile = writeGlobalConfigFile;
17
+ exports.readAuthConfigFile = readAuthConfigFile;
18
+ exports.writeAuthConfigFile = writeAuthConfigFile;
19
+ const node_fs_1 = __importDefault(require("node:fs"));
20
+ const node_path_1 = __importDefault(require("node:path"));
21
+ const node_os_1 = require("node:os");
22
+ const xdg_app_paths_1 = __importDefault(require("xdg-app-paths"));
23
+ const zod_1 = require("zod");
24
+ const schema_1 = require("./schema");
25
+ const DOCS_URL = 'https://vercel.com/docs/projects/project-configuration/global-configuration';
26
+ exports.defaultGlobalConfig = {
27
+ '// Note': 'This is your Vercel config file. For more information see the global configuration documentation.',
28
+ '// Docs': `${DOCS_URL}#config.json`,
29
+ };
30
+ function getDefaultAuthConfig() {
31
+ return {
32
+ '// Note': 'This is your Vercel credentials file. DO NOT SHARE!',
33
+ '// Docs': `${DOCS_URL}#auth.json`,
34
+ };
35
+ }
36
+ exports.defaultAuthConfig = getDefaultAuthConfig();
37
+ function parseGlobalConfig(value) {
38
+ return schema_1.globalConfigSchema.parse(value);
39
+ }
40
+ function parseAuthConfig(value) {
41
+ return schema_1.authConfigSchema.parse(value);
42
+ }
43
+ function readJsonFileSync(filePath) {
44
+ const content = node_fs_1.default.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '');
45
+ return JSON.parse(content);
46
+ }
47
+ function writeJsonFileSync(filePath, value, options = {}) {
48
+ const directory = node_path_1.default.dirname(filePath);
49
+ const tempFilePath = node_path_1.default.join(directory, `.${node_path_1.default.basename(filePath)}.${process.pid}.${Date.now()}.tmp`);
50
+ const content = `${JSON.stringify(value, null, options.indent ?? 2)}\n`;
51
+ node_fs_1.default.mkdirSync(directory, { recursive: true });
52
+ try {
53
+ node_fs_1.default.writeFileSync(tempFilePath, content, {
54
+ encoding: 'utf8',
55
+ mode: options.mode,
56
+ });
57
+ node_fs_1.default.renameSync(tempFilePath, filePath);
58
+ }
59
+ catch (error) {
60
+ try {
61
+ node_fs_1.default.rmSync(tempFilePath, { force: true });
62
+ }
63
+ catch {
64
+ // Best-effort cleanup for failed atomic writes.
65
+ }
66
+ throw error;
67
+ }
68
+ }
69
+ function readConfigFile(configPath, schema) {
70
+ return schema.parse(readJsonFileSync(configPath));
71
+ }
72
+ function writeConfigFile(configPath, schema, config, options) {
73
+ const normalizedConfig = zod_1.z.encode(schema, config);
74
+ writeJsonFileSync(configPath, normalizedConfig, {
75
+ indent: 2,
76
+ ...options,
77
+ });
78
+ }
79
+ function isReadableDirectory(targetPath) {
80
+ try {
81
+ return node_fs_1.default.lstatSync(targetPath).isDirectory();
82
+ }
83
+ catch (_) {
84
+ // We don't care which kind of error occured, it isn't a readable directory anyway.
85
+ return false;
86
+ }
87
+ }
88
+ function getGlobalPathConfig() {
89
+ const vercelDirectories = (0, xdg_app_paths_1.default)('com.vercel.cli').dataDirs();
90
+ const possibleConfigPaths = [
91
+ ...vercelDirectories, // latest vercel directory
92
+ node_path_1.default.join((0, node_os_1.homedir)(), '.now'), // legacy config in user's home directory
93
+ ...(0, xdg_app_paths_1.default)('now').dataDirs(), // legacy XDG directory
94
+ ];
95
+ return (possibleConfigPaths.find(configPath => isReadableDirectory(configPath)) ||
96
+ vercelDirectories[0]);
97
+ }
98
+ function getConfigFilePath(configDir) {
99
+ return node_path_1.default.join(configDir, 'config.json');
100
+ }
101
+ function getAuthConfigFilePath(configDir) {
102
+ return node_path_1.default.join(configDir, 'auth.json');
103
+ }
104
+ function readGlobalConfigFile(configPath) {
105
+ return readConfigFile(configPath, schema_1.globalConfigSchema);
106
+ }
107
+ function writeGlobalConfigFile(configPath, config) {
108
+ writeConfigFile(configPath, schema_1.globalConfigSchema, config);
109
+ }
110
+ function readAuthConfigFile(configPath) {
111
+ return readConfigFile(configPath, schema_1.authConfigSchema);
112
+ }
113
+ function writeAuthConfigFile(configPath, authConfig) {
114
+ if (authConfig.skipWrite) {
115
+ return;
116
+ }
117
+ writeConfigFile(configPath, schema_1.authConfigSchema, authConfig, {
118
+ mode: 0o600,
119
+ });
120
+ }
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './schema';
3
+ export * from './cli-config';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./schema"), exports);
19
+ __exportStar(require("./cli-config"), exports);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Zod schemas for Vercel global config types.
3
+ *
4
+ * Types are defined in types.ts (source of truth).
5
+ * Schemas are generated by ts-to-zod and re-exported here with runtime
6
+ * passthrough behavior for unrecognized config keys.
7
+ */
8
+ import type { z } from 'zod';
9
+ import type { AuthConfig, GlobalConfig, GuidanceConfig, TelemetryConfig } from './types';
10
+ export declare const telemetryConfigSchema: z.ZodType<TelemetryConfig>;
11
+ export declare const guidanceConfigSchema: z.ZodType<GuidanceConfig>;
12
+ export declare const globalConfigSchema: z.ZodType<GlobalConfig>;
13
+ export declare const authConfigSchema: z.ZodType<AuthConfig>;
package/dist/schema.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * Zod schemas for Vercel global config types.
4
+ *
5
+ * Types are defined in types.ts (source of truth).
6
+ * Schemas are generated by ts-to-zod and re-exported here with runtime
7
+ * passthrough behavior for unrecognized config keys.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.authConfigSchema = exports.globalConfigSchema = exports.guidanceConfigSchema = exports.telemetryConfigSchema = void 0;
11
+ const schema_zod_1 = require("./schema.zod");
12
+ exports.telemetryConfigSchema = schema_zod_1.telemetryConfigSchema.passthrough();
13
+ exports.guidanceConfigSchema = schema_zod_1.guidanceConfigSchema.passthrough();
14
+ exports.globalConfigSchema = schema_zod_1.globalConfigSchema
15
+ .extend({
16
+ telemetry: exports.telemetryConfigSchema.optional(),
17
+ guidance: exports.guidanceConfigSchema.optional(),
18
+ })
19
+ .passthrough();
20
+ exports.authConfigSchema = schema_zod_1.authConfigSchema.passthrough();
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ export declare const telemetryConfigSchema: z.ZodObject<{
3
+ enabled: z.ZodOptional<z.ZodBoolean>;
4
+ }, z.core.$strip>;
5
+ export declare const guidanceConfigSchema: z.ZodObject<{
6
+ enabled: z.ZodOptional<z.ZodBoolean>;
7
+ }, z.core.$strip>;
8
+ export declare const authConfigSchema: z.ZodObject<{
9
+ '// Note': z.ZodOptional<z.ZodString>;
10
+ '// Docs': z.ZodOptional<z.ZodString>;
11
+ skipWrite: z.ZodOptional<z.ZodBoolean>;
12
+ token: z.ZodOptional<z.ZodString>;
13
+ userId: z.ZodOptional<z.ZodString>;
14
+ refreshToken: z.ZodOptional<z.ZodString>;
15
+ expiresAt: z.ZodOptional<z.ZodNumber>;
16
+ tokenSource: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"flag">, z.ZodLiteral<"env">]>>;
17
+ }, z.core.$strip>;
18
+ export declare const globalConfigSchema: z.ZodObject<{
19
+ '// Note': z.ZodOptional<z.ZodString>;
20
+ '// Docs': z.ZodOptional<z.ZodString>;
21
+ currentTeam: z.ZodOptional<z.ZodString>;
22
+ api: z.ZodOptional<z.ZodString>;
23
+ telemetry: z.ZodOptional<z.ZodObject<{
24
+ enabled: z.ZodOptional<z.ZodBoolean>;
25
+ }, z.core.$strip>>;
26
+ guidance: z.ZodOptional<z.ZodObject<{
27
+ enabled: z.ZodOptional<z.ZodBoolean>;
28
+ }, z.core.$strip>>;
29
+ }, z.core.$strip>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.globalConfigSchema = exports.authConfigSchema = exports.guidanceConfigSchema = exports.telemetryConfigSchema = void 0;
4
+ // Generated by ts-to-zod
5
+ const zod_1 = require("zod");
6
+ exports.telemetryConfigSchema = zod_1.z.object({
7
+ enabled: zod_1.z.boolean().optional(),
8
+ });
9
+ exports.guidanceConfigSchema = zod_1.z.object({
10
+ enabled: zod_1.z.boolean().optional(),
11
+ });
12
+ exports.authConfigSchema = zod_1.z.object({
13
+ '// Note': zod_1.z.string().optional(),
14
+ '// Docs': zod_1.z.string().optional(),
15
+ skipWrite: zod_1.z.boolean().optional(),
16
+ token: zod_1.z.string().optional(),
17
+ userId: zod_1.z.string().optional(),
18
+ refreshToken: zod_1.z.string().optional(),
19
+ expiresAt: zod_1.z.number().optional(),
20
+ tokenSource: zod_1.z.union([zod_1.z.literal('flag'), zod_1.z.literal('env')]).optional(),
21
+ });
22
+ exports.globalConfigSchema = zod_1.z.object({
23
+ '// Note': zod_1.z.string().optional(),
24
+ '// Docs': zod_1.z.string().optional(),
25
+ currentTeam: zod_1.z.string().optional(),
26
+ api: zod_1.z.string().optional(),
27
+ telemetry: exports.telemetryConfigSchema.optional(),
28
+ guidance: exports.guidanceConfigSchema.optional(),
29
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Pure TypeScript interface definitions for Vercel global config types.
3
+ *
4
+ * These interfaces serve as the source of truth for types.
5
+ * Zod schemas are generated from these using ts-to-zod.
6
+ */
7
+ export interface TelemetryConfig {
8
+ enabled?: boolean;
9
+ }
10
+ export interface GuidanceConfig {
11
+ enabled?: boolean;
12
+ }
13
+ export interface AuthConfig {
14
+ '// Note'?: string;
15
+ '// Docs'?: string;
16
+ skipWrite?: boolean;
17
+ token?: string;
18
+ userId?: string;
19
+ refreshToken?: string;
20
+ expiresAt?: number;
21
+ tokenSource?: 'flag' | 'env';
22
+ }
23
+ export interface GlobalConfig {
24
+ '// Note'?: string;
25
+ '// Docs'?: string;
26
+ currentTeam?: string;
27
+ api?: string;
28
+ telemetry?: TelemetryConfig;
29
+ guidance?: GuidanceConfig;
30
+ }
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Pure TypeScript interface definitions for Vercel global config types.
4
+ *
5
+ * These interfaces serve as the source of truth for types.
6
+ * Zod schemas are generated from these using ts-to-zod.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vercel/cli-config",
3
+ "version": "0.1.0",
4
+ "description": "Shared core utilities for Vercel global configuration",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://vercel.com/docs/projects/project-configuration/global-configuration",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/vercel/vercel.git",
10
+ "directory": "packages/cli-config"
11
+ },
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": "./dist/index.js"
16
+ },
17
+ "private": false,
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "pnpm generate:schemas && tsc",
23
+ "generate:schemas": "ts-to-zod src/types.ts src/schema.zod.ts",
24
+ "test": "pnpm test-unit",
25
+ "test-unit": "pnpm run vitest-run -- test",
26
+ "vitest-run": "vitest run -c ../../vitest.config.mts",
27
+ "vitest-unit": "glob --absolute 'test/*.test.ts'",
28
+ "type-check": "tsc --noEmit"
29
+ },
30
+ "dependencies": {
31
+ "zod": "4.1.11",
32
+ "xdg-app-paths": "5"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "20.11.0",
36
+ "ts-to-zod": "^3",
37
+ "vite": "7.1.7",
38
+ "vitest": "2.1.4"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }