@nativescript/vite 0.0.1-alpha.0
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.
- package/dist/configuration/angular.d.ts +4 -0
- package/dist/configuration/angular.js +30 -0
- package/dist/configuration/base.d.ts +4 -0
- package/dist/configuration/base.js +270 -0
- package/dist/configuration/old-without-merge-base.d.ts +13 -0
- package/dist/configuration/old-without-merge-base.js +249 -0
- package/dist/configuration/react.d.ts +4 -0
- package/dist/configuration/react.js +85 -0
- package/dist/configuration/solid.d.ts +4 -0
- package/dist/configuration/solid.js +48 -0
- package/dist/configuration/vue.d.ts +4 -0
- package/dist/configuration/vue.js +45 -0
- package/dist/helpers/commonjs-plugins.d.ts +6 -0
- package/dist/helpers/commonjs-plugins.js +75 -0
- package/dist/helpers/config-as-json.d.ts +2 -0
- package/dist/helpers/config-as-json.js +35 -0
- package/dist/helpers/css-tree.d.ts +4 -0
- package/dist/helpers/css-tree.js +21 -0
- package/dist/helpers/dynamic-import-plugin.d.ts +4 -0
- package/dist/helpers/dynamic-import-plugin.js +62 -0
- package/dist/helpers/external-configs.d.ts +6 -0
- package/dist/helpers/external-configs.js +33 -0
- package/dist/helpers/flavor.d.ts +5 -0
- package/dist/helpers/flavor.js +40 -0
- package/dist/helpers/global-defines.d.ts +14 -0
- package/dist/helpers/global-defines.js +18 -0
- package/dist/helpers/main-entry.d.ts +5 -0
- package/dist/helpers/main-entry.js +75 -0
- package/dist/helpers/module-resolution.d.ts +1 -0
- package/dist/helpers/module-resolution.js +17 -0
- package/dist/helpers/nativescript-package-resolver.d.ts +5 -0
- package/dist/helpers/nativescript-package-resolver.js +139 -0
- package/dist/helpers/ns-cli-plugins.d.ts +19 -0
- package/dist/helpers/ns-cli-plugins.js +162 -0
- package/dist/helpers/package-platform-aliases.d.ts +4 -0
- package/dist/helpers/package-platform-aliases.js +83 -0
- package/dist/helpers/project.d.ts +23 -0
- package/dist/helpers/project.js +28 -0
- package/dist/helpers/resolver.d.ts +4 -0
- package/dist/helpers/resolver.js +31 -0
- package/dist/helpers/ts-config-paths.d.ts +4 -0
- package/dist/helpers/ts-config-paths.js +241 -0
- package/dist/helpers/utils.d.ts +29 -0
- package/dist/helpers/utils.js +101 -0
- package/dist/helpers/workers.d.ts +20 -0
- package/dist/helpers/workers.js +86 -0
- package/dist/hmr/hmr-angular.d.ts +1 -0
- package/dist/hmr/hmr-angular.js +34 -0
- package/dist/hmr/hmr-bridge.d.ts +18 -0
- package/dist/hmr/hmr-bridge.js +154 -0
- package/dist/hmr/hmr-client.d.ts +5 -0
- package/dist/hmr/hmr-client.js +93 -0
- package/dist/hmr/hmr-server.d.ts +20 -0
- package/dist/hmr/hmr-server.js +179 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/polyfills/mdn-data-at-rules.d.ts +7 -0
- package/dist/polyfills/mdn-data-at-rules.js +7 -0
- package/dist/polyfills/mdn-data-properties.d.ts +7 -0
- package/dist/polyfills/mdn-data-properties.js +7 -0
- package/dist/polyfills/mdn-data-syntaxes.d.ts +7 -0
- package/dist/polyfills/mdn-data-syntaxes.js +7 -0
- package/dist/polyfills/module.d.ts +17 -0
- package/dist/polyfills/module.js +29 -0
- package/dist/shims/react-reconciler-constants.d.ts +14 -0
- package/dist/shims/react-reconciler-constants.js +20 -0
- package/dist/shims/react-reconciler.d.ts +8 -0
- package/dist/shims/react-reconciler.js +14 -0
- package/dist/shims/set-value.d.ts +4 -0
- package/dist/shims/set-value.js +21 -0
- package/dist/transformers/NativeClass/index.d.ts +5 -0
- package/dist/transformers/NativeClass/index.js +46 -0
- package/package.json +31 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { getProjectRootPath } from "./project.js";
|
|
4
|
+
import { findPackageInNodeModules } from "./module-resolution.js";
|
|
5
|
+
const projectRoot = getProjectRootPath();
|
|
6
|
+
// Cache for package resolution results
|
|
7
|
+
const packageCache = new Map();
|
|
8
|
+
export function nativescriptPackageResolver(platform) {
|
|
9
|
+
return {
|
|
10
|
+
name: "nativescript-package-resolver",
|
|
11
|
+
enforce: "pre", // Force this plugin to run before all others
|
|
12
|
+
resolveId(id, importer) {
|
|
13
|
+
// Only handle direct package imports (not relative paths)
|
|
14
|
+
if (id.startsWith(".") || id.startsWith("/") || id.includes(":")) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
// Extract package name properly
|
|
18
|
+
let packageName;
|
|
19
|
+
if (id.startsWith("@")) {
|
|
20
|
+
// Scoped package: @scope/package or @scope/package/subpath
|
|
21
|
+
const parts = id.split("/");
|
|
22
|
+
if (parts.length >= 2) {
|
|
23
|
+
packageName = parts[0] + "/" + parts[1]; // @scope/package
|
|
24
|
+
// Only handle root package imports, not subpaths
|
|
25
|
+
if (parts.length > 2) {
|
|
26
|
+
return null; // This is a subpath import like @scope/package/file
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return null; // Invalid scoped package
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Regular package: package or package/subpath
|
|
35
|
+
const parts = id.split("/");
|
|
36
|
+
packageName = parts[0];
|
|
37
|
+
// Only handle root package imports, not subpaths
|
|
38
|
+
if (parts.length > 1) {
|
|
39
|
+
return null; // This is a subpath import like package/file
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Check cache first
|
|
43
|
+
if (packageCache.has(packageName)) {
|
|
44
|
+
const cachedResult = packageCache.get(packageName);
|
|
45
|
+
if (cachedResult === null) {
|
|
46
|
+
return null; // Previously determined to not need platform resolution
|
|
47
|
+
}
|
|
48
|
+
return cachedResult;
|
|
49
|
+
}
|
|
50
|
+
const packagePath = findPackageInNodeModules(packageName, projectRoot);
|
|
51
|
+
if (packagePath) {
|
|
52
|
+
const packageJsonPath = path.join(packagePath, "package.json");
|
|
53
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
54
|
+
try {
|
|
55
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
56
|
+
const mainField = packageJson.main;
|
|
57
|
+
if (mainField) {
|
|
58
|
+
const mainFilePath = path.join(packagePath, mainField);
|
|
59
|
+
// Case 1: Main field has no extension - try to add extensions
|
|
60
|
+
if (!mainField.includes(".")) {
|
|
61
|
+
// Try platform-specific file first
|
|
62
|
+
const platformFile = path.join(packagePath, `${mainField}.${platform}.js`);
|
|
63
|
+
if (fs.existsSync(platformFile)) {
|
|
64
|
+
const result = {
|
|
65
|
+
id: platformFile,
|
|
66
|
+
resolvedBy: "nativescript-package-resolver",
|
|
67
|
+
};
|
|
68
|
+
packageCache.set(packageName, result);
|
|
69
|
+
// console.log(
|
|
70
|
+
// `🔧 Package resolver: ${packageName} -> ${mainField}.${platform}.js (extensionless)`,
|
|
71
|
+
// );
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
// Fallback to .js
|
|
75
|
+
const jsFile = path.join(packagePath, `${mainField}.js`);
|
|
76
|
+
if (fs.existsSync(jsFile)) {
|
|
77
|
+
const result = {
|
|
78
|
+
id: jsFile,
|
|
79
|
+
resolvedBy: "nativescript-package-resolver",
|
|
80
|
+
};
|
|
81
|
+
packageCache.set(packageName, result);
|
|
82
|
+
// console.log(
|
|
83
|
+
// `🔧 Package resolver: ${packageName} -> ${mainField}.js (extensionless)`,
|
|
84
|
+
// );
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Case 2: Main field has extension but file doesn't exist - look for platform variants
|
|
89
|
+
else if (!fs.existsSync(mainFilePath)) {
|
|
90
|
+
// Extract base name and extension
|
|
91
|
+
const ext = path.extname(mainField);
|
|
92
|
+
const baseName = mainField.slice(0, -ext.length);
|
|
93
|
+
// Try platform-specific file first
|
|
94
|
+
const platformFile = path.join(packagePath, `${baseName}.${platform}${ext}`);
|
|
95
|
+
if (fs.existsSync(platformFile)) {
|
|
96
|
+
const result = {
|
|
97
|
+
id: platformFile,
|
|
98
|
+
resolvedBy: "nativescript-package-resolver",
|
|
99
|
+
};
|
|
100
|
+
packageCache.set(packageName, result);
|
|
101
|
+
// console.log(
|
|
102
|
+
// `🔧 Package resolver: ${packageName} -> ${baseName}.${platform}${ext} (missing main)`,
|
|
103
|
+
// );
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
// Cache as null - no platform variant found
|
|
107
|
+
packageCache.set(packageName, null);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Main file exists - let normal resolution handle it
|
|
112
|
+
packageCache.set(packageName, null);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
// Cache as null on error
|
|
119
|
+
packageCache.set(packageName, null);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// No package.json found
|
|
125
|
+
packageCache.set(packageName, null);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Package doesn't exist
|
|
131
|
+
packageCache.set(packageName, null);
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
// Cache as null and return null
|
|
135
|
+
packageCache.set(packageName, null);
|
|
136
|
+
return null;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
enforce: "post";
|
|
16
|
+
configResolved(config: any): void;
|
|
17
|
+
buildStart(): void;
|
|
18
|
+
closeBundle(): void;
|
|
19
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { readdirSync, statSync } from "fs";
|
|
3
|
+
// NativeScript HMR integration - track changes for incremental builds
|
|
4
|
+
// Track changed files globally for HMR
|
|
5
|
+
let changedFilesTracker = new Set();
|
|
6
|
+
let isInitialBuild = true;
|
|
7
|
+
export function hmrPlugin(targetMode) {
|
|
8
|
+
return {
|
|
9
|
+
name: "nativescript-hmr",
|
|
10
|
+
buildStart() {
|
|
11
|
+
if (targetMode === "development") {
|
|
12
|
+
console.log("🔥 Vite: Build started");
|
|
13
|
+
// Don't clear changedFilesTracker here - we need it for writeBundle
|
|
14
|
+
// We'll clear it in writeBundle after using it
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
// Use watchChange hook to track file changes in build mode
|
|
18
|
+
watchChange(id, { event }) {
|
|
19
|
+
if (targetMode === "development") {
|
|
20
|
+
const relativePath = path.relative(process.cwd(), id);
|
|
21
|
+
// Only track changes in src directory and config files
|
|
22
|
+
const shouldTrack = relativePath.startsWith("src/");
|
|
23
|
+
if (!shouldTrack) {
|
|
24
|
+
return; // Ignore changes to build outputs, platforms, node_modules, etc.
|
|
25
|
+
}
|
|
26
|
+
console.log(`🔥 File ${event}:`, relativePath);
|
|
27
|
+
// Track the changed file
|
|
28
|
+
changedFilesTracker.add(relativePath);
|
|
29
|
+
// Log the type of change for debugging
|
|
30
|
+
if (id.endsWith(".css") || id.endsWith(".scss")) {
|
|
31
|
+
console.log("🔥 CSS file change detected");
|
|
32
|
+
}
|
|
33
|
+
else if (id.endsWith(".html")) {
|
|
34
|
+
console.log("🔥 HTML template change detected");
|
|
35
|
+
}
|
|
36
|
+
else if (id.endsWith(".ts") && !id.endsWith(".d.ts")) {
|
|
37
|
+
console.log("🔥 TypeScript file change detected");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
// Keep handleHotUpdate for completeness, but it won't fire in build mode
|
|
42
|
+
handleHotUpdate({ file, server, timestamp }) {
|
|
43
|
+
if (targetMode === "development") {
|
|
44
|
+
const relativePath = path.relative(process.cwd(), file);
|
|
45
|
+
// Only handle HMR for src directory and config files
|
|
46
|
+
const shouldHandle = relativePath.startsWith("src/");
|
|
47
|
+
if (!shouldHandle) {
|
|
48
|
+
return []; // Ignore HMR for build outputs, platforms, node_modules, etc.
|
|
49
|
+
}
|
|
50
|
+
console.log("🔥 HMR update detected for:", relativePath);
|
|
51
|
+
console.log("🔥 Note: This only fires in dev server mode, not build mode");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// NativeScript CLI integration - including IPC communication for HMR
|
|
58
|
+
export function cliPlugin(targetMode, cliFlags) {
|
|
59
|
+
return {
|
|
60
|
+
name: "nativescript-cli-integration",
|
|
61
|
+
// Ensure we run after other plugins (like vite-plugin-static-copy)
|
|
62
|
+
enforce: "post",
|
|
63
|
+
// Resolve build outDir so we can read final outputs after all plugins finish
|
|
64
|
+
configResolved(config) {
|
|
65
|
+
// no-op, but we keep reference on the closure via getOutDir
|
|
66
|
+
getOutDir = () => path.resolve(config.root ?? process.cwd(), config.build?.outDir ?? "dist");
|
|
67
|
+
},
|
|
68
|
+
buildStart() {
|
|
69
|
+
if (targetMode === "development") {
|
|
70
|
+
console.log("🔥 Vite: Build started");
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
// Defer CLI notification until after all plugins (including static copy) are done.
|
|
74
|
+
closeBundle() {
|
|
75
|
+
if (targetMode !== "development")
|
|
76
|
+
return;
|
|
77
|
+
const buildType = isInitialBuild ? "initial" : "incremental";
|
|
78
|
+
console.log(`🔥 NativeScript: ${buildType} build completed`);
|
|
79
|
+
// After static copy has finished, read actual dist contents
|
|
80
|
+
const distDir = getOutDir();
|
|
81
|
+
const emittedFiles = listFilesFlat(distDir);
|
|
82
|
+
// Determine what changed
|
|
83
|
+
const changedFilesList = Array.from(changedFilesTracker);
|
|
84
|
+
const hasHTMLChanges = changedFilesList.some((f) => f.endsWith(".html"));
|
|
85
|
+
const hasCSSChanges = changedFilesList.some((f) => f.endsWith(".css") || f.endsWith(".scss"));
|
|
86
|
+
const hasComponentChanges = changedFilesList.some((f) => f.includes(".component."));
|
|
87
|
+
const canUseHMR = !isInitialBuild &&
|
|
88
|
+
changedFilesList.length > 0 &&
|
|
89
|
+
(hasHTMLChanges || hasCSSChanges || hasComponentChanges);
|
|
90
|
+
const isHMR = canUseHMR && cliFlags.hmr;
|
|
91
|
+
if (changedFilesList.length > 0) {
|
|
92
|
+
console.log("🔥 Changed files triggered rebuild:", changedFilesList);
|
|
93
|
+
console.log("🔥 Can use HMR:", canUseHMR);
|
|
94
|
+
}
|
|
95
|
+
if (changedFilesList.some((f) => f.endsWith(".ts"))) {
|
|
96
|
+
console.log("🔥 TypeScript changes detected - full rebuild required");
|
|
97
|
+
}
|
|
98
|
+
if (hasCSSChanges) {
|
|
99
|
+
console.log("🔥 CSS changes detected - could be optimized for HMR in future");
|
|
100
|
+
}
|
|
101
|
+
if (hasHTMLChanges) {
|
|
102
|
+
console.log("🔥 HTML template changes detected - using HMR");
|
|
103
|
+
}
|
|
104
|
+
console.log(`🔥 Emitted ${emittedFiles.length} files in ${buildType} build`);
|
|
105
|
+
if (process.send) {
|
|
106
|
+
const message = {
|
|
107
|
+
emittedFiles,
|
|
108
|
+
chunkFiles: emittedFiles.filter((f) => f.includes("chunk") || f.includes("vendor")),
|
|
109
|
+
hash: Date.now().toString(),
|
|
110
|
+
isHMR: isHMR && !isInitialBuild,
|
|
111
|
+
changedFiles: changedFilesList,
|
|
112
|
+
buildType,
|
|
113
|
+
timestamp: Date.now(),
|
|
114
|
+
};
|
|
115
|
+
console.log(`🔥 Sending ${buildType} build notification to CLI (isHMR: ${message.isHMR})`);
|
|
116
|
+
if (changedFilesList.length > 0) {
|
|
117
|
+
console.log("🔥 IPC includes changed files:", changedFilesList);
|
|
118
|
+
}
|
|
119
|
+
process.send(message);
|
|
120
|
+
}
|
|
121
|
+
if (isInitialBuild) {
|
|
122
|
+
isInitialBuild = false;
|
|
123
|
+
console.log("🔥 Initial build complete - subsequent changes will trigger fast rebuilds");
|
|
124
|
+
}
|
|
125
|
+
changedFilesTracker.clear();
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Helper to get outDir resolved at runtime
|
|
130
|
+
let getOutDir = () => path.resolve(process.cwd(), "dist");
|
|
131
|
+
// Recursively list files under a directory and return relative paths
|
|
132
|
+
function listFilesFlat(rootDir) {
|
|
133
|
+
const results = [];
|
|
134
|
+
function walk(dir, relBase = "") {
|
|
135
|
+
let entries = [];
|
|
136
|
+
try {
|
|
137
|
+
entries = readdirSync(dir);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
for (const name of entries) {
|
|
143
|
+
const abs = path.join(dir, name);
|
|
144
|
+
const rel = path.join(relBase, name);
|
|
145
|
+
let s;
|
|
146
|
+
try {
|
|
147
|
+
s = statSync(abs);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (s.isDirectory()) {
|
|
153
|
+
walk(abs, rel);
|
|
154
|
+
}
|
|
155
|
+
else if (s.isFile()) {
|
|
156
|
+
results.push(rel);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
walk(rootDir);
|
|
161
|
+
return results;
|
|
162
|
+
}
|
|
@@ -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, 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)) {
|
|
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,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
|
+
}
|