@sanity/pkg-utils 1.17.3 → 1.19.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/dist/_chunks/{build-6fac40bf.js → build-bcb33ba5.js} +19 -63
- package/dist/_chunks/build-bcb33ba5.js.map +1 -0
- package/dist/_chunks/{buildAction-ff3e6d24.js → buildAction-f240dab8.js} +8 -38
- package/dist/_chunks/buildAction-f240dab8.js.map +1 -0
- package/dist/_chunks/{check-87cbb6cc.js → check-1ea361f5.js} +26 -81
- package/dist/_chunks/check-1ea361f5.js.map +1 -0
- package/dist/_chunks/{checkAction-e7e455d4.js → checkAction-16be1201.js} +5 -22
- package/dist/_chunks/checkAction-16be1201.js.map +1 -0
- package/dist/_chunks/{_handleError-869dec25.js → handleError-65cf3242.js} +3 -8
- package/dist/_chunks/handleError-65cf3242.js.map +1 -0
- package/dist/_chunks/{index-fbba5480.js → index-79fdb33f.js} +105 -282
- package/dist/_chunks/index-79fdb33f.js.map +1 -0
- package/dist/_chunks/{_resolveBuildContext-7ca7e64e.js → resolveBuildContext-f2feec19.js} +63 -184
- package/dist/_chunks/resolveBuildContext-f2feec19.js.map +1 -0
- package/dist/_chunks/{watch-2ea1243e.js → watch-02c85f8a.js} +25 -80
- package/dist/_chunks/watch-02c85f8a.js.map +1 -0
- package/dist/_chunks/{watchAction-10e52cbc.js → watchAction-9cb9681b.js} +8 -41
- package/dist/_chunks/watchAction-9cb9681b.js.map +1 -0
- package/dist/cli.js +4 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +44 -46
- package/dist/index.esm.js +217 -560
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +24 -62
- package/dist/index.js.map +1 -1
- package/package.json +50 -1
- package/src/cli/buildAction.ts +2 -2
- package/src/cli/checkAction.ts +2 -2
- package/src/cli/{_handleError.ts → handleError.ts} +1 -1
- package/src/cli/watchAction.ts +2 -2
- package/src/node/build.ts +11 -11
- package/src/node/check.ts +11 -11
- package/src/node/{_core → core}/config/defineConfig.ts +0 -0
- package/src/node/{_core/config/_findConfigFile.ts → core/config/findConfigFile.ts} +3 -3
- package/src/node/core/config/index.ts +4 -0
- package/src/node/{_core/config/_loadConfig.ts → core/config/loadConfig.ts} +3 -3
- package/src/node/{_core/config/_resolveConfigProperty.ts → core/config/resolveConfigProperty.ts} +1 -1
- package/src/node/{_core → core}/config/types.ts +0 -0
- package/src/node/{_core/_constants.ts → core/constants.ts} +1 -1
- package/src/node/{_core → core}/contexts/buildContext.ts +5 -5
- package/src/node/{_core → core}/contexts/index.ts +0 -0
- package/src/node/core/defaults.ts +7 -0
- package/src/node/core/findCommonPath.test.ts +9 -0
- package/src/node/{_core/_findCommonPath.ts → core/findCommonPath.ts} +3 -3
- package/src/node/{_core → core}/index.ts +3 -3
- package/src/node/{_core/_isRecord.ts → core/isRecord.ts} +1 -1
- package/src/node/core/pkg/index.ts +4 -0
- package/src/node/{_core/pkg/_loadPkg.ts → core/pkg/loadPkg.ts} +4 -4
- package/src/node/{_core/pkg/_loadPkgWithReporting.ts → core/pkg/loadPkgWithReporting.ts} +6 -6
- package/src/node/{_core/pkg/_parseExports.ts → core/pkg/parseExports.ts} +7 -7
- package/src/node/{_core/pkg/_types.ts → core/pkg/types.ts} +1 -1
- package/src/node/{_core/pkg/_validateExports.ts → core/pkg/validateExports.ts} +5 -5
- package/src/node/{_core/pkg/_validatePkg.ts → core/pkg/validatePkg.ts} +2 -2
- package/src/node/core/ts/index.ts +1 -0
- package/src/node/{_core/ts/_loadTSConfig.ts → core/ts/loadTSConfig.ts} +1 -1
- package/src/node/{_getFilesize.ts → getFilesize.ts} +1 -1
- package/src/node/globFiles.ts +5 -0
- package/src/node/index.ts +3 -3
- package/src/node/{_printExtractMessages.ts → printExtractMessages.ts} +2 -2
- package/src/node/{_printPackageTree.ts → printPackageTree.ts} +17 -17
- package/src/node/{_resolveBrowserTarget.ts → resolveBrowserTarget.ts} +2 -2
- package/src/node/{_resolveBrowserslistVersions.ts → resolveBrowserslistVersions.ts} +11 -11
- package/src/node/{_resolveBuildContext.ts → resolveBuildContext.ts} +28 -28
- package/src/node/{_resolveBuildTasks.ts → resolveBuildTasks.ts} +13 -13
- package/src/node/{_resolveNodeTarget.ts → resolveNodeTarget.ts} +2 -2
- package/src/node/{_resolveWatchTasks.ts → resolveWatchTasks.ts} +11 -11
- package/src/node/{_spinner.ts → spinner.ts} +1 -1
- package/src/node/{_tasks/dts/_DtsError.ts → tasks/dts/DtsError.ts} +1 -1
- package/src/node/{_tasks/dts/_buildTypes.ts → tasks/dts/buildTypes.ts} +1 -1
- package/src/node/{_tasks/dts/_createApiExtractorConfig.ts → tasks/dts/createApiExtractorConfig.ts} +1 -1
- package/src/node/{_tasks/dts/_createTSDocConfig.ts → tasks/dts/createTSDocConfig.ts} +1 -1
- package/src/node/{_tasks/dts/_doExtract.ts → tasks/dts/doExtract.ts} +14 -20
- package/src/node/{_tasks/dts/_dtsTask.ts → tasks/dts/dtsTask.ts} +10 -10
- package/src/node/{_tasks/dts/_dtsWatchTask.ts → tasks/dts/dtsWatchTask.ts} +10 -10
- package/src/node/tasks/dts/extractModuleBlocks.ts +45 -0
- package/src/node/{_tasks/dts/_extractTypes.ts → tasks/dts/extractTypes.ts} +20 -10
- package/src/node/{_tasks/dts/_getExtractMessagesConfig.ts → tasks/dts/getExtractMessagesConfig.ts} +12 -12
- package/src/node/tasks/dts/index.ts +4 -0
- package/src/node/{_tasks/dts/_types.ts → tasks/dts/types.ts} +3 -3
- package/src/node/tasks/index.ts +19 -0
- package/src/node/tasks/rollup/index.ts +2 -0
- package/src/node/{_tasks/rollup/_resolveRollupConfig.ts → tasks/rollup/resolveRollupConfig.ts} +16 -11
- package/src/node/{_tasks/rollup/_rollupTask.ts → tasks/rollup/rollupTask.ts} +7 -7
- package/src/node/{_tasks/rollup/_rollupWatchTask.ts → tasks/rollup/rollupWatchTask.ts} +4 -4
- package/src/node/tasks/types.ts +57 -0
- package/src/node/watch.ts +13 -13
- package/src/node/{_watchConfigFiles.ts → watchConfigFiles.ts} +5 -5
- package/src/node/{_watchFiles.ts → watchFiles.ts} +5 -5
- package/dist/_chunks/_handleError-869dec25.js.map +0 -1
- package/dist/_chunks/_resolveBuildContext-7ca7e64e.js.map +0 -1
- package/dist/_chunks/build-6fac40bf.js.map +0 -1
- package/dist/_chunks/buildAction-ff3e6d24.js.map +0 -1
- package/dist/_chunks/check-87cbb6cc.js.map +0 -1
- package/dist/_chunks/checkAction-e7e455d4.js.map +0 -1
- package/dist/_chunks/index-fbba5480.js.map +0 -1
- package/dist/_chunks/watch-2ea1243e.js.map +0 -1
- package/dist/_chunks/watchAction-10e52cbc.js.map +0 -1
- package/src/node/_core/_defaults.ts +0 -9
- package/src/node/_core/_findCommonPath.test.ts +0 -9
- package/src/node/_core/config/index.ts +0 -4
- package/src/node/_core/pkg/index.ts +0 -4
- package/src/node/_core/ts/index.ts +0 -1
- package/src/node/_globFiles.ts +0 -5
- package/src/node/_tasks/_types.ts +0 -57
- package/src/node/_tasks/dts/_declareModuleFix.ts +0 -99
- package/src/node/_tasks/dts/index.ts +0 -4
- package/src/node/_tasks/index.ts +0 -19
- package/src/node/_tasks/rollup/index.ts +0 -2
|
@@ -2,12 +2,11 @@ import path from 'path'
|
|
|
2
2
|
import {promisify} from 'util'
|
|
3
3
|
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
4
4
|
import rimrafCallback from 'rimraf'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {_DtsResult, _DtsTask, _DtsWatchTask} from './_types'
|
|
5
|
+
import {BuildContext} from '../../core'
|
|
6
|
+
import {buildTypes} from './buildTypes'
|
|
7
|
+
import {DtsError} from './DtsError'
|
|
8
|
+
import {extractTypes} from './extractTypes'
|
|
9
|
+
import {DtsResult, DtsTask, DtsWatchTask} from './types'
|
|
11
10
|
|
|
12
11
|
const rimraf = promisify(rimrafCallback)
|
|
13
12
|
|
|
@@ -16,10 +15,10 @@ const rimraf = promisify(rimrafCallback)
|
|
|
16
15
|
* - Create a type definition bundle for each export entry.
|
|
17
16
|
* - When done, remove the temporary directory.
|
|
18
17
|
*/
|
|
19
|
-
export async function
|
|
20
|
-
ctx:
|
|
21
|
-
task:
|
|
22
|
-
): Promise<
|
|
18
|
+
export async function doExtract(
|
|
19
|
+
ctx: BuildContext,
|
|
20
|
+
task: DtsTask | DtsWatchTask
|
|
21
|
+
): Promise<DtsResult> {
|
|
23
22
|
const {config, cwd, files, strict, ts} = ctx
|
|
24
23
|
|
|
25
24
|
if (!ts.config || !ts.configPath) {
|
|
@@ -34,7 +33,7 @@ export async function _doExtract(
|
|
|
34
33
|
|
|
35
34
|
const tmpPath = path.resolve(outDir, '__tmp__')
|
|
36
35
|
|
|
37
|
-
await
|
|
36
|
+
await buildTypes({cwd, outDir: tmpPath, strict, tsconfig: ts.config})
|
|
38
37
|
const messages: ExtractorMessage[] = []
|
|
39
38
|
|
|
40
39
|
const results: {sourcePath: string; filePath: string}[] = []
|
|
@@ -49,23 +48,18 @@ export async function _doExtract(
|
|
|
49
48
|
|
|
50
49
|
const targetPath = path.resolve(cwd, entry.targetPath)
|
|
51
50
|
const filePath = path.relative(outDir, targetPath)
|
|
52
|
-
const result = await
|
|
51
|
+
const result = await extractTypes({
|
|
53
52
|
customTags: config?.extract?.customTags,
|
|
54
53
|
cwd,
|
|
54
|
+
distPath: outDir,
|
|
55
55
|
exportPath,
|
|
56
56
|
files,
|
|
57
57
|
filePath: filePath,
|
|
58
58
|
projectPath: cwd,
|
|
59
59
|
rules: config?.extract?.rules,
|
|
60
60
|
sourceTypesPath: sourceTypesPath,
|
|
61
|
+
tmpPath,
|
|
61
62
|
tsconfigPath: path.resolve(cwd, ts.configPath || 'tsconfig.json'),
|
|
62
|
-
distPath: outDir,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
await _appendModuleBlocks({
|
|
66
|
-
tsOutDir: tmpPath,
|
|
67
|
-
extractResult: result.extractorResult,
|
|
68
|
-
extractTypesOutFile: path.resolve(outDir, targetPath),
|
|
69
63
|
})
|
|
70
64
|
|
|
71
65
|
messages.push(...result.messages)
|
|
@@ -73,7 +67,7 @@ export async function _doExtract(
|
|
|
73
67
|
if (result.messages.some((msg) => msg.logLevel === 'error')) {
|
|
74
68
|
await rimraf(tmpPath)
|
|
75
69
|
|
|
76
|
-
throw new
|
|
70
|
+
throw new DtsError('encountered errors when extracting types', result.messages)
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
results.push({sourcePath: path.resolve(cwd, entry.sourcePath), filePath: targetPath})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import {Observable} from 'rxjs'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import {printExtractMessages} from '../../printExtractMessages'
|
|
4
|
+
import {TaskHandler} from '../types'
|
|
5
|
+
import {doExtract} from './doExtract'
|
|
6
|
+
import {DtsError} from './DtsError'
|
|
7
|
+
import {DtsResult, DtsTask} from './types'
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
|
-
export const
|
|
10
|
+
export const dtsTask: TaskHandler<DtsTask, DtsResult> = {
|
|
11
11
|
name: (_ctx, task) =>
|
|
12
12
|
[
|
|
13
13
|
`build type definitions`,
|
|
@@ -18,7 +18,7 @@ export const _dtsTask: _TaskHandler<_DtsTask, _DtsResult> = {
|
|
|
18
18
|
].join('\n'),
|
|
19
19
|
exec: (ctx, task) => {
|
|
20
20
|
return new Observable((observer) => {
|
|
21
|
-
|
|
21
|
+
doExtract(ctx, task)
|
|
22
22
|
.then((result) => {
|
|
23
23
|
observer.next(result)
|
|
24
24
|
observer.complete()
|
|
@@ -29,13 +29,13 @@ export const _dtsTask: _TaskHandler<_DtsTask, _DtsResult> = {
|
|
|
29
29
|
})
|
|
30
30
|
},
|
|
31
31
|
complete: (ctx, _task, result) => {
|
|
32
|
-
|
|
32
|
+
printExtractMessages(ctx, result.messages)
|
|
33
33
|
},
|
|
34
34
|
error: (ctx, _task, err) => {
|
|
35
35
|
const {logger} = ctx
|
|
36
36
|
|
|
37
|
-
if (err instanceof
|
|
38
|
-
|
|
37
|
+
if (err instanceof DtsError) {
|
|
38
|
+
printExtractMessages(ctx, err.messages)
|
|
39
39
|
} else if (err instanceof Error) {
|
|
40
40
|
logger.error(err)
|
|
41
41
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import {Observable} from 'rxjs'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import {printExtractMessages} from '../../printExtractMessages'
|
|
4
|
+
import {TaskHandler} from '../types'
|
|
5
|
+
import {doExtract} from './doExtract'
|
|
6
|
+
import {DtsError} from './DtsError'
|
|
7
|
+
import {DtsResult, DtsWatchTask} from './types'
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
|
-
export const
|
|
10
|
+
export const dtsWatchTask: TaskHandler<DtsWatchTask, DtsResult> = {
|
|
11
11
|
name: (_ctx, task) =>
|
|
12
12
|
[
|
|
13
13
|
`build type definitions`,
|
|
@@ -18,7 +18,7 @@ export const _dtsWatchTask: _TaskHandler<_DtsWatchTask, _DtsResult> = {
|
|
|
18
18
|
].join('\n'),
|
|
19
19
|
exec: (ctx, task) => {
|
|
20
20
|
return new Observable((observer) => {
|
|
21
|
-
|
|
21
|
+
doExtract(ctx, task)
|
|
22
22
|
.then((result) => {
|
|
23
23
|
observer.next(result)
|
|
24
24
|
observer.complete()
|
|
@@ -29,7 +29,7 @@ export const _dtsWatchTask: _TaskHandler<_DtsWatchTask, _DtsResult> = {
|
|
|
29
29
|
complete: (ctx, _task, result) => {
|
|
30
30
|
const {logger} = ctx
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
printExtractMessages(ctx, result.messages)
|
|
33
33
|
|
|
34
34
|
logger.warn('watching typescript definitions is currently not supported')
|
|
35
35
|
logger.log()
|
|
@@ -37,8 +37,8 @@ export const _dtsWatchTask: _TaskHandler<_DtsWatchTask, _DtsResult> = {
|
|
|
37
37
|
error: (ctx, _task, err) => {
|
|
38
38
|
const {logger} = ctx
|
|
39
39
|
|
|
40
|
-
if (err instanceof
|
|
41
|
-
|
|
40
|
+
if (err instanceof DtsError) {
|
|
41
|
+
printExtractMessages(ctx, err.messages)
|
|
42
42
|
} else if (err instanceof Error) {
|
|
43
43
|
logger.error(err)
|
|
44
44
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {File} from '@babel/types'
|
|
2
|
+
import {ExtractorResult} from '@microsoft/api-extractor'
|
|
3
|
+
import {parse, print} from 'recast'
|
|
4
|
+
import typeScriptParser from 'recast/parsers/typescript'
|
|
5
|
+
import {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
|
+
}
|
|
@@ -8,21 +8,23 @@ import {
|
|
|
8
8
|
} from '@microsoft/api-extractor'
|
|
9
9
|
import mkdirp from 'mkdirp'
|
|
10
10
|
import prettier from 'prettier'
|
|
11
|
-
import {PkgConfigOptions,
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
11
|
+
import {PkgConfigOptions, BuildFile} from '../../core'
|
|
12
|
+
import {createApiExtractorConfig} from './createApiExtractorConfig'
|
|
13
|
+
import {createTSDocConfig} from './createTSDocConfig'
|
|
14
|
+
import {extractModuleBlocksFromTypes} from './extractModuleBlocks'
|
|
15
|
+
import {getExtractMessagesConfig} from './getExtractMessagesConfig'
|
|
15
16
|
|
|
16
|
-
export async function
|
|
17
|
+
export async function extractTypes(options: {
|
|
17
18
|
customTags: NonNullable<PkgConfigOptions['extract']>['customTags']
|
|
18
19
|
cwd: string
|
|
19
20
|
distPath: string
|
|
20
21
|
exportPath: string
|
|
21
22
|
filePath: string
|
|
22
|
-
files:
|
|
23
|
+
files: BuildFile[]
|
|
23
24
|
projectPath: string
|
|
24
25
|
rules?: NonNullable<PkgConfigOptions['extract']>['rules']
|
|
25
26
|
sourceTypesPath: string
|
|
27
|
+
tmpPath: string
|
|
26
28
|
tsconfigPath: string
|
|
27
29
|
}): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
|
|
28
30
|
const {
|
|
@@ -34,19 +36,20 @@ export async function _extractTypes(options: {
|
|
|
34
36
|
projectPath,
|
|
35
37
|
rules,
|
|
36
38
|
sourceTypesPath,
|
|
39
|
+
tmpPath,
|
|
37
40
|
tsconfigPath,
|
|
38
41
|
} = options
|
|
39
42
|
|
|
40
|
-
const tsdocConfigFile = await
|
|
43
|
+
const tsdocConfigFile = await createTSDocConfig({
|
|
41
44
|
customTags: customTags || [],
|
|
42
45
|
})
|
|
43
46
|
|
|
44
47
|
const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
|
|
45
|
-
configObject:
|
|
48
|
+
configObject: createApiExtractorConfig({
|
|
46
49
|
distPath,
|
|
47
50
|
exportPath,
|
|
48
51
|
filePath,
|
|
49
|
-
messages:
|
|
52
|
+
messages: getExtractMessagesConfig({rules}),
|
|
50
53
|
projectFolder: projectPath,
|
|
51
54
|
mainEntryPointFilePath: sourceTypesPath,
|
|
52
55
|
tsconfigPath,
|
|
@@ -77,9 +80,16 @@ export async function _extractTypes(options: {
|
|
|
77
80
|
|
|
78
81
|
await mkdirp(path.dirname(typesPath))
|
|
79
82
|
|
|
83
|
+
const moduleBlocks = await extractModuleBlocksFromTypes({
|
|
84
|
+
extractResult: extractorResult,
|
|
85
|
+
tsOutDir: tmpPath,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const code = [typesBuf.toString(), ...moduleBlocks].join('\n\n')
|
|
89
|
+
|
|
80
90
|
await fs.writeFile(
|
|
81
91
|
typesPath,
|
|
82
|
-
prettier.format(
|
|
92
|
+
prettier.format(code, {
|
|
83
93
|
...prettierConfig,
|
|
84
94
|
filepath: typesPath,
|
|
85
95
|
})
|
package/src/node/{_tasks/dts/_getExtractMessagesConfig.ts → tasks/dts/getExtractMessagesConfig.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ExtractorLogLevel, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
2
|
-
import {PkgRuleLevel, PkgConfigOptions} from '../../
|
|
2
|
+
import {PkgRuleLevel, PkgConfigOptions} from '../../core'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const LOG_LEVELS: Record<PkgRuleLevel, ExtractorLogLevel> = {
|
|
5
5
|
error: 'error' as ExtractorLogLevel.Error,
|
|
6
6
|
info: 'info' as ExtractorLogLevel.Info,
|
|
7
7
|
off: 'none' as ExtractorLogLevel.None,
|
|
@@ -9,18 +9,18 @@ const _LOG_LEVELS: Record<PkgRuleLevel, ExtractorLogLevel> = {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
|
-
export function
|
|
12
|
+
export function getExtractMessagesConfig(options: {
|
|
13
13
|
rules: NonNullable<PkgConfigOptions['extract']>['rules']
|
|
14
14
|
}): IExtractorMessagesConfig {
|
|
15
15
|
const {rules} = options
|
|
16
16
|
|
|
17
|
-
function
|
|
17
|
+
function ruleToLogLevel(
|
|
18
18
|
key: keyof NonNullable<NonNullable<PkgConfigOptions['extract']>['rules']>,
|
|
19
19
|
defaultLevel?: ExtractorLogLevel
|
|
20
20
|
) {
|
|
21
21
|
const r = rules?.[key]
|
|
22
22
|
|
|
23
|
-
return (r ?
|
|
23
|
+
return (r ? LOG_LEVELS[r] : defaultLevel || 'warning') as ExtractorLogLevel
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return {
|
|
@@ -37,22 +37,22 @@ export function _getExtractMessagesConfig(options: {
|
|
|
37
37
|
},
|
|
38
38
|
|
|
39
39
|
'ae-forgotten-export': {
|
|
40
|
-
logLevel:
|
|
40
|
+
logLevel: ruleToLogLevel('ae-forgotten-export', 'error' as ExtractorLogLevel),
|
|
41
41
|
addToApiReportFile: false,
|
|
42
42
|
},
|
|
43
43
|
|
|
44
44
|
'ae-incompatible-release-tags': {
|
|
45
|
-
logLevel:
|
|
45
|
+
logLevel: ruleToLogLevel('ae-incompatible-release-tags', 'error' as ExtractorLogLevel),
|
|
46
46
|
addToApiReportFile: false,
|
|
47
47
|
},
|
|
48
48
|
|
|
49
49
|
'ae-internal-missing-underscore': {
|
|
50
|
-
logLevel:
|
|
50
|
+
logLevel: ruleToLogLevel('ae-internal-missing-underscore'),
|
|
51
51
|
addToApiReportFile: false,
|
|
52
52
|
},
|
|
53
53
|
|
|
54
54
|
'ae-missing-release-tag': {
|
|
55
|
-
logLevel:
|
|
55
|
+
logLevel: ruleToLogLevel('ae-missing-release-tag', 'error' as ExtractorLogLevel),
|
|
56
56
|
addToApiReportFile: false,
|
|
57
57
|
},
|
|
58
58
|
|
|
@@ -69,17 +69,17 @@ export function _getExtractMessagesConfig(options: {
|
|
|
69
69
|
},
|
|
70
70
|
|
|
71
71
|
'tsdoc-link-tag-unescaped-text': {
|
|
72
|
-
logLevel:
|
|
72
|
+
logLevel: ruleToLogLevel('tsdoc-link-tag-unescaped-text', 'warning' as ExtractorLogLevel),
|
|
73
73
|
addToApiReportFile: false,
|
|
74
74
|
},
|
|
75
75
|
|
|
76
76
|
'tsdoc-undefined-tag': {
|
|
77
|
-
logLevel:
|
|
77
|
+
logLevel: ruleToLogLevel('tsdoc-undefined-tag', 'error' as ExtractorLogLevel),
|
|
78
78
|
addToApiReportFile: false,
|
|
79
79
|
},
|
|
80
80
|
|
|
81
81
|
'tsdoc-unsupported-tag': {
|
|
82
|
-
logLevel:
|
|
82
|
+
logLevel: ruleToLogLevel('tsdoc-unsupported-tag', 'none' as ExtractorLogLevel),
|
|
83
83
|
addToApiReportFile: false,
|
|
84
84
|
},
|
|
85
85
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
2
2
|
|
|
3
3
|
/** @internal */
|
|
4
|
-
export interface
|
|
4
|
+
export interface DtsWatchTask {
|
|
5
5
|
type: 'watch:dts'
|
|
6
6
|
entries: {
|
|
7
7
|
exportPath: string
|
|
@@ -12,7 +12,7 @@ export interface _DtsWatchTask {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** @internal */
|
|
15
|
-
export interface
|
|
15
|
+
export interface DtsTask {
|
|
16
16
|
type: 'build:dts'
|
|
17
17
|
entries: {
|
|
18
18
|
exportPath: string
|
|
@@ -23,7 +23,7 @@ export interface _DtsTask {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** @internal */
|
|
26
|
-
export interface
|
|
26
|
+
export interface DtsResult {
|
|
27
27
|
type: 'dts'
|
|
28
28
|
messages: ExtractorMessage[]
|
|
29
29
|
results: {sourcePath: string; filePath: string}[]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {dtsTask, dtsWatchTask} from './dts'
|
|
2
|
+
import {rollupTask, rollupWatchTask} from './rollup'
|
|
3
|
+
import {BuildTaskHandlers, WatchTaskHandlers} from './types'
|
|
4
|
+
|
|
5
|
+
export * from './types'
|
|
6
|
+
export * from './dts'
|
|
7
|
+
export * from './rollup'
|
|
8
|
+
|
|
9
|
+
/** @internal */
|
|
10
|
+
export const buildTaskHandlers: BuildTaskHandlers = {
|
|
11
|
+
'build:dts': dtsTask,
|
|
12
|
+
'build:js': rollupTask,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
export const watchTaskHandlers: WatchTaskHandlers = {
|
|
17
|
+
'watch:dts': dtsWatchTask,
|
|
18
|
+
'watch:js': rollupWatchTask,
|
|
19
|
+
}
|
package/src/node/{_tasks/rollup/_resolveRollupConfig.ts → tasks/rollup/resolveRollupConfig.ts}
RENAMED
|
@@ -8,22 +8,27 @@ import replace from '@rollup/plugin-replace'
|
|
|
8
8
|
import {InputOptions, OutputOptions, Plugin} from 'rollup'
|
|
9
9
|
import esbuild from 'rollup-plugin-esbuild'
|
|
10
10
|
import {terser} from 'rollup-plugin-terser'
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
import {
|
|
12
|
+
BuildContext,
|
|
13
|
+
DEFAULT_BROWSERSLIST_QUERY,
|
|
14
|
+
MODULE_EXT,
|
|
15
|
+
resolveConfigProperty,
|
|
16
|
+
} from '../../core'
|
|
17
|
+
import {RollupTask, RollupWatchTask} from '../types'
|
|
18
|
+
|
|
19
|
+
export interface RollupConfig {
|
|
15
20
|
inputOptions: InputOptions
|
|
16
21
|
outputOptions: OutputOptions
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
/** @internal */
|
|
20
|
-
export function
|
|
21
|
-
ctx:
|
|
22
|
-
buildTask:
|
|
23
|
-
):
|
|
25
|
+
export function resolveRollupConfig(
|
|
26
|
+
ctx: BuildContext,
|
|
27
|
+
buildTask: RollupTask | RollupWatchTask
|
|
28
|
+
): RollupConfig {
|
|
24
29
|
const {format, runtime, target} = buildTask
|
|
25
30
|
const {config, cwd, exports: _exports, external, distPath, logger, pkg, ts} = ctx
|
|
26
|
-
const outputExt =
|
|
31
|
+
const outputExt = MODULE_EXT[pkg.type][format]
|
|
27
32
|
const minify = config?.minify ?? true
|
|
28
33
|
const outDir = path.relative(cwd, distPath)
|
|
29
34
|
|
|
@@ -106,7 +111,7 @@ export function _resolveRollupConfig(
|
|
|
106
111
|
getBabelOutputPlugin({
|
|
107
112
|
babelrc: false,
|
|
108
113
|
plugins: ['@babel/plugin-proposal-object-rest-spread'],
|
|
109
|
-
presets: [['@babel/preset-env', {targets: pkg.browserslist ||
|
|
114
|
+
presets: [['@babel/preset-env', {targets: pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY}]],
|
|
110
115
|
}),
|
|
111
116
|
minify &&
|
|
112
117
|
terser({
|
|
@@ -131,7 +136,7 @@ export function _resolveRollupConfig(
|
|
|
131
136
|
|
|
132
137
|
const plugins = Array.isArray(userPlugins)
|
|
133
138
|
? defaultPlugins.concat(userPlugins)
|
|
134
|
-
:
|
|
139
|
+
: resolveConfigProperty(config?.rollup?.plugins, defaultPlugins)
|
|
135
140
|
|
|
136
141
|
return {
|
|
137
142
|
inputOptions: {
|
|
@@ -4,12 +4,12 @@ import path from 'path'
|
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
import {rollup} from 'rollup'
|
|
6
6
|
import {Observable} from 'rxjs'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import {BuildContext} from '../../core'
|
|
8
|
+
import {RollupTask, TaskHandler} from '../types'
|
|
9
|
+
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
|
-
export const
|
|
12
|
+
export const rollupTask: TaskHandler<RollupTask> = {
|
|
13
13
|
name: (ctx, task) =>
|
|
14
14
|
`build javascript files (target ${task.target.join(' + ')}, format ${
|
|
15
15
|
task.format
|
|
@@ -18,7 +18,7 @@ export const _rollupTask: _TaskHandler<_RollupTask> = {
|
|
|
18
18
|
.join('\n ')}`,
|
|
19
19
|
exec: (ctx, task) => {
|
|
20
20
|
return new Observable((observer) => {
|
|
21
|
-
|
|
21
|
+
execPromise(ctx, task)
|
|
22
22
|
.then((result) => {
|
|
23
23
|
observer.next(result)
|
|
24
24
|
observer.complete()
|
|
@@ -36,11 +36,11 @@ export const _rollupTask: _TaskHandler<_RollupTask> = {
|
|
|
36
36
|
},
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async function
|
|
39
|
+
async function execPromise(ctx: BuildContext, task: RollupTask) {
|
|
40
40
|
const {files, distPath} = ctx
|
|
41
41
|
const outDir = path.relative(ctx.cwd, distPath)
|
|
42
42
|
|
|
43
|
-
const {inputOptions, outputOptions} =
|
|
43
|
+
const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
|
|
44
44
|
|
|
45
45
|
// Create bundle
|
|
46
46
|
const bundle = await rollup(inputOptions)
|
|
@@ -2,11 +2,11 @@ import path from 'path'
|
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import {RollupWatcherEvent, RollupWatchOptions, watch as rollupWatch} from 'rollup'
|
|
4
4
|
import {Observable} from 'rxjs'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import {RollupWatchTask, TaskHandler} from '../types'
|
|
6
|
+
import {resolveRollupConfig} from './resolveRollupConfig'
|
|
7
7
|
|
|
8
8
|
/** @internal */
|
|
9
|
-
export const
|
|
9
|
+
export const rollupWatchTask: TaskHandler<RollupWatchTask, RollupWatcherEvent> = {
|
|
10
10
|
name: (ctx, task) =>
|
|
11
11
|
`build javascript files (target ${task.target.join(' + ')}, format ${
|
|
12
12
|
task.format
|
|
@@ -14,7 +14,7 @@ export const _rollupWatchTask: _TaskHandler<_RollupWatchTask, RollupWatcherEvent
|
|
|
14
14
|
.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`)
|
|
15
15
|
.join('\n ')}`,
|
|
16
16
|
exec: (ctx, task) => {
|
|
17
|
-
const {inputOptions, outputOptions} =
|
|
17
|
+
const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
|
|
18
18
|
|
|
19
19
|
return new Observable((observer) => {
|
|
20
20
|
const watchOptions: RollupWatchOptions = {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {RollupWatcherEvent} from 'rollup'
|
|
2
|
+
import {Observable} from 'rxjs'
|
|
3
|
+
import {PkgRuntime, BuildContext} from '../core'
|
|
4
|
+
import {DtsResult, DtsTask, DtsWatchTask} from './dts'
|
|
5
|
+
|
|
6
|
+
/** @internal */
|
|
7
|
+
export interface RollupTaskEntry {
|
|
8
|
+
path: string
|
|
9
|
+
source: string
|
|
10
|
+
output: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export interface RollupTask {
|
|
15
|
+
type: 'build:js'
|
|
16
|
+
buildId: string
|
|
17
|
+
entries: RollupTaskEntry[]
|
|
18
|
+
runtime: PkgRuntime
|
|
19
|
+
format: 'commonjs' | 'esm'
|
|
20
|
+
target: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
export interface RollupWatchTask {
|
|
25
|
+
type: 'watch:js'
|
|
26
|
+
buildId: string
|
|
27
|
+
entries: RollupTaskEntry[]
|
|
28
|
+
runtime: PkgRuntime
|
|
29
|
+
format: 'commonjs' | 'esm'
|
|
30
|
+
target: string[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @internal */
|
|
34
|
+
export type BuildTask = DtsTask | RollupTask
|
|
35
|
+
|
|
36
|
+
/** @internal */
|
|
37
|
+
export type WatchTask = DtsWatchTask | RollupWatchTask
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
export type TaskHandler<Task, Result = void> = {
|
|
41
|
+
name: (ctx: BuildContext, task: Task) => string
|
|
42
|
+
exec: (ctx: BuildContext, task: Task) => Observable<Result>
|
|
43
|
+
complete: (ctx: BuildContext, task: Task, result: Result) => void
|
|
44
|
+
error: (ctx: BuildContext, task: Task, error: unknown) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @internal */
|
|
48
|
+
export interface BuildTaskHandlers {
|
|
49
|
+
'build:dts': TaskHandler<DtsTask, DtsResult>
|
|
50
|
+
'build:js': TaskHandler<RollupTask>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @internal */
|
|
54
|
+
export interface WatchTaskHandlers {
|
|
55
|
+
'watch:dts': TaskHandler<DtsWatchTask, DtsResult>
|
|
56
|
+
'watch:js': TaskHandler<RollupWatchTask, RollupWatcherEvent>
|
|
57
|
+
}
|
package/src/node/watch.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import {switchMap} from 'rxjs'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import {loadConfig, loadPkgWithReporting} from './core'
|
|
4
|
+
import {resolveBuildContext} from './resolveBuildContext'
|
|
5
|
+
import {resolveWatchTasks} from './resolveWatchTasks'
|
|
6
|
+
import {WatchTask, TaskHandler, watchTaskHandlers} from './tasks'
|
|
7
|
+
import {watchConfigFiles} from './watchConfigFiles'
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
10
|
export async function watch(options: {
|
|
@@ -14,31 +14,31 @@ export async function watch(options: {
|
|
|
14
14
|
}): Promise<void> {
|
|
15
15
|
const {cwd, strict = false, tsconfig: tsconfigOption} = options
|
|
16
16
|
|
|
17
|
-
const configFiles$ = await
|
|
17
|
+
const configFiles$ = await watchConfigFiles({cwd})
|
|
18
18
|
|
|
19
19
|
const ctx$ = configFiles$.pipe(
|
|
20
20
|
switchMap(async (configFiles) => {
|
|
21
|
-
const
|
|
21
|
+
const files = configFiles.map((f) => path.relative(cwd, f))
|
|
22
22
|
|
|
23
|
-
const packageJsonPath =
|
|
23
|
+
const packageJsonPath = files.find((f) => f === 'package.json')
|
|
24
24
|
|
|
25
25
|
if (!packageJsonPath) {
|
|
26
26
|
throw new Error('missing package.json')
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const pkg = await
|
|
30
|
-
const config = await
|
|
29
|
+
const pkg = await loadPkgWithReporting({cwd})
|
|
30
|
+
const config = await loadConfig({cwd})
|
|
31
31
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
32
32
|
|
|
33
|
-
return
|
|
33
|
+
return resolveBuildContext({config, cwd, pkg, strict, tsconfig})
|
|
34
34
|
})
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
ctx$.subscribe(async (ctx) => {
|
|
38
|
-
const watchTasks =
|
|
38
|
+
const watchTasks = resolveWatchTasks(ctx)
|
|
39
39
|
|
|
40
40
|
for (const task of watchTasks) {
|
|
41
|
-
const handler =
|
|
41
|
+
const handler = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>
|
|
42
42
|
const result$ = handler.exec(ctx, task)
|
|
43
43
|
|
|
44
44
|
result$.subscribe({
|