@sanity/pkg-utils 1.18.0 → 1.20.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/browserslist.js +15 -0
- package/dist/_chunks/{build-f39a3550.js → build-bcb33ba5.js} +19 -19
- package/dist/_chunks/build-bcb33ba5.js.map +1 -0
- package/dist/_chunks/{buildAction-8f449d1d.js → buildAction-f240dab8.js} +6 -6
- package/dist/_chunks/buildAction-f240dab8.js.map +1 -0
- package/dist/_chunks/{check-87cbb6cc.js → check-1ea361f5.js} +26 -26
- package/dist/_chunks/check-1ea361f5.js.map +1 -0
- package/dist/_chunks/{checkAction-e7e455d4.js → checkAction-16be1201.js} +5 -5
- package/dist/_chunks/checkAction-16be1201.js.map +1 -0
- package/dist/_chunks/{_handleError-869dec25.js → handleError-65cf3242.js} +3 -3
- package/dist/_chunks/handleError-65cf3242.js.map +1 -0
- package/dist/_chunks/{index-7a851efa.js → index-79fdb33f.js} +63 -63
- package/dist/_chunks/index-79fdb33f.js.map +1 -0
- package/dist/_chunks/{_resolveBuildContext-7ca7e64e.js → resolveBuildContext-f2feec19.js} +60 -62
- package/dist/_chunks/resolveBuildContext-f2feec19.js.map +1 -0
- package/dist/_chunks/{watch-f6cf9246.js → watch-02c85f8a.js} +25 -25
- package/dist/_chunks/watch-02c85f8a.js.map +1 -0
- package/dist/_chunks/{watchAction-4cf253a0.js → watchAction-9cb9681b.js} +6 -6
- package/dist/_chunks/watchAction-9cb9681b.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.d.ts +44 -46
- package/dist/index.esm.js +165 -167
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +22 -22
- package/dist/index.js.map +1 -1
- package/package.json +49 -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} +12 -12
- 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 → tasks/dts/extractModuleBlocks.ts} +3 -3
- package/src/node/{_tasks/dts/_extractTypes.ts → tasks/dts/extractTypes.ts} +11 -11
- 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-f39a3550.js.map +0 -1
- package/dist/_chunks/buildAction-8f449d1d.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-7a851efa.js.map +0 -1
- package/dist/_chunks/watch-f6cf9246.js.map +0 -1
- package/dist/_chunks/watchAction-4cf253a0.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/index.ts +0 -4
- package/src/node/_tasks/index.ts +0 -19
- package/src/node/_tasks/rollup/index.ts +0 -2
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ import {Program} from 'typescript'
|
|
|
8
8
|
* A workaround to find all module blocks in extract TS files.
|
|
9
9
|
* @internal
|
|
10
10
|
* */
|
|
11
|
-
export async function
|
|
11
|
+
export async function extractModuleBlocksFromTypes({
|
|
12
12
|
tsOutDir,
|
|
13
13
|
extractResult,
|
|
14
14
|
}: {
|
|
@@ -26,7 +26,7 @@ export async function _extractModuleBlocksFromTypes({
|
|
|
26
26
|
|
|
27
27
|
for (const sourceFile of sourceFiles) {
|
|
28
28
|
if (sourceFile.text.includes('declare module')) {
|
|
29
|
-
moduleBlocks.push(...
|
|
29
|
+
moduleBlocks.push(...extractModuleBlocks(sourceFile.text))
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ export async function _extractModuleBlocksFromTypes({
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** @internal */
|
|
37
|
-
export function
|
|
37
|
+
export function extractModuleBlocks(fileContent: string): string[] {
|
|
38
38
|
const ast = parse(fileContent, {
|
|
39
39
|
parser: typeScriptParser,
|
|
40
40
|
}) as File
|
|
@@ -8,19 +8,19 @@ 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 {
|
|
15
|
-
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'
|
|
16
16
|
|
|
17
|
-
export async function
|
|
17
|
+
export async function extractTypes(options: {
|
|
18
18
|
customTags: NonNullable<PkgConfigOptions['extract']>['customTags']
|
|
19
19
|
cwd: string
|
|
20
20
|
distPath: string
|
|
21
21
|
exportPath: string
|
|
22
22
|
filePath: string
|
|
23
|
-
files:
|
|
23
|
+
files: BuildFile[]
|
|
24
24
|
projectPath: string
|
|
25
25
|
rules?: NonNullable<PkgConfigOptions['extract']>['rules']
|
|
26
26
|
sourceTypesPath: string
|
|
@@ -40,16 +40,16 @@ export async function _extractTypes(options: {
|
|
|
40
40
|
tsconfigPath,
|
|
41
41
|
} = options
|
|
42
42
|
|
|
43
|
-
const tsdocConfigFile = await
|
|
43
|
+
const tsdocConfigFile = await createTSDocConfig({
|
|
44
44
|
customTags: customTags || [],
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
|
|
48
|
-
configObject:
|
|
48
|
+
configObject: createApiExtractorConfig({
|
|
49
49
|
distPath,
|
|
50
50
|
exportPath,
|
|
51
51
|
filePath,
|
|
52
|
-
messages:
|
|
52
|
+
messages: getExtractMessagesConfig({rules}),
|
|
53
53
|
projectFolder: projectPath,
|
|
54
54
|
mainEntryPointFilePath: sourceTypesPath,
|
|
55
55
|
tsconfigPath,
|
|
@@ -80,7 +80,7 @@ export async function _extractTypes(options: {
|
|
|
80
80
|
|
|
81
81
|
await mkdirp(path.dirname(typesPath))
|
|
82
82
|
|
|
83
|
-
const moduleBlocks = await
|
|
83
|
+
const moduleBlocks = await extractModuleBlocksFromTypes({
|
|
84
84
|
extractResult: extractorResult,
|
|
85
85
|
tsOutDir: tmpPath,
|
|
86
86
|
})
|
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({
|
|
@@ -2,20 +2,20 @@ import path from 'path'
|
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import {Observable} from 'rxjs'
|
|
4
4
|
import {distinctUntilChanged, scan, startWith} from 'rxjs/operators'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import {globFiles} from './globFiles'
|
|
6
|
+
import {watchFiles} from './watchFiles'
|
|
7
7
|
|
|
8
|
-
export async function
|
|
8
|
+
export async function watchConfigFiles(options: {cwd: string}): Promise<Observable<string[]>> {
|
|
9
9
|
const {cwd} = options
|
|
10
10
|
|
|
11
|
-
const initialFiles = await
|
|
11
|
+
const initialFiles = await globFiles([
|
|
12
12
|
path.resolve(cwd, 'package.json'),
|
|
13
13
|
path.resolve(cwd, 'package.config.cjs'),
|
|
14
14
|
path.resolve(cwd, 'package.config.js'),
|
|
15
15
|
path.resolve(cwd, 'package.config.ts'),
|
|
16
16
|
])
|
|
17
17
|
|
|
18
|
-
const fileEvent$ =
|
|
18
|
+
const fileEvent$ = watchFiles([
|
|
19
19
|
path.resolve(cwd, 'package.json'),
|
|
20
20
|
path.resolve(cwd, 'package.config.cjs'),
|
|
21
21
|
path.resolve(cwd, 'package.config.js'),
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import chokidar from 'chokidar'
|
|
2
2
|
import {Observable} from 'rxjs'
|
|
3
3
|
|
|
4
|
-
export interface
|
|
4
|
+
export interface FileEvent {
|
|
5
5
|
type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'
|
|
6
6
|
file: string
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export function
|
|
9
|
+
export function watchFiles(patterns: string[]): Observable<FileEvent> {
|
|
10
10
|
return new Observable((observer) => {
|
|
11
11
|
const watcher = chokidar.watch(patterns, {
|
|
12
12
|
ignoreInitial: true,
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function handleFileEvent(
|
|
16
16
|
type: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',
|
|
17
17
|
file: string
|
|
18
18
|
) {
|
|
19
19
|
observer.next({type, file})
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
watcher.on('all',
|
|
22
|
+
watcher.on('all', handleFileEvent)
|
|
23
23
|
|
|
24
24
|
return () => {
|
|
25
|
-
watcher.off('all',
|
|
25
|
+
watcher.off('all', handleFileEvent)
|
|
26
26
|
watcher.close()
|
|
27
27
|
}
|
|
28
28
|
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_handleError-869dec25.js","sources":["../../src/cli/_handleError.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function _handleError(err: unknown): void {\n if (err instanceof Error) {\n console.error(chalk.red('error'), err.message)\n }\n\n process.exit(1)\n}\n"],"names":["_handleError","err","Error","console","error","chalk","red","message","process","exit"],"mappings":";;;;;;;;;AACO,SAASA,YAAY,CAACC,GAAG,EAAE;EAChC,IAAIA,GAAG,YAAYC,KAAK,EAAE;IACxBC,OAAO,CAACC,KAAK,CAACC,yBAAK,CAACC,GAAG,CAAC,OAAO,CAAC,EAAEL,GAAG,CAACM,OAAO,CAAC;EAC/C;EACDC,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC;AACjB;"}
|