Skip to content

Commit 4322d52

Browse files
committed
chore(preprocess-external-link): re-expose public typedef
1 parent 4ac365c commit 4322d52

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

.changeset/four-hotels-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@svelte-put/preprocess-external-link': patch
3+
---
4+
5+
re-expose public typedef (following https://github.com/Rich-Harris/dts-buddy/pull/82)

packages/preprocess-external-link/src/index.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ import MagicString from 'magic-string';
22
import { parse } from 'svelte-parse-markup';
33
import { walk } from 'zimmerframe';
44

5-
/**
6-
* @typedef ExternalLinkConfig
7-
* @property {string[]} hosts - a list of hosts that, if href does NOT match, will be marked as external. `localhost` is already included
8-
* @property {(filename?: string) => boolean} [files] - a function that returns true if the file should be processed. By defaults it will matches
9-
* @property {string} [markerAttribute] a boolean attribute that explicitly marks the anchor tag as external to be processed. Defaults to `'data-external'`
10-
* @property {Record<string, string>} [attributes] - attributes to add to the anchor tag. Defaults to `{ target: '_blank', rel: 'noopener noreferrer' }`
11-
*/
12-
13-
const DEFAULT_EXTERNAL_LINK_CONFIG = /** @satisfies {Required<ExternalLinkConfig>} */ ({
5+
const DEFAULT_EXTERNAL_LINK_CONFIG = /** @satisfies {Required<import('./types.public').ExternalLinkConfig>} */ ({
146
hosts: ['localhost'],
157
markerAttribute: 'data-external',
168
attributes: { target: '_blank', rel: 'noopener noreferrer' },
@@ -19,11 +11,11 @@ const DEFAULT_EXTERNAL_LINK_CONFIG = /** @satisfies {Required<ExternalLinkConfig
1911

2012
/**
2113
* search for external links and add appropriate attributes
22-
* @param {ExternalLinkConfig | NonNullable<ExternalLinkConfig['hosts']>} config
14+
* @param {import('./types.public').ExternalLinkConfig | NonNullable<import('./types.public').ExternalLinkConfig['hosts']>} config
2315
* @returns {import('svelte/compiler').PreprocessorGroup}
2416
*/
2517
export function externalLink(config) {
26-
/** @type {Required<ExternalLinkConfig>} */
18+
/** @type {Required<import('./types.public').ExternalLinkConfig>} */
2719
let rConfig;
2820
if (Array.isArray(config)) {
2921
rConfig = {
@@ -106,6 +98,7 @@ export function externalLink(config) {
10698
}
10799

108100
export default externalLink;
101+
export * from './types.public.js';
109102

110103
// TODO: add unit tests
111104
/**

packages/preprocess-external-link/src/types.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export type ExternalLinkConfig = {
2+
/** a list of hosts that, if href does NOT match, will be marked as external. `localhost` is already included */
3+
hosts: string[];
4+
/** a function that returns true if the file should be processed. By defaults it will matches */
5+
files?: (filename?: string) => boolean;
6+
/** a boolean attribute that explicitly marks the anchor tag as external to be processed. Defaults to `'data-external'` */
7+
markerAttribute?: string;
8+
/** attributes to add to the anchor tag. Defaults to `{ target: '_blank', rel: 'noopener noreferrer' }` */
9+
attributes?: Record<string, string>;
10+
};
11+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/** to provide typing only, see types.public.d.ts */
2+
export {};
3+

0 commit comments

Comments
 (0)