@nativescript/vite 0.0.1-alpha.7 → 0.0.2
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/LICENSE +19 -0
- package/README.md +44 -0
- package/{dist/configuration → configuration}/angular.d.ts +1 -1
- package/configuration/angular.js +480 -0
- package/configuration/angular.js.map +1 -0
- package/configuration/base.d.ts +5 -0
- package/configuration/base.js +494 -0
- package/configuration/base.js.map +1 -0
- package/configuration/javascript.d.ts +4 -0
- package/configuration/javascript.js +151 -0
- package/configuration/javascript.js.map +1 -0
- package/{dist/configuration → configuration}/react.d.ts +1 -1
- package/{dist/configuration → configuration}/react.js +18 -17
- package/configuration/react.js.map +1 -0
- package/{dist/configuration → configuration}/solid.d.ts +1 -1
- package/{dist/configuration → configuration}/solid.js +17 -16
- package/configuration/solid.js.map +1 -0
- package/configuration/typescript.d.ts +4 -0
- package/configuration/typescript.js +175 -0
- package/configuration/typescript.js.map +1 -0
- package/{dist/configuration → configuration}/vue.d.ts +1 -1
- package/configuration/vue.js +163 -0
- package/configuration/vue.js.map +1 -0
- package/helpers/angular-linker.d.ts +13 -0
- package/helpers/angular-linker.js +181 -0
- package/helpers/angular-linker.js.map +1 -0
- package/helpers/cli-flags.d.ts +1 -0
- package/helpers/cli-flags.js +15 -0
- package/helpers/cli-flags.js.map +1 -0
- package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
- package/helpers/commonjs-plugins.js.map +1 -0
- package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
- package/{dist/helpers → helpers}/config-as-json.js +7 -6
- package/helpers/config-as-json.js.map +1 -0
- package/helpers/css-platform-plugin.d.ts +10 -0
- package/helpers/css-platform-plugin.js +76 -0
- package/helpers/css-platform-plugin.js.map +1 -0
- package/helpers/css-tree.js +22 -0
- package/helpers/css-tree.js.map +1 -0
- package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
- package/helpers/dynamic-import-plugin.js.map +1 -0
- package/helpers/esbuild-platform-resolver.d.ts +14 -0
- package/helpers/esbuild-platform-resolver.js +93 -0
- package/helpers/esbuild-platform-resolver.js.map +1 -0
- package/{dist/helpers → helpers}/external-configs.js +2 -1
- package/helpers/external-configs.js.map +1 -0
- package/{dist/helpers → helpers}/flavor.d.ts +1 -0
- package/helpers/flavor.js +51 -0
- package/helpers/flavor.js.map +1 -0
- package/{dist/helpers → helpers}/global-defines.d.ts +11 -3
- package/helpers/global-defines.js +24 -0
- package/helpers/global-defines.js.map +1 -0
- package/helpers/logging.d.ts +13 -0
- package/helpers/logging.js +111 -0
- package/helpers/logging.js.map +1 -0
- package/helpers/main-entry.d.ts +10 -0
- package/helpers/main-entry.js +215 -0
- package/helpers/main-entry.js.map +1 -0
- package/{dist/helpers → helpers}/module-resolution.js +4 -3
- package/helpers/module-resolution.js.map +1 -0
- package/{dist/helpers → helpers}/module-runner-patch.d.ts +1 -1
- package/{dist/helpers → helpers}/module-runner-patch.js +10 -12
- package/helpers/module-runner-patch.js.map +1 -0
- package/helpers/nativeclass-transform.d.ts +7 -0
- package/helpers/nativeclass-transform.js +158 -0
- package/helpers/nativeclass-transform.js.map +1 -0
- package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
- package/helpers/nativeclass-transformer-plugin.js +23 -0
- package/helpers/nativeclass-transformer-plugin.js.map +1 -0
- package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
- package/helpers/nativescript-package-resolver.js.map +1 -0
- package/{dist/helpers → helpers}/ns-cli-plugins.d.ts +6 -1
- package/{dist/helpers → helpers}/ns-cli-plugins.js +31 -51
- package/helpers/ns-cli-plugins.js.map +1 -0
- package/helpers/package-platform-aliases.d.ts +10 -0
- package/{dist/helpers → helpers}/package-platform-aliases.js +18 -22
- package/helpers/package-platform-aliases.js.map +1 -0
- package/helpers/postcss-platform-config.d.ts +13 -0
- package/helpers/postcss-platform-config.js +97 -0
- package/helpers/postcss-platform-config.js.map +1 -0
- package/helpers/prelink-angular.d.ts +2 -0
- package/helpers/prelink-angular.js +117 -0
- package/helpers/prelink-angular.js.map +1 -0
- package/helpers/preserve-imports.js +38 -0
- package/helpers/preserve-imports.js.map +1 -0
- package/{dist/helpers → helpers}/project.js +2 -4
- package/helpers/project.js.map +1 -0
- package/helpers/resolver.d.ts +4 -0
- package/{dist/helpers → helpers}/resolver.js +7 -6
- package/helpers/resolver.js.map +1 -0
- package/helpers/theme-core-plugins.d.ts +14 -0
- package/helpers/theme-core-plugins.js +121 -0
- package/helpers/theme-core-plugins.js.map +1 -0
- package/helpers/ts-config-paths.d.ts +10 -0
- package/{dist/helpers → helpers}/ts-config-paths.js +70 -71
- package/helpers/ts-config-paths.js.map +1 -0
- package/{dist/helpers → helpers}/utils.js +14 -27
- package/helpers/utils.js.map +1 -0
- package/{dist/helpers → helpers}/workers.js +15 -16
- package/helpers/workers.js.map +1 -0
- package/{dist/hmr → hmr/client}/css-handler.js +18 -17
- package/hmr/client/css-handler.js.map +1 -0
- package/hmr/client/index.d.ts +13 -0
- package/hmr/client/index.js +1550 -0
- package/hmr/client/index.js.map +1 -0
- package/hmr/client/utils.d.ts +38 -0
- package/hmr/client/utils.js +426 -0
- package/hmr/client/utils.js.map +1 -0
- package/hmr/entry-runtime.d.ts +8 -0
- package/hmr/entry-runtime.js +135 -0
- package/hmr/entry-runtime.js.map +1 -0
- package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
- package/hmr/frameworks/angular/server/strategy.js +101 -0
- package/hmr/frameworks/angular/server/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/index.d.ts +22 -0
- package/hmr/frameworks/vue/client/index.js +1537 -0
- package/hmr/frameworks/vue/client/index.js.map +1 -0
- package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
- package/hmr/frameworks/vue/server/compiler.js +26 -0
- package/hmr/frameworks/vue/server/compiler.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
- package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
- package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
- package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
- package/hmr/frameworks/vue/server/strategy.js +273 -0
- package/hmr/frameworks/vue/server/strategy.js.map +1 -0
- package/hmr/helpers/ast-extract.d.ts +6 -0
- package/hmr/helpers/ast-extract.js +72 -0
- package/hmr/helpers/ast-extract.js.map +1 -0
- package/hmr/helpers/ast-normalizer.d.ts +7 -0
- package/hmr/helpers/ast-normalizer.js +772 -0
- package/hmr/helpers/ast-normalizer.js.map +1 -0
- package/hmr/helpers/babel.d.ts +3 -0
- package/hmr/helpers/babel.js +17 -0
- package/hmr/helpers/babel.js.map +1 -0
- package/hmr/helpers/sanitize.d.ts +6 -0
- package/hmr/helpers/sanitize.js +55 -0
- package/hmr/helpers/sanitize.js.map +1 -0
- package/hmr/helpers/vendor-rewrite.d.ts +1 -0
- package/hmr/helpers/vendor-rewrite.js +35 -0
- package/hmr/helpers/vendor-rewrite.js.map +1 -0
- package/hmr/server/compiler.d.ts +2 -0
- package/hmr/server/compiler.js +75 -0
- package/hmr/server/compiler.js.map +1 -0
- package/hmr/server/constants.d.ts +14 -0
- package/hmr/server/constants.js +23 -0
- package/hmr/server/constants.js.map +1 -0
- package/hmr/server/core-sanitize.d.ts +32 -0
- package/hmr/server/core-sanitize.js +134 -0
- package/hmr/server/core-sanitize.js.map +1 -0
- package/hmr/server/framework-strategy.d.ts +68 -0
- package/hmr/server/framework-strategy.js +2 -0
- package/hmr/server/framework-strategy.js.map +1 -0
- package/hmr/server/index.d.ts +5 -0
- package/hmr/server/index.js +19 -0
- package/hmr/server/index.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +5 -0
- package/{dist/hmr/plugins/plugin-vue.js → hmr/server/vite-plugin.js} +13 -15
- package/hmr/server/vite-plugin.js.map +1 -0
- package/hmr/server/websocket.d.ts +15 -0
- package/hmr/server/websocket.js +5528 -0
- package/hmr/server/websocket.js.map +1 -0
- package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
- package/hmr/shared/runtime/http-only-boot.js +107 -0
- package/hmr/shared/runtime/http-only-boot.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +142 -0
- package/hmr/shared/runtime/root-placeholder.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
- package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
- package/hmr/shared/vendor/manifest-loader.js +38 -0
- package/hmr/shared/vendor/manifest-loader.js.map +1 -0
- package/hmr/shared/vendor/manifest.d.ts +34 -0
- package/hmr/shared/vendor/manifest.js +787 -0
- package/hmr/shared/vendor/manifest.js.map +1 -0
- package/hmr/shared/vendor/registry.d.ts +9 -0
- package/hmr/shared/vendor/registry.js +62 -0
- package/hmr/shared/vendor/registry.js.map +1 -0
- package/hmr/vendor-bootstrap.d.ts +3 -0
- package/hmr/vendor-bootstrap.js +32 -0
- package/hmr/vendor-bootstrap.js.map +1 -0
- package/{dist/index.d.ts → index.d.ts} +2 -0
- package/{dist/index.js → index.js} +3 -0
- package/index.js.map +1 -0
- package/package.json +39 -31
- package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
- package/polyfills/mdn-data-at-rules.js.map +1 -0
- package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
- package/polyfills/mdn-data-properties.js.map +1 -0
- package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
- package/polyfills/mdn-data-syntaxes.js.map +1 -0
- package/{dist/polyfills → polyfills}/module.js +1 -0
- package/polyfills/module.js.map +1 -0
- package/runtime/core-aliases-early.d.ts +1 -0
- package/runtime/core-aliases-early.js +334 -0
- package/runtime/core-aliases-early.js.map +1 -0
- package/shims/angular-animations-stub.d.ts +8 -0
- package/shims/angular-animations-stub.js +14 -0
- package/shims/angular-animations-stub.js.map +1 -0
- package/{dist/shims → shims}/node-module.js +3 -2
- package/shims/node-module.js.map +1 -0
- package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
- package/shims/react-reconciler-constants.js.map +1 -0
- package/{dist/shims → shims}/react-reconciler.js +1 -0
- package/shims/react-reconciler.js.map +1 -0
- package/{dist/shims → shims}/set-value.js +5 -1
- package/shims/set-value.js.map +1 -0
- package/transformers/NativeClass/index.d.ts +2 -0
- package/transformers/NativeClass/index.js +222 -0
- package/transformers/NativeClass/index.js.map +1 -0
- package/dist/configuration/angular.js +0 -30
- package/dist/configuration/base.d.ts +0 -4
- package/dist/configuration/base.js +0 -386
- package/dist/configuration/vue.js +0 -45
- package/dist/helpers/css-tree.js +0 -21
- package/dist/helpers/flavor.js +0 -40
- package/dist/helpers/global-defines.js +0 -20
- package/dist/helpers/main-entry-hmr-includes.d.ts +0 -1
- package/dist/helpers/main-entry-hmr-includes.js +0 -18
- package/dist/helpers/main-entry.d.ts +0 -5
- package/dist/helpers/main-entry.js +0 -82
- package/dist/helpers/package-platform-aliases.d.ts +0 -4
- package/dist/helpers/preserve-imports.js +0 -19
- package/dist/helpers/resolver.d.ts +0 -4
- package/dist/helpers/ts-config-paths.d.ts +0 -4
- package/dist/hmr/client-vue.d.ts +0 -6
- package/dist/hmr/client-vue.js +0 -585
- package/dist/hmr/component-tracker.d.ts +0 -23
- package/dist/hmr/component-tracker.js +0 -193
- package/dist/hmr/message-handler.d.ts +0 -1
- package/dist/hmr/message-handler.js +0 -590
- package/dist/hmr/nsv-hooks.d.ts +0 -2
- package/dist/hmr/nsv-hooks.js +0 -481
- package/dist/hmr/plugins/index.d.ts +0 -1
- package/dist/hmr/plugins/index.js +0 -16
- package/dist/hmr/plugins/plugin-vue.d.ts +0 -2
- package/dist/hmr/plugins/websocket-vue.d.ts +0 -2
- package/dist/hmr/plugins/websocket-vue.js +0 -911
- package/dist/hmr/runtime-vue.d.ts +0 -13
- package/dist/hmr/runtime-vue.js +0 -2306
- package/dist/hmr/types.d.ts +0 -24
- package/dist/hmr/types.js +0 -2
- package/dist/transformers/NativeClass/index.d.ts +0 -5
- package/dist/transformers/NativeClass/index.js +0 -46
- /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
- /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
- /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
- /package/{dist/helpers → helpers}/external-configs.d.ts +0 -0
- /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
- /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
- /package/{dist/helpers → helpers}/preserve-imports.d.ts +0 -0
- /package/{dist/helpers → helpers}/project.d.ts +0 -0
- /package/{dist/helpers → helpers}/utils.d.ts +0 -0
- /package/{dist/helpers → helpers}/workers.d.ts +0 -0
- /package/{dist/hmr → hmr/client}/css-handler.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
- /package/{dist/shims → shims}/node-module.d.ts +0 -0
- /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
- /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
- /package/{dist/shims → shims}/set-value.d.ts +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { getPackageJson, getProjectFilePath, getProjectRootPath } from './project.js';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getProjectFlavor } from './flavor.js';
|
|
5
|
+
// Switched to runtime modules to avoid fragile string injection and enable TS checks
|
|
6
|
+
const projectRoot = getProjectRootPath();
|
|
7
|
+
// main entry (always included regardless of HMR)
|
|
8
|
+
const packageJson = getPackageJson();
|
|
9
|
+
const mainEntry = getProjectFilePath(packageJson.main);
|
|
10
|
+
// Normalize to a project-relative posix path (e.g., "/src/app.ts") for HTTP ESM boot
|
|
11
|
+
const mainEntryRelPosix = (() => {
|
|
12
|
+
try {
|
|
13
|
+
const rel = path.relative(projectRoot, mainEntry).replace(/\\/g, '/');
|
|
14
|
+
return ('/' + rel).replace(/\/+/g, '/');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return '/src/app.ts';
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
const flavor = getProjectFlavor();
|
|
21
|
+
// Optional polyfills support (non-HMR specific but dev friendly)
|
|
22
|
+
const polyfillsPath = getProjectFilePath('src/polyfills.ts');
|
|
23
|
+
const polyfillsExists = fs.existsSync(polyfillsPath);
|
|
24
|
+
const VIRTUAL_ID = 'virtual:entry-with-polyfills';
|
|
25
|
+
const RESOLVED = '\0' + VIRTUAL_ID;
|
|
26
|
+
export function mainEntryPlugin(opts) {
|
|
27
|
+
return {
|
|
28
|
+
name: 'main-entry',
|
|
29
|
+
resolveId(id) {
|
|
30
|
+
if (id === VIRTUAL_ID)
|
|
31
|
+
return RESOLVED;
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
load(id) {
|
|
35
|
+
if (id !== RESOLVED)
|
|
36
|
+
return null;
|
|
37
|
+
// consistent verbose flag to easily reference below
|
|
38
|
+
let imports = "const __nsVerboseLog = typeof __NS_ENV_VERBOSE__ !== 'undefined' && __NS_ENV_VERBOSE__;\n";
|
|
39
|
+
// Banner diagnostics for visibility at runtime
|
|
40
|
+
if (opts.verbose) {
|
|
41
|
+
imports += `console.info('[ns-entry] begin', { platform: ${JSON.stringify(opts.platform)}, dev: ${JSON.stringify(opts.isDevMode)}, hmr: ${JSON.stringify(opts.hmrActive)}, verbose: ${JSON.stringify(opts.verbose)}, mainEntry: ${JSON.stringify(mainEntry)}, mainRel: ${JSON.stringify(mainEntryRelPosix)}, time: new Date().toISOString() });\n`;
|
|
42
|
+
}
|
|
43
|
+
if (opts.hmrActive) {
|
|
44
|
+
// ---- Vendor manifest bootstrap ----
|
|
45
|
+
// Use single self-contained vendor module to avoid extra imports affecting chunking
|
|
46
|
+
imports += "import vendorManifest, { __nsVendorModuleMap } from '@nativescript/vendor';\n";
|
|
47
|
+
imports += "import { installVendorBootstrap } from '@nativescript/vite/hmr/shared/runtime/vendor-bootstrap.js';\n";
|
|
48
|
+
if (opts.verbose) {
|
|
49
|
+
imports += `console.info('[ns-entry] vendor manifest imported', { keys: Object.keys(vendorManifest||{}).length, hasMap: typeof __nsVendorModuleMap === 'object' });\n`;
|
|
50
|
+
}
|
|
51
|
+
imports += 'installVendorBootstrap(vendorManifest, __nsVendorModuleMap, __nsVerboseLog);\n';
|
|
52
|
+
if (opts.verbose) {
|
|
53
|
+
imports += `console.info('[ns-entry] vendor bootstrap installed');\n`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// ---- Core runtime globals (always-needed) ----
|
|
57
|
+
// Load globals early
|
|
58
|
+
imports += "import '@nativescript/core/globals/index';\n";
|
|
59
|
+
if (opts.verbose) {
|
|
60
|
+
imports += `console.info('[ns-entry] core globals loaded');\n`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Ensure the canonical @nativescript/core classes are available on globalThis
|
|
64
|
+
* before any other framework modules execute (like bundle-entry-points) to avoid duplicate realms
|
|
65
|
+
* and lifecycle registration using an uninitialized Application instance.
|
|
66
|
+
* We do this for both HMR and non-HMR builds to guarantee stable bootstrap.
|
|
67
|
+
*/
|
|
68
|
+
imports += "import { installCoreAliasesEarly } from '@nativescript/vite/runtime/core-aliases-early.js';\n";
|
|
69
|
+
imports += 'installCoreAliasesEarly(__nsVerboseLog);\n';
|
|
70
|
+
if (opts.hmrActive) {
|
|
71
|
+
// Placeholder root for HMR to show prior to http loaded es modules take over
|
|
72
|
+
if (opts.verbose) {
|
|
73
|
+
imports += `console.info('[ns-entry] installing placeholder...');\n`;
|
|
74
|
+
}
|
|
75
|
+
imports += "import { installRootPlaceholder } from '@nativescript/vite/hmr/shared/runtime/root-placeholder.js';\n";
|
|
76
|
+
imports += 'installRootPlaceholder(__nsVerboseLog);\n';
|
|
77
|
+
if (opts.verbose) {
|
|
78
|
+
imports += `console.info('[ns-entry] placeholder installed');\n`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Load NS bundle entry points after early hook
|
|
82
|
+
imports += "import '@nativescript/core/bundle-entry-points';\n";
|
|
83
|
+
if (opts.verbose) {
|
|
84
|
+
imports += `console.info('[ns-entry] bundle-entry-points loaded');\n`;
|
|
85
|
+
}
|
|
86
|
+
if (flavor === 'typescript') {
|
|
87
|
+
// Statically import bundler context synchronously before app code
|
|
88
|
+
imports += "import 'virtual:ns-bundler-context';\n";
|
|
89
|
+
}
|
|
90
|
+
// ---- Platform-specific always-needed modules ----
|
|
91
|
+
if (opts.platform === 'android') {
|
|
92
|
+
if (opts.hmrActive) {
|
|
93
|
+
/**
|
|
94
|
+
* Ensure the Java Activity class exists by executing the vendor-packed
|
|
95
|
+
* activity registration module via the vendor registry (not ESM import).
|
|
96
|
+
* This avoids any on-disk vendor.mjs export mismatches and guarantees the
|
|
97
|
+
* class is registered before Android tries to instantiate it.
|
|
98
|
+
*/
|
|
99
|
+
imports += `
|
|
100
|
+
(function __nsEnsureAndroidActivityForHMR(){
|
|
101
|
+
try {
|
|
102
|
+
const g = globalThis;
|
|
103
|
+
const req = (g.__nsVendorRequire || g.__nsRequire);
|
|
104
|
+
if (!req) {
|
|
105
|
+
${opts.verbose ? "console.warn('[ns-entry] vendor require not available yet; activity registration may be deferred');" : ''}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const candidates = [
|
|
109
|
+
'@nativescript/core/ui/frame/activity.android',
|
|
110
|
+
'@nativescript/core/ui/frame/activity.android.js'
|
|
111
|
+
];
|
|
112
|
+
for (const id of candidates) {
|
|
113
|
+
try {
|
|
114
|
+
req(id);
|
|
115
|
+
${opts.verbose ? "console.info('[ns-entry] android activity registered via vendor', id);" : ''}
|
|
116
|
+
break;
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
try { console.error('[ns-entry] failed to require android activity from vendor', e); } catch {}
|
|
121
|
+
}
|
|
122
|
+
})();\n`;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
/**
|
|
126
|
+
* Non-HMR: Defer activity lifecycle wiring until native Application is ready
|
|
127
|
+
* to avoid "application is null" errors at production boot.
|
|
128
|
+
*/
|
|
129
|
+
imports += `
|
|
130
|
+
(function __nsDeferAndroidActivityImport(){
|
|
131
|
+
const load = () => { try { import('@nativescript/core/ui/frame/activity.android.js?ns-keep'); } catch (e) { console.error('[ns-entry] failed to import android activity module', e); } };
|
|
132
|
+
try {
|
|
133
|
+
import('@nativescript/core').then(({ Application: __NS_Application }) => {
|
|
134
|
+
try {
|
|
135
|
+
const hasApp = !!(__NS_Application && __NS_Application.android && __NS_Application.android.nativeApp);
|
|
136
|
+
if (hasApp) {
|
|
137
|
+
${opts.verbose ? "console.info('[ns-entry] android activity import: nativeApp present, loading now');" : ''}
|
|
138
|
+
load();
|
|
139
|
+
} else {
|
|
140
|
+
${opts.verbose ? "console.info('[ns-entry] android activity import: deferring until launch/nativeApp');" : ''}
|
|
141
|
+
try { __NS_Application.on && __NS_Application.on(__NS_Application.launchEvent, load); } catch {}
|
|
142
|
+
try { setTimeout(load, 0); } catch {}
|
|
143
|
+
}
|
|
144
|
+
} catch { try { setTimeout(load, 0); } catch {} }
|
|
145
|
+
}).catch(() => { try { setTimeout(load, 0); } catch {} });
|
|
146
|
+
} catch { try { setTimeout(load, 0); } catch {} }
|
|
147
|
+
})();\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// ---- Optional polyfills ----
|
|
151
|
+
if (polyfillsExists) {
|
|
152
|
+
imports += `import '${polyfillsPath}';\n`;
|
|
153
|
+
if (opts.verbose) {
|
|
154
|
+
imports += `console.info('[ns-entry] polyfills imported from', ${JSON.stringify(polyfillsPath)});\n`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (opts.verbose) {
|
|
158
|
+
imports += "console.info('[ns-entry] no polyfills file found');\n";
|
|
159
|
+
}
|
|
160
|
+
// ---- HMR bootstrap prerequisites ----
|
|
161
|
+
if (opts.hmrActive) {
|
|
162
|
+
// WebSocket polyfill needed for dev hot reload messaging
|
|
163
|
+
imports += "import '@valor/nativescript-websockets';\n";
|
|
164
|
+
if (opts.verbose) {
|
|
165
|
+
imports += "console.info('[ns-entry] websockets polyfill imported');\n";
|
|
166
|
+
}
|
|
167
|
+
// Load HMR client for WebSocket connection to Vite dev server before HTTP-only boot attempts.
|
|
168
|
+
imports += "import 'virtual:ns-hmr-client';\n";
|
|
169
|
+
imports += "console.info('@nativescript/vite HMR client loaded.');\n";
|
|
170
|
+
}
|
|
171
|
+
// ---- Global CSS injection (always-needed if file exists) ----
|
|
172
|
+
const appCssPath = path.resolve(projectRoot, 'src/app.css');
|
|
173
|
+
if (fs.existsSync(appCssPath)) {
|
|
174
|
+
imports += `// Import and apply global CSS before app bootstrap\n`;
|
|
175
|
+
imports += `import appCssContent from './src/app.css?inline';\n`;
|
|
176
|
+
imports += `import { Application } from '@nativescript/core';\n`;
|
|
177
|
+
imports += `if (appCssContent) { try { Application.addCss(appCssContent); } catch (error) { console.error('Error applying CSS:', error); } }\n`;
|
|
178
|
+
if (opts.verbose) {
|
|
179
|
+
imports += `console.info('[ns-entry] app.css applied');\n`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// ---- Application main entry ----
|
|
183
|
+
if (opts.hmrActive) {
|
|
184
|
+
// HTTP-only dev boot: try to import the entire app over HTTP; if not reachable, keep retrying.
|
|
185
|
+
if (opts.verbose) {
|
|
186
|
+
imports += `console.info('[ns-entry] including HTTP-only boot', { platform: ${JSON.stringify(opts.platform)}, mainRel: ${JSON.stringify(mainEntryRelPosix)} });\n`;
|
|
187
|
+
}
|
|
188
|
+
const defaultHost = opts.platform === 'android' ? '10.0.2.2' : 'localhost';
|
|
189
|
+
imports += "import { startHttpOnlyBoot } from '@nativescript/vite/hmr/shared/runtime/http-only-boot.js';\n";
|
|
190
|
+
imports += `startHttpOnlyBoot(${JSON.stringify(opts.platform)}, ${JSON.stringify(mainEntryRelPosix)}, ${JSON.stringify((process.env.NS_HMR_HOST || '')) || JSON.stringify('')} || ${JSON.stringify(defaultHost)}, __nsVerboseLog);\n`;
|
|
191
|
+
if (opts.verbose) {
|
|
192
|
+
imports += `console.info('[ns-entry] HTTP-only boot code appended');\n`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
if (opts.verbose) {
|
|
197
|
+
imports += `console.info('[ns-entry] Importing main entry', '${mainEntry}');\n`;
|
|
198
|
+
}
|
|
199
|
+
imports += `import '${mainEntry}';\n`;
|
|
200
|
+
}
|
|
201
|
+
if (opts.isDevMode) {
|
|
202
|
+
// debug tools support
|
|
203
|
+
imports += "import '@nativescript/core/inspector_modules';\n";
|
|
204
|
+
if (opts.verbose) {
|
|
205
|
+
imports += "console.info('[ns-entry] inspector modules imported');\n";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (opts.verbose) {
|
|
209
|
+
imports += `console.info('[ns-entry] end', { time: new Date().toISOString() });\n`;
|
|
210
|
+
}
|
|
211
|
+
return imports;
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=main-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main-entry.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/main-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,qFAAqF;AACrF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EAAE,CAAW,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,sBAAsB,CAAC;gBAChP,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,OAAO,IAAI,4DAA4D,CAAC;gBACzE,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,OAAO,IAAI,oDAAoD,SAAS,OAAO,CAAC;gBACjF,CAAC;gBACD,OAAO,IAAI,WAAW,SAAS,MAAM,CAAC;YACvC,CAAC;YAED,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,sBAAsB;gBACtB,OAAO,IAAI,kDAAkD,CAAC;gBAC9D,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,OAAO,IAAI,0DAA0D,CAAC;gBACvE,CAAC;YACF,CAAC;YAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,OAAO,IAAI,uEAAuE,CAAC;YACpF,CAAC;YAED,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
3
|
// Node.js-style module resolution: walk up directory tree looking for node_modules
|
|
4
4
|
export function findPackageInNodeModules(packageName, startDir) {
|
|
5
5
|
let currentDir = startDir;
|
|
6
6
|
while (currentDir !== path.dirname(currentDir)) {
|
|
7
7
|
// Stop at filesystem root
|
|
8
|
-
const nodeModulesDir = path.join(currentDir,
|
|
8
|
+
const nodeModulesDir = path.join(currentDir, 'node_modules');
|
|
9
9
|
const packagePath = path.join(nodeModulesDir, packageName);
|
|
10
10
|
if (fs.existsSync(packagePath)) {
|
|
11
11
|
return packagePath;
|
|
@@ -15,3 +15,4 @@ export function findPackageInNodeModules(packageName, startDir) {
|
|
|
15
15
|
}
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
+
//# sourceMappingURL=module-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-resolution.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/module-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,mFAAmF;AACnF,MAAM,UAAU,wBAAwB,CAAC,WAAmB,EAAE,QAAgB;IAC7E,IAAI,UAAU,GAAG,QAAQ,CAAC;IAC1B,OAAO,UAAU,KAAK,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAChD,0BAA0B;QAC1B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QAE3D,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAChC,OAAO,WAAW,CAAC;QACpB,CAAC;QAED,wBAAwB;QACxB,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -3,36 +3,33 @@
|
|
|
3
3
|
// "Cannot use 'in' operator to search for 'cache' in undefined".
|
|
4
4
|
export function moduleRunnerPatchPlugin() {
|
|
5
5
|
return {
|
|
6
|
-
name:
|
|
7
|
-
apply:
|
|
8
|
-
enforce:
|
|
6
|
+
name: 'ns-module-runner-patch',
|
|
7
|
+
apply: 'build',
|
|
8
|
+
enforce: 'post',
|
|
9
9
|
generateBundle(_opts, bundle) {
|
|
10
10
|
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
11
|
-
if (fileName !==
|
|
11
|
+
if (fileName !== 'vendor.mjs')
|
|
12
12
|
continue;
|
|
13
|
-
if (chunk.type !==
|
|
13
|
+
if (chunk.type !== 'chunk' || typeof chunk.code !== 'string')
|
|
14
14
|
continue;
|
|
15
15
|
let code = chunk.code;
|
|
16
16
|
// Try to locate the function definition (non-minified dev build keeps names)
|
|
17
17
|
// Handle both forms: function getModuleInformation(id, options) { ... }
|
|
18
18
|
// and class method or object method: getModuleInformation(id, options) { ... }
|
|
19
|
-
const patterns = [
|
|
20
|
-
/function\s+getModuleInformation\s*\(([^)]*)\)\s*\{/,
|
|
21
|
-
/getModuleInformation\s*\(([^)]*)\)\s*\{/,
|
|
22
|
-
];
|
|
19
|
+
const patterns = [/function\s+getModuleInformation\s*\(([^)]*)\)\s*\{/, /getModuleInformation\s*\(([^)]*)\)\s*\{/];
|
|
23
20
|
let replaced = false;
|
|
24
21
|
for (const re of patterns) {
|
|
25
22
|
const m = re.exec(code);
|
|
26
23
|
if (!m)
|
|
27
24
|
continue;
|
|
28
|
-
const rawParams = (m[1] ||
|
|
29
|
-
.split(
|
|
25
|
+
const rawParams = (m[1] || '')
|
|
26
|
+
.split(',')
|
|
30
27
|
.map((s) => s.trim())
|
|
31
28
|
.filter(Boolean);
|
|
32
29
|
const idParam = rawParams[0];
|
|
33
30
|
const second = rawParams[1];
|
|
34
31
|
const third = rawParams[2];
|
|
35
|
-
let guard =
|
|
32
|
+
let guard = '\n';
|
|
36
33
|
if (third && second) {
|
|
37
34
|
// Signature: (id, importer, options)
|
|
38
35
|
guard += `if (typeof ${second} !== 'string') ${second} = undefined;\n`;
|
|
@@ -63,3 +60,4 @@ export function moduleRunnerPatchPlugin() {
|
|
|
63
60
|
};
|
|
64
61
|
}
|
|
65
62
|
export default moduleRunnerPatchPlugin;
|
|
63
|
+
//# sourceMappingURL=module-runner-patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-runner-patch.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/module-runner-patch.ts"],"names":[],"mappings":"AAEA,kFA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AAI,KAAK,IAAI,MAAM,EAAE,CAAC;wBACrB,qCAAqC;wBACrC,KAAK,IAAI,cAAc,MAAM,kBAAkB,MAAM,iBAAiB,CAAC;wBACvE,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,cAAc,KAAK,iBAAiB,KAAK,UAAU,CAAC;wBAChF,KAAK,IAAI,oBAAoB,KAAK,MAAM,KAAK,uBAAuB,CAAC;oBACtE,CAAC;yBAAM,IAAI,MAAM,EAAE,CAAC;wBACnB,2BAA2B;wBAC3B,KAAK,IAAI,GAAG,MAAM,MAAM,MAAM,cAAc,MAAM,iBAAiB,MAAM,UAAU,CAAC;wBACpF,KAAK,IAAI,oBAAoB,MAAM,MAAM,MAAM,uBAAuB,CAAC;oBACxE,CAAC;yBAAM,CAAC;wBACP,8CAA8C;wBAC9C,KAAK,IAAI,2HAA2H,CAAC;wBACrI,KAAK,IAAI,gPAAgP,CAAC;oBAC3P,CAAC;oBAED,6DAA6D;oBAC7D,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;oBACpC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACxD,QAAQ,GAAG,IAAI,CAAC;oBAChB,MAAM;gBACP,CAAC;gBAED,IAAI,QAAQ,EAAE,CAAC;oBACb,KAAa,CAAC,IAAI,GAAG,IAAI,CAAC;gBAC5B,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
// We retain the advanced transformer for future enhancement but perform a safer
|
|
3
|
+
// localized textual + AST-assisted downlevel here to avoid edge corruption of
|
|
4
|
+
// computed property names (e.g. ['frame-in']).
|
|
5
|
+
// import nativeClassTransformer from '../transformers/NativeClass/index.js';
|
|
6
|
+
import { getCliFlags } from './cli-flags.js';
|
|
7
|
+
/**
|
|
8
|
+
* Apply the NativeClass transformer to a source string. Returns null if no change performed.
|
|
9
|
+
*/
|
|
10
|
+
export function transformNativeClassSource(code, fileName) {
|
|
11
|
+
// Avoid transforming platform-specific sources for the non-target platform.
|
|
12
|
+
// Example: don't run Android-specific transforms on iOS builds and vice versa.
|
|
13
|
+
try {
|
|
14
|
+
const flags = getCliFlags();
|
|
15
|
+
const platform = flags.android ? 'android' : 'ios';
|
|
16
|
+
if (fileName.includes('.android.') && platform !== 'android')
|
|
17
|
+
return null;
|
|
18
|
+
if ((fileName.includes('.ios.') || fileName.includes('.visionos.')) && platform === 'android')
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
// If cli flags cannot be read for any reason, fall back to original behavior.
|
|
23
|
+
}
|
|
24
|
+
// If this is JS and we see a __decorate* call that references NativeClass, strip it safely.
|
|
25
|
+
const isJS = /\.(js|mjs|cjs)$/.test(fileName);
|
|
26
|
+
if (isJS && /__decorate[a-zA-Z$]*\s*\(/.test(code) && /\bNativeClass\b/.test(code)) {
|
|
27
|
+
try {
|
|
28
|
+
const sfJS = ts.createSourceFile(fileName, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
29
|
+
let mutated = false;
|
|
30
|
+
const transformer = (ctx) => {
|
|
31
|
+
const factory = ctx.factory ?? ts.factory;
|
|
32
|
+
const visit = (node) => {
|
|
33
|
+
if (ts.isCallExpression(node)) {
|
|
34
|
+
const callee = node.expression;
|
|
35
|
+
const calleeName = ts.isIdentifier(callee) ? callee.text : ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) ? `${callee.expression.text}.${callee.name.text}` : undefined;
|
|
36
|
+
if (calleeName && /^__decorate/.test(calleeName) && node.arguments.length >= 1) {
|
|
37
|
+
const firstArg = node.arguments[0];
|
|
38
|
+
if (ts.isArrayLiteralExpression(firstArg)) {
|
|
39
|
+
const kept = firstArg.elements.filter((el) => !(ts.isIdentifier(el) && el.text === 'NativeClass'));
|
|
40
|
+
if (kept.length !== firstArg.elements.length) {
|
|
41
|
+
mutated = true;
|
|
42
|
+
if (kept.length === 0 && node.arguments.length >= 2) {
|
|
43
|
+
return ts.visitNode(node.arguments[1], visit);
|
|
44
|
+
}
|
|
45
|
+
const newArr = factory.updateArrayLiteralExpression(firstArg, kept);
|
|
46
|
+
return factory.updateCallExpression(node, node.expression, node.typeArguments, [newArr, ...node.arguments.slice(1)]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return ts.visitEachChild(node, visit, ctx);
|
|
52
|
+
};
|
|
53
|
+
return (node) => ts.visitNode(node, visit);
|
|
54
|
+
};
|
|
55
|
+
const res = ts.transform(sfJS, [transformer]);
|
|
56
|
+
const transformed = res.transformed[0];
|
|
57
|
+
if (!mutated) {
|
|
58
|
+
res.dispose();
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
62
|
+
const output = printer.printFile(transformed);
|
|
63
|
+
res.dispose();
|
|
64
|
+
return { code: output, map: null };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// fall through to TS path if anything goes wrong
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Pre-strip textual @NativeClass decorator (and variants with args) immediately preceding a class,
|
|
71
|
+
// replacing just that occurrence with a stable marker. This ensures we never leave a runtime
|
|
72
|
+
// identifier behind if TypeScript skips or rearranges decorators in this compile phase.
|
|
73
|
+
// Matches stacked decorators and multi-line @NativeClass(...) args.
|
|
74
|
+
// Match @NativeClass (optionally with args, multi-line) not preceded by another decorator line capturing stacked sequences.
|
|
75
|
+
// We'll place the marker right before the class declaration start to simplify slicing.
|
|
76
|
+
const DECORATOR_BLOCK_RE = /(^|\n)((?:\s*@[\w$][^\n]*\n)*)\s*@NativeClass(?:\([\s\S]*?\))?\s*(?=\n(?:\s*@[\w$][^\n]*\n)*\s*(?:export\s+)?class\s)/g;
|
|
77
|
+
let working = code.replace(DECORATOR_BLOCK_RE, (full, prefix, stacked) => {
|
|
78
|
+
// Keep other decorators, inject marker after them.
|
|
79
|
+
return `${prefix || '\n'}${stacked || ''}/*__NativeClass__*/`;
|
|
80
|
+
});
|
|
81
|
+
// If neither original nor marker is present, skip transform early.
|
|
82
|
+
if (!working.includes('@NativeClass') && !working.includes('/*__NativeClass__*/'))
|
|
83
|
+
return null;
|
|
84
|
+
try {
|
|
85
|
+
const sf = ts.createSourceFile(fileName, working, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
86
|
+
const edits = [];
|
|
87
|
+
// Collect all class declarations (top-level or nested) for potential transform
|
|
88
|
+
const collect = (node) => {
|
|
89
|
+
if (ts.isClassDeclaration(node)) {
|
|
90
|
+
const fullStart = node.getFullStart ? node.getFullStart() : node.pos;
|
|
91
|
+
const preamble = working.slice(fullStart, Math.min(node.getStart(sf) + 64, node.end));
|
|
92
|
+
if (/\/\*__NativeClass__\*\//.test(preamble)) {
|
|
93
|
+
const original = working.slice(fullStart, node.end);
|
|
94
|
+
const stripped = original.replace(/\/\*__NativeClass__\*\/\s*/g, '').replace(/^\s*@NativeClass(?:\([\s\S]*?\))?\s*$/gm, '');
|
|
95
|
+
const hadExport = /^\s*export\s+class\b/.test(stripped);
|
|
96
|
+
const down = ts
|
|
97
|
+
.transpileModule(stripped, {
|
|
98
|
+
compilerOptions: {
|
|
99
|
+
module: ts.ModuleKind.ESNext,
|
|
100
|
+
target: ts.ScriptTarget.ES5,
|
|
101
|
+
experimentalDecorators: true,
|
|
102
|
+
emitDecoratorMetadata: true,
|
|
103
|
+
noEmitHelpers: true,
|
|
104
|
+
useDefineForClassFields: false,
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
.outputText.replace(/Object\.defineProperty\(([^,]+),\s*(["'`][^"'`]+["'`]|[A-Za-z_$][A-Za-z0-9_$]*),\s*{([^}]*)}\)/g, (m, obj, key, body) => {
|
|
108
|
+
if (/enumerable:\s*false/.test(body)) {
|
|
109
|
+
body = body.replace(/enumerable:\s*false/, 'enumerable: true');
|
|
110
|
+
}
|
|
111
|
+
return `Object.defineProperty(${obj}, ${key}, {${body}})`;
|
|
112
|
+
});
|
|
113
|
+
let cleaned = down.replace(/export \{\};?\s*$/m, '');
|
|
114
|
+
if (hadExport) {
|
|
115
|
+
const name = node.name?.text;
|
|
116
|
+
if (name && !new RegExp(`export\s*{\s*${name}\s*}`, 'm').test(cleaned)) {
|
|
117
|
+
cleaned += `\nexport { ${name} };\n`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
edits.push({ start: fullStart, end: node.end, text: cleaned });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
ts.forEachChild(node, collect);
|
|
124
|
+
};
|
|
125
|
+
collect(sf);
|
|
126
|
+
if (!edits.length)
|
|
127
|
+
return null;
|
|
128
|
+
// Apply edits sequentially
|
|
129
|
+
let output = working;
|
|
130
|
+
// Sort edits by start descending so indices remain valid
|
|
131
|
+
for (const e of edits.sort((a, b) => b.start - a.start)) {
|
|
132
|
+
output = output.slice(0, e.start) + e.text + output.slice(e.end);
|
|
133
|
+
}
|
|
134
|
+
// Remove any remaining markers
|
|
135
|
+
output = output.replace(/\/\*__NativeClass__\*\/\s*/g, '').replace(/@NativeClass(?:\([\s\S]*?\))?\s*/g, '');
|
|
136
|
+
// Deduplicate accidental duplicate re-export lines (e.g. `export { Foo };` appearing twice)
|
|
137
|
+
// This can happen if the transpiled snippet already emitted an export and we also appended one.
|
|
138
|
+
const seenExportLines = new Set();
|
|
139
|
+
output = output
|
|
140
|
+
.split(/\r?\n/)
|
|
141
|
+
.filter((line) => {
|
|
142
|
+
const trimmed = line.trim();
|
|
143
|
+
if (/^export\s*{\s*[A-Za-z_$][A-Za-z0-9_$]*\s*};?$/.test(trimmed)) {
|
|
144
|
+
if (seenExportLines.has(trimmed)) {
|
|
145
|
+
return false; // drop duplicate
|
|
146
|
+
}
|
|
147
|
+
seenExportLines.add(trimmed);
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
})
|
|
151
|
+
.join('\n');
|
|
152
|
+
return { code: output, map: null };
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=nativeclass-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeclass-transform.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/nativeclass-transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,gFAAgF;AAChF,8EAA8E;AAC9E,+CAA+C;AAC/C,6EAA6E;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAY,EAAE,QAAgB;IACxE,4EAA4E;IAC5E,+EAA+E;IAC/E,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAA+C,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/F,IAAI,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;IAC5G,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,8EAA8E;IAC/E,CAAC;IAED,4FAA4F;IAC5F,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,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AAC,CAAC,GAAG,CAAC,CAAC;QAClE,CAAC;QACD,+BAA+B;QAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,6BAA6B,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;QAE5G,4FAA4F;QAC5F,gGAAgG;QAChG,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;QAC1C,MAAM,GAAG,MAAM;aACb,KAAK,CAAC,OAAO,CAAC;aACd,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAChB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,+CAA+C,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnE,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClC,OAAO,KAAK,CAAC,CAAC,iBAAiB;gBAChC,CAAC;gBACD,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;YACD,OAAO,IAAI,CAAC;QACb,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { transformNativeClassSource } from './nativeclass-transform.js';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps NativeClass TS transformer into a Vite plugin.
|
|
4
|
+
*/
|
|
5
|
+
export function createNativeClassTransformerPlugin() {
|
|
6
|
+
return {
|
|
7
|
+
name: 'ns-nativeclass-transformer',
|
|
8
|
+
enforce: 'pre',
|
|
9
|
+
async transform(code, id) {
|
|
10
|
+
if (!code)
|
|
11
|
+
return null;
|
|
12
|
+
const bareId = id.split('?')[0];
|
|
13
|
+
const isTSFile = /\.(ts|tsx)$/.test(bareId);
|
|
14
|
+
const isJSFile = /\.(js|mjs|cjs)$/.test(bareId);
|
|
15
|
+
const isVueTSBlock = !isTSFile && /[?&]lang\.(ts|tsx)\b/.test(id);
|
|
16
|
+
if (!isTSFile && !isVueTSBlock && !isJSFile)
|
|
17
|
+
return null;
|
|
18
|
+
const res = transformNativeClassSource(code, bareId);
|
|
19
|
+
return res; // may be null if no @NativeClass present
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=nativeclass-transformer-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeclass-transformer-plugin.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/nativeclass-transformer-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE;;GAEG;AACH,MAAM,UAAU,kCAAkC;IACjD,OAAO;QACN,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,EAAU;YACvC,IAAI,CAAC,IAAI;gBAAE,OAAO,IAAI,CAAC;YACvB,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5C,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAChD,MAAM,YAAY,GAAG,CAAC,QAAQ,IAAI,sBAAsB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClE,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,IAAI,CAAC,QAAQ;gBAAE,OAAO,IAAI,CAAC;YACzD,MAAM,GAAG,GAAG,0BAA0B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACrD,OAAO,GAAG,CAAC,CAAC,yCAAyC;QACtD,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import { getProjectRootPath } from
|
|
4
|
-
import { findPackageInNodeModules } from
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { getProjectRootPath } from './project.js';
|
|
4
|
+
import { findPackageInNodeModules } from './module-resolution.js';
|
|
5
5
|
const projectRoot = getProjectRootPath();
|
|
6
6
|
// Cache for package resolution results
|
|
7
7
|
const packageCache = new Map();
|
|
8
8
|
export function nativescriptPackageResolver(platform) {
|
|
9
9
|
return {
|
|
10
|
-
name:
|
|
11
|
-
enforce:
|
|
10
|
+
name: 'nativescript-package-resolver',
|
|
11
|
+
enforce: 'pre', // Force this plugin to run before all others
|
|
12
12
|
resolveId(id, importer) {
|
|
13
13
|
// Only handle direct package imports (not relative paths)
|
|
14
|
-
if (id.startsWith(
|
|
14
|
+
if (id.startsWith('.') || id.startsWith('/') || id.includes(':')) {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
// Extract package name properly
|
|
18
18
|
let packageName;
|
|
19
|
-
if (id.startsWith(
|
|
19
|
+
if (id.startsWith('@')) {
|
|
20
20
|
// Scoped package: @scope/package or @scope/package/subpath
|
|
21
|
-
const parts = id.split(
|
|
21
|
+
const parts = id.split('/');
|
|
22
22
|
if (parts.length >= 2) {
|
|
23
|
-
packageName = parts[0] +
|
|
23
|
+
packageName = parts[0] + '/' + parts[1]; // @scope/package
|
|
24
24
|
// Only handle root package imports, not subpaths
|
|
25
25
|
if (parts.length > 2) {
|
|
26
26
|
return null; // This is a subpath import like @scope/package/file
|
|
@@ -32,7 +32,7 @@ export function nativescriptPackageResolver(platform) {
|
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
// Regular package: package or package/subpath
|
|
35
|
-
const parts = id.split(
|
|
35
|
+
const parts = id.split('/');
|
|
36
36
|
packageName = parts[0];
|
|
37
37
|
// Only handle root package imports, not subpaths
|
|
38
38
|
if (parts.length > 1) {
|
|
@@ -49,21 +49,21 @@ export function nativescriptPackageResolver(platform) {
|
|
|
49
49
|
}
|
|
50
50
|
const packagePath = findPackageInNodeModules(packageName, projectRoot);
|
|
51
51
|
if (packagePath) {
|
|
52
|
-
const packageJsonPath = path.join(packagePath,
|
|
52
|
+
const packageJsonPath = path.join(packagePath, 'package.json');
|
|
53
53
|
if (fs.existsSync(packageJsonPath)) {
|
|
54
54
|
try {
|
|
55
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath,
|
|
55
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
56
56
|
const mainField = packageJson.main;
|
|
57
57
|
if (mainField) {
|
|
58
58
|
const mainFilePath = path.join(packagePath, mainField);
|
|
59
59
|
// Case 1: Main field has no extension - try to add extensions
|
|
60
|
-
if (!mainField.includes(
|
|
60
|
+
if (!mainField.includes('.')) {
|
|
61
61
|
// Try platform-specific file first
|
|
62
62
|
const platformFile = path.join(packagePath, `${mainField}.${platform}.js`);
|
|
63
63
|
if (fs.existsSync(platformFile)) {
|
|
64
64
|
const result = {
|
|
65
65
|
id: platformFile,
|
|
66
|
-
resolvedBy:
|
|
66
|
+
resolvedBy: 'nativescript-package-resolver',
|
|
67
67
|
};
|
|
68
68
|
packageCache.set(packageName, result);
|
|
69
69
|
// console.log(
|
|
@@ -76,7 +76,7 @@ export function nativescriptPackageResolver(platform) {
|
|
|
76
76
|
if (fs.existsSync(jsFile)) {
|
|
77
77
|
const result = {
|
|
78
78
|
id: jsFile,
|
|
79
|
-
resolvedBy:
|
|
79
|
+
resolvedBy: 'nativescript-package-resolver',
|
|
80
80
|
};
|
|
81
81
|
packageCache.set(packageName, result);
|
|
82
82
|
// console.log(
|
|
@@ -95,7 +95,7 @@ export function nativescriptPackageResolver(platform) {
|
|
|
95
95
|
if (fs.existsSync(platformFile)) {
|
|
96
96
|
const result = {
|
|
97
97
|
id: platformFile,
|
|
98
|
-
resolvedBy:
|
|
98
|
+
resolvedBy: 'nativescript-package-resolver',
|
|
99
99
|
};
|
|
100
100
|
packageCache.set(packageName, result);
|
|
101
101
|
// console.log(
|
|
@@ -137,3 +137,4 @@ export function nativescriptPackageResolver(platform) {
|
|
|
137
137
|
},
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
+
//# sourceMappingURL=nativescript-package-resolver.js.map
|