@jota-one/drosse
Advanced tools
Comparing version 3.0.2 to 3.1.0--canary.53.3716062239.0
@@ -6,3 +6,3 @@ import Discover from 'node-discover'; | ||
import ansiColors from 'ansi-colors'; | ||
import { getResponseHeader, setResponseHeaders, getRequestHeader, setResponseHeader, createApp, createRouter, readBody } from 'h3'; | ||
import { getResponseHeader, setResponseHeaders, getRequestHeader, setResponseHeader, getRouterParams, getQuery, createApp, createRouter, readBody } from 'h3'; | ||
import { listen } from 'listhen'; | ||
@@ -21,4 +21,6 @@ import { merge, pick, cloneDeep, isEmpty, omit, set as set$1, get as get$1, isString, difference, curry } from 'lodash'; | ||
const version$1 = "3.0.1"; | ||
const version$1 = "3.0.2"; | ||
const RESTART_DISABLED_IN_ESM_MODE = "Restart is not supported in esm mode."; | ||
var config = { | ||
@@ -95,3 +97,3 @@ db: { | ||
const result = path.split(".").reduce((r, p) => { | ||
if (typeof r === "object") { | ||
if (typeof r === "object" && r !== null) { | ||
p = p.startsWith("[") ? p.replace(/\D/g, "") : p; | ||
@@ -243,3 +245,4 @@ return r[p]; | ||
const require = createRequire(import.meta.url); | ||
let cjsRequire; | ||
let esmMode = false; | ||
const getFullPath = (path) => { | ||
@@ -250,12 +253,29 @@ const state = useState(); | ||
}; | ||
const load = async function(path) { | ||
const load$1 = async function(path) { | ||
let module; | ||
const fullPath = getFullPath(path); | ||
console.info("\u{1F5C2} loading module", fullPath); | ||
delete require.cache[fullPath]; | ||
module = require(fullPath); | ||
console.info(`\u{1F5C2} loading ${esmMode ? "esm " : ""}module ${fullPath}`); | ||
if (esmMode) { | ||
module = await import(fullPath); | ||
} else { | ||
if (!cjsRequire) { | ||
cjsRequire = createRequire(import.meta.url); | ||
} | ||
delete require.cache[fullPath]; | ||
module = require(fullPath); | ||
} | ||
return module; | ||
}; | ||
const setEsmMode$1 = function(isEsmMode2) { | ||
esmMode = Boolean(isEsmMode2); | ||
}; | ||
const isEsmMode$1 = function() { | ||
return esmMode; | ||
}; | ||
function useIO$1() { | ||
return { isEsmMode: isEsmMode$1, load: load$1, setEsmMode: setEsmMode$1 }; | ||
} | ||
const state$7 = useState(); | ||
const { load } = useIO$1(); | ||
const fileExists = async (path) => { | ||
@@ -754,5 +774,3 @@ let exists; | ||
} | ||
const orderedRoutes = Object.entries(routes).filter(([path]) => path !== "DROSSE").sort((a, b) => { | ||
return a[0].indexOf(":") === 0 ? 1 : a[0] > b[0] ? -1 : 0; | ||
}); | ||
const orderedRoutes = Object.entries(routes).filter(([path]) => path !== "DROSSE"); | ||
for (const orderedRoute of orderedRoutes) { | ||
@@ -1004,3 +1022,4 @@ const [path, content] = orderedRoute; | ||
try { | ||
const { params, query } = req; | ||
const params = getRouterParams(req); | ||
const query = getQuery(req); | ||
const { extensions } = def; | ||
@@ -1137,2 +1156,3 @@ const [result, extension] = await loadStatic({ routePath: root, params, verb, query, extensions }); | ||
const { checkRoutesFile, loadUuid, getUserConfig, getRoutesDef } = useIO(); | ||
const { isEsmMode } = useIO$1(); | ||
const middlewares = useMiddlewares(); | ||
@@ -1205,3 +1225,10 @@ const state = useState(); | ||
emit$1("restart"); | ||
return { restarted: true }; | ||
if (isEsmMode()) { | ||
return { | ||
restarted: false, | ||
comment: RESTART_DISABLED_IN_ESM_MODE | ||
}; | ||
} else { | ||
return { restarted: true }; | ||
} | ||
} else { | ||
@@ -1254,4 +1281,9 @@ const result = await executeCommand({ | ||
const restart = async () => { | ||
await stop(); | ||
await start(); | ||
if (isEsmMode()) { | ||
console.warn(RESTART_DISABLED_IN_ESM_MODE); | ||
console.info("Please use ctrl+c to restart drosse."); | ||
} else { | ||
await stop(); | ||
await start(); | ||
} | ||
}; | ||
@@ -1329,2 +1361,3 @@ const describe = () => { | ||
let discover, description, noRepl; | ||
const { setEsmMode } = useIO$1(); | ||
const emit = async (event, data) => { | ||
@@ -1383,2 +1416,7 @@ switch (event) { | ||
type: "boolean" | ||
}, | ||
esm: { | ||
default: false, | ||
describe: "Enable esm mode", | ||
type: "boolean" | ||
} | ||
@@ -1388,2 +1426,3 @@ }, | ||
noRepl = argv.norepl; | ||
setEsmMode(argv.esm); | ||
await init(argv.rootPath, emit, version$1); | ||
@@ -1390,0 +1429,0 @@ return start(); |
{ | ||
"name": "@jota-one/drosse", | ||
"version": "3.0.2", | ||
"version": "3.1.0--canary.53.3716062239.0", | ||
"description": "A stateful and programmable mock server", | ||
@@ -22,2 +22,6 @@ "author": "Juniors at Work", | ||
}, | ||
"pkg": { | ||
"scripts": "dist/index.cjs", | ||
"outputPath": "bundle" | ||
}, | ||
"scripts": { | ||
@@ -27,2 +31,3 @@ "describe": "node ./dist/index.cjs describe", | ||
"build:stub": "unbuild --stub", | ||
"bundle": "pkg .", | ||
"serve": "node ./dist/index.cjs serve", | ||
@@ -70,2 +75,3 @@ "static": "node ./dist/index.cjs static", | ||
"express-session": "^1.17.3", | ||
"pkg": "^5.8.0", | ||
"sockjs": "^0.3.24", | ||
@@ -76,3 +82,6 @@ "supertest": "^6.2.4", | ||
"ws": "^8.8.1" | ||
}, | ||
"engines": { | ||
"node": ">=14.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
133547
4238
9
1
7