@nativescript/vite 0.0.1 → 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/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/{dist/helpers → helpers}/global-defines.d.ts +11 -2
- 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/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 +6 -0
- package/{dist/helpers → helpers}/utils.js +28 -34
- 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 +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/hmr/server/vite-plugin.js +44 -0
- 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 -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 +8 -0
- package/shims/angular-animations-stub.js +14 -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.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/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/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
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativescript-package-resolver.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/nativescript-package-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAC;AAEzC,uCAAuC;AACvC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;AAE/B,MAAM,UAAU,2BAA2B,CAAC,QAAgB;IAC3D,OAAO;QACN,IAAI,EAAE,+BAA+B;QACrC,OAAO,EAAE,KAAK,EAAE,6CAA6C;Q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pC,OAAO,IAAI,CAAC;4BACb,CAAC;wBACF,CAAC;oBACF,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACZ,yBAAyB;wBACzB,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;wBACpC,OAAO,IAAI,CAAC;oBACb,CAAC;gBACF,CAAC;qBAAM,CAAC;oBACP,wBAAwB;oBACxB,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;oBACpC,OAAO,IAAI,CAAC;gBACb,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,wBAAwB;gBACxB,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBACpC,OAAO,IAAI,CAAC;YACb,CAAC;YAED,gCAAgC;YAChC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YACpC,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function cliPlugin(opts: {
|
|
2
|
+
distOutputFolder: string;
|
|
3
|
+
isDevMode: boolean;
|
|
4
|
+
verbose: boolean;
|
|
5
|
+
hmrActive: boolean;
|
|
6
|
+
}): {
|
|
7
|
+
name: string;
|
|
8
|
+
apply: string;
|
|
9
|
+
enforce: "post";
|
|
10
|
+
configResolved(config: any): void;
|
|
11
|
+
generateBundle(options: any, bundle: any): void;
|
|
12
|
+
writeBundle(options: any, bundle: any): void;
|
|
13
|
+
closeBundle(): void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { readdirSync, statSync, existsSync, mkdirSync } from 'fs';
|
|
3
|
+
let isInitialBuild = true;
|
|
4
|
+
// NativeScript CLI integration for live reloads, non-HMR rebuilds
|
|
5
|
+
export function cliPlugin(opts) {
|
|
6
|
+
// Capture emitted files directly from Rollup hooks to avoid relying on FS state
|
|
7
|
+
const lastBundleFiles = new Set();
|
|
8
|
+
let lastOutDir;
|
|
9
|
+
// This plugin should not trigger NativeScript CLI rebuild/refresh cycles when HMR is active
|
|
10
|
+
return {
|
|
11
|
+
name: 'nativescript-cli-integration',
|
|
12
|
+
apply: 'build',
|
|
13
|
+
// Ensure we run after other plugins (like vite-plugin-static-copy)
|
|
14
|
+
enforce: 'post',
|
|
15
|
+
// Resolve build outDir so we can read final outputs after all plugins finish
|
|
16
|
+
configResolved(config) {
|
|
17
|
+
// Under HMR, when not initial build; skip - HMR client handles everything
|
|
18
|
+
if (opts.hmrActive && !isInitialBuild)
|
|
19
|
+
return;
|
|
20
|
+
},
|
|
21
|
+
// Use Rollup hook to record emitted file names (relative to output dir)
|
|
22
|
+
generateBundle(options, bundle) {
|
|
23
|
+
// Under HMR, still capture files on initial build
|
|
24
|
+
if (opts.hmrActive && !isInitialBuild)
|
|
25
|
+
return;
|
|
26
|
+
try {
|
|
27
|
+
const keys = Object.keys(bundle);
|
|
28
|
+
for (const k of keys)
|
|
29
|
+
lastBundleFiles.add(k);
|
|
30
|
+
// Remember outDir/file from Rollup options if provided
|
|
31
|
+
lastOutDir = options.dir || (options.file && path.dirname(options.file)) || undefined;
|
|
32
|
+
if (opts.verbose) {
|
|
33
|
+
console.log(`[cliPlugin] generateBundle: files=${keys.length}, dir=${lastOutDir ?? '(unknown)'}`);
|
|
34
|
+
if (keys.length) {
|
|
35
|
+
console.log('[cliPlugin] bundle keys:', keys);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// noop
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
// called only when writing to disk
|
|
44
|
+
writeBundle(options, bundle) {
|
|
45
|
+
// Under HMR, still capture files on initial build
|
|
46
|
+
if (opts.hmrActive && !isInitialBuild)
|
|
47
|
+
return;
|
|
48
|
+
try {
|
|
49
|
+
const keys = Object.keys(bundle);
|
|
50
|
+
for (const k of keys)
|
|
51
|
+
lastBundleFiles.add(k);
|
|
52
|
+
lastOutDir = options.dir || (options.file && path.dirname(options.file)) || lastOutDir;
|
|
53
|
+
if (opts.verbose) {
|
|
54
|
+
console.log(`[cliPlugin] writeBundle: files=${keys.length}, dir=${lastOutDir ?? '(unknown)'}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// noop
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
// Defer CLI notification until after all plugins (including static copy) are done.
|
|
62
|
+
closeBundle() {
|
|
63
|
+
if (opts.hmrActive && !isInitialBuild) {
|
|
64
|
+
// Reset trackers to avoid leaking state between builds even if no-op
|
|
65
|
+
lastBundleFiles.clear();
|
|
66
|
+
lastOutDir = undefined;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!opts.isDevMode)
|
|
70
|
+
return;
|
|
71
|
+
const buildType = isInitialBuild ? 'initial' : 'incremental';
|
|
72
|
+
if (opts.verbose) {
|
|
73
|
+
console.log(`NativeScript: ${buildType} build completed.`);
|
|
74
|
+
}
|
|
75
|
+
// Determine outDir and ensure it exists in dev for a clean start
|
|
76
|
+
const distDir = lastOutDir || opts.distOutputFolder;
|
|
77
|
+
if (!existsSync(distDir)) {
|
|
78
|
+
try {
|
|
79
|
+
mkdirSync(distDir, { recursive: true });
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// ignore; listing will just return []
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Prefer Rollup-reported bundle files; fall back to FS scan
|
|
86
|
+
const emittedFiles = lastBundleFiles.size ? Array.from(lastBundleFiles) : listFilesFlat(distDir);
|
|
87
|
+
if (opts.verbose) {
|
|
88
|
+
console.log(`[cliPlugin] closeBundle: distDir=${distDir}, captured=${lastBundleFiles.size}, fsScan=${emittedFiles.length}`);
|
|
89
|
+
}
|
|
90
|
+
if (opts.verbose) {
|
|
91
|
+
console.log(`Emitted ${emittedFiles.length} files in ${buildType} build.`);
|
|
92
|
+
}
|
|
93
|
+
if (process.send) {
|
|
94
|
+
const sendMessage = (files) => {
|
|
95
|
+
const message = {
|
|
96
|
+
emittedFiles: files,
|
|
97
|
+
chunkFiles: files.filter((f) => f.includes('chunk') || f.includes('vendor')),
|
|
98
|
+
hash: Date.now().toString(),
|
|
99
|
+
isHMR: false,
|
|
100
|
+
buildType,
|
|
101
|
+
timestamp: Date.now(),
|
|
102
|
+
};
|
|
103
|
+
if (opts.verbose) {
|
|
104
|
+
console.log(`Sending ${buildType} build notification to CLI.`);
|
|
105
|
+
}
|
|
106
|
+
process.send(message);
|
|
107
|
+
};
|
|
108
|
+
if (emittedFiles.length === 0) {
|
|
109
|
+
// Allow a short delay for any late FS writes by other post plugins
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
const rescanned = listFilesFlat(distDir);
|
|
112
|
+
if (opts.verbose) {
|
|
113
|
+
console.log(`[cliPlugin] delayed rescan found ${rescanned.length} files in ${distDir}`);
|
|
114
|
+
}
|
|
115
|
+
sendMessage(rescanned);
|
|
116
|
+
}, 50);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
sendMessage(emittedFiles);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (isInitialBuild) {
|
|
123
|
+
isInitialBuild = false;
|
|
124
|
+
if (opts.verbose) {
|
|
125
|
+
console.log('Initial build complete - subsequent changes will trigger fast rebuilds');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
lastBundleFiles.clear();
|
|
129
|
+
lastOutDir = undefined;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Recursively list files under a directory and return relative paths
|
|
134
|
+
function listFilesFlat(rootDir) {
|
|
135
|
+
const results = [];
|
|
136
|
+
function walk(dir, relBase = '') {
|
|
137
|
+
let entries = [];
|
|
138
|
+
try {
|
|
139
|
+
entries = readdirSync(dir);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
for (const name of entries) {
|
|
145
|
+
const abs = path.join(dir, name);
|
|
146
|
+
const rel = path.join(relBase, name);
|
|
147
|
+
let s;
|
|
148
|
+
try {
|
|
149
|
+
s = statSync(abs);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (s.isDirectory()) {
|
|
155
|
+
walk(abs, rel);
|
|
156
|
+
}
|
|
157
|
+
else if (s.isFile()) {
|
|
158
|
+
results.push(rel);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
walk(rootDir);
|
|
163
|
+
return results;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=ns-cli-plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns-cli-plugins.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/ns-cli-plugins.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAElE,IAAI,cAAc,GAAG,IAAI,CAAC;AAE1B,kEAAkE;AAClE,MAAM,UAAU,SAAS,CAAC,IAA4F;IACrH,gFAAgF;IAChF,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAC1C,IAAI,UAA8B,CAAC;IACnC,4FAA4F;IAC5F,OAAO;QACN,IAAI,EAAE,8BAA8B;QACpC,KAAK,EAAE,OAAO;QACd,mEAAmE;QACnE,OAAO,EAAE,MAAe;QACxB,6EAA6E;QAC7E,cAAc,CAAC,MAAM;YACpB,0EAA0E;YAC1E,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,cAAc;gBAAE,OAAO;QAC/C,CAAC;QACD,wEAAwE;QACxE,cAAc,CAAC,OAAO,EAAE,MAAM;YAC7B,kDAAkD;YAClD,IAAI,IAAI,CAAC,SAAS,IAAI,C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+1,48 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import { findPackageInNodeModules } from
|
|
4
|
-
import { getProjectRootPath } from
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { findPackageInNodeModules } from './module-resolution.js';
|
|
4
|
+
import { getProjectRootPath } from './project.js';
|
|
5
5
|
const projectRoot = getProjectRootPath();
|
|
6
|
-
export function packagePlatformAliases(
|
|
6
|
+
export function packagePlatformAliases(opts) {
|
|
7
7
|
// packages used via core transient dependencies and other vite support
|
|
8
|
-
const commonSkips = [
|
|
9
|
-
"source-map-js",
|
|
10
|
-
"html-entities",
|
|
11
|
-
"fast-xml-parser",
|
|
12
|
-
"@valor/nativescript-websockets",
|
|
13
|
-
];
|
|
8
|
+
const commonSkips = ['source-map-js', 'html-entities', 'fast-xml-parser', '@valor/nativescript-websockets'];
|
|
14
9
|
return {
|
|
15
10
|
find: /^(@[^/]+\/[^@/]+|[^@/]+)$/,
|
|
16
11
|
replacement: (id) => {
|
|
17
12
|
// Skip packages that have custom plugins
|
|
18
|
-
if (commonSkips.includes(id)
|
|
13
|
+
if (commonSkips.includes(id)) {
|
|
19
14
|
return id; // Let the plugins handle these
|
|
20
15
|
}
|
|
21
16
|
// Skip if this ID is already handled by tsconfig paths
|
|
22
17
|
// Check if this matches any of our tsconfig path aliases
|
|
23
|
-
if (
|
|
18
|
+
if (opts.tsConfig?.paths && opts.tsConfig.paths[id]) {
|
|
24
19
|
return id; // Let tsconfig aliases handle this
|
|
25
20
|
}
|
|
26
21
|
// Only handle packages that exist in node_modules (real npm packages)
|
|
27
22
|
const packageName = id;
|
|
28
23
|
const packagePath = findPackageInNodeModules(packageName, projectRoot);
|
|
29
24
|
if (packagePath) {
|
|
30
|
-
const packageJsonPath = path.join(packagePath,
|
|
25
|
+
const packageJsonPath = path.join(packagePath, 'package.json');
|
|
31
26
|
if (fs.existsSync(packageJsonPath)) {
|
|
32
27
|
try {
|
|
33
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath,
|
|
28
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
34
29
|
const mainField = packageJson.main;
|
|
35
30
|
if (mainField) {
|
|
36
31
|
const mainFilePath = path.join(packagePath, mainField);
|
|
37
32
|
// Case 1: Main field has no extension - try to add extensions
|
|
38
|
-
if (!mainField.includes(
|
|
33
|
+
if (!mainField.includes('.')) {
|
|
39
34
|
// Try platform-specific file first
|
|
40
|
-
const platformFile = path.join(packagePath, `${mainField}.${platform}.js`);
|
|
35
|
+
const platformFile = path.join(packagePath, `${mainField}.${opts.platform}.js`);
|
|
41
36
|
if (fs.existsSync(platformFile)) {
|
|
42
|
-
if (
|
|
43
|
-
console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.${platform}.js (extensionless)`);
|
|
37
|
+
if (opts.verbose) {
|
|
38
|
+
console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.${opts.platform}.js (extensionless)`);
|
|
44
39
|
}
|
|
45
40
|
return platformFile;
|
|
46
41
|
}
|
|
47
42
|
// Fallback to .js
|
|
48
43
|
const jsFile = path.join(packagePath, `${mainField}.js`);
|
|
49
44
|
if (fs.existsSync(jsFile)) {
|
|
50
|
-
if (
|
|
45
|
+
if (opts.verbose) {
|
|
51
46
|
console.log(`✅ Alias resolver: ${packageName} -> ${mainField}.js (extensionless)`);
|
|
52
47
|
}
|
|
53
48
|
return jsFile;
|
|
@@ -59,10 +54,10 @@ export function packagePlatformAliases(tsConfigData, platform, skipCommonjsPacka
|
|
|
59
54
|
const ext = path.extname(mainField);
|
|
60
55
|
const baseName = mainField.slice(0, -ext.length);
|
|
61
56
|
// Try platform-specific file first
|
|
62
|
-
const platformFile = path.join(packagePath, `${baseName}.${platform}${ext}`);
|
|
57
|
+
const platformFile = path.join(packagePath, `${baseName}.${opts.platform}${ext}`);
|
|
63
58
|
if (fs.existsSync(platformFile)) {
|
|
64
|
-
if (
|
|
65
|
-
console.log(`✅ Alias resolver: ${packageName} -> ${baseName}.${platform}${ext} (missing main)`);
|
|
59
|
+
if (opts.verbose) {
|
|
60
|
+
console.log(`✅ Alias resolver: ${packageName} -> ${baseName}.${opts.platform}${ext} (missing main)`);
|
|
66
61
|
}
|
|
67
62
|
return platformFile;
|
|
68
63
|
}
|
|
@@ -81,3 +76,4 @@ export function packagePlatformAliases(tsConfigData, platform, skipCommonjsPacka
|
|
|
81
76
|
},
|
|
82
77
|
};
|
|
83
78
|
}
|
|
79
|
+
//# sourceMappingURL=package-platform-aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-platform-aliases.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/package-platform-aliases.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAC;AAEzC,MAAM,UAAU,sBAAsB,CAAC,IAAoG;IAC1I,uEAAuE;IACvE,MAAM,WAAW,GAAG,CAAC,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,gCAAgC,CAAC,CAAC;IAC5G,OAAO;QACN,IAAI,EAAE,2BAA2B;QACjC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE;YACnB,yCAAyC;YACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC9B,OAAO,EAAE,CAAC,CAAC,+BAA+B;YAC3C,CAAC;YAED,uDAAuD;YACvD,yDAAyD;YACzD,IAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBACrD,OAAO,EAAE,CAAC,CAAC,mCAAmC;YAC/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+
postcssImport: any;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Builds PostCSS configuration with platform import rewriting + postcss-import fallback.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPostCssConfig(opts: PostCssConfigOptions): "./postcss.config.js" | {
|
|
11
|
+
plugins: any[];
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { findPackageInNodeModules } from './module-resolution.js';
|
|
4
|
+
/**
|
|
5
|
+
* Builds PostCSS configuration with platform import rewriting + postcss-import fallback.
|
|
6
|
+
*/
|
|
7
|
+
export function createPostCssConfig(opts) {
|
|
8
|
+
const { platform, projectRoot, themeCoreRoot, postcssImport } = opts;
|
|
9
|
+
if (!postcssImport)
|
|
10
|
+
return './postcss.config.js';
|
|
11
|
+
return {
|
|
12
|
+
plugins: [
|
|
13
|
+
{
|
|
14
|
+
postcssPlugin: 'ns-postcss-platform-import-rewrite',
|
|
15
|
+
Once(root) {
|
|
16
|
+
try {
|
|
17
|
+
const currentFile = root?.source?.input?.file;
|
|
18
|
+
if (!currentFile)
|
|
19
|
+
return;
|
|
20
|
+
const currentDir = path.dirname(currentFile);
|
|
21
|
+
root.walkAtRules('import', (rule) => {
|
|
22
|
+
const m = /^\s*(?:url\()?["]?([^"')]+)["]?\)?/.exec(rule.params || '');
|
|
23
|
+
if (!m)
|
|
24
|
+
return;
|
|
25
|
+
const spec = m[1];
|
|
26
|
+
if (!spec || !(spec.startsWith('.') || spec.startsWith('/')))
|
|
27
|
+
return;
|
|
28
|
+
if (!spec.endsWith('.css'))
|
|
29
|
+
return;
|
|
30
|
+
const abs = path.isAbsolute(spec) ? spec : path.resolve(currentDir, spec);
|
|
31
|
+
if (existsSync(abs))
|
|
32
|
+
return;
|
|
33
|
+
const ext = platform === 'android' ? '.android.css' : '.ios.css';
|
|
34
|
+
const alt = abs.replace(/\.css$/, ext);
|
|
35
|
+
if (existsSync(alt)) {
|
|
36
|
+
let rel = path.relative(currentDir, alt).replace(/\\/g, '/');
|
|
37
|
+
if (!rel.startsWith('.'))
|
|
38
|
+
rel = './' + rel;
|
|
39
|
+
rule.params = rule.params.replace(spec, rel);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch { }
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
postcssImport({
|
|
47
|
+
resolve(id, basedir) {
|
|
48
|
+
if (id.startsWith('.') || id.startsWith('/')) {
|
|
49
|
+
const cleanBasedir = basedir ? basedir.split('?')[0] : basedir;
|
|
50
|
+
let abs = path.resolve(cleanBasedir || '', id);
|
|
51
|
+
if (!existsSync(abs) && /\.css$/.test(abs)) {
|
|
52
|
+
const platformExt = platform === 'android' ? '.android.css' : '.ios.css';
|
|
53
|
+
const alt = abs.replace(/\.css$/, platformExt);
|
|
54
|
+
if (existsSync(alt))
|
|
55
|
+
return alt;
|
|
56
|
+
}
|
|
57
|
+
return abs;
|
|
58
|
+
}
|
|
59
|
+
if (id.startsWith('nativescript-theme-core/')) {
|
|
60
|
+
const pkgRoot = themeCoreRoot || findPackageInNodeModules('nativescript-theme-core', projectRoot);
|
|
61
|
+
if (!pkgRoot)
|
|
62
|
+
return id;
|
|
63
|
+
let rel = id.substring('nativescript-theme-core/'.length);
|
|
64
|
+
let target = path.join(pkgRoot, rel);
|
|
65
|
+
if (/^css\/.+\.css$/.test(rel)) {
|
|
66
|
+
const platformExt = platform === 'android' ? '.android.css' : '.ios.css';
|
|
67
|
+
const base = target.replace(/\.css$/, '');
|
|
68
|
+
const alt = base + platformExt;
|
|
69
|
+
if (existsSync(alt))
|
|
70
|
+
return alt;
|
|
71
|
+
}
|
|
72
|
+
return target;
|
|
73
|
+
}
|
|
74
|
+
return id;
|
|
75
|
+
},
|
|
76
|
+
load(filename) {
|
|
77
|
+
try {
|
|
78
|
+
const clean = filename.split('?')[0];
|
|
79
|
+
if (existsSync(clean)) {
|
|
80
|
+
return readFileSync(clean, 'utf-8');
|
|
81
|
+
}
|
|
82
|
+
if (/\.css$/.test(clean)) {
|
|
83
|
+
const platformExt = platform === 'android' ? '.android.css' : '.ios.css';
|
|
84
|
+
const alt = clean.replace(/\.css$/, platformExt);
|
|
85
|
+
if (existsSync(alt)) {
|
|
86
|
+
return readFileSync(alt, 'utf-8');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch { }
|
|
91
|
+
return undefined;
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=postcss-platform-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcss-platform-config.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/postcss-platform-config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AASlE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAA0B;IAC7D,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IACrE,IAAI,CAAC,aAAa;QAAE,OAAO,qBAAqB,CAAC;IACjD,OAAO;QACN,OAAO,EAAE;YACR;gBACC,aAAa,EAAE,oCAAoC;gBACnD,IAAI,CAAC,IAAS;oBACb,IAAI,CAAC;wBACJ,MAAM,WAAW,GAAuB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC;wBAClE,IAAI,CAAC,WAAW;4BAAE,OAAO;wBACzB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;wBAC7C,IAAI,CAAC,WAAW,CAAC,QAAQ,EAA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
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
async function pathExists(p) {
|
|
5
|
+
try {
|
|
6
|
+
await fs.access(p);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function ensureDir(p) {
|
|
14
|
+
await fs.mkdir(p, { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
async function linkFile(babel, createLinker, src) {
|
|
17
|
+
const code = await fs.readFile(src, 'utf8');
|
|
18
|
+
if (!code)
|
|
19
|
+
return null;
|
|
20
|
+
// Quick check to skip non-partial files
|
|
21
|
+
if (code.indexOf('\u0275\u0275ngDeclare') === -1 && code.indexOf('ɵɵngDeclare') === -1 && code.indexOf('ngDeclare') === -1)
|
|
22
|
+
return null;
|
|
23
|
+
const plugin = createLinker({ sourceMapping: false });
|
|
24
|
+
const res = await babel.transformAsync(code, {
|
|
25
|
+
filename: src,
|
|
26
|
+
configFile: false,
|
|
27
|
+
babelrc: false,
|
|
28
|
+
sourceMaps: false,
|
|
29
|
+
compact: false,
|
|
30
|
+
plugins: [plugin],
|
|
31
|
+
});
|
|
32
|
+
return res?.code && res.code !== code ? res.code : null;
|
|
33
|
+
}
|
|
34
|
+
async function copyOrLinkInto(babel, createLinker, srcFile, cacheFile) {
|
|
35
|
+
const dir = path.dirname(cacheFile);
|
|
36
|
+
await ensureDir(dir);
|
|
37
|
+
const linked = await linkFile(babel, createLinker, srcFile);
|
|
38
|
+
if (linked) {
|
|
39
|
+
await fs.writeFile(cacheFile, linked, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
await fs.copyFile(srcFile, cacheFile);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function prelinkPackage(req, pkgName, cacheRoot, debug) {
|
|
46
|
+
const pkgEntry = req.resolve(path.join(pkgName, 'package.json'));
|
|
47
|
+
const pkgDir = path.dirname(pkgEntry);
|
|
48
|
+
const fesmDir = path.join(pkgDir, 'fesm2022');
|
|
49
|
+
if (!(await pathExists(fesmDir)))
|
|
50
|
+
return;
|
|
51
|
+
// Lazy load linker deps from app
|
|
52
|
+
let babel = null;
|
|
53
|
+
let createLinker = null;
|
|
54
|
+
try {
|
|
55
|
+
const babelPath = req.resolve('@babel/core');
|
|
56
|
+
const linkerPath = req.resolve('@angular/compiler-cli/linker/babel');
|
|
57
|
+
babel = await import(babelPath);
|
|
58
|
+
const linkerMod = await import(linkerPath);
|
|
59
|
+
createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return; // Can't link without deps; skip quietly
|
|
63
|
+
}
|
|
64
|
+
const destDir = path.join(cacheRoot, pkgName, 'fesm2022');
|
|
65
|
+
await ensureDir(destDir);
|
|
66
|
+
const files = (await fs.readdir(fesmDir)).filter((f) => f.endsWith('.mjs'));
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
const srcFile = path.join(fesmDir, file);
|
|
69
|
+
const cacheFile = path.join(destDir, file);
|
|
70
|
+
await copyOrLinkInto(babel, createLinker, srcFile, cacheFile);
|
|
71
|
+
if (debug) {
|
|
72
|
+
try {
|
|
73
|
+
console.log(`[ns-angular-prelink] cached`, `${pkgName}/fesm2022/${file}`);
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function createAngularPrelinkPlugin(projectRoot) {
|
|
80
|
+
const req = createRequire(projectRoot ? projectRoot + '/package.json' : import.meta.url);
|
|
81
|
+
const cacheRoot = path.join(projectRoot || process.cwd(), 'node_modules', '.ns-linked');
|
|
82
|
+
const pkgs = ['@angular/core', '@angular/common', '@angular/forms', '@angular/platform-browser', '@angular/router', '@nativescript/angular'];
|
|
83
|
+
let done = false;
|
|
84
|
+
return {
|
|
85
|
+
name: 'ns-angular-prelink',
|
|
86
|
+
enforce: 'pre',
|
|
87
|
+
async config(_user, _env) {
|
|
88
|
+
const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
89
|
+
const disabled = process.env.NS_PRELINK === '0' || process.env.NS_PRELINK === 'false';
|
|
90
|
+
if (disabled)
|
|
91
|
+
return {};
|
|
92
|
+
// Prelink synchronously to ensure alias points to ready files.
|
|
93
|
+
for (const pkg of pkgs) {
|
|
94
|
+
await prelinkPackage(req, pkg, cacheRoot, !!debug);
|
|
95
|
+
}
|
|
96
|
+
done = true;
|
|
97
|
+
const alias = [
|
|
98
|
+
{ find: /^@angular\//, replacement: path.join(cacheRoot, '@angular') + '/' },
|
|
99
|
+
{ find: /^@nativescript\/angular(\/.*)?$/, replacement: (_, sub) => path.join(cacheRoot, '@nativescript', 'angular') + (sub || '') },
|
|
100
|
+
];
|
|
101
|
+
return { resolve: { alias } };
|
|
102
|
+
},
|
|
103
|
+
async buildStart() {
|
|
104
|
+
if (done)
|
|
105
|
+
return;
|
|
106
|
+
const disabled = process.env.NS_PRELINK === '0' || process.env.NS_PRELINK === 'false';
|
|
107
|
+
if (disabled)
|
|
108
|
+
return;
|
|
109
|
+
// Fallback: in case config() path was skipped (edge), run once.
|
|
110
|
+
for (const pkg of pkgs) {
|
|
111
|
+
await prelinkPackage(req, pkg, cacheRoot, false);
|
|
112
|
+
}
|
|
113
|
+
done = true;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=prelink-angular.js.map
|