-
Notifications
You must be signed in to change notification settings - Fork 34
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
72636c
wants to merge
1
commit into
main
Choose a base branch
from
skuba-config-ts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Propose skuba.config.ts
#1168
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
|
||
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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