Skip to content
Merged
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ These are produced by tooling and overwritten on the next run — change the sou

## Code style

The [DEVELOPMENT](DEVELOPMENT.md) doc is authoritative for the topics below — see "[How to name and locate your package's files](DEVELOPMENT.md#develop-file-structure)" and "[How to work with modules](DEVELOPMENT.md#develop-modules)". Summarized here because they apply to nearly every change; consult the [DEVELOPMENT](DEVELOPMENT.md) doc when this summary is not enough, and treat it as correct if the two disagree.
The [DEVELOPMENT](DEVELOPMENT.md) doc is authoritative for the topics below — see "[How to name and locate your package's files](DEVELOPMENT.md#develop-file-structure)", "[How to work with modules](DEVELOPMENT.md#develop-modules)" and "[How to format your code](DEVELOPMENT.md#develop-formatting)". Summarized here because they apply to nearly every change; consult the [DEVELOPMENT](DEVELOPMENT.md) doc when this summary is not enough, and treat it as correct if the two disagree.

**File naming and placement.** All packages live in `packages/`, all local development scripts live in `bin/`.

Expand Down
23 changes: 23 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,29 @@ import { formatLabel } from './lib/format.js';



</p>
</details>

<details id="develop-formatting">
<summary>
<b>How to format your code</b>
</summary>
<p>

The repo lints with `@bust/eslint-config`'s `strict` option, which covers blank lines between statements, declaration order, constant naming, and test suite structure. The full list is in that package's "[Strict conventions](packages/eslint-config/README.md#strict-conventions)" section.

To check your code, and to fix everything but the naming and ordering rules:

```
npm run lint
npm run lint:fix
```

Two conventions are on you, since lint cannot check them:

* code is ordered top-down: the highest-level constructs first, lower-level and utility functions below them
* `it()` names the behavior concisely - e.g. `'Loads values from a .env file before building the config'`

</p>
</details>

Expand Down
3 changes: 1 addition & 2 deletions bin/create-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ try {
await git.add(['README.md', 'npm-shrinkwrap.json', pkg.path]);
await git.commit(`[${pkg.basename}] create package`);
await git.tag(['-a', pkg.tag, '-m', pkg.tag]);

logTitle('Success!');
logTitle(`Your new ${pkg.name} package is located here: ${pkg.path}`);
} catch (error){
Expand Down Expand Up @@ -72,6 +71,7 @@ async function promptForPackageInfo(cli){
if (await pkg.exists()){
return `Directory "${pkg.path}" already exists! please choose a different name.`;
}

return true;
},
},
Expand All @@ -85,4 +85,3 @@ async function promptForPackageInfo(cli){

return new Pkg({ name, description });
}

1 change: 0 additions & 1 deletion bin/lib/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export const REPO_DIR = path.join(__dirname, '..', '..');
export const TEMP_DIR = path.join(REPO_DIR, 'tmp');
export const PACKAGES_DIR = path.join(REPO_DIR, 'packages');
export const TEMPLATES_DIR = path.join(__dirname, '..', 'templates');

1 change: 0 additions & 1 deletion bin/lib/create-substitution-pattern.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const createSubstitutionPtn = (start, end) => {
return new RegExp(`${start}[\\s\\S]*?${end}`, 'gmi');
};

1 change: 0 additions & 1 deletion bin/lib/git.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ export class Git {
}
}
}

2 changes: 0 additions & 2 deletions bin/lib/load-templates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const loadTemplates = async () => {
const filename = path.join(TEMPLATES_DIR, f.name);
const tmplData = await fs.readFile(filename, 'utf8');
const key = formatKey(f);

templates[key] = _.template(tmplData, {
imports: {
camelCase: _.camelCase,
Expand All @@ -41,4 +40,3 @@ function formatKey(file){
const ext = parts.pop();
return _.camelCase(parts.join('-')) + ext;
}

1 change: 0 additions & 1 deletion bin/lib/log.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ export const logErrorAndExit = (error, code = 1) => {
console.error(error);
return process.exit(code);
};

5 changes: 0 additions & 5 deletions bin/lib/pkg.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export class Pkg {
}

const tag = `${this.name}@${version}`;

this.publishedTag = await this.git.hasTag(tag) ? tag : null;

return this.publishedTag;
}

Expand All @@ -88,9 +86,7 @@ export class Pkg {
const query = `--grep=\\[${basename}\\]`;
const fmt = '--pretty=format:%B';
const prefix = `[${basename}]`;

const { stdout: history } = await this.git.log([range, query, fmt]);

return history
.split('\n')
.filter((x) => !!x)
Expand Down Expand Up @@ -123,7 +119,6 @@ export class Pkg {
}

lines.push('\n');

return this.writeChangelog(
content.replace(ptn, lines.join('')),
);
Expand Down
2 changes: 0 additions & 2 deletions bin/show-unpublished-changes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ try {
const pkg = await Pkg.createFromDisk(args[0].trim());
const tag = await pkg.getPublishedTag();
const changes = await pkg.getUnpublishedChanges();

logTitle(`${pkg.name} - Unpublished Changes`);
log(tag
? `:::: since ${tag}`
Expand All @@ -27,4 +26,3 @@ try {
}

logTitle('All Done!');

1 change: 0 additions & 1 deletion bin/templates/index.test.ts.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ describe('<%= name %>', () => {
assert.equal(<%= exportName %>.greet(), 'hello world!');
});
});

1 change: 0 additions & 1 deletion bin/update-changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ try {
}

logTitle('All Done!');

1 change: 0 additions & 1 deletion bin/update-package-readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ try {
}

logTitle('All Done!');

1 change: 0 additions & 1 deletion bin/update-readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ function writeDocs(readme, docs){
const fragment = `${PKGLIST_MARKER_START}\n${docs}\n${PKGLIST_MARKER_END}`;
return readme.replace(ptn, fragment);
}

2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import bust from '@bust/eslint-config';
export default [
includeIgnoreFile(path.join(import.meta.dirname, '.gitignore')),

...bust({ nodeTest: true, ignores: ['**/docs/**'] }),
...bust({ nodeTest: true, strict: true, ignores: ['**/docs/**'] }),

{
name: 'jsville/tests',
Expand Down
14 changes: 7 additions & 7 deletions packages/config/docs/config/classes/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Class: Config\<S\>

Defined in: [config.ts:54](/packages/config/src/config.ts#L54)
Defined in: [config.ts:113](/packages/config/src/config.ts#L113)

Schema-driven configuration store. Given a [SettingsSchemaTree](../../node/interfaces/SettingsSchemaTree.md) and a
map of environment variables, hydrates each leaf setting's value from the
Expand Down Expand Up @@ -48,7 +48,7 @@ SettingsValue union.

> **new Config**\<`S`\>(`__namedParameters?`): `Config`\<`S`\>

Defined in: [config.ts:57](/packages/config/src/config.ts#L57)
Defined in: [config.ts:116](/packages/config/src/config.ts#L116)

#### Parameters

Expand All @@ -66,15 +66,15 @@ Defined in: [config.ts:57](/packages/config/src/config.ts#L57)

> **settings**: `Settings`

Defined in: [config.ts:55](/packages/config/src/config.ts#L55)
Defined in: [config.ts:114](/packages/config/src/config.ts#L114)

## Methods

### get()

> **get**\<`K`\>(`key`): `SettingsValueAt`\<`S`, `K`\>

Defined in: [config.ts:66](/packages/config/src/config.ts#L66)
Defined in: [config.ts:125](/packages/config/src/config.ts#L125)

Looks up a single setting's hydrated value by its dot-delimited key.

Expand Down Expand Up @@ -104,7 +104,7 @@ if `key` isn't present in the hydrated schema

> **getPublicEnvVars**(): [`ConfigEnvVars`](../../node/interfaces/ConfigEnvVars.md)

Defined in: [config.ts:95](/packages/config/src/config.ts#L95)
Defined in: [config.ts:154](/packages/config/src/config.ts#L154)

Returns every public setting's value keyed by its *environment variable
name* rather than its schema path.
Expand All @@ -119,7 +119,7 @@ name* rather than its schema path.

> **getPublicSettings**(): `PublicSettings`

Defined in: [config.ts:77](/packages/config/src/config.ts#L77)
Defined in: [config.ts:136](/packages/config/src/config.ts#L136)

Returns every hydrated setting marked `public: true`, keyed by dot-delimited path.

Expand All @@ -133,7 +133,7 @@ Returns every hydrated setting marked `public: true`, keyed by dot-delimited pat

> **hydrate**(`data`, `env?`): `Settings`

Defined in: [config.ts:118](/packages/config/src/config.ts#L118)
Defined in: [config.ts:177](/packages/config/src/config.ts#L177)

Walks a [SettingsSchemaTree](../../node/interfaces/SettingsSchemaTree.md), resolving each leaf's format,
coercing/validating its value from `env` (or its default), and
Expand Down
2 changes: 1 addition & 1 deletion packages/config/docs/node/interfaces/ConfigEnvVars.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Interface: ConfigEnvVars

Defined in: [types.ts:241](/packages/config/src/types.ts#L241)
Defined in: [types.ts:242](/packages/config/src/types.ts#L242)

A map of environment variable names to values. Values are typically raw
strings (as they'd come from `process.env`), but pre-coerced values are
Expand Down
9 changes: 3 additions & 6 deletions packages/config/src/browser.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ describe('@bust/config/browser', () => {
delete (globalThis as GlobalWithBustConfig).__BUST_CONFIG__;
});

describe('createConfig', () => {
describe('createConfig()', () => {
it('Builds a config sourced from its schema defaults when nothing was baked in', () => {
const config = createConfig(schema);
assert.strictEqual(config.get('app.name'), 'My App');
});

it('Builds a config sourced from a `getBrowserDefine()`-baked settings blob', () => {
(globalThis as GlobalWithBustConfig).__BUST_CONFIG__ = { MY_APP_NAME: 'Baked In By Vite' };

const config = createConfig(schema);
assert.strictEqual(config.get('app.name'), 'Baked In By Vite');
});
});

describe('Schema-derived types', () => {
describe('createConfig() schema-derived types', () => {
it('Types keys and values from the schema, same as the Node entry point', () => {
const config = createConfig({
app: {
Expand All @@ -41,22 +40,20 @@ describe('@bust/config/browser', () => {
});
const name: string = config.get('app.name');
const mode: 'light' | 'dark' = config.get('app.mode');

// @ts-expect-error - 'app.nmae' is a typo, not a declared key
assert.throws(() => config.get('app.nmae'));
assert.strictEqual(name, 'My App');
assert.strictEqual(mode, 'light');
});
});

describe('getBrowserEnv', () => {
describe('getBrowserEnv()', () => {
it('Falls back to an empty object when nothing was baked in', () => {
assert.deepEqual(getBrowserEnv(), {});
});

it('Returns the settings blob a bundler baked in via `define`', () => {
(globalThis as GlobalWithBustConfig).__BUST_CONFIG__ = { MY_APP_NAME: 'Baked In By Vite' };

assert.deepEqual(getBrowserEnv(), { MY_APP_NAME: 'Baked In By Vite' });
});
});
Expand Down
Loading
Loading