{"name":"babel-plugin-transform-typescript-metadata","version":"0.2.2","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","@babel/template":"^7.4.0","@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":"a90bdd5b005e17c72cdf3630623b27c27023f448","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.2","_npmVersion":"6.4.1","_nodeVersion":"10.14.1","_npmUser":{"name":"leonardfactory","email":"leonardo@favoloso.team"},"dist":{"integrity":"sha512-wWRw1p3IDNZN8l3UOLgeScq9Nhh4lvxT7ZOvUzYi5sMw8lUWW+KdRlnBeQKehHAsgDs5TR6PvMJmsQ6e6NmKCg==","shasum":"fc44611187409ed9d5cb372ca2f85939a359cada","tarball":"http://registry-npm.ywwl.com/babel-plugin-transform-typescript-metadata/download/babel-plugin-transform-typescript-metadata-0.2.2.tgz","fileCount":16,"unpackedSize":26350,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcm37OCRA9TVsSAnZWagAAYtEQAIwvAug9J7LAyxGB/LJL\nkRSKD/U4RCrWgjjdRlA7OlG/l+QTIGUp3V2GZsqFl92qw+PgCxBRd5p/h9nH\nE5ICQ0Sh4YebphJDuhHy0ZmKylBPFBdv2gpp/pLuE45LaMXM+1amtWA/UnOT\ni+bEVbl51IGGvB/HbEJkdzQt3To4pR+orNe095Le6C/VpILe6UAbgw8rr4uM\nXAXyN1EcJY8P9bNdx3LPp6ot5ecFHcX9v3cEWjWlkGcHJlVqZK1z2rExYWjH\nM/po4oebxI/DjyFIgUKajdC9aDVK1nhkhOKsYrOE5/3TWLtn/xMmlmY/pTIH\nRTT0E0tvJ5uPg6/roVUTNpAiHPIgB07q1kuZX9WCIWF5L4zhvK7mHdFwzhu4\nlf0CDGblnx3MUzwHbcGmZEaGV9ZTSMtRAVeoYaeNrv9PEpg+zMNyHOGbUuD4\nHEQ+lKxkduHdZnFWoXQHJp7G8XOaUJFPuh0k/5uvj/K34MA+4o470Hz9SPjB\n315rVa5iuHHrP7fEr51e+Mlk6aIHPz20nkE3jJz4278EeH3keikErao+jGGG\nloOkUJv8IEPKH698ebheRUU8oyqGXa+6MNuzHrUrZQ0LbZ6lfWjUFoqREk7l\nW2b238eSaYarPlEUgtboxHVAok5ixuxsgPVrt1MdxxT02jzZteQWuP37UvdD\nVjjh\r\n=MyFi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDMpNkXzKA4cYFXeC9pAkdY3gDzTP+C2ZsKJgSGfLUUWQIhAJbZ5hrJ1XM+EhXMxC8t6zJ7MclGgm8j7Pfiof5WMoBR"}],"size":8416,"noattachment":false,"key":"/babel-plugin-transform-typescript-metadata/-/babel-plugin-transform-typescript-metadata-0.2.2.tgz"},"maintainers":[{"name":"leonardfactory","email":"leonardo@favoloso.team"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-typescript-metadata_0.2.2_1553694414151_0.7959259769832798"},"_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":1553694414245,"_cnpm_publish_time":1553694414245,"dist-tags":{"latest":"0.4.0"}}