@sanity/tsdown-config 0.22.0 → 0.24.0
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/README.md +114 -17
- package/dist/cssLoweringTargets-Dn_sJGip.mjs +34 -0
- package/dist/cssLoweringTargets-Dn_sJGip.mjs.map +1 -0
- package/dist/cssNodeCompatPlugin-B_ndKoRv.mjs +115 -0
- package/dist/cssNodeCompatPlugin-B_ndKoRv.mjs.map +1 -0
- package/dist/index.d.mts +100 -19
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +119 -17
- package/dist/index.mjs.map +1 -1
- package/dist/tsdoc.d.mts +47 -0
- package/dist/tsdoc.d.mts.map +1 -0
- package/dist/tsdoc.mjs +196 -0
- package/dist/tsdoc.mjs.map +1 -0
- package/dist/types-CrQ2my_P.d.mts +38 -0
- package/dist/types-CrQ2my_P.d.mts.map +1 -0
- package/package.json +15 -6
package/dist/tsdoc.mjs
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { Extractor, ExtractorConfig, ExtractorLogLevel } from "@microsoft/api-extractor";
|
|
5
|
+
import ts from "@typescript/typescript6";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { TSDocConfigFile } from "@microsoft/tsdoc-config";
|
|
8
|
+
import { parse } from "jsonc-parser";
|
|
9
|
+
/** @internal */
|
|
10
|
+
function createApiExtractorConfig(options) {
|
|
11
|
+
let { bundledPackages, distPath, exportPath, filePath, messages, projectFolder, mainEntryPointFilePath, tsconfig, tsconfigPath } = options;
|
|
12
|
+
return {
|
|
13
|
+
apiReport: {
|
|
14
|
+
enabled: !1,
|
|
15
|
+
reportFileName: "<unscopedPackageName>.api.md"
|
|
16
|
+
},
|
|
17
|
+
bundledPackages,
|
|
18
|
+
compiler: tsconfig.options.paths ? { overrideTsconfig: {
|
|
19
|
+
extends: tsconfigPath,
|
|
20
|
+
compilerOptions: { paths: {} }
|
|
21
|
+
} } : { tsconfigFilePath: tsconfigPath },
|
|
22
|
+
docModel: {
|
|
23
|
+
enabled: !1,
|
|
24
|
+
apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`)
|
|
25
|
+
},
|
|
26
|
+
dtsRollup: {
|
|
27
|
+
enabled: !1,
|
|
28
|
+
untrimmedFilePath: path.resolve(distPath, filePath)
|
|
29
|
+
},
|
|
30
|
+
tsdocMetadata: { enabled: !1 },
|
|
31
|
+
messages,
|
|
32
|
+
mainEntryPointFilePath,
|
|
33
|
+
projectFolder
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
/** @internal */
|
|
38
|
+
async function createTSDocConfig(opts) {
|
|
39
|
+
let { customTags } = opts;
|
|
40
|
+
if (customTags.length === 0) return;
|
|
41
|
+
let tsDocBaseBuf = await readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json")), tsDocBaseConfig = parse(tsDocBaseBuf.toString()), tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map((t) => ({
|
|
42
|
+
tagName: `@${t.name}`,
|
|
43
|
+
syntaxKind: t.syntaxKind,
|
|
44
|
+
allowMultiple: t.allowMultiple
|
|
45
|
+
}))), supportForTags = { ...tsDocBaseConfig.supportForTags };
|
|
46
|
+
for (let customTag of customTags) supportForTags[`@${customTag.name}`] = !0;
|
|
47
|
+
return TSDocConfigFile.loadFromObject({
|
|
48
|
+
...tsDocBaseConfig,
|
|
49
|
+
noStandardTags: !1,
|
|
50
|
+
tagDefinitions,
|
|
51
|
+
supportForTags
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const LOG_LEVELS = {
|
|
55
|
+
error: ExtractorLogLevel.Error,
|
|
56
|
+
info: ExtractorLogLevel.Info,
|
|
57
|
+
off: ExtractorLogLevel.None,
|
|
58
|
+
warn: ExtractorLogLevel.Warning
|
|
59
|
+
};
|
|
60
|
+
/** @internal */
|
|
61
|
+
function getExtractMessagesConfig(options) {
|
|
62
|
+
let { rules, disabled = !1 } = options;
|
|
63
|
+
function ruleToLogLevel(key, defaultLevel) {
|
|
64
|
+
let r = rules?.[key];
|
|
65
|
+
return r ? LOG_LEVELS[r] : defaultLevel || ExtractorLogLevel.Warning;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
compilerMessageReporting: { default: { logLevel: disabled ? ExtractorLogLevel.None : ExtractorLogLevel.Warning } },
|
|
69
|
+
extractorMessageReporting: disabled ? { default: {
|
|
70
|
+
logLevel: ExtractorLogLevel.None,
|
|
71
|
+
addToApiReportFile: !1
|
|
72
|
+
} } : {
|
|
73
|
+
default: {
|
|
74
|
+
logLevel: ExtractorLogLevel.Warning,
|
|
75
|
+
addToApiReportFile: !1
|
|
76
|
+
},
|
|
77
|
+
"ae-forgotten-export": {
|
|
78
|
+
/**
|
|
79
|
+
* This is hardcoded to `none` as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
|
|
80
|
+
* It's hardcoded to `none` since supported by API Extractor when using `module: 'Preserve'` doesn't support it well since `@microsoft/api-extractor` v7.49.0, which upgraded from TS 5.4 to 5.7 internally
|
|
81
|
+
*/
|
|
82
|
+
logLevel: ExtractorLogLevel.None,
|
|
83
|
+
addToApiReportFile: !1
|
|
84
|
+
},
|
|
85
|
+
"ae-incompatible-release-tags": {
|
|
86
|
+
logLevel: ruleToLogLevel("ae-incompatible-release-tags", ExtractorLogLevel.Error),
|
|
87
|
+
addToApiReportFile: !1
|
|
88
|
+
},
|
|
89
|
+
"ae-internal-missing-underscore": {
|
|
90
|
+
logLevel: ruleToLogLevel("ae-internal-missing-underscore"),
|
|
91
|
+
addToApiReportFile: !1
|
|
92
|
+
},
|
|
93
|
+
"ae-missing-release-tag": {
|
|
94
|
+
logLevel: ruleToLogLevel("ae-missing-release-tag", ExtractorLogLevel.Error),
|
|
95
|
+
addToApiReportFile: !1
|
|
96
|
+
},
|
|
97
|
+
"ae-wrong-input-file-type": {
|
|
98
|
+
logLevel: ExtractorLogLevel.None,
|
|
99
|
+
addToApiReportFile: !1
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
tsdocMessageReporting: disabled ? { default: {
|
|
103
|
+
logLevel: ExtractorLogLevel.None,
|
|
104
|
+
addToApiReportFile: !1
|
|
105
|
+
} } : {
|
|
106
|
+
default: {
|
|
107
|
+
logLevel: ExtractorLogLevel.Warning,
|
|
108
|
+
addToApiReportFile: !1
|
|
109
|
+
},
|
|
110
|
+
"tsdoc-link-tag-unescaped-text": {
|
|
111
|
+
logLevel: ruleToLogLevel("tsdoc-link-tag-unescaped-text", ExtractorLogLevel.Warning),
|
|
112
|
+
addToApiReportFile: !1
|
|
113
|
+
},
|
|
114
|
+
"tsdoc-undefined-tag": {
|
|
115
|
+
logLevel: ruleToLogLevel("tsdoc-undefined-tag", ExtractorLogLevel.Error),
|
|
116
|
+
addToApiReportFile: !1
|
|
117
|
+
},
|
|
118
|
+
"tsdoc-unsupported-tag": {
|
|
119
|
+
logLevel: ruleToLogLevel("tsdoc-unsupported-tag", ExtractorLogLevel.None),
|
|
120
|
+
addToApiReportFile: !1
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Run `@microsoft/api-extractor` against the given entry declaration files to check that TSDoc
|
|
127
|
+
* tags are valid and release tags are correct. Import from `@sanity/tsdown-config/tsdoc`.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
async function checkTsdoc(options) {
|
|
131
|
+
let { cwd, entryDtsFiles, bundledPackages, customTags = [], rules = {}, logger, outDir: outDirOption } = options, tsconfigPath = path.resolve(cwd, options.tsconfig || "tsconfig.json"), tsconfig = loadTSConfig({
|
|
132
|
+
cwd,
|
|
133
|
+
tsconfigPath
|
|
134
|
+
}), outDir = tsconfig?.options.outDir ?? (outDirOption ? path.resolve(cwd, outDirOption) : void 0) ?? commonParentDir(entryDtsFiles) ?? path.resolve(cwd, "dist"), tsdocConfigFile = await createTSDocConfig({ customTags }), messagesConfig = getExtractMessagesConfig({ rules }), allMessages = [];
|
|
135
|
+
for (let exportPath of entryDtsFiles) {
|
|
136
|
+
if (!existsSync(exportPath)) continue;
|
|
137
|
+
let relativeDtsPath = path.relative(outDir, exportPath), extractorConfig = ExtractorConfig.prepare({
|
|
138
|
+
configObject: createApiExtractorConfig({
|
|
139
|
+
bundledPackages,
|
|
140
|
+
distPath: outDir,
|
|
141
|
+
exportPath,
|
|
142
|
+
filePath: relativeDtsPath,
|
|
143
|
+
messages: messagesConfig,
|
|
144
|
+
projectFolder: cwd,
|
|
145
|
+
mainEntryPointFilePath: exportPath,
|
|
146
|
+
tsconfig: tsconfig ?? { options: {} },
|
|
147
|
+
tsconfigPath
|
|
148
|
+
}),
|
|
149
|
+
configObjectFullPath: void 0,
|
|
150
|
+
tsdocConfigFile,
|
|
151
|
+
packageJsonFullPath: path.resolve(cwd, "package.json")
|
|
152
|
+
});
|
|
153
|
+
Extractor.invoke(extractorConfig, {
|
|
154
|
+
localBuild: !0,
|
|
155
|
+
showVerboseMessages: !0,
|
|
156
|
+
messageCallback(message) {
|
|
157
|
+
allMessages.push(message), message.handled = !0;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
let warnings = allMessages.filter((msg) => msg.logLevel === ExtractorLogLevel.Warning), errors = allMessages.filter((msg) => msg.logLevel === ExtractorLogLevel.Error);
|
|
162
|
+
if (logger && reportMessages(cwd, logger, warnings, errors), errors.length) throw Error(`TSDoc/release-tag check failed with ${errors.length} error${errors.length === 1 ? "" : "s"}`);
|
|
163
|
+
return {
|
|
164
|
+
messages: allMessages,
|
|
165
|
+
errorCount: errors.length,
|
|
166
|
+
warningCount: warnings.length
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function loadTSConfig(options) {
|
|
170
|
+
let { cwd, tsconfigPath } = options, configPath;
|
|
171
|
+
if (configPath = path.isAbsolute(tsconfigPath) ? tsconfigPath : ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath), !configPath || !existsSync(configPath)) return;
|
|
172
|
+
let configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
173
|
+
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
174
|
+
}
|
|
175
|
+
function commonParentDir(files) {
|
|
176
|
+
if (files.length === 0) return;
|
|
177
|
+
let dir = path.dirname(files[0]);
|
|
178
|
+
for (let file of files.slice(1)) for (; dir !== path.dirname(dir) && !file.startsWith(dir + path.sep) && file !== dir;) dir = path.dirname(dir);
|
|
179
|
+
return dir;
|
|
180
|
+
}
|
|
181
|
+
function reportMessages(cwd, logger, warnings, errors) {
|
|
182
|
+
warnings.length && logger.log();
|
|
183
|
+
for (let msg of warnings) {
|
|
184
|
+
if (msg.messageId === "TS6307") continue;
|
|
185
|
+
let sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
186
|
+
logger.warn(`${sourceFilePath || "?"}:${msg.sourceFileLine}:${msg.sourceFileColumn} - warning ${msg.messageId}\n${msg.text}\n`);
|
|
187
|
+
}
|
|
188
|
+
!warnings.length && errors.length && logger.log();
|
|
189
|
+
for (let msg of errors) {
|
|
190
|
+
let sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
191
|
+
logger.error(`${sourceFilePath || "?"}:${msg.sourceFileLine}:${msg.sourceFileColumn} - error ${msg.messageId}\n${msg.text}\n`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export { checkTsdoc };
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=tsdoc.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsdoc.mjs","names":[],"sources":["../src/tsdoc/createApiExtractorConfig.ts","../src/tsdoc/createTSDocConfig.ts","../src/tsdoc/getExtractMessagesConfig.ts","../src/tsdoc/checkTsdoc.ts"],"sourcesContent":["import path from 'node:path'\nimport type {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'\n\n/** @internal */\nexport function createApiExtractorConfig(options: {\n bundledPackages?: string[]\n distPath: string\n exportPath: string\n filePath: string\n messages: IExtractorMessagesConfig\n projectFolder: string\n mainEntryPointFilePath: string\n /**\n * Only `compilerOptions.paths` is read: when present, API Extractor gets an override that\n * clears `paths` so self-referencing package imports resolve through `node_modules` instead.\n */\n tsconfig: {options: {paths?: unknown}}\n tsconfigPath: string\n}): IConfigFile {\n const {\n bundledPackages,\n distPath,\n exportPath,\n filePath,\n messages,\n projectFolder,\n mainEntryPointFilePath,\n tsconfig,\n tsconfigPath,\n } = options\n\n return {\n apiReport: {\n enabled: false,\n reportFileName: '<unscopedPackageName>.api.md',\n },\n bundledPackages,\n\n // If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),\n compiler: tsconfig.options.paths\n ? {\n overrideTsconfig: {\n extends: tsconfigPath,\n compilerOptions: {\n // An empty object replaces whatever is in the original tsconfig file\n paths: {},\n },\n },\n }\n : {tsconfigFilePath: tsconfigPath},\n\n docModel: {\n enabled: false,\n apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),\n },\n dtsRollup: {\n // Types come from tsdown; this check only runs API Extractor's TSDoc/release-tag rules\n enabled: false,\n untrimmedFilePath: path.resolve(distPath, filePath),\n },\n tsdocMetadata: {\n enabled: false,\n },\n messages,\n mainEntryPointFilePath,\n projectFolder,\n }\n}\n","import {readFile} from 'node:fs/promises'\nimport {createRequire} from 'node:module'\nimport {TSDocConfigFile} from '@microsoft/tsdoc-config'\nimport {parse} from 'jsonc-parser'\nimport type {PackageTsdocCustomTag} from './types.ts'\n\nconst require = createRequire(import.meta.url)\n\n/** @internal */\nexport async function createTSDocConfig(opts: {\n customTags: PackageTsdocCustomTag[]\n}): Promise<TSDocConfigFile | undefined> {\n const {customTags} = opts\n\n if (customTags.length === 0) {\n return undefined\n }\n\n const tsDocBaseBuf = await readFile(\n require.resolve('@microsoft/api-extractor/extends/tsdoc-base.json'),\n )\n\n // Include the definitions that are required for API Extractor\n // extends: ['@microsoft/api-extractor/extends/tsdoc-base.json'],\n const tsDocBaseConfig = parse(tsDocBaseBuf.toString())\n\n // Define custom tags and specify how they should be parsed\n const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(\n customTags.map((t) => ({\n tagName: `@${t.name}`,\n syntaxKind: t.syntaxKind,\n allowMultiple: t.allowMultiple,\n })),\n )\n\n // Indicate that custom tags are supported by your tooling.\n // (Without this, warnings may be reported saying that a tag is unsupported.)\n const supportForTags = {...tsDocBaseConfig.supportForTags}\n\n for (const customTag of customTags) {\n supportForTags[`@${customTag.name}`] = true\n }\n\n return TSDocConfigFile.loadFromObject({\n ...tsDocBaseConfig,\n noStandardTags: false,\n tagDefinitions,\n supportForTags,\n })\n}\n","import {ExtractorLogLevel, type IExtractorMessagesConfig} from '@microsoft/api-extractor'\nimport type {PackageTsdocOptions, PackageTsdocRuleLevel} from './types.ts'\n\nconst LOG_LEVELS: Record<PackageTsdocRuleLevel, ExtractorLogLevel> = {\n error: ExtractorLogLevel.Error,\n info: ExtractorLogLevel.Info,\n off: ExtractorLogLevel.None,\n warn: ExtractorLogLevel.Warning,\n}\n\n/** @internal */\nexport function getExtractMessagesConfig(options: {\n rules: PackageTsdocOptions['rules']\n disabled?: boolean\n}): IExtractorMessagesConfig {\n const {rules, disabled = false} = options\n\n function ruleToLogLevel(\n key: keyof NonNullable<PackageTsdocOptions['rules']>,\n defaultLevel?: ExtractorLogLevel,\n ) {\n const r = rules?.[key]\n\n return r ? LOG_LEVELS[r] : defaultLevel || ExtractorLogLevel.Warning\n }\n\n return {\n compilerMessageReporting: {\n default: {\n logLevel: disabled ? ExtractorLogLevel.None : ExtractorLogLevel.Warning,\n },\n },\n\n extractorMessageReporting: disabled\n ? {\n default: {\n logLevel: ExtractorLogLevel.None,\n addToApiReportFile: false,\n },\n }\n : {\n 'default': {\n logLevel: ExtractorLogLevel.Warning,\n addToApiReportFile: false,\n },\n\n 'ae-forgotten-export': {\n /**\n * This is hardcoded to `none` as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873\n * It's hardcoded to `none` since supported by API Extractor when using `module: 'Preserve'` doesn't support it well since `@microsoft/api-extractor` v7.49.0, which upgraded from TS 5.4 to 5.7 internally\n */\n logLevel: ExtractorLogLevel.None,\n addToApiReportFile: false,\n },\n\n 'ae-incompatible-release-tags': {\n logLevel: ruleToLogLevel('ae-incompatible-release-tags', ExtractorLogLevel.Error),\n addToApiReportFile: false,\n },\n\n 'ae-internal-missing-underscore': {\n logLevel: ruleToLogLevel('ae-internal-missing-underscore'),\n addToApiReportFile: false,\n },\n\n 'ae-missing-release-tag': {\n logLevel: ruleToLogLevel('ae-missing-release-tag', ExtractorLogLevel.Error),\n addToApiReportFile: false,\n },\n\n 'ae-wrong-input-file-type': {\n logLevel: ExtractorLogLevel.None,\n addToApiReportFile: false,\n },\n },\n\n tsdocMessageReporting: disabled\n ? {\n default: {\n logLevel: ExtractorLogLevel.None,\n addToApiReportFile: false,\n },\n }\n : {\n 'default': {\n logLevel: ExtractorLogLevel.Warning,\n addToApiReportFile: false,\n },\n\n 'tsdoc-link-tag-unescaped-text': {\n logLevel: ruleToLogLevel('tsdoc-link-tag-unescaped-text', ExtractorLogLevel.Warning),\n addToApiReportFile: false,\n },\n\n 'tsdoc-undefined-tag': {\n logLevel: ruleToLogLevel('tsdoc-undefined-tag', ExtractorLogLevel.Error),\n addToApiReportFile: false,\n },\n\n 'tsdoc-unsupported-tag': {\n logLevel: ruleToLogLevel('tsdoc-unsupported-tag', ExtractorLogLevel.None),\n addToApiReportFile: false,\n },\n },\n }\n}\n","import {existsSync} from 'node:fs'\nimport path from 'node:path'\nimport {\n Extractor,\n ExtractorConfig,\n ExtractorLogLevel,\n type ExtractorMessage,\n} from '@microsoft/api-extractor'\n// The JS compiler API is loaded from the official `@typescript/typescript6` compat package\n// instead of the `typescript` peer dependency, as TypeScript 7 (the Go-native compiler) no longer\n// ships it\nimport ts from '@typescript/typescript6'\nimport {createApiExtractorConfig} from './createApiExtractorConfig.ts'\nimport {createTSDocConfig} from './createTSDocConfig.ts'\nimport {getExtractMessagesConfig} from './getExtractMessagesConfig.ts'\nimport type {PackageTsdocOptions} from './types.ts'\n\n/** @public */\nexport interface CheckTsdocLogger {\n log: (...args: unknown[]) => void\n warn: (...args: unknown[]) => void\n error: (...args: unknown[]) => void\n}\n\n/** @public */\nexport interface CheckTsdocOptions extends PackageTsdocOptions {\n /** Package root (directory containing `package.json`). */\n cwd: string\n /**\n * Absolute paths to the entry `.d.ts` / `.d.mts` / `.d.cts` files to check.\n * JS-only entries with no declarations are skipped automatically when listed.\n */\n entryDtsFiles: string[]\n /**\n * Path to the tsconfig used for the build, relative to `cwd` or absolute.\n * @defaultValue `'tsconfig.json'`\n */\n tsconfig?: string\n /**\n * Directory of distributed files (used for API Extractor's path mapping). Defaults to the\n * common parent of `entryDtsFiles`, or `dist` under `cwd` when the list is empty.\n */\n outDir?: string\n /**\n * When provided, messages are printed through this logger. Errors throw after reporting so\n * callers (and tsdown's `build:done` hook) fail the build.\n */\n logger?: CheckTsdocLogger\n}\n\n/** @public */\nexport interface CheckTsdocResult {\n messages: ExtractorMessage[]\n errorCount: number\n warningCount: number\n}\n\n/**\n * Run `@microsoft/api-extractor` against the given entry declaration files to check that TSDoc\n * tags are valid and release tags are correct. Import from `@sanity/tsdown-config/tsdoc`.\n * @public\n */\nexport async function checkTsdoc(options: CheckTsdocOptions): Promise<CheckTsdocResult> {\n const {\n cwd,\n entryDtsFiles,\n bundledPackages,\n customTags = [],\n rules = {},\n logger,\n outDir: outDirOption,\n } = options\n\n const tsconfigPath = path.resolve(cwd, options.tsconfig || 'tsconfig.json')\n const tsconfig = loadTSConfig({cwd, tsconfigPath})\n // api-extractor needs a `compilerOptions.outDir` for its path mapping; tsdown does not, so\n // fall back to the configured outDir / dist folder when the tsconfig leaves it unset\n const outDir =\n tsconfig?.options.outDir ??\n (outDirOption ? path.resolve(cwd, outDirOption) : undefined) ??\n commonParentDir(entryDtsFiles) ??\n path.resolve(cwd, 'dist')\n\n const tsdocConfigFile = await createTSDocConfig({customTags})\n const messagesConfig = getExtractMessagesConfig({rules})\n const allMessages: ExtractorMessage[] = []\n\n for (const exportPath of entryDtsFiles) {\n if (!existsSync(exportPath)) continue\n\n const relativeDtsPath = path.relative(outDir, exportPath)\n const extractorConfig = ExtractorConfig.prepare({\n configObject: createApiExtractorConfig({\n bundledPackages,\n distPath: outDir,\n exportPath,\n filePath: relativeDtsPath,\n messages: messagesConfig,\n projectFolder: cwd,\n mainEntryPointFilePath: exportPath,\n tsconfig: tsconfig ?? {options: {}},\n tsconfigPath,\n }),\n configObjectFullPath: undefined,\n tsdocConfigFile,\n packageJsonFullPath: path.resolve(cwd, 'package.json'),\n })\n\n Extractor.invoke(extractorConfig, {\n localBuild: true,\n showVerboseMessages: true,\n messageCallback(message: ExtractorMessage) {\n allMessages.push(message)\n message.handled = true\n },\n })\n }\n\n const warnings = allMessages.filter((msg) => msg.logLevel === ExtractorLogLevel.Warning)\n const errors = allMessages.filter((msg) => msg.logLevel === ExtractorLogLevel.Error)\n\n if (logger) {\n reportMessages(cwd, logger, warnings, errors)\n }\n\n if (errors.length) {\n throw new Error(\n `TSDoc/release-tag check failed with ${errors.length} error${errors.length === 1 ? '' : 's'}`,\n )\n }\n\n return {\n messages: allMessages,\n errorCount: errors.length,\n warningCount: warnings.length,\n }\n}\n\nfunction loadTSConfig(options: {\n cwd: string\n tsconfigPath: string\n}): ReturnType<typeof ts.parseJsonConfigFileContent> | undefined {\n const {cwd, tsconfigPath} = options\n // Resolve a relative name from `cwd` (e.g. `tsconfig.dist.json`); an absolute path is kept.\n let configPath: string | undefined\n if (path.isAbsolute(tsconfigPath)) {\n configPath = tsconfigPath\n } else {\n // oxlint-disable-next-line unbound-method\n configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath)\n }\n if (!configPath || !existsSync(configPath)) return undefined\n // oxlint-disable-next-line unbound-method\n const configFile = ts.readConfigFile(configPath, ts.sys.readFile)\n // Relative `extends`/`include`/`paths` are resolved from the tsconfig's directory, not `cwd`\n return ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath))\n}\n\nfunction commonParentDir(files: string[]): string | undefined {\n if (files.length === 0) return undefined\n let dir = path.dirname(files[0]!)\n for (const file of files.slice(1)) {\n while (dir !== path.dirname(dir) && !file.startsWith(dir + path.sep) && file !== dir) {\n dir = path.dirname(dir)\n }\n }\n return dir\n}\n\nfunction reportMessages(\n cwd: string,\n logger: CheckTsdocLogger,\n warnings: ExtractorMessage[],\n errors: ExtractorMessage[],\n): void {\n if (warnings.length) {\n logger.log()\n }\n\n for (const msg of warnings) {\n if (msg.messageId === 'TS6307') {\n // Ignore this warning:\n // > TS6307: <filename> is not in project file list.\n // > Projects must list all files or use an 'include' pattern.\n continue\n }\n const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)\n logger.warn(\n `${sourceFilePath || '?'}:${msg.sourceFileLine}:${msg.sourceFileColumn} - warning ${msg.messageId}\\n${msg.text}\\n`,\n )\n }\n\n if (!warnings.length && errors.length) {\n logger.log()\n }\n\n for (const msg of errors) {\n const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)\n logger.error(\n `${sourceFilePath || '?'}:${msg.sourceFileLine}:${msg.sourceFileColumn} - error ${msg.messageId}\\n${msg.text}\\n`,\n )\n }\n}\n"],"mappings":";;;;;;;;;AAIA,SAAgB,yBAAyB,SAczB;CACd,IAAM,EACJ,iBACA,UACA,YACA,UACA,UACA,eACA,wBACA,UACA,iBACE;CAEJ,OAAO;EACL,WAAW;GACT,SAAS;GACT,gBAAgB;EAClB;EACA;EAGA,UAAU,SAAS,QAAQ,QACvB,EACE,kBAAkB;GAChB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BAAgB,OAAqC;CAC5D,IAAI,MAAM,WAAW,GAAG;CACxB,IAAI,MAAM,KAAK,QAAQ,MAAM,EAAG;CAChC,KAAK,IAAM,QAAQ,MAAM,MAAM,CAAC,GAC9B,OAAO,QAAQ,KAAK,QAAQ,GAAG,KAAK,CAAC,KAAK,WAAW,MAAM,KAAK,GAAG,KAAK,SAAS,MAC/E,MAAM,KAAK,QAAQ,GAAG;CAG1B,OAAO;AACT;AAEA,SAAS,eACP,KACA,QACA,UACA,QACM;CACN,AAAI,SAAS,UACX,OAAO,IAAI;CAGb,KAAK,IAAM,OAAO,UAAU;EAC1B,IAAI,IAAI,cAAc,UAIpB;EAEF,IAAM,iBAAiB,IAAI,kBAAkB,KAAK,SAAS,KAAK,IAAI,cAAc;EAClF,OAAO,KACL,GAAG,kBAAkB,IAAI,GAAG,IAAI,eAAe,GAAG,IAAI,iBAAiB,aAAa,IAAI,UAAU,IAAI,IAAI,KAAK,GACjH;CACF;CAEA,AAAI,CAAC,SAAS,UAAU,OAAO,UAC7B,OAAO,IAAI;CAGb,KAAK,IAAM,OAAO,QAAQ;EACxB,IAAM,iBAAiB,IAAI,kBAAkB,KAAK,SAAS,KAAK,IAAI,cAAc;EAClF,OAAO,MACL,GAAG,kBAAkB,IAAI,GAAG,IAAI,eAAe,GAAG,IAAI,iBAAiB,WAAW,IAAI,UAAU,IAAI,IAAI,KAAK,GAC/G;CACF;AACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level for a TSDoc / API Extractor rule.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
type PackageTsdocRuleLevel = "error" | "warn" | "info" | "off";
|
|
6
|
+
/**
|
|
7
|
+
* A custom TSDoc tag definition, forwarded to `@microsoft/tsdoc-config`.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
interface PackageTsdocCustomTag {
|
|
11
|
+
name: string;
|
|
12
|
+
syntaxKind: "block" | "modifier";
|
|
13
|
+
allowMultiple?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Options for the `tsdoc` option: the `@microsoft/api-extractor` powered TSDoc and release-tag
|
|
17
|
+
* checking that runs after the build (via tsdown's `build:done` hook).
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
interface PackageTsdocOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Packages whose types should be treated as part of this project (API Extractor's
|
|
23
|
+
* `bundledPackages`). Usually inferred from `deps.alwaysBundle` string entries; pass
|
|
24
|
+
* explicitly when the check needs a richer list (e.g. non-external `devDependencies`).
|
|
25
|
+
*/
|
|
26
|
+
bundledPackages?: string[];
|
|
27
|
+
customTags?: PackageTsdocCustomTag[];
|
|
28
|
+
rules?: {
|
|
29
|
+
"ae-incompatible-release-tags"?: PackageTsdocRuleLevel;
|
|
30
|
+
"ae-internal-missing-underscore"?: PackageTsdocRuleLevel;
|
|
31
|
+
"ae-missing-release-tag"?: PackageTsdocRuleLevel;
|
|
32
|
+
"tsdoc-link-tag-unescaped-text"?: PackageTsdocRuleLevel;
|
|
33
|
+
"tsdoc-undefined-tag"?: PackageTsdocRuleLevel;
|
|
34
|
+
"tsdoc-unsupported-tag"?: PackageTsdocRuleLevel;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { PackageTsdocOptions as n, PackageTsdocRuleLevel as r, PackageTsdocCustomTag as t };
|
|
38
|
+
//# sourceMappingURL=types-CrQ2my_P.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CrQ2my_P.d.mts","names":[],"sources":["../src/tsdoc/types.ts"],"mappings":"AAIA;;;;KAAY;;;;;UAMK;EACf;EACA;EACA;;;;;;;UAQe;;;;;;EAMf;EACA,aAAa;EACb;IACE,iCAAiC;IACjC,mCAAmC;IACnC,2BAA2B;IAC3B,kCAAkC;IAClC,wBAAwB;IACxB,0BAA0B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/tsdown-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Shared configuration for tsdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"type": "module",
|
|
29
29
|
"exports": {
|
|
30
30
|
".": "./dist/index.mjs",
|
|
31
|
+
"./tsdoc": "./dist/tsdoc.mjs",
|
|
31
32
|
"./package.json": "./package.json"
|
|
32
33
|
},
|
|
33
34
|
"types": "./dist/index.d.mts",
|
|
@@ -36,33 +37,41 @@
|
|
|
36
37
|
],
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"@babel/core": "^7.29.7",
|
|
40
|
+
"@microsoft/api-extractor": "^7.58.12",
|
|
41
|
+
"@microsoft/tsdoc-config": "^0.18.1",
|
|
39
42
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
40
43
|
"@sanity/browserslist-config": "^1.0.5",
|
|
44
|
+
"@typescript/typescript6": "^6.0.2",
|
|
41
45
|
"@vitejs/plugin-react": "^6.0.5",
|
|
42
46
|
"browserslist": "^4.28.7",
|
|
47
|
+
"jsonc-parser": "^3.3.1",
|
|
43
48
|
"lightningcss": "^1.33.0",
|
|
44
49
|
"package-manager-detector": "^1.8.0",
|
|
45
|
-
"publint": "^0.3.
|
|
46
|
-
"@sanity/vanilla-extract-tsdown-plugin": "^0.
|
|
50
|
+
"publint": "^0.3.23",
|
|
51
|
+
"@sanity/vanilla-extract-tsdown-plugin": "^0.3.0"
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
54
|
"@tsdown/css": "^0.22.14",
|
|
50
55
|
"@types/babel__core": "^7.20.5",
|
|
51
56
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
52
57
|
"rolldown": "~1.2.0",
|
|
53
|
-
"tinyexec": "^1.
|
|
58
|
+
"tinyexec": "^1.3.0",
|
|
54
59
|
"tsdown": "^0.22.14",
|
|
55
60
|
"typescript": "7.0.2",
|
|
56
61
|
"vitest": "^4.1.10",
|
|
57
|
-
"@sanity/pkg-utils": "^12.
|
|
62
|
+
"@sanity/pkg-utils": "^12.1.0",
|
|
58
63
|
"@sanity/tsconfig": "^2.2.1"
|
|
59
64
|
},
|
|
60
65
|
"peerDependencies": {
|
|
66
|
+
"@tsdown/css": "*",
|
|
61
67
|
"babel-plugin-react-compiler": "*",
|
|
62
|
-
"tsdown": "^0.22.
|
|
68
|
+
"tsdown": "^0.22.7",
|
|
63
69
|
"typescript": "6.x || 7.x"
|
|
64
70
|
},
|
|
65
71
|
"peerDependenciesMeta": {
|
|
72
|
+
"@tsdown/css": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
66
75
|
"babel-plugin-react-compiler": {
|
|
67
76
|
"optional": true
|
|
68
77
|
}
|