@kuratchi/js 0.0.15 → 0.0.16
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/README.md +10 -8
- package/dist/cli.js +80 -47
- package/dist/compiler/api-route-pipeline.d.ts +8 -0
- package/dist/compiler/api-route-pipeline.js +23 -0
- package/dist/compiler/asset-pipeline.d.ts +7 -0
- package/dist/compiler/asset-pipeline.js +33 -0
- package/dist/compiler/client-module-pipeline.d.ts +25 -0
- package/dist/compiler/client-module-pipeline.js +257 -0
- package/dist/compiler/compiler-shared.d.ts +55 -0
- package/dist/compiler/compiler-shared.js +4 -0
- package/dist/compiler/component-pipeline.d.ts +15 -0
- package/dist/compiler/component-pipeline.js +163 -0
- package/dist/compiler/config-reading.d.ts +11 -0
- package/dist/compiler/config-reading.js +323 -0
- package/dist/compiler/convention-discovery.d.ts +9 -0
- package/dist/compiler/convention-discovery.js +83 -0
- package/dist/compiler/durable-object-pipeline.d.ts +9 -0
- package/dist/compiler/durable-object-pipeline.js +255 -0
- package/dist/compiler/error-page-pipeline.d.ts +1 -0
- package/dist/compiler/error-page-pipeline.js +16 -0
- package/dist/compiler/import-linking.d.ts +36 -0
- package/dist/compiler/import-linking.js +139 -0
- package/dist/compiler/index.d.ts +3 -3
- package/dist/compiler/index.js +133 -3305
- package/dist/compiler/layout-pipeline.d.ts +31 -0
- package/dist/compiler/layout-pipeline.js +155 -0
- package/dist/compiler/page-route-pipeline.d.ts +16 -0
- package/dist/compiler/page-route-pipeline.js +62 -0
- package/dist/compiler/parser.d.ts +4 -0
- package/dist/compiler/parser.js +433 -51
- package/dist/compiler/root-layout-pipeline.d.ts +10 -0
- package/dist/compiler/root-layout-pipeline.js +517 -0
- package/dist/compiler/route-discovery.d.ts +7 -0
- package/dist/compiler/route-discovery.js +87 -0
- package/dist/compiler/route-pipeline.d.ts +57 -0
- package/dist/compiler/route-pipeline.js +296 -0
- package/dist/compiler/route-state-pipeline.d.ts +25 -0
- package/dist/compiler/route-state-pipeline.js +139 -0
- package/dist/compiler/routes-module-feature-blocks.d.ts +2 -0
- package/dist/compiler/routes-module-feature-blocks.js +330 -0
- package/dist/compiler/routes-module-pipeline.d.ts +2 -0
- package/dist/compiler/routes-module-pipeline.js +6 -0
- package/dist/compiler/routes-module-runtime-shell.d.ts +2 -0
- package/dist/compiler/routes-module-runtime-shell.js +81 -0
- package/dist/compiler/routes-module-types.d.ts +44 -0
- package/dist/compiler/routes-module-types.js +1 -0
- package/dist/compiler/script-transform.d.ts +16 -0
- package/dist/compiler/script-transform.js +218 -0
- package/dist/compiler/server-module-pipeline.d.ts +13 -0
- package/dist/compiler/server-module-pipeline.js +124 -0
- package/dist/compiler/template.d.ts +13 -1
- package/dist/compiler/template.js +315 -58
- package/dist/compiler/worker-output-pipeline.d.ts +13 -0
- package/dist/compiler/worker-output-pipeline.js +37 -0
- package/dist/compiler/wrangler-sync.d.ts +14 -0
- package/dist/compiler/wrangler-sync.js +185 -0
- package/dist/runtime/app.js +15 -3
- package/dist/runtime/generated-worker.d.ts +33 -0
- package/dist/runtime/generated-worker.js +412 -0
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/router.d.ts +2 -1
- package/dist/runtime/router.js +12 -3
- package/dist/runtime/types.d.ts +8 -2
- package/package.json +5 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { stripTopLevelImports } from './parser.js';
|
|
3
|
+
function collectBindingNames(name, out) {
|
|
4
|
+
if (ts.isIdentifier(name)) {
|
|
5
|
+
out.add(name.text);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
for (const element of name.elements) {
|
|
9
|
+
if (ts.isOmittedExpression(element))
|
|
10
|
+
continue;
|
|
11
|
+
collectBindingNames(element.name, out);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function collectScopeBindings(node) {
|
|
15
|
+
const names = new Set();
|
|
16
|
+
const collectVariableStatement = (statement) => {
|
|
17
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
18
|
+
collectBindingNames(declaration.name, names);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
if (ts.isSourceFile(node)) {
|
|
22
|
+
for (const statement of node.statements) {
|
|
23
|
+
if (ts.isImportDeclaration(statement)) {
|
|
24
|
+
const clause = statement.importClause;
|
|
25
|
+
if (!clause)
|
|
26
|
+
continue;
|
|
27
|
+
if (clause.name)
|
|
28
|
+
names.add(clause.name.text);
|
|
29
|
+
if (clause.namedBindings) {
|
|
30
|
+
if (ts.isNamedImports(clause.namedBindings)) {
|
|
31
|
+
for (const element of clause.namedBindings.elements) {
|
|
32
|
+
names.add(element.name.text);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (ts.isNamespaceImport(clause.namedBindings)) {
|
|
36
|
+
names.add(clause.namedBindings.name.text);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ts.isVariableStatement(statement)) {
|
|
42
|
+
collectVariableStatement(statement);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name) {
|
|
46
|
+
names.add(statement.name.text);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return names;
|
|
50
|
+
}
|
|
51
|
+
if (ts.isBlock(node) || ts.isModuleBlock(node)) {
|
|
52
|
+
for (const statement of node.statements) {
|
|
53
|
+
if (ts.isVariableStatement(statement)) {
|
|
54
|
+
collectVariableStatement(statement);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name) {
|
|
58
|
+
names.add(statement.name.text);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return names;
|
|
62
|
+
}
|
|
63
|
+
if (ts.isCatchClause(node)) {
|
|
64
|
+
if (node.variableDeclaration) {
|
|
65
|
+
collectBindingNames(node.variableDeclaration.name, names);
|
|
66
|
+
}
|
|
67
|
+
return names;
|
|
68
|
+
}
|
|
69
|
+
if (ts.isFunctionLike(node)) {
|
|
70
|
+
if (node.name && ts.isIdentifier(node.name))
|
|
71
|
+
names.add(node.name.text);
|
|
72
|
+
for (const parameter of node.parameters) {
|
|
73
|
+
collectBindingNames(parameter.name, names);
|
|
74
|
+
}
|
|
75
|
+
return names;
|
|
76
|
+
}
|
|
77
|
+
return names;
|
|
78
|
+
}
|
|
79
|
+
function isScopeNode(node) {
|
|
80
|
+
return ts.isSourceFile(node)
|
|
81
|
+
|| ts.isBlock(node)
|
|
82
|
+
|| ts.isModuleBlock(node)
|
|
83
|
+
|| ts.isCatchClause(node)
|
|
84
|
+
|| ts.isFunctionLike(node);
|
|
85
|
+
}
|
|
86
|
+
function shouldRewriteEnvIdentifier(node) {
|
|
87
|
+
const parent = node.parent;
|
|
88
|
+
if (!parent)
|
|
89
|
+
return false;
|
|
90
|
+
if (ts.isImportClause(parent) || ts.isImportSpecifier(parent) || ts.isNamespaceImport(parent) || ts.isNamedImports(parent))
|
|
91
|
+
return false;
|
|
92
|
+
if (ts.isVariableDeclaration(parent) && parent.name === node)
|
|
93
|
+
return false;
|
|
94
|
+
if (ts.isParameter(parent) && parent.name === node)
|
|
95
|
+
return false;
|
|
96
|
+
if (ts.isFunctionDeclaration(parent) && parent.name === node)
|
|
97
|
+
return false;
|
|
98
|
+
if (ts.isClassDeclaration(parent) && parent.name === node)
|
|
99
|
+
return false;
|
|
100
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === node)
|
|
101
|
+
return false;
|
|
102
|
+
if (ts.isQualifiedName(parent) && parent.right === node)
|
|
103
|
+
return false;
|
|
104
|
+
if (ts.isPropertyAssignment(parent) && parent.name === node)
|
|
105
|
+
return false;
|
|
106
|
+
if (ts.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
107
|
+
return true;
|
|
108
|
+
if (ts.isBindingElement(parent) && parent.name === node)
|
|
109
|
+
return false;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
function transformSource(source, visitorFactory) {
|
|
113
|
+
const sourceFile = ts.createSourceFile('kuratchi-script.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
114
|
+
const scopeStack = [];
|
|
115
|
+
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
116
|
+
const result = ts.transform(sourceFile, [context => {
|
|
117
|
+
const baseFactory = visitorFactory({
|
|
118
|
+
isShadowed(name) {
|
|
119
|
+
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
120
|
+
if (scopeStack[i].names.has(name))
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
},
|
|
125
|
+
factory: context.factory,
|
|
126
|
+
});
|
|
127
|
+
const visitNode = (node) => {
|
|
128
|
+
let pushed = false;
|
|
129
|
+
if (isScopeNode(node)) {
|
|
130
|
+
scopeStack.push({ names: collectScopeBindings(node) });
|
|
131
|
+
pushed = true;
|
|
132
|
+
}
|
|
133
|
+
const transformed = baseFactory(node);
|
|
134
|
+
const visited = ts.visitEachChild(transformed, visitNode, context);
|
|
135
|
+
if (pushed)
|
|
136
|
+
scopeStack.pop();
|
|
137
|
+
return visited;
|
|
138
|
+
};
|
|
139
|
+
return file => ts.visitNode(file, visitNode);
|
|
140
|
+
}]);
|
|
141
|
+
const transformedFile = result.transformed[0];
|
|
142
|
+
const printed = printer.printFile(transformedFile);
|
|
143
|
+
result.dispose();
|
|
144
|
+
return printed;
|
|
145
|
+
}
|
|
146
|
+
export function rewriteImportedFunctionCalls(source, fnToModule) {
|
|
147
|
+
const fnEntries = Object.entries(fnToModule).filter(([fnName]) => /^[A-Za-z_$][\w$]*$/.test(fnName));
|
|
148
|
+
if (fnEntries.length === 0)
|
|
149
|
+
return source;
|
|
150
|
+
const fnSet = new Set(fnEntries.map(([fnName]) => fnName));
|
|
151
|
+
return transformSource(source, ({ isShadowed, factory }) => (node) => {
|
|
152
|
+
if (ts.isCallExpression(node)
|
|
153
|
+
&& ts.isIdentifier(node.expression)
|
|
154
|
+
&& fnSet.has(node.expression.text)
|
|
155
|
+
&& !isShadowed(node.expression.text)) {
|
|
156
|
+
const moduleId = fnToModule[node.expression.text];
|
|
157
|
+
return factory.updateCallExpression(node, factory.createPropertyAccessExpression(factory.createIdentifier(moduleId), factory.createIdentifier(node.expression.text)), node.typeArguments, node.arguments);
|
|
158
|
+
}
|
|
159
|
+
return node;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export function rewriteWorkerEnvAliases(source, aliases) {
|
|
163
|
+
const aliasSet = new Set(aliases.filter((alias) => /^[A-Za-z_$][\w$]*$/.test(alias)));
|
|
164
|
+
if (aliasSet.size === 0)
|
|
165
|
+
return source;
|
|
166
|
+
return transformSource(source, ({ isShadowed, factory }) => (node) => {
|
|
167
|
+
if (ts.isIdentifier(node)
|
|
168
|
+
&& aliasSet.has(node.text)
|
|
169
|
+
&& !isShadowed(node.text)
|
|
170
|
+
&& shouldRewriteEnvIdentifier(node)) {
|
|
171
|
+
return factory.createIdentifier('__env');
|
|
172
|
+
}
|
|
173
|
+
return node;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export function buildDevAliasDeclarations(aliases, isDev) {
|
|
177
|
+
if (!aliases || aliases.length === 0)
|
|
178
|
+
return '';
|
|
179
|
+
return aliases.map((alias) => `const ${alias} = ${isDev ? 'true' : 'false'};`).join('\n');
|
|
180
|
+
}
|
|
181
|
+
export function buildSegmentedScriptBody(opts) {
|
|
182
|
+
const { segments, fnToModule, importDecls, workerEnvAliases, devAliases, isDev, asyncMode } = opts;
|
|
183
|
+
const lines = [];
|
|
184
|
+
const routeDevDecls = buildDevAliasDeclarations(devAliases, isDev);
|
|
185
|
+
if (routeDevDecls)
|
|
186
|
+
lines.push(routeDevDecls);
|
|
187
|
+
if (importDecls)
|
|
188
|
+
lines.push(importDecls);
|
|
189
|
+
lines.push('const __segmentData: Record<string, any> = {};');
|
|
190
|
+
const availableVars = [];
|
|
191
|
+
let segmentIndex = 0;
|
|
192
|
+
for (const segment of segments) {
|
|
193
|
+
if (!segment.script)
|
|
194
|
+
continue;
|
|
195
|
+
let segmentBody = stripTopLevelImports(segment.script);
|
|
196
|
+
segmentBody = rewriteImportedFunctionCalls(segmentBody, fnToModule);
|
|
197
|
+
segmentBody = rewriteWorkerEnvAliases(segmentBody, workerEnvAliases);
|
|
198
|
+
if (!segmentBody.trim())
|
|
199
|
+
continue;
|
|
200
|
+
const returnVars = segment.dataVars.filter((name) => /^[A-Za-z_$][\w$]*$/.test(name));
|
|
201
|
+
const segmentVar = '__segment_' + segmentIndex++;
|
|
202
|
+
const invokePrefix = asyncMode ? 'await ' : '';
|
|
203
|
+
const factoryPrefix = asyncMode ? 'async ' : '';
|
|
204
|
+
lines.push('const ' + segmentVar + ' = ' + invokePrefix + '(' + factoryPrefix + '(__ctx: Record<string, any>) => {');
|
|
205
|
+
lines.push(segmentBody);
|
|
206
|
+
lines.push(returnVars.length > 0 ? 'return { ' + returnVars.join(', ') + ' };' : 'return {};');
|
|
207
|
+
lines.push('})(__segmentData);');
|
|
208
|
+
lines.push('Object.assign(__segmentData, ' + segmentVar + ');');
|
|
209
|
+
for (const name of returnVars) {
|
|
210
|
+
if (!availableVars.includes(name))
|
|
211
|
+
availableVars.push(name);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!asyncMode && availableVars.length > 0) {
|
|
215
|
+
lines.push('const { ' + availableVars.join(', ') + ' } = __segmentData;');
|
|
216
|
+
}
|
|
217
|
+
return lines.join('\n');
|
|
218
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ServerModuleCompiler {
|
|
2
|
+
toModuleSpecifier(fromFileAbs: string, toFileAbs: string): string;
|
|
3
|
+
transformModule(entryAbsPath: string): string;
|
|
4
|
+
resolveCompiledImportPath(origPath: string, importerDir: string, outFileDir: string): string;
|
|
5
|
+
}
|
|
6
|
+
interface CreateServerModuleCompilerOptions {
|
|
7
|
+
projectDir: string;
|
|
8
|
+
srcDir: string;
|
|
9
|
+
doHandlerProxyPaths: Map<string, string>;
|
|
10
|
+
writeFile: (filePath: string, content: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function createServerModuleCompiler(options: CreateServerModuleCompilerOptions): ServerModuleCompiler;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
function resolveExistingModuleFile(absBase) {
|
|
4
|
+
const candidates = [
|
|
5
|
+
absBase,
|
|
6
|
+
absBase + '.ts',
|
|
7
|
+
absBase + '.js',
|
|
8
|
+
absBase + '.mjs',
|
|
9
|
+
absBase + '.cjs',
|
|
10
|
+
path.join(absBase, 'index.ts'),
|
|
11
|
+
path.join(absBase, 'index.js'),
|
|
12
|
+
path.join(absBase, 'index.mjs'),
|
|
13
|
+
path.join(absBase, 'index.cjs'),
|
|
14
|
+
];
|
|
15
|
+
for (const candidate of candidates) {
|
|
16
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile())
|
|
17
|
+
return candidate;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
export function createServerModuleCompiler(options) {
|
|
22
|
+
const { projectDir, srcDir, doHandlerProxyPaths, writeFile } = options;
|
|
23
|
+
const transformedServerModules = new Map();
|
|
24
|
+
const modulesOutDir = path.join(projectDir, '.kuratchi', 'modules');
|
|
25
|
+
const normalizedProjectDir = projectDir.replace(/\\/g, '/');
|
|
26
|
+
function toModuleSpecifier(fromFileAbs, toFileAbs) {
|
|
27
|
+
let rel = path.relative(path.dirname(fromFileAbs), toFileAbs).replace(/\\/g, '/');
|
|
28
|
+
if (!rel.startsWith('.'))
|
|
29
|
+
rel = './' + rel;
|
|
30
|
+
return rel;
|
|
31
|
+
}
|
|
32
|
+
function resolveDoProxyTarget(absPath) {
|
|
33
|
+
const normalizedNoExt = absPath.replace(/\\/g, '/').replace(/\.[^.\/]+$/, '');
|
|
34
|
+
const proxyNoExt = doHandlerProxyPaths.get(normalizedNoExt);
|
|
35
|
+
if (!proxyNoExt)
|
|
36
|
+
return null;
|
|
37
|
+
return resolveExistingModuleFile(proxyNoExt) ?? (fs.existsSync(proxyNoExt + '.js') ? proxyNoExt + '.js' : null);
|
|
38
|
+
}
|
|
39
|
+
function resolveImportTarget(importerAbs, spec) {
|
|
40
|
+
if (spec.startsWith('$')) {
|
|
41
|
+
const slashIdx = spec.indexOf('/');
|
|
42
|
+
const folder = slashIdx === -1 ? spec.slice(1) : spec.slice(1, slashIdx);
|
|
43
|
+
const rest = slashIdx === -1 ? '' : spec.slice(slashIdx + 1);
|
|
44
|
+
if (!folder)
|
|
45
|
+
return null;
|
|
46
|
+
const abs = path.join(srcDir, folder, rest);
|
|
47
|
+
return resolveExistingModuleFile(abs) ?? abs;
|
|
48
|
+
}
|
|
49
|
+
if (spec.startsWith('.')) {
|
|
50
|
+
const abs = path.resolve(path.dirname(importerAbs), spec);
|
|
51
|
+
return resolveExistingModuleFile(abs) ?? abs;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function transformModule(entryAbsPath) {
|
|
56
|
+
const resolved = resolveExistingModuleFile(entryAbsPath) ?? entryAbsPath;
|
|
57
|
+
const normalized = resolved.replace(/\\/g, '/');
|
|
58
|
+
const cached = transformedServerModules.get(normalized);
|
|
59
|
+
if (cached)
|
|
60
|
+
return cached;
|
|
61
|
+
const relFromProject = path.relative(projectDir, resolved);
|
|
62
|
+
const outPath = path.join(modulesOutDir, relFromProject);
|
|
63
|
+
transformedServerModules.set(normalized, outPath);
|
|
64
|
+
const outDir = path.dirname(outPath);
|
|
65
|
+
if (!fs.existsSync(outDir))
|
|
66
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
67
|
+
if (!/\.(ts|js|mjs|cjs)$/i.test(resolved) || !fs.existsSync(resolved)) {
|
|
68
|
+
transformedServerModules.set(normalized, resolved);
|
|
69
|
+
return resolved;
|
|
70
|
+
}
|
|
71
|
+
const source = fs.readFileSync(resolved, 'utf-8');
|
|
72
|
+
const rewriteSpecifier = (spec) => {
|
|
73
|
+
const target = resolveImportTarget(resolved, spec);
|
|
74
|
+
if (!target)
|
|
75
|
+
return spec;
|
|
76
|
+
const doProxyTarget = resolveDoProxyTarget(target);
|
|
77
|
+
if (doProxyTarget)
|
|
78
|
+
return toModuleSpecifier(outPath, doProxyTarget);
|
|
79
|
+
const normalizedTarget = target.replace(/\\/g, '/');
|
|
80
|
+
const inProject = normalizedTarget.startsWith(normalizedProjectDir + '/');
|
|
81
|
+
if (!inProject)
|
|
82
|
+
return spec;
|
|
83
|
+
const targetResolved = resolveExistingModuleFile(target) ?? target;
|
|
84
|
+
if (!/\.(ts|js|mjs|cjs)$/i.test(targetResolved))
|
|
85
|
+
return spec;
|
|
86
|
+
const rewrittenTarget = transformModule(targetResolved);
|
|
87
|
+
return toModuleSpecifier(outPath, rewrittenTarget);
|
|
88
|
+
};
|
|
89
|
+
let rewritten = source.replace(/(from\s+)(['"])([^'"]+)\2/g, (_match, prefix, quote, spec) => {
|
|
90
|
+
return `${prefix}${quote}${rewriteSpecifier(spec)}${quote}`;
|
|
91
|
+
});
|
|
92
|
+
rewritten = rewritten.replace(/(import\s*\(\s*)(['"])([^'"]+)\2(\s*\))/g, (_match, prefix, quote, spec, suffix) => {
|
|
93
|
+
return `${prefix}${quote}${rewriteSpecifier(spec)}${quote}${suffix}`;
|
|
94
|
+
});
|
|
95
|
+
writeFile(outPath, rewritten);
|
|
96
|
+
return outPath;
|
|
97
|
+
}
|
|
98
|
+
function resolveCompiledImportPath(origPath, importerDir, outFileDir) {
|
|
99
|
+
const isBareModule = !origPath.startsWith('.') && !origPath.startsWith('/') && !origPath.startsWith('$');
|
|
100
|
+
if (isBareModule)
|
|
101
|
+
return origPath;
|
|
102
|
+
let absImport;
|
|
103
|
+
if (origPath.startsWith('$')) {
|
|
104
|
+
const slashIdx = origPath.indexOf('/');
|
|
105
|
+
const folder = slashIdx === -1 ? origPath.slice(1) : origPath.slice(1, slashIdx);
|
|
106
|
+
const rest = slashIdx === -1 ? '' : origPath.slice(slashIdx + 1);
|
|
107
|
+
absImport = path.join(srcDir, folder, rest);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
absImport = path.resolve(importerDir, origPath);
|
|
111
|
+
}
|
|
112
|
+
const doProxyTarget = resolveDoProxyTarget(absImport);
|
|
113
|
+
const target = doProxyTarget ?? transformModule(absImport);
|
|
114
|
+
let relPath = path.relative(outFileDir, target).replace(/\\/g, '/');
|
|
115
|
+
if (!relPath.startsWith('.'))
|
|
116
|
+
relPath = './' + relPath;
|
|
117
|
+
return relPath;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
toModuleSpecifier,
|
|
121
|
+
transformModule,
|
|
122
|
+
resolveCompiledImportPath,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -19,13 +19,25 @@
|
|
|
19
19
|
* - Lines that are pure JS control flow (for/if/else/}) → emitted as JS
|
|
20
20
|
* - Everything else → emitted as HTML string with {expr} interpolation
|
|
21
21
|
*/
|
|
22
|
+
export interface TemplateRenderSections {
|
|
23
|
+
bodyTemplate: string;
|
|
24
|
+
headTemplate: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CompileTemplateOptions {
|
|
27
|
+
emitCall?: string;
|
|
28
|
+
enableFragmentManifest?: boolean;
|
|
29
|
+
appendNewline?: boolean;
|
|
30
|
+
clientRouteRegistry?: ClientRouteRegistry;
|
|
31
|
+
}
|
|
32
|
+
export declare function splitTemplateRenderSections(template: string): TemplateRenderSections;
|
|
22
33
|
/**
|
|
23
34
|
* Compile a template string into a JS render function body.
|
|
24
35
|
*
|
|
25
36
|
* The generated code expects `data` in scope (destructured load return)
|
|
26
37
|
* and an `__esc` helper for HTML-escaping.
|
|
27
38
|
*/
|
|
28
|
-
export declare function compileTemplate(template: string, componentNames?: Map<string, string>, actionNames?: Set<string>, rpcNameMap?: Map<string, string
|
|
39
|
+
export declare function compileTemplate(template: string, componentNames?: Map<string, string>, actionNames?: Set<string>, rpcNameMap?: Map<string, string>, options?: CompileTemplateOptions): string;
|
|
40
|
+
import type { ClientRouteRegistry } from './client-module-pipeline.js';
|
|
29
41
|
/**
|
|
30
42
|
* Generate the full render function source code.
|
|
31
43
|
*/
|