{"id":43687854,"url":"https://github.com/NativeScript/nativescript-hook","last_synced_at":"2026-02-16T13:01:56.622Z","repository":{"id":1878028,"uuid":"45173579","full_name":"NativeScript/nativescript-hook","owner":"NativeScript","description":"Helper for installing hooks into NativeScript projects","archived":false,"fork":false,"pushed_at":"2025-08-03T05:04:54.000Z","size":29,"stargazers_count":15,"open_issues_count":5,"forks_count":9,"subscribers_count":25,"default_branch":"master","last_synced_at":"2026-01-25T05:55:57.512Z","etag":null,"topics":["nativescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NativeScript.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"NativeScript","open_collective":"nativescript"}},"created_at":"2015-10-29T09:37:27.000Z","updated_at":"2025-08-03T05:04:56.000Z","dependencies_parsed_at":"2025-07-16T15:05:16.578Z","dependency_job_id":"bff75aee-c2e9-47d4-a269-6863cfd56e9d","html_url":"https://github.com/NativeScript/nativescript-hook","commit_stats":{"total_commits":15,"total_committers":10,"mean_commits":1.5,"dds":0.7333333333333334,"last_synced_commit":"7d3b4715fa3e46afefa49ae5e2cedcb5acb0cc90"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/NativeScript/nativescript-hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fnativescript-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fnativescript-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fnativescript-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fnativescript-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NativeScript","download_url":"https://codeload.github.com/NativeScript/nativescript-hook/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fnativescript-hook/sbom","scorecard":{"id":99273,"data":{"date":"2025-08-11","repo":{"name":"github.com/NativeScript/nativescript-hook","commit":"c64e3d77c0c6166fe25e2d6a5b9ef3e9ea9bb164"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.3,"checks":[{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":3,"reason":"Found 7/20 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":5,"reason":"6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v0.2.4 not signed: https://api.github.com/repos/NativeScript/nativescript-hook/releases/10580945","Warn: release artifact v0.2.3 not signed: https://api.github.com/repos/NativeScript/nativescript-hook/releases/9735211","Warn: release artifact v0.2.4 does not have provenance: https://api.github.com/repos/NativeScript/nativescript-hook/releases/10580945","Warn: release artifact v0.2.3 does not have provenance: https://api.github.com/repos/NativeScript/nativescript-hook/releases/9735211"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/NativeScript/.github/SECURITY.md:1","Info: Found linked content: github.com/NativeScript/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/NativeScript/.github/SECURITY.md:1","Info: Found text in security policy: github.com/NativeScript/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 1 commits out of 19 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-15T09:47:36.902Z","repository_id":1878028,"created_at":"2025-08-15T09:47:36.902Z","updated_at":"2025-08-15T09:47:36.902Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29508735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["nativescript"],"created_at":"2026-02-05T03:00:21.768Z","updated_at":"2026-02-16T13:01:56.617Z","avatar_url":"https://github.com/NativeScript.png","language":"JavaScript","readme":"@nativescript/hook\n=======================================\n\nAn easier way to install hooks into NativeScript projects when using the `ns install \u003cmodule\u003e` command. A project hook is a script that is configured to be executed when the NativeScript CLI executes some action.\n\nHooks go into the `hooks/` folder of a project. For example, when `ns prepare ...` is executed, all script files in the `hooks/before-prepare/` and `hooks/after-prepare/` folders are executed as well.\n\nThis simplifies the process of installing the scripts into the right project folder.\n\nHow to use\n----------\n\n### Describe the hooks\n\nFirst, add a description of your hooks to the module's `package.json`. Here's an example:\n```json\n{\n  \"nativescript\": {\n    \"hooks\": [\n      {\n        \"type\": \"before-prepare\",\n        \"script\": \"lib/before-prepare.js\"\n      }\n    ]\n  },\n}\n```\nThe above specifies that the script `lib/before-prepare.js` should be executed when the `ns prepare ...` command is executed. the `\"type\"` property specifies the type of the hook to install. The `\"script\"` property specifies the path to the script to execute. You can add more hooks by extending the `\"hooks\"` array.\n\n### Install the hooks\n\nAdd a post-install and pre-uninstall script to your `package.json`, if you haven't done so already:\n\n```ts\n  \"scripts\": {\n    ...\n    \"postinstall\": \"node postinstall.js\",\n    \"preuninstall\": \"node preuninstall.js\"\n  },\n```\n\nThe post-install script (`postinstall.js` in the example) should contain the following line:\n\n```javascript\nimport path from 'path';\nimport hook from '@nativescript/hook';\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nhook(__dirname).postinstall();\n```\n\nThe pre-uninstall script (`preuninstall.js` in the example) should contain the following line:\n\n```javascript\nimport path from 'path';\nimport hook from '@nativescript/hook';\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nhook(__dirname).preuninstall();\n```\n\nThese two hooks will take care of installing and removing the hooks from the NativeScript project, when your module is installed or uninstalled.\n\n`ns install \u003cmodule\u003e`\n----------------------\nNativeScript modules that install hooks are intended to be installed using the `ns install \u003cmodule\u003e` command, not through npm directly. During module installation the NativeScript CLI provides information to the post-install script where to put the hooks. The following environment variables are defined when installing through `ns install \u003cmodule\u003e`:\n* `TNS_HOOKS_DIR` - the directory where the hooks should be installed. It may or may not exist.\n* `TNS_PROJECT_DIR` - the current project directory.\n\nModules installed this way can be uninstalled simply by running `npm rm --save-dev`.\n\nIn-process hooks\n----------------\nBy default, hooks are executed in a child process and execution continues when the child process dies. This gives you flexibility when writing your hooks, but doesn't allow you to use any of the services of the CLI.\n\nTo that end, in-process hooks allow you to execute your hooks in such a way so that you can use any of the services available from the injector. In-process hooks work only for JavaScript hooks. To enable in-process execution, all you need to have is a `export default function(...)` statement in the hook. For example, if the hook script is:\n\n```javascript\nexport default function($logger) {\n};\n```\nThen, the hook script will be required by the CLI and the exported function will be called through the injector.\n\nHooks can take a special injected argument named `hookArgs`:\n\n```javascript\nexport default function(hookArgs) {\n};\n```\n\n`hookArgs` is a hash containing all the arguments passed to the hooked method. For example, the `prepare` hook is activated by the CLI method `preparePlatform(platform: string)`. Here, the hook will get the value of the `platform` argument in the `hookArgs.platform` property.\n\nIf you execute asynchronous code in your hook, you need to return a promise, otherwise execution will continue before your hook completes:\n\n```javascript\nimport mkdirp from 'mkdirp';\n\nexport default function($logger) {\n  return new Promise(function(resolve, reject) {\n      mkdirp('somedir', function(err) {\n          if (err) {\n            reject(err);\n          else {\n            resolve();\n          }\n        })\n    });\n}\n```\n\nAnd finally, when installing in-process hooks through this module, you need to explicitly specify that using the `inject` property of the script descriptor in the `package.json`:\n```json\n{\n  \"nativescript\": {\n    \"hooks\": [\n      {\n        \"type\": \"after-prepare\",\n        \"script\": \"lib/after-prepare.js\",\n        \"inject\": true\n      }\n    ]\n  },\n}\n```\n\nYou have the ability to define a custom name to your hook in `package.json`, this attribute is optional and defaults to the plugin package name:\n```json\n{\n  \"nativescript\": {\n    \"hooks\": [\n      {\n        \"type\": \"after-prepare\",\n        \"script\": \"lib/after-prepare.js\",\n        \"name\": \"my-custom-hook\"\n      }\n    ]\n  },\n}\n```\n\n\n","funding_links":["https://github.com/sponsors/NativeScript","https://opencollective.com/nativescript"],"categories":["Awesome {N} [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)"],"sub_categories":["Table of Contents"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNativeScript%2Fnativescript-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNativeScript%2Fnativescript-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNativeScript%2Fnativescript-hook/lists"}