@nativescript/vite 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/configuration/angular.d.ts +4 -0
  2. package/dist/configuration/angular.js +30 -0
  3. package/dist/configuration/base.d.ts +13 -0
  4. package/dist/configuration/base.js +228 -0
  5. package/dist/configuration/old-without-merge-base.d.ts +13 -0
  6. package/dist/configuration/old-without-merge-base.js +249 -0
  7. package/dist/configuration/react.d.ts +4 -0
  8. package/dist/configuration/react.js +85 -0
  9. package/dist/configuration/solid.d.ts +4 -0
  10. package/dist/configuration/solid.js +48 -0
  11. package/dist/configuration/vue.d.ts +4 -0
  12. package/dist/configuration/vue.js +45 -0
  13. package/dist/helpers/commonjs-plugins.d.ts +6 -0
  14. package/dist/helpers/commonjs-plugins.js +75 -0
  15. package/dist/helpers/config-as-json.d.ts +2 -0
  16. package/dist/helpers/config-as-json.js +35 -0
  17. package/dist/helpers/css-tree.d.ts +4 -0
  18. package/dist/helpers/css-tree.js +21 -0
  19. package/dist/helpers/dynamic-import-plugin.d.ts +4 -0
  20. package/dist/helpers/dynamic-import-plugin.js +62 -0
  21. package/dist/helpers/flavor.d.ts +5 -0
  22. package/dist/helpers/flavor.js +40 -0
  23. package/dist/helpers/global-defines.d.ts +14 -0
  24. package/dist/helpers/global-defines.js +18 -0
  25. package/dist/helpers/main-entry.d.ts +5 -0
  26. package/dist/helpers/main-entry.js +75 -0
  27. package/dist/helpers/module-resolution.d.ts +1 -0
  28. package/dist/helpers/module-resolution.js +17 -0
  29. package/dist/helpers/nativescript-package-resolver.d.ts +5 -0
  30. package/dist/helpers/nativescript-package-resolver.js +139 -0
  31. package/dist/helpers/ns-cli-plugins.d.ts +17 -0
  32. package/dist/helpers/ns-cli-plugins.js +128 -0
  33. package/dist/helpers/package-platform-aliases.d.ts +4 -0
  34. package/dist/helpers/package-platform-aliases.js +83 -0
  35. package/dist/helpers/project.d.ts +23 -0
  36. package/dist/helpers/project.js +28 -0
  37. package/dist/helpers/resolver.d.ts +4 -0
  38. package/dist/helpers/resolver.js +31 -0
  39. package/dist/helpers/ts-config-paths.d.ts +4 -0
  40. package/dist/helpers/ts-config-paths.js +241 -0
  41. package/dist/helpers/utils.d.ts +23 -0
  42. package/dist/helpers/utils.js +94 -0
  43. package/dist/helpers/workers.d.ts +20 -0
  44. package/dist/helpers/workers.js +86 -0
  45. package/dist/hmr/hmr-angular.d.ts +1 -0
  46. package/dist/hmr/hmr-angular.js +34 -0
  47. package/dist/hmr/hmr-bridge.d.ts +18 -0
  48. package/dist/hmr/hmr-bridge.js +154 -0
  49. package/dist/hmr/hmr-client.d.ts +5 -0
  50. package/dist/hmr/hmr-client.js +93 -0
  51. package/dist/hmr/hmr-server.d.ts +20 -0
  52. package/dist/hmr/hmr-server.js +179 -0
  53. package/dist/index.d.ts +5 -0
  54. package/dist/index.js +5 -0
  55. package/dist/polyfills/mdn-data-at-rules.d.ts +7 -0
  56. package/dist/polyfills/mdn-data-at-rules.js +7 -0
  57. package/dist/polyfills/mdn-data-properties.d.ts +7 -0
  58. package/dist/polyfills/mdn-data-properties.js +7 -0
  59. package/dist/polyfills/mdn-data-syntaxes.d.ts +7 -0
  60. package/dist/polyfills/mdn-data-syntaxes.js +7 -0
  61. package/dist/polyfills/module.d.ts +17 -0
  62. package/dist/polyfills/module.js +29 -0
  63. package/dist/shims/react-reconciler-constants.d.ts +14 -0
  64. package/dist/shims/react-reconciler-constants.js +20 -0
  65. package/dist/shims/react-reconciler.d.ts +8 -0
  66. package/dist/shims/react-reconciler.js +14 -0
  67. package/dist/shims/set-value.d.ts +4 -0
  68. package/dist/shims/set-value.js +21 -0
  69. package/dist/transformers/NativeClass/index.d.ts +5 -0
  70. package/dist/transformers/NativeClass/index.js +46 -0
  71. package/package.json +31 -0
@@ -0,0 +1,17 @@
1
+ export declare function hmrPlugin(targetMode: string): {
2
+ name: string;
3
+ buildStart(): void;
4
+ watchChange(id: any, { event }: {
5
+ event: any;
6
+ }): void;
7
+ handleHotUpdate({ file, server, timestamp }: {
8
+ file: any;
9
+ server: any;
10
+ timestamp: any;
11
+ }): any[];
12
+ };
13
+ export declare function cliPlugin(targetMode: string, cliFlags: any): {
14
+ name: string;
15
+ buildStart(): void;
16
+ writeBundle(options: any, bundle: any): void;
17
+ };
@@ -0,0 +1,128 @@
1
+ import path from "path";
2
+ // NativeScript HMR integration - track changes for incremental builds
3
+ // Track changed files globally for HMR
4
+ let changedFilesTracker = new Set();
5
+ let isInitialBuild = true;
6
+ export function hmrPlugin(targetMode) {
7
+ return {
8
+ name: "nativescript-hmr",
9
+ buildStart() {
10
+ if (targetMode === "development") {
11
+ console.log("🔥 Vite: Build started");
12
+ // Don't clear changedFilesTracker here - we need it for writeBundle
13
+ // We'll clear it in writeBundle after using it
14
+ }
15
+ },
16
+ // Use watchChange hook to track file changes in build mode
17
+ watchChange(id, { event }) {
18
+ if (targetMode === "development") {
19
+ const relativePath = path.relative(process.cwd(), id);
20
+ // Only track changes in src directory and config files
21
+ const shouldTrack = relativePath.startsWith("src/");
22
+ if (!shouldTrack) {
23
+ return; // Ignore changes to build outputs, platforms, node_modules, etc.
24
+ }
25
+ console.log(`🔥 File ${event}:`, relativePath);
26
+ // Track the changed file
27
+ changedFilesTracker.add(relativePath);
28
+ // Log the type of change for debugging
29
+ if (id.endsWith(".css") || id.endsWith(".scss")) {
30
+ console.log("🔥 CSS file change detected");
31
+ }
32
+ else if (id.endsWith(".html")) {
33
+ console.log("🔥 HTML template change detected");
34
+ }
35
+ else if (id.endsWith(".ts") && !id.endsWith(".d.ts")) {
36
+ console.log("🔥 TypeScript file change detected");
37
+ }
38
+ }
39
+ },
40
+ // Keep handleHotUpdate for completeness, but it won't fire in build mode
41
+ handleHotUpdate({ file, server, timestamp }) {
42
+ if (targetMode === "development") {
43
+ const relativePath = path.relative(process.cwd(), file);
44
+ // Only handle HMR for src directory and config files
45
+ const shouldHandle = relativePath.startsWith("src/");
46
+ if (!shouldHandle) {
47
+ return []; // Ignore HMR for build outputs, platforms, node_modules, etc.
48
+ }
49
+ console.log("🔥 HMR update detected for:", relativePath);
50
+ console.log("🔥 Note: This only fires in dev server mode, not build mode");
51
+ return;
52
+ }
53
+ },
54
+ };
55
+ }
56
+ // NativeScript CLI integration - including IPC communication for HMR
57
+ export function cliPlugin(targetMode, cliFlags) {
58
+ return {
59
+ name: "nativescript-cli-integration",
60
+ buildStart() {
61
+ if (targetMode === "development") {
62
+ console.log("🔥 Vite: Build started");
63
+ }
64
+ },
65
+ writeBundle(options, bundle) {
66
+ if (targetMode === "development") {
67
+ const buildType = isInitialBuild ? "initial" : "incremental";
68
+ console.log(`🔥 NativeScript: ${buildType} build completed`);
69
+ // Get all emitted files from the bundle
70
+ const emittedFiles = Object.keys(bundle);
71
+ // Determine what changed
72
+ const changedFilesList = Array.from(changedFilesTracker);
73
+ // Determine if this should be an HMR update:
74
+ // - Not the initial build
75
+ // - Has specific changed files
76
+ // - Changes are HMR-compatible (HTML templates, CSS, some TS changes)
77
+ const hasHTMLChanges = changedFilesList.some((f) => f.endsWith(".html"));
78
+ const hasCSSChanges = changedFilesList.some((f) => f.endsWith(".css") || f.endsWith(".scss"));
79
+ const hasComponentChanges = changedFilesList.some((f) => f.includes(".component."));
80
+ const canUseHMR = !isInitialBuild &&
81
+ changedFilesList.length > 0 &&
82
+ (hasHTMLChanges || hasCSSChanges || hasComponentChanges);
83
+ const isHMR = canUseHMR && cliFlags.hmr;
84
+ if (changedFilesList.length > 0) {
85
+ console.log("🔥 Changed files triggered rebuild:", changedFilesList);
86
+ console.log("🔥 Can use HMR:", canUseHMR);
87
+ }
88
+ // For TypeScript changes, this will be a full rebuild (expected)
89
+ // For CSS changes, this could potentially be optimized (future enhancement)
90
+ const hasTypeScriptChanges = changedFilesList.some((f) => f.endsWith(".ts"));
91
+ if (hasTypeScriptChanges) {
92
+ console.log("🔥 TypeScript changes detected - full rebuild required");
93
+ }
94
+ if (hasCSSChanges) {
95
+ console.log("🔥 CSS changes detected - could be optimized for HMR in future");
96
+ }
97
+ if (hasHTMLChanges) {
98
+ console.log("🔥 HTML template changes detected - using HMR");
99
+ }
100
+ console.log(`🔥 Emitted ${emittedFiles.length} files in ${buildType} build`);
101
+ // Send IPC message to CLI
102
+ if (process.send) {
103
+ const message = {
104
+ emittedFiles: emittedFiles,
105
+ chunkFiles: emittedFiles.filter((f) => f.includes("chunk") || f.includes("vendor")),
106
+ hash: Date.now().toString(),
107
+ isHMR: isHMR && !isInitialBuild, // Mark as HMR for incremental builds
108
+ changedFiles: changedFilesList,
109
+ buildType: buildType,
110
+ timestamp: Date.now(),
111
+ };
112
+ console.log(`🔥 Sending ${buildType} build notification to CLI (isHMR: ${message.isHMR})`);
113
+ if (changedFilesList.length > 0) {
114
+ console.log("🔥 IPC includes changed files:", changedFilesList);
115
+ }
116
+ process.send(message);
117
+ }
118
+ // Reset trackers AFTER we've used them
119
+ if (isInitialBuild) {
120
+ isInitialBuild = false;
121
+ console.log("🔥 Initial build complete - subsequent changes will trigger fast rebuilds");
122
+ }
123
+ // Clear the tracker for the next build cycle
124
+ changedFilesTracker.clear();
125
+ }
126
+ },
127
+ };
128
+ }
@@ -0,0 +1,4 @@
1
+ export declare function packagePlatformAliases(tsConfigData: any, platform: string, skipCommonjsPackages?: string[], debugViteLogs?: boolean): {
2
+ find: RegExp;
3
+ replacement: (id: any) => any;
4
+ };
@@ -0,0 +1,83 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { findPackageInNodeModules } from "./module-resolution.js";
4
+ import { getProjectRootPath } from "./project.js";
5
+ const projectRoot = getProjectRootPath();
6
+ export function packagePlatformAliases(tsConfigData, platform, skipCommonjsPackages, debugViteLogs) {
7
+ // packages used via core transient dependencies and other vite support
8
+ const commonSkips = [
9
+ "source-map-js",
10
+ "html-entities",
11
+ "fast-xml-parser",
12
+ "@valor/nativescript-websockets",
13
+ ];
14
+ return {
15
+ find: /^(@[^/]+\/[^@/]+|[^@/]+)$/,
16
+ replacement: (id) => {
17
+ // Skip packages that have custom plugins
18
+ if (commonSkips.includes(id) || skipCommonjsPackages?.includes(id)) {
19
+ return id; // Let the plugins handle these
20
+ }
21
+ // Skip if this ID is already handled by tsconfig paths
22
+ // Check if this matches any of our tsconfig path aliases
23
+ if (tsConfigData.paths && tsConfigData.paths[id]) {
24
+ return id; // Let tsconfig aliases handle this
25
+ }
26
+ // Only handle packages that exist in node_modules (real npm packages)
27
+ const packageName = id;
28
+ const packagePath = findPackageInNodeModules(packageName, projectRoot);
29
+ if (packagePath) {
30
+ const packageJsonPath = path.join(packagePath, "package.json");
31
+ if (fs.existsSync(packageJsonPath)) {
32
+ try {
33
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
34
+ const mainField = packageJson.main;
35
+ if (mainField) {
36
+ const mainFilePath = path.join(packagePath, mainField);
37
+ // Case 1: Main field has no extension - try to add extensions
38
+ if (!mainField.includes(".")) {
39
+ // Try platform-specific file first
40
+ const platformFile = path.join(packagePath, `${mainField}.${platform}.js`);
41
+ if (fs.existsSync(platformFile)) {
42
+ if (debugViteLogs) {
43
+ console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.${platform}.js (extensionless)`);
44
+ }
45
+ return platformFile;
46
+ }
47
+ // Fallback to .js
48
+ const jsFile = path.join(packagePath, `${mainField}.js`);
49
+ if (fs.existsSync(jsFile)) {
50
+ if (debugViteLogs) {
51
+ console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.js (extensionless)`);
52
+ }
53
+ return jsFile;
54
+ }
55
+ }
56
+ // Case 2: Main field has extension but file doesn't exist - look for platform variants
57
+ else if (!fs.existsSync(mainFilePath)) {
58
+ // Extract base name and extension
59
+ const ext = path.extname(mainField);
60
+ const baseName = mainField.slice(0, -ext.length);
61
+ // Try platform-specific file first
62
+ const platformFile = path.join(packagePath, `${baseName}.${platform}${ext}`);
63
+ if (fs.existsSync(platformFile)) {
64
+ if (debugViteLogs) {
65
+ console.log(`✅ Alias resolver: ${packageName} -> ${baseName}.${platform}${ext} (missing main)`);
66
+ }
67
+ return platformFile;
68
+ }
69
+ // If main file exists, let normal resolution handle it
70
+ // If it doesn't exist and no platform variant found, let it fail naturally
71
+ }
72
+ }
73
+ }
74
+ catch (e) {
75
+ // Ignore parse errors and fall through
76
+ }
77
+ }
78
+ }
79
+ // Return original if no resolution needed
80
+ return id;
81
+ },
82
+ };
83
+ }
@@ -0,0 +1,23 @@
1
+ export declare function getProjectRootPath(): string;
2
+ export declare const __dirname: string;
3
+ interface IPackageJson {
4
+ name?: string;
5
+ main?: string;
6
+ dependencies?: {
7
+ [name: string]: string;
8
+ };
9
+ devDependencies?: {
10
+ [name: string]: string;
11
+ };
12
+ }
13
+ /**
14
+ * Utility function to get the contents of the project package.json
15
+ */
16
+ export declare function getPackageJson(): IPackageJson;
17
+ /**
18
+ * Utility to get project files relative to the project root.
19
+ * @param filePath path to get
20
+ */
21
+ export declare function getProjectFilePath(filePath: string): string;
22
+ export declare function getProjectTSConfigPath(): string | undefined;
23
+ export {};
@@ -0,0 +1,28 @@
1
+ import { existsSync } from 'fs';
2
+ import { resolve, dirname } from 'path';
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
5
+ export function getProjectRootPath() {
6
+ return process.cwd();
7
+ }
8
+ // Get current directory for ES modules (equivalent to __dirname)
9
+ export const __dirname = dirname(new URL(import.meta.url).pathname);
10
+ /**
11
+ * Utility function to get the contents of the project package.json
12
+ */
13
+ export function getPackageJson() {
14
+ return require(getProjectFilePath('package.json'));
15
+ }
16
+ /**
17
+ * Utility to get project files relative to the project root.
18
+ * @param filePath path to get
19
+ */
20
+ export function getProjectFilePath(filePath) {
21
+ return resolve(getProjectRootPath(), filePath);
22
+ }
23
+ export function getProjectTSConfigPath() {
24
+ return [
25
+ getProjectFilePath('tsconfig.app.json'),
26
+ getProjectFilePath('tsconfig.json'),
27
+ ].find((path) => existsSync(path));
28
+ }
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "vite";
2
+ export default function NativeScriptPlugin(options: {
3
+ platform: "ios" | "android" | "visionos";
4
+ }): Plugin;
@@ -0,0 +1,31 @@
1
+ import path from "path";
2
+ import { resolveNativeScriptPlatformFile } from "./utils.js";
3
+ export default function NativeScriptPlugin(options) {
4
+ return {
5
+ name: "vite:nativescript",
6
+ resolveId(source, importer) {
7
+ const platform = options.platform;
8
+ if (!platform || !importer || source.startsWith(".") === false) {
9
+ return null;
10
+ }
11
+ const resolved = path.resolve(path.dirname(importer), source);
12
+ const extVariants = [".ts", ".js", ".vue"];
13
+ for (const ext of extVariants) {
14
+ const file = resolveNativeScriptPlatformFile(resolved + ext, platform);
15
+ if (file) {
16
+ return file;
17
+ }
18
+ }
19
+ return null;
20
+ },
21
+ transform(code, id) {
22
+ if (id.endsWith(".xml") || id.endsWith(".vue")) {
23
+ // Example: simple pass-through or custom transform for NativeScript view files
24
+ return {
25
+ code,
26
+ map: null,
27
+ };
28
+ }
29
+ },
30
+ };
31
+ }
@@ -0,0 +1,4 @@
1
+ export declare const getTsConfigData: (debugViteLogs: boolean, platform: string) => {
2
+ data: any;
3
+ aliases: any[];
4
+ };
@@ -0,0 +1,241 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { getProjectFilePath, getProjectRootPath } from "./project.js";
4
+ let tsConfigPath;
5
+ const projectRoot = getProjectRootPath();
6
+ // Read TypeScript path mappings
7
+ function getTsConfigPaths(debugViteLogs = false) {
8
+ try {
9
+ if (debugViteLogs)
10
+ console.log("📁 Parsing tsconfig at:", tsConfigPath);
11
+ // The configDir should be the directory of the starting tsconfig file
12
+ const startingConfigDir = path.dirname(tsConfigPath);
13
+ // Recursive function to resolve tsconfig extends chain
14
+ function resolveTsConfigChain(configPath, visitedPaths = new Set()) {
15
+ // Prevent infinite loops
16
+ if (visitedPaths.has(configPath)) {
17
+ if (debugViteLogs)
18
+ console.log("📁 Warning: Circular tsconfig extends detected, skipping:", configPath);
19
+ return { paths: {}, baseUrl: "." };
20
+ }
21
+ visitedPaths.add(configPath);
22
+ const tsConfigContent = fs.readFileSync(configPath, "utf8");
23
+ // Parse JSON (handle JSONC)
24
+ let tsConfig;
25
+ try {
26
+ tsConfig = JSON.parse(tsConfigContent);
27
+ }
28
+ catch (parseError) {
29
+ // Clean up JSONC
30
+ if (debugViteLogs)
31
+ console.log("📁 Cleaning JSONC for:", configPath);
32
+ let cleanContent = tsConfigContent
33
+ .replace(/\/\/.*$/gm, "")
34
+ .replace(/\/\*[\s\S]*?\*\//g, "")
35
+ .replace(/,(\s*[}\]])/g, "$1");
36
+ tsConfig = JSON.parse(cleanContent);
37
+ }
38
+ // Start with current config's options
39
+ let currentPaths = { ...(tsConfig.compilerOptions?.paths || {}) };
40
+ let mergedBaseUrl = tsConfig.compilerOptions?.baseUrl || ".";
41
+ const currentConfigDir = path.dirname(configPath);
42
+ // Handle path resolution for this config file
43
+ if (currentPaths) {
44
+ const resolvedPaths = {};
45
+ for (const [key, values] of Object.entries(currentPaths)) {
46
+ if (Array.isArray(values)) {
47
+ resolvedPaths[key] = values.map((value) => {
48
+ // Handle ${configDir} substitution - use the STARTING config directory
49
+ if (value.includes("${configDir}")) {
50
+ return value.replace(/\$\{configDir\}/g, startingConfigDir);
51
+ }
52
+ // For other paths, resolve relative to THIS config file's directory
53
+ if (!path.isAbsolute(value)) {
54
+ return path.resolve(currentConfigDir, value);
55
+ }
56
+ return value;
57
+ });
58
+ }
59
+ else {
60
+ resolvedPaths[key] = values;
61
+ }
62
+ }
63
+ currentPaths = resolvedPaths;
64
+ }
65
+ // If this config extends another, resolve it first
66
+ if (tsConfig.extends) {
67
+ const baseConfigPath = path.resolve(path.dirname(configPath), tsConfig.extends);
68
+ if (debugViteLogs)
69
+ console.log("📁 Following extends to:", baseConfigPath);
70
+ if (fs.existsSync(baseConfigPath)) {
71
+ try {
72
+ const baseResult = resolveTsConfigChain(baseConfigPath, visitedPaths);
73
+ // Base config comes first, then override with current
74
+ const mergedPaths = { ...baseResult.paths, ...currentPaths };
75
+ // Use current baseUrl if specified, otherwise inherit from base
76
+ if (!tsConfig.compilerOptions?.baseUrl) {
77
+ mergedBaseUrl = baseResult.baseUrl;
78
+ }
79
+ return { paths: mergedPaths, baseUrl: mergedBaseUrl };
80
+ }
81
+ catch (e) {
82
+ if (debugViteLogs)
83
+ console.log("📁 Warning: Could not load extended config:", baseConfigPath, e.message);
84
+ }
85
+ }
86
+ else {
87
+ if (debugViteLogs)
88
+ console.log("📁 Warning: Extended config not found:", baseConfigPath);
89
+ }
90
+ }
91
+ return { paths: currentPaths, baseUrl: mergedBaseUrl };
92
+ }
93
+ const result = resolveTsConfigChain(tsConfigPath);
94
+ if (debugViteLogs) {
95
+ console.log("📁 Found paths in tsconfig:", Object.keys(result.paths));
96
+ console.log("📁 Base URL:", result.baseUrl);
97
+ console.log("📁 Starting configDir:", startingConfigDir);
98
+ // Show first few resolved paths for debugging
99
+ Object.entries(result.paths)
100
+ .slice(0, 3)
101
+ .forEach(([key, values]) => {
102
+ console.log(`📁 Path example: ${key} -> ${values[0]}`);
103
+ });
104
+ }
105
+ return result;
106
+ }
107
+ catch (e) {
108
+ console.warn("Failed to parse tsconfig paths:", e.message);
109
+ return { paths: {}, baseUrl: "." };
110
+ }
111
+ }
112
+ // Function to create TypeScript aliases with platform support
113
+ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
114
+ const aliases = [];
115
+ // Process patterns in order: wildcards first, then exact matches
116
+ const sortedPatterns = Object.entries(paths).sort(([a], [b]) => {
117
+ // Wildcards (with *) come first
118
+ const aHasWildcard = a.includes("*");
119
+ const bHasWildcard = b.includes("*");
120
+ if (aHasWildcard && !bHasWildcard)
121
+ return -1;
122
+ if (!aHasWildcard && bHasWildcard)
123
+ return 1;
124
+ // Within same type, longer patterns first (more specific)
125
+ return b.length - a.length;
126
+ });
127
+ for (const [pattern, destinations] of sortedPatterns) {
128
+ if (Array.isArray(destinations) && destinations.length > 0) {
129
+ if (pattern.includes("*")) {
130
+ // Handle wildcard patterns (like "@scope/plugins/*")
131
+ const aliasKey = pattern.replace(/\/\*$/, "");
132
+ const destination = destinations[0].replace(/\/\*$/, "");
133
+ // Check if destination is already absolute (resolved by tsconfig chain)
134
+ const resolvedDestination = path.isAbsolute(destination)
135
+ ? destination
136
+ : path.resolve(projectRoot, baseUrl, destination);
137
+ console.log(`📁 Creating wildcard alias: ${aliasKey} -> ${resolvedDestination}`);
138
+ aliases.push({
139
+ find: new RegExp(`^${aliasKey.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/(.*))?$`),
140
+ replacement: (match, subpath) => {
141
+ const fullPath = subpath
142
+ ? path.join(resolvedDestination, subpath)
143
+ : resolvedDestination;
144
+ if (debugViteLogs) {
145
+ console.log(`📁 TypeScript wildcard alias: ${match} -> ${fullPath}`);
146
+ }
147
+ // Check if this resolves to a directory, and if so, try to find index files
148
+ if (fs.existsSync(fullPath) &&
149
+ fs.statSync(fullPath).isDirectory()) {
150
+ // Try platform-specific index files first
151
+ const platformIndexPatterns = [
152
+ `index.${platform}.ts`,
153
+ `index.${platform}.js`,
154
+ `index.${platform}.mjs`,
155
+ ];
156
+ for (const indexFile of platformIndexPatterns) {
157
+ const indexPath = path.join(fullPath, indexFile);
158
+ if (fs.existsSync(indexPath)) {
159
+ if (debugViteLogs) {
160
+ console.log(`📁 Found platform-specific directory index: ${indexPath}`);
161
+ }
162
+ return indexPath;
163
+ }
164
+ }
165
+ // Try standard index files
166
+ const indexPatterns = ["index.ts", "index.js", "index.mjs"];
167
+ for (const indexFile of indexPatterns) {
168
+ const indexPath = path.join(fullPath, indexFile);
169
+ if (fs.existsSync(indexPath)) {
170
+ if (debugViteLogs) {
171
+ console.log(`📁 Found directory index: ${indexPath}`);
172
+ }
173
+ return indexPath;
174
+ }
175
+ }
176
+ }
177
+ // If not a directory or no index found, try platform-specific resolution
178
+ const extensions = [".ts", ".js", ".mjs"];
179
+ for (const ext of extensions) {
180
+ const basePath = fullPath + ext;
181
+ // Try platform-specific file first
182
+ const platformPath = fullPath + `.${platform}` + ext;
183
+ if (fs.existsSync(platformPath)) {
184
+ if (debugViteLogs) {
185
+ console.log(`📁 Found platform-specific file: ${platformPath}`);
186
+ }
187
+ return platformPath;
188
+ }
189
+ // Try base file
190
+ if (fs.existsSync(basePath)) {
191
+ if (debugViteLogs) {
192
+ console.log(`📁 Found base file: ${basePath}`);
193
+ }
194
+ return basePath;
195
+ }
196
+ }
197
+ return fullPath;
198
+ },
199
+ });
200
+ }
201
+ else {
202
+ // Handle exact matches (like "@scope/anything/anywhere")
203
+ // Use regex to ensure exact match only
204
+ // Check if destination is already absolute (resolved by tsconfig chain)
205
+ const resolvedDestination = path.isAbsolute(destinations[0])
206
+ ? destinations[0]
207
+ : path.resolve(projectRoot, baseUrl, destinations[0]);
208
+ if (debugViteLogs) {
209
+ console.log(`📁 Creating exact alias: ${pattern} -> ${resolvedDestination}`);
210
+ }
211
+ aliases.push({
212
+ find: new RegExp(`^${pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`),
213
+ replacement: resolvedDestination,
214
+ });
215
+ }
216
+ }
217
+ }
218
+ return aliases;
219
+ }
220
+ // Get TypeScript path configuration
221
+ let tsConfigData;
222
+ export const getTsConfigData = (debugViteLogs, platform) => {
223
+ tsConfigPath = getProjectFilePath("tsconfig.app.json");
224
+ if (!fs.existsSync(tsConfigPath)) {
225
+ tsConfigPath = getProjectFilePath("tsconfig.json");
226
+ }
227
+ if (!tsConfigData) {
228
+ tsConfigData = getTsConfigPaths();
229
+ }
230
+ if (debugViteLogs) {
231
+ console.log("📁 Loaded TypeScript path configuration");
232
+ }
233
+ const aliases = createTsConfigAliases(tsConfigData.paths, tsConfigData.baseUrl, platform);
234
+ if (aliases.length > 0 && debugViteLogs) {
235
+ console.log("📁 Created TypeScript path aliases:", aliases.length);
236
+ }
237
+ return {
238
+ data: tsConfigData,
239
+ aliases
240
+ };
241
+ };
@@ -0,0 +1,23 @@
1
+ export declare function nsConfigToJson(): Record<string, any>;
2
+ /**
3
+ * Resolves the NativeScript platform-specific file for a given module ID.
4
+ * @param id The module ID to resolve.
5
+ * @param platform The target platform (e.g., "ios", "android").
6
+ * @returns The resolved file path or undefined if not found.
7
+ */
8
+ export declare function resolveNativeScriptPlatformFile(id: string, platform: string): string | undefined;
9
+ /**
10
+ * Utility to get all dependencies from the project package.json.
11
+ * The result combines dependencies and devDependencies
12
+ *
13
+ * @returns string[] dependencies
14
+ */
15
+ export declare function getAllDependencies(): string[];
16
+ /**
17
+ * Check if a dependency is present in package.json
18
+ */
19
+ export declare function hasDependency(packageName: string): boolean;
20
+ /**
21
+ * Get the version of a dependency from package.json
22
+ */
23
+ export declare function getDependencyVersion(packageName: string): string | undefined;