cosmiconfig-loader-pkl
v0.2.0
Published
Loader for Apple's Pkl format.
Maintainers
Readme
cosmiconfig-loader-pkl
Loader for Apple's Pkl format.
Installation 💿
npm i cosmiconfig-loader-pklUsage 🚀
Pass the loader to cosmiconfig's loaders option, keyed by the .pkl extension. Since cosmiconfig merges your loaders into its defaults but leaves searchPlaces alone, you also have to tell it where to look for Pkl files:
import { cosmiconfig } from 'cosmiconfig';
import { pklLoader } from 'cosmiconfig-loader-pkl';
const explorer = cosmiconfig('myapp', {
searchPlaces: ['myapp.config.pkl'],
loaders: {
'.pkl': pklLoader,
},
});Synchronous usage
pklLoaderSync is a valid LoaderSync, for use with cosmiconfigSync():
import { cosmiconfigSync } from 'cosmiconfig';
import { pklLoaderSync } from 'cosmiconfig-loader-pkl';
const explorer = cosmiconfigSync('myapp', {
searchPlaces: ['myapp.config.pkl'],
loaders: {
'.pkl': pklLoaderSync,
},
});Both loaders shell out to the Pkl toolchain, so the sync one blocks the event loop for the duration of the evaluation. Prefer pklLoader unless you're in a context that can't await – a CLI's startup path, for instance.
[!TIP] The config file is handed to Pkl by path, so relative
amends,importandread()URIs resolve against the config file itself.
Custom Pkl options
Use createLoaders() to pass options through to the Pkl CLI. It returns both loaders as { async, sync }. The output format is always json and can't be overridden:
import { cosmiconfig } from 'cosmiconfig';
import { createLoaders } from 'cosmiconfig-loader-pkl';
const { async: pklLoader } = createLoaders({
// default config
allowedModules: undefined,
allowedResources: undefined,
timeout: 0,
cache: {
enabled: false,
directory: undefined
}
});
const explorer = cosmiconfig('myapp', {
searchPlaces: ['myapp.config.pkl'],
loaders: {
'.pkl': pklLoader,
},
});License ©️
This work is licensed under The MIT License.
