Automatically bundle and release an NPM package using the libnpm library

My goal is to automate publishing to NPM within my CI/build system. I came across libnpmpublish, which appears to be the right tool for the job. However, it clearly states that it does not package code into a tarball, even though the publish API requires a tarball input instead of a folder or path.

The suggested workaround is:

Since libnpmpublish doesn't create tarballs on its own, one solution is to generate your own tarball for publishing by running npm pack in the desired directory. You can then use

fs.createReadStream('my-proj-1.0.0.tgz')
and provide that along with require('./package.json') to libnpmpublish.

I'm wondering if there's a way to script this process programmatically in Node. I searched through NPM repositories but couldn't find a dedicated packaging tool. Although I did come across this code that seems to handle packing, it's part of an archived repository and not under libnpm.

Answer №1

After thorough research, the most suitable solution appears to be located at this npm-packlist repository. This tool generates a file list from a specified folder which can then be used with NPM's tar package, as illustrated in the accompanying README for npm-packlist.

Answer №2

Here's a clever workaround that involves utilizing the command line to achieve a similar functionality. In this scenario, I am generating and uploading a package via a REST command. By encapsulating the process in a promise that returns a stream, I can seamlessly integrate it into the formPost data:

const exec = require('child_process').exec;
return new Promise((resolve, reject) => {
    exec(`npm pack ${t}`, { cwd: d }, (error, stdout, stderr) => {
        if (error) {
            console.error(error);
            reject(error);
        }
        var f = d + p.sep + stdout.trim();
        if (debug) console.log(`zip file "${f}" created.`);
        resolve(fs.createReadStream(f))
    });
});

Feel free to give it a try!

Answer №3

Introducing libnpmpack, a tool that generates a tarball buffer in the precise format required by libnpmpublish. With this, the process can be simplified as follows:

const pack = require('libnpmpack')
const { publish } = require('libnpmpublish')

async function packageAndDeploy(packagePath) {
  // readPackageJson implementation not shown here
  const manifest = readPackageJson(packagePath)

  const tarball = await pack(packagePath)
  return publish(manifest, tarball)
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sliding out list elements with jQuery ladder effect

I'm stuck on a seemingly simple task and need some guidance. facepalm. Currently, my site at this link has a menu list item issue where they all come out from the left side after the picture loads. I want them to slide out one by one, starting from t ...

Using JavaScript to open a new window and display CSS while it loads

I am looking to utilize a new window for printing a portion of HTML content. var cssLink = document.getElementByTagName('link')[2]; var prtContent = document.getElementById('print_body'); var WinPrint = window.open(' ...

Unveiling and Shifting Among Concealed HTML Forms

After going through numerous tickets with similar questions, I still can't seem to achieve what I want. So, I have no choice but to ask this question myself. I currently have an HTML page with 2 forms and 2 buttons. Both forms are initially hidden us ...

Ways to send users to a different page with parameters without relying on cookies

Is there a way to redirect users from URLs containing parameters like /?v=xxx to the index page without those parameters showing in the address bar? I still need to retain and use these parameters internally. One approach I considered was using custom hea ...

How can I set up automatic language selection for Google Translate's menu indexing feature?

My goal is to implement an automatic page translation feature using Google Translate's Library. I have been following the instructions provided in this link: The issue lies in the code snippet below, where the select menu creation works fine, but acc ...

Determining the Width of a DIV Dynamically with CSS or LESS Depending on the Number of Siblings

One of my challenges involves a parent DIV with a width set to 100%. Dynamically, this parent DIV is filled with numerous children DIVs. I am trying to calculate and assign their widths using only the calc method in CSS or LESS. This is because the flex ...

I can't seem to figure out why my characters keep disappearing from the HTML string when I attempt to dynamically add HTML using JavaScript

I am currently facing an issue with dynamically adding links to a page. The links are being added successfully, however, the '[' and ']' at the beginning and end of the line are disappearing. Here is the code snippet from my .js file: ...

Issue with Discord.js (14.1) - Message Handling Unresponsive

After developing a sizable Discord Bot in Python, I decided to expand my skills and start learning JS. Despite thoroughly studying the documentation and comparing with my original Python Bot regarding intents, I am facing difficulties getting the message ...

The scroll function is failing to activate at the desired location

I've been trying to fine-tune a window scroll function I created. Initially, I attempted to use waypoints for this, but unfortunately, I couldn't get it to work as expected. The main issue I'm facing is that the function triggers too early ...

What to do when faced with the error message "Nodemon is not recognized as a command"?

When I try to run npm start, my Node.js is not starting. The error message displayed is: 'nodemon' is not recognized as an internal or external command, operable program or batch file. I have double-checked my environment path and also tried r ...

Ways to transfer a value to another component in React

Currently, I am working on a project where users can add, edit, or delete movies from a list. While the addition and deletion functionalities are working fine, I am facing challenges with the editing feature. In my Movie component, I have included a text i ...

Replicating form fields using jQuery

I have come across many questions similar to mine, but unfortunately none of them address the specific details I am looking for. On a single page, I have multiple forms all structured in the same way: <form> <div class="form-group"> ...

Unable to locate module for a Node.js application running within a Docker Compose environment

Apologies for this beginner question, as I am really struggling to resolve an issue today. I have an Express app that I am attempting to run using Docker Compose. Here is the Dockerfile I have used: FROM mhart/alpine-node RUN mkdir -p /usr/src/app RUN chm ...

Is there a way to convert a URL into a user-friendly json format displayed on a web page

Can someone please help me figure out the proper way to convert this URL into a JSON format that is easily readable using jQuery on an HTML page? ...

Bringing in Node Package in Angular

I decided to clone the Angular project from here: https://github.com/etherparty/explorer Now, I am looking to incorporate another module into it by following this link: https://github.com/miguelmota/ethereum-input-data-decoder However, when trying to uti ...

What initiates the call for CSS?

During his instructional video, the creator visits the CodeIgniter website at . When he initially arrives at the site (at 1:32), it appears somewhat odd, almost as if it lacks CSS styling. However, after refreshing the page (1:37), it displays properly. ...

Having trouble loading script files with JSDOM in NodeJS?

I'm currently experimenting with loading an HTML page in jsdom to generate graphs, but I'm facing challenges in getting the JavaScript to execute. Here's the HTML page I'm trying to load, which simply renders a basic graph: <html&g ...

Tips for Removing Padding in Material UI Container Component

I'm currently working on creating a hero banner using the material-ui framework and I've encountered an issue. Here's what I have so far: https://i.stack.imgur.com/UXTDY.png However, I'm facing an irritating problem with left and rig ...

Pass on the error to the callback in Node.js

Here is the code snippet in question: User.findById(id, function(err, user) { //blah blah }); The findById method can be found within the User module. Here's a glimpse at its implementation: exports.findById = function(id,callback) { connec ...

What are the steps to locally test my custom UI library package built with tsdx in a React.js project

I am currently utilizing tsdx to develop a React UI library, and I am looking to test it within my Next.js project before officially publishing it to the npm package. Initially, I attempted using npm link, which worked initially. However, when I made ch ...