typework

0.1.1 • Public • Published

typework

npm version

Typework is used to Manage And Vendor JSDoc Types. With the special /* typework */ keyword, JSDoc type declarations can be moved across JS files, and imported files in types (import('../types/context')) will be copied across to the target project.

yarn add typework

Table Of Contents

CLI

The package works via a CLI by passing the configuration file to it.

typework example/config.json

The config must include 3 properties:

{
  "entry": "@typedefs/goa",
  "js": "compile/index.js",
  "destination": "types"
}
  • 🔖 entry This is where the types are coming form. This can be a separate package, e.g., @typedefs/goa
  • 🎯 js The project source code into where to place the original types into.
  • 📂 destination Whenever the types import other files with import('../types/'), the target files will be copied to this folder.

Upon run, the types' JSDoc declarations are copied from the entry into the source JS file, so that they become a native part of the project. All other files found under relative import paths, will be placed into the Destination folder.

The example below demonstrates, how types written for the Goa package and published as @typedefs/goa, were imported into the Goa/Koa project, so that they can be distributed without having to install @typedefs/goa from NPM as a production dependency. This is a strategy for distribution of JSDoc types.

entry.js Typework will read the entry files, to detect the /* typework */ market which indicates a single block of types which can be managed by the binary (only types within this block will be worked on).
export {}
 
/* typework */
/**
 * @typedef {import('./vendor/cookies').Keygrip} Keygrip
 * @typedef {import('./typedefs/application').Middleware} Middleware
 * @typedef {import('./typedefs/application').Application} Application
 * @typedef {import('./typedefs/context').KoaContext} Context
 * @typedef {import('./typedefs/request').Request} Request
 * @typedef {import('./typedefs/request').ContextDelegatedRequest} ContextDelegatedRequest
 * @typedef {import('./typedefs/response').Response} Response
 * @typedef {import('./typedefs/response').ContextDelegatedResponse} ContextDelegatedResponse
 */
index2.js The JS file where the types need to be placed, will also contain the /* typework */ marker, but only a single one. It should be at the end and allow for 1 extra line at the end (a file cannot finish with */, only */\n).
const _Koa = require('./koa')
 
class Koa extends _Koa {
  /**
   * Initialize a new `Application`.
   */
  constructor() {
    super()
  }
}
 
module.exports = Koa
Show Typework
/* typework */
/**
 * @typedef {import('types/vendor/cookies').Keygrip} Keygrip
 * @typedef {import('types/typedefs/application').Middleware} Middleware
 * @typedef {import('types/typedefs/application').Application} Application
 * @typedef {import('types/typedefs/context').KoaContext} Context
 * @typedef {import('types/typedefs/request').Request} Request
 * @typedef {import('types/typedefs/request').ContextDelegatedRequest} ContextDelegatedRequest
 * @typedef {import('types/typedefs/response').Response} Response
 * @typedef {import('types/typedefs/response').ContextDelegatedResponse} ContextDelegatedResponse
 */
types The purpose of Typework is to vendor JSDoc across packages easily, so that the IDE documentation can be shown without relying on additional infrastructure like Typings. One of downside of current JSDoc is the lack of import statements, therefore Typework is meant to work in environments which support import.
example/types
├── typedefs
│   ├── application.js
│   ├── context.js
│   ├── request.js
│   └── response.js
└── vendor
    ├── accepts.js
    └── cookies.js

Copyright

(c) Art Deco 2019

Readme

Keywords

Package Sidebar

Install

npm i typework

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

17.6 kB

Total Files

7

Last publish

Collaborators

  • zvr