ts-package-scope-plugin

1.1.0 • Public • Published

npm version Build Status Build Status

ts-package-scope-plugin

TypeScript Language Service Plugin for creating package scopes using dir names and JS Docs.

It provides IntelliSense for VS Code and error reporting using TypeScript TSServer.

Installation and usage

Install package:

yarn add -D ts-package-scope-plugin or npm i --save-dev ts-package-scope-plugin

Update tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-package-scope-plugin"
      }
    ]
  }
}

VS Code users

Run command TypeScript: Select TypeScript version and choose Use workspace version:

Configuration

By default, plugin will analyse the same files as the TypeScript compiler in your project. You can override this behavior by using include property:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-package-scope-plugin",
        "options": {
          "include": ["./src/**/*"]
        }
      }
    ]
  }
}

Package scope

There are two ways to make module package scoped. Using suffix/prefix in folder name or setting plugin option with specific folder names.

1. package prefix/suffix

To make file package scoped using prefix/suffix it needs to be placed in folder with package in its name separated with dot ex. package.<name> or <name>.package:

project
│   README.md
│   file001.txt
│
└───package.interface
│   │   api.ts
│
└───package.domain
    │   client.ts

2. packageNames option

To make file package scoped using specific folder names, they have to be listed as an array in tsconfig.json plugin option:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-package-scope-plugin",
        "options": {
          "packageNames": ["core", "domain"]
        }
      }
    ]
  }
}

When you import file from one package into another, IDE will show a TypeScript error.

Public scope

To make file available from other packages set its scope to public using JS Doc tag at the top of the file:

/** @package-scope public **/
import { Helper } from "./helpers";

export function getClient() {}

IntelliSense filtering (only for VS Code)

By default, files which are not available for current package will be removed from intellisense suggestions. To turn on or off this feature you can use intelliSense option in tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-package-scope-plugin",
        "options": {
          "intelliSense": false
        }
      }
    ]
  }
}

Package Sidebar

Install

npm i ts-package-scope-plugin

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

26.4 kB

Total Files

24

Last publish

Collaborators

  • pawfa