Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/twelve-things-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
12 changes: 4 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"files.associations": {
// package.json needs to be "json" rather than "json with comments" so that the "version lens" plugin works
"package.json": "json",
"turbo.json": "jsonc",
},
"eslint.validate": [
// enable eslint on file types other than js/ts
Expand All @@ -24,7 +25,7 @@
// these are written out individually because if written as a group
// users cannot override individual items in their settings.json
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
Expand All @@ -42,17 +43,12 @@
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[env]": {
"editor.formatOnSave": false
},

// vscode's built-in json formatter is removing the extra newline at the end which conflicts with editorconfig
// "json.format.keepLines": true,
// "json.format.enable": false,

}
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default tseslint.config(
'packages/eslint-custom-rules',
'packages/env-spec-parser/src/grammar.js',
'packages/varlock-website/.astro',
'packages/varlock/env-graph/test/plugins',
'packages/varlock/src/env-graph/test/plugins',
'**/*.ignore',
'**/.vercel',
'**/.netlify',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"scripts": {
"build": "turbo build --filter='!./examples/**'",
"build:libs": "pnpm run build --filter=\"!@varlock/website\"",
"test:ci": "turbo test:ci",
"test:ci": "turbo test:ci --filter='!./examples/**'",
"preinstall": "npx only-allow pnpm",
"dev": "turbo run dev --concurrency=40 --parallel",
"dev": "turbo run dev --concurrency=40 --parallel --filter='!./examples/**'",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"changeset:add": "changeset add",
Expand Down
1 change: 1 addition & 0 deletions packages/varlock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:sea": "tsup --config tsup-sea.config.ts",
"dev": "tsup",
"test": "vitest",
"test:ci": "vitest --run",
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/varlock/src/cli/commands/load.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getItemSummary } from '../../lib/formatting';
import { checkForConfigErrors, checkForSchemaErrors } from '../helpers/error-checks';
import { type TypedGunshiCommandFn } from '../helpers/gunshi-type-utils';
import path from 'node:path';
import { FileBasedDataSource } from '../../../env-graph';
import { FileBasedDataSource } from '../../env-graph';

export const commandSpec = define({
name: 'load',
Expand Down
2 changes: 1 addition & 1 deletion packages/varlock/src/cli/commands/plugin.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { define } from 'gunshi';
import { loadEnvGraph } from '../../../env-graph';
import { loadEnvGraph } from '../../env-graph';
import { type TypedGunshiCommandFn } from '../helpers/gunshi-type-utils';
import { checkForSchemaErrors } from '../helpers/error-checks';

Expand Down
4 changes: 2 additions & 2 deletions packages/varlock/src/cli/helpers/error-checks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ansis from 'ansis';
import { gracefulExit } from 'exit-hook';
import _ from '@env-spec/utils/my-dash';
import { EnvGraph, ConfigItem } from '../../../env-graph';
import { EnvGraph, ConfigItem } from '../../env-graph';
import { getItemSummary, joinAndCompact } from '../../lib/formatting';
import { VarlockError } from '../../../env-graph/lib/errors';
import { VarlockError } from '../../env-graph/lib/errors';


function showErrorLocationDetails(err: Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export function envFilesTest(spec: {
for (const key of Object.keys(spec.expectValues)) {
const item = g.configSchema[key];
if (spec.expectValues[key] === SchemaError) {
expect(item._schemaErrors.length).toBe(1);
expect(item._schemaErrors[0]).toBeInstanceOf(spec.expectValues[key]);
expect(item.errors.length).toBeGreaterThan(0);
expect(item.errors[0]).toBeInstanceOf(spec.expectValues[key]);
} else {
expect(item.resolvedValue, `${key} value did not match`).toEqual(spec.expectValues[key]);
}
Expand All @@ -94,8 +94,8 @@ export function envFilesTest(spec: {
for (const key of Object.keys(spec.expectRequired)) {
const item = g.configSchema[key];
if (spec.expectRequired[key] === SchemaError) {
expect(item._schemaErrors.length, 'Expected a schema error').toBe(1);
expect(item._schemaErrors[0]).toBeInstanceOf(spec.expectRequired[key]);
expect(item.errors.length, 'Expected a schema error').toBeGreaterThan(0);
expect(item.errors[0]).toBeInstanceOf(spec.expectRequired[key]);
} else {
expect(item.isRequired, `expected ${key} to be ${spec.expectRequired[key] ? 'required' : 'NOT required'}`).toBe(spec.expectRequired[key]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../../../src/plugin-lib.ts" />
/// <reference path="../../../../plugin-lib.ts" />

plugin.registerResolverFunction({
name: 'conflict',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../../../src/plugin-lib.ts" />
/// <reference path="../../../../plugin-lib.ts" />

plugin.registerResolverFunction({
name: 'conflict',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../../../src/plugin-lib.ts" />
/// <reference path="../../../../plugin-lib.ts" />

plugin.registerResolverFunction({
name: 'noop',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../../../src/plugin-lib.ts" />
/// <reference path="../../../../plugin-lib.ts" />

plugin.registerResolverFunction({
name: 'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,126 @@ describe('remap()', functionValueTests({
},
}));

describe('eq()', functionValueTests({
'check equality': {
input: outdent`
STR=eq("a", "a")
NUM=eq(42, 42)
BOOL=eq(false, false)
UNDEF=eq(undefined, undefined)
`,
expected: {
STR: true,
NUM: true,
BOOL: true,
UNDEF: true,
},
},
'check inequality': {
input: outdent`
STR=eq("a", "b")
NUM=eq(42, 41)
BOOL=eq(true, false)
MIXED=eq(42, "42")
`,
expected: {
STR: false,
NUM: false,
BOOL: false,
MIXED: false,
},
},
'with variables': {
input: outdent`
A=test
B=test
C=different
ITEM1=eq($A, $B)
ITEM2=eq($A, $C)
`,
expected: { ITEM1: true, ITEM2: false },
},
'with nested resolvers': {
input: 'ITEM=eq(concat("a", "b"), "ab")',
expected: { ITEM: true },
},
'working example - undefined values': {
input: outdent`
A=
B=
ITEM=eq($A, $B)
`,
expected: { A: undefined, B: undefined, ITEM: true },
},
'error - no args': {
input: 'ITEM=eq()',
expected: { ITEM: SchemaError },
},
'error - single arg': {
input: 'ITEM=eq("a")',
expected: { ITEM: SchemaError },
},
'error - too many args': {
input: 'ITEM=eq("a", "b", "c")',
expected: { ITEM: SchemaError },
},
'error - key/val args': {
input: 'ITEM=eq(left="a", right="b")',
expected: { ITEM: SchemaError },
},
}));

describe('if()', functionValueTests({
'working examples': {
input: outdent`
TRUE=if(true, yes, no)
FALSE=if(false, yes, no)
STR=if("a", yes, no)
NUM=if(1, yes, no)
NUM0=if(0, yes, no)
`,
expected: {
TRUE: 'yes',
FALSE: 'no',
STR: 'yes',
NUM: 'yes',
NUM0: 'no',
},
},
'with nested fns': {
input: outdent`
ITEM1=if(eq(a, a), if(true, yes), no)
ITEM2=if(eq(a, b), yes, if(true, no))
`,
expected: {
ITEM1: 'yes',
ITEM2: 'no',
},
},
'optional false value': {
input: outdent`
ITEM1=if(true, "yes")
ITEM2=if(false, "yes")
`,
expected: { ITEM1: 'yes', ITEM2: undefined },
},
'error - no args': {
input: 'ITEM=if()',
expected: { ITEM: SchemaError },
},
'error - single arg': {
input: 'ITEM=if(true)',
expected: { ITEM: SchemaError },
},
'error - key/val args': {
input: 'ITEM=if(condition=true, trueVal="yes", falseVal="no")',
expected: { ITEM: SchemaError },
},
'error - nested bad arg': {
input: 'ITEM=if(ref(BADKEY), "yes", "no")',
expected: { ITEM: SchemaError },
},
}));

describe('dependency cycles', functionValueTests({
'detect cycle - self': {
Expand Down
2 changes: 1 addition & 1 deletion packages/varlock/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
CoercionError,
ResolutionError,
type SerializedEnvGraph,
} from '../env-graph';
} from './env-graph';

export async function load() {
// TODO: add some options
Expand Down
2 changes: 1 addition & 1 deletion packages/varlock/src/lib/formatting.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ansis, { type AnsiColors, type AnsiStyles } from 'ansis';
import _ from '@env-spec/utils/my-dash';

import { ConfigItem, VarlockError } from '../../env-graph';
import { ConfigItem, VarlockError } from '../env-graph';
import { redactString } from '../runtime/lib/redaction';

type ColorMod = AnsiStyles | AnsiColors;
Expand Down
2 changes: 1 addition & 1 deletion packages/varlock/src/lib/load-graph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadEnvGraph } from '../../env-graph';
import { loadEnvGraph } from '../env-graph';

export async function loadVarlockEnvGraph(opts?: {
currentEnvFallback?: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/varlock/src/plugin-lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { VarlockPlugin } from '../env-graph/lib/plugins';
export type { Resolver } from '../env-graph/lib/resolver';
import type { VarlockPlugin } from './env-graph/lib/plugins';
export type { Resolver } from './env-graph/lib/resolver';

// we must inject our varlock code via the global scope
// because of how we dynamically import the plugin code
Expand Down
2 changes: 1 addition & 1 deletion packages/varlock/src/runtime/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { redactString } from './lib/redaction';

import type { SerializedEnvGraph } from '../../env-graph';
import type { SerializedEnvGraph } from '../env-graph';
import { isBrowser } from '../lib/detect-runtime';
import { debug } from './lib/debug';

Expand Down
1 change: 0 additions & 1 deletion packages/varlock/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
},
"include": [
"src/**/*.ts",
"env-graph/**/*.ts",
"*.ts",
],
"exclude": ["src/plugin-lib.ts"]
Expand Down