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

pretsc

v1.0.1

Published

Pre-build step for TypeScript Compiler (TSC)

Downloads

51

Readme

PreTSC

The aim of this project is

  • To enable running any arbitrary pre-build step before invoking typescript compiler (tsc).
  • The pre-build step should be able to modify/add the typescript files to be compiled without requiring to write those files to disk (and thus creating issues with version control).
  • The pre-build step should also be able to modify any other file type, for e.g. an included JS file
  • The project should be a drop-in replacement for the TSC compiler
  • The project should take care not to introduce any hard dependency on a particular typescript version

By integrating this project in the build tool chain, a variety of use cases can become viable. For e.g.

  • Conditional compilation (pre-build step can be written to remove conditional code on the basis of env the build is running on)
  • Compile time decorators (pre-build step can be written to replace compile time decorator placeholders with some real typescript code dynamically generated on the basis of decorator position and parameters) -- 'nameOf' operator anyone? -- Logging framework (pre-build step can be written to inject required logger tied to current class name)
  • Dependency injection framework (pre-build step can be written to parse typescript files and dump meta information about the interfaces to a separate json file. This json file can then be used by a decorator (e.g. @inject) to inject concrete implementations in place of the mentioned interface)
  • And many more...Please feel free to add more use cases if you come across any

How to use

  • Add npm devdependency on "pretsc"
  • Add a dependency/devdependency on "typescript"
  • Add in the working directory from where you invoke the build chain a file name ".tscPreBuildHook.js".
    •   module.exports = function (inMemoryFS) {
            //Use typescript compiler api or any other means to discover the files to be compiled and modified. 
            //For e.g.
            const ts = require("typescript");
            const tsConfig = ts.getParsedCommandLineOfConfigFile(path.resolve("tsconfig.json"), {}, ts.sys);
            const program = ts.createProgram(tsConfig.fileNames, tsConfig.options);
            program.getSourceFiles().forEach((sfNode) => {
                const modifiedContent = ...//process the file
                if(modifiedContent) {
                    //tell pretsc to use the modified content instead of the original file from disk
                    inMemoryFS.addFile(sfNode.fileName, modifiedContent);
                }
            }
        }
    `
  • In your build tool chain instead of invoking tsc, invoke pretsc passing the exact same arguments as you would have passed to tsc

Note 1: In the first cut I will not support tsc watch mode

Note 2: I am open to suggestions on the api front and implementation in general