{"name":"@rushstack/rig-package","version":"0.3.11","description":"A system for sharing tool configurations between projects without duplicating config files.","main":"lib/index.js","typings":"dist/rig-package.d.ts","license":"MIT","repository":{"url":"git+https://github.com/microsoft/rushstack.git","type":"git","directory":"libraries/rig-package"},"dependencies":{"resolve":"~1.17.0","strip-json-comments":"~3.1.1"},"devDependencies":{"@rushstack/eslint-config":"2.6.0","@rushstack/heft-node-rig":"1.8.7","@rushstack/heft":"0.44.9","@types/heft-jest":"1.0.1","@types/node":"12.20.24","@types/resolve":"1.17.1","ajv":"~6.12.5","resolve":"~1.17.0"},"scripts":{"build":"heft build --clean","_phase:build":"heft build --clean","_phase:test":"heft test --no-build"},"_resolved":"","_integrity":"","_from":"file:rushstack-rig-package-0.3.11.tgz","bugs":{"url":"https://github.com/microsoft/rushstack/issues"},"homepage":"https://github.com/microsoft/rushstack#readme","_id":"@rushstack/rig-package@0.3.11","_nodeVersion":"12.22.12","_npmVersion":"6.14.16","dist":{"integrity":"sha512-uI1/g5oQPtyrT9nStoyX/xgZSLa2b+srRFaDk3r1eqC7zA5th4/bvTGl2QfV3C9NcP+coSqmk5mFJkUfH6i3Lw==","shasum":"92a05929822610e8b42f2ad330d9ea20afae5165","tarball":"http://registry-npm.ywwl.com/@rushstack/rig-package/download/@rushstack/rig-package-0.3.11.tgz","fileCount":18,"unpackedSize":82092,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFrl2/aTuKhNYDTzl20hdWYoMDrHrhGXTRU17G1zYfbfAiEAsieruREvV8D6UMHdAEg8e8xRV/AQA9u6ENYfHQ0NQik="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiY2EsACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpBzA/7BgXmaT7qXNV5pxTKmpqIoOk9Gq9gNihaRYK4niJuHeGoKyn2\r\ne2MW2v/9he9EaDlTIyvbHxYYmfWwoHgMZMEL0W63m7PfMa5dgL0lwNTSwg39\r\nUnQs4D9/PoyaEMey8ikQU2G22eAgYrQ5E5wVrNt9aKas+jtqNjEb3kHOeqGn\r\nkJzMouIAmHilV5fW4zjSTP/c5LjF2+mpbB3lUgm8oqd96C7roFIowoy+6cQG\r\nzJGRPiEHGeEa/xOYv6Cqz2De0N3ghAQ/e2UkwWoT8dqD6aCC+xmUsuDrQF2T\r\nMgpVsjiuVTE3nJwCGrfk9NfkBEBBe3hF5e4rPZE6fr6PUuBELwRHnLQyi2s5\r\nYPY9KA4dFZLkE/D5QFD6Hw7t8gzTS8Pl3mNfctZgHVPUVjcJMf4+N1MqcLaD\r\nYx0v8zywXhKb/0+JffFYfULs9pOLvq8eB+Mvmv+o9AZdpFzO3L2Mmkl+p1NQ\r\nt01H1C1di4nlxzzH2MPoIjRJbbF+ZE4EZHDxmQTu5C9YlVj5CQKQ1rndFrVW\r\nNmfQtnniHof3px7pdPJttx9EOzWbtdwu5Yo2egokMqyFC1IDxWHChJ5ZWjml\r\nFeDhcFo68iTkAfh8iy7fYn5E9j1rsejD7cDZVaSeU2sQ37+dcId6OuTH8OPL\r\n6mSu0r3tQk9z+n5cCIqZteXwHZG711oLMi4=\r\n=YAXg\r\n-----END PGP SIGNATURE-----\r\n","size":17594,"noattachment":false,"key":"/@rushstack/rig-package/-/@rushstack/rig-package-0.3.11.tgz"},"_npmUser":{"name":"odspnpm","email":"odspnpm@microsoft.com"},"directories":{},"maintainers":[{"name":"octogonz","email":"npm@octogonz.com"},{"name":"odspnpm","email":"odspnpm@microsoft.com"},{"name":"rushstack-admin","email":"rushstack@octogonz.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rig-package_0.3.11_1650680108260_0.42490780616459056"},"_hasShrinkwrap":false,"readme":"# @rushstack/rig-package\n\nThe **config/rig.json** file is a system that Node.js build tools can adopt, in order to eliminate\nduplication of config files when many projects share a common configuration. This is particularly valuable\nin a setup where hundreds of projects may be built using a small set of reusable recipes.\n\n## Motivation\n\nFor a concrete example, consider the [API Extractor](https://api-extractor.com/) tool which reads its\nconfiguration from **\\<projectFolder\\>/config/api-extractor.json**. Suppose that we have three separate projects\nthat all share the exact same configuration:\n\n```\nproject1/package.json\nproject1/config/api-extractor.json\nproject1/config/other-tool2.json\nproject1/config/other-tool3.json\nproject1/src/index.ts\n\nproject2/package.json\nproject2/config/api-extractor.json\nproject2/config/other-tool2.json\nproject2/config/other-tool3.json\nproject2/src/index.ts\n\nproject3/package.json\nproject3/config/api-extractor.json\nproject3/config/other-tool2.json\nproject3/config/other-tool3.json\nproject3/src/index.ts\n```\n\nIt seems wasteful to copy and paste the **api-extractor.json** file with all those settings. If we later need\nto tune the configuration, we'd have to find and update each file. For a large organization, there could be\nhundreds of such projects.\n\nThe `\"extends\"` setting provides a basic way to centralize the configuration in a \"rig package\". For this example,\nwe'll call our NPM package **example-rig**:\n\n```\nexample-rig/package.json\nexample-rig/profile/node-library/config/api-extractor.json\nexample-rig/profile/web-library/config/api-extractor.json\n\nproject1/package.json\nproject1/config/api-extractor.json\nproject1/config/other-tool2.json\nproject1/config/other-tool3.json\nproject1/src/index.ts\n\nproject2/package.json\nproject2/config/api-extractor.json\nproject2/config/other-tool2.json\nproject2/config/other-tool3.json\nproject2/src/index.ts\n\nproject3/package.json\nproject3/config/api-extractor.json\nproject3/config/other-tool2.json\nproject3/config/other-tool3.json\nproject3/src/index.ts\n```\n\nTo make things interesting, above we've introduced two \"profiles\":\n\n- `node-library` is for libraries that target the Node.js runtime\n- `web-library` is for libraries that target a web browser\n\n> **NOTE:** The `node-library` and `web-library` names are hypothetical examples. The names and purposes of\n> rig profiles are user-defined. If you only need one profile, then call it `default`.\n\nIf **project1** and **project2** are Node.js libraries, then their **api-extractor.json** now reduces to this:\n\n**project1/config/api-extractor.json**\n\n```js\n{\n  \"$schema\": \"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json\",\n  \"extends\": \"example-rig/profile/node-library/config/api-extractor.json\"\n}\n```\n\nWhereas if **project3** is a web browser library, then it might look like this:\n\n**project3/config/api-extractor.json**\n\n```js\n{\n  \"$schema\": \"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json\",\n  \"extends\": \"example-rig/profile/web-library/config/api-extractor.json\"\n}\n```\n\nUsing `\"extends\"` definitely made the config file shorter! But imagine that we have a large monorepo with 100 projects.\nAnd each project has 5 config files like **api-extactor.json**. We still have to copy+paste 100 x 5 = 500 config files\nacross all our project folders.\n\nCan we do better?\n\n## rig.json eliminates files entirely\n\nThe idea is to replace `config/api-extractor.json` and `config/other-tool2.json` (and any other such files)\nwith a single file `config/rig.json` that delegates everything to the rig package:\n\n**project3/config/rig.json**\n\n```js\n{\n  \"$schema\": \"https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json\",\n\n  /**\n   * (Required) The name of the rig package to inherit from.\n   * It should be an NPM package name with the \"-rig\" suffix.\n   */\n  \"rigPackageName\": \"example-rig\",\n\n  /**\n   * (Optional) Selects a config profile from the rig package.  The name must consist of\n   * lowercase alphanumeric words separated by hyphens, for example \"sample-profile\".\n   * If omitted, then the \"default\" profile will be used.\"\n   */\n  \"rigProfile\": \"web-library\"\n}\n```\n\nUsing **rig.json** eliminates the `\"extends\"` stub files entirely. A tool that implements the **rig.json** system\nwould probe for its config file (`<targetFile>.json`) using the following procedure:\n\n1. First check for `config/<targetFile>.json` in the project folder; if found, use that file. OTHERWISE...\n2. Check for `config/rig.json`; if found, then this project is using a rig package. Read the `<rigPackageName>`\n   and `<rigProfile>` settings from that file.\n3. Use Node.js module resolution to find the `<rigPackageName>` package folder (let's call that `<rigPackageFolder>`)\n4. Check for `<rigPackageFolder>/profile/<rigProfile>/<targetFile>.json`; if found, use that file. OTHERWISE...\n5. If the `<targetFile>.json` cannot be found in either of these places, the behavior is left to the tool.\n   For example, it could report an error, or proceed using defaults.\n\nIn cases where we need a project-specific customization, the `\"extends\"` field is still supported. For example,\n**project1** can still add a local override like this:\n\n**project1/config/api-extractor.json**\n\n```js\n{\n  \"$schema\": \"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json\",\n  \"extends\": \"example-rig/profile/node-library/config/api-extractor.json\",\n\n  // Local override:\n  \"mainEntryPointFilePath\": \"<projectFolder>/lib/custom.d.ts\",\n}\n```\n\nThe result is a much shorter inventory of files:\n\n```\nexample-rig/package.json\n\nexample-rig/profile/node-library/config/api-extractor.json\nexample-rig/profile/node-library/config/other-tool2.json\nexample-rig/profile/node-library/config/other-tool3.json\n\nexample-rig/profile/web-library/config/api-extractor.json\nexample-rig/profile/web-library/config/other-tool2.json\nexample-rig/profile/web-library/config/other-tool3.json\n\nproject1/package.json\nproject1/config/rig.json\nproject1/config/api-extractor.json  <-- local override shown above\nproject1/src/index.ts\n\nproject2/package.json\nproject2/config/rig.json\nproject2/src/index.ts\n\nproject3/package.json\nproject3/config/rig.json\nproject3/src/index.ts\n```\n\n## The `@rushstack/rig-package` API\n\nThe `@rushstack/rig-package` library provides an API for loading the **rig.json** file and performing lookups.\nIt is a lightweight NPM package, intended to be easy for tool projects to accept as a dependency. The package\nalso includes the JSON schema file **rig.schema.json**.\n\nExample usage of the API:\n\n```ts\nimport { RigConfig } from '@rushstack/rig-package';\n\n// Probe for the rig.json file and load it if found\nconst rigConfig: RigConfig = RigConfig.loadForProjectFolder({\n  // Specify a  project folder (i.e. where its package.json file is located)\n  projectFolderPath: testProjectFolder\n});\n\nif (rigConfig.rigFound) {\n  // We found a config/rig.json file\n  //\n  // Prints \"/path/to/project3/config/rig.json\"\n  console.log('Found rig.json: ' + rigConfig.filePath);\n\n  // Prints \"example-rig\"\n  console.log('The rig package is: ' + rigConfig.rigPackageName);\n\n  // Resolve the rig package\n  //\n  // Prints \"/path/to/project3/node_modules/example-rig/profile/web-library\"\n  console.log('Profile folder: ' + rigConfig.getResolvedProfileFolder());\n\n  // Look up a config file.  These file paths will be tested:\n  //\n  //   /path/to/project3/folder/file.json\n  //   /path/to/project3/node_modules/example-rig/profile/web-library/folder/file.json\n  //\n  // The result will be the first path that exists, or undefined if the config file was not found.\n  console.log('Resolved config file: ' + rigConfig.tryResolveConfigFilePath('folder/file.json'));\n}\n```\n\nNote that there are also async variants of the functions that access the filesystem.\n\n## Links\n\n- [CHANGELOG.md](\n  https://github.com/microsoft/rushstack/blob/main/libraries/rig-package/CHANGELOG.md) - Find\n  out what's new in the latest version\n- [API Reference](https://api.rushstack.io/pages/rig-package/)\n\n`@rushstack/rig-package` is part of the [Rush Stack](https://rushstack.io/) family of projects.\n","publish_time":1650680108403,"_cnpm_publish_time":1650680108403,"dist-tags":{"latest":"0.7.4"}}