What are the steps necessary to "release" a proprietary Typescript npm package on git?

It seems like a common issue, but I haven't been able to find a solution anywhere...

I have two projects written in TypeScript - LibraryA and WebserverB. They are stored in separate git repositories and are set as private projects to keep them from being public.

Naturally, I need to use LibraryA in WebserverB. My understanding is that the best way to do this is through npm, which handles other libraries effectively. Fortunately, npm allows for git URLs in dependencies, so I can link it directly to LibraryA's repository.

The problem arises because the repository only contains TypeScript files and not the compiled Javascript files. How can I resolve this issue? What would be the most appropriate approach in this scenario?

Answer №1

Alright, I've decided to provide my own answer by compiling a summary of the existing answers and incorporating some additional options.

Upon reflection, it struck me - who exactly is responsible for running tsc to compile LibraryA's Typescript into Javascript, and when does this process occur? Essentially, there are only a handful of possibilities:

  1. The developer of LibraryA initiates the compilation and shares the compiled outcome (somewhere);
  2. LibraryA is released in its source form, with the compilation occurring during package installation on WebserverB;
  3. LibraryA is distributed in its source form, with the compilation taking place during the build process on WebserverB.

Let's delve into each option in greater depth.

1. Publishing the compiled result

The key question then becomes - where is the published result stored? It must be accessible to NPM. Consequently, the available choices narrow down once again:

  • A private or public npm registry if feasible. Drawback: monetary cost associated with this option.
  • A tarball hosted on a server accompanied by a URL link. Drawback: necessitates owning a server for hosting purposes and must manage said server.
  • A new GIT repository, without being tarballed as npm lacks untarring ability from git repositories. Drawback: results in maintaining two separate repositories for one project.
  • Within the same git repository housing LibraryA. Ultimately, this entails committing not just TypeScript source files but also the compiled output. Drawback: against best practices to commit compilation artifacts and exposes sources alongside compiled outcomes which aren't necessary for WebserverB.
  • Under the same git repository as LibraryA, yet within a distinct, isolated branch. Drawback: can lead to confusion as to operating multiple repositories with disconnected primary branches.

Despite the drawbacks, all alternatives remain viable.

2. Compiling during installation

The main downside here lies in introducing an immediate dependency on typescript for WebserverB. This isn't solely a development-dependency but rather a full runtime dependence. While this approach might work, it appears unconventional. How do you intend to deploy WebserverB? Will it handle compilation as well? This doesn't seem like the ideal route to take, although it is feasible. For more insights, refer to H.B.'s response.

3. Simultaneous compilation with WebserverB

If your plan centers on using LibraryA solely within TypeScript projects, this method could suffice. However, I'm uncertain about the installation process. Modifying your tsconfig.json file to incorporate node_modules/LibraryA for compilation seems odd. Will your IDE function smoothly with this setup? Overall, this doesn't strike me as a favorable strategy either. It feels like going against the system and may lead to unfavorable outcomes.

In conclusion, I lean towards adopting the "commit compiled JS" strategy. After all, dismissing something as "just wrong" isn't a strong argument. Given that this is a private project, the surplus publication of sources shouldn't pose significant issues. In fact, these additional sources may even aid in debugging processes.

Answer №2

If you prefer not to download your dependency from a git repository source, there are alternative methods:

Option #1 — Download the dependency from a local directory

An easy fix is to download LibraryA using git clone, build it, and then in WebserverB/, run

npm install ../path/to/local/LibraryA
:

  • npm install <folder>:

This command installs the package as a symlink in the current project directory. Dependencies will be installed before it's linked. If <folder> is in the project root, its dependencies may move to the top-level node_modules. (Source: NPM documentation)

Option #2 — Set up a private npm proxy registry

You can establish a private npm proxy registry on your server, like Verdaccio. This way, you can publish your package with all compiled files.

Option #3 — Use a paid NPM account to deploy a private package

To securely distribute a package (including compiled files), consider publishing it in a private repository through a paid NPM account.

Option #4 — Release on GitHub repository (untested)

According to NPM documentation, another possibility is:

  • npm install <tarball url>

This command fetches the tarball URL for installation. To differentiate this method, the URL must start with "http://" or "https://".

Subsequently, create a packaged release by building, compressing, and uploading it as a new release in your private GitHub repository. Following that, access the tarball via URL using a personal access token.

Answer №3

To streamline the process, consider incorporating an install script within the library's package.json to handle compilation. By setting the main and types paths to the resulting files, you can easily manage the output.

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

Transferring data from a child to a parent component in Angular 2 using a combination of reactive and template-driven approaches

Recently delving into Angular 2 ( and Angular overall ) , I found myself at a crossroads with my co-worker. He opted for the template-driven method while I leaned towards the reactive-driven approach. We both built components, with his being a search produ ...

What is the proper way to implement jest.mock in a describe or it block?

Using typescript and jest, I am faced with a scenario involving two files: users.service.ts, which imports producer.ts. In an attempt to mock a function in producer.ts, I successfully implement it. import { sendUserData } from "./users.service"; const pro ...

What steps can be taken to resolve an npm repository issue when facing a Validation Error?

While working on a project with Angular, I encountered an issue. My build process involves: npm install And to run the project, I use: npm install The error message I'm receiving is: ERROR in ./node_modules/font-awesome/fonts/fontawesome-webfont. ...

Trouble displaying data from rest api in Angular Material's mat-table

I've been attempting to incorporate mat-table into my Angular 8 project, but I seem to be missing something. The data from my REST endpoint is showing up fine in the console output. Here's my admin.component.html file: <table mat-table [ ...

Utilize Typescript to aim for the most recent edition of EcmaScript

Are you looking to configure your typescript build to compile to the most recent version or the most current stable release of EcmaScript? For example, using this command: tsc --target <get latest version> Alternatively, in a tsconfig file: { & ...

Error 404 Encountered During Azure Functions GET Request

I have double-checked the file and everything seems to be correct. The name matches the Azure website, the API Key is included, but I am not getting any response when trying to use this on Postman as a GET request. What could be the issue? //https://disn ...

module for digital signature using soap in Node.js

I am inquiring about the npm module "soap" and whether it supports digital signatures. I would like to create a soap header as shown below: <s:Header> <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws ...

Should one bother utilizing Promise.all within the context of a TypeORM transaction?

Using TypeORM to perform two operations in a single transaction with no specified order. Will utilizing Promise.all result in faster processing, or do the commands wait internally regardless? Is there any discernible difference in efficiency between the t ...

Definition for TypeScript for an individual JavaScript document

I am currently attempting to integrate an Ionic2 app within a Movilizer HTML5 view. To facilitate communication between the Movilizer container client and the Ionic2 app, it is crucial to incorporate a plugins/Movilizer.js file. The functionality of this f ...

Definition file in TypeScript for an npm package provided by an external source - constructor

In my Node project, I am utilizing ES6 and Typescript. Despite this, there is a commonjs library that I need to incorporate. To address this, I have created my own .d.ts declaration file for the library: module "@alpacahq/alpaca-trade-api" { e ...

Encountering difficulties while trying to install yarn using npm

I'm attempting to install yarn using npm on my Mac following the instructions provided in this documentation npm install --global yarn However, when I enter this command in the terminal, I encounter an error and the package fails to install npm WARN ...

What steps are involved in setting up a Typescript-based custom Jest environment?

Currently, I am attempting to develop an extension based on jest-node-environment as a CustomTestEnvironment. However, I encountered an error when trying to execute jest: ● Test suite failed to run ~/git/my-application/tests/environment/custom-test ...

Managing plain text and server responses in Angular 2: What you need to know

What is the best way to handle a plain text server response in Angular 2? Currently, I have this implementation: this.http.get('lib/respApiTest.res') .subscribe(testReadme => this.testReadme = testReadme); The content of lib/respApi ...

Is there a way for me to pinpoint the source of an NPM's transitive dependency?

I've encountered an issue while attempting to install a package using npm. The installation is failing because of a missing transitive dependency. What's happening is that we are proxying to a Nexus NPM registry, which did not support scoped mod ...

I'm curious why my phone number is being treated as an object when it's passed in as a prop

I am facing an issue with my FooterScroll component while using it on the TvIndex main page. This is the FooterScroll Component const FooterScroll = (Id: number) => { const { event } = useEvent(Id); console.log('Id', Id); return ( ...

Chai Test Assertion - Enhancing Your Grunt Plugin

I am currently working on writing a test for my Grunt plugin. The main goal of the test is to check if an error occurs when trying to perform actions on an invalid file type. In the callback function, the 'err' variable returns a string value of: ...

Astro component experiencing script tag malfunction within content collection

I'm trying to create something using a script tag, but for some reason the script doesn't seem to be working properly. Below is my content collection: --- title: Essay Similarity stakeholder: THESIS articleDate: 05 Feb 2023 projectStart: 2022-08 ...

Unlocking Spotify: A Guide to Generating an Access Token through Web API Node

I visited the following link for more information: https://www.npmjs.com/package/spotify-web-api-node Here is a code snippet: var SpotifyWebApi = require('spotify-web-api-node'); // credentials are optional var spotifyApi = new SpotifyWebApi( ...

Missing "this" after initialization? (typescript/node/express)

I am currently working on creating a basic http application using node-express. One issue I encountered is that when setting up routes, the constructor of the MyRouter class has access to this, but it seems to be lost within the getRoutes() function. cla ...

The npm installation for react-icons is failing to add the package

I am new to React and I'm attempting to download react-icons. However, I encountered an error that is different from what I have seen before. Can anyone offer assistance? (base) Jana-MacBook-Air:react_project jb$ npm install react-icons --save Respo ...