{"name":"babel-plugin-transform-typescript-metadata","version":"0.2.1","description":"Babel plugin to emit decorator metadata like typescript compiler","main":"lib/plugin.js","repository":{"type":"git","url":"git+https://github.com/leonardfactory/babel-plugin-transform-typescript-metadata.git"},"author":{"name":"Leonardo Ascione","email":"leonardo.ascione@gmail.com"},"license":"MIT","keywords":["babel","babel-plugin","babel-typescript","decorators","reflect-metadata"],"scripts":{"dev":"babel src -w -d lib -x '.ts,.tsx'","build":"yarn build:lib && yarn build:types","prebuild:lib":"rm -rf lib","build:lib":"babel src -d lib -x '.ts,.tsx'","build:types":"tsc --emitDeclarationOnly","check-types":"tsc --noEmit","release":"yarn test && yarn build && release-it","test":"jest","test:dev":"jest --watch","test:ci":"jest --ci --runInBand --coverage"},"husky":{"hooks":{"commit-msg":"emoji-commit-lint"}},"release-it":{"git":{"tagName":"v${version}","commitMessage":"🔖 v${version}"},"github":{"release":true},"increment":"conventional:@favoloso/emoji","scripts":{"changelog":"./node_modules/.bin/conventional-changelog -p @favoloso/emoji | tail -n +3","beforeStage":"./node_modules/.bin/conventional-changelog -p @favoloso/emoji -i CHANGELOG.md -s"}},"publishConfig":{"registry":"https://registry.npmjs.org/"},"devDependencies":{"@babel/cli":"^7.2.3","@babel/core":"^7.4.0","@babel/plugin-proposal-class-properties":"^7.4.0","@babel/plugin-proposal-decorators":"^7.4.0","@babel/preset-env":"^7.4.2","@babel/preset-typescript":"^7.3.3","@favoloso/conventional-changelog-emoji":"^0.9.0","@types/jest":"^24.0.11","babel-test":"^0.1.6","conventional-changelog-cli":"^2.0.12","husky":"^1.3.1","jest":"^24.5.0","jest-file-snapshot":"^0.3.6","release-it":"^10.3.1","typescript":"^3.3.4000"},"dependencies":{"@babel/helper-plugin-utils":"^7.0.0"},"gitHead":"44d7b581c547437edd233dc7e82579065eb47320","bugs":{"url":"https://github.com/leonardfactory/babel-plugin-transform-typescript-metadata/issues"},"homepage":"https://github.com/leonardfactory/babel-plugin-transform-typescript-metadata#readme","_id":"babel-plugin-transform-typescript-metadata@0.2.1","_npmVersion":"6.4.1","_nodeVersion":"10.14.1","_npmUser":{"name":"leonardfactory","email":"leonardo@favoloso.team"},"dist":{"integrity":"sha512-4xROk0UQwG6gorCTSE0nymcGaLkSkG/pMhDvptuozqIKxg/bnGyMOAglTPOO2EQ3E1fW+Q0/wi4WAstqXw8wTQ==","shasum":"64cab4eb1cb7ffd7afa8fdd08bd8a02d80ae05c6","tarball":"http://registry-npm.ywwl.com/babel-plugin-transform-typescript-metadata/download/babel-plugin-transform-typescript-metadata-0.2.1.tgz","fileCount":16,"unpackedSize":22262,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcl5JWCRA9TVsSAnZWagAAgRUQAJGPczoKz4tg68RU2uo/\n1UtXqlWkX7/UUNMKZsrwq7OTXfDTofPOS/R1AclFJb7uB0WkRUv6z4A65KWY\n04TswMQLeoTOEZ5S8lOlECoGEwSOewxf/NbqISCKAwBHmIF0mUvBhGervGfJ\njkCXHGclNqMv+EZ0/rfGokRHCo8DG6NnUhJ902KjXa4qwLtAoNTnfpAocKj4\nIW1dmTIqW4Sw+V8dhXI1hxfShsx8bwFQaGYN+iMtutHUfL8+hQRJIifRKSJs\nkMXsWwHYL7rrJG8CF9uY09U0KeKXO1M8R5RVw/CAIJXpX3quTLhCbRSp6uod\nd1e1x3kEuZkFSX5FHrOGb22VQv9g5HTBOrQ4t8S8/90hvOv0gEqqCJRXywuS\nzY8f90kQ58PDk7TFpWwltA5ewXMO+lbgkS7eYgJbxX1pv0Bex0lx+n6p0wlS\nDdSM2eShZiDGK1tqV3EicCRImBZ0tHH6USH/D+j41MIg4YRrFpUw916G4+vz\n/jvnRzwGuKf2xppPdUQuQUE+MXFqRutsMcAdrRI7LBcDvPeXooXCEjctMVo7\nAUUUMOmRxANo9TspPSUYZm/T0uyDTAOCMiQltNSBGBwtmvKzlooGZMpKRhAd\nTph8k3wJolu/VMglI9ENa43MkLJg2afMdtgCTEnDBW3zF/L2QvCml2Zct1fY\nQTcz\r\n=ldGl\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCpmXnOue+yoReM3p3oX9zLTo/J4rGfRTPcr/MjT8D7AQIgcFwowShVDQ/9qcqUoZ8bN9/ZYyJPjT07pY4wu4bDa0s="}],"size":7328,"noattachment":false,"key":"/babel-plugin-transform-typescript-metadata/-/babel-plugin-transform-typescript-metadata-0.2.1.tgz"},"maintainers":[{"name":"leonardfactory","email":"leonardo@favoloso.team"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-typescript-metadata_0.2.1_1553437269639_0.37591602400749125"},"_hasShrinkwrap":false,"readme":"# babel-plugin-transform-typescript-metadata\n\n[![Travis (.com)](https://img.shields.io/travis/com/leonardfactory/babel-plugin-transform-typescript-metadata.svg)](https://travis-ci.com/leonardfactory/babel-plugin-transform-typescript-metadata)\n[![Codecov](https://img.shields.io/codecov/c/github/leonardfactory/babel-plugin-transform-typescript-metadata.svg)](https://codecov.io/gh/leonardfactory/babel-plugin-transform-typescript-metadata)\n[![npm](https://img.shields.io/npm/v/babel-plugin-transform-typescript-metadata.svg?style=popout)](https://www.npmjs.com/package/babel-plugin-transform-typescript-metadata)\n\nBabel plugin to emit decorator metadata like typescript compiler\n\n## Motivation\n\nTypeScript _Decorators_ allows advanced reflection patterns when combined\nwith [`Reflect.metadata`](https://rbuckton.github.io/reflect-metadata/) output.\n\nCurrent `@babel/preset-typescript` implementation however just strips all types and\n_does not_ emit the relative Metadata in the output code.\n\nSince this kind of information is used extensively in libraries like\n[Nest](https://docs.nestjs.com/providers) and [TypeORM](https://typeorm.io/#/)\nto implement advanced features like **Dependency Injection**, I've thought it would\nbe awesome to be able to provide the same functionality that [TypeScript\ncompiler `experimentalDecorators` and `emitDecoratorMetadata`\nflags](https://www.typescriptlang.org/docs/handbook/decorators.html) provide.\n\nThis means that code like:\n\n```ts\nimport { Injectable, Inject } from 'some-di-library'; // Just an example\nimport { MyService } from './MyService';\nimport { Configuration } from './Configuration';\n\n@Injectable()\nclass AnotherService {\n  @Inject()\n  config: Configuration;\n\n  constructor(private service: MyService) {}\n}\n```\n\nwill be interpreted like:\n\n```ts\nimport { MyService } from './MyService';\nimport { Configuration } from './Configuration';\n\n@Injectable()\n@Reflect.metadata('design:paramtypes', [MyService])\nclass AnotherService {\n  @Inject()\n  @Reflect.metadata('design:type', Configuration)\n  config: Configuration;\n\n  constructor(private service: MyService) {}\n}\n```\n\n### Parameter decorators\n\nSince decorators in typescript supports also _Parameters_, this plugin\nalso provides support for them, enabling the following syntax:\n\n```ts\n@Injectable()\nclass Some {\n  constructor(@Inject() private: SomeService);\n}\n```\n\nThis will be roughly translated to:\n\n```js\n// ...\nInject()(Some.prototype, undefined, 0);\n```\n\n## Installation\n\nWith npm:\n\n```sh\nnpm install --dev --save babel-plugin-transform-typescript-metadata\n```\n\nor with Yarn:\n\n```sh\nyarn add --dev babel-plugin-transform-typescript-metadata\n```\n\n## Usage\n\nWith `.babelrc`:\n\n> **Note:** should be placed **before** `@babel/plugin-proposal-decorators`.\n\n```js\n{\n  \"plugins\": [\n    \"babel-plugin-transform-typescript-metadata\",\n    [\"@babel/plugin-proposal-decorators\", { \"legacy\": true }],\n    [\"@babel/plugin-proposal-class-properties\", { \"loose\": true }],\n  ],\n  \"presets\": [\n    \"@babel/preset-typescript\"\n  ]\n}\n```\n\n### Usage with [InversifyJS](http://inversify.io)\n\nIf you are using normal dependency injection letting Inversify **create your instances**, you should be fine with all kind of decorators.\n\nInstead, if you are using **property injection**, when [the container does not\ncreate the instances](https://github.com/inversify/InversifyJS/blob/master/wiki/property_injection.md#when-we-cannot-use-inversifyjs-to-create-an-instance-of-a-class),\nyou would likely encounter errors since babel\ndecorators are not exactly the same as TypeScript.\n\nYou can fix it by _enhancing property decorators_ with the following function:\n\n```ts\nimport getDecorators from 'inversify-inject-decorators';\n// setup the container...\nlet { lazyInject: originalLazyInject } = getDecorators(container);\n\n// Additional function to make properties decorators compatible with babel.\nfunction fixPropertyDecorator<T extends Function>(decorator: T): T {\n  return ((...args: any[]) => (\n    target: any,\n    propertyName: any,\n    ...decoratorArgs: any[]\n  ) => {\n    decorator(...args)(target, propertyName, ...decoratorArgs);\n    return Object.getOwnPropertyDescriptor(target, propertyName);\n  }) as any;\n}\n\nexport const lazyInject = fixPropertyDecorator(originalLazyInject);\n```\n\n## Current Pitfalls\n\n- If you are using webpack and it complains about missing exports due to types\n  not being removed, you can switch from `import { MyType } from ...` to \n  `import type { MyType } from ...`. See [#46](https://github.com/leonardfactory/babel-plugin-transform-typescript-metadata/issues/46) for details and \n  examples.\n\n- We cannot know if type annotations are just types (i.e. `IMyInterface`) or\n  concrete values (like classes, etc.). In order to resolve this, we emit the\n  following: `typeof Type === 'undefined' ? Object : Type`. The code has the\n  advantage of not throwing. If you know a better way to do this, let me know!\n","publish_time":1553437269875,"_cnpm_publish_time":1553437269875,"dist-tags":{"latest":"0.4.0"}}