1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const path_1 = require("path");
|
4 | const fs_1 = require("fs");
|
5 | function getResolver(platforms, explicitResolve, nsPackageFilters, platformSpecificExt) {
|
6 | explicitResolve = explicitResolve || [];
|
7 | nsPackageFilters = nsPackageFilters || ['nativescript', 'tns', 'ns'];
|
8 | platformSpecificExt = platformSpecificExt || [".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"];
|
9 | return function (path) {
|
10 | const nmIndex = path.lastIndexOf('node_modules');
|
11 | if (nmIndex !== -1) {
|
12 | const subPath = path.substr(nmIndex + 'node_modules'.length).replace(/\\/g, '/');
|
13 | const shouldResolve = explicitResolve.length && explicitResolve.some(packageName => subPath.indexOf(packageName) !== -1);
|
14 | const pathParts = subPath.split(/[/\-_]/);
|
15 | if (!shouldResolve && pathParts.every(p => nsPackageFilters.every(f => f !== p))) {
|
16 | return path;
|
17 | }
|
18 | }
|
19 | const { dir, name, ext } = path_1.parse(path);
|
20 | if (platformSpecificExt.indexOf(ext) === -1) {
|
21 | return path;
|
22 | }
|
23 | for (const platform of platforms) {
|
24 | const platformFileName = `${name}.${platform}${ext}`;
|
25 | const platformPath = toSystemPath(path_1.join(dir, platformFileName));
|
26 | try {
|
27 | if (fs_1.statSync(platformPath)) {
|
28 | return platformPath;
|
29 | }
|
30 | }
|
31 | catch (_e) {
|
32 |
|
33 | }
|
34 | }
|
35 | return path;
|
36 | };
|
37 | }
|
38 | exports.getResolver = getResolver;
|
39 |
|
40 | function toSystemPath(path) {
|
41 | if (!process.platform.startsWith("win32")) {
|
42 | return path;
|
43 | }
|
44 | const drive = path.match(/^\\(\w)\\(.*)$/);
|
45 | return drive ?
|
46 | `${drive[1]}:\\${drive[2]}` :
|
47 | path;
|
48 | }
|
49 |
|
\ | No newline at end of file |