npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unrelate

v0.2.0

Published

A library that transforms relative paths to absolute

Downloads

3

Readme

Unrelate (TypeScript)

Build Status npm bundle size npm

This library is used to transform relative paths into absolute paths for TypeScript projects.

Usage

As a global package

You can install it as a global npm package using the following bash command.

npm install -g unrelate

As a devDependency

If you would rather install it as a devDependency instead, you can do that as well.

npm install --save-dev unrelate

After installation, you would have to add unrelate to the scripts section of your package.json file.

image

If you've installed it as a devDependency, to use unrelate, you have to use the following command.

npm run unrelate <command>

Without installing (using npx)

If you'd rather not install it at all, you can simply use npx to run unrelate using the following command.

npx unrelate <command>

Base URL

Before you start using unrelate, you have to configure the baseUrl property in your tsconfig.json file. It informs the compiler where to find modules. All absolute import paths you configure using unrelate, are always relative to the baseUrl. So set the property to the folder that contains, or contains subfolders that contains all the .ts files that would use the absolute imports. It's common to set baseUrl to the project root folder or the src or lib folders, depending on where most of your code lies.

Configuration

You can either add it manually in your tsconfig.json file, or let unrelate do it for you.

unrelate configure base-url <your value here>

If you want to set it to the current directory (project root), you can use the following command.

unrelate configure base-url ./

Paths

After setting your Base URL, you can now configure your absolute paths to import from.

Configuration

You can add paths using the following command.

unrelate configure add-path <your path here>

For example, if you want to create an absolute path for lib/services, you can use the following command.

unrelate configure add-path lib/services

Once that's done, you should be able to see an entry like

paths

in your tsconfig.json file. You can now import from '@services' in your .ts files!

(Note that paths are always relative to Base URL. So if your baseUrl value is src, and you are adding an absolute path for src/app/components, the value for @components/* will show up as app/components/*, not src/app/components/*)

(Also note that if you are setting aliases for a ts-node project, you will have to add tsconfig-paths to your application)

(Also note that if setting paths should be after you set your Base URL. If you change your Base URL after adding paths, your paths will not automatically reflect that change)

Cleanup

The cleanup tool can save you time, by cleaning up files that have relative imports, and change them to absolute imports, depending on what paths you have configured in the previous step.

To cleanup a file, use the following

unrelate cleanup path/to/file.ts

For example, if you want to cleanup ./src/app/components/component.ts, use the following command.

unrelate cleanup ./src/app/components/component.ts

Once you run this command, you should see that the file now uses absolute imports instead of relative ones wherever possible.

You can also clean up a whole directory. Just pass the name of the directory instead of the file and unrelate will do the rest.

For example,

unrelate cleanup ./src/app/components

will cleanup all files in the components directory and any files in any child directory.

Contributing

Please feel free to raise a PR if you want to contribute.