@interval/sdk
Advanced tools
Comparing version 1.0.0-dev0 to 1.0.0-dev1
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -12,2 +35,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const fs_1 = __importDefault(require("fs")); | ||
const import_1 = require("@brillout/import"); | ||
const Action_1 = __importDefault(require("../classes/Action")); | ||
@@ -30,2 +54,34 @@ const Page_1 = __importDefault(require("../classes/Page")); | ||
const slug = path_1.default.basename(file, ext || undefined); | ||
const attemptLoadRoute = (fileExports) => { | ||
if (slug === 'index') { | ||
if ('default' in fileExports) { | ||
let defaultExport = fileExports.default; | ||
if ('default' in defaultExport) { | ||
defaultExport = defaultExport.default; | ||
} | ||
if (defaultExport instanceof Page_1.default) { | ||
Object.assign(defaultExport.routes, router.routes); | ||
router = defaultExport; | ||
} | ||
else { | ||
logger.warn(`Default export of ${fullPath} is not a Page class instance, skipping.`); | ||
} | ||
} | ||
} | ||
else { | ||
if ('default' in fileExports) { | ||
let defaultExport = fileExports.default; | ||
if ('default' in defaultExport) { | ||
defaultExport = defaultExport.default; | ||
} | ||
if (defaultExport instanceof Page_1.default || | ||
defaultExport instanceof Action_1.default) { | ||
router.routes[slug] = defaultExport; | ||
} | ||
else { | ||
logger.warn(`Default export of ${fullPath} is not a Page or Action class instance, skipping.`); | ||
} | ||
} | ||
} | ||
}; | ||
if ((await fs.stat(fullPath)).isDirectory()) { | ||
@@ -35,31 +91,15 @@ const group = await loadFolder(path_1.default.join(currentDirectory, slug), logger); | ||
} | ||
else if (ext === '.ts' || ext === '.js') { | ||
else if (ext === '.ts' || ext === '.js' || ext === '.mjs') { | ||
try { | ||
const fileExports = await import(fullPath); | ||
if (slug === 'index') { | ||
if ('default' in fileExports) { | ||
if (fileExports.default instanceof Page_1.default) { | ||
Object.assign(fileExports.default.routes, router.routes); | ||
router = fileExports.default; | ||
} | ||
else { | ||
logger.warn(`Default export of ${fullPath} is not a Page class instance, skipping.`); | ||
} | ||
} | ||
attemptLoadRoute(await Promise.resolve().then(() => __importStar(require(fullPath)))); | ||
} | ||
catch (err) { | ||
logger.debug(`Failed loading file at ${fullPath} as CommonJS, trying again as module.`, err); | ||
try { | ||
attemptLoadRoute(await (0, import_1.import_)(fullPath)); | ||
} | ||
else { | ||
if ('default' in fileExports) { | ||
if (fileExports.default instanceof Page_1.default || | ||
fileExports.default instanceof Action_1.default) { | ||
router.routes[slug] = fileExports.default; | ||
} | ||
else { | ||
logger.warn(`Default export of ${fullPath} is not a Page or Action class instance, skipping.`); | ||
} | ||
} | ||
catch (err) { | ||
logger.warn(`Failed loading file at ${fullPath}, skipping.`, err); | ||
} | ||
} | ||
catch (err) { | ||
logger.warn(`Failed loading file at ${fullPath} as module, skipping.`, err); | ||
} | ||
} | ||
@@ -66,0 +106,0 @@ } |
{ | ||
"name": "@interval/sdk", | ||
"version": "1.0.0-dev0", | ||
"version": "1.0.0-dev1", | ||
"description": "The frontendless framework for high growth companies. Interval automatically generates apps by inlining the UI in your backend code. It's a faster and more maintainable way to build internal tools, rapid prototypes, and more.", | ||
@@ -27,2 +27,3 @@ "homepage": "https://interval.com", | ||
"dependencies": { | ||
"@brillout/import": "^0.2.2", | ||
"cross-fetch": "^3.1.5", | ||
@@ -29,0 +30,0 @@ "evt": "^2.4.10", |
@@ -10,3 +10,2 @@ { | ||
"esModuleInterop": true, | ||
"moduleResolution": "Node16", | ||
"strict": true, | ||
@@ -13,0 +12,0 @@ "strictNullChecks": true, |
Sorry, the diff of this file is too big to display
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1203389
24438
8
4
+ Added@brillout/import@^0.2.2
+ Added@brillout/import@0.2.3(transitive)