@seip/bluebird-js 0.1.4 → 0.1.5

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.
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import Config from "./config.js";
5
5
  import html from "./html.js";
6
- import { compileJsx, registerJsxLoader } from "./jsx.js";
6
+ import { compileJsx, registerJsxLoader, stripTsTypes } from "./jsx.js";
7
7
 
8
8
  registerJsxLoader();
9
9
 
@@ -157,8 +157,11 @@ async function importModule(absolutePath) {
157
157
  }
158
158
 
159
159
  const isJsxFile = targetPath.endsWith(".jsx");
160
+ const isTsxFile = targetPath.endsWith(".tsx");
161
+ const isTsFile = targetPath.endsWith(".ts");
162
+ const isJsxOrTsx = isJsxFile || isTsxFile;
160
163
  const rawCode = fs.readFileSync(targetPath, "utf-8");
161
- const hasTemplateJsx = !isJsxFile && (/\$\{\s*<[A-Z]|<[A-Z][a-zA-Z0-9_]*\s+props=/.test(rawCode));
164
+ const hasTemplateJsx = !isJsxOrTsx && (/\$\{\s*<[A-Z]|<[A-Z][a-zA-Z0-9_]*\s+props=/.test(rawCode));
162
165
 
163
166
  let mod;
164
167
  if (hasTemplateJsx) {
@@ -185,8 +188,11 @@ async function importModule(absolutePath) {
185
188
  try {
186
189
  mod = await import(targetUrl);
187
190
  } catch (err) {
188
- if (isJsxFile || absolutePath.includes(".asar")) {
189
- const sourceToLoad = isJsxFile ? compileJsx(rawCode) : rawCode;
191
+ if (isJsxOrTsx || isTsFile || absolutePath.includes(".asar")) {
192
+ let sourceToLoad = isJsxOrTsx ? compileJsx(rawCode, { ts: isTsxFile }) : rawCode;
193
+ if (isTsxFile || isTsFile) {
194
+ sourceToLoad = stripTsTypes(sourceToLoad);
195
+ }
190
196
  const dataUrl = `data:text/javascript;base64,${Buffer.from(sourceToLoad).toString("base64")}`;
191
197
  mod = await import(dataUrl);
192
198
  } else {
@@ -233,27 +239,49 @@ export class ViewLoader {
233
239
  const clean = viewName.replace(/^\/+/, "").replace(/\.(jsx|js|html|ejs)$/, "");
234
240
 
235
241
  const candidates = [
242
+ `${clean}.tsx`,
236
243
  `${clean}.jsx`,
244
+ `${clean}.ts`,
237
245
  `${clean}.js`,
246
+ `${clean}/view.tsx`,
238
247
  `${clean}/view.jsx`,
248
+ `${clean}/view.ts`,
239
249
  `${clean}/view.js`,
250
+ path.join("pages", `${clean}.tsx`),
240
251
  path.join("pages", `${clean}.jsx`),
252
+ path.join("pages", `${clean}.ts`),
241
253
  path.join("pages", `${clean}.js`),
254
+ path.join("pages", `${clean}/view.tsx`),
242
255
  path.join("pages", `${clean}/view.jsx`),
256
+ path.join("pages", `${clean}/view.ts`),
243
257
  path.join("pages", `${clean}/view.js`),
258
+ path.join("components", `${clean}.tsx`),
244
259
  path.join("components", `${clean}.jsx`),
260
+ path.join("components", `${clean}.ts`),
245
261
  path.join("components", `${clean}.js`),
262
+ path.join("components", `${clean}/view.tsx`),
246
263
  path.join("components", `${clean}/view.jsx`),
264
+ path.join("components", `${clean}/view.ts`),
247
265
  path.join("components", `${clean}/view.js`),
266
+ path.join("partials", `${clean}.tsx`),
248
267
  path.join("partials", `${clean}.jsx`),
268
+ path.join("partials", `${clean}.ts`),
249
269
  path.join("partials", `${clean}.js`),
270
+ path.join("partials", `${clean}/view.tsx`),
250
271
  path.join("partials", `${clean}/view.jsx`),
272
+ path.join("partials", `${clean}/view.ts`),
251
273
  path.join("partials", `${clean}/view.js`),
274
+ path.join("islands", `${clean}.tsx`),
252
275
  path.join("islands", `${clean}.jsx`),
276
+ path.join("islands", `${clean}.ts`),
253
277
  path.join("islands", `${clean}.js`),
278
+ path.join("layouts", `${clean}/view.tsx`),
254
279
  path.join("layouts", `${clean}/view.jsx`),
280
+ path.join("layouts", `${clean}/view.ts`),
255
281
  path.join("layouts", `${clean}/view.js`),
282
+ path.join("layouts", `${clean}.tsx`),
256
283
  path.join("layouts", `${clean}.jsx`),
284
+ path.join("layouts", `${clean}.ts`),
257
285
  path.join("layouts", `${clean}.js`),
258
286
  `${clean}.html`,
259
287
  path.join("pages", `${clean}.html`),
@@ -268,12 +296,12 @@ export class ViewLoader {
268
296
 
269
297
  const fullPath = path.resolve(viewsDir, candidate);
270
298
  if (fs.existsSync(fullPath)) {
271
- if (candidate.endsWith(".jsx")) {
299
+ if (candidate.endsWith(".jsx") || candidate.endsWith(".tsx")) {
272
300
  const mod = await importModule(fullPath);
273
301
  return { type: "jsx", module: mod, filePath: fullPath };
274
302
  }
275
303
 
276
- if (candidate.endsWith(".js")) {
304
+ if (candidate.endsWith(".js") || candidate.endsWith(".ts")) {
277
305
  const mod = await importModule(fullPath);
278
306
  return { type: "js", module: mod, filePath: fullPath };
279
307
  }
@@ -297,16 +325,24 @@ export class ViewLoader {
297
325
  */
298
326
  static async loadLayout(layoutName) {
299
327
  if (!layoutName) return null;
300
- const clean = layoutName.replace(/^\/+/, "").replace(/\.(jsx|js|html)$/, "");
328
+ const clean = layoutName.replace(/^\/+/, "").replace(/\.(jsx|tsx|js|ts|html)$/, "");
301
329
 
302
330
  const candidates = [
331
+ path.join("layouts", `${clean}/view.tsx`),
303
332
  path.join("layouts", `${clean}/view.jsx`),
333
+ path.join("layouts", `${clean}/view.ts`),
304
334
  path.join("layouts", `${clean}/view.js`),
335
+ path.join("layouts", `${clean}.tsx`),
305
336
  path.join("layouts", `${clean}.jsx`),
337
+ path.join("layouts", `${clean}.ts`),
306
338
  path.join("layouts", `${clean}.js`),
339
+ `${clean}/view.tsx`,
307
340
  `${clean}/view.jsx`,
341
+ `${clean}/view.ts`,
308
342
  `${clean}/view.js`,
343
+ `${clean}.tsx`,
309
344
  `${clean}.jsx`,
345
+ `${clean}.ts`,
310
346
  `${clean}.js`,
311
347
  path.join("layouts", `${clean}.html`),
312
348
  ];
@@ -317,12 +353,12 @@ export class ViewLoader {
317
353
 
318
354
  const fullPath = path.resolve(viewsDir, candidate);
319
355
  if (fs.existsSync(fullPath)) {
320
- if (candidate.endsWith(".jsx")) {
356
+ if (candidate.endsWith(".jsx") || candidate.endsWith(".tsx")) {
321
357
  const mod = await importModule(fullPath);
322
358
  return { type: "jsx", module: mod, filePath: fullPath };
323
359
  }
324
360
 
325
- if (candidate.endsWith(".js")) {
361
+ if (candidate.endsWith(".js") || candidate.endsWith(".ts")) {
326
362
  const mod = await importModule(fullPath);
327
363
  return { type: "js", module: mod, filePath: fullPath };
328
364
  }
@@ -388,8 +424,10 @@ export class ViewLoader {
388
424
 
389
425
  entries.sort((a, b) => {
390
426
  if (a.isFile() && b.isFile()) {
391
- if (a.name.endsWith(".jsx") && !b.name.endsWith(".jsx")) return -1;
392
- if (!a.name.endsWith(".jsx") && b.name.endsWith(".jsx")) return 1;
427
+ const aIsJsx = a.name.endsWith(".jsx") || a.name.endsWith(".tsx");
428
+ const bIsJsx = b.name.endsWith(".jsx") || b.name.endsWith(".tsx");
429
+ if (aIsJsx && !bIsJsx) return -1;
430
+ if (!aIsJsx && bIsJsx) return 1;
393
431
  }
394
432
  return a.name.localeCompare(b.name);
395
433
  });
@@ -407,7 +445,14 @@ export class ViewLoader {
407
445
  }
408
446
 
409
447
  if (!entry.isFile()) continue;
410
- if (!entry.name.endsWith(".jsx") && !entry.name.endsWith(".js")) continue;
448
+ if (
449
+ !entry.name.endsWith(".jsx") &&
450
+ !entry.name.endsWith(".tsx") &&
451
+ !entry.name.endsWith(".js") &&
452
+ !entry.name.endsWith(".ts")
453
+ ) {
454
+ continue;
455
+ }
411
456
 
412
457
  const ext = path.extname(entry.name);
413
458
  const rawViewName = relPath.slice(0, -ext.length).replace(/\\/g, "/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seip/bluebird-js",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Performance-first Node.js API and web framework with built-in JWT auth, HTML rendering, validation, BaseModel, and multi-level caching",
5
5
  "type": "module",
6
6
  "main": "core/app.js",
@@ -73,7 +73,7 @@
73
73
  "AGENTS.md",
74
74
  "production.md",
75
75
  ".env_example",
76
- "jsconfig.json",
76
+ "jsconfig.json",
77
77
  ".vscode"
78
78
  ],
79
79
  "dependencies": {