diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts
index d935e4e..a0db838 100644
--- a/demo/app/main-page.ts
+++ b/demo/app/main-page.ts
@@ -1,14 +1,12 @@
import * as Https from "nativescript-https";
-import * as Observable from "@nativescript/core/data/observable";
+import {fromObject, Dialogs as dialogs, Page, EventData} from "@nativescript/core";
import * as fs from "@nativescript/core/file-system";
-import * as dialogs from "@nativescript/core/ui/dialogs";
-import * as Page from "@nativescript/core/ui/page";
let page;
let viewModel;
-export function pageLoaded(args: Page.NavigatedData) {
- page = args.object as Page.Page;
- viewModel = Observable.fromObject({
+export function pageLoaded(args: EventData) {
+ page = args.object as Page;
+ viewModel = fromObject({
enabled: false,
progress: 0,
currentRequest: null,
@@ -141,7 +139,7 @@ export function get404() {
getRequest("https://mockbin.com/reque2st");
}
-export function enableSSLPinning(args: Observable.EventData) {
+export function enableSSLPinning(args: EventData) {
let dir = fs.knownFolders.currentApp().getFolder("assets");
let certificate = dir.getFile("httpbin.org.cer").path;
Https.enableSSLPinning({
@@ -152,14 +150,14 @@ export function enableSSLPinning(args: Observable.EventData) {
console.log("enabled");
}
-export function enableSSLPinningExpired(args: Observable.EventData) {
+export function enableSSLPinningExpired(args: EventData) {
let dir = fs.knownFolders.currentApp().getFolder("assets");
let certificate = dir.getFile("httpbin.org.expired.cer").path;
Https.enableSSLPinning({ host: "httpbin.org", certificate });
console.log("enabled");
}
-export function disableSSLPinning(args: Observable.EventData) {
+export function disableSSLPinning(args: EventData) {
Https.disableSSLPinning();
console.log("disabled");
}
diff --git a/demo/app/package.json b/demo/app/package.json
deleted file mode 100644
index 7ed188b..0000000
--- a/demo/app/package.json
+++ /dev/null
@@ -1,112 +0,0 @@
-{
- "name": "tns-template-hello-world-ts",
- "main": "app.js",
- "version": "1.6.0",
- "author": {
- "name": "Telerik",
- "email": "support@telerik.com"
- },
- "description": "Nativescript hello-world-ts project template",
- "license": "Apache-2.0",
- "keywords": [
- "telerik",
- "mobile",
- "nativescript",
- "{N}",
- "tns",
- "appbuilder",
- "template"
- ],
- "repository": {
- "type": "git",
- "url": "git+ssh://git@github.com/NativeScript/template-hello-world-ts.git"
- },
- "bugs": {
- "url": "https://github.com/NativeScript/template-hello-world-ts/issues"
- },
- "homepage": "https://github.com/NativeScript/template-hello-world-ts",
- "android": {
- "v8Flags": "--expose_gc",
- "requireModules": [
- "nativescript-https"
- ],
- "markingMode": "none"
- },
- "devDependencies": {
- "nativescript-dev-typescript": "^0.3.0"
- },
- "_id": "tns-template-hello-world-ts@1.6.0",
- "_shasum": "a567c2b9a56024818c06596dab9629d155c5b8a8",
- "_resolved": "https://registry.npmjs.org/tns-template-hello-world-ts/-/tns-template-hello-world-ts-1.6.0.tgz",
- "_from": "tns-template-hello-world-ts@latest",
- "scripts": {
- "build.plugin": "cd ../src && npm run build",
- "ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'"
- },
- "_npmVersion": "2.14.7",
- "_nodeVersion": "4.2.2",
- "_npmUser": {
- "name": "enchev",
- "email": "vladimir.enchev@gmail.com"
- },
- "dist": {
- "shasum": "a567c2b9a56024818c06596dab9629d155c5b8a8",
- "tarball": "http://registry.npmjs.org/tns-template-hello-world-ts/-/tns-template-hello-world-ts-1.6.0.tgz"
- },
- "maintainers": [
- {
- "name": "enchev",
- "email": "vladimir.enchev@gmail.com"
- },
- {
- "name": "erjangavalji",
- "email": "erjan.gavalji@gmail.com"
- },
- {
- "name": "fatme",
- "email": "hfatme@gmail.com"
- },
- {
- "name": "hdeshev",
- "email": "hristo@deshev.com"
- },
- {
- "name": "kerezov",
- "email": "d.kerezov@gmail.com"
- },
- {
- "name": "ligaz",
- "email": "stefan.dobrev@gmail.com"
- },
- {
- "name": "nsndeck",
- "email": "nedyalko.nikolov@telerik.com"
- },
- {
- "name": "rosen-vladimirov",
- "email": "rosen.vladimirov.91@gmail.com"
- },
- {
- "name": "sdobrev",
- "email": "stefan.dobrev@gmail.com"
- },
- {
- "name": "tailsu",
- "email": "tailsu@gmail.com"
- },
- {
- "name": "teobugslayer",
- "email": "teobugslayer@gmail.com"
- },
- {
- "name": "valio.stoychev",
- "email": "valio.stoychev@gmail.com"
- }
- ],
- "_npmOperationalInternal": {
- "host": "packages-5-east.internal.npmjs.com",
- "tmp": "tmp/tns-template-hello-world-ts-1.6.0.tgz_1455717516189_0.6427943941671401"
- },
- "directories": {},
- "readme": "ERROR: No README data found!"
-}
diff --git a/demo/nativescript.config.ts b/demo/nativescript.config.ts
new file mode 100644
index 0000000..8af2c0a
--- /dev/null
+++ b/demo/nativescript.config.ts
@@ -0,0 +1,14 @@
+import { NativeScriptConfig } from '@nativescript/core'
+
+export default {
+ id: 'org.nativescript.plugindemo.https',
+ appResourcesPath: 'app/App_Resources',
+ android: {
+ v8Flags: '--expose_gc',
+ markingMode: 'none',
+ requireModules: {
+ 0: 'nativescript-https',
+ },
+ },
+ appPath: 'app',
+} as NativeScriptConfig
diff --git a/demo/package.json b/demo/package.json
index 890d788..379d894 100644
--- a/demo/package.json
+++ b/demo/package.json
@@ -1,28 +1,22 @@
{
- "nativescript": {
- "id": "org.nativescript.plugindemo.https",
- "tns-android": {
- "version": "6.4.1"
- },
- "tns-ios": {
- "version": "7.0.0-beta.3-v8-2020-03-21-010353-01"
- }
- },
"dependencies": {
"nativescript-https": "file:../src",
"nativescript-theme-core": "^1.0.4",
"nativescript-unit-test-runner": "0.7.0",
- "@nativescript/core": "~6.4.0"
+ "@nativescript/core": "7.0.10"
},
"devDependencies": {
+ "@nativescript/android": "7.0.0",
+ "@nativescript/ios": "7.0.1",
+ "@nativescript/types": "7.0.0",
+ "@nativescript/webpack": "3.0.0",
"nativescript-css-loader": "~0.26.1",
- "nativescript-dev-webpack": "~1.5.0",
- "tns-platform-declarations": "~6.4.0",
"tslint": "~5.11.0",
- "typescript": "3.4.5"
+ "typescript": "3.9.7"
},
"scripts": {
"build.plugin": "cd ../src && npm run build",
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'"
- }
+ },
+ "main": "app.js"
}
diff --git a/demo/references.d.ts b/demo/references.d.ts
index 680f3ef..4764a10 100644
--- a/demo/references.d.ts
+++ b/demo/references.d.ts
@@ -1,2 +1 @@
-///
-///
+///
\ No newline at end of file
diff --git a/demo/tsconfig.json b/demo/tsconfig.json
index cbdc960..6f16f6f 100644
--- a/demo/tsconfig.json
+++ b/demo/tsconfig.json
@@ -1,15 +1,16 @@
{
"compilerOptions": {
- "target": "es5",
- "module": "commonjs",
+ "target": "es2017",
+ "module": "esnext",
"declaration": false,
- "removeComments": true,
+ "removeComments": false,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
- "dom"
+ "dom",
+ "es2017"
],
"pretty": true,
"allowUnreachableCode": false,
@@ -28,7 +29,8 @@
"~/*": [
"app/*"
]
- }
+ },
+ "moduleResolution": "node"
},
"include": [
"**/*"
diff --git a/demo/tsconfig.tns.json b/demo/tsconfig.tns.json
deleted file mode 100644
index 95f2ece..0000000
--- a/demo/tsconfig.tns.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "extends": "./tsconfig",
- "compilerOptions": {
- "module": "es2015",
- "moduleResolution": "node"
- }
-}
diff --git a/demo/webpack.config.js b/demo/webpack.config.js
index 35c4fe6..bde3a35 100644
--- a/demo/webpack.config.js
+++ b/demo/webpack.config.js
@@ -1,10 +1,11 @@
const { join, relative, resolve, sep } = require("path");
+const fs = require('fs');
const webpack = require("webpack");
-const nsWebpack = require("nativescript-dev-webpack");
-const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
-const { getNoEmitOnErrorFromTSConfig } = require("nativescript-dev-webpack/utils/tsconfig-utils");
-const CleanWebpackPlugin = require("clean-webpack-plugin");
+const nsWebpack = require("@nativescript/webpack");
+const nativescriptTarget = require("@nativescript/webpack/nativescript-target");
+const { getNoEmitOnErrorFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils");
+const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
@@ -16,8 +17,8 @@ module.exports = env => {
// Add your custom Activities, Services and other Android app components here.
const appComponents = env.appComponents || [];
appComponents.push(...[
- "tns-core-modules/ui/frame",
- "tns-core-modules/ui/frame/activity",
+ "@nativescript/core/ui/frame",
+ "@nativescript/core/ui/frame/activity",
]);
const platform = env && (env.android && "android" || env.ios && "ios" || env.platform);
@@ -38,8 +39,8 @@ module.exports = env => {
const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
- appPath = "app",
- appResourcesPath = "app/App_Resources",
+ appPath = "src",
+ appResourcesPath = "App_Resources",
// You can provide the following flags when running 'tns run android|ios'
snapshot, // --env.snapshot
@@ -50,6 +51,7 @@ module.exports = env => {
hiddenSourceMap, // --env.hiddenSourceMap
hmr, // --env.hmr,
unitTesting, // --env.unitTesting,
+ testing, // --env.testing
verbose, // --env.verbose
snapshotInDocker, // --env.snapshotInDocker
skipSnapshotTools, // --env.skipSnapshotTools
@@ -60,10 +62,15 @@ module.exports = env => {
const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap;
const externals = nsWebpack.getConvertedExternals(env.externals);
- const appFullPath = resolve(projectRoot, appPath);
+ let appFullPath = resolve(projectRoot, appPath);
+ if (!fs.existsSync(appFullPath)) {
+ // some apps use 'app' directory
+ appFullPath = resolve(projectRoot, 'app');
+ }
const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot });
let coreModulesPackageName = "tns-core-modules";
const alias = env.alias || {};
+ alias['~/package.json'] = resolve(projectRoot, 'package.json');
alias['~'] = appFullPath;
if (hasRootLevelScopedModules) {
@@ -72,16 +79,18 @@ module.exports = env => {
}
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
+ const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] };
+
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
const entryPath = `.${sep}${entryModule}.ts`;
const entries = env.entries || {};
entries.bundle = entryPath;
- const tsConfigPath = resolve(projectRoot, "tsconfig.tns.json");
+ const tsConfigPath = resolve(projectRoot, "tsconfig.json");
- const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("tns-core-modules") > -1);
- if (platform === "ios" && !areCoreModulesExternal) {
- entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules";
+ const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1);
+ if (platform === "ios" && !areCoreModulesExternal && !testing) {
+ entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules";
};
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
@@ -119,7 +128,7 @@ module.exports = env => {
},
resolve: {
extensions: [".ts", ".js", ".scss", ".css"],
- // Resolve {N} system modules from tns-core-modules
+ // Resolve {N} system modules from @nativescript/core
modules: [
resolve(__dirname, `node_modules/${coreModulesPackageName}`),
resolve(__dirname, "node_modules"),
@@ -189,12 +198,12 @@ module.exports = env => {
use: [
// Require all Android app components
platform === "android" && {
- loader: "nativescript-dev-webpack/android-app-components-loader",
+ loader: "@nativescript/webpack/helpers/android-app-components-loader",
options: { modules: appComponents }
},
{
- loader: "nativescript-dev-webpack/bundle-config-loader",
+ loader: "@nativescript/webpack/bundle-config-loader",
options: {
loadCss: !snapshot, // load the application css if in debug mode
unitTesting,
@@ -208,20 +217,20 @@ module.exports = env => {
{
test: /\.(ts|css|scss|html|xml)$/,
- use: "nativescript-dev-webpack/hmr/hot-loader"
+ use: "@nativescript/webpack/hmr/hot-loader"
},
- { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },
+ { test: /\.(html|xml)$/, use: "@nativescript/webpack/helpers/xml-namespace-loader" },
{
test: /\.css$/,
- use: "nativescript-dev-webpack/css2json-loader"
+ use: "@nativescript/webpack/helpers/css2json-loader"
},
{
test: /\.scss$/,
use: [
- "nativescript-dev-webpack/css2json-loader",
+ "@nativescript/webpack/helpers/css2json-loader",
"sass-loader"
]
},
@@ -239,7 +248,12 @@ module.exports = env => {
compilerOptions: {
sourceMap: isAnySourceMapEnabled,
declaration: false
- }
+ },
+ getCustomTransformers: (program) => ({
+ before: [
+ require("@nativescript/webpack/transformers/ns-transform-native-classes").default
+ ]
+ })
},
}
},
@@ -249,16 +263,24 @@ module.exports = env => {
// Define useful constants like TNS_WEBPACK
new webpack.DefinePlugin({
"global.TNS_WEBPACK": "true",
+ "global.isAndroid": platform === 'android',
+ "global.isIOS": platform === 'ios',
"process": "global.process",
}),
// Remove all files from the out dir.
- new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }),
- // Copy assets to out dir. Add your own globs as needed.
- new CopyWebpackPlugin([
- { from: { glob: "fonts/**" } },
- { from: { glob: "**/*.jpg" } },
- { from: { glob: "**/*.png" } },
- ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
+ new CleanWebpackPlugin({
+ cleanOnceBeforeBuildPatterns: itemsToClean,
+ verbose: !!verbose
+ }),
+ // Copy assets
+ new CopyWebpackPlugin({
+ patterns: [
+ { from: 'assets/**', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } },
+ { from: 'fonts/**', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } },
+ { from: '**/*.jpg', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } },
+ { from: '**/*.png', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } },
+ ],
+ }),
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
// For instructions on how to set up workers with webpack
// check out https://github.com/nativescript/worker-loader
@@ -272,11 +294,15 @@ module.exports = env => {
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
// https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement
new ForkTsCheckerWebpackPlugin({
- tsconfig: tsConfigPath,
- async: false,
- useTypescriptIncrementalApi: true,
- checkSyntacticErrors: true,
- memoryLimit: 4096
+ async: false,
+ typescript: {
+ configFile: tsConfigPath,
+ memoryLimit: 4096,
+ diagnosticOptions: {
+ syntactic: true,
+ semantic: true
+ }
+ }
})
],
};
@@ -296,7 +322,7 @@ module.exports = env => {
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
chunk: "vendor",
requireModules: [
- "tns-core-modules/bundle-entry-points",
+ "@nativescript/core/bundle-entry-points",
],
projectRoot,
webpackConfig: config,
@@ -310,6 +336,5 @@ module.exports = env => {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
-
return config;
};
diff --git a/src/https.android.ts b/src/https.android.ts
index d9b2a10..c80ae99 100644
--- a/src/https.android.ts
+++ b/src/https.android.ts
@@ -598,8 +598,8 @@ export function createRequest(
});
} else {
resolve({
- response,
- content: responseBody.string(),
+ response: response,
+ content: JSON.parse(responseBody.string()),
reason: message,
statusCode,
get headers() {
diff --git a/src/https.common.d.ts b/src/https.common.d.ts
index 2b15db7..e70652d 100644
--- a/src/https.common.d.ts
+++ b/src/https.common.d.ts
@@ -42,6 +42,7 @@ export interface HttpsResponse {
description?: string;
url?: string;
failure?: any;
+ response?: any;
}
export interface HttpsRequest {
nativeRequest: any;
diff --git a/src/https.common.ts b/src/https.common.ts
index 8796174..e90cd0c 100644
--- a/src/https.common.ts
+++ b/src/https.common.ts
@@ -67,6 +67,7 @@ export interface HttpsResponse {
description?: string;
url?: string;
failure?: any;
+ response?: any;
}
export interface HttpsRequest {
diff --git a/src/https.ios.ts b/src/https.ios.ts
index f806050..7718f5c 100644
--- a/src/https.ios.ts
+++ b/src/https.ios.ts
@@ -343,7 +343,7 @@ class HttpsResponse implements Https.HttpsResponseLegacy {
// useLegacy: boolean,
// data?: NSDictionary & NSData & NSArray
// ) {
-// let content = useLegacy ? new HttpsResponse(data, url) : getData(data);
+// let content = useLegacy ? newz& HttpsResponse(data, url) : getData(data);
// resolve({ task, content });
// }
@@ -409,7 +409,7 @@ function AFFailure(
sendi.content = new HttpsResponse(data, url);
resolve(sendi);
} else {
- let content: any = {
+ let response: any = {
body: parsedData,
description: error.description,
reason: error.localizedDescription,
@@ -417,11 +417,12 @@ function AFFailure(
};
if (policies.secured === true) {
- content.description =
+ response.description =
"nativescript-https > Invalid SSL certificate! " +
- content.description;
+ response.description;
}
- sendi.content = content;
+ sendi.content = parsedData;
+ sendi.response = response;
resolve(sendi);
}