{"id":19777495,"url":"https://github.com/ilib-js/conditionalinstall","last_synced_at":"2026-02-26T17:45:57.118Z","repository":{"id":213167677,"uuid":"733156187","full_name":"iLib-js/conditionalInstall","owner":"iLib-js","description":"Install npm packages based on various conditions","archived":false,"fork":false,"pushed_at":"2024-10-08T08:11:34.000Z","size":80,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-01T12:52:45.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iLib-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-18T17:28:00.000Z","updated_at":"2024-10-08T08:07:43.000Z","dependencies_parsed_at":"2023-12-19T03:24:53.505Z","dependency_job_id":"95a9f5b5-27d3-423e-8159-a4052b60917c","html_url":"https://github.com/iLib-js/conditionalInstall","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"3abfa44e0a2205da76ad071a165b5c2866885a1c"},"previous_names":["ilib-js/conditionalinstall"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/iLib-js/conditionalInstall","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2FconditionalInstall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2FconditionalInstall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2FconditionalInstall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2FconditionalInstall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iLib-js","download_url":"https://codeload.github.com/iLib-js/conditionalInstall/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iLib-js%2FconditionalInstall/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268075014,"owners_count":24191651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T05:25:16.623Z","updated_at":"2026-02-26T17:45:57.097Z","avatar_url":"https://github.com/iLib-js.png","language":"JavaScript","readme":"# conditional-install\n\nA utility to install npm packages based on certain conditions.\n \nWhy?\n--------------------\n\nThe original motivation for this package is to install the proper version of\nthe jest unit testing library.\n\nSome of the ilib packages supported node 10 through the\ncurrent latest version and used jest as their unit testing library. The only\nproblem is that the latest version of jest did not run on node 10 through 13\nbecause it was rewritten with ES6 syntax in jest@27.0.0. The tests, which were\nnot particularly fancy and did not use any advanced features, ran fine\nwith jest@26.6.2 on older versions of node but would not work with the latest\njest because it wasn't transpiled to support older versions of node.\n\nWhat was needed was a way to install jest@26 for older versions of node and\njest@29 for the newer ones. There was no easy, elegant way to do that.\n\nHence this conditional install package.\n\nHow Does it Work?\n--------------------\n\nUsage is simple. Basically, modify your package.json to include conditional\ndependencies, and then run this package as a postinstall script.\n\nHere is what the package.json would look like:\n\n```json\n{\n    \"name\": \"mypackage\",\n    \"scripts\": {\n        \"postinstall\": \"conditional-install\"\n    },\n    \"dependencies\": {\n        \"conditional-install\": \"^1.0.0\"\n    },\n    \"conditionalDependencies\": {\n        \"process.version \u003e= 14.0.0\": {\n            \"example-package\": \"^29.0.0\"\n        },\n        \"process.version \u003c 14.0.0\": {\n            \"example-package\": \"^26.0.0\"\n        }\n    }\n}\n```\n\nThe postinstall script is run automatically by `npm` or `yarn` after the\nregular installation is complete. If you are using `npm-ci`, it does not, so\nyou will have to run `npm-ci run postinstall` explicitly in order to\ninstall the conditional dependencies.\n\nThe `conditionalDependencies` object contains properties that are\nexpressions to test against the current version of node. Inside of the\nvalue object is a list of dependencies to install if the value of that\nexpression is true. All dependencies inside of the value are installed.\nThe versions are specified with the same syntax as regular, dev, or peer\ndependencies.\n\nWhen the dependencies are installed, they are installed using the current\npackage manner, but in such a way that the new dependencies are not saved\nto the package.json.\n\nConditional Expressions\n----------------------\n\nThe expressions are built on the hard work of\n[node-compat-table](https://github.com/williamkapke/node-compat-table).\n\nThe core of an expression is a test. There are multiple things that can\nbe tested:\n\n- A JS \"feature\" to test against from the node-compat-table project. This tests whether or not\n  the current version of node supports that feature. For example, the feature may be\n  `RegExp.prototype.flags`. See the [node.green](https://node.green) web site to see all the\n  possible features and their pass/fail values for various versions of node.\n- ECMAScript versions. If you give then name or alias of a version of ECMAScript, it\n  can test to see if the current version of node supports that form of ECMAScript. Examples\n  are \"ES2015\" or \"ES6\" or \"ESM\". The data for this is also from node-compat-tables.\n- The value of a setting in the `process` variable. There are various different\n  possible types of values:\n    - numbers. Example: `process.config.variables.icu_ver_major` will give you the major\n      version of ICU that this version of node supports as a number\n    - strings. Example: `process.ENV.variableName` will return you the value of an environment\n      variable as a string. In this way, you can control conditional installation\n      with external means. Strings may have spaces and other characters in them\n      so that they can represent JS features.\n    - versions. Example: `process.versions.node` will return a full version spec,\n      like \"v14.4.2\" or \"18.0.0\". This may or may not have the leading \"v\" in front\n      of it.\n    - booleans. Example: `process.config.variables.icu_small` return true if this\n      version of node uses the small ICU package, and false if this version has\n      full ICU.\n\nIndividual tests can be combined into more complex expressions together using the following\nfamiliar operators. All operators return a boolean value as well.\n\n- `!` is \"not\". A value can be negated using this unary operator, meaning that the current\nversion of node does NOT support that feature. Negation for numbers are similar to\nJavascript's truthy and falsy. String literals that do not name a JS feature, an ES\nversion, or a setting inside of the process variable are considered to be false.\n- `\u0026\u0026` is \"and\". Both sides must be true\n- `||` is \"or\". At least one side must be true\n- `=` is \"equals\". Both sides must be equal\n- `!=` is \"not equal\". Both sides must not be equal each other\n- `\u003e` is \"greater than\". Left side must be greater than the right side\n- `\u003e=` is \"greater than or equal to\". Left side must be greater than or equal to the right side\n- `\u003c` is \"less than\". Left side must be less than the right side\n- `\u003c=` is \"less than or equal to\". Left side must be less than or equal to the right side.\n- `^` is \"major compatibility\". For versions, this is the same as carat compatibility in the\n  semver package. For strings and numbers, this operator returns false.\n- `~` is \"minor compatibility\". For versions, this is the same as tilde compatibility in the\n  semver package. For strings and numbers, this operator returns false.\n- `-` is \"range\". For versions, this is the range operator which forms ranges of versions. For\n  strings and numbers, this operator returns false.\n- `(` and `)` group expressions together to enforce order of operations\n\nWhen the two sides of a binary operator are versions, this package will use [semver](https://github.com/npm/node-semver)\nto compare them using all the normal, familiar semver rules. Examples:\n\n```\n\"process.versions.node ^ 14.0.0\" -\u003e test whether or not the current version of node\nis carat compatible with version 14.0.0\n\n\"process.versions.node \u003c v14.0.0\" -\u003e test whether or not the current version of node\nis less than version 14.0.0\n```\n\nIf the two sides of an operator are different types, the right side will be co-ersed to the same\ntype as the left side.\n    - strings become numbers with parseInt()\n    - numbers become boolean with 0 = false, any other number = true\n    - numbers become versions by treating them as a major version number. 14 = v14.0.0\n    - strings become booleans by value. \"true\" is true, and everything else is false\n\nExample of a conditional expression using more complex syntax:\n\n```json\n    \"conditionalDependencies\": {\n        \"!ES6 || (process.config.variables.icu_ver_major \u003c 67 \u0026\u0026 process.config.variables.icu_small)\": {\n            \"full-icu\": \"^1.5.0\"\n        }\n    }\n```\n\nConditional Dev Dependencies\n--------\n\nIf you put \"conditional-install\" into the postinstall script, both npm and yarn will run the\nconditional installation whether you are doing `npm install` locally in your cloned git repo, or\nincluding your package into another package from the npm repository.\n\nIn some cases, you only want to do conditional installation when running locally during development.\nTo do that, put \"conditional-install\" into the \"prepare\" script instead and include \"conditional-install\"\nin your `devDependencies` instead:\n\n```json\n{\n    \"name\": \"mypackage\",\n    \"scripts\": {\n        \"prepare\": \"conditional-install\"\n    },\n    \"devDependencies\": {\n        \"conditional-install\": \"^1.0.0\"\n    },\n    \"conditionalDependencies\": {\n        \"process.version \u003e= 14.0.0\": {\n            \"jest\": \"^29.0.0\"\n        },\n        \"process.version \u003c 14.0.0\": {\n            \"jest\": \"^26.0.0\"\n        }\n    }\n}\n```\n\nSee Also\n--------\n\n- Check out the [node.green](https://node.green/) site for all of the features that can be tested against as well\n  as a fascinating view of what versions of node support what features.\n- Check out [compat-table](https://github.com/compat-table/compat-table) for the raw data, including JS support\n  in browsers as well as node.\n- [Semver](https://github.com/npm/node-semver) can compare version numbers semantically.\n\n## License\n\nCopyright © 2023-2024, JEDLSoft\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n## Release Notes\n\n### v1.0.3\n\n- update dependencies\n\n### v1.0.2\n\n- now while installing the conditional dependencies, it ignores any automatically run scripts you may have set up\n  in your package.json . The original run of npm install will run those scripts properly once the conditional\n  install is complete. This prevents a recursive install loop.\n- tests now run properly on node 22\n\n### v1.0.1\n\n- fixed a broken \"postinstall\" script in the package.json\n- updated documentation\n\n### v1.0.0\n\n- Initial version\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filib-js%2Fconditionalinstall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filib-js%2Fconditionalinstall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filib-js%2Fconditionalinstall/lists"}