@sanity/pkg-utils 7.2.10-canary.1 → 7.2.10-canary.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/dist/_chunks-cjs/index.cjs +10 -106
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/resolveRolldownConfig.cjs +79 -0
- package/dist/_chunks-cjs/resolveRolldownConfig.cjs.map +1 -0
- package/dist/_chunks-es/index.js +2311 -0
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/_chunks-es/resolveRolldownConfig.js +78 -0
- package/dist/_chunks-es/resolveRolldownConfig.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/index.d.cts +487 -408
- package/dist/index.d.ts +487 -408
- package/dist/index.js +1 -2390
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/cli/buildAction.ts +0 -21
- package/src/cli/checkAction.ts +0 -14
- package/src/cli/handleError.ts +0 -11
- package/src/cli/index.ts +0 -65
- package/src/cli/initAction.ts +0 -13
- package/src/cli/watchAction.ts +0 -14
- package/src/global.ts +0 -5
- package/src/node/__snapshots__/strict.test.ts.snap +0 -154
- package/src/node/build.ts +0 -100
- package/src/node/check.ts +0 -188
- package/src/node/consoleSpy.ts +0 -39
- package/src/node/core/config/defineConfig.ts +0 -6
- package/src/node/core/config/findConfigFile.ts +0 -31
- package/src/node/core/config/index.ts +0 -4
- package/src/node/core/config/loadConfig.ts +0 -37
- package/src/node/core/config/resolveConfigProperty.ts +0 -15
- package/src/node/core/config/types.ts +0 -315
- package/src/node/core/contexts/buildContext.ts +0 -32
- package/src/node/core/contexts/index.ts +0 -1
- package/src/node/core/defaults.ts +0 -4
- package/src/node/core/findCommonPath.ts +0 -35
- package/src/node/core/isRecord.ts +0 -4
- package/src/node/core/pkg/helpers.ts +0 -36
- package/src/node/core/pkg/index.ts +0 -5
- package/src/node/core/pkg/loadPkg.ts +0 -21
- package/src/node/core/pkg/loadPkgWithReporting.ts +0 -154
- package/src/node/core/pkg/parseExports.ts +0 -233
- package/src/node/core/pkg/pkgExt.ts +0 -22
- package/src/node/core/pkg/types.ts +0 -60
- package/src/node/core/pkg/validateExports.ts +0 -30
- package/src/node/core/pkg/validatePkg.ts +0 -82
- package/src/node/core/template/createFromTemplate.ts +0 -84
- package/src/node/core/template/define.ts +0 -6
- package/src/node/core/template/index.ts +0 -3
- package/src/node/core/template/types.ts +0 -45
- package/src/node/core/ts/index.ts +0 -1
- package/src/node/core/ts/loadTSConfig.ts +0 -19
- package/src/node/fileExists.ts +0 -12
- package/src/node/getFilesize.ts +0 -8
- package/src/node/globFiles.ts +0 -6
- package/src/node/index.ts +0 -48
- package/src/node/init.ts +0 -54
- package/src/node/isEmptyDirectory.ts +0 -5
- package/src/node/logger.ts +0 -32
- package/src/node/printExtractMessages.ts +0 -59
- package/src/node/printPackageTree.ts +0 -95
- package/src/node/resolveBrowserTarget.ts +0 -17
- package/src/node/resolveBuildContext.ts +0 -202
- package/src/node/resolveBuildTasks.ts +0 -199
- package/src/node/resolveNodeTarget.ts +0 -9
- package/src/node/resolveWatchTasks.ts +0 -132
- package/src/node/spinner.ts +0 -17
- package/src/node/strict.test-d.ts +0 -6
- package/src/node/strict.ts +0 -84
- package/src/node/tasks/dts/DtsError.ts +0 -11
- package/src/node/tasks/dts/buildTypes.ts +0 -42
- package/src/node/tasks/dts/createApiExtractorConfig.ts +0 -67
- package/src/node/tasks/dts/createTSDocConfig.ts +0 -53
- package/src/node/tasks/dts/doExtract.ts +0 -80
- package/src/node/tasks/dts/dtsTask.ts +0 -50
- package/src/node/tasks/dts/dtsWatchTask.ts +0 -165
- package/src/node/tasks/dts/extractModuleBlocks.ts +0 -45
- package/src/node/tasks/dts/extractTypes.ts +0 -128
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +0 -109
- package/src/node/tasks/dts/getTargetPaths.ts +0 -72
- package/src/node/tasks/dts/printDiagnostic.ts +0 -42
- package/src/node/tasks/dts/types.ts +0 -30
- package/src/node/tasks/index.ts +0 -19
- package/src/node/tasks/rolldown/resolveRolldownConfig.ts +0 -208
- package/src/node/tasks/rolldown/rolldownDtsTask.ts +0 -155
- package/src/node/tasks/rollup/resolveRollupConfig.ts +0 -264
- package/src/node/tasks/rollup/rollupTask.ts +0 -154
- package/src/node/tasks/rollup/rollupWatchTask.ts +0 -77
- package/src/node/tasks/types.ts +0 -69
- package/src/node/templates/default/index.ts +0 -1
- package/src/node/templates/default/template.ts +0 -547
- package/src/node/templates/index.ts +0 -1
- package/src/node/watch.ts +0 -66
- package/src/node/watchConfigFiles.ts +0 -53
- package/src/node/watchFiles.ts +0 -31
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types'
|
|
3
|
-
import type {BuildContext} from './core/contexts/buildContext'
|
|
4
|
-
import {getTargetPaths} from './tasks/dts/getTargetPaths'
|
|
5
|
-
import type {DtsWatchTask} from './tasks/dts/types'
|
|
6
|
-
import type {RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks/types'
|
|
7
|
-
|
|
8
|
-
/** @internal */
|
|
9
|
-
export function resolveWatchTasks(ctx: BuildContext): WatchTask[] {
|
|
10
|
-
const {pkg, target} = ctx
|
|
11
|
-
const tasks: WatchTask[] = []
|
|
12
|
-
|
|
13
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
14
|
-
([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
const dtsTask: DtsWatchTask = {
|
|
18
|
-
type: 'watch:dts',
|
|
19
|
-
entries: [],
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const rollupTasks: Record<string, RollupWatchTask> = {}
|
|
23
|
-
|
|
24
|
-
function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
25
|
-
const buildId = `${format}:${runtime}`
|
|
26
|
-
|
|
27
|
-
if (rollupTasks[buildId]) {
|
|
28
|
-
rollupTasks[buildId].entries.push(entry)
|
|
29
|
-
} else {
|
|
30
|
-
rollupTasks[buildId] = {
|
|
31
|
-
type: 'watch:js',
|
|
32
|
-
buildId,
|
|
33
|
-
entries: [entry],
|
|
34
|
-
runtime,
|
|
35
|
-
format,
|
|
36
|
-
target: target[runtime],
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Parse `dts` tasks
|
|
42
|
-
for (const exp of exports) {
|
|
43
|
-
const importId = path.join(pkg.name, exp._path)
|
|
44
|
-
|
|
45
|
-
if (exp.source?.endsWith('.ts')) {
|
|
46
|
-
dtsTask.entries.push({
|
|
47
|
-
importId,
|
|
48
|
-
exportPath: exp._path,
|
|
49
|
-
sourcePath: exp.source,
|
|
50
|
-
targetPaths: getTargetPaths(pkg.type, exp),
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (exp.browser?.source?.endsWith('.ts')) {
|
|
55
|
-
dtsTask.entries.push({
|
|
56
|
-
importId,
|
|
57
|
-
exportPath: exp._path,
|
|
58
|
-
sourcePath: exp.browser.source,
|
|
59
|
-
targetPaths: getTargetPaths(pkg.type, exp.browser),
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (exp.node?.source?.endsWith('.ts')) {
|
|
64
|
-
dtsTask.entries.push({
|
|
65
|
-
importId,
|
|
66
|
-
exportPath: exp._path,
|
|
67
|
-
sourcePath: exp.node.source,
|
|
68
|
-
targetPaths: getTargetPaths(pkg.type, exp.node),
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Parse rollup:commonjs:* tasks
|
|
74
|
-
for (const exp of exports) {
|
|
75
|
-
const output = exp.require
|
|
76
|
-
|
|
77
|
-
if (!output) continue
|
|
78
|
-
|
|
79
|
-
addRollupTaskEntry('commonjs', ctx.runtime, {
|
|
80
|
-
path: exp._path,
|
|
81
|
-
source: exp.source,
|
|
82
|
-
output,
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Parse rollup:commonjs:browser tasks
|
|
87
|
-
for (const exp of exports) {
|
|
88
|
-
const output = exp.browser?.require
|
|
89
|
-
|
|
90
|
-
if (!output) continue
|
|
91
|
-
|
|
92
|
-
addRollupTaskEntry('commonjs', 'browser', {
|
|
93
|
-
path: exp._path,
|
|
94
|
-
source: exp.browser?.source || exp.source,
|
|
95
|
-
output,
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Parse rollup:esm:* tasks
|
|
100
|
-
for (const exp of exports) {
|
|
101
|
-
const output = exp.import
|
|
102
|
-
|
|
103
|
-
if (!output) continue
|
|
104
|
-
|
|
105
|
-
addRollupTaskEntry('esm', ctx.runtime, {
|
|
106
|
-
path: exp._path,
|
|
107
|
-
source: exp.source,
|
|
108
|
-
output,
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Parse rollup:esm:browser tasks
|
|
113
|
-
for (const exp of exports) {
|
|
114
|
-
const output = exp.browser?.import
|
|
115
|
-
|
|
116
|
-
if (!output) continue
|
|
117
|
-
|
|
118
|
-
addRollupTaskEntry('esm', 'browser', {
|
|
119
|
-
path: exp._path,
|
|
120
|
-
source: exp.browser?.source || exp.source,
|
|
121
|
-
output,
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (dtsTask.entries.length) {
|
|
126
|
-
tasks.push(dtsTask)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
tasks.push(...Object.values(rollupTasks))
|
|
130
|
-
|
|
131
|
-
return tasks
|
|
132
|
-
}
|
package/src/node/spinner.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// oxlint-disable no-console
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
|
|
4
|
-
export function createSpinner(msg: string): {complete: () => void; error: () => void} {
|
|
5
|
-
const startTime = Date.now()
|
|
6
|
-
|
|
7
|
-
console.log(msg)
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
complete: () => {
|
|
11
|
-
console.log(`${chalk.green('[success]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)
|
|
12
|
-
},
|
|
13
|
-
error: () => {
|
|
14
|
-
console.log(`${chalk.red('[error]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)
|
|
15
|
-
},
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/node/strict.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {errorMap} from 'zod-validation-error'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export const toggle = z.union([z.literal('error'), z.literal('warn'), z.literal('off')])
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export type ToggleType = z.infer<typeof toggle>
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export const strictOptions = z
|
|
18
|
-
.object({
|
|
19
|
-
noPackageJsonTypings: toggle.default('error'),
|
|
20
|
-
noImplicitSideEffects: toggle.default('warn'),
|
|
21
|
-
noImplicitBrowsersList: toggle.default('warn'),
|
|
22
|
-
alwaysPackageJsonTypes: toggle.default('error'),
|
|
23
|
-
alwaysPackageJsonMain: toggle.default('error'),
|
|
24
|
-
alwaysPackageJsonFiles: toggle.default('error'),
|
|
25
|
-
})
|
|
26
|
-
.strict()
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* To make error message paths line up with the paths in package.config.ts the schema is hoisted into a root schema
|
|
30
|
-
* This way errors will say `Expected boolean, received string at "strict.noPackageJsonTypings"` instead of `Expected boolean, received string at "noPackageJsonTypings"`.
|
|
31
|
-
*/
|
|
32
|
-
const validationSchema = z.object({
|
|
33
|
-
strictOptions: strictOptions.default({}),
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export type InferredStrictOptions = z.infer<typeof strictOptions>
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
export interface StrictOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Disallows a top level `typings` field in `package.json` if it is equal to `exports['.'].source`.
|
|
47
|
-
* @defaultValue 'error'
|
|
48
|
-
*/
|
|
49
|
-
noPackageJsonTypings?: ToggleType
|
|
50
|
-
/**
|
|
51
|
-
* Requires specifying `sideEffects` in `package.json`.
|
|
52
|
-
* @defaultValue 'warn'
|
|
53
|
-
*/
|
|
54
|
-
noImplicitSideEffects?: ToggleType
|
|
55
|
-
/**
|
|
56
|
-
* Requires specifying `browserslist` in `package.json`, instead of relying on it implicitly being:
|
|
57
|
-
* @example
|
|
58
|
-
* ```
|
|
59
|
-
* "browserslist": "extends @sanity/browserslist-config"
|
|
60
|
-
* ```
|
|
61
|
-
* @defaultValue 'warn'
|
|
62
|
-
*/
|
|
63
|
-
noImplicitBrowsersList?: ToggleType
|
|
64
|
-
/**
|
|
65
|
-
* If typescript is used then `types` in `package.json` should be specified for npm listings to show the TS icon.
|
|
66
|
-
* @defaultValue 'error'
|
|
67
|
-
*/
|
|
68
|
-
alwaysPackageJsonTypes?: ToggleType
|
|
69
|
-
/**
|
|
70
|
-
* A lot of analysis tooling requiers the `main` field to work (like bundlephobia) and so it's best practice to always include it
|
|
71
|
-
* @defaultValue 'error'
|
|
72
|
-
*/
|
|
73
|
-
alwaysPackageJsonMain?: ToggleType
|
|
74
|
-
/**
|
|
75
|
-
* Using `.npmignore` is error prone, it's best practice to always declare `files` instead
|
|
76
|
-
* @defaultValue 'error'
|
|
77
|
-
*/
|
|
78
|
-
alwaysPackageJsonFiles?: ToggleType
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @alpha */
|
|
82
|
-
export function parseStrictOptions(input: unknown): InferredStrictOptions {
|
|
83
|
-
return validationSchema.parse({strictOptions: input}, {errorMap}).strictOptions
|
|
84
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type {ExtractorMessage} from '@microsoft/api-extractor'
|
|
2
|
-
|
|
3
|
-
/** @internal */
|
|
4
|
-
export class DtsError extends Error {
|
|
5
|
-
messages: ExtractorMessage[]
|
|
6
|
-
|
|
7
|
-
constructor(message: string, messages: ExtractorMessage[]) {
|
|
8
|
-
super(message)
|
|
9
|
-
this.messages = messages
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript'
|
|
2
|
-
import type {Logger} from '../../logger'
|
|
3
|
-
import {printDiagnostic} from './printDiagnostic'
|
|
4
|
-
|
|
5
|
-
/** @internal */
|
|
6
|
-
export async function buildTypes(options: {
|
|
7
|
-
cwd: string
|
|
8
|
-
logger: Logger
|
|
9
|
-
outDir: string
|
|
10
|
-
tsconfig: ts.ParsedCommandLine
|
|
11
|
-
strict: boolean
|
|
12
|
-
}): Promise<void> {
|
|
13
|
-
const {cwd, logger, outDir, tsconfig, strict = false} = options
|
|
14
|
-
|
|
15
|
-
const compilerOptions: ts.CompilerOptions = {
|
|
16
|
-
...tsconfig.options,
|
|
17
|
-
declaration: true,
|
|
18
|
-
declarationDir: outDir,
|
|
19
|
-
emitDeclarationOnly: true,
|
|
20
|
-
noEmit: false,
|
|
21
|
-
noEmitOnError: strict ? true : (tsconfig.options.noEmitOnError ?? true),
|
|
22
|
-
outDir,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const program = ts.createProgram(tsconfig.fileNames, compilerOptions)
|
|
26
|
-
|
|
27
|
-
const emitResult = program.emit()
|
|
28
|
-
|
|
29
|
-
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
|
|
30
|
-
|
|
31
|
-
for (const diagnostic of allDiagnostics) {
|
|
32
|
-
printDiagnostic({cwd, logger, diagnostic})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (emitResult.emitSkipped) {
|
|
36
|
-
const errors = allDiagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error)
|
|
37
|
-
|
|
38
|
-
if (errors.length) {
|
|
39
|
-
throw new Error('failed to compile TypeScript definitions')
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import type {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
3
|
-
import ts from 'typescript'
|
|
4
|
-
|
|
5
|
-
export function createApiExtractorConfig(options: {
|
|
6
|
-
bundledPackages?: string[]
|
|
7
|
-
distPath: string
|
|
8
|
-
exportPath: string
|
|
9
|
-
filePath: string
|
|
10
|
-
messages: IExtractorMessagesConfig
|
|
11
|
-
projectFolder: string
|
|
12
|
-
mainEntryPointFilePath: string
|
|
13
|
-
tsconfig: ts.ParsedCommandLine
|
|
14
|
-
tsconfigPath: string
|
|
15
|
-
dtsRollupEnabled: boolean
|
|
16
|
-
}): IConfigFile {
|
|
17
|
-
const {
|
|
18
|
-
bundledPackages,
|
|
19
|
-
distPath,
|
|
20
|
-
exportPath,
|
|
21
|
-
filePath,
|
|
22
|
-
messages,
|
|
23
|
-
projectFolder,
|
|
24
|
-
mainEntryPointFilePath,
|
|
25
|
-
tsconfig,
|
|
26
|
-
tsconfigPath,
|
|
27
|
-
dtsRollupEnabled,
|
|
28
|
-
} = options
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
apiReport: {
|
|
32
|
-
enabled: false,
|
|
33
|
-
reportFileName: '<unscopedPackageName>.api.md',
|
|
34
|
-
},
|
|
35
|
-
bundledPackages,
|
|
36
|
-
|
|
37
|
-
// 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`),
|
|
38
|
-
compiler: tsconfig.options.paths
|
|
39
|
-
? {
|
|
40
|
-
overrideTsconfig: {
|
|
41
|
-
extends: tsconfigPath,
|
|
42
|
-
compilerOptions: {
|
|
43
|
-
// An empty object replaces whatever is in the original tsconfig file
|
|
44
|
-
paths: {},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
: {tsconfigFilePath: tsconfigPath},
|
|
49
|
-
|
|
50
|
-
docModel: {
|
|
51
|
-
enabled: false,
|
|
52
|
-
apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),
|
|
53
|
-
},
|
|
54
|
-
dtsRollup: {
|
|
55
|
-
enabled: dtsRollupEnabled,
|
|
56
|
-
untrimmedFilePath: path.resolve(distPath, filePath),
|
|
57
|
-
// betaTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-beta.d.ts')),
|
|
58
|
-
// publicTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-public.d.ts')),
|
|
59
|
-
},
|
|
60
|
-
tsdocMetadata: {
|
|
61
|
-
enabled: false,
|
|
62
|
-
},
|
|
63
|
-
messages,
|
|
64
|
-
mainEntryPointFilePath,
|
|
65
|
-
projectFolder,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {readFile} from 'node:fs/promises'
|
|
2
|
-
import {TSDocConfigFile} from '@microsoft/tsdoc-config'
|
|
3
|
-
import {parse} from 'jsonc-parser'
|
|
4
|
-
|
|
5
|
-
/** @public */
|
|
6
|
-
export interface TSDocCustomTag {
|
|
7
|
-
name: string
|
|
8
|
-
syntaxKind: 'block' | 'modifier'
|
|
9
|
-
allowMultiple?: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** @internal */
|
|
13
|
-
export async function createTSDocConfig(opts: {
|
|
14
|
-
customTags: TSDocCustomTag[]
|
|
15
|
-
}): Promise<TSDocConfigFile | undefined> {
|
|
16
|
-
const {customTags} = opts
|
|
17
|
-
|
|
18
|
-
if (customTags.length === 0) {
|
|
19
|
-
return undefined
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const tsDocBaseBuf = await readFile(
|
|
23
|
-
require.resolve('@microsoft/api-extractor/extends/tsdoc-base.json'),
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
// Include the definitions that are required for API Extractor
|
|
27
|
-
// extends: ['@microsoft/api-extractor/extends/tsdoc-base.json'],
|
|
28
|
-
const tsDocBaseConfig = parse(tsDocBaseBuf.toString())
|
|
29
|
-
|
|
30
|
-
// Define custom tags and specify how they should be parsed
|
|
31
|
-
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(
|
|
32
|
-
customTags.map((t) => ({
|
|
33
|
-
tagName: `@${t.name}`,
|
|
34
|
-
syntaxKind: t.syntaxKind,
|
|
35
|
-
allowMultiple: t.allowMultiple,
|
|
36
|
-
})),
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
// Indicate that custom tags are supported by your tooling.
|
|
40
|
-
// (Without this, warnings may be reported saying that a tag is unsupported.)
|
|
41
|
-
const supportForTags = {...tsDocBaseConfig.supportForTags}
|
|
42
|
-
|
|
43
|
-
for (const customTag of customTags) {
|
|
44
|
-
supportForTags[`@${customTag.name}`] = true
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return TSDocConfigFile.loadFromObject({
|
|
48
|
-
...tsDocBaseConfig,
|
|
49
|
-
noStandardTags: false,
|
|
50
|
-
tagDefinitions,
|
|
51
|
-
supportForTags,
|
|
52
|
-
})
|
|
53
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import type {ExtractorMessage} from '@microsoft/api-extractor'
|
|
3
|
-
import {rimraf} from 'rimraf'
|
|
4
|
-
import type {BuildContext} from '../../core/contexts/buildContext'
|
|
5
|
-
import {buildTypes} from './buildTypes'
|
|
6
|
-
import {DtsError} from './DtsError'
|
|
7
|
-
import {extractTypes} from './extractTypes'
|
|
8
|
-
import type {DtsResult, DtsTask, DtsWatchTask} from './types'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* - Build type definitions to a temporary directory using TypeScript compiler.
|
|
12
|
-
* - Create a type definition bundle for each export entry.
|
|
13
|
-
* - When done, remove the temporary directory.
|
|
14
|
-
*/
|
|
15
|
-
export async function doExtract(
|
|
16
|
-
ctx: BuildContext,
|
|
17
|
-
task: DtsTask | DtsWatchTask,
|
|
18
|
-
): Promise<DtsResult> {
|
|
19
|
-
const {config, cwd, files, logger, strict, ts, bundledPackages} = ctx
|
|
20
|
-
|
|
21
|
-
if (!ts.config || !ts.configPath) {
|
|
22
|
-
return {type: 'dts', messages: [], results: []}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const {outDir, rootDir = cwd} = ts.config.options
|
|
26
|
-
|
|
27
|
-
if (!outDir) {
|
|
28
|
-
throw new Error('tsconfig.json is missing `compilerOptions.outDir`')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const tmpPath = path.resolve(outDir, '__tmp__')
|
|
32
|
-
|
|
33
|
-
await buildTypes({cwd, logger, outDir: tmpPath, strict, tsconfig: ts.config})
|
|
34
|
-
const messages: ExtractorMessage[] = []
|
|
35
|
-
|
|
36
|
-
const results: {sourcePath: string; filePaths: string[]}[] = []
|
|
37
|
-
|
|
38
|
-
for (const entry of task.entries) {
|
|
39
|
-
const exportPath = entry.exportPath === '.' ? './index' : entry.exportPath
|
|
40
|
-
|
|
41
|
-
const sourceTypesPath = path.resolve(
|
|
42
|
-
tmpPath,
|
|
43
|
-
path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, '.d.ts'),
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
const targetPaths = entry.targetPaths.map((targetPath) => path.resolve(cwd, targetPath))
|
|
47
|
-
const filePaths = targetPaths.map((targetPath) => path.relative(outDir, targetPath))
|
|
48
|
-
const result = await extractTypes({
|
|
49
|
-
bundledPackages: bundledPackages || [],
|
|
50
|
-
customTags: config?.extract?.customTags,
|
|
51
|
-
cwd,
|
|
52
|
-
distPath: outDir,
|
|
53
|
-
exportPath,
|
|
54
|
-
files,
|
|
55
|
-
filePaths,
|
|
56
|
-
projectPath: cwd,
|
|
57
|
-
rules: config?.extract?.rules,
|
|
58
|
-
sourceTypesPath: sourceTypesPath,
|
|
59
|
-
tsconfig: ts.config,
|
|
60
|
-
tmpPath,
|
|
61
|
-
tsconfigPath: path.resolve(cwd, ts.configPath || 'tsconfig.json'),
|
|
62
|
-
extractorDisabled: config?.extract?.enabled === false,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
messages.push(...result.messages)
|
|
66
|
-
|
|
67
|
-
const errors = result.messages.filter((msg) => msg.logLevel === 'error')
|
|
68
|
-
|
|
69
|
-
if (errors.length > 0) {
|
|
70
|
-
await rimraf(tmpPath)
|
|
71
|
-
throw new DtsError(`encountered ${errors.length} errors when extracting types`, errors)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
results.push({sourcePath: path.resolve(cwd, entry.sourcePath), filePaths: targetPaths})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
await rimraf(tmpPath)
|
|
78
|
-
|
|
79
|
-
return {type: 'dts', messages, results}
|
|
80
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import {Observable} from 'rxjs'
|
|
3
|
-
import {printExtractMessages} from '../../printExtractMessages'
|
|
4
|
-
import type {TaskHandler} from '../types'
|
|
5
|
-
import {doExtract} from './doExtract'
|
|
6
|
-
import {DtsError} from './DtsError'
|
|
7
|
-
import type {DtsResult, DtsTask} from './types'
|
|
8
|
-
|
|
9
|
-
/** @internal */
|
|
10
|
-
export const dtsTask: TaskHandler<DtsTask, DtsResult> = {
|
|
11
|
-
name: (ctx, task) =>
|
|
12
|
-
[
|
|
13
|
-
`Build type definitions with ${chalk.bold(ctx.dts)}...`,
|
|
14
|
-
' entries:',
|
|
15
|
-
...task.entries.map((entry) => {
|
|
16
|
-
return entry.targetPaths
|
|
17
|
-
.map((targetPath) => {
|
|
18
|
-
return [
|
|
19
|
-
` - ${chalk.cyan(entry.importId)}: `,
|
|
20
|
-
`${chalk.yellow(entry.sourcePath)} ${chalk.gray('→')} ${chalk.yellow(targetPath)}`,
|
|
21
|
-
].join('')
|
|
22
|
-
})
|
|
23
|
-
.join('\n')
|
|
24
|
-
}),
|
|
25
|
-
].join('\n'),
|
|
26
|
-
exec: (ctx, task) => {
|
|
27
|
-
return new Observable((observer) => {
|
|
28
|
-
doExtract(ctx, task)
|
|
29
|
-
.then((result) => {
|
|
30
|
-
observer.next(result)
|
|
31
|
-
observer.complete()
|
|
32
|
-
})
|
|
33
|
-
.catch((err) => {
|
|
34
|
-
observer.error(err)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
complete: (ctx, _task, result) => {
|
|
39
|
-
printExtractMessages(ctx, result.messages)
|
|
40
|
-
},
|
|
41
|
-
error: (ctx, _task, err) => {
|
|
42
|
-
const {logger} = ctx
|
|
43
|
-
|
|
44
|
-
if (err instanceof DtsError) {
|
|
45
|
-
printExtractMessages(ctx, err.messages)
|
|
46
|
-
} else if (err instanceof Error) {
|
|
47
|
-
logger.error(err)
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
}
|