@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
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import { getProjectFilePath, getProjectRootPath } from
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getProjectFilePath, getProjectRootPath } from './project.js';
|
|
4
4
|
let tsConfigPath;
|
|
5
5
|
const projectRoot = getProjectRootPath();
|
|
6
6
|
// Read TypeScript path mappings
|
|
7
7
|
function getTsConfigPaths(debugViteLogs = false) {
|
|
8
8
|
try {
|
|
9
9
|
if (debugViteLogs)
|
|
10
|
-
console.log(
|
|
10
|
+
console.log('📁 Parsing tsconfig at:', tsConfigPath);
|
|
11
11
|
// The configDir should be the directory of the starting tsconfig file
|
|
12
12
|
const startingConfigDir = path.dirname(tsConfigPath);
|
|
13
13
|
// Recursive function to resolve tsconfig extends chain
|
|
@@ -15,11 +15,11 @@ function getTsConfigPaths(debugViteLogs = false) {
|
|
|
15
15
|
// Prevent infinite loops
|
|
16
16
|
if (visitedPaths.has(configPath)) {
|
|
17
17
|
if (debugViteLogs)
|
|
18
|
-
console.log(
|
|
19
|
-
return { paths: {}, baseUrl:
|
|
18
|
+
console.log('📁 Warning: Circular tsconfig extends detected, skipping:', configPath);
|
|
19
|
+
return { paths: {}, baseUrl: '.' };
|
|
20
20
|
}
|
|
21
21
|
visitedPaths.add(configPath);
|
|
22
|
-
const tsConfigContent = fs.readFileSync(configPath,
|
|
22
|
+
const tsConfigContent = fs.readFileSync(configPath, 'utf8');
|
|
23
23
|
// Parse JSON (handle JSONC)
|
|
24
24
|
let tsConfig;
|
|
25
25
|
try {
|
|
@@ -28,16 +28,16 @@ function getTsConfigPaths(debugViteLogs = false) {
|
|
|
28
28
|
catch (parseError) {
|
|
29
29
|
// Clean up JSONC
|
|
30
30
|
if (debugViteLogs)
|
|
31
|
-
console.log(
|
|
31
|
+
console.log('📁 Cleaning JSONC for:', configPath);
|
|
32
32
|
let cleanContent = tsConfigContent
|
|
33
|
-
.replace(/\/\/.*$/gm,
|
|
34
|
-
.replace(/\/\*[\s\S]*?\*\//g,
|
|
35
|
-
.replace(/,(\s*[}\]])/g,
|
|
33
|
+
.replace(/\/\/.*$/gm, '')
|
|
34
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
35
|
+
.replace(/,(\s*[}\]])/g, '$1');
|
|
36
36
|
tsConfig = JSON.parse(cleanContent);
|
|
37
37
|
}
|
|
38
38
|
// Start with current config's options
|
|
39
39
|
let currentPaths = { ...(tsConfig.compilerOptions?.paths || {}) };
|
|
40
|
-
let mergedBaseUrl = tsConfig.compilerOptions?.baseUrl ||
|
|
40
|
+
let mergedBaseUrl = tsConfig.compilerOptions?.baseUrl || '.';
|
|
41
41
|
const currentConfigDir = path.dirname(configPath);
|
|
42
42
|
// Handle path resolution for this config file
|
|
43
43
|
if (currentPaths) {
|
|
@@ -46,7 +46,7 @@ function getTsConfigPaths(debugViteLogs = false) {
|
|
|
46
46
|
if (Array.isArray(values)) {
|
|
47
47
|
resolvedPaths[key] = values.map((value) => {
|
|
48
48
|
// Handle ${configDir} substitution - use the STARTING config directory
|
|
49
|
-
if (value.includes(
|
|
49
|
+
if (value.includes('${configDir}')) {
|
|
50
50
|
return value.replace(/\$\{configDir\}/g, startingConfigDir);
|
|
51
51
|
}
|
|
52
52
|
// For other paths, resolve relative to THIS config file's directory
|
|
@@ -66,7 +66,7 @@ function getTsConfigPaths(debugViteLogs = false) {
|
|
|
66
66
|
if (tsConfig.extends) {
|
|
67
67
|
const baseConfigPath = path.resolve(path.dirname(configPath), tsConfig.extends);
|
|
68
68
|
if (debugViteLogs)
|
|
69
|
-
console.log(
|
|
69
|
+
console.log('📁 Following extends to:', baseConfigPath);
|
|
70
70
|
if (fs.existsSync(baseConfigPath)) {
|
|
71
71
|
try {
|
|
72
72
|
const baseResult = resolveTsConfigChain(baseConfigPath, visitedPaths);
|
|
@@ -80,21 +80,21 @@ function getTsConfigPaths(debugViteLogs = false) {
|
|
|
80
80
|
}
|
|
81
81
|
catch (e) {
|
|
82
82
|
if (debugViteLogs)
|
|
83
|
-
console.log(
|
|
83
|
+
console.log('📁 Warning: Could not load extended config:', baseConfigPath, e.message);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
if (debugViteLogs)
|
|
88
|
-
console.log(
|
|
88
|
+
console.log('📁 Warning: Extended config not found:', baseConfigPath);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
return { paths: currentPaths, baseUrl: mergedBaseUrl };
|
|
92
92
|
}
|
|
93
93
|
const result = resolveTsConfigChain(tsConfigPath);
|
|
94
94
|
if (debugViteLogs) {
|
|
95
|
-
console.log(
|
|
96
|
-
console.log(
|
|
97
|
-
console.log(
|
|
95
|
+
console.log('📁 Found paths in tsconfig:', Object.keys(result.paths));
|
|
96
|
+
console.log('📁 Base URL:', result.baseUrl);
|
|
97
|
+
console.log('📁 Starting configDir:', startingConfigDir);
|
|
98
98
|
// Show first few resolved paths for debugging
|
|
99
99
|
Object.entries(result.paths)
|
|
100
100
|
.slice(0, 3)
|
|
@@ -105,18 +105,18 @@ function getTsConfigPaths(debugViteLogs = false) {
|
|
|
105
105
|
return result;
|
|
106
106
|
}
|
|
107
107
|
catch (e) {
|
|
108
|
-
console.warn(
|
|
109
|
-
return { paths: {}, baseUrl:
|
|
108
|
+
console.warn('Failed to parse tsconfig paths:', e.message);
|
|
109
|
+
return { paths: {}, baseUrl: '.' };
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
// Function to create TypeScript aliases with platform support
|
|
113
|
-
function createTsConfigAliases(
|
|
113
|
+
function createTsConfigAliases(opts) {
|
|
114
114
|
const aliases = [];
|
|
115
115
|
// Process patterns in order: wildcards first, then exact matches
|
|
116
|
-
const sortedPatterns = Object.entries(paths).sort(([a], [b]) => {
|
|
116
|
+
const sortedPatterns = Object.entries(opts.paths).sort(([a], [b]) => {
|
|
117
117
|
// Wildcards (with *) come first
|
|
118
|
-
const aHasWildcard = a.includes(
|
|
119
|
-
const bHasWildcard = b.includes(
|
|
118
|
+
const aHasWildcard = a.includes('*');
|
|
119
|
+
const bHasWildcard = b.includes('*');
|
|
120
120
|
if (aHasWildcard && !bHasWildcard)
|
|
121
121
|
return -1;
|
|
122
122
|
if (!aHasWildcard && bHasWildcard)
|
|
@@ -126,48 +126,41 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
|
|
|
126
126
|
});
|
|
127
127
|
for (const [pattern, destinations] of sortedPatterns) {
|
|
128
128
|
if (Array.isArray(destinations) && destinations.length > 0) {
|
|
129
|
-
if (pattern.includes(
|
|
129
|
+
if (pattern.includes('*')) {
|
|
130
130
|
// Handle wildcard patterns (like "@scope/plugins/*")
|
|
131
|
-
const aliasKey = pattern.replace(/\/\*$/,
|
|
132
|
-
const destination = destinations[0].replace(/\/\*$/,
|
|
131
|
+
const aliasKey = pattern.replace(/\/\*$/, '');
|
|
132
|
+
const destination = destinations[0].replace(/\/\*$/, '');
|
|
133
133
|
// Check if destination is already absolute (resolved by tsconfig chain)
|
|
134
|
-
const resolvedDestination = path.isAbsolute(destination)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
const resolvedDestination = path.isAbsolute(destination) ? destination : path.resolve(projectRoot, opts.baseUrl, destination);
|
|
135
|
+
// console.log(
|
|
136
|
+
// `📁 Creating wildcard alias: ${aliasKey} -> ${resolvedDestination}`,
|
|
137
|
+
// );
|
|
138
138
|
aliases.push({
|
|
139
|
-
find: new RegExp(`^${aliasKey.replace(/[.*+?^${}()|[\]\\]/g,
|
|
139
|
+
find: new RegExp(`^${aliasKey.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:/(.*))?$`),
|
|
140
140
|
replacement: (match, subpath) => {
|
|
141
|
-
const fullPath = subpath
|
|
142
|
-
|
|
143
|
-
: resolvedDestination;
|
|
144
|
-
if (debugViteLogs) {
|
|
141
|
+
const fullPath = subpath ? path.join(resolvedDestination, subpath) : resolvedDestination;
|
|
142
|
+
if (opts.verbose) {
|
|
145
143
|
console.log(`📁 TypeScript wildcard alias: ${match} -> ${fullPath}`);
|
|
146
144
|
}
|
|
147
145
|
// Check if this resolves to a directory, and if so, try to find index files
|
|
148
|
-
if (fs.existsSync(fullPath) &&
|
|
149
|
-
fs.statSync(fullPath).isDirectory()) {
|
|
146
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
|
|
150
147
|
// Try platform-specific index files first
|
|
151
|
-
const platformIndexPatterns = [
|
|
152
|
-
`index.${platform}.ts`,
|
|
153
|
-
`index.${platform}.js`,
|
|
154
|
-
`index.${platform}.mjs`,
|
|
155
|
-
];
|
|
148
|
+
const platformIndexPatterns = [`index.${opts.platform}.ts`, `index.${opts.platform}.js`, `index.${opts.platform}.mjs`];
|
|
156
149
|
for (const indexFile of platformIndexPatterns) {
|
|
157
150
|
const indexPath = path.join(fullPath, indexFile);
|
|
158
151
|
if (fs.existsSync(indexPath)) {
|
|
159
|
-
if (
|
|
152
|
+
if (opts.verbose) {
|
|
160
153
|
console.log(`📁 Found platform-specific directory index: ${indexPath}`);
|
|
161
154
|
}
|
|
162
155
|
return indexPath;
|
|
163
156
|
}
|
|
164
157
|
}
|
|
165
158
|
// Try standard index files
|
|
166
|
-
const indexPatterns = [
|
|
159
|
+
const indexPatterns = ['index.ts', 'index.js', 'index.mjs'];
|
|
167
160
|
for (const indexFile of indexPatterns) {
|
|
168
161
|
const indexPath = path.join(fullPath, indexFile);
|
|
169
162
|
if (fs.existsSync(indexPath)) {
|
|
170
|
-
if (
|
|
163
|
+
if (opts.verbose) {
|
|
171
164
|
console.log(`📁 Found directory index: ${indexPath}`);
|
|
172
165
|
}
|
|
173
166
|
return indexPath;
|
|
@@ -175,20 +168,20 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
|
|
|
175
168
|
}
|
|
176
169
|
}
|
|
177
170
|
// If not a directory or no index found, try platform-specific resolution
|
|
178
|
-
const extensions = [
|
|
171
|
+
const extensions = ['.ts', '.js', '.mjs'];
|
|
179
172
|
for (const ext of extensions) {
|
|
180
173
|
const basePath = fullPath + ext;
|
|
181
174
|
// Try platform-specific file first
|
|
182
|
-
const platformPath = fullPath + `.${platform}` + ext;
|
|
175
|
+
const platformPath = fullPath + `.${opts.platform}` + ext;
|
|
183
176
|
if (fs.existsSync(platformPath)) {
|
|
184
|
-
if (
|
|
177
|
+
if (opts.verbose) {
|
|
185
178
|
console.log(`📁 Found platform-specific file: ${platformPath}`);
|
|
186
179
|
}
|
|
187
180
|
return platformPath;
|
|
188
181
|
}
|
|
189
182
|
// Try base file
|
|
190
183
|
if (fs.existsSync(basePath)) {
|
|
191
|
-
if (
|
|
184
|
+
if (opts.verbose) {
|
|
192
185
|
console.log(`📁 Found base file: ${basePath}`);
|
|
193
186
|
}
|
|
194
187
|
return basePath;
|
|
@@ -202,14 +195,12 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
|
|
|
202
195
|
// Handle exact matches (like "@scope/anything/anywhere")
|
|
203
196
|
// Use regex to ensure exact match only
|
|
204
197
|
// Check if destination is already absolute (resolved by tsconfig chain)
|
|
205
|
-
const resolvedDestination = path.isAbsolute(destinations[0])
|
|
206
|
-
|
|
207
|
-
: path.resolve(projectRoot, baseUrl, destinations[0]);
|
|
208
|
-
if (debugViteLogs) {
|
|
198
|
+
const resolvedDestination = path.isAbsolute(destinations[0]) ? destinations[0] : path.resolve(projectRoot, opts.baseUrl, destinations[0]);
|
|
199
|
+
if (opts.verbose) {
|
|
209
200
|
console.log(`📁 Creating exact alias: ${pattern} -> ${resolvedDestination}`);
|
|
210
201
|
}
|
|
211
202
|
aliases.push({
|
|
212
|
-
find: new RegExp(`^${pattern.replace(/[.*+?^${}()|[\]\\]/g,
|
|
203
|
+
find: new RegExp(`^${pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`),
|
|
213
204
|
replacement: resolvedDestination,
|
|
214
205
|
});
|
|
215
206
|
}
|
|
@@ -217,25 +208,35 @@ function createTsConfigAliases(paths, baseUrl, platform, debugViteLogs) {
|
|
|
217
208
|
}
|
|
218
209
|
return aliases;
|
|
219
210
|
}
|
|
220
|
-
|
|
221
|
-
let
|
|
222
|
-
export const getTsConfigData = (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
211
|
+
let cachedConfig = null;
|
|
212
|
+
let cachedPath = null;
|
|
213
|
+
export const getTsConfigData = (options) => {
|
|
214
|
+
const verbose = !!options.verbose;
|
|
215
|
+
let candidatePath = getProjectFilePath('tsconfig.app.json');
|
|
216
|
+
if (!fs.existsSync(candidatePath)) {
|
|
217
|
+
candidatePath = getProjectFilePath('tsconfig.json');
|
|
226
218
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
tsConfigPath = candidatePath;
|
|
220
|
+
if (!cachedConfig || cachedPath !== candidatePath) {
|
|
221
|
+
cachedConfig = getTsConfigPaths(verbose);
|
|
222
|
+
cachedPath = candidatePath;
|
|
223
|
+
if (verbose) {
|
|
224
|
+
console.log('📁 Loaded TypeScript path configuration');
|
|
225
|
+
}
|
|
232
226
|
}
|
|
233
|
-
const aliases = createTsConfigAliases(
|
|
234
|
-
|
|
235
|
-
|
|
227
|
+
const aliases = createTsConfigAliases({
|
|
228
|
+
paths: cachedConfig.paths,
|
|
229
|
+
baseUrl: cachedConfig.baseUrl,
|
|
230
|
+
platform: options.platform,
|
|
231
|
+
verbose,
|
|
232
|
+
});
|
|
233
|
+
if (aliases.length > 0 && verbose) {
|
|
234
|
+
console.log('📁 Created TypeScript path aliases:', aliases.length);
|
|
236
235
|
}
|
|
237
236
|
return {
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
paths: cachedConfig.paths,
|
|
238
|
+
baseUrl: cachedConfig.baseUrl,
|
|
239
|
+
aliases,
|
|
240
240
|
};
|
|
241
241
|
};
|
|
242
|
+
//# sourceMappingURL=ts-config-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-config-paths.js","sourceRoot":"","sources":["../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AAI,OAAO,EAAE,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;IAED,OAAO;QACN,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,OAAO;KACP,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -17,7 +17,17 @@ export declare function getAllDependencies(): string[];
|
|
|
17
17
|
* Check if a dependency is present in package.json
|
|
18
18
|
*/
|
|
19
19
|
export declare function hasDependency(packageName: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Utility to get the path (usually nested in node_modules) of a dependency.
|
|
22
|
+
*
|
|
23
|
+
* @param dependencyName
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDependencyPath(dependencyName: string): string | null;
|
|
20
26
|
/**
|
|
21
27
|
* Get the version of a dependency from package.json
|
|
22
28
|
*/
|
|
23
29
|
export declare function getDependencyVersion(packageName: string): string | undefined;
|
|
30
|
+
export declare function getProjectAppPath(): string;
|
|
31
|
+
export declare function getProjectAppRelativePath(subPath?: string): string;
|
|
32
|
+
export declare function getProjectAppAbsolutePath(subPath?: string): string;
|
|
33
|
+
export declare function getProjectAppVirtualPath(subPath?: string): string;
|
package/helpers/utils.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { transformSync } from 'esbuild';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { getPackageJson, getProjectFilePath, getProjectRootPath } from './project.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
// get the name from the package for the output
|
|
8
|
+
const packageJson = getPackageJson();
|
|
9
|
+
export function nsConfigToJson() {
|
|
10
|
+
let configObject;
|
|
11
|
+
const tsPath = getProjectFilePath('nativescript.config.ts');
|
|
12
|
+
const tsCode = fs.readFileSync(tsPath, 'utf-8');
|
|
13
|
+
// a) Transpile your TS config to CommonJS so we can require() it
|
|
14
|
+
const { code: cjsCode } = transformSync(tsCode, {
|
|
15
|
+
loader: 'ts',
|
|
16
|
+
format: 'cjs',
|
|
17
|
+
target: 'esnext',
|
|
18
|
+
});
|
|
19
|
+
// b) Evaluate it in a VM-style sandbox to pull out the default export
|
|
20
|
+
const module = { exports: {} };
|
|
21
|
+
const requireFunc = (id) => require(id);
|
|
22
|
+
new Function('exports', 'require', 'module', '__filename', '__dirname', cjsCode)(module.exports, requireFunc, module, tsPath, path.dirname(tsPath));
|
|
23
|
+
configObject = module.exports.default ?? module.exports;
|
|
24
|
+
// ensure the config has a name
|
|
25
|
+
configObject.name = packageJson.name;
|
|
26
|
+
// ensure the main entry is set to "bundle"
|
|
27
|
+
configObject.main = 'bundle';
|
|
28
|
+
return configObject;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the NativeScript platform-specific file for a given module ID.
|
|
32
|
+
* @param id The module ID to resolve.
|
|
33
|
+
* @param platform The target platform (e.g., "ios", "android").
|
|
34
|
+
* @returns The resolved file path or undefined if not found.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveNativeScriptPlatformFile(id, platform) {
|
|
37
|
+
const ext = path.extname(id);
|
|
38
|
+
const base = id.slice(0, -ext.length);
|
|
39
|
+
let platformFile = `${base}.${platform}${ext}`;
|
|
40
|
+
if (fs.existsSync(platformFile)) {
|
|
41
|
+
return platformFile;
|
|
42
|
+
}
|
|
43
|
+
// core uses indices for many barrels
|
|
44
|
+
platformFile = `${base}/index.${platform}${ext}`;
|
|
45
|
+
if (fs.existsSync(platformFile)) {
|
|
46
|
+
return platformFile;
|
|
47
|
+
}
|
|
48
|
+
// fallback to non-platform file
|
|
49
|
+
return fs.existsSync(id) ? id : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Utility to get all dependencies from the project package.json.
|
|
53
|
+
* The result combines dependencies and devDependencies
|
|
54
|
+
*
|
|
55
|
+
* @returns string[] dependencies
|
|
56
|
+
*/
|
|
57
|
+
export function getAllDependencies() {
|
|
58
|
+
return [...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.devDependencies ?? {})];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a dependency is present in package.json
|
|
62
|
+
*/
|
|
63
|
+
export function hasDependency(packageName) {
|
|
64
|
+
return getAllDependencies().includes(packageName);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Utility to get the path (usually nested in node_modules) of a dependency.
|
|
68
|
+
*
|
|
69
|
+
* @param dependencyName
|
|
70
|
+
*/
|
|
71
|
+
export function getDependencyPath(dependencyName) {
|
|
72
|
+
try {
|
|
73
|
+
const resolvedPath = require.resolve(`${dependencyName}/package.json`, {
|
|
74
|
+
paths: [getProjectRootPath()],
|
|
75
|
+
});
|
|
76
|
+
return path.dirname(resolvedPath);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the version of a dependency from package.json
|
|
84
|
+
*/
|
|
85
|
+
export function getDependencyVersion(packageName) {
|
|
86
|
+
return packageJson.dependencies?.[packageName] ?? packageJson.devDependencies?.[packageName] ?? packageJson.peerDependencies?.[packageName];
|
|
87
|
+
}
|
|
88
|
+
let cachedAppPath;
|
|
89
|
+
function normalizePathSegment(segment) {
|
|
90
|
+
if (!segment)
|
|
91
|
+
return undefined;
|
|
92
|
+
const normalized = segment
|
|
93
|
+
.replace(/\\/g, '/')
|
|
94
|
+
.replace(/^\.\/+/, '')
|
|
95
|
+
.replace(/^\/+/, '')
|
|
96
|
+
.replace(/\/+$/, '');
|
|
97
|
+
return normalized || undefined;
|
|
98
|
+
}
|
|
99
|
+
function deriveAppPathFromPackage() {
|
|
100
|
+
const mainEntry = packageJson?.main;
|
|
101
|
+
const normalized = normalizePathSegment(mainEntry);
|
|
102
|
+
if (!normalized)
|
|
103
|
+
return undefined;
|
|
104
|
+
const segments = normalized.split('/').filter(Boolean);
|
|
105
|
+
if (segments.length >= 2) {
|
|
106
|
+
return segments[0];
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
function computeProjectAppPath() {
|
|
111
|
+
if (cachedAppPath)
|
|
112
|
+
return cachedAppPath;
|
|
113
|
+
let candidate;
|
|
114
|
+
try {
|
|
115
|
+
const config = nsConfigToJson();
|
|
116
|
+
candidate = normalizePathSegment(config?.appPath);
|
|
117
|
+
}
|
|
118
|
+
catch { }
|
|
119
|
+
if (!candidate) {
|
|
120
|
+
candidate = deriveAppPathFromPackage();
|
|
121
|
+
}
|
|
122
|
+
cachedAppPath = candidate || 'src';
|
|
123
|
+
return cachedAppPath;
|
|
124
|
+
}
|
|
125
|
+
export function getProjectAppPath() {
|
|
126
|
+
return computeProjectAppPath();
|
|
127
|
+
}
|
|
128
|
+
export function getProjectAppRelativePath(subPath = '') {
|
|
129
|
+
const base = computeProjectAppPath();
|
|
130
|
+
const cleanSub = normalizePathSegment(subPath);
|
|
131
|
+
if (!cleanSub)
|
|
132
|
+
return base;
|
|
133
|
+
return `${base}/${cleanSub}`.replace(/\/+/g, '/');
|
|
134
|
+
}
|
|
135
|
+
export function getProjectAppAbsolutePath(subPath = '') {
|
|
136
|
+
const rel = getProjectAppRelativePath(subPath);
|
|
137
|
+
return path.resolve(getProjectRootPath(), rel);
|
|
138
|
+
}
|
|
139
|
+
export function getProjectAppVirtualPath(subPath = '') {
|
|
140
|
+
const rel = getProjectAppRelativePath(subPath).replace(/^\/+/, '');
|
|
141
|
+
return `/${rel.replace(/\/+/g, '/')}`;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,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EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import { nsConfigToJson, resolveNativeScriptPlatformFile } from
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { nsConfigToJson, resolveNativeScriptPlatformFile } from './utils.js';
|
|
3
3
|
export function getWorkerPlugins(platform) {
|
|
4
4
|
return [
|
|
5
5
|
// Handle ~/package.json virtual module for workers
|
|
6
6
|
{
|
|
7
|
-
name:
|
|
7
|
+
name: 'worker-virtual-package-json',
|
|
8
8
|
resolveId(id) {
|
|
9
|
-
if (id ===
|
|
10
|
-
return
|
|
9
|
+
if (id === '~/package.json') {
|
|
10
|
+
return '\0worker:nsconfig-json'; // Use a completely different virtual ID that doesn't look like JSON
|
|
11
11
|
}
|
|
12
12
|
return null;
|
|
13
13
|
},
|
|
14
14
|
load(id) {
|
|
15
|
-
if (id ===
|
|
15
|
+
if (id === '\0worker:nsconfig-json') {
|
|
16
16
|
const configObject = nsConfigToJson();
|
|
17
17
|
// Return the NativeScript config as a JavaScript module
|
|
18
18
|
return `export default ${JSON.stringify(configObject, null, 2)};`;
|
|
@@ -22,13 +22,13 @@ export function getWorkerPlugins(platform) {
|
|
|
22
22
|
},
|
|
23
23
|
// Resolve NativeScript platform-specific files for workers
|
|
24
24
|
{
|
|
25
|
-
name:
|
|
25
|
+
name: 'nativescript-platform-resolver-worker',
|
|
26
26
|
resolveId(id, importer) {
|
|
27
27
|
// Handle relative imports from node_modules (not just @nativescript/core)
|
|
28
28
|
if (importer) {
|
|
29
29
|
const resolvedPath = path.resolve(path.dirname(importer), id);
|
|
30
30
|
// Try different extensions with platform-specific resolution
|
|
31
|
-
const extensions = [
|
|
31
|
+
const extensions = ['.js', '.mjs', '.ts'];
|
|
32
32
|
for (const ext of extensions) {
|
|
33
33
|
const testPath = resolvedPath + ext;
|
|
34
34
|
// Use the existing NativeScript platform file resolver
|
|
@@ -44,14 +44,14 @@ export function getWorkerPlugins(platform) {
|
|
|
44
44
|
},
|
|
45
45
|
// Handle import.meta expressions in workers
|
|
46
46
|
{
|
|
47
|
-
name:
|
|
47
|
+
name: 'worker-import-meta-handler',
|
|
48
48
|
transform(code, id) {
|
|
49
49
|
// Replace import.meta.dirname with a static value for workers
|
|
50
|
-
if (code.includes(
|
|
50
|
+
if (code.includes('import.meta.dirname')) {
|
|
51
51
|
code = code.replace(/import\.meta\.dirname/g, '""');
|
|
52
52
|
}
|
|
53
53
|
// Replace import.meta.url with a static value for workers
|
|
54
|
-
if (code.includes(
|
|
54
|
+
if (code.includes('import.meta.url')) {
|
|
55
55
|
code = code.replace(/import\.meta\.url/g, '"file:///app/"');
|
|
56
56
|
}
|
|
57
57
|
return code;
|
|
@@ -61,11 +61,11 @@ export function getWorkerPlugins(platform) {
|
|
|
61
61
|
}
|
|
62
62
|
export function workerUrlPlugin() {
|
|
63
63
|
return {
|
|
64
|
-
name:
|
|
64
|
+
name: 'nativescript-worker-url-transform',
|
|
65
65
|
generateBundle(options, bundle) {
|
|
66
66
|
// Transform the main bundle to use NativeScript worker paths
|
|
67
67
|
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
68
|
-
if (chunk.type ===
|
|
68
|
+
if (chunk.type === 'chunk' && !fileName.includes('.worker')) {
|
|
69
69
|
// Transform Vite's worker URL pattern to NativeScript's expected format
|
|
70
70
|
// From: new Worker(new URL(/* @vite-ignore */ "/assets/sample.worker-C6wW8q2-.js", import.meta.url))
|
|
71
71
|
// To: new Worker('~/' + 'assets/sample.worker-C6wW8q2-.js')
|
|
@@ -73,9 +73,7 @@ export function workerUrlPlugin() {
|
|
|
73
73
|
if (workerUrlRegex.test(chunk.code)) {
|
|
74
74
|
chunk.code = chunk.code.replace(workerUrlRegex, (match, assetPath) => {
|
|
75
75
|
// Use the full asset path including assets/ folder
|
|
76
|
-
const fullPath = assetPath.startsWith(
|
|
77
|
-
? assetPath.slice(1)
|
|
78
|
-
: assetPath;
|
|
76
|
+
const fullPath = assetPath.startsWith('/') ? assetPath.slice(1) : assetPath;
|
|
79
77
|
return `new Worker('~/' + '${fullPath}')`;
|
|
80
78
|
});
|
|
81
79
|
}
|
|
@@ -84,3 +82,4 @@ export function workerUrlPlugin() {
|
|
|
84
82
|
},
|
|
85
83
|
};
|
|
86
84
|
}
|
|
85
|
+
//# sourceMappingURL=workers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/workers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAC;AAE7E,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAChD,OAAO;QACN,mDAAmD;QACnD;YACC,IAAI,EAAE,6BAA6B;YACnC,SAAS,CAAC,EAAE;gBACX,IAAI,EAAE,KAAK,gBAAgB,EAAE,CAAC;oBAC7B,OAAO,wBAAwB,CAAC,CAAC,oEAAoE;gBACtG,CAAC;gBACD,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,CAAC,EAAE;gBACN,IAAI,EAAE,KAAK,wBAAwB,EAAE,CAAC;oBACrC,MAAM,YAAY,GAAG,cAAc,EAAE,CAAC;oBACtC,wDAAwD;oBACxD,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC;gBACnE,CAAC;gBACD,OAAO,IAAI,CAAC;YACb,CAAC;SACD;QACD,2DAA2D;QAC3D;YACC,IAAI,EAAE,uCAAuC;YAC7C,SAAS,CAAC,EAAE,EAAE,QAAQ;gBACrB,0EAA0E;gBAC1E,IAAI,QAAQ,EAAE,CAAC;oBACd,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;oBAE9D,6DAA6D;oBAC7D,MAAM,UAA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C7D,wEAAwE;oBACxE,qGAAqG;oBACrG,4DAA4D;oBAC5D,MAAM,cAAc,GAAG,+GAA+G,CAAC;oBAEvI,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;wBACrC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;4BACpE,mDAAmD;4BACnD,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;4BAC5E,OAAO,sBAAsB,QAAQ,IAAI,CAAC;wBAC3C,CAAC,CAAC,CAAC;oBACJ,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function applyCssText(cssText: string): void;
|
|
2
|
+
export declare function fetchText(url: string): Promise<string>;
|
|
3
|
+
export declare function handleCssUpdates(cssUpdates: any[], httpOrigin: string): Promise<void>;
|
|
4
|
+
export declare function handleCustomCss(cssText: string): void;
|