@lsst/pik-core 0.6.3 → 0.6.5

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type { Option, Selector, ParseResult, PikPlugin } from './lib/types/index.js';
2
2
  export { CommentStyle } from './lib/types/index.js';
3
- export { defineConfig, loadConfig, isValidPlugin, type PikConfig, } from './lib/config.js';
3
+ export { defineConfig, loadConfig, findLocalConfig, isValidPlugin, type PikConfig, } from './lib/config.js';
4
4
  export { Parser } from './lib/parser.js';
5
5
  export { Switcher } from './lib/switcher.js';
6
6
  export { SingleSwitcher } from './lib/single-switcher.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,aAAa,EACb,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,EACb,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
- import { pathToFileURL } from "url";
2
- import { existsSync } from "fs";
3
- import { resolve } from "path";
1
+ import { cosmiconfig } from "cosmiconfig";
4
2
  class CommentStyle {
5
3
  constructor(lineComment, blockOpen, blockClose) {
6
4
  this.lineComment = lineComment;
@@ -59,24 +57,20 @@ class CommentStyle {
59
57
  function defineConfig(config) {
60
58
  return config;
61
59
  }
62
- const CONFIG_FILES = [
63
- "pik.config.mts",
64
- "pik.config.ts",
65
- "pik.config.mjs",
66
- "pik.config.js",
67
- ".pik.config.mts",
68
- ".pik.config.ts",
69
- ".pik.config.mjs",
70
- ".pik.config.js"
71
- ];
72
60
  async function loadConfig(cwd = process.cwd()) {
73
- for (const configFile of CONFIG_FILES) {
74
- const configPath = resolve(cwd, configFile);
75
- if (existsSync(configPath)) {
76
- const configUrl = pathToFileURL(configPath).href;
77
- const module = await import(configUrl);
78
- return module.default;
79
- }
61
+ const explorer = cosmiconfig("pik", {
62
+ searchStrategy: "global"
63
+ });
64
+ const result = await explorer.search(cwd);
65
+ return result?.config ?? null;
66
+ }
67
+ async function findLocalConfig(cwd = process.cwd()) {
68
+ const explorer = cosmiconfig("pik", {
69
+ searchStrategy: "none"
70
+ });
71
+ const result = await explorer.search(cwd);
72
+ if (result) {
73
+ return result.filepath.split("/").pop() || null;
80
74
  }
81
75
  return null;
82
76
  }
@@ -314,6 +308,7 @@ export {
314
308
  SingleSwitcher,
315
309
  Switcher,
316
310
  defineConfig,
311
+ findLocalConfig,
317
312
  isValidPlugin,
318
313
  loadConfig
319
314
  };
@@ -25,9 +25,16 @@ export interface PikConfig {
25
25
  */
26
26
  export declare function defineConfig<T extends PikConfig>(config: T): T;
27
27
  /**
28
- * Load pik config from the current directory
28
+ * Load pik config by searching up the directory tree
29
+ * Uses cosmiconfig to search for config files starting from cwd
30
+ * Uses 'global' strategy to search up to home directory
29
31
  */
30
32
  export declare function loadConfig(cwd?: string): Promise<PikConfig | null>;
33
+ /**
34
+ * Check if a pik config file exists in the specified directory (not parent directories)
35
+ * Returns the config file name if found, null otherwise
36
+ */
37
+ export declare function findLocalConfig(cwd?: string): Promise<string | null>;
31
38
  /**
32
39
  * Validate that an object satisfies the PikPlugin interface
33
40
  */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAE9D;AAaD;;GAEG;AACH,wBAAsB,UAAU,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAYvF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAa5D"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAE9D;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAO3B;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAa5D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsst/pik-core",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Core library for parsing and switching @pik config markers",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  "!**/*.tsbuildinfo"
35
35
  ],
36
36
  "dependencies": {
37
- "commander": "^14.0.0"
37
+ "commander": "^14.0.0",
38
+ "cosmiconfig": "^9.0.0"
38
39
  }
39
40
  }