Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose skuba.config.ts #1168

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions docs/deep-dives/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
parent: Deep dives
---

# Config

**skuba** configuration can be specified in an optional `skuba.config.ts` file next to your `package.json`.

```typescript
import { SkubaConfig } from 'skuba';

const config: SkubaConfig = {
assets: [...SkubaConfig.assets.default, '**/*.adoc'],
};

export default config;
```
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"ejs": "^3.1.6",
"enquirer": "^2.3.6",
"esbuild": "~0.17.0",
"esbuild-register": "^3.4.2",
"eslint": "^8.11.0",
"eslint-config-skuba": "2.0.2",
"execa": "^5.0.0",
Expand Down Expand Up @@ -117,7 +118,8 @@
"tsconfig-paths": "^4.0.0",
"tsconfig-seek": "1.0.2",
"typescript": "~5.0.0",
"validate-npm-package-name": "^5.0.0"
"validate-npm-package-name": "^5.0.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@changesets/cli": "2.26.1",
Expand Down
32 changes: 32 additions & 0 deletions src/config/load.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import path from 'path';

import { register } from 'esbuild-register/dist/node';

import { type SkubaConfig, skubaConfigSchema } from './types';

import { getDestinationManifest } from 'cli/configure/analysis/package';
import { log } from 'utils/logging';

const CONFIG_FILENAME = 'skuba.config.ts';

export const loadSkubaConfig = async (cwd?: string): Promise<SkubaConfig> => {
// FIXME: remove underlying `process.exit`
const manifest = await getDestinationManifest({ cwd });

const configPath = path.join(manifest.path, '..', CONFIG_FILENAME);

const esbuildRegistration = register({ target: 'node16' });
Copy link
Contributor

@mrm007 mrm007 May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth having a hot reloading ability when the config changes, e.g. restart the server started with skuba start or anything like that.

For reference, we do this in Crackle:
https://github.com/seek-oss/crackle/blob/49b48ee405477cccdc1d6e7bbbb4c26b921c7760/packages/cli/src/index.ts#L33-L44
https://github.com/seek-oss/crackle/blob/560489afdadda7f8b3985f0639ae55f83815875e/packages/core/src/entries/resolve-config.ts#L25


try {
const rawConfig: unknown = await import(configPath);

return skubaConfigSchema.parse(rawConfig);
} catch (err) {
log.warn(`Failed to load ${log.bold(configPath)}.`);
log.subtle(err);

return {};
} finally {
esbuildRegistration.unregister();
}
};
36 changes: 36 additions & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { z } from 'zod';

export const skubaConfigSchema = z.object({
/**
* Files to copy from the working directory to the output directory after
* compilation. This feature is useful to bundle non-JavaScript assets in an
* npm package, back-end deployment package or container image.
*
* Supports `picomatch` glob patterns with dotfile matching.
*
* - https://github.com/micromatch/picomatch#globbing-features
* - https://github.com/micromatch/picomatch#picomatch-options
*
* Commands:
*
* - `skuba build`
* - `skuba build-package`
*/
assets: z.array(z.string()).optional(),
});

export const SkubaConfig = {
assets: {
/**
* The default list of `assets` that are applied if your project does not
* specify the configuration property.
*
* Currently includes:
*
* - JSON translation files for https://github.com/seek-oss/vocab
*/
default: ['**/*.vocab/*translations.json'],
},
};

export type SkubaConfig = z.infer<typeof skubaConfigSchema>;
46 changes: 45 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@ import * as skuba from '.';

describe('skuba', () => {
it('exports', () => {
expect(skuba).toHaveProperty('Net');
expect(skuba).toMatchInlineSnapshot(`
{
"Buildkite": {
"annotate": [Function],
"md": {
"terminal": [Function],
},
},
"Git": {
"commit": [Function],
"commitAllChanges": [Function],
"currentBranch": [Function],
"fastForwardBranch": [Function],
"getChangedFiles": [Function],
"getHeadCommitId": [Function],
"getHeadCommitMessage": [Function],
"getOwnerAndRepo": [Function],
"push": [Function],
"reset": [Function],
},
"GitHub": {
"buildNameFromEnvironment": [Function],
"createCheckRun": [Function],
"enabledFromEnvironment": [Function],
"getPullRequestNumber": [Function],
"putIssueComment": [Function],
"readFileChanges": [Function],
"uploadAllFileChanges": [Function],
"uploadFileChanges": [Function],
},
"Jest": {
"mergePreset": [Function],
},
"Net": {
"waitFor": [Function],
},
"SkubaConfig": {
"assets": {
"default": [
"**/*.vocab/*translations.json",
],
},
},
}
`);
});
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * as Git from './api/git';
export * as GitHub from './api/github';
export * as Jest from './api/jest';
export * as Net from './api/net';
export { SkubaConfig } from './config/types';

// evanw/esbuild#2388
declare global {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3611,6 +3611,13 @@ es-to-primitive@^1.2.1:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

esbuild-register@^3.4.2:
version "3.4.2"
resolved "https://registry.yarnpkg.com/esbuild-register/-/esbuild-register-3.4.2.tgz#1e39ee0a77e8f320a9790e68c64c3559620b9175"
integrity sha512-kG/XyTDyz6+YDuyfB9ZoSIOOmgyFCH+xPRtsCa8W85HLRV5Csp+o3jWVbOSHgSLfyLc5DmP+KFDNwty4mEjC+Q==
dependencies:
debug "^4.3.4"

esbuild@~0.17.0:
version "0.17.18"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.18.tgz#f4f8eb6d77384d68cd71c53eb6601c7efe05e746"
Expand Down Expand Up @@ -10025,6 +10032,11 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

zod@^3.21.4:
version "3.21.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db"
integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==

zwitch@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-2.0.4.tgz#c827d4b0acb76fc3e685a4c6ec2902d51070e9d7"
Expand Down