c12 1.4.0 → 1.4.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
@@ -75,9 +75,9 @@ Resolve configuration from this working directory. The default is `process.cwd()
75
75
 
76
76
  Configuration base name. The default is `config`.
77
77
 
78
- ### `configName`
78
+ ### `configFile`
79
79
 
80
- Configuration file name without extension. Default is generated from `name` (name=foo => `foo.config`).
80
+ Configuration file name without extension. Default is generated from `name` (f.e., if `name` is `foo`, the config file will be => `foo.config`).
81
81
 
82
82
  Set to `false` to avoid loading the config file.
83
83
 
package/dist/index.cjs CHANGED
@@ -64,7 +64,7 @@ async function loadDotenv(options) {
64
64
  }
65
65
  function interpolate(target, source = {}, parse = (v) => v) {
66
66
  function getValue(key) {
67
- return source[key] !== void 0 ? source[key] : target[key];
67
+ return source[key] === void 0 ? target[key] : source[key];
68
68
  }
69
69
  function interpolate2(value, parents = []) {
70
70
  if (typeof value !== "string") {
@@ -94,7 +94,7 @@ function interpolate(target, source = {}, parse = (v) => v) {
94
94
  value2 = getValue(key);
95
95
  value2 = interpolate2(value2, [...parents, key]);
96
96
  }
97
- return value2 !== void 0 ? newValue.replace(replacePart, value2) : newValue;
97
+ return value2 === void 0 ? newValue : newValue.replace(replacePart, value2);
98
98
  }, value)
99
99
  );
100
100
  }
@@ -107,7 +107,7 @@ async function loadConfig(options) {
107
107
  options.cwd = pathe.resolve(process.cwd(), options.cwd || ".");
108
108
  options.name = options.name || "config";
109
109
  options.envName = options.envName ?? process.env.NODE_ENV;
110
- options.configFile = options.configFile ?? (options.name !== "config" ? `${options.name}.config` : "config");
110
+ options.configFile = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
111
111
  options.rcFile = options.rcFile ?? `.${options.name}rc`;
112
112
  if (options.extend !== false) {
113
113
  options.extend = {
@@ -276,7 +276,8 @@ async function resolveConfig(source, options, sourceOptions = {}) {
276
276
  } catch {
277
277
  }
278
278
  }
279
- const isDir = !pathe.extname(source);
279
+ const ext = pathe.extname(source);
280
+ const isDir = !ext || ext === pathe.basename(source);
280
281
  const cwd = pathe.resolve(options.cwd, isDir ? source : pathe.dirname(source));
281
282
  if (isDir) {
282
283
  source = options.configFile;
@@ -329,11 +330,12 @@ const eventMap = {
329
330
  async function watchConfig(options) {
330
331
  let config = await loadConfig(options);
331
332
  const configName = options.name || "config";
333
+ const configFileName = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
332
334
  const watchingFiles = [
333
335
  ...new Set(
334
336
  (config.layers || []).filter((l) => l.cwd).flatMap((l) => [
335
337
  ...["ts", "js", "mjs", "cjs", "cts", "mts", "json"].map(
336
- (ext) => pathe.resolve(l.cwd, (options.name || "config") + "." + ext)
338
+ (ext) => pathe.resolve(l.cwd, configFileName + "." + ext)
337
339
  ),
338
340
  l.source && pathe.resolve(l.cwd, l.source),
339
341
  // TODO: Support watching rc from home and workspace
@@ -378,10 +380,10 @@ async function watchConfig(options) {
378
380
  await options.onUpdate(changeCtx);
379
381
  }
380
382
  };
381
- if (options.debounce !== false) {
382
- _fswatcher.on("all", perfectDebounce.debounce(onChange, options.debounce));
383
- } else {
383
+ if (options.debounce === false) {
384
384
  _fswatcher.on("all", onChange);
385
+ } else {
386
+ _fswatcher.on("all", perfectDebounce.debounce(onChange, options.debounce ?? 100));
385
387
  }
386
388
  const utils = {
387
389
  watchingFiles,
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, promises } from 'node:fs';
2
- import { resolve, extname, dirname } from 'pathe';
2
+ import { resolve, extname, basename, dirname } from 'pathe';
3
3
  import * as dotenv from 'dotenv';
4
4
  import { rm } from 'node:fs/promises';
5
5
  import { homedir } from 'node:os';
@@ -44,7 +44,7 @@ async function loadDotenv(options) {
44
44
  }
45
45
  function interpolate(target, source = {}, parse = (v) => v) {
46
46
  function getValue(key) {
47
- return source[key] !== void 0 ? source[key] : target[key];
47
+ return source[key] === void 0 ? target[key] : source[key];
48
48
  }
49
49
  function interpolate2(value, parents = []) {
50
50
  if (typeof value !== "string") {
@@ -74,7 +74,7 @@ function interpolate(target, source = {}, parse = (v) => v) {
74
74
  value2 = getValue(key);
75
75
  value2 = interpolate2(value2, [...parents, key]);
76
76
  }
77
- return value2 !== void 0 ? newValue.replace(replacePart, value2) : newValue;
77
+ return value2 === void 0 ? newValue : newValue.replace(replacePart, value2);
78
78
  }, value)
79
79
  );
80
80
  }
@@ -87,7 +87,7 @@ async function loadConfig(options) {
87
87
  options.cwd = resolve(process.cwd(), options.cwd || ".");
88
88
  options.name = options.name || "config";
89
89
  options.envName = options.envName ?? process.env.NODE_ENV;
90
- options.configFile = options.configFile ?? (options.name !== "config" ? `${options.name}.config` : "config");
90
+ options.configFile = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
91
91
  options.rcFile = options.rcFile ?? `.${options.name}rc`;
92
92
  if (options.extend !== false) {
93
93
  options.extend = {
@@ -256,7 +256,8 @@ async function resolveConfig(source, options, sourceOptions = {}) {
256
256
  } catch {
257
257
  }
258
258
  }
259
- const isDir = !extname(source);
259
+ const ext = extname(source);
260
+ const isDir = !ext || ext === basename(source);
260
261
  const cwd = resolve(options.cwd, isDir ? source : dirname(source));
261
262
  if (isDir) {
262
263
  source = options.configFile;
@@ -309,11 +310,12 @@ const eventMap = {
309
310
  async function watchConfig(options) {
310
311
  let config = await loadConfig(options);
311
312
  const configName = options.name || "config";
313
+ const configFileName = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
312
314
  const watchingFiles = [
313
315
  ...new Set(
314
316
  (config.layers || []).filter((l) => l.cwd).flatMap((l) => [
315
317
  ...["ts", "js", "mjs", "cjs", "cts", "mts", "json"].map(
316
- (ext) => resolve(l.cwd, (options.name || "config") + "." + ext)
318
+ (ext) => resolve(l.cwd, configFileName + "." + ext)
317
319
  ),
318
320
  l.source && resolve(l.cwd, l.source),
319
321
  // TODO: Support watching rc from home and workspace
@@ -358,10 +360,10 @@ async function watchConfig(options) {
358
360
  await options.onUpdate(changeCtx);
359
361
  }
360
362
  };
361
- if (options.debounce !== false) {
362
- _fswatcher.on("all", debounce(onChange, options.debounce));
363
- } else {
363
+ if (options.debounce === false) {
364
364
  _fswatcher.on("all", onChange);
365
+ } else {
366
+ _fswatcher.on("all", debounce(onChange, options.debounce ?? 100));
365
367
  }
366
368
  const utils = {
367
369
  watchingFiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c12",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Smart Config Loader",
5
5
  "repository": "unjs/c12",
6
6
  "license": "MIT",
@@ -26,32 +26,32 @@
26
26
  "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
27
27
  "prepack": "unbuild",
28
28
  "release": "changelogen --release && npm publish && git push --follow-tags",
29
- "test": "vitest run --coverage && pnpm test:types",
29
+ "test": "pnpm lint && vitest run --coverage && pnpm test:types",
30
30
  "test:types": "tsc --noEmit"
31
31
  },
32
32
  "dependencies": {
33
33
  "chokidar": "^3.5.3",
34
34
  "defu": "^6.1.2",
35
- "dotenv": "^16.0.3",
35
+ "dotenv": "^16.3.1",
36
36
  "giget": "^1.1.2",
37
37
  "jiti": "^1.18.2",
38
- "mlly": "^1.2.0",
39
- "ohash": "^1.1.1",
40
- "pathe": "^1.1.0",
41
- "perfect-debounce": "^0.1.3",
42
- "pkg-types": "^1.0.2",
43
- "rc9": "^2.1.0"
38
+ "mlly": "^1.4.0",
39
+ "ohash": "^1.1.2",
40
+ "pathe": "^1.1.1",
41
+ "perfect-debounce": "^1.0.0",
42
+ "pkg-types": "^1.0.3",
43
+ "rc9": "^2.1.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@vitest/coverage-c8": "^0.30.1",
46
+ "@vitest/coverage-v8": "^0.32.2",
47
47
  "changelogen": "^0.5.3",
48
- "eslint": "^8.38.0",
49
- "eslint-config-unjs": "^0.1.0",
50
- "expect-type": "^0.15.0",
51
- "prettier": "^2.8.7",
52
- "typescript": "^5.0.4",
48
+ "eslint": "^8.43.0",
49
+ "eslint-config-unjs": "^0.2.1",
50
+ "expect-type": "^0.16.0",
51
+ "prettier": "^2.8.8",
52
+ "typescript": "^5.1.3",
53
53
  "unbuild": "^1.2.1",
54
- "vitest": "^0.30.1"
54
+ "vitest": "^0.32.2"
55
55
  },
56
- "packageManager": "pnpm@8.3.0"
56
+ "packageManager": "pnpm@8.6.3"
57
57
  }