@magidoc/plugin-starter-variables 1.1.1 → 2.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.
@@ -0,0 +1,6 @@
1
+ import type { Variable } from '../variables/variable';
2
+ export declare function toVariablesFile(options: Record<string, unknown>, supportedVariables: ReadonlyArray<Variable<unknown>>): string;
3
+ export declare class UnsupportedVariablesError extends Error {
4
+ unsupportedVariables: string[];
5
+ constructor(message: string, unsupportedVariables: string[]);
6
+ }
@@ -0,0 +1,45 @@
1
+ import _ from 'lodash';
2
+ import magidoc from '../variables/magidoc.js';
3
+
4
+ function toVariablesFile(options, supportedVariables) {
5
+ return asVariablesString(buildEnv(options, supportedVariables));
6
+ }
7
+ function asVariablesString(env) {
8
+ return JSON.stringify(env);
9
+ }
10
+ function buildEnv(options, supportedVariables) {
11
+ let newRecord = {};
12
+ const unsupportedVariables = [];
13
+ _.forEach(options, (value, key) => {
14
+ const variable = supportedVariables.find((option) => option.name === key);
15
+ if (!variable) {
16
+ unsupportedVariables.push(key);
17
+ return;
18
+ }
19
+ newRecord = {
20
+ ...newRecord,
21
+ ...variable.asEnv(value),
22
+ };
23
+ });
24
+ if (unsupportedVariables.length > 0) {
25
+ throw new UnsupportedVariablesError(`Options [${unsupportedVariables.toString()}] are not supported... Supported option names are [${supportedVariables
26
+ .map((value) => value.name)
27
+ .join(', ')}]`, unsupportedVariables);
28
+ }
29
+ insertDefaultVariables(newRecord);
30
+ return newRecord;
31
+ }
32
+ function insertDefaultVariables(newRecord) {
33
+ newRecord[magidoc.MAGIDOC_GENERATE.key] = 'true';
34
+ }
35
+ class UnsupportedVariablesError extends Error {
36
+ unsupportedVariables;
37
+ constructor(message, unsupportedVariables) {
38
+ super(message);
39
+ this.unsupportedVariables = unsupportedVariables;
40
+ this.name = 'UnsupportedVariableError';
41
+ }
42
+ }
43
+
44
+ export { UnsupportedVariablesError, toVariablesFile };
45
+ //# sourceMappingURL=envFileContent.js.map
@@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sB,CAAC,SAAS,CAAC,CAAA;AACjC,IAAA,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAS,sBAAsB,CAAC,SAAiC,EAAA;IAC/D,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;AAClD,CAAC;AAEK,MAAO,yBAA0B,SAAQ,KAAK,CAAA;AAC3C,IAAA,oBAAoB,CAAU;IAErC,WAAY,CAAA,OAAe,EAAE,oBAA8B,EAAA;QACzD,KAAK,CAAC,OAAO,CAAC,CAAA;AACd,QAAA,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;AAChD,QAAA,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;KACvC;AACF;;;;"}
package/build/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import templates from './variables/templates';
2
2
  import magidoc from './variables/magidoc';
3
- import type { Variable, ViteVariable } from './variables/variable';
3
+ import { toVariablesFile, UnsupportedVariablesError } from './env/envFileContent';
4
+ import type { Variable } from './variables/variable';
4
5
  import type { Page } from './variables/templates';
5
6
  export { templates };
6
7
  export { magidoc };
7
- export type { Variable, ViteVariable, Page };
8
+ export type { Variable, Page };
9
+ export { toVariablesFile, UnsupportedVariablesError };
package/build/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as templates } from './variables/templates.js';
2
2
  export { default as magidoc } from './variables/magidoc.js';
3
+ export { UnsupportedVariablesError, toVariablesFile } from './env/envFileContent.js';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,15 +1,14 @@
1
1
  import type { ZodType, ZodTypeDef } from 'zod';
2
- /**
3
- * Copy of the ViteJS import meta interface
4
- */
5
2
  interface MetaEnv {
6
3
  [key: string]: unknown;
7
4
  }
8
5
  export declare type Variable<T> = {
9
6
  name: string;
7
+ key: string;
10
8
  asEnv: (value: T) => Record<string, string>;
9
+ get: (env: MetaEnv) => T | null;
10
+ getOrDefault: (env: MetaEnv, def: T) => T;
11
11
  zod: ZodVariable<T>;
12
- vite: ViteVariable<T>;
13
12
  };
14
13
  export declare type ZodTypeProvider<T> = (zod: typeof import('zod')) => ZodType<T | undefined, ZodTypeDef, T | undefined>;
15
14
  export declare type ZodVariable<T> = {
@@ -20,10 +19,5 @@ export declare type Converter<T> = {
20
19
  asString: (value: T) => string;
21
20
  type: ZodTypeProvider<T>;
22
21
  };
23
- export declare type ViteVariable<T> = {
24
- key: string;
25
- get: (env: MetaEnv) => T | null;
26
- getOrDefault: (env: MetaEnv, def: T) => T;
27
- };
28
22
  export declare function createVariable<T>(key: string, converter: Converter<T>): Variable<T>;
29
23
  export {};
@@ -1,17 +1,14 @@
1
1
  function createVariable(key, converter) {
2
- const viteKey = `VITE_${key.toUpperCase()}`;
3
- const viteGet = (env) => converter.convert(env[viteKey]);
2
+ const get = (env) => converter.convert(env[key]);
4
3
  return {
5
4
  name: toCamelCase(key),
6
- asEnv: (value) => ({ [viteKey]: converter.asString(value) }),
5
+ key: key,
6
+ asEnv: (value) => ({ [key]: converter.asString(value) }),
7
7
  zod: {
8
8
  type: converter.type,
9
9
  },
10
- vite: {
11
- key: viteKey,
12
- get: viteGet,
13
- getOrDefault: (env, def) => viteGet(env) ?? def,
14
- },
10
+ get: get,
11
+ getOrDefault: (env, def) => get(env) ?? def,
15
12
  };
16
13
  }
17
14
  function toCamelCase(key) {
@@ -1 +1 @@
1
- {"version":3,"file":"variable.js","sources":["../../../src/variables/variable.ts"],"sourcesContent":[null],"names":[],"mappings":"AAoCgB,SAAA,cAAc,CAC5B,GAAW,EACX,SAAuB,EAAA;IAEvB,MAAM,OAAO,GAAG,CAAQ,KAAA,EAAA,GAAG,CAAC,WAAW,EAAE,EAAE,CAAA;AAC3C,IAAA,MAAM,OAAO,GAAG,CAAC,GAAY,KAAK,SAAS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AC,EAAE,CAAC;AAC3D,QAAA,GAAG,EAAE;YACH,IAAI,EAAE,SAAS,CAAC,IAAI;AACrB,SAAA;AACD,QAAA,GAAG,EAAE,GAAG;AACR,QAAA,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG;KAC5C,CAAA;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAW,EAAA;AAC9B,IAAA,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,EAAE,KAAI;AACvD,QAAA,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAC3D,KAAC,CAAC,CAAA;AACJ;;;;"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@magidoc/plugin-starter-variables",
3
3
  "description": "A shared library that contains common Magidoc starter environment variables keys.",
4
4
  "private": false,
5
- "version": "1.1.1",
5
+ "version": "2.0.0",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "./build/index.js",
@@ -19,12 +19,15 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@rollup/plugin-typescript": "^8.3.2",
22
- "@types/jest": "^27.5.1",
22
+ "@types/jest": "^28.1.1",
23
+ "@types/lodash": "^4.14.182",
24
+ "@types/node": "^17.0.40",
23
25
  "jest": "^28.1.0",
24
- "rollup": "^2.75.3",
25
- "ts-jest": "^28.0.3",
26
+ "lodash": "^4.17.21",
27
+ "rollup": "^2.75.5",
28
+ "ts-jest": "^28.0.4",
26
29
  "tslib": "^2.4.0",
27
- "typescript": "^4.7.2"
30
+ "typescript": "^4.7.3"
28
31
  },
29
32
  "optionalDependencies": {
30
33
  "zod": "^3.17.3"
package/rollup.config.cjs CHANGED
@@ -4,7 +4,7 @@ const typescript = require('@rollup/plugin-typescript')
4
4
  module.exports = defineConfig({
5
5
  input: ['src/index.ts'],
6
6
  plugins: [typescript()],
7
- external: ['zod'],
7
+ external: ['zod', 'lodash'],
8
8
  output: {
9
9
  dir: 'build',
10
10
  format: 'esm',
@@ -0,0 +1,60 @@
1
+ import _ from 'lodash'
2
+ import magidoc from '../variables/magidoc'
3
+ import type { Variable } from '../variables/variable'
4
+
5
+ export function toVariablesFile(
6
+ options: Record<string, unknown>,
7
+ supportedVariables: ReadonlyArray<Variable<unknown>>,
8
+ ): string {
9
+ return asVariablesString(buildEnv(options, supportedVariables))
10
+ }
11
+
12
+ function asVariablesString(env: Record<string, string>) {
13
+ return JSON.stringify(env)
14
+ }
15
+
16
+ function buildEnv(
17
+ options: Record<string, unknown>,
18
+ supportedVariables: ReadonlyArray<Variable<unknown>>,
19
+ ): Record<string, string> {
20
+ let newRecord: Record<string, string> = {}
21
+ const unsupportedVariables: string[] = []
22
+ _.forEach(options, (value, key) => {
23
+ const variable = supportedVariables.find((option) => option.name === key)
24
+ if (!variable) {
25
+ unsupportedVariables.push(key)
26
+ return
27
+ }
28
+
29
+ newRecord = {
30
+ ...newRecord,
31
+ ...variable.asEnv(value),
32
+ }
33
+ })
34
+
35
+ if (unsupportedVariables.length > 0) {
36
+ throw new UnsupportedVariablesError(
37
+ `Options [${unsupportedVariables.toString()}] are not supported... Supported option names are [${supportedVariables
38
+ .map((value) => value.name)
39
+ .join(', ')}]`,
40
+ unsupportedVariables,
41
+ )
42
+ }
43
+
44
+ insertDefaultVariables(newRecord)
45
+ return newRecord
46
+ }
47
+
48
+ function insertDefaultVariables(newRecord: Record<string, string>) {
49
+ newRecord[magidoc.MAGIDOC_GENERATE.key] = 'true'
50
+ }
51
+
52
+ export class UnsupportedVariablesError extends Error {
53
+ public unsupportedVariables: string[]
54
+
55
+ constructor(message: string, unsupportedVariables: string[]) {
56
+ super(message)
57
+ this.unsupportedVariables = unsupportedVariables
58
+ this.name = 'UnsupportedVariableError'
59
+ }
60
+ }
package/src/index.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  import templates from './variables/templates'
2
2
  import magidoc from './variables/magidoc'
3
- import type { Variable, ViteVariable } from './variables/variable'
3
+ import {
4
+ toVariablesFile,
5
+ UnsupportedVariablesError,
6
+ } from './env/envFileContent'
7
+ import type { Variable } from './variables/variable'
4
8
  import type { Page } from './variables/templates'
5
9
 
6
10
  export { templates }
7
11
  export { magidoc }
8
- export type { Variable, ViteVariable, Page }
12
+ export type { Variable, Page }
13
+ export { toVariablesFile, UnsupportedVariablesError }
@@ -1,17 +1,16 @@
1
1
  import type { ZodType, ZodTypeDef } from 'zod'
2
2
 
3
- /**
4
- * Copy of the ViteJS import meta interface
5
- */
6
3
  interface MetaEnv {
7
4
  [key: string]: unknown
8
5
  }
9
6
 
10
7
  export type Variable<T> = {
11
8
  name: string
9
+ key: string
12
10
  asEnv: (value: T) => Record<string, string>
11
+ get: (env: MetaEnv) => T | null
12
+ getOrDefault: (env: MetaEnv, def: T) => T
13
13
  zod: ZodVariable<T>
14
- vite: ViteVariable<T>
15
14
  }
16
15
 
17
16
  export type ZodTypeProvider<T> = (
@@ -28,30 +27,21 @@ export type Converter<T> = {
28
27
  type: ZodTypeProvider<T>
29
28
  }
30
29
 
31
- export type ViteVariable<T> = {
32
- key: string
33
- get: (env: MetaEnv) => T | null
34
- getOrDefault: (env: MetaEnv, def: T) => T
35
- }
36
-
37
30
  export function createVariable<T>(
38
31
  key: string,
39
32
  converter: Converter<T>,
40
33
  ): Variable<T> {
41
- const viteKey = `VITE_${key.toUpperCase()}`
42
- const viteGet = (env: MetaEnv) => converter.convert(env[viteKey])
34
+ const get = (env: MetaEnv) => converter.convert(env[key])
43
35
 
44
36
  return {
45
37
  name: toCamelCase(key),
46
- asEnv: (value: T) => ({ [viteKey]: converter.asString(value) }),
38
+ key: key,
39
+ asEnv: (value: T) => ({ [key]: converter.asString(value) }),
47
40
  zod: {
48
41
  type: converter.type,
49
42
  },
50
- vite: {
51
- key: viteKey,
52
- get: viteGet,
53
- getOrDefault: (env, def) => viteGet(env) ?? def,
54
- },
43
+ get: get,
44
+ getOrDefault: (env, def) => get(env) ?? def,
55
45
  }
56
46
  }
57
47
 
@@ -0,0 +1,54 @@
1
+ import { templates, Variable, magidoc, toVariablesFile } from '../../src'
2
+ import { UnsupportedVariablesError } from '../../src/env/envFileContent'
3
+
4
+ describe('creating a variables file ', () => {
5
+ const initialObject = {
6
+ appTitle: 'My App',
7
+ pages: [
8
+ {
9
+ title: 'My-page-title',
10
+ content:
11
+ 'A raw markdown string containing stuff like "double quotes", `code`, and **bold**.',
12
+ },
13
+ {
14
+ title: 'My-page-title-2',
15
+ content: [
16
+ {
17
+ title:
18
+ "This is another page, but this one contains 'single quotes', ```much more code```,\n new lines \n\n # And a new header apparently",
19
+ },
20
+ ],
21
+ },
22
+ ],
23
+ }
24
+
25
+ describe('all provided options are supported', () => {
26
+ const result = toVariablesFile(initialObject, [
27
+ templates.APP_TITLE as Variable<unknown>,
28
+ templates.PAGES as Variable<unknown>,
29
+ ])
30
+
31
+ it('is possible to convert it back to the original object using variables', () => {
32
+ const parsed = JSON.parse(result) as Record<string, string>
33
+
34
+ expect(magidoc.MAGIDOC_GENERATE.get(parsed)).toBe(true)
35
+ expect(templates.APP_TITLE.get(parsed)).toBe(initialObject.appTitle)
36
+ expect(templates.PAGES.get(parsed)).toEqual(initialObject.pages)
37
+ })
38
+ })
39
+
40
+ describe('some of the options are unsupported', () => {
41
+ it('raises an error', () => {
42
+ expect.assertions(2)
43
+
44
+ try {
45
+ toVariablesFile(initialObject, [])
46
+ } catch (error) {
47
+ expect(error).toBeInstanceOf(UnsupportedVariablesError)
48
+ expect(
49
+ (error as UnsupportedVariablesError).unsupportedVariables,
50
+ ).toEqual(['appTitle', 'pages'])
51
+ }
52
+ })
53
+ })
54
+ })
@@ -6,7 +6,12 @@ import type { Page } from '../src/index'
6
6
 
7
7
  describe('variables', () => {
8
8
  it('contains the right number of export keys', () => {
9
- expect(Object.keys(variables)).toEqual(['templates', 'magidoc'])
9
+ expect(Object.keys(variables)).toEqual([
10
+ 'templates',
11
+ 'magidoc',
12
+ 'toVariablesFile',
13
+ 'UnsupportedVariablesError',
14
+ ])
10
15
  })
11
16
 
12
17
  describe('template variables', () => {
@@ -25,7 +30,7 @@ describe('variables', () => {
25
30
  test('app title', () => {
26
31
  testStringVariable(
27
32
  variables.templates.APP_TITLE,
28
- 'VITE_APP_TITLE',
33
+ 'APP_TITLE',
29
34
  z.string().optional(),
30
35
  )
31
36
  })
@@ -33,7 +38,7 @@ describe('variables', () => {
33
38
  test('app logo', () => {
34
39
  testStringVariable(
35
40
  variables.templates.APP_LOGO,
36
- 'VITE_APP_LOGO',
41
+ 'APP_LOGO',
37
42
  z.string().optional(),
38
43
  )
39
44
  })
@@ -41,7 +46,7 @@ describe('variables', () => {
41
46
  test('app favicon', () => {
42
47
  testStringVariable(
43
48
  variables.templates.APP_FAVICON,
44
- 'VITE_APP_FAVICON',
49
+ 'APP_FAVICON',
45
50
  z.string().optional(),
46
51
  )
47
52
  })
@@ -49,7 +54,7 @@ describe('variables', () => {
49
54
  test('site root', () => {
50
55
  testStringVariable(
51
56
  variables.templates.SITE_ROOT,
52
- 'VITE_SITE_ROOT',
57
+ 'SITE_ROOT',
53
58
  z.string().optional(),
54
59
  )
55
60
  })
@@ -57,7 +62,7 @@ describe('variables', () => {
57
62
  test('site meta', () => {
58
63
  testRecordVariable(
59
64
  variables.templates.SITE_META,
60
- 'VITE_SITE_META',
65
+ 'SITE_META',
61
66
  z.record(z.string().optional()).optional(),
62
67
  )
63
68
  })
@@ -65,7 +70,7 @@ describe('variables', () => {
65
70
  test('query generation factories', () => {
66
71
  testRecordVariable(
67
72
  variables.templates.QUERY_GENERATION_FACTORIES,
68
- 'VITE_QUERY_GENERATION_FACTORIES',
73
+ 'QUERY_GENERATION_FACTORIES',
69
74
  z
70
75
  .record(
71
76
  z
@@ -92,7 +97,7 @@ describe('variables', () => {
92
97
 
93
98
  testArrayVariable(
94
99
  variables.templates.PAGES,
95
- 'VITE_PAGES',
100
+ 'PAGES',
96
101
  z.array(pagesType).optional(),
97
102
  )
98
103
  })
@@ -106,7 +111,7 @@ describe('variables', () => {
106
111
  test('magidoc generate', () => {
107
112
  testBooleanVariable(
108
113
  variables.magidoc.MAGIDOC_GENERATE,
109
- 'VITE_MAGIDOC_GENERATE',
114
+ 'MAGIDOC_GENERATE',
110
115
  z.boolean().optional(),
111
116
  )
112
117
  })
@@ -115,24 +120,20 @@ describe('variables', () => {
115
120
 
116
121
  function testStringVariable(
117
122
  target: Variable<string>,
118
- viteKey: string,
123
+ key: string,
119
124
  expectedZod: ZodType<any>,
120
125
  ) {
121
- expect(target.vite.key).toEqual(viteKey)
126
+ expect(target.key).toEqual(key)
122
127
 
123
- expect(target.vite.get({ [viteKey]: 'Potato' })).toBe('Potato')
124
- expect(target.vite.get({ [viteKey]: false })).toBe('false')
125
- expect(target.vite.get({})).toBeNull()
128
+ expect(target.get({ [key]: 'Potato' })).toBe('Potato')
129
+ expect(target.get({ [key]: false })).toBe('false')
130
+ expect(target.get({})).toBeNull()
126
131
 
127
- expect(target.vite.getOrDefault({ [viteKey]: 'Potato' }, 'Default')).toBe(
128
- 'Potato',
129
- )
130
- expect(target.vite.getOrDefault({ [viteKey]: false }, 'Default')).toBe(
131
- 'false',
132
- )
133
- expect(target.vite.getOrDefault({}, 'Default')).toBe('Default')
132
+ expect(target.getOrDefault({ [key]: 'Potato' }, 'Default')).toBe('Potato')
133
+ expect(target.getOrDefault({ [key]: false }, 'Default')).toBe('false')
134
+ expect(target.getOrDefault({}, 'Default')).toBe('Default')
134
135
 
135
- expect(target.asEnv('Potato')).toEqual({ [viteKey]: 'Potato' })
136
+ expect(target.asEnv('Potato')).toEqual({ [key]: 'Potato' })
136
137
 
137
138
  ensureZodTypeEqual(target, expectedZod)
138
139
  }
@@ -142,27 +143,27 @@ function testBooleanVariable(
142
143
  viteKey: string,
143
144
  expectedZod: ZodType<any>,
144
145
  ) {
145
- expect(target.vite.key).toEqual(viteKey)
146
+ expect(target.key).toEqual(viteKey)
146
147
 
147
- expect(target.vite.get({ [viteKey]: true })).toBe(true)
148
- expect(target.vite.get({ [viteKey]: 'true' })).toBe(true)
149
- expect(target.vite.get({ [viteKey]: 't' })).toBe(true)
150
- expect(target.vite.get({ [viteKey]: '1' })).toBe(true)
151
- expect(target.vite.get({ [viteKey]: 12 })).toBe(true)
148
+ expect(target.get({ [viteKey]: true })).toBe(true)
149
+ expect(target.get({ [viteKey]: 'true' })).toBe(true)
150
+ expect(target.get({ [viteKey]: 't' })).toBe(true)
151
+ expect(target.get({ [viteKey]: '1' })).toBe(true)
152
+ expect(target.get({ [viteKey]: 12 })).toBe(true)
152
153
 
153
- expect(target.vite.get({ [viteKey]: false })).toBe(false)
154
- expect(target.vite.get({ [viteKey]: 'false' })).toBe(false)
155
- expect(target.vite.get({ [viteKey]: 'wow' })).toBe(false)
156
- expect(target.vite.get({ [viteKey]: 0 })).toBe(false)
154
+ expect(target.get({ [viteKey]: false })).toBe(false)
155
+ expect(target.get({ [viteKey]: 'false' })).toBe(false)
156
+ expect(target.get({ [viteKey]: 'wow' })).toBe(false)
157
+ expect(target.get({ [viteKey]: 0 })).toBe(false)
157
158
 
158
- expect(target.vite.get({ [viteKey]: {} })).toBeNull()
159
- expect(target.vite.get({ [viteKey]: null })).toBeNull()
160
- expect(target.vite.get({ [viteKey]: undefined })).toBeNull()
161
- expect(target.vite.get({})).toBeNull()
159
+ expect(target.get({ [viteKey]: {} })).toBeNull()
160
+ expect(target.get({ [viteKey]: null })).toBeNull()
161
+ expect(target.get({ [viteKey]: undefined })).toBeNull()
162
+ expect(target.get({})).toBeNull()
162
163
 
163
- expect(target.vite.getOrDefault({ [viteKey]: false }, true)).toBe(false)
164
- expect(target.vite.getOrDefault({ [viteKey]: {} }, true)).toBe(true)
165
- expect(target.vite.getOrDefault({}, true)).toBe(true)
164
+ expect(target.getOrDefault({ [viteKey]: false }, true)).toBe(false)
165
+ expect(target.getOrDefault({ [viteKey]: {} }, true)).toBe(true)
166
+ expect(target.getOrDefault({}, true)).toBe(true)
166
167
 
167
168
  expect(target.asEnv(true)).toEqual({ [viteKey]: 'true' })
168
169
  expect(target.asEnv(false)).toEqual({ [viteKey]: 'false' })
@@ -172,76 +173,71 @@ function testBooleanVariable(
172
173
 
173
174
  function testRecordVariable(
174
175
  target: Variable<Record<string, any>>,
175
- viteKey: string,
176
+ key: string,
176
177
  expectedZod: ZodType<any>,
177
178
  ) {
178
- expect(target.vite.key).toEqual(viteKey)
179
+ expect(target.key).toEqual(key)
179
180
 
180
- expect(target.vite.get({ [viteKey]: true })).toBeNull()
181
- expect(target.vite.get({ [viteKey]: 'true' })).toBeNull()
182
- expect(target.vite.get({ [viteKey]: '4234' })).toBeNull()
183
- expect(target.vite.get({ [viteKey]: 4234 })).toBeNull()
181
+ expect(target.get({ [key]: true })).toBeNull()
182
+ expect(target.get({ [key]: 'true' })).toBeNull()
183
+ expect(target.get({ [key]: '4234' })).toBeNull()
184
+ expect(target.get({ [key]: 4234 })).toBeNull()
184
185
 
185
- expect(target.vite.get({ [viteKey]: { abc: '123' } })).toEqual({ abc: '123' })
186
- expect(
187
- target.vite.get({ [viteKey]: JSON.stringify({ abc: '123' }) }),
188
- ).toEqual({ abc: '123' })
186
+ expect(target.get({ [key]: { abc: '123' } })).toEqual({ abc: '123' })
187
+ expect(target.get({ [key]: JSON.stringify({ abc: '123' }) })).toEqual({
188
+ abc: '123',
189
+ })
189
190
 
190
- expect(target.vite.getOrDefault({ [viteKey]: false }, { abc: 123 })).toEqual({
191
+ expect(target.getOrDefault({ [key]: false }, { abc: 123 })).toEqual({
191
192
  abc: 123,
192
193
  })
193
- expect(target.vite.getOrDefault({ [viteKey]: {} }, { abc: 123 })).toEqual({})
194
- expect(target.vite.getOrDefault({}, { abc: 123 })).toEqual({ abc: 123 })
194
+ expect(target.getOrDefault({ [key]: {} }, { abc: 123 })).toEqual({})
195
+ expect(target.getOrDefault({}, { abc: 123 })).toEqual({ abc: 123 })
195
196
 
196
197
  expect(target.asEnv({ abc: 123 })).toEqual({
197
- [viteKey]: JSON.stringify({ abc: 123 }),
198
+ [key]: JSON.stringify({ abc: 123 }),
198
199
  })
199
- expect(target.asEnv({})).toEqual({ [viteKey]: '{}' })
200
+ expect(target.asEnv({})).toEqual({ [key]: '{}' })
200
201
 
201
202
  ensureZodTypeEqual(target, expectedZod)
202
203
  }
203
204
 
204
205
  function testArrayVariable(
205
206
  target: Variable<Array<any>>,
206
- viteKey: string,
207
+ key: string,
207
208
  expectedZod: ZodType<any>,
208
209
  ) {
209
- expect(target.vite.key).toEqual(viteKey)
210
+ expect(target.key).toEqual(key)
210
211
 
211
- expect(target.vite.get({ [viteKey]: true })).toBeNull()
212
- expect(target.vite.get({ [viteKey]: 'true' })).toBeNull()
213
- expect(target.vite.get({ [viteKey]: '4234' })).toBeNull()
214
- expect(target.vite.get({ [viteKey]: 4234 })).toBeNull()
215
- expect(target.vite.get({ [viteKey]: {} })).toBeNull()
212
+ expect(target.get({ [key]: true })).toBeNull()
213
+ expect(target.get({ [key]: 'true' })).toBeNull()
214
+ expect(target.get({ [key]: '4234' })).toBeNull()
215
+ expect(target.get({ [key]: 4234 })).toBeNull()
216
+ expect(target.get({ [key]: {} })).toBeNull()
216
217
 
217
- expect(target.vite.get({ [viteKey]: [{ abc: '123' }] })).toEqual([
218
+ expect(target.get({ [key]: [{ abc: '123' }] })).toEqual([{ abc: '123' }])
219
+ expect(target.get({ [key]: JSON.stringify([{ abc: '123' }]) })).toEqual([
218
220
  { abc: '123' },
219
221
  ])
220
- expect(
221
- target.vite.get({ [viteKey]: JSON.stringify([{ abc: '123' }]) }),
222
- ).toEqual([{ abc: '123' }])
223
222
 
224
- expect(
225
- target.vite.getOrDefault({ [viteKey]: false }, [{ abc: 123 }]),
226
- ).toEqual([
223
+ expect(target.getOrDefault({ [key]: false }, [{ abc: 123 }])).toEqual([
227
224
  {
228
225
  abc: 123,
229
226
  },
230
227
  ])
231
- expect(target.vite.getOrDefault({ [viteKey]: [] }, [{ abc: 123 }])).toEqual(
232
- [],
233
- )
234
- expect(target.vite.getOrDefault({}, [{ abc: 123 }])).toEqual([{ abc: 123 }])
228
+ expect(target.getOrDefault({ [key]: [] }, [{ abc: 123 }])).toEqual([])
229
+ expect(target.getOrDefault({}, [{ abc: 123 }])).toEqual([{ abc: 123 }])
235
230
 
236
231
  expect(target.asEnv([{ abc: 123 }])).toEqual({
237
- [viteKey]: JSON.stringify([{ abc: 123 }]),
232
+ [key]: JSON.stringify([{ abc: 123 }]),
238
233
  })
239
- expect(target.asEnv([])).toEqual({ [viteKey]: '[]' })
234
+ expect(target.asEnv([])).toEqual({ [key]: '[]' })
240
235
 
241
236
  ensureZodTypeEqual(target, expectedZod)
242
237
  }
243
238
 
244
239
  function ensureZodTypeEqual(target: Variable<any>, expected: ZodType<any>) {
240
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
245
241
  // @ts-ignore
246
242
  // this does a good enough compare to make sure they have the same schema
247
243
  expect(JSON.parse(JSON.stringify(target.zod.type(z)))).toEqual(