{"id":22477488,"url":"https://github.com/orienteerbap/jnpm","last_synced_at":"2025-08-02T13:31:02.748Z","repository":{"id":45375297,"uuid":"262714137","full_name":"OrienteerBAP/JNPM","owner":"OrienteerBAP","description":"Native Java API to work with JavaScript Node Package Manager (NPM): query, retrieve, pack into jar (webjars), CDN","archived":false,"fork":false,"pushed_at":"2024-07-15T08:34:41.000Z","size":177,"stargazers_count":20,"open_issues_count":5,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-01T01:48:23.634Z","etag":null,"topics":["artifact","frontend","java","npm","resources"],"latest_commit_sha":null,"homepage":"","language":"Java","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/OrienteerBAP.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}},"created_at":"2020-05-10T04:49:05.000Z","updated_at":"2024-09-23T09:30:12.000Z","dependencies_parsed_at":"2024-03-04T06:44:15.635Z","dependency_job_id":null,"html_url":"https://github.com/OrienteerBAP/JNPM","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrienteerBAP%2FJNPM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrienteerBAP%2FJNPM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrienteerBAP%2FJNPM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrienteerBAP%2FJNPM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OrienteerBAP","download_url":"https://codeload.github.com/OrienteerBAP/JNPM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228476044,"owners_count":17926134,"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","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":["artifact","frontend","java","npm","resources"],"created_at":"2024-12-06T14:11:18.070Z","updated_at":"2024-12-06T14:11:18.661Z","avatar_url":"https://github.com/OrienteerBAP.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/OrienteerBAP/JNPM.svg?branch=master)](https://travis-ci.org/OrienteerBAP/JNPM) [![javadoc](https://javadoc.io/badge2/org.orienteer.jnpm/jnpm/javadoc.svg)](https://javadoc.io/doc/org.orienteer.jnpm/jnpm)\n\n# JNPM\n\nNative Java API to work with JavaScript Node Package Manager (NPM): query, retrieve, pack into jar (webjars), CDN\n\n1. [Java API](#java-api)\n2. [Command Line Interface](#command-line-interface)\n3. [Maven Plugin](#maven-plugin) (lightweight and fast replacement for [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin), [npm-maven-plugin](https://github.com/jy4618272/npm-maven-plugin) and even [WebJars](https://www.webjars.org/))\n4. [Make your CDN](#cdn)\n\t* [Servlet](#servlet)\n\t* [Apache Wicket](#apache-wicket)\n\n## Java API\n\nInclude JNPM Jar into pom.xml:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.orienteer.jnpm\u003c/groupId\u003e\n    \u003cartifactId\u003ejnpm\u003c/artifactId\u003e\n    \u003cversion\u003eLATEST JNPM VERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nInitialize JNPM API prior to use.\n\n```java\nJNPMService.configure(JNPMSettings.builder()\n  .homeDirectory(Paths.get(\"/home/myuser/.jnpm\")) //Optional\n  .downloadDirectory(Paths.get(\"/tmp\")) //Optional\n  //Other optional configurations: see JavaDoc for more info\n \t.build());\n```\n\nJNPM API has 2 options: **Synchronous API** and **RXJava API**. Please use required one per your needs:\n\n```java\nJNPMService jnpmService = JNPMService.instance(); //Synchronous Java API\nRxJNPMService rxJnpmService = JNPMService.instance().getRxService() //RXJava API\n```\n\nExamples of API use:\n\n```java\n//Print NPM Registry Information\nSystem.out.println(JNPMService.instance().getRegistryInfo());\n//Retrieve and print VUE package latest version\nSystem.out.println(JNPMService.instance().getPackageInfo(\"vue\").getLatest());\n//Print package description for vue@2.6.11\nSystem.out.println(JNPMService.instance().getVersionInfo(\"vue\", \"2.6.11\").getDescription());\n//Print latest version prior to vue version 2 official release\nSystem.out.println(JNPMService.instance().bestMatch(\"vue@\u003c2\").getVersionAsString());\n//Download tarball for vue@2.6.11 and print localpath\nVersionInfo vueVersion = JNPMService.instance().getVersionInfo(\"vue\", \"2.6.11\");\nvueVersion.downloadTarball().blockingAwait();\nSystem.out.println(vueVersion.getLocalTarball().getAbsolutePath());\n//Search for \"vue\" and print description for first result\nSystem.out.println(JNPMService.instance().search(\"vue\").getObjects().get(0).getSearchPackage().getDescription());\n//Traverse through all dev dependencies of latest vue package, print information\n// and install as NPM do (node_modules/vue and etc)\nJNPMService.instance().getRxService()\n   .traverse(TraverseDirection.WIDER, TraversalRule.DEV_DEPENDENCIES, \"vue\")\n   .subscribe(t -\u003e {System.out.println(t); t.install(Paths.get(\"target\", \"readme\"), InstallationStrategy.NPM);});\n```\n\nRead [![javadoc](https://javadoc.io/badge2/org.orienteer.jnpm/jnpm/javadoc.svg)](https://javadoc.io/doc/org.orienteer.jnpm/jnpm) for more information.\n\n## Command Line Interface\n\n```\nUsage: jnpm [-hV] [--download-dir=\u003cdownloadDirectory\u003e]\n            [--home-dir=\u003chomeDirectory\u003e] [--install-dir=\u003cinstallDirectory\u003e]\n            [-P=\u003cpassword\u003e] [--registry=\u003cregistryUrl\u003e] [-U=\u003cusername\u003e] [COMMAND]\nJava implementation of Node Package Manager\n      --download-dir=\u003cdownloadDirectory\u003e\n                  Cache directory for JNPM to download packages to (default:\n                    \u003chome-dir\u003e/cache/)\n  -f, --force     Force to fetch remote resources even if a local copy exists                                                                                                    on disk\n  -h, --help      Show this help message and exit.\n      --home-dir=\u003chomeDirectory\u003e\n                  Home directory for JNPM (default: C:\\Users\\naryzhny\\.jnpm)\n      --install-dir=\u003cinstallDirectory\u003e\n                  Global install directory for JNPM (default:\n                    \u003chome-dir\u003e/node_modules/)\n  -L, --http-logger-level\n                  HTTP Logger Level for debugging\n                  Valid values: NONE, BASIC, HEADERS, BODY\n  -P, --password=\u003cpassword\u003e\n                  Password for authentication (optional)\n      --registry=\u003cregistryUrl\u003e\n                  NPM registry URL to be used for package lookup and retrieval\n                    (default: http://registry.npmjs.org/)\n  -U, --username=\u003cusername\u003e\n                  Username for authentication (optional)\n  -V, --version   Print version information and exit.\nCommands:\n  download, d  Download packages into local cache\n  extract, e   Extract packages: very similiar to 'npm install', but without\n                 changing package.json modification\n``` \n```\nUsage: jnpm download [-h] [--[no-]dev] [--[no-]download] [--[no-]optional] [--\n                     [no-]peer] [--[no-]prod] \u003cpackageStatements\u003e...\nDownload packages into local cache\n      \u003cpackageStatements\u003e...\n                        Packages to be retrieved\n      --[no-]dev        Download dev dependencies\n      --[no-]download   Download by default. Negate if  just attempt to lookup\n                          is needed\n  -h, --help\n      --[no-]optional   Download optional dependencies\n      --[no-]peer       Download peer dependencies\n      --[no-]prod       Download dependencies (default)\n```\n\n```\nUsage: jnpm extract [-gh] [--[no-]dev] [--[no-]download] [--[no-]optional] [--\n                    [no-]peer] [--[no-]prod] [-o=\u003cfolder\u003e] [-s=\u003cstrategy\u003e]\n                    \u003cpackageStatements\u003e...\nExtract packages: very similiar to 'npm install', but without changing package.\njson modification\n      \u003cpackageStatements\u003e...\n                          Packages to be retrieved\n      --[no-]dev          Download dev dependencies\n      --[no-]download     Download by default. Negate if  just attempt to\n                            lookup is needed\n  -g                      Extract package(s) globally\n  -h, --help\n  -o, --output=\u003cfolder\u003e   Output folder to extract to\n      --[no-]optional     Download optional dependencies\n      --[no-]peer         Download peer dependencies\n      --[no-]prod         Download dependencies (default)\n  -s, --strategy=\u003cstrategy\u003e\n                          Strategy for extraction: FLAT, NPM, SIMPLE,\n                            SIMPLE_VERSIONED, WEBJARS, ONE_DUMP, DIST\n```\n## Maven Plugin\n\nJNPM maven plugin allows you natively integrate NPM resources into your build process.\nFor example, you can download and pack JS packages inside your WAR to use later through WebJars extensions.\nTo include `vue` and into your WAR please add the following into build\u003eplugins section of your `pom.xml`\n\n```xml\n\u003cplugin\u003e\n\u003cgroupId\u003eorg.orienteer.jnpm\u003c/groupId\u003e\n    \u003cartifactId\u003ejnpm-maven-plugin\u003c/artifactId\u003e\n\t\u003cversion\u003e${LATEST_JNPM_VERSION}\u003c/version\u003e\n\t\u003cexecutions\u003e\n\t\t\u003cexecution\u003e\n\t\t\t\u003cgoals\u003e\n\t\t\t\t\u003cgoal\u003einstall\u003c/goal\u003e\n\t\t\t\u003c/goals\u003e\n\t\t\t\u003cconfiguration\u003e\n\t\t\t\t\u003cpackages\u003e\n\t\t\t\t\t\u003cpackage\u003evue@2.6.11\u003c/package\u003e\n\t\t\t\t\t\u003cpackage\u003evuex@~3.4.0\u003c/package\u003e\n\t\t\t\t\u003c/packages\u003e\n\t\t\t\u003c/configuration\u003e\n\t\t\u003c/execution\u003e\n\t\u003c/executions\u003e\n\u003c/plugin\u003e\n```\n\nMore details about the plugin:\n\n```\njnpm:install\n  Goal to download, extract and attach npm resources\n\n  Available parameters:\n\n    attachResources (Default: true)\n      Attach downloaded resources to the build process\n\n    excludes\n      What has to be excluded from resources to be attached\n\n    getDev (Default: false)\n      Download development dependencies\n\n    getOptional (Default: false)\n      Download optional dependencies\n\n    getPeer (Default: false)\n      Download peer dependencies\n\n    getProd (Default: false)\n      Download direct dependencies\n      \n    httpLoggerLevel (Default: NONE)\n    \tHTTP Logger Level for debugging\n\n    includes\n      What should be included as resources (Default: empty - means everything)\n\n    outputDirectory (Default: ${project.build.directory}/jnpm/)\n      Location of the output directory\n      Required: Yes\n\n    packages\n      NPM packages to be downloaded and extracted (For example: vue@2.6.11)\n      Required: Yes\n\n    password\n      Password for authentication (optional)\n\n    pathPrefix\n      Prefix for the directory under outputDirectory to which files will be\n      placed\n\n    registryUrl (Default: http://registry.npmjs.org/)\n      NPM registry URL to be used for package lookup and retrieval\n\n    serverId\n      Server id from settings to get username and password from\n\n    strategy (Default: WEBJARS)\n      Installation strategy to be used\n\n    useCache (Default: true)\n      Use local cache. Useful if the same package version can be re-uploaded to a registry\n\n    username\n      Username for authentication (optional)\n```\n\n## CDN\n\n### Servlet\n\nAdd the following mapping to your `web.xml`. Adjust as needed:\n\n```xml\n  \u003cservlet\u003e\n    \u003cservlet-name\u003eCDNServlet\u003c/servlet-name\u003e\n    \u003cservlet-class\u003eorg.orienteer.jnpm.cdn.CDNServlet\u003c/servlet-class\u003e\n  \u003c/servlet\u003e\n\n  \u003cservlet-mapping\u003e\n    \u003cservlet-name\u003eCDNServlet\u003c/servlet-name\u003e\n    \u003curl-pattern\u003e/cdn/*\u003c/url-pattern\u003e\n  \u003c/servlet-mapping\u003e\n```\n\nFiles from NPM packages will be available through URLs with the following pattern: `http(s)://\u003chost\u003e:\u003cport\u003e/\u003cdeploy-folder\u003e/cdn/\u003cpackage expression\u003e/\u003crequired file\u003e`.\nFor example: `http://localhost:8080/cdn/vue@2.6.11/dist/vue.js`\n\nYou can user `init-param` to specify extra JNPM parameters, for example, `registryUrl`, `username`, `password` and etc.\n\n### Apache Wicket\n\nAdd the following code to your [Apache Wicket](https://wicket.apache.org/) WebApplication:\n\n```java\nif(!JNPMService.isConfigured()) \n   JNPMService.configure(JNPMSettings.builder().build()); //Configure as you wish\n   CDNWicketResource.mount(this, \"/cdn\");\n```\n\nFiles from NPM packages will be available through URLs with the following pattern: `http(s)://\u003chost\u003e:\u003cport\u003e/\u003cdeploy-folder\u003e/cdn/\u003cpackage expression\u003e/\u003crequired file\u003e`.\nFor example: `http://localhost:8080/cdn/vue@2.6.11/dist/vue.js`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forienteerbap%2Fjnpm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forienteerbap%2Fjnpm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forienteerbap%2Fjnpm/lists"}