@kitsy/cnos-vite 1.1.2 → 1.3.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/dist/index.cjs CHANGED
@@ -24,7 +24,15 @@ __export(index_exports, {
24
24
  loadCnosViteEnv: () => loadCnosViteEnv
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
- var import_cnos = require("@kitsy/cnos");
27
+ var import_build = require("@kitsy/cnos/build");
28
+ var import_configure = require("@kitsy/cnos/configure");
29
+ function resolveRuntimeOptions(options, env) {
30
+ const profile = options.profile ?? options.profileFromMode?.(env.mode, env);
31
+ return {
32
+ ...options,
33
+ ...profile ? { profile } : {}
34
+ };
35
+ }
28
36
  function mergeEnvPrefix(existing, nextPrefix) {
29
37
  const prefixes = Array.isArray(existing) ? existing : existing ? [existing] : [];
30
38
  const merged = /* @__PURE__ */ new Set([...prefixes, nextPrefix]);
@@ -34,11 +42,7 @@ async function loadCnosViteEnv(options = {}, env = {
34
42
  command: "build",
35
43
  mode: "production"
36
44
  }) {
37
- const profile = options.profile ?? options.profileFromMode?.(env.mode, env);
38
- const runtime = await (0, import_cnos.createCnos)({
39
- ...options,
40
- ...profile ? { profile } : {}
41
- });
45
+ const runtime = await (0, import_configure.createCnos)(resolveRuntimeOptions(options, env));
42
46
  return runtime.toPublicEnv({
43
47
  framework: "vite",
44
48
  ...options.prefix ? { prefix: options.prefix } : {}
@@ -49,7 +53,10 @@ function createCnosVitePlugin(options = {}) {
49
53
  name: "cnos-vite",
50
54
  enforce: "pre",
51
55
  async config(config, env) {
52
- const publicEnv = await loadCnosViteEnv(options, env);
56
+ const [publicEnv, browserData] = await Promise.all([
57
+ loadCnosViteEnv(options, env),
58
+ (0, import_build.resolveBrowserData)(resolveRuntimeOptions(options, env))
59
+ ]);
53
60
  const defineEntries = Object.fromEntries(
54
61
  Object.entries(publicEnv).flatMap(([key, value]) => {
55
62
  const entries = [[`import.meta.env.${key}`, JSON.stringify(value)]];
@@ -63,6 +70,8 @@ function createCnosVitePlugin(options = {}) {
63
70
  return {
64
71
  define: {
65
72
  ...config.define ?? {},
73
+ "globalThis.__CNOS_BROWSER_DATA__": JSON.stringify(JSON.stringify(browserData)),
74
+ "process.env.__CNOS_BROWSER_DATA__": JSON.stringify(JSON.stringify(browserData)),
66
75
  ...defineEntries
67
76
  },
68
77
  envPrefix: mergeEnvPrefix(config.envPrefix, prefix)
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { CnosCreateOptions } from '@kitsy/cnos';
1
+ import { CnosCreateOptions } from '@kitsy/cnos/configure';
2
2
 
3
3
  interface ViteConfigEnv {
4
4
  command: 'serve' | 'build';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CnosCreateOptions } from '@kitsy/cnos';
1
+ import { CnosCreateOptions } from '@kitsy/cnos/configure';
2
2
 
3
3
  interface ViteConfigEnv {
4
4
  command: 'serve' | 'build';
package/dist/index.js CHANGED
@@ -1,5 +1,13 @@
1
1
  // src/index.ts
2
- import { createCnos } from "@kitsy/cnos";
2
+ import { resolveBrowserData } from "@kitsy/cnos/build";
3
+ import { createCnos } from "@kitsy/cnos/configure";
4
+ function resolveRuntimeOptions(options, env) {
5
+ const profile = options.profile ?? options.profileFromMode?.(env.mode, env);
6
+ return {
7
+ ...options,
8
+ ...profile ? { profile } : {}
9
+ };
10
+ }
3
11
  function mergeEnvPrefix(existing, nextPrefix) {
4
12
  const prefixes = Array.isArray(existing) ? existing : existing ? [existing] : [];
5
13
  const merged = /* @__PURE__ */ new Set([...prefixes, nextPrefix]);
@@ -9,11 +17,7 @@ async function loadCnosViteEnv(options = {}, env = {
9
17
  command: "build",
10
18
  mode: "production"
11
19
  }) {
12
- const profile = options.profile ?? options.profileFromMode?.(env.mode, env);
13
- const runtime = await createCnos({
14
- ...options,
15
- ...profile ? { profile } : {}
16
- });
20
+ const runtime = await createCnos(resolveRuntimeOptions(options, env));
17
21
  return runtime.toPublicEnv({
18
22
  framework: "vite",
19
23
  ...options.prefix ? { prefix: options.prefix } : {}
@@ -24,7 +28,10 @@ function createCnosVitePlugin(options = {}) {
24
28
  name: "cnos-vite",
25
29
  enforce: "pre",
26
30
  async config(config, env) {
27
- const publicEnv = await loadCnosViteEnv(options, env);
31
+ const [publicEnv, browserData] = await Promise.all([
32
+ loadCnosViteEnv(options, env),
33
+ resolveBrowserData(resolveRuntimeOptions(options, env))
34
+ ]);
28
35
  const defineEntries = Object.fromEntries(
29
36
  Object.entries(publicEnv).flatMap(([key, value]) => {
30
37
  const entries = [[`import.meta.env.${key}`, JSON.stringify(value)]];
@@ -38,6 +45,8 @@ function createCnosVitePlugin(options = {}) {
38
45
  return {
39
46
  define: {
40
47
  ...config.define ?? {},
48
+ "globalThis.__CNOS_BROWSER_DATA__": JSON.stringify(JSON.stringify(browserData)),
49
+ "process.env.__CNOS_BROWSER_DATA__": JSON.stringify(JSON.stringify(browserData)),
41
50
  ...defineEntries
42
51
  },
43
52
  envPrefix: mergeEnvPrefix(config.envPrefix, prefix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitsy/cnos-vite",
3
- "version": "1.1.2",
3
+ "version": "1.3.0",
4
4
  "description": "Vite integration for CNOS public config injection.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@kitsy/cnos": "1.1.2"
38
+ "@kitsy/cnos": "1.3.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "vite": ">=5"