{"id":18084,"library":"yargs-test-extends","title":"Yargs Configuration Extends Test Module","description":"The `yargs-test-extends` package is a specialized internal fixture designed for unit testing the `.config()` and `extends` functionality within the `yargs` command-line argument parsing library. It is not intended for general-purpose use in consumer applications, but rather serves as a static configuration source to verify `yargs`'s dynamic configuration loading capabilities. This package currently maintains version `1.0.1`. Its primary role is to demonstrate and verify that `yargs` can load configuration from an external Node.js module by inspecting its `main` entry point, which points to a static `index.json` file containing predefined configuration values. This mechanism tests `yargs`'s ability to extend configuration dynamically from installed packages rather than solely from local JSON files, ensuring robust configuration management within the `yargs` ecosystem.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install yargs-test-extends","lang":"bash","label":"npm"},{"cmd":"yarn add yargs-test-extends","lang":"bash","label":"yarn"},{"cmd":"pnpm add yargs-test-extends","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is designed as a configuration fixture for `yargs`. It is referenced by its package name as a string to `yargs`'s `.config()` method, which then internally resolves its `main` entry point (`index.json`) for configuration. This is the primary intended method of 'using' this package.","symbol":"yargs-test-extends (as config extension string)","correct":"yargs().config({ extends: 'yargs-test-extends' })"},{"note":"Direct CommonJS `require()` of this package will load the raw `index.json` content as a JavaScript object. This is typically not the intended use when interacting with `yargs`'s `extends` feature, but useful for inspecting the raw configuration fixture programmatically.","symbol":"config (CommonJS direct require)","correct":"const config = require('yargs-test-extends');"},{"note":"In an ESM environment, importing this package directly will similarly yield the `index.json` content as the default export. Note that `yargs`'s `extends` mechanism handles module resolution differently from direct module imports, and named imports like `{ c }` will not work as the JSON is a default export.","wrong":"import { c } from 'yargs-test-extends';","symbol":"config (ESM direct import)","correct":"import config from 'yargs-test-extends';"}],"quickstart":{"code":"const yargs = require('yargs');\nconst assert = require('assert');\n\n// This example demonstrates how yargs loads configuration\n// from the 'yargs-test-extends' module via its 'extends' mechanism.\n// The 'yargs-test-extends' package's package.json specifies 'index.json' as its main.\n// The index.json contains { \"c\": 201 }.\n// The initial config sets 'a' to 2.\n\nconst argv = yargs()\n  .config({\n    a: 2,\n    extends: 'yargs-test-extends' // Yargs resolves this module's main file\n  })\n  .argv;\n\n// Verify that the initial config 'a' is preserved.\nassert.strictEqual(argv.a, 2, 'Value for `a` should be 2 from direct config.');\n\n// Verify that 'c' is loaded from the extended module.\nassert.strictEqual(argv.c, 201, 'Value for `c` should be 201 from extended module.');\n\nconsole.log('Yargs successfully extended configuration from yargs-test-extends.');\nconsole.log('Parsed argv:', argv);","lang":"javascript","description":"Demonstrates `yargs` loading configuration from an external Node.js module specified by `extends`."},"warnings":[{"fix":"Avoid using 'yargs-test-extends' in production code. For dynamic configuration in your own `yargs` applications, create your own module that exports a configuration object or points to a custom JSON file.","message":"This package (`yargs-test-extends`) is a test fixture for the 'yargs' library and is not intended for general use in consumer applications. It serves a specific role in `yargs`'s internal testing suite.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need to inspect the raw configuration, direct import/require is functional. However, if you intend for `yargs` to interpret it as an extension, you must use `yargs().config({ extends: 'yargs-test-extends' })`.","message":"Attempting to import or require 'yargs-test-extends' directly will return the raw JSON object defined in its `index.json` file, not a processed `yargs` configuration object or functionality. Its `package.json` specifies `main: 'index.json'`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Understand that direct `require('yargs-test-extends')` or `import config from 'yargs-test-extends'` provides the raw JSON content. For `yargs` to process it as an extension, use `yargs().config({ extends: 'yargs-test-extends' })`.","cause":"The package's `main` entry points to `index.json`, causing `require()` or `import` to return a plain JavaScript object (parsed JSON), not a module exporting functions or a default configuration object interpreted by `yargs`.","error":"Unexpected object received when requiring 'yargs-test-extends' directly."},{"fix":"Ensure `yargs-test-extends` is listed in your project's `dependencies` or `devDependencies` (if used only for testing) and installed via `npm install yargs-test-extends` or `yarn add yargs-test-extends`.","cause":"The `yargs-test-extends` package has not been installed, but `yargs`'s `.config({ extends: 'yargs-test-extends' })` is attempting to resolve it.","error":"Module not found: Can't resolve 'yargs-test-extends'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}