mockaton 13.9.1 → 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
@@ -46,6 +46,7 @@ export declare interface Config {
46
46
  onReady?: (address: string) => void
47
47
 
48
48
  hotReload?: boolean // For UI dev purposes only
49
+ bypassImportCache?: boolean
49
50
  }
50
51
 
51
52
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "13.9.1",
5
+ "version": "13.9.3",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./index.js",
@@ -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
- if (config.watcherEnabled)
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)
@@ -54,7 +54,8 @@ const schema = {
54
54
 
55
55
  onReady: [await openInBrowser, is(Function)],
56
56
 
57
- hotReload: [false, is(Boolean)]
57
+ hotReload: [false, is(Boolean)],
58
+ bypassImportCache: [true, is(Boolean)]
58
59
  }
59
60
 
60
61
 
@@ -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 { resolve as _resolve, join, dirname } from 'node:path'
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
- result = await nextResolve(specifier, context)
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
  }
@@ -5,7 +5,10 @@
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "exports": {
8
- ".": "./index.ts"
8
+ ".": {
9
+ "import": "./index.js",
10
+ "types": "./index.d.ts"
11
+ }
9
12
  },
10
13
  "peerDependencies": {
11
14
  "vite": ">=8.0.0",