{"name":"babel-plugin-transform-typescript-metadata","version":"0.1.0","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","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 --reporters=default --reporters=jest-junit"},"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":"e709b2db581a99f503a4489602218d7905f7990f","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.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.14.1","_npmUser":{"name":"leonardfactory","email":"leonardo@favoloso.team"},"dist":{"integrity":"sha512-Jahh/sLf9KBonIxjxsvE4UCQZx4STxzSehBGwqV498VkQWElGX7ieA3EiA49fLrQ41lPEji93WV6ckEKTY+EsA==","shasum":"2874f96da1e54b3fa3b634100414c8886073bea7","tarball":"http://registry-npm.ywwl.com/babel-plugin-transform-typescript-metadata/download/babel-plugin-transform-typescript-metadata-0.1.0.tgz","fileCount":16,"unpackedSize":13774,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcl3TnCRA9TVsSAnZWagAAJhAP/0nNYcj2kqrqHkZmamqT\nxzBSMfyfsFq40NwJfxIipBZnWLSa1GwU4M7Z8N1zOzEYQEuhnirsddrg4s3R\nuoXdl1T24oXcJfFgqDMFHHoS9yqE3ou/jtuiKiZJ0lq9sPb1oNsDtWQEakoc\nUNKOdbVtH9N9i1RatZETJNwDQ1NBpc8uXwQ1aVHQ//j2an6cttp7BB7/TytL\nh7nXlG5wSPeDIy7tQ3O3g2U+qvz68MN+9Dvl0glI0bzCsvwe8UymgafTgWhS\nwTJBYSjxh1EHCqXB5mwR8cJl52RVpjOJ00HbBaozFeJOx6zkvfPrYmwXJeFD\n7HJoPsJ/GpuTx3aiZm7MHsfvdhENrdilYbKWp9B2qHoivcQxBjK0NJSflNaU\nNNP1+4tAzSgGuG6thyczj2D+4PR86F5RqSGnVvx/T0UAw+Gh1Fy48bstH7kG\nujEq6lgEf99XmVmwoe5QOLNUUm0Y0ckXzd+AoKURsO76HND/yXS4DSUearYj\nqKaYh6HY0c4CP+kb7OubNFPlrArmiKc5bFtfqUdJ41Dj9QyxyjO0rJNzM0ok\ntGpVc+0tofvBvv5sWw8Kz598Kek8rxLPp5opS/wnZjpqRZNE7MnSLTLzFPCS\nKtrY2uVYt49SdTzbfIZUyTcnT35g9PHptJDUfK1Wr82xnLKpczYxKZCeTEYy\nC6sq\r\n=L0sE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCngUxSA0JvLMOMEVMdeAThejkc/fsRxXsCcUQIXbxrQAIhAIxPpuSr+A5FX+ReVqz/Bx5VYlpVxY20Jx07szFvH9wu"}],"size":4901,"noattachment":false,"key":"/babel-plugin-transform-typescript-metadata/-/babel-plugin-transform-typescript-metadata-0.1.0.tgz"},"maintainers":[{"name":"leonardfactory","email":"leonardo@favoloso.team"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-typescript-metadata_0.1.0_1553429734396_0.7002900923024715"},"_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":1553429734514,"_cnpm_publish_time":1553429734514,"dist-tags":{"latest":"0.4.0"}}