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

@ts-united/cra

v1.0.0

Published

Helps one TypeScript project (folder containing a tsconfig.json file) import TypeScript/JavaScript code from any other project, while checking each project's code and resolving imports in each project using that project's tsconfig.json.

Downloads

4

Readme

TS United: CRA Edition

Building shared code and reinstalling it into all parts of a monorepo (backend, frontend, mobile)? Incrementing version and publishing shared code to NPM on every small change? Wasting time? Forget about it with TS United!

TS United helps one TypeScript project (folder containing a tsconfig.json file) import TypeScript/JavaScript code from any other project, while checking each project's code and resolving imports in each project using that project's tsconfig.json.

Note: CRA Edition is a wrapper around Webpack Edition (@ts-united/webpack), which injects the Webpack Edition into react-scripts's underlying Webpack config and helps you avoid ejecting. If you've ejected your app or are using another runtime, go to the list of editions and choose the edition you need.

Sounds great? Let's get started!

Adding TS United to your Create React App project

Step one: Install the @ts-united/cra package from NPM into your main (aka root) project. Root project is the project you'll run npm start in when starting the whole app. For example, the frontend part of your app will be a root project.


Step two: Create a configuration file for TS United in your root project's base directory

Config file can be in either JS or JSON format and can have the following file names:

  • ts-united.config.{js,json}
  • ts-united.{js,json}
  • .tsunitedrc.{js,json}
  • .unitedrc.{js,json}

Example - ts-united.config.js

See the Config options section below for complete explanation of config options. It also shows an example config file.


Step three: Use TS United binary for starting and building your code

In root project's package.json file use tsu-cra binary to start, build and test your code.

Note: Testing is currently not supported, because it uses Jest runtime, which needs it's own edition. Jest Edition will be added soon!

Example:

{
    // ...regular package.json
    "scripts": {
        "start": "tsu-cra start",
        "build": "tsu-cra build",
        "test": "tsu-cra test"
        // ...some other scripts
    }
}

tsu-cra binary usage: tsu-cra <one of react scripts: start, build or test>


That's all! Now your project uses TS United! Import files from other projects and then run npm start and npm run build as usual.

Tip: Any project can import any other project, listed in config file. Related projects can import each other and can import root project (importing root project from related projects is not recommended).

Also you can see a complete example project on GitHub: https://github.com/R-Mielamud/TsUnited/tree/main/example/cra-frontend

Config options

| Option | Data type | Default value | Description | | ----------------- | -------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | cwd | string(path)? | path.dirname(path_of_ts_united_config_file) | CWD is a base directory for all other directories in config. It can be either absolute or relative. If it's relative, it'll be relative to path.dirname(path_of_ts_united_config_file). | | extensions | Array<string(file extension)>? | [".js", ".jsx", ".ts", ".tsx", ".json"] | Array of extensions path aliases will be implicitly resolved to. | | rootProject | Project | | Root project's info (see Project schema below). | | relatedProjects | Array<Project>? | [] | Array containing related projects' info. If empty, no projects will be considered related. |

Project schema

| Option | Data type | Default value | Description | | ------------ | -------------------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | string, unique | | Any unique project name (id). | | path | string(path) | | The path tsconfig.json file is located in or any child path. Importing files that are outside all projects' paths is forbidden. The path can be absolute or relative to CWD. | | extensions | Array<string(file extension)>? | The top-level extensions option | Array of extensions path aliases of this project will be implicitly resolved to. Each extension must begin with a dot. |

Example folder structure and config:

|---myproject
    |---shared
        |--- ...
        |---tsconfig.json
    |---frontend - the root project
        |--- ...
        |---ts-united.config.js
        |---tsconfig.json
    |---tsconfig.base.json
// /myproject/frontend/ts-united.config.js
// path.dirname("/myproject/frontend/ts-united.config.js") === "/myproject/frontend"

module.exports = {
    cwd: "../", // /myproject
    extensions: [".ts", ".tsx"], // `~/myfile` can become either `./myfile.ts` or `./myfile.tsx`
    rootProject: {
        name: "frontend",
        path: "./frontend", // /myproject/frontend
        extensions: [".ts", ".tsx"], // Set to default value
    },
    relatedProjects: [
        {
            name: "shared",
            path: "./shared", // /myproject/shared
        },
    ],
};