@vistagenic/vista 0.2.13 → 0.2.14

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.
@@ -0,0 +1,4 @@
1
+ export interface ProjectAliasResolver {
2
+ resolve: (request: string) => string | null;
3
+ }
4
+ export declare function createProjectAliasResolver(cwd: string, resolveFromWorkspace: (specifier: string, cwd: string) => string): ProjectAliasResolver | null;
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createProjectAliasResolver = createProjectAliasResolver;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const projectAliasCache = new Map();
10
+ function stripJsonComments(input) {
11
+ let result = '';
12
+ let inString = false;
13
+ let stringQuote = '';
14
+ let isEscaped = false;
15
+ let inLineComment = false;
16
+ let inBlockComment = false;
17
+ for (let index = 0; index < input.length; index++) {
18
+ const current = input[index];
19
+ const next = input[index + 1];
20
+ if (inLineComment) {
21
+ if (current === '\n') {
22
+ inLineComment = false;
23
+ result += current;
24
+ }
25
+ continue;
26
+ }
27
+ if (inBlockComment) {
28
+ if (current === '*' && next === '/') {
29
+ inBlockComment = false;
30
+ index++;
31
+ }
32
+ continue;
33
+ }
34
+ if (inString) {
35
+ result += current;
36
+ if (isEscaped) {
37
+ isEscaped = false;
38
+ continue;
39
+ }
40
+ if (current === '\\') {
41
+ isEscaped = true;
42
+ continue;
43
+ }
44
+ if (current === stringQuote) {
45
+ inString = false;
46
+ stringQuote = '';
47
+ }
48
+ continue;
49
+ }
50
+ if ((current === '"' || current === "'") && !inString) {
51
+ inString = true;
52
+ stringQuote = current;
53
+ result += current;
54
+ continue;
55
+ }
56
+ if (current === '/' && next === '/') {
57
+ inLineComment = true;
58
+ index++;
59
+ continue;
60
+ }
61
+ if (current === '/' && next === '*') {
62
+ inBlockComment = true;
63
+ index++;
64
+ continue;
65
+ }
66
+ result += current;
67
+ }
68
+ return result;
69
+ }
70
+ function isBareSpecifier(request) {
71
+ if (!request)
72
+ return false;
73
+ if (request.startsWith('.') || request.startsWith('/'))
74
+ return false;
75
+ return !/^[A-Za-z]:[\\/]/.test(request);
76
+ }
77
+ function resolveAliasTargetPath(candidatePath) {
78
+ const resolvedBase = path_1.default.resolve(candidatePath);
79
+ const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.json'];
80
+ const directCandidates = path_1.default.extname(resolvedBase)
81
+ ? [resolvedBase]
82
+ : [resolvedBase, ...extensions.map((extension) => `${resolvedBase}${extension}`)];
83
+ for (const candidate of directCandidates) {
84
+ try {
85
+ if (fs_1.default.existsSync(candidate) && fs_1.default.statSync(candidate).isFile()) {
86
+ return candidate;
87
+ }
88
+ }
89
+ catch {
90
+ // continue
91
+ }
92
+ }
93
+ try {
94
+ if (fs_1.default.existsSync(resolvedBase) && fs_1.default.statSync(resolvedBase).isDirectory()) {
95
+ const packageJsonPath = path_1.default.join(resolvedBase, 'package.json');
96
+ if (fs_1.default.existsSync(packageJsonPath)) {
97
+ try {
98
+ const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf-8'));
99
+ if (packageJson.main) {
100
+ const packageMainPath = resolveAliasTargetPath(path_1.default.join(resolvedBase, packageJson.main));
101
+ if (packageMainPath)
102
+ return packageMainPath;
103
+ }
104
+ }
105
+ catch {
106
+ // ignore invalid package.json while resolving alias target
107
+ }
108
+ }
109
+ for (const extension of extensions) {
110
+ const indexPath = path_1.default.join(resolvedBase, `index${extension}`);
111
+ if (fs_1.default.existsSync(indexPath) && fs_1.default.statSync(indexPath).isFile()) {
112
+ return indexPath;
113
+ }
114
+ }
115
+ }
116
+ }
117
+ catch {
118
+ // continue
119
+ }
120
+ return null;
121
+ }
122
+ function createProjectAliasResolver(cwd, resolveFromWorkspace) {
123
+ if (projectAliasCache.has(cwd)) {
124
+ return projectAliasCache.get(cwd) ?? null;
125
+ }
126
+ const configPath = ['tsconfig.json', 'jsconfig.json']
127
+ .map((filename) => path_1.default.join(cwd, filename))
128
+ .find((filename) => fs_1.default.existsSync(filename));
129
+ if (!configPath) {
130
+ projectAliasCache.set(cwd, null);
131
+ return null;
132
+ }
133
+ let compilerOptions = null;
134
+ try {
135
+ const typescriptPath = resolveFromWorkspace('typescript', cwd);
136
+ const ts = require(typescriptPath);
137
+ const readResult = ts.readConfigFile(configPath, ts.sys.readFile);
138
+ if (!readResult.error) {
139
+ compilerOptions = readResult.config?.compilerOptions ?? null;
140
+ }
141
+ }
142
+ catch {
143
+ // fallback to plain JSON parse below
144
+ }
145
+ if (!compilerOptions) {
146
+ try {
147
+ const rawConfig = fs_1.default.readFileSync(configPath, 'utf-8');
148
+ const parsedConfig = JSON.parse(stripJsonComments(rawConfig));
149
+ compilerOptions = parsedConfig.compilerOptions ?? null;
150
+ }
151
+ catch {
152
+ compilerOptions = null;
153
+ }
154
+ }
155
+ const configDir = path_1.default.dirname(configPath);
156
+ const rawPaths = compilerOptions?.paths;
157
+ if (!rawPaths || typeof rawPaths !== 'object') {
158
+ projectAliasCache.set(cwd, null);
159
+ return null;
160
+ }
161
+ const baseDir = path_1.default.resolve(configDir, typeof compilerOptions?.baseUrl === 'string' && compilerOptions.baseUrl.trim()
162
+ ? compilerOptions.baseUrl
163
+ : '.');
164
+ const exactEntries = new Map();
165
+ const wildcardEntries = [];
166
+ for (const [pattern, targetsValue] of Object.entries(rawPaths)) {
167
+ const targets = Array.isArray(targetsValue)
168
+ ? targetsValue.filter((entry) => typeof entry === 'string' && entry.trim().length > 0)
169
+ : [];
170
+ if (targets.length === 0)
171
+ continue;
172
+ if (pattern.includes('*')) {
173
+ const starIndex = pattern.indexOf('*');
174
+ wildcardEntries.push({
175
+ prefix: pattern.slice(0, starIndex),
176
+ suffix: pattern.slice(starIndex + 1),
177
+ targets,
178
+ });
179
+ }
180
+ else {
181
+ exactEntries.set(pattern, targets);
182
+ }
183
+ }
184
+ const resolver = {
185
+ resolve(request) {
186
+ if (!isBareSpecifier(request))
187
+ return null;
188
+ const resolveTargets = (targets, wildcardValue) => {
189
+ for (const targetPattern of targets) {
190
+ const replacedTarget = wildcardValue === undefined ? targetPattern : targetPattern.replace('*', wildcardValue);
191
+ const candidate = resolveAliasTargetPath(path_1.default.resolve(baseDir, replacedTarget));
192
+ if (candidate) {
193
+ return candidate;
194
+ }
195
+ }
196
+ return null;
197
+ };
198
+ const exactMatch = exactEntries.get(request);
199
+ if (exactMatch) {
200
+ return resolveTargets(exactMatch);
201
+ }
202
+ for (const entry of wildcardEntries) {
203
+ if (!request.startsWith(entry.prefix) || !request.endsWith(entry.suffix)) {
204
+ continue;
205
+ }
206
+ const wildcardValue = request.slice(entry.prefix.length, request.length - entry.suffix.length);
207
+ const resolved = resolveTargets(entry.targets, wildcardValue);
208
+ if (resolved) {
209
+ return resolved;
210
+ }
211
+ }
212
+ return null;
213
+ },
214
+ };
215
+ projectAliasCache.set(cwd, resolver);
216
+ return resolver;
217
+ }
@@ -80,6 +80,7 @@ const request_context_1 = require("./request-context");
80
80
  const app_router_runtime_1 = require("./app-router-runtime");
81
81
  const fetch_policy_1 = require("./fetch-policy");
82
82
  const vista_import_map_1 = require("./vista-import-map");
83
+ const project_alias_resolver_1 = require("./project-alias-resolver");
83
84
  // Support CSS imports on server runtime
84
85
  // - Regular .css: ignored (handled by PostCSS)
85
86
  // - .module.css: return empty class mapping (webpack build handles real mappings)
@@ -273,10 +274,15 @@ function installSingleReactResolution(cwd) {
273
274
  }
274
275
  }
275
276
  originalResolveFilename = CjsModule._resolveFilename;
277
+ const projectAliasResolver = (0, project_alias_resolver_1.createProjectAliasResolver)(cwd, resolveFromWorkspace);
276
278
  CjsModule._resolveFilename = function (request, parent, isMain, options) {
277
279
  const vistaResolvedPath = resolveVistaInternalRequest(request);
278
280
  if (vistaResolvedPath)
279
281
  return vistaResolvedPath;
282
+ const aliasResolvedPath = projectAliasResolver?.resolve(request);
283
+ if (aliasResolvedPath) {
284
+ return originalResolveFilename.call(this, aliasResolvedPath, parent, isMain, options);
285
+ }
280
286
  if (request === 'react')
281
287
  return reactPath;
282
288
  if (request === 'react-dom')
@@ -20,6 +20,7 @@ const fetch_policy_1 = require("./fetch-policy");
20
20
  const runtime_artifacts_1 = require("./runtime-artifacts");
21
21
  const config_1 = require("../config");
22
22
  const vista_import_map_1 = require("./vista-import-map");
23
+ const project_alias_resolver_1 = require("./project-alias-resolver");
23
24
  // NOTE: RouteErrorBoundary and RouteSuspense are 'use client' components.
24
25
  // Under --conditions react-server, React.Component is not available, so we
25
26
  // must NOT import them at the top level. Instead we lazy-require them after
@@ -190,7 +191,7 @@ function isClientBoundaryFile(filename, transpiledSource) {
190
191
  clientDirectiveCache.set(filename, isClient);
191
192
  return isClient;
192
193
  }
193
- function installSingleReactResolution() {
194
+ function installSingleReactResolution(cwd) {
194
195
  if (reactResolutionInstalled)
195
196
  return;
196
197
  let reactPath;
@@ -203,10 +204,15 @@ function installSingleReactResolution() {
203
204
  return;
204
205
  }
205
206
  originalResolveFilename = CjsModule._resolveFilename;
207
+ const projectAliasResolver = (0, project_alias_resolver_1.createProjectAliasResolver)(cwd, resolveFromWorkspace);
206
208
  CjsModule._resolveFilename = function (request, parent, isMain, options) {
207
209
  const vistaResolvedPath = resolveVistaInternalRequest(request);
208
210
  if (vistaResolvedPath)
209
211
  return vistaResolvedPath;
212
+ const aliasResolvedPath = projectAliasResolver?.resolve(request);
213
+ if (aliasResolvedPath) {
214
+ return originalResolveFilename.call(this, aliasResolvedPath, parent, isMain, options);
215
+ }
210
216
  if (request === 'react')
211
217
  return reactPath;
212
218
  if (request === 'react-dom')
@@ -472,7 +478,7 @@ function startUpstream() {
472
478
  const isDev = process.env.NODE_ENV !== 'production';
473
479
  const port = resolvePort(3101);
474
480
  const vistaDirRoot = path_1.default.join(cwd, constants_1.BUILD_DIR);
475
- installSingleReactResolution();
481
+ installSingleReactResolution(runtimeRoot);
476
482
  setupTypeScriptRuntime(runtimeRoot);
477
483
  const flightServerPath = resolveFromWorkspace('react-server-dom-webpack/server.node', cwd);
478
484
  const flightServer = require(flightServerPath);
@@ -27,6 +27,7 @@ const spawn_permissions_1 = require("./spawn-permissions");
27
27
  const config_1 = require("../config");
28
28
  const ppr_1 = require("./ppr");
29
29
  const vista_import_map_1 = require("./vista-import-map");
30
+ const project_alias_resolver_1 = require("./project-alias-resolver");
30
31
  const CjsModule = require('module');
31
32
  let staticRuntimeReady = false;
32
33
  let reactResolutionInstalled = false;
@@ -72,10 +73,15 @@ function installSingleReactResolution(cwd) {
72
73
  }
73
74
  }
74
75
  originalResolveFilename = CjsModule._resolveFilename;
76
+ const projectAliasResolver = (0, project_alias_resolver_1.createProjectAliasResolver)(cwd, resolveFromWorkspace);
75
77
  CjsModule._resolveFilename = function (request, parent, isMain, options) {
76
78
  const vistaResolvedPath = resolveVistaInternalRequest(request);
77
79
  if (vistaResolvedPath)
78
80
  return vistaResolvedPath;
81
+ const aliasResolvedPath = projectAliasResolver?.resolve(request);
82
+ if (aliasResolvedPath) {
83
+ return originalResolveFilename.call(this, aliasResolvedPath, parent, isMain, options);
84
+ }
79
85
  if (request === 'react')
80
86
  return reactPath;
81
87
  if (request === 'react-dom')
package/package.json CHANGED
@@ -1,148 +1,149 @@
1
- {
2
- "name": "@vistagenic/vista",
3
- "version": "0.2.13",
4
- "description": "The React Framework for Visionaries - Rust-powered SSR with Server Components",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/vistagen/Vista-Js.git",
10
- "directory": "packages/vista"
11
- },
12
- "author": "Vista Team",
13
- "license": "MIT",
14
- "keywords": [
15
- "react",
16
- "framework",
17
- "ssr",
18
- "server-components",
19
- "rsc",
20
- "rust",
21
- "swc",
22
- "vista"
23
- ],
24
- "files": [
25
- "dist",
26
- "bin"
27
- ],
28
- "exports": {
29
- ".": {
30
- "react-server": "./dist/react-server.js",
31
- "types": "./dist/index.d.ts",
32
- "default": "./dist/index.js"
33
- },
34
- "./link": {
35
- "types": "./dist/client/link.d.ts",
36
- "default": "./dist/client/link.js"
37
- },
38
- "./image": {
39
- "react-server": "./dist/image/react-server.js",
40
- "types": "./dist/image/index.d.ts",
41
- "default": "./dist/image/index.js"
42
- },
43
- "./router": {
44
- "types": "./dist/client/router.d.ts",
45
- "default": "./dist/client/router.js"
46
- },
47
- "./navigation": {
48
- "types": "./dist/client/navigation.d.ts",
49
- "default": "./dist/client/navigation.js"
50
- },
51
- "./dynamic": {
52
- "types": "./dist/client/dynamic.d.ts",
53
- "default": "./dist/client/dynamic.js"
54
- },
55
- "./script": {
56
- "types": "./dist/client/script.d.ts",
57
- "default": "./dist/client/script.js"
58
- },
59
- "./font": {
60
- "types": "./dist/font/index.d.ts",
61
- "default": "./dist/font/index.js"
62
- },
63
- "./font/google": {
64
- "types": "./dist/font/google.d.ts",
65
- "default": "./dist/font/google.js"
66
- },
67
- "./font/local": {
68
- "types": "./dist/font/local.d.ts",
69
- "default": "./dist/font/local.js"
70
- },
71
- "./head": {
72
- "react-server": "./dist/client/head.react-server.js",
73
- "types": "./dist/client/head.d.ts",
74
- "default": "./dist/client/head.js"
75
- },
76
- "./config": {
77
- "types": "./dist/config.d.ts",
78
- "default": "./dist/config.js"
79
- },
80
- "./stack": {
81
- "types": "./dist/stack/index.d.ts",
82
- "default": "./dist/stack/index.js"
83
- },
84
- "./stack/client": {
85
- "types": "./dist/stack/client/index.d.ts",
86
- "default": "./dist/stack/client/index.js"
87
- },
88
- "./client/rsc-router": {
89
- "types": "./dist/client/rsc-router.d.ts",
90
- "default": "./dist/client/rsc-router.js"
91
- },
92
- "./client/server-actions": {
93
- "types": "./dist/client/server-actions.d.ts",
94
- "default": "./dist/client/server-actions.js"
95
- },
96
- "./server": {
97
- "types": "./dist/server/index.d.ts",
98
- "default": "./dist/server/index.js"
99
- },
100
- "./server/runtime-actions": {
101
- "types": "./dist/server/runtime-actions.d.ts",
102
- "default": "./dist/server/runtime-actions.js"
103
- },
104
- "./cache": {
105
- "types": "./dist/server/cache.d.ts",
106
- "default": "./dist/server/cache.js"
107
- },
108
- "./package.json": "./package.json"
109
- },
110
- "bin": {
111
- "vista": "bin/vista.js"
112
- },
113
- "publishConfig": {
114
- "access": "public"
115
- },
116
- "scripts": {
117
- "build": "tsc"
118
- },
119
- "dependencies": {
120
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
121
- "@swc-node/register": "^1.9.0",
122
- "@swc/core": "^1.4.0",
123
- "chokidar": "^3.6.0",
124
- "css-loader": "^7.1.2",
125
- "esbuild": "^0.24.2",
126
- "express": "^4.21.2",
127
- "mini-css-extract-plugin": "^2.9.4",
128
- "null-loader": "^4.0.1",
129
- "react": "^19.0.0",
130
- "react-dom": "^19.0.0",
131
- "react-refresh": "^0.14.0",
132
- "react-server-dom-webpack": "^19.0.0",
133
- "swc-loader": "^0.2.6",
134
- "ts-node": "^10.9.2",
135
- "webpack": "^5.90.0",
136
- "webpack-dev-middleware": "^7.0.0",
137
- "webpack-hot-middleware": "^2.26.0"
138
- },
139
- "devDependencies": {
140
- "@types/express": "^5.0.0",
141
- "@types/node": "^22.10.2",
142
- "@types/react": "^19.0.1",
143
- "@types/react-dom": "^19.0.2",
144
- "@types/webpack": "^5.28.5",
145
- "@types/webpack-hot-middleware": "^2.25.9",
146
- "typescript": "^5.7.2"
147
- }
148
- }
1
+ {
2
+ "name": "@vistagenic/vista",
3
+ "version": "0.2.14",
4
+ "description": "The React Framework for Visionaries - Rust-powered SSR with Server Components",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/vistakit/Vista-Js.git",
10
+ "directory": "packages/vista"
11
+ },
12
+ "author": "Vista Team",
13
+ "license": "MIT",
14
+ "keywords": [
15
+ "react",
16
+ "framework",
17
+ "ssr",
18
+ "server-components",
19
+ "rsc",
20
+ "rust",
21
+ "swc",
22
+ "vista"
23
+ ],
24
+ "files": [
25
+ "dist",
26
+ "bin"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "react-server": "./dist/react-server.js",
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./link": {
35
+ "types": "./dist/client/link.d.ts",
36
+ "default": "./dist/client/link.js"
37
+ },
38
+ "./image": {
39
+ "react-server": "./dist/image/react-server.js",
40
+ "types": "./dist/image/index.d.ts",
41
+ "default": "./dist/image/index.js"
42
+ },
43
+ "./router": {
44
+ "types": "./dist/client/router.d.ts",
45
+ "default": "./dist/client/router.js"
46
+ },
47
+ "./navigation": {
48
+ "types": "./dist/client/navigation.d.ts",
49
+ "default": "./dist/client/navigation.js"
50
+ },
51
+ "./dynamic": {
52
+ "types": "./dist/client/dynamic.d.ts",
53
+ "default": "./dist/client/dynamic.js"
54
+ },
55
+ "./script": {
56
+ "types": "./dist/client/script.d.ts",
57
+ "default": "./dist/client/script.js"
58
+ },
59
+ "./font": {
60
+ "types": "./dist/font/index.d.ts",
61
+ "default": "./dist/font/index.js"
62
+ },
63
+ "./font/google": {
64
+ "types": "./dist/font/google.d.ts",
65
+ "default": "./dist/font/google.js"
66
+ },
67
+ "./font/local": {
68
+ "types": "./dist/font/local.d.ts",
69
+ "default": "./dist/font/local.js"
70
+ },
71
+ "./head": {
72
+ "react-server": "./dist/client/head.react-server.js",
73
+ "types": "./dist/client/head.d.ts",
74
+ "default": "./dist/client/head.js"
75
+ },
76
+ "./config": {
77
+ "types": "./dist/config.d.ts",
78
+ "default": "./dist/config.js"
79
+ },
80
+ "./stack": {
81
+ "types": "./dist/stack/index.d.ts",
82
+ "default": "./dist/stack/index.js"
83
+ },
84
+ "./stack/client": {
85
+ "types": "./dist/stack/client/index.d.ts",
86
+ "default": "./dist/stack/client/index.js"
87
+ },
88
+ "./client/rsc-router": {
89
+ "types": "./dist/client/rsc-router.d.ts",
90
+ "default": "./dist/client/rsc-router.js"
91
+ },
92
+ "./client/server-actions": {
93
+ "types": "./dist/client/server-actions.d.ts",
94
+ "default": "./dist/client/server-actions.js"
95
+ },
96
+ "./server": {
97
+ "types": "./dist/server/index.d.ts",
98
+ "default": "./dist/server/index.js"
99
+ },
100
+ "./server/runtime-actions": {
101
+ "types": "./dist/server/runtime-actions.d.ts",
102
+ "default": "./dist/server/runtime-actions.js"
103
+ },
104
+ "./cache": {
105
+ "types": "./dist/server/cache.d.ts",
106
+ "default": "./dist/server/cache.js"
107
+ },
108
+ "./package.json": "./package.json"
109
+ },
110
+ "bin": {
111
+ "vista": "bin/vista.js"
112
+ },
113
+ "publishConfig": {
114
+ "access": "public"
115
+ },
116
+ "scripts": {
117
+ "build": "tsc"
118
+ },
119
+ "dependencies": {
120
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
121
+ "@swc-node/register": "^1.9.0",
122
+ "@swc/core": "^1.4.0",
123
+ "chokidar": "^3.6.0",
124
+ "css-loader": "^7.1.2",
125
+ "esbuild": "^0.24.2",
126
+ "express": "^4.21.2",
127
+ "mini-css-extract-plugin": "^2.9.4",
128
+ "null-loader": "^4.0.1",
129
+ "react": "^19.0.0",
130
+ "react-dom": "^19.0.0",
131
+ "react-refresh": "^0.14.0",
132
+ "react-server-dom-webpack": "^19.0.0",
133
+ "swc-loader": "^0.2.6",
134
+ "ts-node": "^10.9.2",
135
+ "webpack": "^5.90.0",
136
+ "webpack-dev-middleware": "^7.0.0",
137
+ "webpack-hot-middleware": "^2.26.0"
138
+ },
139
+ "devDependencies": {
140
+ "@types/express": "^5.0.0",
141
+ "@types/node": "^22.10.2",
142
+ "@types/react": "^19.0.1",
143
+ "@types/react-dom": "^19.0.2",
144
+ "@types/webpack": "^5.28.5",
145
+ "@types/webpack-hot-middleware": "^2.25.9",
146
+ "typescript": "^5.7.2"
147
+ },
148
+ "gitHead": "d1b9f715d6365d8e1f553e96b752fbce8d98df7c"
149
+ }