Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Release 0.19.2 #785

Merged
merged 3 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="0.19.2"></a>
## [0.19.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.1...0.19.2) (2019-02-01)


### Bug Fixes

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



<a name="0.19.1"></a>
## [0.19.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.0...0.19.1) (2019-01-28)

Expand Down
39 changes: 29 additions & 10 deletions host/resolver.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
Expand All @@ -34,6 +53,6 @@ function toSystemPath(path: string) {

const drive = path.match(/^\\(\w)\\(.*)$/);
return drive ?
`${drive[1]}:\\${drive[2]}`:
`${drive[1]}:\\${drive[2]}` :
path;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-dev-webpack",
"version": "0.19.1",
"version": "0.19.2",
"main": "index",
"description": "",
"homepage": "http://www.telerik.com",
Expand Down