{"name":"babel-plugin-transform-typescript-metadata","version":"0.3.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},"plugins":{"@release-it/conventional-changelog":{"preset":"@favoloso/emoji","infile":"CHANGELOG.md"}}},"publishConfig":{"registry":"https://registry.npmjs.org/"},"devDependencies":{"@babel/cli":"^7.6.4","@babel/core":"^7.6.4","@babel/plugin-proposal-class-properties":"^7.5.5","@babel/plugin-proposal-decorators":"^7.6.0","@babel/plugin-transform-modules-commonjs":"^7.10.4","@babel/preset-env":"^7.6.3","@babel/preset-typescript":"^7.6.0","@babel/template":"^7.6.0","@babel/types":"^7.6.3","@favoloso/conventional-changelog-emoji":"^0.10.0","@release-it/conventional-changelog":"^1.1.0","@types/jest":"^24.0.19","babel-test":"^0.2.3","conventional-changelog-cli":"^2.0.25","husky":"^4.2.3","jest":"^24.9.0","jest-file-snapshot":"^0.3.7","release-it":"13.7.1","typescript":"^3.6.4"},"dependencies":{"@babel/helper-plugin-utils":"^7.0.0"},"gitHead":"775caf3244a610efa3d8bfb5408a366b7a1fe321","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.3.1","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","_npmUser":{"name":"leonardfactory","email":"leonardo@favoloso.team"},"dist":{"integrity":"sha512-thOuACZReULfLy7vh2o3/joYkkRerMKLBDmXy3ImCnkNUnxBmNw0uVa05JhhX0slluaEkio6OIFa7zPgaJdk6g==","shasum":"d86599b7139131ba5e917f5f568d0c824a5cdfc3","tarball":"http://registry-npm.ywwl.com/babel-plugin-transform-typescript-metadata/download/babel-plugin-transform-typescript-metadata-0.3.1.tgz","fileCount":16,"unpackedSize":28956,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfhJ3/CRA9TVsSAnZWagAAjVkP/0H98qYufUln5tAbCCNA\nT0F8OmNu8M1YOTOu+xe4+RpPbu8jfk7n1e5fRpgEA/8wCFhl0UMuG1J0rZt0\nI8TEPGXhi73zAh343uzBgK3178106NFk6NX3vaebN5CaNnuOGp3u1qlbOk/S\ncFR6XITFAc3dE+V89zifAnFCODiKHWcahZQrpDArAEJGeiFF+/0/y0/yZw97\nnbpDqpoZaUYfTtz3oOKIIp9XexR3sFnc9yB71Micps8m0DrUXq8JUjgNQ8V0\nF9yNfQb6oBtmqnUHCEVsYGlAX0PlcHOpVT/MbSdbqSm0o3g5DmASKH94CEcp\nwjGeYhHKdYB6ASLelPOH43Exhhj1yNAoRy+oeP9XLBamIKqejmUZk2vNhBjD\naPERvKk+e8XjXr+F7X+diQuj7h2kyXKnjpeWeZcx2UN48HSQk88o08x3k/ku\nWsFzVdzcuKQN+lOaCTO645hJEQTB7Id5xX8LPRwZT6js/VTZQUJQ8QcHWZiA\nIKY5KMOomt+q7dmeUzD2SWTM3tA+qHTTMJV0g/Dx357F5pZ1xmU8ODdTrbWe\nxa6OyyZni8xmyzGTEr22F7yKS824aXlYBxARBzIKpiKQL/HmO6fxdIos4bWu\nK8He2+kvTTUqu7D8yrQmYfmRPfIocTfu9H1Tu9cPNOZpCVrJuEqnfHMRu4tN\nPeLe\r\n=z+6r\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBvijlt0eOBLTsYQ6+TQZxRqmwDF55lrTY3XS1bnmHLYAiEArzRiXaU5wC5qk6zwlXU2hk93ThcYgs5oPJb6jly8SrA="}],"size":9054,"noattachment":false,"key":"/babel-plugin-transform-typescript-metadata/-/babel-plugin-transform-typescript-metadata-0.3.1.tgz"},"maintainers":[{"name":"leonardfactory","email":"leonardo@favoloso.team"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-typescript-metadata_0.3.1_1602526718751_0.5311759614808589"},"_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":1602526718901,"_cnpm_publish_time":1602526718901,"dist-tags":{"latest":"0.4.0"}}