Skip to content

Commit

Permalink
dartservices - working on axios error: axios/axios#2968
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicwbaker committed Oct 29, 2020
1 parent 2cf3cb2 commit 21e3631
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 60 deletions.
21 changes: 21 additions & 0 deletions 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.
2 changes: 2 additions & 0 deletions packages/dartservices/README.md
Expand Up @@ -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)
18 changes: 11 additions & 7 deletions 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"

Expand All @@ -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<CompileDDCResponse> {
const res = await axios.post<CompileDDCResponse>("/compileDDC", <CompileRequest>{
const axios = require('axios');
axios.defaults.baseURL = DEFAULT_BASE_URL + API_PATH;
const res = await axios.post("/compileDDC", <CompileRequest>{
source: source,
})
return res.data
Expand All @@ -38,9 +38,13 @@ export async function compile(source: string): Promise<CompileResponse> {
* compiles and build decorated js
* @param source
*/
export async function compileComplete(source: string): Promise<string> {
export async function compileComplete(source: string): Promise<CompileResponse> {
const compiled = await compileDDC(source)
const complete = decorateJavascript(compiled.result, { modulesBaseUrl: compiled.modulesBaseUrl });
return complete;
return {
result: complete,
sourceMap: null,
error: null
};
}

5 changes: 3 additions & 2 deletions packages/dartservices/tests/compile.test.ts
@@ -1,4 +1,4 @@
import { compileComplete } from "../lib";
import { compileComplete } from "../dist";



Expand Down Expand Up @@ -147,11 +147,12 @@ class _SunflowerState extends State<Sunflower> {
`

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)
}
}

Expand Down
22 changes: 14 additions & 8 deletions 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"
]
}
43 changes: 0 additions & 43 deletions yarn.lock
Expand Up @@ -7,61 +7,18 @@
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"
integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==
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"
Expand Down

0 comments on commit 21e3631

Please sign in to comment.