From 0d1f2826212eb58f40074a265e4f08403aa704bf Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Thu, 26 Oct 2023 10:52:43 +0200 Subject: [PATCH] fix(engines): remove old engines (vue, arc, marko) --- docs/docs/templating.md | 1 - packages/core/jest.config.js | 8 +- .../core/src/decorators/deprecated.spec.ts | 40 +- packages/core/src/decorators/deprecated.ts | 33 +- packages/engines/.nycrc | 2 +- packages/engines/package.json | 14 +- packages/engines/readme.md | 1 - .../engines/src/components/MarkoEngine.ts | 28 - .../engines/src/components/VueEngine.spec.ts | 40 - packages/engines/src/components/VueEngine.ts | 156 - packages/engines/src/index.ts | 2 - packages/engines/src/utils/getEngines.spec.ts | 2 - .../engines/test/fixtures/marko/user.marko | 1 - packages/engines/test/integration.spec.ts | 1 - yarn.lock | 5349 +++-------------- 15 files changed, 1034 insertions(+), 4644 deletions(-) delete mode 100644 packages/engines/src/components/MarkoEngine.ts delete mode 100644 packages/engines/src/components/VueEngine.spec.ts delete mode 100644 packages/engines/src/components/VueEngine.ts delete mode 100644 packages/engines/test/fixtures/marko/user.marko diff --git a/docs/docs/templating.md b/docs/docs/templating.md index 53d80ce8d5c..cb678bb4137 100644 --- a/docs/docs/templating.md +++ b/docs/docs/templating.md @@ -115,7 +115,6 @@ If `dustjs-helpers` is installed, `dustjs-linkedin` will not be used by consolid | [velocityjs](https://github.com/julianshapiro/velocity) | [BETA](https://www.npmjs.com/package/velocity-animate) | [(website)](http://velocityjs.org/) | | [walrus](https://github.com/jeremyruppel/walrus) | [`npm install walrus`](https://www.npmjs.com/package/walrus) | [(website)](http://documentup.com/jeremyruppel/walrus/) | | [whiskers](https://github.com/gsf/whiskers.js) | [`npm install whiskers`](https://www.npmjs.com/package/whiskers) | - | -| [vue](https://github.com/vuejs/vue) | `npm install vue vue-pronto` | [(website)](https://vuejs.org/) | ::: tip Note You must still install the engines you wish to use, add them to your package.json dependencies. diff --git a/packages/core/jest.config.js b/packages/core/jest.config.js index 31296db1365..4dabc07dd5c 100644 --- a/packages/core/jest.config.js +++ b/packages/core/jest.config.js @@ -5,10 +5,10 @@ module.exports = { ...require("@tsed/jest-config"), coverageThreshold: { global: { - statements: 98.99, - branches: 94.93, - functions: 95.81, - lines: 98.99 + statements: 98.75, + branches: 94.67, + functions: 95.41, + lines: 98.41 } } }; diff --git a/packages/core/src/decorators/deprecated.spec.ts b/packages/core/src/decorators/deprecated.spec.ts index 178b129b8c9..bc0a8914ffd 100644 --- a/packages/core/src/decorators/deprecated.spec.ts +++ b/packages/core/src/decorators/deprecated.spec.ts @@ -1,17 +1,47 @@ import {Deprecated} from "./deprecated"; -import {deprecate} from "util"; - -jest.mock("util"); describe("Deprecated", () => { + beforeEach(() => { + jest.spyOn(console, "error").mockReturnValue(); + jest.spyOn(console, "warn").mockReturnValue(); + }); it("should wrap method as deprecated", () => { class Test { @Deprecated("test") test() {} } - new Test(); + new Test().test(); + + expect(console.error).toHaveBeenCalledWith("test"); + }); + it("should wrap method as deprecated (throwDeprecation)", () => { + class Test { + @Deprecated("test") + test() {} + } + + (process as any).throwDeprecation = true; + + try { + new Test().test(); + } catch (er) { + expect(er.message).toEqual("test"); + } finally { + (process as any).throwDeprecation = false; + } + }); + it("should wrap method as deprecated (traceDeprecation)", () => { + class Test { + @Deprecated("test") + test() {} + } + + (process as any).traceDeprecation = true; + new Test().test(); + + expect(console.error).toHaveBeenCalled(); - expect(deprecate).toHaveBeenCalledWith(expect.any(Function), "test"); + (process as any).traceDeprecation = false; }); }); diff --git a/packages/core/src/decorators/deprecated.ts b/packages/core/src/decorators/deprecated.ts index 9dd9ed04d68..3e0cc9bfef3 100644 --- a/packages/core/src/decorators/deprecated.ts +++ b/packages/core/src/decorators/deprecated.ts @@ -1,5 +1,36 @@ -import {deprecate} from "util"; import {Type} from "../domain/Type"; + +function deprecate(fn: any, msg: string) { + if (typeof process !== "undefined" && (process as any).noDeprecation === true) { + return fn; + } + + // Allow for deprecating things in the process of starting up. + if (typeof process === "undefined") { + return function (...args: any[]) { + return deprecate(fn, msg).apply(this, args); + }; + } + + let warned = false; + + function deprecated(...args: any[]) { + if (!warned) { + if ((process as any).throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, args); + } + + return deprecated; +} + /** * The `@Deprecated()` decorators wraps the given method in such a way that it is marked as deprecated. * diff --git a/packages/engines/.nycrc b/packages/engines/.nycrc index ea0f737ad7d..05605266113 100644 --- a/packages/engines/.nycrc +++ b/packages/engines/.nycrc @@ -20,7 +20,7 @@ ], "check-coverage": true, "statements": 96.38, - "branches": 75.14, + "branches": 72.9, "functions": 96.26, "lines": 96.32 } diff --git a/packages/engines/package.json b/packages/engines/package.json index 671f0824b76..78d3f49472c 100644 --- a/packages/engines/package.json +++ b/packages/engines/package.json @@ -31,12 +31,11 @@ "@tsed/typescript": "7.39.1", "@types/fs-extra": "^11.0.3", "@types/semver": "^7.3.9", - "arc-templates": "^0.5.3", - "atpl": "^0.9.3", - "babel-core": "^6.26.3", - "babel-plugin-transform-runtime": "^6.23.0", - "babel-preset-es2015": "^6.24.1", - "babel-preset-react": "^6.24.1", + "@babel/core": "7.23.2", + "@babel/plugin-transform-runtime": "7.23.2", + "@babel/preset-env": "7.23.2", + "@babel/preset-react": "7.22.15", + "atpl": "0.9.3", "bracket-template": "^1.1.5", "coffee-script": "^1.12.7", "dot": "^1.1.3", @@ -60,7 +59,6 @@ "liquid-node": "^3.0.1", "liquor": "^0.0.5", "lodash": "^4.17.21", - "marko": "^5.20.3", "mote": "^0.2.0", "mustache": "^4.2.0", "nunjucks": "^3.2.3", @@ -73,7 +71,6 @@ "semver": "^7.3.2", "slm": "^2.0.0", "squirrelly": "^5.1.0", - "swig": "^1.4.2", "swig-templates": "^2.0.3", "teacup": "^2.0.0", "templayed": ">=0.2.3", @@ -84,7 +81,6 @@ "underscore": "^1.11.0", "vash": "^0.13.0", "velocityjs": "^2.0.1", - "vue-pronto": "^2.4.0", "walrus": "^0.10.1", "whiskers": "^0.4.0" }, diff --git a/packages/engines/readme.md b/packages/engines/readme.md index f1677f9dcf3..1015228d16f 100644 --- a/packages/engines/readme.md +++ b/packages/engines/readme.md @@ -86,7 +86,6 @@ If `dustjs-helpers` is installed, `dustjs-linkedin` will not be used by consolid | [velocityjs](https://github.com/julianshapiro/velocity) | [BETA](https://www.npmjs.com/package/velocity-animate) | [(website)](http://velocityjs.org/) | | [walrus](https://github.com/jeremyruppel/walrus) | [`npm install walrus`](https://www.npmjs.com/package/walrus) | [(website)](http://documentup.com/jeremyruppel/walrus/) | | [whiskers](https://github.com/gsf/whiskers.js) | [`npm install whiskers`](https://www.npmjs.com/package/whiskers) | - | -| [vue](https://github.com/vuejs/vue) | `npm install vue vue-pronto` | [(website)](https://vuejs.org/) | > **NOTE**: you must still install the engines you wish to use, add them to your package.json dependencies. diff --git a/packages/engines/src/components/MarkoEngine.ts b/packages/engines/src/components/MarkoEngine.ts deleted file mode 100644 index cf6379b7015..00000000000 --- a/packages/engines/src/components/MarkoEngine.ts +++ /dev/null @@ -1,28 +0,0 @@ -import {promisify} from "util"; -import {ViewEngine} from "../decorators/viewEngine"; -import {Engine, EngineOptions} from "./Engine"; - -@ViewEngine("marko") -export class MarkoEngine extends Engine { - $cacheOptions(template: string, options: any, fromFile: boolean): any { - options.writeToDisk = !!options.cache; - - if (!fromFile) { - options.filename = options.filename || "string.marko"; - } - - return options; - } - - $compileFile(file: string, options: EngineOptions) { - const $cmp = this.engine.load(file, options); - - return promisify($cmp.renderToString.bind($cmp)) as any; - } - - protected $compile(template: string, options: EngineOptions) { - const $cmp = this.engine.load(options.filename, template, options); - - return promisify($cmp.renderToString.bind($cmp)) as any; - } -} diff --git a/packages/engines/src/components/VueEngine.spec.ts b/packages/engines/src/components/VueEngine.spec.ts deleted file mode 100644 index 017a5fb93b4..00000000000 --- a/packages/engines/src/components/VueEngine.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import {expect} from "chai"; -import {getEngineFixture} from "../../test/getEngineFixture"; -import {VueEngine} from "./VueEngine"; - -describe("VueEngine", () => { - beforeEach(() => { - process.env.VUE_DEV = String(true); - }); - it("should render the given content (by string - no cache)", async () => { - const {render, $compile} = await getEngineFixture({token: VueEngine}); - await render(); - - expect(await render()).to.eq('

Tobi

'); - expect($compile()).to.have.been.callCount(2); - }); - it("should render the given content (by string - with cache)", async () => { - const {render, $compile} = await getEngineFixture({token: VueEngine, cache: true}); - await render(); - - expect(await render()).to.eq('

Tobi

'); - expect($compile()).to.have.been.callCount(1); - }); - it("should render the given content (by file - no cache)", async () => { - const {renderFile, $compileFile} = await getEngineFixture({token: VueEngine}); - await renderFile(); - const content = await renderFile(); - - expect(content).to.contains('

Tobi