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