@sanity/pkg-utils 7.2.10-canary.0 → 7.2.10-canary.2

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.
Files changed (95) hide show
  1. package/dist/_chunks-cjs/index.cjs +10 -105
  2. package/dist/_chunks-cjs/index.cjs.map +1 -1
  3. package/dist/_chunks-cjs/resolveRolldownConfig.cjs +114 -0
  4. package/dist/_chunks-cjs/resolveRolldownConfig.cjs.map +1 -0
  5. package/dist/_chunks-es/index.js +2311 -0
  6. package/dist/_chunks-es/index.js.map +1 -0
  7. package/dist/_chunks-es/resolveRolldownConfig.js +117 -0
  8. package/dist/_chunks-es/resolveRolldownConfig.js.map +1 -0
  9. package/dist/cli.cjs +1 -1
  10. package/dist/cli.d.cts +1 -1
  11. package/dist/index.d.cts +486 -443
  12. package/dist/index.d.ts +486 -443
  13. package/dist/index.js +1 -2389
  14. package/dist/index.js.map +1 -1
  15. package/package.json +7 -8
  16. package/src/cli/buildAction.ts +0 -21
  17. package/src/cli/checkAction.ts +0 -14
  18. package/src/cli/handleError.ts +0 -11
  19. package/src/cli/index.ts +0 -65
  20. package/src/cli/initAction.ts +0 -13
  21. package/src/cli/watchAction.ts +0 -14
  22. package/src/global.ts +0 -5
  23. package/src/node/__snapshots__/strict.test.ts.snap +0 -154
  24. package/src/node/build.ts +0 -100
  25. package/src/node/check.ts +0 -188
  26. package/src/node/consoleSpy.ts +0 -39
  27. package/src/node/core/config/defineConfig.ts +0 -6
  28. package/src/node/core/config/findConfigFile.ts +0 -31
  29. package/src/node/core/config/index.ts +0 -4
  30. package/src/node/core/config/loadConfig.ts +0 -37
  31. package/src/node/core/config/resolveConfigProperty.ts +0 -15
  32. package/src/node/core/config/types.ts +0 -315
  33. package/src/node/core/contexts/buildContext.ts +0 -32
  34. package/src/node/core/contexts/index.ts +0 -1
  35. package/src/node/core/defaults.ts +0 -4
  36. package/src/node/core/findCommonPath.ts +0 -35
  37. package/src/node/core/isRecord.ts +0 -4
  38. package/src/node/core/pkg/helpers.ts +0 -36
  39. package/src/node/core/pkg/index.ts +0 -5
  40. package/src/node/core/pkg/loadPkg.ts +0 -21
  41. package/src/node/core/pkg/loadPkgWithReporting.ts +0 -154
  42. package/src/node/core/pkg/parseExports.ts +0 -233
  43. package/src/node/core/pkg/pkgExt.ts +0 -22
  44. package/src/node/core/pkg/types.ts +0 -60
  45. package/src/node/core/pkg/validateExports.ts +0 -30
  46. package/src/node/core/pkg/validatePkg.ts +0 -82
  47. package/src/node/core/template/createFromTemplate.ts +0 -84
  48. package/src/node/core/template/define.ts +0 -6
  49. package/src/node/core/template/index.ts +0 -3
  50. package/src/node/core/template/types.ts +0 -45
  51. package/src/node/core/ts/index.ts +0 -1
  52. package/src/node/core/ts/loadTSConfig.ts +0 -19
  53. package/src/node/fileExists.ts +0 -12
  54. package/src/node/getFilesize.ts +0 -8
  55. package/src/node/globFiles.ts +0 -6
  56. package/src/node/index.ts +0 -48
  57. package/src/node/init.ts +0 -54
  58. package/src/node/isEmptyDirectory.ts +0 -5
  59. package/src/node/logger.ts +0 -32
  60. package/src/node/printExtractMessages.ts +0 -59
  61. package/src/node/printPackageTree.ts +0 -95
  62. package/src/node/resolveBrowserTarget.ts +0 -17
  63. package/src/node/resolveBuildContext.ts +0 -202
  64. package/src/node/resolveBuildTasks.ts +0 -199
  65. package/src/node/resolveNodeTarget.ts +0 -9
  66. package/src/node/resolveWatchTasks.ts +0 -132
  67. package/src/node/spinner.ts +0 -17
  68. package/src/node/strict.test-d.ts +0 -6
  69. package/src/node/strict.ts +0 -84
  70. package/src/node/tasks/dts/DtsError.ts +0 -11
  71. package/src/node/tasks/dts/buildTypes.ts +0 -42
  72. package/src/node/tasks/dts/createApiExtractorConfig.ts +0 -67
  73. package/src/node/tasks/dts/createTSDocConfig.ts +0 -53
  74. package/src/node/tasks/dts/doExtract.ts +0 -80
  75. package/src/node/tasks/dts/dtsTask.ts +0 -50
  76. package/src/node/tasks/dts/dtsWatchTask.ts +0 -165
  77. package/src/node/tasks/dts/extractModuleBlocks.ts +0 -45
  78. package/src/node/tasks/dts/extractTypes.ts +0 -128
  79. package/src/node/tasks/dts/getExtractMessagesConfig.ts +0 -109
  80. package/src/node/tasks/dts/getTargetPaths.ts +0 -72
  81. package/src/node/tasks/dts/printDiagnostic.ts +0 -42
  82. package/src/node/tasks/dts/types.ts +0 -30
  83. package/src/node/tasks/index.ts +0 -19
  84. package/src/node/tasks/rolldown/resolveRolldownConfig.ts +0 -202
  85. package/src/node/tasks/rolldown/rolldownDtsTask.ts +0 -155
  86. package/src/node/tasks/rollup/resolveRollupConfig.ts +0 -264
  87. package/src/node/tasks/rollup/rollupTask.ts +0 -154
  88. package/src/node/tasks/rollup/rollupWatchTask.ts +0 -77
  89. package/src/node/tasks/types.ts +0 -69
  90. package/src/node/templates/default/index.ts +0 -1
  91. package/src/node/templates/default/template.ts +0 -547
  92. package/src/node/templates/index.ts +0 -1
  93. package/src/node/watch.ts +0 -66
  94. package/src/node/watchConfigFiles.ts +0 -53
  95. package/src/node/watchFiles.ts +0 -31
@@ -1,165 +0,0 @@
1
- import path from 'node:path'
2
- import type {ExtractorMessage} from '@microsoft/api-extractor'
3
- import chalk from 'chalk'
4
- import * as rimraf from 'rimraf'
5
- import {Observable} from 'rxjs'
6
- import ts from 'typescript'
7
- import {printExtractMessages} from '../../printExtractMessages'
8
- import type {TaskHandler} from '../types'
9
- import {buildTypes} from './buildTypes'
10
- import {DtsError} from './DtsError'
11
- import {extractTypes} from './extractTypes'
12
- import type {DtsResult, DtsWatchTask} from './types'
13
-
14
- /** @internal */
15
- export const dtsWatchTask: TaskHandler<DtsWatchTask, DtsResult> = {
16
- name: (_ctx, task) =>
17
- [
18
- 'build type definitions',
19
- ...task.entries.map((entry) => {
20
- return entry.targetPaths.map((targetPath) => {
21
- return [
22
- ` - ${chalk.cyan(entry.importId)}: `,
23
- `${chalk.yellow(entry.sourcePath)} ${chalk.gray('→')} ${chalk.yellow(targetPath)}`,
24
- ].join('')
25
- })
26
- }),
27
- ].join('\n'),
28
- exec: (ctx, task) => {
29
- const {config, cwd, files, logger, strict, ts: tsContext, bundledPackages} = ctx
30
-
31
- return new Observable((observer) => {
32
- if (!tsContext.config || !tsContext.configPath) {
33
- observer.next({type: 'dts', messages: [], results: []})
34
- observer.complete()
35
-
36
- return
37
- }
38
-
39
- const {outDir, rootDir = cwd} = tsContext.config.options
40
-
41
- if (!outDir) {
42
- observer.error(new Error('tsconfig.json is missing `compilerOptions.outDir`'))
43
-
44
- return
45
- }
46
-
47
- const tmpPath = path.resolve(outDir, '__tmp__')
48
-
49
- buildTypes({
50
- cwd,
51
- logger,
52
- outDir: tmpPath,
53
- tsconfig: tsContext.config,
54
- strict,
55
- }).catch((err) => {
56
- observer.error(err)
57
- })
58
-
59
- const host = ts.createWatchCompilerHost(
60
- tsContext.configPath,
61
- {
62
- ...tsContext.config.options,
63
- declaration: true,
64
- declarationDir: tmpPath,
65
- emitDeclarationOnly: true,
66
- noEmit: false,
67
- noEmitOnError: strict ? true : (tsContext.config.options.noEmitOnError ?? true),
68
- outDir: tmpPath,
69
- },
70
- ts.sys,
71
- ts.createEmitAndSemanticDiagnosticsBuilderProgram,
72
- (diagnostic) => {
73
- logger.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
74
- },
75
- (diagnostic) => {
76
- logger.info(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
77
- },
78
- )
79
-
80
- const origPostProgramCreate = host.afterProgramCreate
81
-
82
- host.afterProgramCreate = async (program) => {
83
- origPostProgramCreate?.(program)
84
-
85
- const messages: ExtractorMessage[] = []
86
- const results: {sourcePath: string; filePaths: string[]}[] = []
87
-
88
- for (const entry of task.entries) {
89
- const exportPath = entry.exportPath === '.' ? './index' : entry.exportPath
90
-
91
- const sourceTypesPath = path.resolve(
92
- tmpPath,
93
- path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, '.d.ts'),
94
- )
95
-
96
- const targetPaths = entry.targetPaths.map((targetPath) => path.resolve(cwd, targetPath))
97
- const filePaths = targetPaths.map((targetPath) => path.relative(outDir, targetPath))
98
-
99
- try {
100
- const result = await extractTypes({
101
- bundledPackages: bundledPackages || [],
102
- customTags: config?.extract?.customTags,
103
- cwd,
104
- distPath: outDir,
105
- exportPath,
106
- files,
107
- filePaths,
108
- projectPath: cwd,
109
- rules: config?.extract?.rules,
110
- sourceTypesPath: sourceTypesPath,
111
- tsconfig: tsContext.config!,
112
- tmpPath,
113
- tsconfigPath: path.resolve(cwd, tsContext.configPath || 'tsconfig.json'),
114
- extractorDisabled: config?.extract?.enabled === false,
115
- })
116
-
117
- messages.push(...result.messages)
118
- results.push({sourcePath: path.resolve(cwd, entry.sourcePath), filePaths: targetPaths})
119
- } catch (err) {
120
- if (err instanceof DtsError) {
121
- messages.push(...err.messages)
122
- } else {
123
- observer.error(err)
124
-
125
- return
126
- }
127
- }
128
- }
129
-
130
- observer.next({type: 'dts', messages, results})
131
- }
132
-
133
- const watchProgram = ts.createWatchProgram(host)
134
-
135
- return () => {
136
- watchProgram.close()
137
- rimraf.sync(tmpPath)
138
- }
139
- })
140
- },
141
- complete: (ctx, task, result) => {
142
- const {logger} = ctx
143
-
144
- printExtractMessages(ctx, result.messages)
145
-
146
- logger.success(
147
- `build type definitions\n ${task.entries
148
- .map(
149
- (entry) =>
150
- ` - ${chalk.cyan(entry.importId)}: ${chalk.yellow(entry.sourcePath)} ${chalk.gray('→')} ${chalk.yellow(entry.targetPaths.join(', '))}`,
151
- )
152
- .join('\n ')}`,
153
- )
154
- logger.log('')
155
- },
156
- error: (ctx, _task, err) => {
157
- const {logger} = ctx
158
-
159
- if (err instanceof DtsError) {
160
- printExtractMessages(ctx, err.messages)
161
- } else if (err instanceof Error) {
162
- logger.error(err)
163
- }
164
- },
165
- }
@@ -1,45 +0,0 @@
1
- import type {File} from '@babel/types'
2
- import type {ExtractorResult} from '@microsoft/api-extractor'
3
- import {parse, print} from 'recast'
4
- import typeScriptParser from 'recast/parsers/typescript.js'
5
- import type {Program} from 'typescript'
6
-
7
- /**
8
- * A workaround to find all module blocks in extract TS files.
9
- * @internal
10
- * */
11
- export async function extractModuleBlocksFromTypes({
12
- tsOutDir,
13
- extractResult,
14
- }: {
15
- tsOutDir: string
16
- extractResult: ExtractorResult
17
- }): Promise<string[]> {
18
- const program = extractResult.compilerState.program as Program
19
- const moduleBlocks: string[] = []
20
-
21
- // all program files, including node_modules
22
- const allProgramFiles = [...program.getSourceFiles()]
23
-
24
- // just our compiled files used in the program
25
- const sourceFiles = allProgramFiles.filter((sourceFile) => sourceFile.fileName.includes(tsOutDir))
26
-
27
- for (const sourceFile of sourceFiles) {
28
- if (sourceFile.text.includes('declare module')) {
29
- moduleBlocks.push(...extractModuleBlocks(sourceFile.text))
30
- }
31
- }
32
-
33
- return moduleBlocks
34
- }
35
-
36
- /** @internal */
37
- export function extractModuleBlocks(fileContent: string): string[] {
38
- const ast = parse(fileContent, {
39
- parser: typeScriptParser,
40
- }) as File
41
-
42
- return ast.program.body
43
- .filter((node) => node.type === 'TSModuleDeclaration')
44
- .map((node) => print(node).code)
45
- }
@@ -1,128 +0,0 @@
1
- import fs from 'node:fs/promises'
2
- import path from 'node:path'
3
- import {
4
- Extractor,
5
- ExtractorConfig,
6
- type ExtractorMessage,
7
- type ExtractorResult,
8
- } from '@microsoft/api-extractor'
9
- import {mkdirp} from 'mkdirp'
10
- import * as prettier from 'prettier'
11
- import type ts from 'typescript'
12
- import type {PkgConfigOptions} from '../../core/config/types'
13
- import type {BuildFile} from '../../core/contexts/buildContext'
14
- import {createApiExtractorConfig} from './createApiExtractorConfig'
15
- import {createTSDocConfig} from './createTSDocConfig'
16
- import {extractModuleBlocksFromTypes} from './extractModuleBlocks'
17
- import {getExtractMessagesConfig} from './getExtractMessagesConfig'
18
-
19
- export async function extractTypes(options: {
20
- bundledPackages?: string[]
21
- customTags: NonNullable<PkgConfigOptions['extract']>['customTags']
22
- cwd: string
23
- distPath: string
24
- exportPath: string
25
- filePaths: string[]
26
- files: BuildFile[]
27
- projectPath: string
28
- rules?: NonNullable<PkgConfigOptions['extract']>['rules']
29
- sourceTypesPath: string
30
- tmpPath: string
31
- tsconfig: ts.ParsedCommandLine
32
- tsconfigPath: string
33
- /**
34
- * If the extractor is disabled then it means API Extractor is only used to bundle dts, and not check tsdoc release tags.
35
- */
36
- extractorDisabled: boolean
37
- }): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
38
- const {
39
- bundledPackages,
40
- customTags,
41
- distPath,
42
- exportPath,
43
- files,
44
- filePaths,
45
- projectPath,
46
- rules,
47
- sourceTypesPath,
48
- tmpPath,
49
- tsconfig,
50
- tsconfigPath,
51
- extractorDisabled,
52
- } = options
53
-
54
- const tsdocConfigFile = await createTSDocConfig({
55
- customTags: customTags || [],
56
- })
57
-
58
- const filePath = filePaths[0].replace(/\.d\.[mc]ts$/, '.d.ts')
59
- // If there are package.config.ts `bundles` we might not have something that should leave behind a `.d.ts` file and need to handle that
60
- const shouldCleanUpDts = !filePaths.includes(filePath)
61
- const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
62
- configObject: createApiExtractorConfig({
63
- bundledPackages,
64
- distPath,
65
- exportPath,
66
- filePath,
67
- messages: getExtractMessagesConfig({rules, disabled: extractorDisabled}),
68
- projectFolder: projectPath,
69
- mainEntryPointFilePath: sourceTypesPath,
70
- tsconfig,
71
- tsconfigPath,
72
- dtsRollupEnabled: true,
73
- }),
74
- configObjectFullPath: undefined,
75
- tsdocConfigFile,
76
- packageJsonFullPath: path.resolve(projectPath, 'package.json'),
77
- })
78
-
79
- const messages: ExtractorMessage[] = []
80
-
81
- // Invoke API Extractor
82
- const extractorResult = Extractor.invoke(extractorConfig, {
83
- // Equivalent to the "--local" command-line parameter
84
- localBuild: true,
85
- // Equivalent to the "--verbose" command-line parameter
86
- showVerboseMessages: true,
87
- // handle messages
88
- messageCallback(message: ExtractorMessage) {
89
- messages.push(message)
90
- message.handled = true
91
- },
92
- })
93
-
94
- const typesPath = path.resolve(distPath, filePath)
95
- const typesBuf = await fs.readFile(typesPath)
96
- const prettierConfig = await prettier.resolveConfig(typesPath)
97
-
98
- await mkdirp(path.dirname(typesPath))
99
-
100
- const moduleBlocks = await extractModuleBlocksFromTypes({
101
- extractResult: extractorResult,
102
- tsOutDir: tmpPath,
103
- })
104
-
105
- const code = [typesBuf.toString(), ...moduleBlocks].join('\n\n')
106
- const prettyCode = await prettier.format(code, {
107
- ...prettierConfig,
108
- filepath: typesPath,
109
- })
110
-
111
- for (const expFilePath of filePaths) {
112
- const expTypesPath = path.resolve(distPath, expFilePath)
113
-
114
- await fs.writeFile(expTypesPath, prettyCode)
115
-
116
- // Add to `files` in context
117
- files.push({
118
- type: 'types',
119
- path: expTypesPath,
120
- })
121
- }
122
-
123
- if (shouldCleanUpDts) {
124
- await fs.unlink(typesPath)
125
- }
126
-
127
- return {extractorResult, messages}
128
- }
@@ -1,109 +0,0 @@
1
- import type {ExtractorLogLevel, IExtractorMessagesConfig} from '@microsoft/api-extractor'
2
- import type {PkgConfigOptions, PkgRuleLevel} from '../../core/config/types'
3
-
4
- const LOG_LEVELS: Record<PkgRuleLevel, ExtractorLogLevel> = {
5
- error: 'error' as ExtractorLogLevel.Error,
6
- info: 'info' as ExtractorLogLevel.Info,
7
- off: 'none' as ExtractorLogLevel.None,
8
- warn: 'warning' as ExtractorLogLevel.Warning,
9
- }
10
-
11
- /** @alpha */
12
- export function getExtractMessagesConfig(options: {
13
- rules: NonNullable<PkgConfigOptions['extract']>['rules']
14
- disabled?: boolean
15
- }): IExtractorMessagesConfig {
16
- const {rules, disabled = false} = options
17
-
18
- function ruleToLogLevel(
19
- key: keyof NonNullable<NonNullable<PkgConfigOptions['extract']>['rules']>,
20
- defaultLevel?: ExtractorLogLevel,
21
- ) {
22
- const r = rules?.[key]
23
-
24
- return (r ? LOG_LEVELS[r] : defaultLevel || 'warning') as ExtractorLogLevel
25
- }
26
-
27
- return {
28
- compilerMessageReporting: {
29
- default: {
30
- logLevel: (disabled ? 'none' : 'warning') as ExtractorLogLevel,
31
- },
32
- },
33
-
34
- extractorMessageReporting: disabled
35
- ? {
36
- default: {
37
- logLevel: 'none' as ExtractorLogLevel,
38
- addToApiReportFile: false,
39
- },
40
- }
41
- : {
42
- 'default': {
43
- logLevel: 'warning' as ExtractorLogLevel,
44
- addToApiReportFile: false,
45
- },
46
-
47
- 'ae-forgotten-export': {
48
- /**
49
- * This is hardcoded to `none` as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
50
- * 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
51
- */
52
- logLevel: 'none' as ExtractorLogLevel,
53
- addToApiReportFile: false,
54
- },
55
-
56
- 'ae-incompatible-release-tags': {
57
- logLevel: ruleToLogLevel('ae-incompatible-release-tags', 'error' as ExtractorLogLevel),
58
- addToApiReportFile: false,
59
- },
60
-
61
- 'ae-internal-missing-underscore': {
62
- logLevel: ruleToLogLevel('ae-internal-missing-underscore'),
63
- addToApiReportFile: false,
64
- },
65
-
66
- 'ae-missing-release-tag': {
67
- logLevel: ruleToLogLevel('ae-missing-release-tag', 'error' as ExtractorLogLevel),
68
- addToApiReportFile: false,
69
- },
70
-
71
- 'ae-wrong-input-file-type': {
72
- logLevel: 'none' as ExtractorLogLevel,
73
- addToApiReportFile: false,
74
- },
75
- },
76
-
77
- tsdocMessageReporting: disabled
78
- ? {
79
- default: {
80
- logLevel: 'none' as ExtractorLogLevel,
81
- addToApiReportFile: false,
82
- },
83
- }
84
- : {
85
- 'default': {
86
- logLevel: 'warning' as ExtractorLogLevel,
87
- addToApiReportFile: false,
88
- },
89
-
90
- 'tsdoc-link-tag-unescaped-text': {
91
- logLevel: ruleToLogLevel(
92
- 'tsdoc-link-tag-unescaped-text',
93
- 'warning' as ExtractorLogLevel,
94
- ),
95
- addToApiReportFile: false,
96
- },
97
-
98
- 'tsdoc-undefined-tag': {
99
- logLevel: ruleToLogLevel('tsdoc-undefined-tag', 'error' as ExtractorLogLevel),
100
- addToApiReportFile: false,
101
- },
102
-
103
- 'tsdoc-unsupported-tag': {
104
- logLevel: ruleToLogLevel('tsdoc-unsupported-tag', 'none' as ExtractorLogLevel),
105
- addToApiReportFile: false,
106
- },
107
- },
108
- }
109
- }
@@ -1,72 +0,0 @@
1
- import type {PkgBundle, PkgExport} from '../../core/config/types'
2
- import type {PackageJSON} from '../../core/pkg/types'
3
-
4
- /** @internal */
5
- export const fileEnding = /\.[mc]?js$/
6
- /** @internal */
7
- export const dtsEnding = '.d.ts' as const
8
- /** @internal */
9
- export const defaultEnding = '.js' as const
10
- /** @internal */
11
- export const mjsEnding = '.mjs' as const
12
- /** @internal */
13
- export const cjsEnding = '.cjs' as const
14
- const mtsEnding = '.d.mts' as const
15
- const ctsEnding = '.d.cts' as const
16
-
17
- /** @internal */
18
- export function getTargetPaths(
19
- _type: PackageJSON['type'],
20
- expOrBundle: PkgExport | PkgExport['browser'] | PkgExport['node'] | PkgBundle,
21
- ): string[] {
22
- const type = (_type === 'module' ? 'module' : 'commonjs') satisfies PackageJSON['type']
23
-
24
- const set = new Set<string>()
25
-
26
- if (expOrBundle?.import) {
27
- set.add(expOrBundle.import.replace(fileEnding, type === 'module' ? dtsEnding : mtsEnding))
28
- }
29
-
30
- if (expOrBundle?.require) {
31
- set.add(expOrBundle.require.replace(fileEnding, type === 'commonjs' ? dtsEnding : ctsEnding))
32
- }
33
-
34
- if (isPkgExport(expOrBundle)) {
35
- if (!expOrBundle.browser?.source) {
36
- if (expOrBundle.browser?.import) {
37
- set.add(
38
- expOrBundle.browser.import.replace(fileEnding, type === 'module' ? dtsEnding : mtsEnding),
39
- )
40
- }
41
-
42
- if (expOrBundle.browser?.require) {
43
- set.add(
44
- expOrBundle.browser.require.replace(
45
- fileEnding,
46
- type === 'commonjs' ? dtsEnding : ctsEnding,
47
- ),
48
- )
49
- }
50
- }
51
-
52
- if (!expOrBundle.node?.source) {
53
- if (expOrBundle.node?.import) {
54
- set.add(
55
- expOrBundle.node.import.replace(fileEnding, type === 'module' ? dtsEnding : mtsEnding),
56
- )
57
- }
58
-
59
- if (expOrBundle.node?.require) {
60
- set.add(
61
- expOrBundle.node.require.replace(fileEnding, type === 'commonjs' ? dtsEnding : ctsEnding),
62
- )
63
- }
64
- }
65
- }
66
-
67
- return Array.from(set)
68
- }
69
-
70
- function isPkgExport(exp: any): exp is PkgExport {
71
- return exp?.browser || exp?.node || exp?.default
72
- }
@@ -1,42 +0,0 @@
1
- import path from 'node:path'
2
- import chalk from 'chalk'
3
- import ts from 'typescript'
4
- import type {Logger} from '../../logger'
5
-
6
- export function printDiagnostic(options: {
7
- cwd: string
8
- logger: Logger
9
- diagnostic: ts.Diagnostic
10
- }): void {
11
- const {cwd, logger, diagnostic} = options
12
-
13
- if (diagnostic.file && diagnostic.start) {
14
- const {line, character} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start)
15
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')
16
-
17
- const file = path.relative(cwd, diagnostic.file.fileName)
18
-
19
- const output = [
20
- `${chalk.yellow(file)}:${chalk.blue(line + 1)}:${chalk.blue(character + 1)} - `,
21
- `${chalk.gray(`TS${diagnostic.code}:`)} ${message}`,
22
- ].join('')
23
-
24
- if (diagnostic.category === ts.DiagnosticCategory.Error) {
25
- logger.error(output)
26
- }
27
-
28
- if (diagnostic.category === ts.DiagnosticCategory.Warning) {
29
- logger.warn(output)
30
- }
31
-
32
- if (diagnostic.category === ts.DiagnosticCategory.Message) {
33
- logger.log(output)
34
- }
35
-
36
- if (diagnostic.category === ts.DiagnosticCategory.Suggestion) {
37
- logger.log(output)
38
- }
39
- } else {
40
- logger.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
41
- }
42
- }
@@ -1,30 +0,0 @@
1
- import type {ExtractorMessage} from '@microsoft/api-extractor'
2
-
3
- /** @internal */
4
- export interface DtsWatchTask {
5
- type: 'watch:dts'
6
- entries: {
7
- exportPath: string
8
- importId: string
9
- sourcePath: string
10
- targetPaths: string[]
11
- }[]
12
- }
13
-
14
- /** @internal */
15
- export interface DtsTask {
16
- type: 'build:dts'
17
- entries: {
18
- exportPath: string
19
- importId: string
20
- sourcePath: string
21
- targetPaths: string[]
22
- }[]
23
- }
24
-
25
- /** @internal */
26
- export interface DtsResult {
27
- type: 'dts'
28
- messages: ExtractorMessage[]
29
- results: {sourcePath: string; filePaths: string[]}[]
30
- }
@@ -1,19 +0,0 @@
1
- import {dtsTask} from './dts/dtsTask'
2
- import {dtsWatchTask} from './dts/dtsWatchTask'
3
- import {rolldownDtsTask} from './rolldown/rolldownDtsTask'
4
- import {rollupTask} from './rollup/rollupTask'
5
- import {rollupWatchTask} from './rollup/rollupWatchTask'
6
- import type {BuildTaskHandlers, WatchTaskHandlers} from './types'
7
-
8
- /** @internal */
9
- export const buildTaskHandlers: BuildTaskHandlers = {
10
- 'build:dts': dtsTask,
11
- 'build:js': rollupTask,
12
- 'rolldown:dts': rolldownDtsTask,
13
- }
14
-
15
- /** @internal */
16
- export const watchTaskHandlers: WatchTaskHandlers = {
17
- 'watch:dts': dtsWatchTask,
18
- 'watch:js': rollupWatchTask,
19
- }