From 0a956ccb16bdd53735aa2b8cd73309d30ecdbd59 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Mon, 1 Mar 2021 11:34:07 +0100 Subject: [PATCH 01/14] feat: add support for TS --- lib/generator.js | 12 ++++++++---- lib/utils.js | 18 ++++++++++++++++++ package-lock.json | 23 +++++++++++++++++++++++ package.json | 4 +++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index cbaae60d9..2069e48d8 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -28,14 +28,12 @@ const { getInvalidOptions, isReactTemplate, isJsFile, + registerSourceMap, + registerTypeScript, } = require('./utils'); const { registerFilters } = require('./filtersRegistry'); const { registerHooks } = require('./hooksRegistry'); -parser.registerSchemaParser(openapiSchemaParser); -parser.registerSchemaParser(ramlDtParser); -parser.registerSchemaParser(avroSchemaParser); - const FILTERS_DIRNAME = 'filters'; const HOOKS_DIRNAME = 'hooks'; const CONFIG_FILENAME = 'package.json'; @@ -56,6 +54,12 @@ const shouldIgnoreDir = dirPath => dirPath === '.git' || dirPath.startsWith(`.git${path.sep}`); +parser.registerSchemaParser(openapiSchemaParser); +parser.registerSchemaParser(ramlDtParser); +parser.registerSchemaParser(avroSchemaParser); +registerSourceMap(); +registerTypeScript(); + class Generator { /** * Instantiates a new Generator object. diff --git a/lib/utils.js b/lib/utils.js index d98c8fad8..4c049e6a6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -127,3 +127,21 @@ utils.getInvalidOptions = (generatorOptions, options) => { utils.isAsyncFunction = (fn) => { return fn && fn.constructor && fn.constructor.name === 'AsyncFunction'; }; + +/** + * Register `source-map-support` package. + * + * @private + */ +utils.registerSourceMap = () => { + require("source-map-support").install(); +}; + +/** + * Register TypeScript transpiler. It enables transpilation of TS filters and hooks on the fly. + * + * @private + */ +utils.registerTypeScript = () => { + require("ts-node").register(); +}; diff --git a/package-lock.json b/package-lock.json index 8cd184f04..03f45db8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3632,6 +3632,11 @@ "yaml": "^1.10.0" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -3871,6 +3876,11 @@ "integrity": "sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=", "dev": true }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" + }, "diff-sequences": { "version": "25.2.6", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-25.2.6.tgz", @@ -14567,6 +14577,19 @@ "escape-string-regexp": "^1.0.2" } }, + "ts-node": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz", + "integrity": "sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==", + "requires": { + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + } + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", diff --git a/package.json b/package.json index c1b0a8a1b..6a0101451 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,9 @@ "nunjucks": "^3.2.0", "resolve-pkg": "^2.0.0", "semver": "^7.3.2", - "simple-git": "^1.131.0" + "simple-git": "^1.131.0", + "source-map-support": "^0.5.19", + "ts-node": "^9.1.1" }, "devDependencies": { "@semantic-release/commit-analyzer": "^8.0.1", From e2316cde60ed4378ff3316852f8b55fc5514172e Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Mon, 1 Mar 2021 12:29:54 +0100 Subject: [PATCH 02/14] add docs --- docs/authoring.md | 9 +++ package-lock.json | 194 ++++++++++++++++++++++++++++++++++++++++++++-- package.json | 3 +- 3 files changed, 197 insertions(+), 9 deletions(-) diff --git a/docs/authoring.md b/docs/authoring.md index 1ab25de2d..3b13bb605 100644 --- a/docs/authoring.md +++ b/docs/authoring.md @@ -391,3 +391,12 @@ async function asyncCamelCase(str, callback) { ``` In case you have more than one template and want to reuse filters, you can put them in a single library. You can configure such a library in the template configuration under `filters` property. You can also use the official AsyncAPI [filters library](https://github.com/asyncapi/generator-filters). To learn how to add such filters to configuration [read more about the configuration file](#configuration-file). + +## TypeScript support + +The AsyncAPI generator has support for the TypeScript for [hooks](#hooks) and Nunjucks's [filters](#filters). Assumptions: + +- Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. +- Source code of the hook/filter must have `ts` or `tsx` extension. +- Each package related with the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template. +- Each package should have installed `@types/node` package to support typings for Node. diff --git a/package-lock.json b/package-lock.json index 03f45db8a..3f7140fc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3471,6 +3471,32 @@ "inherits": "^2.0.3", "readable-stream": "^2.2.2", "typedarray": "^0.0.6" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "concat-with-sourcemaps": { @@ -3958,6 +3984,32 @@ "dev": true, "requires": { "readable-stream": "^2.0.2" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "ecc-jsbn": { @@ -4862,6 +4914,32 @@ "requires": { "inherits": "^2.0.1", "readable-stream": "^2.0.0" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "fs-extra": { @@ -4988,6 +5066,18 @@ "integrity": "sha512-A1B3Bh1UmL0bidM/YX2NsCOTnGJePL9rO/M+Mw3m9f2gUpfokS0hi5Eah0WSUEWZdZhIZtMjkIYS7mDfOqNHbg==", "dev": true }, + "get-package-type": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", + "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", + "dev": true + }, + "get-stream": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.0.tgz", + "integrity": "sha512-A1B3Bh1UmL0bidM/YX2NsCOTnGJePL9rO/M+Mw3m9f2gUpfokS0hi5Eah0WSUEWZdZhIZtMjkIYS7mDfOqNHbg==", + "dev": true + }, "get-value": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", @@ -5016,6 +5106,21 @@ "traverse": "~0.6.6" }, "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, "split2": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/split2/-/split2-1.0.0.tgz", @@ -5025,6 +5130,15 @@ "through2": "~2.0.0" } }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -5063,6 +5177,11 @@ "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==" }, + "globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==" + }, "globby": { "version": "11.0.2", "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.2.tgz", @@ -5129,6 +5248,30 @@ "through2": "^2.0.0" }, "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -12725,13 +12868,9 @@ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" } }, "readdir-scoped-modules": { @@ -14072,6 +14211,32 @@ "requires": { "duplexer2": "~0.1.0", "readable-stream": "^2.0.2" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "stream-connect": { @@ -14142,7 +14307,15 @@ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "requires": { - "safe-buffer": "~5.1.0" + "safe-buffer": "~5.2.0" + }, + "dependencies": { + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + } } }, "strip-ansi": { @@ -14653,6 +14826,11 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.2.tgz", + "integrity": "sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ==" + }, "typical": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", diff --git a/package.json b/package.json index 6a0101451..8182d07e0 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,8 @@ "semver": "^7.3.2", "simple-git": "^1.131.0", "source-map-support": "^0.5.19", - "ts-node": "^9.1.1" + "ts-node": "^9.1.1", + "typescript": "^4.2.2" }, "devDependencies": { "@semantic-release/commit-analyzer": "^8.0.1", From 093a925d3c7c551a9b2c6f9cebe3fd8a9fbdfebb Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Mon, 1 Mar 2021 12:30:30 +0100 Subject: [PATCH 03/14] fix linter errors --- lib/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 4c049e6a6..86d4523af 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -134,7 +134,7 @@ utils.isAsyncFunction = (fn) => { * @private */ utils.registerSourceMap = () => { - require("source-map-support").install(); + require('source-map-support').install(); }; /** @@ -143,5 +143,5 @@ utils.registerSourceMap = () => { * @private */ utils.registerTypeScript = () => { - require("ts-node").register(); + require('ts-node').register(); }; From beabad6e26963c80c1876b125113f023df5939d3 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Mon, 1 Mar 2021 17:14:43 +0100 Subject: [PATCH 04/14] add new util --- lib/renderer/react.js | 3 +++ lib/utils.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/renderer/react.js b/lib/renderer/react.js index ab139254a..696517315 100644 --- a/lib/renderer/react.js +++ b/lib/renderer/react.js @@ -1,6 +1,7 @@ const path = require('path'); const AsyncReactSDK = require('@asyncapi/generator-react-sdk'); const { + changeExtenstionToJS, writeFile } = require('../utils'); @@ -38,7 +39,9 @@ reactExport.configureReact = async (templateLocation, templateContentDir, transp */ reactExport.renderReact = async (asyncapiDocument, filePath, extraTemplateData, templateLocation, templateContentDir, transpiledTemplateLocation, templateParams, debug, originalAsyncAPI) => { extraTemplateData = extraTemplateData || {}; + filePath = changeExtenstionToJS(filePath); filePath = filePath.replace(templateContentDir, path.resolve(templateLocation, transpiledTemplateLocation)); + return await AsyncReactSDK.renderTemplate( filePath, { diff --git a/lib/utils.js b/lib/utils.js index 86d4523af..80ea68003 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -95,7 +95,18 @@ utils.isFilePath = (str) => { */ utils.isJsFile = (filepath) => { const ext = filepath.split('.').pop() || ''; - return ['js', 'jsx', 'cjs'].includes(ext); + return ['js', 'jsx', 'cjs', 'tsx'].includes(ext); +}; + +/** + * Change file's extension to .js + * + * @param {String} filename information representing file path + * @returns {Boolean} + */ +utils.changeExtenstionToJS = (filename) => { + const basename = path.basename(filename, path.extname(filename)); + return path.join(path.dirname(filename), basename + '.js'); }; /** From d6b5e82bbd917565728e54b26124ea367d16e5d3 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Thu, 4 Mar 2021 10:04:27 +0100 Subject: [PATCH 05/14] reverse last changes --- lib/renderer/react.js | 2 -- lib/utils.js | 13 +------------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/renderer/react.js b/lib/renderer/react.js index 696517315..5ba49e43f 100644 --- a/lib/renderer/react.js +++ b/lib/renderer/react.js @@ -39,9 +39,7 @@ reactExport.configureReact = async (templateLocation, templateContentDir, transp */ reactExport.renderReact = async (asyncapiDocument, filePath, extraTemplateData, templateLocation, templateContentDir, transpiledTemplateLocation, templateParams, debug, originalAsyncAPI) => { extraTemplateData = extraTemplateData || {}; - filePath = changeExtenstionToJS(filePath); filePath = filePath.replace(templateContentDir, path.resolve(templateLocation, transpiledTemplateLocation)); - return await AsyncReactSDK.renderTemplate( filePath, { diff --git a/lib/utils.js b/lib/utils.js index 80ea68003..86d4523af 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -95,18 +95,7 @@ utils.isFilePath = (str) => { */ utils.isJsFile = (filepath) => { const ext = filepath.split('.').pop() || ''; - return ['js', 'jsx', 'cjs', 'tsx'].includes(ext); -}; - -/** - * Change file's extension to .js - * - * @param {String} filename information representing file path - * @returns {Boolean} - */ -utils.changeExtenstionToJS = (filename) => { - const basename = path.basename(filename, path.extname(filename)); - return path.join(path.dirname(filename), basename + '.js'); + return ['js', 'jsx', 'cjs'].includes(ext); }; /** From 5001643e8c01da0165eff19019a9258c2c6e5341 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Thu, 4 Mar 2021 10:14:54 +0100 Subject: [PATCH 06/14] update docs --- docs/authoring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/authoring.md b/docs/authoring.md index 3b13bb605..f2d4ff7ae 100644 --- a/docs/authoring.md +++ b/docs/authoring.md @@ -397,6 +397,6 @@ In case you have more than one template and want to reuse filters, you can put t The AsyncAPI generator has support for the TypeScript for [hooks](#hooks) and Nunjucks's [filters](#filters). Assumptions: - Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. -- Source code of the hook/filter must have `ts` or `tsx` extension. +- Source code of the hook/filter must have `ts` extension. - Each package related with the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template. - Each package should have installed `@types/node` package to support typings for Node. From 9c32b185452aa681f818b0b84f12f996a80b0939 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Thu, 4 Mar 2021 10:16:34 +0100 Subject: [PATCH 07/14] update package-lock --- package-lock.json | 103 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3f7140fc7..905fb0290 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,36 @@ "react": "^17.0.1", "rollup": "^2.34.0", "source-map-support": "^0.5.19" + }, + "dependencies": { + "@babel/core": { + "version": "7.12.9", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.12.9.tgz", + "integrity": "sha512-gTXYh3M5wb7FRXQy+FErKFAv90BnlOuNn1QkCK2lREoPAjrQCO49+HVSrFoe5uakFAF5eenS75KbO2vQiLrTMQ==", + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/generator": "^7.12.5", + "@babel/helper-module-transforms": "^7.12.1", + "@babel/helpers": "^7.12.5", + "@babel/parser": "^7.12.7", + "@babel/template": "^7.12.7", + "@babel/traverse": "^7.12.9", + "@babel/types": "^7.12.7", + "convert-source-map": "^1.7.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.1", + "json5": "^2.1.2", + "lodash": "^4.17.19", + "resolve": "^1.3.2", + "semver": "^5.4.1", + "source-map": "^0.5.0" + } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + } } }, "@asyncapi/openapi-schema-parser": { @@ -2513,6 +2543,11 @@ "readable-stream": "^2.0.6" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -4096,6 +4131,15 @@ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz", "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true + }, + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "requires": { + "path-key": "^3.0.0" + } } } }, @@ -4432,6 +4476,17 @@ "onetime": "^5.1.2", "signal-exit": "^3.0.3", "strip-final-newline": "^2.0.0" + }, + "dependencies": { + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "requires": { + "path-key": "^3.0.0" + } + } } }, "exit": { @@ -5315,7 +5370,7 @@ "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", "requires": { - "ajv": "^6.12.3", + "ajv": "^6.5.5", "har-schema": "^2.0.0" } }, @@ -6160,11 +6215,29 @@ "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true }, + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, + "requires": { + "path-key": "^3.0.0" + } + }, "p-finally": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-2.0.1.tgz", "integrity": "sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw==", "dev": true + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } } } }, @@ -7938,6 +8011,11 @@ } } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, "make-fetch-happen": { "version": "8.0.14", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-8.0.14.tgz", @@ -8173,7 +8251,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz", "integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==", "requires": { - "mime-db": "1.46.0" + "mime-db": "1.44.0" } }, "mimic-fn": { @@ -12257,6 +12335,12 @@ "mimic-fn": "^2.1.0" } }, + "opener": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", + "integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==", + "dev": true + }, "optionator": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", @@ -12868,9 +12952,13 @@ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" } }, "readdir-scoped-modules": { @@ -14307,14 +14395,13 @@ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "requires": { - "safe-buffer": "~5.2.0" + "safe-buffer": "~5.1.0" }, "dependencies": { "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" } } }, From acf35ca0a5409c3b6cf49712a119c22dfc67c3b1 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Thu, 4 Mar 2021 10:21:06 +0100 Subject: [PATCH 08/14] fix linter errors --- lib/renderer/react.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/renderer/react.js b/lib/renderer/react.js index 5ba49e43f..ab139254a 100644 --- a/lib/renderer/react.js +++ b/lib/renderer/react.js @@ -1,7 +1,6 @@ const path = require('path'); const AsyncReactSDK = require('@asyncapi/generator-react-sdk'); const { - changeExtenstionToJS, writeFile } = require('../utils'); From a96962de2a669036429c36cea716f46b71370fd5 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Thu, 4 Mar 2021 11:12:02 +0100 Subject: [PATCH 09/14] add support for ESM default export in hooks --- docs/authoring.md | 6 +++--- lib/hooksRegistry.js | 5 +++++ package-lock.json | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/authoring.md b/docs/authoring.md index f2d4ff7ae..5e8537de9 100644 --- a/docs/authoring.md +++ b/docs/authoring.md @@ -394,9 +394,9 @@ In case you have more than one template and want to reuse filters, you can put t ## TypeScript support -The AsyncAPI generator has support for the TypeScript for [hooks](#hooks) and Nunjucks's [filters](#filters). Assumptions: +The AsyncAPI generator has TypeScript support for [hooks](#hooks) and Nunjucks's [filters](#filters). Assumptions: - Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. -- Source code of the hook/filter must have `ts` extension. -- Each package related with the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template. +- Source code of the hook/filter must have `.ts` extension. +- Each package related with the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template, so cannot uses packages under `devDependencies`. - Each package should have installed `@types/node` package to support typings for Node. diff --git a/lib/hooksRegistry.js b/lib/hooksRegistry.js index e75be0b61..662c6ab7b 100644 --- a/lib/hooksRegistry.js +++ b/lib/hooksRegistry.js @@ -98,6 +98,11 @@ async function registerConfigHooks(hooks, templateDir, templateConfig) { * @param {Array} config List of hooks configured in template configuration */ function addHook(hooks, mod, config) { + // for ESM `export default {}` + if (typeof mod.default === 'object') { + mod = mod.default; + } + Object.keys(mod).forEach(hookType => { const moduleHooksArray = [].concat(mod[hookType]); diff --git a/package-lock.json b/package-lock.json index 905fb0290..dcf77bc4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14399,9 +14399,9 @@ }, "dependencies": { "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" } } }, From d8fbdd66881394b0846b1bf13dd4a0e50d2f9d81 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Thu, 4 Mar 2021 13:05:35 +0100 Subject: [PATCH 10/14] fix package-lock --- package-lock.json | 259 ++-------------------------------------------- 1 file changed, 7 insertions(+), 252 deletions(-) diff --git a/package-lock.json b/package-lock.json index dcf77bc4a..82711015f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,36 +34,6 @@ "react": "^17.0.1", "rollup": "^2.34.0", "source-map-support": "^0.5.19" - }, - "dependencies": { - "@babel/core": { - "version": "7.12.9", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.12.9.tgz", - "integrity": "sha512-gTXYh3M5wb7FRXQy+FErKFAv90BnlOuNn1QkCK2lREoPAjrQCO49+HVSrFoe5uakFAF5eenS75KbO2vQiLrTMQ==", - "requires": { - "@babel/code-frame": "^7.10.4", - "@babel/generator": "^7.12.5", - "@babel/helper-module-transforms": "^7.12.1", - "@babel/helpers": "^7.12.5", - "@babel/parser": "^7.12.7", - "@babel/template": "^7.12.7", - "@babel/traverse": "^7.12.9", - "@babel/types": "^7.12.7", - "convert-source-map": "^1.7.0", - "debug": "^4.1.0", - "gensync": "^1.0.0-beta.1", - "json5": "^2.1.2", - "lodash": "^4.17.19", - "resolve": "^1.3.2", - "semver": "^5.4.1", - "source-map": "^0.5.0" - } - }, - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" - } } }, "@asyncapi/openapi-schema-parser": { @@ -3506,32 +3476,6 @@ "inherits": "^2.0.3", "readable-stream": "^2.2.2", "typedarray": "^0.0.6" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - } } }, "concat-with-sourcemaps": { @@ -4019,32 +3963,6 @@ "dev": true, "requires": { "readable-stream": "^2.0.2" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - } } }, "ecc-jsbn": { @@ -4131,15 +4049,6 @@ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz", "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true - }, - "npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "dev": true, - "requires": { - "path-key": "^3.0.0" - } } } }, @@ -4476,17 +4385,6 @@ "onetime": "^5.1.2", "signal-exit": "^3.0.3", "strip-final-newline": "^2.0.0" - }, - "dependencies": { - "npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "dev": true, - "requires": { - "path-key": "^3.0.0" - } - } } }, "exit": { @@ -4969,32 +4867,6 @@ "requires": { "inherits": "^2.0.1", "readable-stream": "^2.0.0" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - } } }, "fs-extra": { @@ -5121,18 +4993,6 @@ "integrity": "sha512-A1B3Bh1UmL0bidM/YX2NsCOTnGJePL9rO/M+Mw3m9f2gUpfokS0hi5Eah0WSUEWZdZhIZtMjkIYS7mDfOqNHbg==", "dev": true }, - "get-package-type": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", - "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", - "dev": true - }, - "get-stream": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.0.tgz", - "integrity": "sha512-A1B3Bh1UmL0bidM/YX2NsCOTnGJePL9rO/M+Mw3m9f2gUpfokS0hi5Eah0WSUEWZdZhIZtMjkIYS7mDfOqNHbg==", - "dev": true - }, "get-value": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", @@ -5161,21 +5021,6 @@ "traverse": "~0.6.6" }, "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, "split2": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/split2/-/split2-1.0.0.tgz", @@ -5185,15 +5030,6 @@ "through2": "~2.0.0" } }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -5232,11 +5068,6 @@ "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==" }, - "globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==" - }, "globby": { "version": "11.0.2", "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.2.tgz", @@ -5303,30 +5134,6 @@ "through2": "^2.0.0" }, "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -5370,7 +5177,7 @@ "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", "requires": { - "ajv": "^6.5.5", + "ajv": "^6.12.3", "har-schema": "^2.0.0" } }, @@ -6215,29 +6022,11 @@ "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true }, - "npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "dev": true, - "requires": { - "path-key": "^3.0.0" - } - }, "p-finally": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-2.0.1.tgz", "integrity": "sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw==", "dev": true - }, - "which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "requires": { - "isexe": "^2.0.0" - } } } }, @@ -8251,7 +8040,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz", "integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==", "requires": { - "mime-db": "1.44.0" + "mime-db": "1.46.0" } }, "mimic-fn": { @@ -12335,12 +12124,6 @@ "mimic-fn": "^2.1.0" } }, - "opener": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", - "integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==", - "dev": true - }, "optionator": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", @@ -14299,32 +14082,6 @@ "requires": { "duplexer2": "~0.1.0", "readable-stream": "^2.0.2" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - } } }, "stream-connect": { @@ -14396,13 +14153,6 @@ "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "requires": { "safe-buffer": "~5.1.0" - }, - "dependencies": { - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - } } }, "strip-ansi": { @@ -15550,6 +15300,11 @@ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.6.tgz", "integrity": "sha512-AP1+fQIWSM/sMiET8fyayjx/J+JmTPt2Mr0FkrgqB4todtfa53sOsrSAcIrJRD5XS20bKUwaDIuMkWKCEiQLKA==", "dev": true + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==" } } } From 3d604feb9b9e336ba9c651c7de46ebbb35868bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Urba=C5=84czyk?= Date: Fri, 5 Mar 2021 10:56:36 +0100 Subject: [PATCH 11/14] Apply suggestions from code review Co-authored-by: Lukasz Gornicki --- docs/authoring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/authoring.md b/docs/authoring.md index 5e8537de9..8f84e60c4 100644 --- a/docs/authoring.md +++ b/docs/authoring.md @@ -398,5 +398,5 @@ The AsyncAPI generator has TypeScript support for [hooks](#hooks) and Nunjucks's - Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. - Source code of the hook/filter must have `.ts` extension. -- Each package related with the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template, so cannot uses packages under `devDependencies`. +- Each package related to the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template, and cannot use packages under `devDependencies`. - Each package should have installed `@types/node` package to support typings for Node. From 887c4075f48adc7c4459df3b10141f5aa316db76 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Fri, 5 Mar 2021 11:13:59 +0100 Subject: [PATCH 12/14] after review --- docs/authoring.md | 2 +- lib/utils.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/authoring.md b/docs/authoring.md index 8f84e60c4..4456a9c47 100644 --- a/docs/authoring.md +++ b/docs/authoring.md @@ -399,4 +399,4 @@ The AsyncAPI generator has TypeScript support for [hooks](#hooks) and Nunjucks's - Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. - Source code of the hook/filter must have `.ts` extension. - Each package related to the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template, and cannot use packages under `devDependencies`. -- Each package should have installed `@types/node` package to support typings for Node. +- Each template should have installed `@types/node` package to support typings for Node. diff --git a/lib/utils.js b/lib/utils.js index 86d4523af..710afbe90 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -130,6 +130,7 @@ utils.isAsyncFunction = (fn) => { /** * Register `source-map-support` package. + * This package provides source map support for stack traces in Node - also for transpiled code from TS. * * @private */ From 8e0aed4175e7ac84446a5a258656723b6a4d2ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Urba=C5=84czyk?= Date: Fri, 5 Mar 2021 13:50:42 +0100 Subject: [PATCH 13/14] Apply suggestions from code review Co-authored-by: Lukasz Gornicki --- docs/authoring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/authoring.md b/docs/authoring.md index 4456a9c47..a153713b3 100644 --- a/docs/authoring.md +++ b/docs/authoring.md @@ -399,4 +399,4 @@ The AsyncAPI generator has TypeScript support for [hooks](#hooks) and Nunjucks's - Installing the `typescript` package and creating the` tsconfig.json` file isn't necessary. - Source code of the hook/filter must have `.ts` extension. - Each package related to the typings for TypeScript like `@types/node` must be installed in the template under `dependencies` array. This is because the Generator transpiles the TypeScript code on-the-fly while rendering the template, and cannot use packages under `devDependencies`. -- Each template should have installed `@types/node` package to support typings for Node. +- Each template should have `@types/node` package installed to enable support for typings for Node. From 4c70301aa8dca085ca0c1a5061a5c92baba0d8e8 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Fri, 5 Mar 2021 13:54:51 +0100 Subject: [PATCH 14/14] after review --- lib/hooksRegistry.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/hooksRegistry.js b/lib/hooksRegistry.js index 662c6ab7b..a6b010748 100644 --- a/lib/hooksRegistry.js +++ b/lib/hooksRegistry.js @@ -98,7 +98,11 @@ async function registerConfigHooks(hooks, templateDir, templateConfig) { * @param {Array} config List of hooks configured in template configuration */ function addHook(hooks, mod, config) { - // for ESM `export default {}` + /** + * ESM `export default { ... }` is transpiled to: + * module.exports = { default: { ... } }; + * First check the `default` object, and if it exists the override mod to `default`. + */ if (typeof mod.default === 'object') { mod = mod.default; }