@nativescript/vite 0.0.1 → 1.0.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/LICENSE +19 -0
- package/README.md +81 -0
- package/{dist/configuration → configuration}/angular.d.ts +1 -1
- package/configuration/angular.js +371 -0
- package/configuration/angular.js.map +1 -0
- package/configuration/base.d.ts +5 -0
- package/configuration/base.js +491 -0
- package/configuration/base.js.map +1 -0
- package/configuration/javascript.d.ts +4 -0
- package/configuration/javascript.js +152 -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 +176 -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/angular-linker.d.ts +13 -0
- package/helpers/angular/angular-linker.js +189 -0
- package/helpers/angular/angular-linker.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +4 -0
- package/helpers/angular/shared-linker.js +39 -0
- package/helpers/angular/shared-linker.js.map +1 -0
- package/helpers/angular/util.d.ts +1 -0
- package/helpers/angular/util.js +67 -0
- package/helpers/angular/util.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/helpers/external-configs.d.ts +6 -0
- package/helpers/external-configs.js +34 -0
- 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/helpers/global-defines.d.ts +25 -0
- package/helpers/global-defines.js +29 -0
- package/helpers/global-defines.js.map +1 -0
- package/helpers/init.d.ts +1 -0
- package/helpers/init.js +119 -0
- package/helpers/init.js.map +1 -0
- package/helpers/logging.d.ts +13 -0
- package/helpers/logging.js +115 -0
- package/helpers/logging.js.map +1 -0
- package/helpers/main-entry.d.ts +10 -0
- package/helpers/main-entry.js +223 -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/helpers/module-runner-patch.d.ts +3 -0
- package/helpers/module-runner-patch.js +63 -0
- 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/helpers/ns-cli-plugins.d.ts +14 -0
- package/helpers/ns-cli-plugins.js +165 -0
- 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 +19 -23
- 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.d.ts +2 -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 +73 -72
- package/helpers/ts-config-paths.js.map +1 -0
- package/{dist/helpers → helpers}/utils.d.ts +10 -0
- package/helpers/utils.js +143 -0
- package/helpers/utils.js.map +1 -0
- package/{dist/helpers → helpers}/workers.js +15 -16
- package/helpers/workers.js.map +1 -0
- package/hmr/client/css-handler.d.ts +4 -0
- package/hmr/client/css-handler.js +78 -0
- package/hmr/client/css-handler.js.map +1 -0
- package/hmr/client/index.d.ts +13 -0
- package/hmr/client/index.js +1723 -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/client/index.d.ts +8 -0
- package/hmr/frameworks/angular/client/index.js +59 -0
- package/hmr/frameworks/angular/client/index.js.map +1 -0
- package/hmr/frameworks/angular/server/linker.d.ts +1 -0
- package/hmr/frameworks/angular/server/linker.js +101 -0
- package/hmr/frameworks/angular/server/linker.js.map +1 -0
- package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
- package/hmr/frameworks/angular/server/strategy.js +187 -0
- package/hmr/frameworks/angular/server/strategy.js.map +1 -0
- package/hmr/frameworks/solid/server/strategy.d.ts +2 -0
- package/hmr/frameworks/solid/server/strategy.js +56 -0
- package/hmr/frameworks/solid/server/strategy.js.map +1 -0
- package/hmr/frameworks/typescript/server/strategy.d.ts +2 -0
- package/hmr/frameworks/typescript/server/strategy.js +125 -0
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/index.d.ts +22 -0
- package/hmr/frameworks/vue/client/index.js +1541 -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 +272 -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 +23 -0
- package/hmr/server/index.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +5 -0
- package/hmr/server/vite-plugin.js +44 -0
- package/hmr/server/vite-plugin.js.map +1 -0
- package/hmr/server/websocket.d.ts +21 -0
- package/hmr/server/websocket.js +5619 -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 +35 -0
- package/hmr/shared/vendor/manifest.js +811 -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/index.js +19 -0
- package/index.js.map +1 -0
- package/package.json +42 -30
- 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 +68 -0
- package/shims/angular-animations-stub.js +140 -0
- package/shims/angular-animations-stub.js.map +1 -0
- package/shims/node-module.d.ts +5 -0
- package/shims/node-module.js +13 -0
- 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 -13
- package/dist/configuration/base.js +0 -228
- package/dist/configuration/old-without-merge-base.d.ts +0 -13
- package/dist/configuration/old-without-merge-base.js +0 -249
- 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.d.ts +0 -14
- package/dist/helpers/global-defines.js +0 -18
- package/dist/helpers/main-entry.d.ts +0 -5
- package/dist/helpers/main-entry.js +0 -75
- package/dist/helpers/ns-cli-plugins.d.ts +0 -17
- package/dist/helpers/ns-cli-plugins.js +0 -128
- package/dist/helpers/package-platform-aliases.d.ts +0 -4
- package/dist/helpers/resolver.d.ts +0 -4
- package/dist/helpers/ts-config-paths.d.ts +0 -4
- package/dist/helpers/utils.js +0 -94
- package/dist/hmr/hmr-angular.d.ts +0 -1
- package/dist/hmr/hmr-angular.js +0 -34
- package/dist/hmr/hmr-bridge.d.ts +0 -18
- package/dist/hmr/hmr-bridge.js +0 -154
- package/dist/hmr/hmr-client.d.ts +0 -5
- package/dist/hmr/hmr-client.js +0 -93
- package/dist/hmr/hmr-server.d.ts +0 -20
- package/dist/hmr/hmr-server.js +0 -179
- package/dist/index.js +0 -5
- 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}/module-resolution.d.ts +0 -0
- /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
- /package/{dist/helpers → helpers}/project.d.ts +0 -0
- /package/{dist/helpers → helpers}/workers.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}/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,811 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
5
|
+
import { createHash } from 'crypto';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { registerVendorManifest, clearVendorManifest, getVendorManifest } from './registry.js';
|
|
8
|
+
export const VENDOR_MANIFEST_ID = '@nativescript/vendor-manifest';
|
|
9
|
+
export const VENDOR_MANIFEST_VIRTUAL_ID = '\0' + VENDOR_MANIFEST_ID;
|
|
10
|
+
export const VENDOR_BUNDLE_ID = '@nativescript/vendor';
|
|
11
|
+
export const VENDOR_BUNDLE_VIRTUAL_ID = '\0' + VENDOR_BUNDLE_ID;
|
|
12
|
+
export const SERVER_VENDOR_PATH = '/@nativescript/vendor.mjs';
|
|
13
|
+
export const SERVER_MANIFEST_PATH = '/@nativescript/vendor-manifest.json';
|
|
14
|
+
export const DEFAULT_VENDOR_FILENAME = 'ns-vendor.mjs';
|
|
15
|
+
export const DEFAULT_MANIFEST_FILENAME = 'ns-vendor-manifest.json';
|
|
16
|
+
// Do not force-include @nativescript/core in the dev vendor bundle.
|
|
17
|
+
// Keeping core out of vendor avoids duplicate side-effect registrations (e.g.,
|
|
18
|
+
// com.tns.FragmentClass, com.tns.NativeScriptActivity) across bundle.mjs and vendor.
|
|
19
|
+
// Reserved for any future always-include packages; keep empty by default so
|
|
20
|
+
// framework-specific tooling like @angular/compiler are only pulled in when
|
|
21
|
+
// the corresponding framework is actually used.
|
|
22
|
+
const ALWAYS_INCLUDE = new Set([]);
|
|
23
|
+
const ALWAYS_EXCLUDE = new Set([
|
|
24
|
+
'@nativescript/android',
|
|
25
|
+
'@nativescript/ios',
|
|
26
|
+
'@nativescript/types',
|
|
27
|
+
'@nativescript/webpack',
|
|
28
|
+
// Angular browser animations are not used in NativeScript; excluding reduces
|
|
29
|
+
// memory pressure and avoids bringing partial declarations into vendor.
|
|
30
|
+
'@angular/animations',
|
|
31
|
+
'@angular/platform-browser/animations',
|
|
32
|
+
// Not needed at runtime with linked partials; reduce vendor size/memory.
|
|
33
|
+
'@angular/platform-browser-dynamic',
|
|
34
|
+
// Native add-on helpers pulled by ws or others; exclude in NS dev vendor
|
|
35
|
+
'bufferutil',
|
|
36
|
+
'utf-8-validate',
|
|
37
|
+
'node-gyp-build',
|
|
38
|
+
'bufferutil',
|
|
39
|
+
'utf-8-validate',
|
|
40
|
+
'node-gyp-build',
|
|
41
|
+
'@babel/core',
|
|
42
|
+
'@babel/helper-plugin-utils',
|
|
43
|
+
'@babel/generator',
|
|
44
|
+
'@babel/helper-string-parser',
|
|
45
|
+
'@babel/helper-validator-identifier',
|
|
46
|
+
'@babel/parser',
|
|
47
|
+
'@babel/plugin-syntax-typescript',
|
|
48
|
+
'@babel/plugin-transform-typescript',
|
|
49
|
+
'@babel/types',
|
|
50
|
+
// Heavy dependency not needed in vendor dev bundle; fetch via HTTP loader instead
|
|
51
|
+
'rxjs',
|
|
52
|
+
'nativescript',
|
|
53
|
+
'typescript',
|
|
54
|
+
'ts-node',
|
|
55
|
+
'vue-tsc',
|
|
56
|
+
'ws',
|
|
57
|
+
'@types/node',
|
|
58
|
+
]);
|
|
59
|
+
const INDEX_ALIAS_SUFFIXES = ['/index', '/index.js', '/index.android.js', '/index.ios.js', '/index.visionos.js'];
|
|
60
|
+
export function vendorManifestPlugin(options) {
|
|
61
|
+
let cachedResult = null;
|
|
62
|
+
let generating = null;
|
|
63
|
+
const ensureResult = async (reason) => {
|
|
64
|
+
if (cachedResult) {
|
|
65
|
+
if (!getVendorManifest()) {
|
|
66
|
+
registerVendorManifest(cachedResult.manifest);
|
|
67
|
+
}
|
|
68
|
+
return cachedResult;
|
|
69
|
+
}
|
|
70
|
+
if (!generating) {
|
|
71
|
+
if (options.verbose) {
|
|
72
|
+
console.log(`[vendor] generating vendor bundle (${reason}) for platform ${options.platform}...`);
|
|
73
|
+
}
|
|
74
|
+
generating = generateVendorBundle({
|
|
75
|
+
projectRoot: options.projectRoot,
|
|
76
|
+
platform: options.platform,
|
|
77
|
+
mode: options.mode,
|
|
78
|
+
verbose: options.verbose,
|
|
79
|
+
flavor: options.flavor,
|
|
80
|
+
})
|
|
81
|
+
.then((result) => {
|
|
82
|
+
cachedResult = result;
|
|
83
|
+
registerVendorManifest(result.manifest);
|
|
84
|
+
generating = null;
|
|
85
|
+
if (options.verbose) {
|
|
86
|
+
console.log(`[vendor] generated bundle with ${result.entries.length} modules`);
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
generating = null;
|
|
92
|
+
console.error('[vendor] failed to generate vendor bundle', error);
|
|
93
|
+
throw error;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return generating;
|
|
97
|
+
};
|
|
98
|
+
const resetCache = () => {
|
|
99
|
+
cachedResult = null;
|
|
100
|
+
clearVendorManifest();
|
|
101
|
+
};
|
|
102
|
+
const respondWithVendor = async (_server, req, res) => {
|
|
103
|
+
try {
|
|
104
|
+
const result = await ensureResult('server');
|
|
105
|
+
if (req.url === SERVER_VENDOR_PATH) {
|
|
106
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
107
|
+
res.end(result.code);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (req.url === SERVER_MANIFEST_PATH) {
|
|
111
|
+
res.setHeader('Content-Type', 'application/json');
|
|
112
|
+
res.end(JSON.stringify(result.manifest, null, 2));
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('[vendor] error serving vendor artifacts', error);
|
|
118
|
+
res.statusCode = 500;
|
|
119
|
+
res.end('// vendor manifest generation failed');
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
name: 'nativescript-vendor-manifest',
|
|
126
|
+
enforce: 'pre',
|
|
127
|
+
configResolved() { },
|
|
128
|
+
async configureServer(server) {
|
|
129
|
+
await ensureResult('server-start');
|
|
130
|
+
server.middlewares.use(async (req, res, next) => {
|
|
131
|
+
if (req.url === SERVER_VENDOR_PATH || req.url === SERVER_MANIFEST_PATH) {
|
|
132
|
+
const handled = await respondWithVendor(server, req, res);
|
|
133
|
+
if (!handled) {
|
|
134
|
+
next();
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
next();
|
|
139
|
+
});
|
|
140
|
+
const packageJsonPath = path.resolve(options.projectRoot, 'package.json');
|
|
141
|
+
server.watcher.add(packageJsonPath);
|
|
142
|
+
server.watcher.on('change', (file) => {
|
|
143
|
+
if (path.resolve(file) !== packageJsonPath) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
resetCache();
|
|
147
|
+
ensureResult('package.json change').catch((error) => {
|
|
148
|
+
console.error('[vendor] failed to regenerate vendor bundle', error);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
async buildStart() {
|
|
153
|
+
await ensureResult('build-start');
|
|
154
|
+
},
|
|
155
|
+
resolveId(source) {
|
|
156
|
+
if (source === VENDOR_MANIFEST_ID || source === VENDOR_MANIFEST_VIRTUAL_ID) {
|
|
157
|
+
return VENDOR_MANIFEST_VIRTUAL_ID;
|
|
158
|
+
}
|
|
159
|
+
if (source === VENDOR_BUNDLE_ID || source === VENDOR_BUNDLE_VIRTUAL_ID) {
|
|
160
|
+
return VENDOR_BUNDLE_VIRTUAL_ID;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
},
|
|
164
|
+
async load(id) {
|
|
165
|
+
if (id === VENDOR_MANIFEST_VIRTUAL_ID) {
|
|
166
|
+
const result = await ensureResult('load-manifest');
|
|
167
|
+
return `export default ${JSON.stringify(result.manifest)};`;
|
|
168
|
+
}
|
|
169
|
+
if (id === VENDOR_BUNDLE_VIRTUAL_ID) {
|
|
170
|
+
const result = await ensureResult('load-bundle');
|
|
171
|
+
// Return a single self-contained module that includes both the vendor module map
|
|
172
|
+
// and the vendor manifest to avoid extra imports that can influence chunking.
|
|
173
|
+
// - result.code exports `__nsVendorModuleMap`
|
|
174
|
+
// - we append an inline manifest export
|
|
175
|
+
return `${result.code}
|
|
176
|
+
export const vendorManifest = ${JSON.stringify(result.manifest)};
|
|
177
|
+
export default vendorManifest;
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
},
|
|
182
|
+
async generateBundle() {
|
|
183
|
+
// Default to emitting assets unless explicitly disabled.
|
|
184
|
+
const shouldEmit = options.emitAssets !== false;
|
|
185
|
+
if (!shouldEmit) {
|
|
186
|
+
if (options.verbose) {
|
|
187
|
+
console.log('[vendor] skip emitting ns-vendor assets (HMR/dev mode)');
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Emit a MINIMAL on-disk vendor asset for Android SBG to scan, to avoid
|
|
192
|
+
// duplicate Java proxy generation with bundle.mjs. The dev server will
|
|
193
|
+
// still serve the full vendor bundle from memory for HMR.
|
|
194
|
+
const minimalVendorCode = createSbgVendorAssetCode(options.platform);
|
|
195
|
+
this.emitFile({
|
|
196
|
+
type: 'asset',
|
|
197
|
+
fileName: DEFAULT_VENDOR_FILENAME,
|
|
198
|
+
source: minimalVendorCode,
|
|
199
|
+
});
|
|
200
|
+
// Also emit a manifest (debug aid); not consumed by SBG.
|
|
201
|
+
const result = await ensureResult('generate-bundle-manifest');
|
|
202
|
+
this.emitFile({
|
|
203
|
+
type: 'asset',
|
|
204
|
+
fileName: DEFAULT_MANIFEST_FILENAME,
|
|
205
|
+
source: JSON.stringify(result.manifest, null, 2),
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async function generateVendorBundle(options) {
|
|
211
|
+
const { projectRoot, platform, mode, flavor } = options;
|
|
212
|
+
const entries = collectVendorModules(projectRoot, platform, flavor);
|
|
213
|
+
const entryCode = createVendorEntry(entries);
|
|
214
|
+
const plugins = [
|
|
215
|
+
// Resolve virtual modules and Angular shims used by the vendor entry.
|
|
216
|
+
createVendorEsbuildPlugin(projectRoot),
|
|
217
|
+
];
|
|
218
|
+
// Only run the Angular linker in the vendor bundle when the active flavor
|
|
219
|
+
// is Angular. Solid and other flavors do not require @angular/compiler,
|
|
220
|
+
// and attempting to bundle it pulls in Babel tooling that depends on
|
|
221
|
+
// Node built-ins like fs/path/url in a browser-like environment.
|
|
222
|
+
if (flavor === 'angular') {
|
|
223
|
+
plugins.push(angularLinkerEsbuildPlugin(projectRoot));
|
|
224
|
+
}
|
|
225
|
+
const buildResult = await esbuild.build({
|
|
226
|
+
stdin: {
|
|
227
|
+
contents: entryCode,
|
|
228
|
+
resolveDir: projectRoot,
|
|
229
|
+
sourcefile: 'ns-vendor-entry.ts',
|
|
230
|
+
loader: 'ts',
|
|
231
|
+
},
|
|
232
|
+
platform: 'neutral',
|
|
233
|
+
format: 'esm',
|
|
234
|
+
bundle: true,
|
|
235
|
+
target: 'es2019',
|
|
236
|
+
treeShaking: false,
|
|
237
|
+
sourcemap: false,
|
|
238
|
+
write: false,
|
|
239
|
+
logLevel: 'silent',
|
|
240
|
+
// Move license comments to the end of the file to avoid mid-module annotations
|
|
241
|
+
// that Rollup warns it "cannot interpret due to the position of the comment".
|
|
242
|
+
// This preserves license text while preventing noisy warnings.
|
|
243
|
+
legalComments: 'eof',
|
|
244
|
+
conditions: ['module', 'import', platform, mode],
|
|
245
|
+
mainFields: ['module', 'browser', 'main'],
|
|
246
|
+
resolveExtensions: resolveExtensionsForPlatform(platform),
|
|
247
|
+
loader: {
|
|
248
|
+
'.css': 'text',
|
|
249
|
+
'.json': 'json',
|
|
250
|
+
},
|
|
251
|
+
define: {
|
|
252
|
+
'process.env.NODE_ENV': JSON.stringify(mode),
|
|
253
|
+
},
|
|
254
|
+
plugins,
|
|
255
|
+
external: ['fs', 'fs/promises', 'path', 'url', 'module', 'node:fs', 'node:fs/promises', 'node:path', 'node:url', 'node:module', 'assert', 'process', 'v8', 'util'],
|
|
256
|
+
});
|
|
257
|
+
if (!buildResult.outputFiles?.length) {
|
|
258
|
+
throw new Error('Vendor bundle generation produced no output');
|
|
259
|
+
}
|
|
260
|
+
const vendorCode = buildResult.outputFiles[0].text;
|
|
261
|
+
const hash = createHash('sha1').update(vendorCode).digest('hex');
|
|
262
|
+
const manifest = buildManifest(entries, hash);
|
|
263
|
+
return {
|
|
264
|
+
code: vendorCode,
|
|
265
|
+
manifest,
|
|
266
|
+
entries,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function collectVendorModules(projectRoot, platform, flavor) {
|
|
270
|
+
const packageJsonPath = path.resolve(projectRoot, 'package.json');
|
|
271
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
272
|
+
const projectRequire = createRequire(packageJsonPath);
|
|
273
|
+
const vendor = new Set();
|
|
274
|
+
const visited = new Set();
|
|
275
|
+
const queue = [];
|
|
276
|
+
const isPackageRootSpecifier = (name) => {
|
|
277
|
+
if (!name)
|
|
278
|
+
return false;
|
|
279
|
+
if (name.startsWith('@')) {
|
|
280
|
+
// Scoped: @scope/name is root; anything deeper is subpath
|
|
281
|
+
const parts = name.split('/');
|
|
282
|
+
return parts.length === 2;
|
|
283
|
+
}
|
|
284
|
+
// Unscoped: no slash means root; any slash means subpath
|
|
285
|
+
return !name.includes('/');
|
|
286
|
+
};
|
|
287
|
+
const isAngularFlavor = flavor === 'angular';
|
|
288
|
+
const addCandidate = (name) => {
|
|
289
|
+
if (!name || shouldSkipDependency(name)) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// Avoid pulling Angular compiler/runtime into the dev vendor bundle when
|
|
293
|
+
// the current project flavor is not Angular (for example, solid). This
|
|
294
|
+
// prevents esbuild from trying to bundle @angular/compiler and its Babel
|
|
295
|
+
// toolchain, which requires Node built-ins like fs/path/url.
|
|
296
|
+
if (!isAngularFlavor && (name === '@angular/compiler' || name.startsWith('@angular/'))) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const isRoot = isPackageRootSpecifier(name);
|
|
300
|
+
if (!visited.has(name)) {
|
|
301
|
+
visited.add(name);
|
|
302
|
+
}
|
|
303
|
+
vendor.add(name);
|
|
304
|
+
// Only traverse peer deps for package roots; subpaths should not attempt package.json resolution
|
|
305
|
+
if (isRoot) {
|
|
306
|
+
queue.push(name);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const addDeps = (deps) => {
|
|
310
|
+
if (!deps) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
for (const name of Object.keys(deps)) {
|
|
314
|
+
addCandidate(name);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
addDeps(pkg.dependencies);
|
|
318
|
+
addDeps(pkg.optionalDependencies);
|
|
319
|
+
for (const name of ALWAYS_INCLUDE) {
|
|
320
|
+
addCandidate(name);
|
|
321
|
+
}
|
|
322
|
+
// Ensure Android Activity proxy is present for SBG scanning in dev/HMR
|
|
323
|
+
// and non-HMR builds alike: explicitly include the side-effect module
|
|
324
|
+
// that registers `com.tns.NativeScriptActivity`.
|
|
325
|
+
if (platform === 'android') {
|
|
326
|
+
addCandidate('@nativescript/core/ui/frame/activity.android');
|
|
327
|
+
}
|
|
328
|
+
if (pkg.dependencies?.['nativescript-vue'] && pkg.devDependencies?.vue) {
|
|
329
|
+
addCandidate('vue');
|
|
330
|
+
}
|
|
331
|
+
if (pkg.dependencies?.['@nativescript/angular']) {
|
|
332
|
+
if (pkg.dependencies?.['@angular/core']) {
|
|
333
|
+
addCandidate('@angular/core');
|
|
334
|
+
}
|
|
335
|
+
if (pkg.dependencies?.['@angular/common']) {
|
|
336
|
+
addCandidate('@angular/common');
|
|
337
|
+
}
|
|
338
|
+
// RxJS is large and not required inside the vendor bundle for dev HMR.
|
|
339
|
+
// Avoid bundling to reduce memory pressure; let app import via HTTP loader.
|
|
340
|
+
}
|
|
341
|
+
if (pkg.dependencies?.['react-nativescript']) {
|
|
342
|
+
if (pkg.dependencies?.react) {
|
|
343
|
+
addCandidate('react');
|
|
344
|
+
}
|
|
345
|
+
if (pkg.dependencies?.['react-dom']) {
|
|
346
|
+
addCandidate('react-dom');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
parseEnvList(process.env.NS_VENDOR_INCLUDE).forEach(addCandidate);
|
|
350
|
+
const projectDeps = {
|
|
351
|
+
dependencies: new Set(Object.keys(pkg.dependencies ?? {})),
|
|
352
|
+
optional: new Set(Object.keys(pkg.optionalDependencies ?? {})),
|
|
353
|
+
dev: new Set(Object.keys(pkg.devDependencies ?? {})),
|
|
354
|
+
};
|
|
355
|
+
while (queue.length) {
|
|
356
|
+
const specifier = queue.shift();
|
|
357
|
+
const dependencyPkg = readDependencyPackageJson(specifier, projectRequire);
|
|
358
|
+
if (!dependencyPkg) {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const peerDependencies = Object.keys(dependencyPkg.peerDependencies ?? {});
|
|
362
|
+
for (const peer of peerDependencies) {
|
|
363
|
+
if (shouldSkipDependency(peer)) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (projectDeps.dependencies.has(peer) || projectDeps.optional.has(peer) || projectDeps.dev.has(peer)) {
|
|
367
|
+
addCandidate(peer);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
parseEnvList(process.env.NS_VENDOR_EXCLUDE).forEach((name) => {
|
|
372
|
+
vendor.delete(name);
|
|
373
|
+
});
|
|
374
|
+
return Array.from(vendor).sort();
|
|
375
|
+
}
|
|
376
|
+
function shouldSkipDependency(name) {
|
|
377
|
+
if (!name) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
if (ALWAYS_EXCLUDE.has(name)) {
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
if (name.startsWith('.')) {
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
if (name.startsWith('file:')) {
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
if (name.startsWith('workspace:')) {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (name.startsWith('link:')) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
function readDependencyPackageJson(specifier, projectRequire) {
|
|
398
|
+
try {
|
|
399
|
+
const packageJsonPath = projectRequire.resolve(`${specifier}/package.json`);
|
|
400
|
+
return JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (process.env.VITE_DEBUG_LOGS) {
|
|
404
|
+
console.warn(`[vendor] unable to resolve ${specifier} package.json`, error);
|
|
405
|
+
}
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function parseEnvList(value) {
|
|
410
|
+
if (!value) {
|
|
411
|
+
return [];
|
|
412
|
+
}
|
|
413
|
+
return value
|
|
414
|
+
.split(',')
|
|
415
|
+
.map((token) => token.trim())
|
|
416
|
+
.filter(Boolean);
|
|
417
|
+
}
|
|
418
|
+
function createVendorEntry(entries) {
|
|
419
|
+
if (!entries.length) {
|
|
420
|
+
return `export const __nsVendorModuleMap = {};
|
|
421
|
+
`;
|
|
422
|
+
}
|
|
423
|
+
const imports = entries.map((specifier, index) => `import * as __nsVendor_${index} from ${JSON.stringify(specifier)};`).join('\n');
|
|
424
|
+
const modules = entries.map((specifier, index) => `${JSON.stringify(specifier)}: __nsVendor_${index}`).join(',\n ');
|
|
425
|
+
return `${imports}\n\nexport const __nsVendorModuleMap = {\n ${modules}\n};\n`;
|
|
426
|
+
}
|
|
427
|
+
function resolveExtensionsForPlatform(platform) {
|
|
428
|
+
const base = ['.tsx', '.jsx', '.ts', '.js', '.mjs', '.cjs', '.json'];
|
|
429
|
+
const extensions = new Set(base);
|
|
430
|
+
if (platform === 'android') {
|
|
431
|
+
['.android.tsx', '.android.jsx', '.android.ts', '.android.js'].forEach((ext) => extensions.add(ext));
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
['.ios.tsx', '.ios.jsx', '.ios.ts', '.ios.js', '.visionos.tsx', '.visionos.jsx', '.visionos.ts', '.visionos.js'].forEach((ext) => extensions.add(ext));
|
|
435
|
+
}
|
|
436
|
+
return Array.from(extensions);
|
|
437
|
+
}
|
|
438
|
+
function buildManifest(entries, hash) {
|
|
439
|
+
const modules = {};
|
|
440
|
+
const aliases = {};
|
|
441
|
+
for (const specifier of entries) {
|
|
442
|
+
modules[specifier] = {
|
|
443
|
+
id: specifier,
|
|
444
|
+
exports: { '*': true },
|
|
445
|
+
};
|
|
446
|
+
const canonical = stripIndexSuffix(specifier);
|
|
447
|
+
if (canonical !== specifier) {
|
|
448
|
+
modules[canonical] ?? (modules[canonical] = {
|
|
449
|
+
id: canonical,
|
|
450
|
+
exports: { '*': true },
|
|
451
|
+
});
|
|
452
|
+
aliases[specifier] = canonical;
|
|
453
|
+
aliases[canonical] = canonical;
|
|
454
|
+
}
|
|
455
|
+
for (const suffix of INDEX_ALIAS_SUFFIXES) {
|
|
456
|
+
const alias = canonical + suffix;
|
|
457
|
+
if (alias !== specifier) {
|
|
458
|
+
aliases[alias] || (aliases[alias] = canonical);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
version: 1,
|
|
464
|
+
createdAt: new Date().toISOString(),
|
|
465
|
+
hash,
|
|
466
|
+
modules,
|
|
467
|
+
aliases,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
// Produce a tiny vendor file for Android SBG scanning to generate required Java proxies
|
|
471
|
+
// without duplicating other proxies already present in bundle.mjs.
|
|
472
|
+
function createSbgVendorAssetCode(platform) {
|
|
473
|
+
const lines = [];
|
|
474
|
+
lines.push('// ns-vendor.mjs (minimal) - emitted for Android SBG scanning only');
|
|
475
|
+
lines.push('// Avoid importing @nativescript/core root to prevent duplicate Java proxies.');
|
|
476
|
+
if (platform === 'android') {
|
|
477
|
+
// Ensure Activity proxy is generated by SBG.
|
|
478
|
+
lines.push("import '@nativescript/core/ui/frame/activity.android';");
|
|
479
|
+
}
|
|
480
|
+
// Export an empty vendor module map for consistency; unused by SBG.
|
|
481
|
+
lines.push('export const __nsVendorModuleMap = {};\nexport default {};\n');
|
|
482
|
+
return lines.join('\n');
|
|
483
|
+
}
|
|
484
|
+
function createVendorEsbuildPlugin(projectRoot) {
|
|
485
|
+
return {
|
|
486
|
+
name: 'ns-vendor-resolver',
|
|
487
|
+
setup(build) {
|
|
488
|
+
const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
489
|
+
build.onResolve({ filter: /^~\/package\.json$/ }, () => ({
|
|
490
|
+
path: path.resolve(projectRoot, 'package.json'),
|
|
491
|
+
}));
|
|
492
|
+
build.onResolve({ filter: /^module$/ }, () => ({
|
|
493
|
+
path: 'ns-vendor-module-shim',
|
|
494
|
+
namespace: 'ns-vendor',
|
|
495
|
+
}));
|
|
496
|
+
build.onLoad({ filter: /^ns-vendor-module-shim$/, namespace: 'ns-vendor' }, () => ({
|
|
497
|
+
contents: vendorModuleShim,
|
|
498
|
+
loader: 'js',
|
|
499
|
+
}));
|
|
500
|
+
// Stub Angular animations in vendor to avoid bundling browser-only code.
|
|
501
|
+
// Provide named exports expected by @nativescript/angular to satisfy esbuild.
|
|
502
|
+
const PB_ANIMATIONS_ID = 'ns-animations-pb-shim';
|
|
503
|
+
const ANIMATIONS_BROWSER_ID = 'ns-animations-browser-shim';
|
|
504
|
+
const ANIMATIONS_ID = 'ns-animations-noop';
|
|
505
|
+
// @angular/platform-browser/animations -> provide concrete named stubs
|
|
506
|
+
build.onResolve({ filter: /^@angular\/platform-browser\/animations(?:\/.*)?$/ }, (args) => {
|
|
507
|
+
if (debug) {
|
|
508
|
+
try {
|
|
509
|
+
console.log('[vendor] map', args.path, '->', PB_ANIMATIONS_ID);
|
|
510
|
+
}
|
|
511
|
+
catch { }
|
|
512
|
+
}
|
|
513
|
+
return { path: PB_ANIMATIONS_ID, namespace: 'ns-vendor' };
|
|
514
|
+
});
|
|
515
|
+
build.onLoad({ filter: new RegExp(`^${PB_ANIMATIONS_ID}$`), namespace: 'ns-vendor' }, () => ({
|
|
516
|
+
contents: [
|
|
517
|
+
'export default {};',
|
|
518
|
+
// Commonly imported symbols by @nativescript/angular
|
|
519
|
+
'export class AnimationBuilder {};',
|
|
520
|
+
'export const \u0275BrowserAnimationBuilder = class {};',
|
|
521
|
+
'export const \u0275AnimationEngine = class {};',
|
|
522
|
+
'export const \u0275AnimationRendererFactory = class {};',
|
|
523
|
+
'export const \u0275WebAnimationsStyleNormalizer = class {};',
|
|
524
|
+
// Typical platform-browser/animations APIs exported; safe no-ops
|
|
525
|
+
'export class BrowserAnimationsModule {};',
|
|
526
|
+
'export class NoopAnimationsModule {};',
|
|
527
|
+
'export const provideAnimations = (..._args) => [];',
|
|
528
|
+
'export const provideNoopAnimations = (..._args) => [];',
|
|
529
|
+
// Marker used by some Angular internals
|
|
530
|
+
'export const ANIMATION_MODULE_TYPE = void 0;',
|
|
531
|
+
].join('\n'),
|
|
532
|
+
loader: 'js',
|
|
533
|
+
}));
|
|
534
|
+
// @angular/animations/browser -> provide ɵ* engine/renderer/style normalizer stubs
|
|
535
|
+
build.onResolve({ filter: /^@angular\/animations\/browser(?:\/.*)?$/ }, (args) => {
|
|
536
|
+
if (debug) {
|
|
537
|
+
try {
|
|
538
|
+
console.log('[vendor] map', args.path, '->', ANIMATIONS_BROWSER_ID);
|
|
539
|
+
}
|
|
540
|
+
catch { }
|
|
541
|
+
}
|
|
542
|
+
return { path: ANIMATIONS_BROWSER_ID, namespace: 'ns-vendor' };
|
|
543
|
+
});
|
|
544
|
+
build.onLoad({ filter: new RegExp(`^${ANIMATIONS_BROWSER_ID}$`), namespace: 'ns-vendor' }, () => ({
|
|
545
|
+
contents: [
|
|
546
|
+
'export default {};',
|
|
547
|
+
'export class AnimationDriver {};',
|
|
548
|
+
'export const \u0275AnimationRendererFactory = class {};',
|
|
549
|
+
'export const \u0275AnimationStyleNormalizer = class {};',
|
|
550
|
+
'export const \u0275WebAnimationsStyleNormalizer = class {};',
|
|
551
|
+
'export const \u0275AnimationEngine = class {};',
|
|
552
|
+
// Convenience alias if any consumers import non-ɵ name
|
|
553
|
+
'export const AnimationStyleNormalizer = \u0275AnimationStyleNormalizer;',
|
|
554
|
+
].join('\n'),
|
|
555
|
+
loader: 'js',
|
|
556
|
+
}));
|
|
557
|
+
// @angular/animations -> broad no-op surface
|
|
558
|
+
build.onResolve(
|
|
559
|
+
// Keep generic mapping for @angular/animations base; /browser is handled above
|
|
560
|
+
{ filter: /^@angular\/animations(?:$|\/)$/ }, (args) => {
|
|
561
|
+
if (debug) {
|
|
562
|
+
try {
|
|
563
|
+
console.log('[vendor] map', args.path, '->', ANIMATIONS_ID);
|
|
564
|
+
}
|
|
565
|
+
catch { }
|
|
566
|
+
}
|
|
567
|
+
return { path: ANIMATIONS_ID, namespace: 'ns-vendor' };
|
|
568
|
+
});
|
|
569
|
+
build.onLoad({ filter: new RegExp(`^${ANIMATIONS_ID}$`), namespace: 'ns-vendor' }, () => ({
|
|
570
|
+
contents: [
|
|
571
|
+
'export default {};',
|
|
572
|
+
// Provide names sometimes (incorrectly) imported from @angular/animations by wrappers
|
|
573
|
+
'export class AnimationBuilder {};',
|
|
574
|
+
'export const \u0275BrowserAnimationBuilder = class {};',
|
|
575
|
+
'export const \u0275AnimationEngine = class {};',
|
|
576
|
+
'export const \u0275AnimationRendererFactory = class {};',
|
|
577
|
+
'export const \u0275WebAnimationsStyleNormalizer = class {};',
|
|
578
|
+
'export const ANIMATION_MODULE_TYPE = void 0;',
|
|
579
|
+
// Export a few common tokens as harmless stubs
|
|
580
|
+
'export const animate = (..._a) => ({});',
|
|
581
|
+
'export const state = (..._a) => ({});',
|
|
582
|
+
'export const style = (..._a) => ({});',
|
|
583
|
+
'export const transition = (..._a) => ({});',
|
|
584
|
+
'export const trigger = (..._a) => ({});',
|
|
585
|
+
'export const sequence = (..._a) => ({});',
|
|
586
|
+
'export const group = (..._a) => ({});',
|
|
587
|
+
'export const query = (..._a) => ({});',
|
|
588
|
+
'export const stagger = (..._a) => ({});',
|
|
589
|
+
'export const keyframes = (..._a) => ({});',
|
|
590
|
+
].join('\n'),
|
|
591
|
+
loader: 'js',
|
|
592
|
+
}));
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Minimal esbuild plugin to run Angular linker (Babel) over partial-compiled
|
|
598
|
+
* Angular packages in node_modules. This converts ɵɵngDeclare* calls into
|
|
599
|
+
* ɵɵdefine* so runtime doesn't require the JIT compiler.
|
|
600
|
+
*/
|
|
601
|
+
function angularLinkerEsbuildPlugin(projectRoot) {
|
|
602
|
+
// Lazily resolve Babel and Angular linker from the project to avoid hard deps
|
|
603
|
+
let babel = null;
|
|
604
|
+
let createLinker = null;
|
|
605
|
+
async function ensureDeps() {
|
|
606
|
+
if (babel && createLinker)
|
|
607
|
+
return;
|
|
608
|
+
try {
|
|
609
|
+
const req = createRequire(projectRoot + '/package.json');
|
|
610
|
+
// Resolve from the application project first
|
|
611
|
+
const babelPath = req.resolve('@babel/core');
|
|
612
|
+
const linkerPath = req.resolve('@angular/compiler-cli/linker/babel');
|
|
613
|
+
babel = (await import(babelPath));
|
|
614
|
+
const linkerMod = await import(linkerPath);
|
|
615
|
+
createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin || null;
|
|
616
|
+
}
|
|
617
|
+
catch {
|
|
618
|
+
// As a fallback, try local resolution (hoisted installs)
|
|
619
|
+
try {
|
|
620
|
+
babel = (await import('@babel/core'));
|
|
621
|
+
}
|
|
622
|
+
catch { }
|
|
623
|
+
try {
|
|
624
|
+
const linkerMod = await import('@angular/compiler-cli/linker/babel');
|
|
625
|
+
createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin || null;
|
|
626
|
+
}
|
|
627
|
+
catch { }
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
// Restrict to Angular framework packages to minimize esbuild memory usage.
|
|
631
|
+
const FILTER = /node_modules\/(?:@angular|@nativescript\/angular)\/.*\.[mc]?js$/;
|
|
632
|
+
return {
|
|
633
|
+
name: 'ns-angular-linker',
|
|
634
|
+
async setup(build) {
|
|
635
|
+
const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
636
|
+
await ensureDeps();
|
|
637
|
+
if (!babel || !createLinker) {
|
|
638
|
+
// Nothing to do if deps unavailable
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
build.onLoad({ filter: FILTER }, async (args) => {
|
|
642
|
+
try {
|
|
643
|
+
const source = await readFile(args.path, 'utf8');
|
|
644
|
+
// Fast-path: only run linker when partial declarations are present
|
|
645
|
+
if (!(source.includes('\u0275\u0275ngDeclare') || source.includes('ɵɵngDeclare'))) {
|
|
646
|
+
return { contents: source, loader: 'js' };
|
|
647
|
+
}
|
|
648
|
+
const plugin = createLinker({
|
|
649
|
+
// Link everything the filter captures; plugin will no-op otherwise
|
|
650
|
+
// shouldLink is inferred by plugin when left unset for Babel version
|
|
651
|
+
sourceMapping: false,
|
|
652
|
+
});
|
|
653
|
+
if (debug) {
|
|
654
|
+
try {
|
|
655
|
+
console.log('[ns-angular-linker][vendor] linking', args.path);
|
|
656
|
+
}
|
|
657
|
+
catch { }
|
|
658
|
+
}
|
|
659
|
+
const result = await babel.transformAsync(source, {
|
|
660
|
+
filename: args.path,
|
|
661
|
+
configFile: false,
|
|
662
|
+
babelrc: false,
|
|
663
|
+
sourceMaps: false,
|
|
664
|
+
compact: false,
|
|
665
|
+
plugins: [plugin],
|
|
666
|
+
});
|
|
667
|
+
return {
|
|
668
|
+
contents: (result && result.code) || source,
|
|
669
|
+
loader: 'js',
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
catch (e) {
|
|
673
|
+
// On any failure, return original source to avoid breaking the build
|
|
674
|
+
return { contents: await readFile(args.path, 'utf8'), loader: 'js' };
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
const vendorModuleShim = `
|
|
681
|
+
const g = globalThis;
|
|
682
|
+
const BACKSLASH = String.fromCharCode(92);
|
|
683
|
+
|
|
684
|
+
function toForwardSlashes(input) {
|
|
685
|
+
return String(input ?? '').split(BACKSLASH).join('/');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function getNativeScriptRequire() {
|
|
689
|
+
const nsRequire = typeof g.require === "function" ? g.require : null;
|
|
690
|
+
if (nsRequire) {
|
|
691
|
+
return nsRequire;
|
|
692
|
+
}
|
|
693
|
+
const legacy = g.__nsRequire;
|
|
694
|
+
if (typeof legacy === "function") {
|
|
695
|
+
return legacy;
|
|
696
|
+
}
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function getDocumentsPath() {
|
|
701
|
+
const cached = g.__NS_DOCUMENTS_PATH__;
|
|
702
|
+
if (typeof cached === "string" && cached.length) {
|
|
703
|
+
return toForwardSlashes(cached);
|
|
704
|
+
}
|
|
705
|
+
try {
|
|
706
|
+
const core = g.require ? g.require("@nativescript/core") : null;
|
|
707
|
+
const docsFolder = core?.knownFolders?.documents?.();
|
|
708
|
+
const docPath = docsFolder?.path;
|
|
709
|
+
if (docPath) {
|
|
710
|
+
const normalized = toForwardSlashes(docPath);
|
|
711
|
+
g.__NS_DOCUMENTS_PATH__ = normalized;
|
|
712
|
+
return normalized;
|
|
713
|
+
}
|
|
714
|
+
} catch (_err) {
|
|
715
|
+
// ignore - fallback to raw specifier
|
|
716
|
+
}
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function collapseSegments(input) {
|
|
721
|
+
const segments = [];
|
|
722
|
+
const parts = input.split('/');
|
|
723
|
+
for (const part of parts) {
|
|
724
|
+
if (!part || part === ".") {
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
if (part === "..") {
|
|
728
|
+
if (segments.length && segments[segments.length - 1] !== "..") {
|
|
729
|
+
segments.pop();
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
segments.push(part);
|
|
734
|
+
}
|
|
735
|
+
const leadingSlash = input.startsWith('/');
|
|
736
|
+
return (leadingSlash ? '/' : '') + segments.join('/');
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function normalizeSpecifier(spec) {
|
|
740
|
+
let value = String(spec ?? "");
|
|
741
|
+
value = toForwardSlashes(value);
|
|
742
|
+
const docsPath = getDocumentsPath();
|
|
743
|
+
if (value.startsWith("__NSDOC__/")) {
|
|
744
|
+
if (docsPath) {
|
|
745
|
+
value = docsPath + '/' + value.slice("__NSDOC__/".length);
|
|
746
|
+
} else {
|
|
747
|
+
value = value.slice("__NSDOC__/".length);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (value.startsWith("~/") && docsPath) {
|
|
751
|
+
value = docsPath + '/' + value.slice(2);
|
|
752
|
+
}
|
|
753
|
+
if (value.startsWith("file://")) {
|
|
754
|
+
const stripped = value.slice("file://".length);
|
|
755
|
+
value = stripped.startsWith('/') ? stripped : '/' + stripped;
|
|
756
|
+
}
|
|
757
|
+
if (value.includes("/../") || value.includes("/./")) {
|
|
758
|
+
value = collapseSegments(value);
|
|
759
|
+
}
|
|
760
|
+
return value;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export function createRequire(_url) {
|
|
764
|
+
const nsRequire = getNativeScriptRequire();
|
|
765
|
+
if (!nsRequire) {
|
|
766
|
+
return function () {
|
|
767
|
+
throw new Error("NativeScript require() is not available in this context");
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
const req = function (id) {
|
|
771
|
+
const normalizedId = normalizeSpecifier(id);
|
|
772
|
+
if (
|
|
773
|
+
normalizedId.includes("../data/patch.json") ||
|
|
774
|
+
normalizedId.includes("css-tree/lib/data/patch.json")
|
|
775
|
+
) {
|
|
776
|
+
return {
|
|
777
|
+
atrules: {},
|
|
778
|
+
properties: {},
|
|
779
|
+
types: {},
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
if (normalizedId.includes("mdn-data/")) {
|
|
783
|
+
return {};
|
|
784
|
+
}
|
|
785
|
+
if (
|
|
786
|
+
normalizedId.endsWith("/package.json") ||
|
|
787
|
+
normalizedId.includes("../package.json")
|
|
788
|
+
) {
|
|
789
|
+
return { version: "0.0.0" };
|
|
790
|
+
}
|
|
791
|
+
if (normalizedId.endsWith(".json")) {
|
|
792
|
+
return {};
|
|
793
|
+
}
|
|
794
|
+
return nsRequire(normalizedId);
|
|
795
|
+
};
|
|
796
|
+
req.resolve = nsRequire.resolve
|
|
797
|
+
? function (id) {
|
|
798
|
+
return nsRequire.resolve(id);
|
|
799
|
+
}
|
|
800
|
+
: function (id) {
|
|
801
|
+
return id;
|
|
802
|
+
};
|
|
803
|
+
return req;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export default { createRequire };
|
|
807
|
+
`;
|
|
808
|
+
function stripIndexSuffix(specifier) {
|
|
809
|
+
return specifier.replace(/\/(?:(?:index)(?:\.[^.\/]+)?)$/, '');
|
|
810
|
+
}
|
|
811
|
+
//# sourceMappingURL=manifest.js.map
|