@rstackjs/load-config 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,13 +13,27 @@ A config loading utility for the Rstack ecosystem, designed for loading JavaScri
13
13
  ## Installation
14
14
 
15
15
  ```bash
16
+ # pnpm
17
+ pnpm add @rstackjs/load-config -D
18
+ # yarn
19
+ yarn add @rstackjs/load-config -D
20
+ # npm
16
21
  npm add @rstackjs/load-config -D
22
+ # bun
23
+ bun add @rstackjs/load-config -D
17
24
  ```
18
25
 
19
26
  [jiti](https://github.com/unjs/jiti) is an optional peer dependency. Install it only when you use the `jiti` or `auto` loaders:
20
27
 
21
28
  ```bash
29
+ # pnpm
30
+ pnpm add jiti -D
31
+ # yarn
32
+ yarn add jiti -D
33
+ # npm
22
34
  npm add jiti -D
35
+ # bun
36
+ bun add jiti -D
23
37
  ```
24
38
 
25
39
  ## Usage
package/dist/index.js CHANGED
@@ -38,12 +38,6 @@ const loadWithJiti = async (configPath, exportName, fresh)=>{
38
38
  };
39
39
  };
40
40
  const JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/;
41
- const tryFreshImport = async (configFileURL)=>{
42
- try {
43
- const { freshImport } = await import("./freshImport.js");
44
- return await freshImport(configFileURL);
45
- } catch {}
46
- };
47
41
  const loadWithNative = async (configPath, fresh)=>{
48
42
  const configFileURL = pathToFileURL(configPath).href;
49
43
  if (!fresh) {
@@ -53,7 +47,8 @@ const loadWithNative = async (configPath, fresh)=>{
53
47
  dependencies: []
54
48
  };
55
49
  }
56
- const freshImportResult = await tryFreshImport(configFileURL);
50
+ const { freshImport } = await import("./freshImport.js");
51
+ const freshImportResult = await freshImport(configFileURL);
57
52
  if (freshImportResult) return {
58
53
  configModule: freshImportResult.result,
59
54
  dependencies: freshImportResult.dependencies.sort()
@@ -77,6 +72,7 @@ const resolveConfigPath = (root, customConfig, configFileNames = [])=>{
77
72
  return null;
78
73
  };
79
74
  async function loadConfig({ cwd = process.cwd(), path, configFileNames = [], loader = 'auto', exportName = 'default', configParams = [], fresh = false } = {}) {
75
+ if (!path && 0 === configFileNames.length) throw new Error('Either `path` or at least one `configFileNames` entry must be provided.');
80
76
  const configPath = resolveConfigPath(cwd, path, configFileNames);
81
77
  if (!configPath) return {
82
78
  content: {},
package/dist/types.d.ts CHANGED
@@ -14,7 +14,7 @@ export type LoadConfigOptions<Params extends unknown[] = []> = {
14
14
  path?: string;
15
15
  /**
16
16
  * Config file names to search in `cwd` when `path` is not provided.
17
- * The package-level loader has no built-in framework defaults.
17
+ * Required when `path` is not provided.
18
18
  * @default []
19
19
  */
20
20
  configFileNames?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstackjs/load-config",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rstackjs/load-config"