Can the GitHub URL be utilized for installing TypeScript npm dependencies?

When working with an npm library written in TypeScript, the usual process involves writing the source code in TypeScript, pushing it to GitHub, then converting it to JavaScript and pushing the resulting JavaScript code to the npm repository. When adding dependencies, we typically use the converted JavaScript version. However, is there a way to directly use TypeScript on GitHub or store the converted JavaScript on GitHub and access it through a GitHub URL instead? I want to avoid publishing every time the TypeScript source code changes. Since npm does not support override or snapshot versions, am I required to compile TypeScript to JavaScript before publishing to npm? Any suggestions would be appreciated.

Answer №1

My typical approach involves organizing my project with a src/ folder for TypeScript files and a separate directory called lib/ for the compiled JavaScript files.

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./lib"
    },
    "exclude": [
        "lib"
    ]
}

In the package.json file, you can specify the main field as ./lib/index.js (or your main entry file).

To exclude certain files from NPM, you can create an .npmignore file similar to a .gitignore.

.npmignore

# Ignore all src files
src

Use npm pack to see what will be packed by NPM (it displays the tarball contents).

You can also add the lib folder to your .gitignore as it is generated.

If providing source maps, consider including the original TypeScript files as well.

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

Using a component again with variations in the input data

I'm looking to reuse a card component to display different types of data, but the @Input() properties are for different objects (articles and events). Parent HTML: <card-component [headline]="Articles" [content]="art ...

Updating the default value for react-i18next (stored in localstorage)

When utilizing a backend and language detector, an issue arises: The localstorage contains the key I18nextLng with the value en-US. How can we set the default value to be I18nextLng with the value En? init and other settings are as per the default docume ...

Notify programmers about the potential risks associated with utilizing certain third-party components

Incorporating a 3rd party library into our codebase involves utilizing its components directly, although some are enclosed within internally created components. Is there a method available to alert developers when they try to use one of the wrapped compone ...

Error encountered: MissingDriverError when the database type specified is oracle while using TypeORM

Currently, I am utilizing typeorm within a JavaScript codebase for the node and express backend, following the guidelines provided at this link: The current node version being used is v6.11.1 List of dependencies from package.json: "@types/es6-shim": ...

Is there a solution for troubleshooting 'npm init' and the inability to update it?

I haven't worked with Node or written any code in 3 years. Can anyone help me fix this issue? npm init node:internal/modules/cjs/loader:922 throw err; ^ Error: Cannot find module '../lib/cli.js' Require stack: - /usr/local/lib/node_modu ...

Utilizing the onscroll feature to trigger a function within a ScrollView

I am facing an issue with an animated view where I need to execute multiple events within the onScroll property. The current onScroll implementation is as follows: onScroll={ Animated.event( [{ nativeEvent: { conten ...

Having issues with 'main character' dependency while using 'yarn install' command

Executing yarn install on the command line resulted in the following error: yarn install v1.15.2 $ node tools/nodeVersionCheck.js [1/5] Validating package.json... [2/5] Resolving packages... [3/5] Fetching packages... info <a href="/cdn-cgi/l/email-pro ...

Creating a file logging system with log4js to capture Console logs

Is there a way to automatically log all console logs, including failed expectations and exceptions, to a file without using try and catch in JavaScript? In Java's LOG4j, the rootlogger feature does this by default. Is there a similar functionality ava ...

Troubleshooting problem with refreshing URL on "ionic serve" mode

After transitioning my project from Ionic 2 to Ionic 3, I've encountered an issue with ionic serve and the rebuilding process. Initially, when I build the project, everything functions as expected. However, I've noticed that the URL in the brows ...

Strategies for managing common dependencies while distributing components across various applications within a monorepo

In my monorepo, the structure is as follows: root --AppOne ----package.json ----node_modules ------styled-components --AppTwo ----package.json ----node_modules ------styled-components --Shared ----componentA ----package.json ----node_modules ------style ...

Retrieve weight measurements from a serial port by using Node JS

I'm a novice in node.js and I'm trying to retrieve weight data from a serial port. I have nodejs(v14.19.0) and npm(6.14.16) installed, and I'm attempting to obtain weight data using localhost:8080/get_weight. However, the script isn't f ...

Invoke a function of a child component that resides within the <ng-content> tag of its parent component

Check out the Plunkr to see what I'm working on. I have a dynamic tab control where each tab contains a component that extends from a 'Delay-load' component. The goal is for the user to click on a tab and then trigger the 'loadData&apo ...

The error message "Type 'null' cannot be assigned to type 'Element | DocumentFragment'" occurs when using Nextjs/React createPortal

I am completely new to typescript. Currently, I'm working on a project that has a lot of pre-configured react components in JavaScript files (.js). My task now is to convert everything to TypeScript (.tsx) without triggering any ESLint errors. Unfort ...

Circular dependency has been detected when using the ESLint with TypeORM

Having two entity typeorm with a bi-directional one-to-one relationship: Departament: @Entity('Departament') export default class Departament { @PrimaryGeneratedColumn() id: string; @Column() departament_name: string; @OneToOne(type ...

The module 'cropit' is not located within Npm's directory

I'm having trouble with npm recognizing my installation of cropit. In my package.json, I have specified the following lines: "cropit": "^0.1.9", "jquery": "~2.1.1" Could it be that I selected the wrong version? Do the versions of jquery and cropit I ...

Issues may arise in TypeScript when you are working with an array of objects along with other properties within a type

I am encountering an issue with an object structure similar to the one below: let Obj = { ['0'] : { mode: 'x' }, getMode: () => 'x' } The problem arises when I attempt to create a type definition as shown here: type Obj = ...

"Enhance your slider experience with React Alice Carousel: place dot controls directly over images for

I am currently working with react-alice-carousel and I'm looking to adjust the placement of the dot controllers on the slider. Instead of their current position, which you can see in this image (https://i.sstatic.net/mi6eD.png), I want them to be loca ...

Unable to locate any static exports within the TypeScript library bundle

In my file Style.ts, I have a class called Style: export class Style { ... } The Style class consists of properties, methods, and a constructor, along with import statements for other class dependencies. It is being used by other classes through the ...

Error: Unexpected reserved word discovered in prettier/third-party.js due to syntax issue

Recently, I decided to dive into Node, npm, and webpack. My goal is to create a Craft 3 environment integrated with Tailwind CSS Craft 3 environment. Initially, everything seemed to work smoothly, but upon running npm run dev, an error popped up: > < ...

An issue occurred with building deployments on Vercel due to a typing error

When attempting to deploy my build on Vercel, I encountered an error. The deployment works fine locally, but when trying to build it on vercel, the following error occurs: [![Type error: Type '(ref: HTMLDivElement | null) => HTMLDivElement | null&a ...