mockaton 13.9.2 → 13.9.3
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/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/server/Mockaton.js
CHANGED
|
@@ -25,9 +25,12 @@ export function Mockaton(options) {
|
|
|
25
25
|
setup(options)
|
|
26
26
|
cookie.init(config.cookies)
|
|
27
27
|
mockBrokerCollection.init()
|
|
28
|
-
register('./importResolver.js', import.meta.url)
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
register('./resolverResolveExtensionless.js', import.meta.url)
|
|
30
|
+
if (config.bypassImportCache)
|
|
31
|
+
register('./resolverBypassImportCache.js', import.meta.url)
|
|
32
|
+
|
|
33
|
+
if (config.watcherEnabled)
|
|
31
34
|
watchMocksDir()
|
|
32
35
|
|
|
33
36
|
if (config.hotReload)
|
package/src/server/config.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { resolve as _resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
const mockatonSrcRoot = `file://${_resolve(import.meta.dirname, '..')}`
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// We register this hook at runtime so it doesn’t interfere with non-dynamic imports.
|
|
7
|
+
// Cache bust by appending timestamp query param
|
|
8
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
9
|
+
const result = await nextResolve(specifier, context)
|
|
10
|
+
if (result.url?.startsWith('file://') && !result.url.startsWith(mockatonSrcRoot)) {
|
|
11
|
+
const url = new URL(result.url)
|
|
12
|
+
url.searchParams.set('t', performance.now())
|
|
13
|
+
return {
|
|
14
|
+
...result,
|
|
15
|
+
url: url.href,
|
|
16
|
+
shortCircuit: true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result
|
|
20
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
|
-
import {
|
|
2
|
+
import { join, dirname } from 'node:path'
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
4
4
|
|
|
5
|
-
const mockatonSrcRoot = `file://${_resolve(import.meta.dirname, '..')}`
|
|
6
|
-
|
|
7
|
-
// We register this hook at runtime so it doesn’t interfere with non-dynamic imports.
|
|
8
5
|
export async function resolve(specifier, context, nextResolve) {
|
|
9
|
-
let result
|
|
10
6
|
try {
|
|
11
|
-
|
|
7
|
+
return await nextResolve(specifier, context)
|
|
12
8
|
}
|
|
13
9
|
catch (error) {
|
|
14
10
|
// Attempt to resolve imports as .ts and .js
|
|
@@ -20,16 +16,4 @@ export async function resolve(specifier, context, nextResolve) {
|
|
|
20
16
|
}
|
|
21
17
|
throw error
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
// Cache bust by appending timestamp query param
|
|
25
|
-
if (result.url?.startsWith('file://') && !result.url.startsWith(mockatonSrcRoot)) {
|
|
26
|
-
const url = new URL(result.url)
|
|
27
|
-
url.searchParams.set('t', performance.now())
|
|
28
|
-
return {
|
|
29
|
-
...result,
|
|
30
|
-
url: url.href,
|
|
31
|
-
shortCircuit: true
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return result
|
|
35
19
|
}
|