From 6702b57af072d3fb55cf97a97c8442ba3210c9be Mon Sep 17 00:00:00 2001 From: softmarshmallow Date: Thu, 29 Oct 2020 14:56:18 +0900 Subject: [PATCH] dartservices - working on axios error: https://github.com/axios/axios/issues/2968 --- packages/dartservices/LICENSE | 21 ++++++++++ packages/dartservices/README.md | 2 + packages/dartservices/lib/index.ts | 18 +++++---- packages/dartservices/tests/compile.test.ts | 5 ++- packages/dartservices/tsconfig.json | 22 +++++++---- yarn.lock | 43 --------------------- 6 files changed, 51 insertions(+), 60 deletions(-) create mode 100644 packages/dartservices/LICENSE diff --git a/packages/dartservices/LICENSE b/packages/dartservices/LICENSE new file mode 100644 index 0000000..daf328a --- /dev/null +++ b/packages/dartservices/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Bridged + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/dartservices/README.md b/packages/dartservices/README.md index 58fed09..18a501d 100644 --- a/packages/dartservices/README.md +++ b/packages/dartservices/README.md @@ -2,6 +2,8 @@ > This is a ts wrapper for aclling dartservies api, which remotely compiles dart code to js - executable for flutter +Use with your own obligation. Dartservices is + ## References - [dart-pad](https://github.com/dart-lang/dart-pad) - [dart-services](https://github.com/dart-lang/dart-services) \ No newline at end of file diff --git a/packages/dartservices/lib/index.ts b/packages/dartservices/lib/index.ts index ab1e6b9..1087c64 100644 --- a/packages/dartservices/lib/index.ts +++ b/packages/dartservices/lib/index.ts @@ -1,4 +1,4 @@ -import Axios from "axios" +import axios from "axios" import { CompileDDCResponse, CompileRequest, CompileResponse, } from "./types" import { decorateJavascript } from "./utils/deocrate-js" @@ -8,16 +8,16 @@ const BASE_URLS = [ ] const API_PATH = "api/dartservices/v2" -const axios = Axios.create({ - baseURL: DEFAULT_BASE_URL + API_PATH -}) +axios.defaults.baseURL = DEFAULT_BASE_URL + API_PATH; /** * use this for flutter code compile * @param source */ export async function compileDDC(source: string): Promise { - const res = await axios.post("/compileDDC", { + const axios = require('axios'); + axios.defaults.baseURL = DEFAULT_BASE_URL + API_PATH; + const res = await axios.post("/compileDDC", { source: source, }) return res.data @@ -38,9 +38,13 @@ export async function compile(source: string): Promise { * compiles and build decorated js * @param source */ -export async function compileComplete(source: string): Promise { +export async function compileComplete(source: string): Promise { const compiled = await compileDDC(source) const complete = decorateJavascript(compiled.result, { modulesBaseUrl: compiled.modulesBaseUrl }); - return complete; + return { + result: complete, + sourceMap: null, + error: null + }; } diff --git a/packages/dartservices/tests/compile.test.ts b/packages/dartservices/tests/compile.test.ts index c43ce5b..b1daade 100644 --- a/packages/dartservices/tests/compile.test.ts +++ b/packages/dartservices/tests/compile.test.ts @@ -1,4 +1,4 @@ -import { compileComplete } from "../lib"; +import { compileComplete } from "../dist"; @@ -147,11 +147,12 @@ class _SunflowerState extends State { ` async function test() { + console.log('start testing') try { const js = await compileComplete(EX_DART_SOURCE) console.log(js) } catch (e) { - console.error(e.response) + console.error(e) } } diff --git a/packages/dartservices/tsconfig.json b/packages/dartservices/tsconfig.json index a9fb02c..46ba0bc 100644 --- a/packages/dartservices/tsconfig.json +++ b/packages/dartservices/tsconfig.json @@ -1,19 +1,25 @@ { "compilerOptions": { + "target": "ES2016", "module": "commonjs", + "lib": [ + "es2017", + "es7", + "es6", + "dom" + ], + "outDir": "dist", "declaration": true, - "removeComments": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, "allowSyntheticDefaultImports": true, - "target": "es2017", + "esModuleInterop": true, "sourceMap": true, - "outDir": "./dist", - "incremental": true + "experimentalDecorators": true, + "noUnusedLocals": false, }, "exclude": [ + "node_modules", + "dist", "example", - "tests", - "dist" + "tests" ] } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f02559a..dde8d3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,16 +7,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.5.tgz#e92d3b8f76583efa26c1a63a21c9d3c1143daa29" integrity sha512-H5Wn24s/ZOukBmDn03nnGTp18A60ny9AmCwnEcgJiTgSGsCO7k+NWP7zjCCbhlcnVCoI+co52dUAt9GMhOSULw== -"@types/node@^14.14.6": - version "14.14.6" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f" - integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw== - -asynckit@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" - integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= - axios@^0.21.0: version "0.21.0" resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca" @@ -24,44 +14,11 @@ axios@^0.21.0: dependencies: follow-redirects "^1.10.0" -combined-stream@^1.0.8: - version "1.0.8" - resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" - integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== - dependencies: - delayed-stream "~1.0.0" - -delayed-stream@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" - integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= - follow-redirects@^1.10.0: version "1.13.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db" integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA== -form-data@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682" - integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg== - dependencies: - asynckit "^0.4.0" - combined-stream "^1.0.8" - mime-types "^2.1.12" - -mime-db@1.44.0: - version "1.44.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92" - integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg== - -mime-types@^2.1.12: - version "2.1.27" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f" - integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w== - dependencies: - mime-db "1.44.0" - typescript@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"