From fb52c53e3da29dc1371d67e886c5fa22f44191e1 Mon Sep 17 00:00:00 2001 From: Ventsislav Georgiev Date: Wed, 30 Jan 2019 13:38:25 +0200 Subject: [PATCH 1/3] fix: optimize platform specific files resolver (#782) ## What is the current behavior? The platform specific files resolver for `.tns`, `.ios`, `.android` files is having performance issues on webpack and seems to break (make it run very slow like its for the first time) the incremental compilation. This is happening in big projects with many files in the `node_modules` directory, as the current implementation makes a file system call for each file. ## What is the new behavior? The resolver now handles only the files that are considered to support platform specific names e.g: * packages in `node_modules` with `nativescript`, `tns` or `ns` anywhere in the name * only files with following extensions: `[".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"]` --- host/resolver.ts | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/host/resolver.ts b/host/resolver.ts index 13e7cc04..30d8c7a0 100644 --- a/host/resolver.ts +++ b/host/resolver.ts @@ -1,23 +1,42 @@ -import { - parse, - join, -} from "path"; +import { parse, join } from "path"; import { statSync } from "fs"; -export function getResolver(platforms: string[]) { - return function(path: string) { +export function getResolver(platforms: string[], explicitResolve: string[] = []) { + const platformSpecificExt = [".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"]; + const nsPackageFilters = [ + 'nativescript', + 'tns', + 'ns' + ]; + + return function (path: string) { + const nmIndex = path.lastIndexOf('node_modules'); + + if (nmIndex !== -1) { + const subPath = path.substr(nmIndex + 'node_modules'.length).replace(/\\/g, '/'); + const shouldResolve = explicitResolve.length && explicitResolve.some(packageName => subPath.indexOf(packageName) !== -1); + const pathParts = subPath.split(/[/\-_]/); + + if (!shouldResolve && pathParts.every(p => nsPackageFilters.every(f => f !== p))) { + return path; + } + } + const { dir, name, ext } = parse(path); + if (platformSpecificExt.indexOf(ext) === -1) { + return 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()) { + if (statSync(platformPath)) { return platformPath; } - } catch(_e) { + } catch (_e) { // continue checking the other platforms } } @@ -34,6 +53,6 @@ function toSystemPath(path: string) { const drive = path.match(/^\\(\w)\\(.*)$/); return drive ? - `${drive[1]}:\\${drive[2]}`: + `${drive[1]}:\\${drive[2]}` : path; } From cada118720c70a2ec8cc9fc8b7da4e3f2508acce Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Fri, 1 Feb 2019 09:59:36 +0200 Subject: [PATCH 2/3] release: cut the 0.19.2 release --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d83646e9..9131d670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ + +## [0.19.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.0...0.19.2) (2019-02-01) + + +### Bug Fixes + +* **Vue:** apply style changes with HMR ([#763](https://github.com/NativeScript/nativescript-dev-webpack/issues/763)) ([#777](https://github.com/NativeScript/nativescript-dev-webpack/issues/777)) ([8ee1880](https://github.com/NativeScript/nativescript-dev-webpack/commit/8ee1880)), closes [#744](https://github.com/NativeScript/nativescript-dev-webpack/issues/744) [#742](https://github.com/NativeScript/nativescript-dev-webpack/issues/742) [#762](https://github.com/NativeScript/nativescript-dev-webpack/issues/762) +* optimize platform specific files resolver ([#782](https://github.com/NativeScript/nativescript-dev-webpack/issues/782)) ([fb52c53](https://github.com/NativeScript/nativescript-dev-webpack/commit/fb52c53)) + + + ## [0.19.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.0...0.19.1) (2019-01-28) diff --git a/package.json b/package.json index 5b311ee5..7496b3cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "0.19.1", + "version": "0.19.2", "main": "index", "description": "", "homepage": "http://www.telerik.com", From 6d9dc9e5b7c3f57ad77447377fa95881723154ef Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Fri, 1 Feb 2019 10:03:00 +0200 Subject: [PATCH 3/3] docs: update changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9131d670..cfdee7ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,9 @@ -## [0.19.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.0...0.19.2) (2019-02-01) +## [0.19.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.1...0.19.2) (2019-02-01) ### Bug Fixes -* **Vue:** apply style changes with HMR ([#763](https://github.com/NativeScript/nativescript-dev-webpack/issues/763)) ([#777](https://github.com/NativeScript/nativescript-dev-webpack/issues/777)) ([8ee1880](https://github.com/NativeScript/nativescript-dev-webpack/commit/8ee1880)), closes [#744](https://github.com/NativeScript/nativescript-dev-webpack/issues/744) [#742](https://github.com/NativeScript/nativescript-dev-webpack/issues/742) [#762](https://github.com/NativeScript/nativescript-dev-webpack/issues/762) * optimize platform specific files resolver ([#782](https://github.com/NativeScript/nativescript-dev-webpack/issues/782)) ([fb52c53](https://github.com/NativeScript/nativescript-dev-webpack/commit/fb52c53))