diff --git a/.gitignore b/.gitignore index 251f193f..fcbafce7 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,9 @@ plugins/WatchStateLoggerPlugin.d.ts plugins/WatchStateLoggerPlugin.js plugins/WatchStateLoggerPlugin.js.map -host/platform.d.ts -host/platform.js -host/platform.js.map +host/resolver.d.ts +host/resolver.js +host/resolver.js.map hooks .DS_Store diff --git a/.npmignore b/.npmignore index d4915faa..a6d37dc4 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,6 @@ -prepublish -demo \ No newline at end of file +build +demo + +*.ts +!*.d.ts + diff --git a/demo/AngularApp/package.json b/demo/AngularApp/package.json index 9c8ac61b..386a7288 100644 --- a/demo/AngularApp/package.json +++ b/demo/AngularApp/package.json @@ -13,14 +13,14 @@ } }, "dependencies": { - "@angular/common": "~6.1.0-beta.3", - "@angular/compiler": "~6.1.0-beta.3", - "@angular/core": "~6.1.0-beta.3", - "@angular/forms": "~6.1.0-beta.3", - "@angular/http": "~6.1.0-beta.3", - "@angular/platform-browser": "~6.1.0-beta.3", - "@angular/platform-browser-dynamic": "~6.1.0-beta.3", - "@angular/router": "~6.1.0-beta.3", + "@angular/common": "~6.1.0-rc.0", + "@angular/compiler": "~6.1.0-rc.0", + "@angular/core": "~6.1.0-rc.0", + "@angular/forms": "~6.1.0-rc.0", + "@angular/http": "~6.1.0-rc.0", + "@angular/platform-browser": "~6.1.0-rc.0", + "@angular/platform-browser-dynamic": "~6.1.0-rc.0", + "@angular/router": "~6.1.0-rc.0", "nativescript-angular": "next", "nativescript-theme-core": "~1.0.2", "reflect-metadata": "~0.1.8", @@ -29,8 +29,8 @@ "zone.js": "^0.8.26" }, "devDependencies": { - "@angular/compiler-cli": "~6.1.0-beta.3", - "@ngtools/webpack": "6.1.0-rc.0", + "@angular/compiler-cli": "~6.1.0-rc.0", + "@ngtools/webpack": "~6.1.0-rc.3", "@types/chai": "^4.0.2", "@types/mocha": "^2.2.41", "@types/node": "^7.0.5", diff --git a/demo/AngularApp/webpack.config.js b/demo/AngularApp/webpack.config.js index 04731f1a..6f96e0e7 100644 --- a/demo/AngularApp/webpack.config.js +++ b/demo/AngularApp/webpack.config.js @@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path"); const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform"); const CleanWebpackPlugin = require("clean-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); @@ -24,9 +23,6 @@ module.exports = env => { throw new Error("You need to provide a target platform!"); } - const extensions = ["tns", platform]; - const platformHost = new PlatformReplacementHost(extensions); - const projectRoot = __dirname; // Default destination inside platforms//... @@ -227,7 +223,7 @@ module.exports = env => { new NativeScriptWorkerPlugin(), new AngularCompilerPlugin({ - host: platformHost, + hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]), entryModule: resolve(appPath, "app.module#AppModule"), tsConfigPath: join(__dirname, "tsconfig.esm.json"), skipCodeGeneration: !aot, diff --git a/host/platform.ts b/host/platform.ts deleted file mode 100644 index 9af7eeb7..00000000 --- a/host/platform.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { - parse, - join, -} from "path"; -import { statSync } from "fs"; - -import { Observable } from "rxjs"; -import { - Path, - PathFragment, -} from "@angular-devkit/core"; -import { - FileBuffer, - Host, - HostCapabilities, - HostWatchOptions, - HostWatchEvent, - Stats, -} from "@angular-devkit/core/src/virtual-fs/host"; -const { NodeJsSyncHost } = require("@angular-devkit/core/node"); - - -export class PlatformReplacementHost implements Host { - constructor(protected _platforms: string[], protected _delegate = new NodeJsSyncHost()) { - } - - protected _resolve(path) { - const { dir, name, ext } = parse(path); - - for (const platform of this._platforms) { - const platformFileName = `${name}.${platform}${ext}`; - const platformPath = this.toSystemPath(join(dir, platformFileName)); - - try { - const stat = statSync(platformPath); - if (stat && stat.isFile()) { - return platformPath; - } - } catch(_e) { - // continue checking the other platforms - } - } - - return path; - } - - // Convert paths from \c\some\path to c:\some\path - private toSystemPath(path: string) { - if (!process.platform.startsWith("win32")) { - return path; - } - - const drive = path.match(/^\\(\w)\\(.*)$/); - return drive ? - `${drive[1]}:\\${drive[2]}`: - path; - } - - get capabilities(): HostCapabilities { - return this._delegate.capabilities; - } - - write(path: Path, content: FileBuffer): Observable { - return this._delegate.write(this._resolve(path), content); - } - read(path: Path): Observable { - return this._delegate.read(this._resolve(path)); - } - delete(path: Path): Observable { - return this._delegate.delete(this._resolve(path)); - } - rename(from: Path, to: Path): Observable { - return this._delegate.rename(this._resolve(from), this._resolve(to)); - } - - list(path: Path): Observable { - return this._delegate.list(this._resolve(path)); - } - - exists(path: Path): Observable { - return this._delegate.exists(this._resolve(path)); - } - isDirectory(path: Path): Observable { - return this._delegate.isDirectory(this._resolve(path)); - } - isFile(path: Path): Observable { - return this._delegate.isFile(this._resolve(path)); - } - - stat(path: Path): Observable> | null { - return this._delegate.stat(this._resolve(path)); - } - - watch(path: Path, options?: HostWatchOptions): Observable | null { - return this._delegate.watch(this._resolve(path), options); - } -} diff --git a/host/resolver.ts b/host/resolver.ts new file mode 100644 index 00000000..13e7cc04 --- /dev/null +++ b/host/resolver.ts @@ -0,0 +1,39 @@ +import { + parse, + join, +} from "path"; +import { statSync } from "fs"; + +export function getResolver(platforms: string[]) { + return function(path: string) { + const { dir, name, ext } = parse(path); + + for (const platform of platforms) { + const platformFileName = `${name}.${platform}${ext}`; + const platformPath = toSystemPath(join(dir, platformFileName)); + + try { + const stat = statSync(platformPath); + if (stat && stat.isFile()) { + return platformPath; + } + } catch(_e) { + // continue checking the other platforms + } + } + + return path; + } +} + +// Convert paths from \c\some\path to c:\some\path +function toSystemPath(path: string) { + if (!process.platform.startsWith("win32")) { + return path; + } + + const drive = path.match(/^\\(\w)\\(.*)$/); + return drive ? + `${drive[1]}:\\${drive[2]}`: + path; +} diff --git a/index.js b/index.js index 17657000..363658eb 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ const { } = require("./projectHelpers"); Object.assign(exports, require('./plugins')); +Object.assign(exports, require('./host/resolver')); exports.getAotEntryModule = function (appDirectory) { verifyEntryModuleDirectory(appDirectory); diff --git a/package.json b/package.json index df168c31..7c7dbe63 100644 --- a/package.json +++ b/package.json @@ -92,11 +92,8 @@ "sass-loader": "~7.0.1" }, "devDependencies": { - "@angular-devkit/core": "^0.7.0-rc.0", "@types/node": "^8.0.0", "conventional-changelog-cli": "^1.3.22", - "rxjs": "^6.2.0", - "source-map-support": "^0.5.0", "typescript": "~2.7.2" } } diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index 2a594d42..895ce298 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path"); const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform"); const CleanWebpackPlugin = require("clean-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); @@ -23,9 +22,6 @@ module.exports = env => { throw new Error("You need to provide a target platform!"); } - const extensions = ["tns", platform]; - const platformHost = new PlatformReplacementHost(extensions); - const projectRoot = __dirname; // Default destination inside platforms//... @@ -226,7 +222,7 @@ module.exports = env => { new NativeScriptWorkerPlugin(), new AngularCompilerPlugin({ - host: platformHost, + hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]), entryModule: resolve(appPath, "app.module#AppModule"), tsConfigPath: join(__dirname, "tsconfig.esm.json"), skipCodeGeneration: !aot, diff --git a/tsconfig.json b/tsconfig.json index fe233eaf..1c2aac63 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,6 @@ "files": [ "plugins/PlatformFSPlugin.ts", "plugins/WatchStateLoggerPlugin.ts", - "host/platform.ts" + "host/resolver.ts" ] }