@kitsy/cnos-vite 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kitsy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @kitsy/cnos-vite
2
+
3
+ Vite integration for CNOS.
4
+
5
+ It resolves CNOS public config during Vite config evaluation and injects the exported values into `import.meta.env.*` and `process.env.*` define replacements using the Vite public convention.
package/dist/index.cjs ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createCnosVitePlugin: () => createCnosVitePlugin,
24
+ loadCnosViteEnv: () => loadCnosViteEnv
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_cnos = require("@kitsy/cnos");
28
+ function mergeEnvPrefix(existing, nextPrefix) {
29
+ const prefixes = Array.isArray(existing) ? existing : existing ? [existing] : [];
30
+ const merged = /* @__PURE__ */ new Set([...prefixes, nextPrefix]);
31
+ return [...merged];
32
+ }
33
+ async function loadCnosViteEnv(options = {}, env = {
34
+ command: "build",
35
+ mode: "production"
36
+ }) {
37
+ const profile = options.profile ?? options.profileFromMode?.(env.mode, env);
38
+ const runtime = await (0, import_cnos.createCnos)({
39
+ ...options,
40
+ ...profile ? { profile } : {}
41
+ });
42
+ return runtime.toPublicEnv({
43
+ framework: "vite",
44
+ ...options.prefix ? { prefix: options.prefix } : {}
45
+ });
46
+ }
47
+ function createCnosVitePlugin(options = {}) {
48
+ return {
49
+ name: "cnos-vite",
50
+ enforce: "pre",
51
+ async config(config, env) {
52
+ const publicEnv = await loadCnosViteEnv(options, env);
53
+ const defineEntries = Object.fromEntries(
54
+ Object.entries(publicEnv).flatMap(([key, value]) => {
55
+ const entries = [[`import.meta.env.${key}`, JSON.stringify(value)]];
56
+ if (options.includeProcessEnvShim ?? true) {
57
+ entries.push([`process.env.${key}`, JSON.stringify(value)]);
58
+ }
59
+ return entries;
60
+ })
61
+ );
62
+ const prefix = options.prefix ?? "VITE_";
63
+ return {
64
+ define: {
65
+ ...config.define ?? {},
66
+ ...defineEntries
67
+ },
68
+ envPrefix: mergeEnvPrefix(config.envPrefix, prefix)
69
+ };
70
+ }
71
+ };
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ createCnosVitePlugin,
76
+ loadCnosViteEnv
77
+ });
@@ -0,0 +1,24 @@
1
+ import { CnosCreateOptions } from '@kitsy/cnos';
2
+
3
+ interface ViteConfigEnv {
4
+ command: 'serve' | 'build';
5
+ mode: string;
6
+ }
7
+ interface ViteUserConfigLike {
8
+ define?: Record<string, string>;
9
+ envPrefix?: string | string[];
10
+ }
11
+ interface VitePluginLike {
12
+ name: string;
13
+ enforce?: 'pre' | 'post';
14
+ config?: (config: ViteUserConfigLike, env: ViteConfigEnv) => Promise<ViteUserConfigLike> | ViteUserConfigLike;
15
+ }
16
+ interface CnosVitePluginOptions extends CnosCreateOptions {
17
+ prefix?: string;
18
+ includeProcessEnvShim?: boolean;
19
+ profileFromMode?: (mode: string, env: ViteConfigEnv) => string | undefined;
20
+ }
21
+ declare function loadCnosViteEnv(options?: CnosVitePluginOptions, env?: ViteConfigEnv): Promise<Record<string, string>>;
22
+ declare function createCnosVitePlugin(options?: CnosVitePluginOptions): VitePluginLike;
23
+
24
+ export { type CnosVitePluginOptions, type ViteConfigEnv, type VitePluginLike, type ViteUserConfigLike, createCnosVitePlugin, loadCnosViteEnv };
@@ -0,0 +1,24 @@
1
+ import { CnosCreateOptions } from '@kitsy/cnos';
2
+
3
+ interface ViteConfigEnv {
4
+ command: 'serve' | 'build';
5
+ mode: string;
6
+ }
7
+ interface ViteUserConfigLike {
8
+ define?: Record<string, string>;
9
+ envPrefix?: string | string[];
10
+ }
11
+ interface VitePluginLike {
12
+ name: string;
13
+ enforce?: 'pre' | 'post';
14
+ config?: (config: ViteUserConfigLike, env: ViteConfigEnv) => Promise<ViteUserConfigLike> | ViteUserConfigLike;
15
+ }
16
+ interface CnosVitePluginOptions extends CnosCreateOptions {
17
+ prefix?: string;
18
+ includeProcessEnvShim?: boolean;
19
+ profileFromMode?: (mode: string, env: ViteConfigEnv) => string | undefined;
20
+ }
21
+ declare function loadCnosViteEnv(options?: CnosVitePluginOptions, env?: ViteConfigEnv): Promise<Record<string, string>>;
22
+ declare function createCnosVitePlugin(options?: CnosVitePluginOptions): VitePluginLike;
23
+
24
+ export { type CnosVitePluginOptions, type ViteConfigEnv, type VitePluginLike, type ViteUserConfigLike, createCnosVitePlugin, loadCnosViteEnv };
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ // src/index.ts
2
+ import { createCnos } from "@kitsy/cnos";
3
+ function mergeEnvPrefix(existing, nextPrefix) {
4
+ const prefixes = Array.isArray(existing) ? existing : existing ? [existing] : [];
5
+ const merged = /* @__PURE__ */ new Set([...prefixes, nextPrefix]);
6
+ return [...merged];
7
+ }
8
+ async function loadCnosViteEnv(options = {}, env = {
9
+ command: "build",
10
+ mode: "production"
11
+ }) {
12
+ const profile = options.profile ?? options.profileFromMode?.(env.mode, env);
13
+ const runtime = await createCnos({
14
+ ...options,
15
+ ...profile ? { profile } : {}
16
+ });
17
+ return runtime.toPublicEnv({
18
+ framework: "vite",
19
+ ...options.prefix ? { prefix: options.prefix } : {}
20
+ });
21
+ }
22
+ function createCnosVitePlugin(options = {}) {
23
+ return {
24
+ name: "cnos-vite",
25
+ enforce: "pre",
26
+ async config(config, env) {
27
+ const publicEnv = await loadCnosViteEnv(options, env);
28
+ const defineEntries = Object.fromEntries(
29
+ Object.entries(publicEnv).flatMap(([key, value]) => {
30
+ const entries = [[`import.meta.env.${key}`, JSON.stringify(value)]];
31
+ if (options.includeProcessEnvShim ?? true) {
32
+ entries.push([`process.env.${key}`, JSON.stringify(value)]);
33
+ }
34
+ return entries;
35
+ })
36
+ );
37
+ const prefix = options.prefix ?? "VITE_";
38
+ return {
39
+ define: {
40
+ ...config.define ?? {},
41
+ ...defineEntries
42
+ },
43
+ envPrefix: mergeEnvPrefix(config.envPrefix, prefix)
44
+ };
45
+ }
46
+ };
47
+ }
48
+ export {
49
+ createCnosVitePlugin,
50
+ loadCnosViteEnv
51
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@kitsy/cnos-vite",
3
+ "version": "1.0.0",
4
+ "description": "Vite integration for CNOS public config injection.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/kitsyai/cnos.git",
23
+ "directory": "packages/vite"
24
+ },
25
+ "homepage": "https://github.com/kitsyai/cnos/tree/main/packages/vite",
26
+ "bugs": {
27
+ "url": "https://github.com/kitsyai/cnos/issues"
28
+ },
29
+ "keywords": [
30
+ "cnos",
31
+ "vite",
32
+ "config"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {
38
+ "@kitsy/cnos": "1.0.0"
39
+ },
40
+ "peerDependencies": {
41
+ "vite": ">=5"
42
+ },
43
+ "scripts": {
44
+ "build": "tsup src/index.ts --format esm,cjs --dts",
45
+ "clean": "rimraf dist",
46
+ "dev": "tsup src/index.ts --watch --format esm,cjs --dts",
47
+ "lint": "eslint src test",
48
+ "test": "vitest run",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit"
50
+ }
51
+ }