-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to TypeScript #78
base: main
Are you sure you want to change the base?
Changes from all commits
97a71de
458c5aa
418bf34
ddf05dc
681519b
86d51f8
4581855
4a2fb49
95a9491
6df53c4
bcea29a
bdb8f1a
3ba0bec
1c56336
ee1835d
8789e23
c050656
007a526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ oldtest.mjs | |
!.yarn/releases | ||
!.yarn/plugins | ||
.pnp.* | ||
dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,11 @@ | |
"relative links" | ||
], | ||
"homepage": "https://github.com/vernak2539/astro-rehype-relative-markdown-links", | ||
"main": "./src/index.mjs", | ||
"type": "module", | ||
"types": "./src/index.d.ts", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"src/index.mjs", | ||
"src/utils.mjs", | ||
"src/options.mjs", | ||
"src/**/*.d.ts" | ||
"dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
|
@@ -30,10 +27,10 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"pre-release": "yarn run changelog && yarn run prettier && yarn run generate-docs", | ||
"build": "tsup", | ||
"generate-docs": "typedoc", | ||
"prettier": "prettier ./src/** -w", | ||
"test": "ARRML_MATTER_CACHE_DISABLE=true node --loader=esmock --test", | ||
"test": "ARRML_MATTER_CACHE_DISABLE=true node --import tsx --loader=esmock --test src/**/*.test.ts", | ||
"type-check": "tsc --noEmit --emitDeclarationOnly false", | ||
"prepare": "husky" | ||
}, | ||
|
@@ -59,9 +56,12 @@ | |
"prettier": "^4.0.0-alpha.8", | ||
"rehype": "^13.0.2", | ||
"remark-toc": "^9.0.0", | ||
"typedoc": "^0.27.4", | ||
"typedoc-plugin-markdown": "^4.3.2", | ||
"typedoc-plugin-remark": "^1.2.0", | ||
"tsup": "^8.3.5", | ||
"tsx": "^4.19.2", | ||
"typedoc": "^0.27.5", | ||
"typedoc-plugin-markdown": "^4.3.3", | ||
"typedoc-plugin-remark": "^1.2.1", | ||
"typedoc-plugin-zod": "^1.3.1", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import astroRehypeRelativeMarkdownLinks from "./plugin"; | ||
|
||
export type { Options, CollectionConfig } from "./options"; | ||
export default astroRehypeRelativeMarkdownLinks; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,8 +112,21 @@ export const OptionsSchema = z.object({ | |
.default("ignore"), | ||
}); | ||
|
||
/** @type {import('./options.d.ts').ValidateOptions} */ | ||
export const validateOptions = (options) => { | ||
/** Collection specific options */ | ||
export interface CollectionConfig extends z.input<CollectionConfigSchemaType> {} | ||
type CollectionConfigSchemaType = typeof CollectionConfigSchema; | ||
|
||
/** General options */ | ||
export type Options = z.infer<typeof OptionsSchema>; | ||
interface EffectiveOptions extends Options {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couple of things here:
type OptionsSchemaType = typeof OptionsSchema;
type CollectionConfigSchemaType = typeof CollectionConfigSchema;
/**
* Collection specific options
* @interface
*/
export type CollectionConfig = z.input<CollectionConfigSchemaType>;
/**
* General options
* @interface
*/
export type Options = z.input<OptionsSchemaType>;
interface EffectiveOptions extends z.infer<OptionsSchemaType> {}; EDIT: Per my recent comment, the |
||
export interface EffectiveCollectionOptions | ||
extends Omit<EffectiveOptions, "collections"> { | ||
collectionName: string; | ||
} | ||
|
||
export const validateOptions = ( | ||
options: Options | null | undefined | ||
): EffectiveOptions => { | ||
const result = OptionsSchema.safeParse(options || {}); | ||
if (!result.success) { | ||
throw result.error; | ||
|
@@ -122,8 +135,10 @@ export const validateOptions = (options) => { | |
return result.data; | ||
}; | ||
|
||
/** @type {import('./options.d.ts').MergeCollectionOptions} */ | ||
export const mergeCollectionOptions = (collectionName, options) => { | ||
export const mergeCollectionOptions = ( | ||
collectionName: string, | ||
options: EffectiveOptions | ||
): EffectiveCollectionOptions => { | ||
const config = options.collections[collectionName] || {}; | ||
const { base = options.collectionBase, name = collectionName } = config; | ||
return { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,18 @@ import path, { dirname } from "path"; | |
import { rehype } from "rehype"; | ||
import { visit } from "unist-util-visit"; | ||
import esmock from "esmock"; | ||
import { validateOptions as validateOptionsOriginal } from "./options.mjs"; | ||
import { validateOptions as validateOptionsOriginal } from "./options"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
import astroRehypeRelativeMarkdownLinks from "./index.mjs"; | ||
import astroRehypeRelativeMarkdownLinks from "./plugin"; | ||
|
||
/* | ||
NOTE ON ESMOCK USAGE | ||
|
||
node:test does not provide a stock way of mocking sub-modules. There is work being done on this (see | ||
links below) but for now some type of module loader is required. Esmock (https://github.com/iambumblehead/esmock) | ||
links below) but for now some type of module loader is required. Esmock (https://github.com/iambumblehead/esmock) | ||
seems to address what is needed for our use cases for now although there doesn't seem to be a simple way for a simple spy | ||
as you need to swap in the original manually. If/When node:test supports this natively, esmock can be removed. | ||
|
||
|
@@ -418,10 +418,10 @@ describe("astroRehypeRelativeMarkdownLinks", () => { | |
}); | ||
|
||
describe("config option validation", () => { | ||
const runValidationTest = async (context, options) => { | ||
const runValidationTest = async (context, options?) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment actually refers to line 34 above (https://github.com/vernak2539/astro-rehype-relative-markdown-links/pull/78/files#diff-15ddc1bcd6ddf3b9483b554a2e56cad27ca25a7924fcd2e1db0bf2d7a849ccadR34) - GH doesn't allow commenting on unchanged lines :( The old jsdoc type can be removed. It was wrong to begin with so line 35 should actually be: function testSetupRehype(options: { currentFilePath?: string } = {}) { |
||
const validateOptionsMock = context.mock.fn(validateOptionsOriginal); | ||
const astroRehypeRelativeMarkdownLinksMock = await esmock("./index.mjs", { | ||
"./options.mjs": { | ||
const astroRehypeRelativeMarkdownLinksMock = await esmock("./plugin.ts", { | ||
"./options.ts": { | ||
validateOptions: validateOptionsMock, | ||
}, | ||
}); | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to the following to ensure docs generate correctly when using types