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

@workshift/ts-transformer-imports

v0.3.1

Published

Transform import paths in TypeScript

Downloads

4

Readme

ts-transformer-imports

A TypeScript transformer which enables compilation of absolute imports (using baseUrl or paths) so they can be required as modules from Javascript or TypeScript, without additional configuration or path mapping.

Build Status NPM version Downloads

Read more about why this exists and what problem it solves

How to use this package

If you're using the TypeScript compiler and using TypeScript's native "absolute imports" mapping (specifying baseUrl or paths in your config), you've found none of the compiled code is usable in Javascript or unconfigured TypeScript.

ttypescript

First, install ttypescript:

npm install --save-dev ttypescript

See examples/ttypescript for detail, and ttypescript's README for how to set up in your project.

Now, specify ts-transfomer-imports in your tsconfig.json:

{
  "compilerOptions": {
    // ...
    "plugins": [
      { "transform": "ts-transformer-imports" }
    ]
  },
}

Using with ts-node, webpack, etc

See ttypescript's README for usage information with other compilers. It should work!

TypeScript API

You probably won't need this. See test for more detail.

const ts = require('typescript');
const importsTransformer = require('ts-transformer-imports').default;

const program = ts.createProgram([/* your files to compile */], {
  strict: true,
  noEmitOnError: true,
  target: ts.ScriptTarget.ES5
});

const transformers = {
  before: [importsTransformer(program)]
};
const { emitSkipped, diagnostics } = program.emit(undefined, undefined, undefined, false, transformers);

TL;DR:

I don't want to write:

// ugh, annoying on bigger projects
import isTruthy from '../../utils/isTruthy'

so TypeScript allows me write:

import isTruthy from 'isTruthy'

but tsc compiles it to:

const isTruthy = require('isTruthy')
// This makes NO SENSE to normal Javascript, or even downstream TypeScript!

So ts-transformer-import rewrites to this at compile time:

const isTruthy = require('../../utils/isTruthy')

Compatibility

TypeScript >= 2.4.1

License

MIT

Thanks to

  • https://gist.github.com/rifler/39fdcd92e78505bbc94dc5b9f845292b
  • https://github.com/kimamula/ts-transformer-keys
  • https://github.com/dsherret/ts-simple-ast