@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,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,29 @@
|
|
|
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
|
+
* Utility to get the path (usually nested in node_modules) of a dependency.
|
|
22
|
+
*
|
|
23
|
+
* @param dependencyName
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDependencyPath(dependencyName: string): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Get the version of a dependency from package.json
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDependencyVersion(packageName: string): string | undefined;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { transformSync } from "esbuild";
|
|
4
|
+
import { satisfies } from "semver";
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
import { getPackageJson, getProjectFilePath, getProjectRootPath } from "./project.js";
|
|
8
|
+
// get the name from the package for the output
|
|
9
|
+
const packageJson = getPackageJson();
|
|
10
|
+
export function nsConfigToJson() {
|
|
11
|
+
let configObject;
|
|
12
|
+
;
|
|
13
|
+
const tsPath = getProjectFilePath("nativescript.config.ts");
|
|
14
|
+
const tsCode = fs.readFileSync(tsPath, "utf-8");
|
|
15
|
+
// a) Transpile your TS config to CommonJS so we can require() it
|
|
16
|
+
const { code: cjsCode } = transformSync(tsCode, {
|
|
17
|
+
loader: "ts",
|
|
18
|
+
format: "cjs",
|
|
19
|
+
target: "esnext",
|
|
20
|
+
});
|
|
21
|
+
// b) Evaluate it in a VM-style sandbox to pull out the default export
|
|
22
|
+
const module = { exports: {} };
|
|
23
|
+
const requireFunc = (id) => require(id);
|
|
24
|
+
new Function("exports", "require", "module", "__filename", "__dirname", cjsCode)(module.exports, requireFunc, module, tsPath, path.dirname(tsPath));
|
|
25
|
+
configObject = module.exports.default ?? module.exports;
|
|
26
|
+
// ensure the config has a name
|
|
27
|
+
configObject.name = packageJson.name;
|
|
28
|
+
// ensure the main entry is set to "bundle"
|
|
29
|
+
configObject.main = "bundle";
|
|
30
|
+
return configObject;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the NativeScript platform-specific file for a given module ID.
|
|
34
|
+
* @param id The module ID to resolve.
|
|
35
|
+
* @param platform The target platform (e.g., "ios", "android").
|
|
36
|
+
* @returns The resolved file path or undefined if not found.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveNativeScriptPlatformFile(id, platform) {
|
|
39
|
+
const ext = path.extname(id);
|
|
40
|
+
const base = id.slice(0, -ext.length);
|
|
41
|
+
let platformFile = `${base}.${platform}${ext}`;
|
|
42
|
+
if (fs.existsSync(platformFile)) {
|
|
43
|
+
return platformFile;
|
|
44
|
+
}
|
|
45
|
+
// core uses indices for many barrels
|
|
46
|
+
platformFile = `${base}/index.${platform}${ext}`;
|
|
47
|
+
if (fs.existsSync(platformFile)) {
|
|
48
|
+
return platformFile;
|
|
49
|
+
}
|
|
50
|
+
// fallback to non-platform file
|
|
51
|
+
return fs.existsSync(id) ? id : undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Utility to get all dependencies from the project package.json.
|
|
55
|
+
* The result combines dependencies and devDependencies
|
|
56
|
+
*
|
|
57
|
+
* @returns string[] dependencies
|
|
58
|
+
*/
|
|
59
|
+
export function getAllDependencies() {
|
|
60
|
+
return [
|
|
61
|
+
...Object.keys(packageJson.dependencies ?? {}),
|
|
62
|
+
...Object.keys(packageJson.devDependencies ?? {}),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a dependency is present in package.json
|
|
67
|
+
*/
|
|
68
|
+
export function hasDependency(packageName) {
|
|
69
|
+
return getAllDependencies().includes(packageName);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Utility to get the path (usually nested in node_modules) of a dependency.
|
|
73
|
+
*
|
|
74
|
+
* @param dependencyName
|
|
75
|
+
*/
|
|
76
|
+
export function getDependencyPath(dependencyName) {
|
|
77
|
+
try {
|
|
78
|
+
const resolvedPath = require.resolve(`${dependencyName}/package.json`, {
|
|
79
|
+
paths: [getProjectRootPath()],
|
|
80
|
+
});
|
|
81
|
+
return path.dirname(resolvedPath);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the version of a dependency from package.json
|
|
89
|
+
*/
|
|
90
|
+
export function getDependencyVersion(packageName) {
|
|
91
|
+
try {
|
|
92
|
+
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
93
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
94
|
+
return (packageJson.dependencies?.[packageName] ||
|
|
95
|
+
packageJson.devDependencies?.[packageName] ||
|
|
96
|
+
packageJson.peerDependencies?.[packageName]);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function getWorkerPlugins(platform: string): ({
|
|
2
|
+
name: string;
|
|
3
|
+
resolveId(id: any): string;
|
|
4
|
+
load(id: any): string;
|
|
5
|
+
transform?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
name: string;
|
|
8
|
+
resolveId(id: any, importer: any): string;
|
|
9
|
+
load?: undefined;
|
|
10
|
+
transform?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
name: string;
|
|
13
|
+
transform(code: any, id: any): any;
|
|
14
|
+
resolveId?: undefined;
|
|
15
|
+
load?: undefined;
|
|
16
|
+
})[];
|
|
17
|
+
export declare function workerUrlPlugin(): {
|
|
18
|
+
name: string;
|
|
19
|
+
generateBundle(options: any, bundle: any): void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { nsConfigToJson, resolveNativeScriptPlatformFile } from "./utils.js";
|
|
3
|
+
export function getWorkerPlugins(platform) {
|
|
4
|
+
return [
|
|
5
|
+
// Handle ~/package.json virtual module for workers
|
|
6
|
+
{
|
|
7
|
+
name: "worker-virtual-package-json",
|
|
8
|
+
resolveId(id) {
|
|
9
|
+
if (id === "~/package.json") {
|
|
10
|
+
return "\0worker:nsconfig-json"; // Use a completely different virtual ID that doesn't look like JSON
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
},
|
|
14
|
+
load(id) {
|
|
15
|
+
if (id === "\0worker:nsconfig-json") {
|
|
16
|
+
const configObject = nsConfigToJson();
|
|
17
|
+
// Return the NativeScript config as a JavaScript module
|
|
18
|
+
return `export default ${JSON.stringify(configObject, null, 2)};`;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
// Resolve NativeScript platform-specific files for workers
|
|
24
|
+
{
|
|
25
|
+
name: "nativescript-platform-resolver-worker",
|
|
26
|
+
resolveId(id, importer) {
|
|
27
|
+
// Handle relative imports from node_modules (not just @nativescript/core)
|
|
28
|
+
if (importer) {
|
|
29
|
+
const resolvedPath = path.resolve(path.dirname(importer), id);
|
|
30
|
+
// Try different extensions with platform-specific resolution
|
|
31
|
+
const extensions = [".js", ".mjs", ".ts", ".vue"];
|
|
32
|
+
for (const ext of extensions) {
|
|
33
|
+
const testPath = resolvedPath + ext;
|
|
34
|
+
// Use the existing NativeScript platform file resolver
|
|
35
|
+
const platformResolvedFile = resolveNativeScriptPlatformFile(testPath, platform);
|
|
36
|
+
if (platformResolvedFile) {
|
|
37
|
+
return platformResolvedFile;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
// Handle import.meta expressions in workers
|
|
46
|
+
{
|
|
47
|
+
name: "worker-import-meta-handler",
|
|
48
|
+
transform(code, id) {
|
|
49
|
+
// Replace import.meta.dirname with a static value for workers
|
|
50
|
+
if (code.includes("import.meta.dirname")) {
|
|
51
|
+
code = code.replace(/import\.meta\.dirname/g, '""');
|
|
52
|
+
}
|
|
53
|
+
// Replace import.meta.url with a static value for workers
|
|
54
|
+
if (code.includes("import.meta.url")) {
|
|
55
|
+
code = code.replace(/import\.meta\.url/g, '"file:///app/"');
|
|
56
|
+
}
|
|
57
|
+
return code;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
export function workerUrlPlugin() {
|
|
63
|
+
return {
|
|
64
|
+
name: "nativescript-worker-url-transform",
|
|
65
|
+
generateBundle(options, bundle) {
|
|
66
|
+
// Transform the main bundle to use NativeScript worker paths
|
|
67
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
68
|
+
if (chunk.type === "chunk" && !fileName.includes(".worker")) {
|
|
69
|
+
// Transform Vite's worker URL pattern to NativeScript's expected format
|
|
70
|
+
// From: new Worker(new URL(/* @vite-ignore */ "/assets/sample.worker-C6wW8q2-.js", import.meta.url))
|
|
71
|
+
// To: new Worker('~/' + 'assets/sample.worker-C6wW8q2-.js')
|
|
72
|
+
const workerUrlRegex = /new\s+Worker\s*\(\s*new\s+URL\s*\(\s*(?:\/\*[^*]*\*\/\s*)?["']([^"']+)["']\s*,\s*import\.meta\.url\s*\)\s*\)/g;
|
|
73
|
+
if (workerUrlRegex.test(chunk.code)) {
|
|
74
|
+
chunk.code = chunk.code.replace(workerUrlRegex, (match, assetPath) => {
|
|
75
|
+
// Use the full asset path including assets/ folder
|
|
76
|
+
const fullPath = assetPath.startsWith("/")
|
|
77
|
+
? assetPath.slice(1)
|
|
78
|
+
: assetPath;
|
|
79
|
+
return `new Worker('~/' + '${fullPath}')`;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleAngularHmrUpdate(): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isDevMode, ɵresetCompiledComponents,
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
} from "@angular/core";
|
|
4
|
+
export function handleAngularHmrUpdate() {
|
|
5
|
+
// Reset JIT compiled components cache
|
|
6
|
+
ɵresetCompiledComponents();
|
|
7
|
+
try {
|
|
8
|
+
console.log(`typeof global["__cleanup_ng_hot__"]`, typeof global["__cleanup_ng_hot__"]);
|
|
9
|
+
if (global["__cleanup_ng_hot__"])
|
|
10
|
+
global["__cleanup_ng_hot__"]();
|
|
11
|
+
global["__reboot_ng_modules__"]();
|
|
12
|
+
console.log('angular called __reboot_ng_modules__!');
|
|
13
|
+
// need to call some kind of apply here?
|
|
14
|
+
// Webpack would call in this order with angular-hot-loader/hmr-accept:
|
|
15
|
+
/**
|
|
16
|
+
* angular hot dispose called!
|
|
17
|
+
hot dispose called here?!
|
|
18
|
+
__cleanup_ng_hot__ called!
|
|
19
|
+
angular hot accept about to be called!
|
|
20
|
+
Angular is running in development mode.
|
|
21
|
+
[HMR][bd598ae5b97083449f33] success | Successfully applied update.
|
|
22
|
+
calling global.__onLiveSync!
|
|
23
|
+
*/
|
|
24
|
+
global.__onLiveSync();
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error("[NG HMR] Error disposing previous module");
|
|
28
|
+
console.error(e, e?.stack);
|
|
29
|
+
// HMR breaks when rejecting the main module dispose, so we manually trigger an HMR restart
|
|
30
|
+
// const hash = __webpack_require__.h();
|
|
31
|
+
// console.log(`[HMR][${hash}] failure | Error disposing previous module`);
|
|
32
|
+
// throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple HMR Notification Bridge
|
|
3
|
+
*
|
|
4
|
+
* This creates a lightweight WebSocket server that the NativeScript CLI
|
|
5
|
+
* can notify when builds complete, and forwards those to the app.
|
|
6
|
+
*/
|
|
7
|
+
declare class SimpleHMRBridge {
|
|
8
|
+
private wsServer;
|
|
9
|
+
private connectedClients;
|
|
10
|
+
private buildProcess;
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
private startWebSocketServer;
|
|
13
|
+
private startNativeScriptBuild;
|
|
14
|
+
private parseBuildOutput;
|
|
15
|
+
private notifyClients;
|
|
16
|
+
stop(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export { SimpleHMRBridge };
|