vocs 2.0.2 → 2.0.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.
@@ -3,12 +3,18 @@ import type { MiddlewareHandler } from 'hono';
3
3
  * Removes trailing slashes from URLs.
4
4
  *
5
5
  * Redirects `/about/` → `/about` with a 308 Permanent Redirect.
6
- * Skips the root path (`/`) and paths with file extensions.
6
+ * Skips the root path (`/`), configured base path root, and paths with file
7
+ * extensions.
7
8
  *
8
9
  * Uses relative Location values so redirects work correctly behind
9
10
  * TLS-terminating reverse proxies, where the internal request URL
10
11
  * may use `http://`.
11
12
  */
12
- export declare const trailingSlash: () => MiddlewareHandler;
13
+ export declare const trailingSlash: (options?: trailingSlash.Options) => MiddlewareHandler;
13
14
  export default trailingSlash;
15
+ export declare namespace trailingSlash {
16
+ type Options = {
17
+ basePath?: string | undefined;
18
+ };
19
+ }
14
20
  //# sourceMappingURL=trailing-slash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trailing-slash.d.ts","sourceRoot":"","sources":["../../../../src/waku/internal/middleware/trailing-slash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAG7C;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAAO,iBAgBhC,CAAA;AAED,eAAe,aAAa,CAAA"}
1
+ {"version":3,"file":"trailing-slash.d.ts","sourceRoot":"","sources":["../../../../src/waku/internal/middleware/trailing-slash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAM7C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,UAAS,aAAa,CAAC,OAAY,KAAG,iBAuBnE,CAAA;AAED,eAAe,aAAa,CAAA;AAE5B,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,KAAK,OAAO,GAAG;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC9B,CAAA;CACF"}
@@ -1,19 +1,26 @@
1
+ import * as Config from '../../../internal/config.js';
1
2
  import { appendSearch } from '../../../internal/redirects.js';
3
+ const normalizeBasePath = (basePath) => (basePath.endsWith('/') ? basePath : `${basePath}/`);
2
4
  /**
3
5
  * Removes trailing slashes from URLs.
4
6
  *
5
7
  * Redirects `/about/` → `/about` with a 308 Permanent Redirect.
6
- * Skips the root path (`/`) and paths with file extensions.
8
+ * Skips the root path (`/`), configured base path root, and paths with file
9
+ * extensions.
7
10
  *
8
11
  * Uses relative Location values so redirects work correctly behind
9
12
  * TLS-terminating reverse proxies, where the internal request URL
10
13
  * may use `http://`.
11
14
  */
12
- export const trailingSlash = () => {
15
+ export const trailingSlash = (options = {}) => {
16
+ const basePathPromise = options.basePath !== undefined
17
+ ? Promise.resolve(normalizeBasePath(options.basePath))
18
+ : Config.resolve({ server: true }).then((config) => normalizeBasePath(config.basePath));
13
19
  return async (context, next) => {
14
20
  const url = new URL(context.req.url);
15
- // Skip root path and paths with file extensions
16
- if (url.pathname === '/' || /\.\w+$/.test(url.pathname))
21
+ const basePath = await basePathPromise;
22
+ // Skip root path, base path root, and paths with file extensions
23
+ if (url.pathname === '/' || url.pathname === basePath || /\.\w+$/.test(url.pathname))
17
24
  return next();
18
25
  // Redirect trailing slash to non-trailing slash
19
26
  if (url.pathname.endsWith('/')) {
@@ -1 +1 @@
1
- {"version":3,"file":"trailing-slash.js","sourceRoot":"","sources":["../../../../src/waku/internal/middleware/trailing-slash.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAE7D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAsB,EAAE;IACnD,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEpC,gDAAgD;Q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AAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;IAE3F,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACpC,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAA;QAEtC,iEAAiE;QACjE,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;YAClF,OAAO,IAAI,EAAE,CAAA;QAEf,gDAAgD;QAChD,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;YACvE,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;YAChD,OAAM;QACR,CAAC;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,aAAa,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import * as middleware from './internal/middleware/index.js';
2
2
  export declare function middlewareModules(overrides?: Record<string, () => Promise<unknown>>): {
3
3
  [x: string]: (() => Promise<unknown>) | (() => Promise<{
4
- default: typeof middleware.mdRouter | (() => import("hono").MiddlewareHandler) | (() => import("hono").MiddlewareHandler);
4
+ default: typeof middleware.mdRouter | (() => import("hono").MiddlewareHandler) | ((options?: middleware.trailingSlash.Options) => import("hono").MiddlewareHandler);
5
5
  }>);
6
6
  };
7
7
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/waku/vite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAMvD;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,IAAI,CAAC,OAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CA8C9E;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,KAAK,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAA;CAChE"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/waku/vite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAMvD;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,IAAI,CAAC,OAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CA+C9E;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,KAAK,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAA;CAChE"}
package/dist/waku/vite.js CHANGED
@@ -13,8 +13,9 @@ export async function vocs(options = {}) {
13
13
  const { privateDir = 'private', rscBase = 'RSC', unstable_adapter = getDefaultAdapter(), } = options;
14
14
  const config = await Config.resolve();
15
15
  const { basePath, srcDir, outDir } = config;
16
+ const wakuBasePath = basePath.endsWith('/') ? basePath : `${basePath}/`;
16
17
  const wakuConfig = {
17
- basePath,
18
+ basePath: wakuBasePath,
18
19
  srcDir,
19
20
  distDir: outDir,
20
21
  privateDir,
@@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AAY;QACtB,MAAM;QACN,OAAO,EAAE,MAAM;QACf,UAAU;QACV,OAAO;QACP,gBAAgB;QAChB,IAAI,EAAE,EAAE;KACT,CAAA;IAED,OAAO;QACL,SAAS,EAAE;QACX,OAAO,CAAC,WAAW,EAAE;QACrB,SAAS,CAAC;YACR,aAAa,EAAE,KAAK;YACpB,iBAAiB,EAAE,IAAI;YACvB,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW;SACzC,CAAC;QACF,OAAO,CAAC,MAAM,EAAE;QAChB,OAAO,CAAC,OAAO,EAAE;QACjB,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QAChC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC;QACvC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC;QACjC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QAChC,OAAO,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,SAAS,EAAE;QACnB,OAAO,CAAC,mBAAmB,EAAE;QAC7B,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC;QACjC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;QAC/B,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC;QAC9B,OAAO,CAAC,SAAS,EAAE;QACnB,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC;QACnC,OAAO,CAAC,OAAO,EAAE;QACjB,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC;KAC3B,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vocs",
3
3
  "type": "module",
4
- "version": "2.0.2",
4
+ "version": "2.0.3",
5
5
  "main": "./dist/index.js",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -6,9 +6,9 @@ import { trailingSlash } from './trailing-slash.js'
6
6
  * Creates a Hono app with trailing-slash middleware and a catch-all handler,
7
7
  * then sends a request to the given path.
8
8
  */
9
- function request(path: string) {
9
+ function request(path: string, options?: trailingSlash.Options) {
10
10
  const app = new Hono()
11
- app.use('*', trailingSlash())
11
+ app.use('*', trailingSlash(options))
12
12
  app.get('*', (c) => c.text('ok'))
13
13
  return app.request(path)
14
14
  }
@@ -31,6 +31,13 @@ describe('trailingSlash', () => {
31
31
  expect(res.status).toBe(200)
32
32
  })
33
33
 
34
+ it('skips configured base path root', async () => {
35
+ const res = await request('http://localhost/open-source/', {
36
+ basePath: '/open-source',
37
+ })
38
+ expect(res.status).toBe(200)
39
+ })
40
+
34
41
  it('skips paths with file extensions', async () => {
35
42
  const res = await request('http://localhost/styles.css')
36
43
  expect(res.status).toBe(200)
@@ -1,22 +1,33 @@
1
1
  import type { MiddlewareHandler } from 'hono'
2
+ import * as Config from '../../../internal/config.js'
2
3
  import { appendSearch } from '../../../internal/redirects.js'
3
4
 
5
+ const normalizeBasePath = (basePath: string) => (basePath.endsWith('/') ? basePath : `${basePath}/`)
6
+
4
7
  /**
5
8
  * Removes trailing slashes from URLs.
6
9
  *
7
10
  * Redirects `/about/` → `/about` with a 308 Permanent Redirect.
8
- * Skips the root path (`/`) and paths with file extensions.
11
+ * Skips the root path (`/`), configured base path root, and paths with file
12
+ * extensions.
9
13
  *
10
14
  * Uses relative Location values so redirects work correctly behind
11
15
  * TLS-terminating reverse proxies, where the internal request URL
12
16
  * may use `http://`.
13
17
  */
14
- export const trailingSlash = (): MiddlewareHandler => {
18
+ export const trailingSlash = (options: trailingSlash.Options = {}): MiddlewareHandler => {
19
+ const basePathPromise =
20
+ options.basePath !== undefined
21
+ ? Promise.resolve(normalizeBasePath(options.basePath))
22
+ : Config.resolve({ server: true }).then((config) => normalizeBasePath(config.basePath))
23
+
15
24
  return async (context, next) => {
16
25
  const url = new URL(context.req.url)
26
+ const basePath = await basePathPromise
17
27
 
18
- // Skip root path and paths with file extensions
19
- if (url.pathname === '/' || /\.\w+$/.test(url.pathname)) return next()
28
+ // Skip root path, base path root, and paths with file extensions
29
+ if (url.pathname === '/' || url.pathname === basePath || /\.\w+$/.test(url.pathname))
30
+ return next()
20
31
 
21
32
  // Redirect trailing slash to non-trailing slash
22
33
  if (url.pathname.endsWith('/')) {
@@ -30,3 +41,9 @@ export const trailingSlash = (): MiddlewareHandler => {
30
41
  }
31
42
 
32
43
  export default trailingSlash
44
+
45
+ export declare namespace trailingSlash {
46
+ type Options = {
47
+ basePath?: string | undefined
48
+ }
49
+ }
package/src/waku/vite.ts CHANGED
@@ -21,9 +21,10 @@ export async function vocs(options: vocs.Options = {}): Promise<PluginOption[]>
21
21
 
22
22
  const config = await Config.resolve()
23
23
  const { basePath, srcDir, outDir } = config
24
+ const wakuBasePath = basePath.endsWith('/') ? basePath : `${basePath}/`
24
25
 
25
26
  const wakuConfig = {
26
- basePath,
27
+ basePath: wakuBasePath,
27
28
  srcDir,
28
29
  distDir: outDir,
29
30
  privateDir,