@sanity/pkg-utils 1.18.0 → 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-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 +48 -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,9 +1,9 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
-
import {
|
|
4
|
+
import {BuildContext} from './core'
|
|
5
5
|
|
|
6
|
-
export function
|
|
6
|
+
export function printExtractMessages(ctx: BuildContext, messages: ExtractorMessage[]): void {
|
|
7
7
|
const {cwd, logger} = ctx
|
|
8
8
|
|
|
9
9
|
const warnings = messages.filter((msg) => msg.logLevel === 'warning')
|
|
@@ -2,10 +2,10 @@ import fs from 'fs'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import treeify from 'treeify'
|
|
5
|
-
import {PkgExport,
|
|
6
|
-
import {
|
|
5
|
+
import {PkgExport, BuildContext} from './core'
|
|
6
|
+
import {getFilesize} from './getFilesize'
|
|
7
7
|
|
|
8
|
-
export function
|
|
8
|
+
export function fileExists(file: string): boolean {
|
|
9
9
|
try {
|
|
10
10
|
fs.accessSync(file)
|
|
11
11
|
|
|
@@ -15,15 +15,15 @@ export function _fileExists(file: string): boolean {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function getFileInfo(cwd: string, filePath: string) {
|
|
19
19
|
const p = path.resolve(cwd, filePath)
|
|
20
|
-
const exists =
|
|
21
|
-
const size = exists ?
|
|
20
|
+
const exists = fileExists(p)
|
|
21
|
+
const size = exists ? getFilesize(p) : undefined
|
|
22
22
|
|
|
23
23
|
return {exists, size}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function
|
|
26
|
+
export function printPackageTree(ctx: BuildContext): void {
|
|
27
27
|
const {cwd, exports, logger, pkg} = ctx
|
|
28
28
|
|
|
29
29
|
if (!exports) return
|
|
@@ -37,8 +37,8 @@ export function _printPackageTree(ctx: _BuildContext): void {
|
|
|
37
37
|
tree.bin = pkg.bin
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function
|
|
41
|
-
const info =
|
|
40
|
+
function fileInfo(file: string) {
|
|
41
|
+
const info = getFileInfo(cwd, file)
|
|
42
42
|
|
|
43
43
|
if (!info.size) {
|
|
44
44
|
return `${chalk.gray(file)} ${chalk.red('does not exist')}`
|
|
@@ -62,7 +62,7 @@ export function _printPackageTree(ctx: _BuildContext): void {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
if (entry.types) {
|
|
65
|
-
exp.types =
|
|
65
|
+
exp.types = fileInfo(entry.types)
|
|
66
66
|
} else {
|
|
67
67
|
delete exp.types
|
|
68
68
|
}
|
|
@@ -70,8 +70,8 @@ export function _printPackageTree(ctx: _BuildContext): void {
|
|
|
70
70
|
if (entry.browser) {
|
|
71
71
|
exp.browser = {source: entry.browser.source}
|
|
72
72
|
|
|
73
|
-
if (entry.browser.import) exp.browser.import =
|
|
74
|
-
if (entry.browser.require) exp.browser.require =
|
|
73
|
+
if (entry.browser.import) exp.browser.import = fileInfo(entry.browser.import)
|
|
74
|
+
if (entry.browser.require) exp.browser.require = fileInfo(entry.browser.require)
|
|
75
75
|
} else {
|
|
76
76
|
delete exp.browser
|
|
77
77
|
}
|
|
@@ -79,25 +79,25 @@ export function _printPackageTree(ctx: _BuildContext): void {
|
|
|
79
79
|
if (entry.node) {
|
|
80
80
|
exp.node = {source: entry.node.source}
|
|
81
81
|
|
|
82
|
-
if (entry.node.import) exp.node.import =
|
|
83
|
-
if (entry.node.require) exp.node.require =
|
|
82
|
+
if (entry.node.import) exp.node.import = fileInfo(entry.node.import)
|
|
83
|
+
if (entry.node.require) exp.node.require = fileInfo(entry.node.require)
|
|
84
84
|
} else {
|
|
85
85
|
delete exp.node
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
if (entry.import) {
|
|
89
|
-
exp.import =
|
|
89
|
+
exp.import = fileInfo(entry.import)
|
|
90
90
|
} else {
|
|
91
91
|
delete exp.import
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
if (entry.require) {
|
|
95
|
-
exp.require =
|
|
95
|
+
exp.require = fileInfo(entry.require)
|
|
96
96
|
} else {
|
|
97
97
|
delete exp.require
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
exp.default =
|
|
100
|
+
exp.default = fileInfo(entry.default)
|
|
101
101
|
|
|
102
102
|
return [chalk.green(path.join(pkg.name, exportPath)), exp]
|
|
103
103
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PackageTargetVersions} from './resolveBrowserslistVersions'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function resolveBrowserTarget(versions: PackageTargetVersions): string[] | undefined {
|
|
4
4
|
const target: string[] = []
|
|
5
5
|
|
|
6
6
|
if (versions.chrome.length) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import browserslist from 'browserslist'
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface PackageTargetVersions {
|
|
4
4
|
chrome: string[]
|
|
5
5
|
ff: string[]
|
|
6
6
|
edge: string[]
|
|
@@ -10,14 +10,14 @@ export interface _PackageTargetVersions {
|
|
|
10
10
|
node: string[]
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function
|
|
13
|
+
function sortAsNumber(a: string, b: string) {
|
|
14
14
|
const aVersion = Number(a)
|
|
15
15
|
const bVersion = Number(b)
|
|
16
16
|
|
|
17
17
|
return aVersion - bVersion
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function
|
|
20
|
+
export function resolveBrowserslistVersions(query: string[]): PackageTargetVersions {
|
|
21
21
|
const result = browserslist(query)
|
|
22
22
|
|
|
23
23
|
const entries = result.map((key) => {
|
|
@@ -37,7 +37,7 @@ export function _resolveBrowserslistVersions(query: string[]): _PackageTargetVer
|
|
|
37
37
|
const node = entries.filter((b) => b.name === 'node')
|
|
38
38
|
|
|
39
39
|
// versions
|
|
40
|
-
const versions:
|
|
40
|
+
const versions: PackageTargetVersions = {
|
|
41
41
|
chrome: andChr.concat(chrome).map((b) => b.version),
|
|
42
42
|
ff: andFf.concat(ff).map((b) => b.version),
|
|
43
43
|
edge: edge.map((b) => b.version),
|
|
@@ -48,13 +48,13 @@ export function _resolveBrowserslistVersions(query: string[]): _PackageTargetVer
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// sort
|
|
51
|
-
versions.chrome.sort(
|
|
52
|
-
versions.ff.sort(
|
|
53
|
-
versions.edge.sort(
|
|
54
|
-
versions.iosSaf.sort(
|
|
55
|
-
versions.saf.sort(
|
|
56
|
-
versions.opera.sort(
|
|
57
|
-
versions.node.sort(
|
|
51
|
+
versions.chrome.sort(sortAsNumber)
|
|
52
|
+
versions.ff.sort(sortAsNumber)
|
|
53
|
+
versions.edge.sort(sortAsNumber)
|
|
54
|
+
versions.iosSaf.sort(sortAsNumber)
|
|
55
|
+
versions.saf.sort(sortAsNumber)
|
|
56
|
+
versions.opera.sort(sortAsNumber)
|
|
57
|
+
versions.node.sort(sortAsNumber)
|
|
58
58
|
|
|
59
59
|
return versions
|
|
60
60
|
}
|
|
@@ -4,19 +4,19 @@ import {
|
|
|
4
4
|
PkgConfigOptions,
|
|
5
5
|
PkgExports,
|
|
6
6
|
PkgRuntime,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from './
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
function
|
|
7
|
+
BuildContext,
|
|
8
|
+
DEFAULT_BROWSERSLIST_QUERY,
|
|
9
|
+
loadTSConfig,
|
|
10
|
+
PackageJSON,
|
|
11
|
+
parseExports,
|
|
12
|
+
resolveConfigProperty,
|
|
13
|
+
} from './core'
|
|
14
|
+
import {findCommonDirPath, pathContains} from './core/findCommonPath'
|
|
15
|
+
import {resolveBrowserslistVersions} from './resolveBrowserslistVersions'
|
|
16
|
+
import {resolveBrowserTarget} from './resolveBrowserTarget'
|
|
17
|
+
import {resolveNodeTarget} from './resolveNodeTarget'
|
|
18
|
+
|
|
19
|
+
function createLogger(): BuildContext['logger'] {
|
|
20
20
|
return {
|
|
21
21
|
/* eslint-disable no-console */
|
|
22
22
|
log: (...args) => {
|
|
@@ -38,20 +38,20 @@ function _createLogger(): _BuildContext['logger'] {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export async function
|
|
41
|
+
export async function resolveBuildContext(options: {
|
|
42
42
|
config?: PkgConfigOptions
|
|
43
43
|
cwd: string
|
|
44
44
|
emitDeclarationOnly?: boolean
|
|
45
|
-
pkg:
|
|
45
|
+
pkg: PackageJSON
|
|
46
46
|
strict: boolean
|
|
47
47
|
tsconfig: string
|
|
48
|
-
}): Promise<
|
|
48
|
+
}): Promise<BuildContext> {
|
|
49
49
|
const {config, cwd, emitDeclarationOnly = false, pkg, strict, tsconfig: tsconfigPath} = options
|
|
50
|
-
const logger =
|
|
51
|
-
const tsconfig = await
|
|
52
|
-
const targetVersions =
|
|
53
|
-
const nodeTarget =
|
|
54
|
-
const webTarget =
|
|
50
|
+
const logger = createLogger()
|
|
51
|
+
const tsconfig = await loadTSConfig({cwd, tsconfigPath})
|
|
52
|
+
const targetVersions = resolveBrowserslistVersions(pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY)
|
|
53
|
+
const nodeTarget = resolveNodeTarget(targetVersions)
|
|
54
|
+
const webTarget = resolveBrowserTarget(targetVersions)
|
|
55
55
|
|
|
56
56
|
if (!nodeTarget) {
|
|
57
57
|
throw new Error('no matching `node` target')
|
|
@@ -67,13 +67,13 @@ export async function _resolveBuildContext(options: {
|
|
|
67
67
|
node: nodeTarget,
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const parsedExports =
|
|
70
|
+
const parsedExports = parseExports({pkg, strict}).reduce<PkgExports>((acc, x) => {
|
|
71
71
|
const {_path: exportPath, ...exportEntry} = x
|
|
72
72
|
|
|
73
73
|
return {...acc, [exportPath]: exportEntry}
|
|
74
74
|
}, {})
|
|
75
75
|
|
|
76
|
-
const exports =
|
|
76
|
+
const exports = resolveConfigProperty(config?.exports, parsedExports)
|
|
77
77
|
|
|
78
78
|
const parsedExternal = [
|
|
79
79
|
...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
|
|
@@ -84,7 +84,7 @@ export async function _resolveBuildContext(options: {
|
|
|
84
84
|
const external =
|
|
85
85
|
config && Array.isArray(config.external)
|
|
86
86
|
? [...parsedExternal, ...config.external]
|
|
87
|
-
:
|
|
87
|
+
: resolveConfigProperty(config?.external, parsedExternal)
|
|
88
88
|
|
|
89
89
|
const outputPaths = Object.values(exports)
|
|
90
90
|
.flatMap((exportEntry) => {
|
|
@@ -99,7 +99,7 @@ export async function _resolveBuildContext(options: {
|
|
|
99
99
|
})
|
|
100
100
|
.map((p) => path.resolve(cwd, p))
|
|
101
101
|
|
|
102
|
-
const commonDistPath =
|
|
102
|
+
const commonDistPath = findCommonDirPath(outputPaths)
|
|
103
103
|
|
|
104
104
|
if (commonDistPath === cwd) {
|
|
105
105
|
throw new Error(
|
|
@@ -107,7 +107,7 @@ export async function _resolveBuildContext(options: {
|
|
|
107
107
|
)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
if (commonDistPath && !
|
|
110
|
+
if (commonDistPath && !pathContains(cwd, commonDistPath)) {
|
|
111
111
|
throw new Error('all output files must be located within the package')
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -117,7 +117,7 @@ export async function _resolveBuildContext(options: {
|
|
|
117
117
|
configDistPath &&
|
|
118
118
|
commonDistPath &&
|
|
119
119
|
configDistPath !== commonDistPath &&
|
|
120
|
-
!
|
|
120
|
+
!pathContains(configDistPath, commonDistPath)
|
|
121
121
|
) {
|
|
122
122
|
logger.log(`did you mean to configure \`dist: './${path.relative(cwd, commonDistPath)}'\`?`)
|
|
123
123
|
|
|
@@ -130,7 +130,7 @@ export async function _resolveBuildContext(options: {
|
|
|
130
130
|
throw new Error('could not detect `dist` path')
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
const ctx:
|
|
133
|
+
const ctx: BuildContext = {
|
|
134
134
|
config,
|
|
135
135
|
cwd,
|
|
136
136
|
distPath,
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import {PkgExport, PkgFormat, PkgRuntime,
|
|
4
|
-
import {
|
|
3
|
+
import {PkgExport, PkgFormat, PkgRuntime, BuildContext} from './core'
|
|
4
|
+
import {BuildTask, DtsTask, RollupTask, RollupTaskEntry} from './tasks'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
7
|
-
export function
|
|
7
|
+
export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
8
8
|
const {config, cwd, pkg, target} = ctx
|
|
9
9
|
|
|
10
10
|
const bundles = config?.bundles || []
|
|
11
11
|
|
|
12
|
-
const tasks:
|
|
12
|
+
const tasks: BuildTask[] = []
|
|
13
13
|
|
|
14
14
|
const exports = Object.entries(ctx.exports || {}).map(
|
|
15
15
|
([_path, exp]) => ({_path, ...exp} as PkgExport & {_path: string})
|
|
16
16
|
)
|
|
17
17
|
|
|
18
|
-
const dtsTask:
|
|
18
|
+
const dtsTask: DtsTask = {
|
|
19
19
|
type: 'build:dts',
|
|
20
20
|
entries: [],
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const rollupTasks: Record<string,
|
|
23
|
+
const rollupTasks: Record<string, RollupTask> = {}
|
|
24
24
|
|
|
25
|
-
function
|
|
25
|
+
function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
26
26
|
const buildId = `${format}:${runtime}`
|
|
27
27
|
|
|
28
28
|
if (rollupTasks[buildId]) {
|
|
@@ -65,7 +65,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
65
65
|
|
|
66
66
|
if (!output) continue
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
addRollupTaskEntry('commonjs', ctx.runtime, {
|
|
69
69
|
path: exp._path,
|
|
70
70
|
source: exp.source,
|
|
71
71
|
output,
|
|
@@ -78,7 +78,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
78
78
|
|
|
79
79
|
if (!output) continue
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
addRollupTaskEntry('esm', ctx.runtime, {
|
|
82
82
|
path: exp._path,
|
|
83
83
|
source: exp.source,
|
|
84
84
|
output,
|
|
@@ -91,7 +91,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
91
91
|
|
|
92
92
|
if (!output) continue
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
addRollupTaskEntry('commonjs', 'browser', {
|
|
95
95
|
path: exp._path,
|
|
96
96
|
source: exp.browser?.source || exp.source,
|
|
97
97
|
output,
|
|
@@ -104,7 +104,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
104
104
|
|
|
105
105
|
if (!output) continue
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
addRollupTaskEntry('esm', 'browser', {
|
|
108
108
|
path: exp._path,
|
|
109
109
|
source: exp.browser?.source || exp.source,
|
|
110
110
|
output,
|
|
@@ -113,7 +113,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
113
113
|
|
|
114
114
|
for (const bundle of bundles) {
|
|
115
115
|
if (bundle.require) {
|
|
116
|
-
|
|
116
|
+
addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {
|
|
117
117
|
path: '__bundle__',
|
|
118
118
|
source: bundle.source,
|
|
119
119
|
output: bundle.require,
|
|
@@ -121,7 +121,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
if (bundle.import) {
|
|
124
|
-
|
|
124
|
+
addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {
|
|
125
125
|
path: '__bundle__',
|
|
126
126
|
source: bundle.source,
|
|
127
127
|
output: bundle.import,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {PackageTargetVersions} from './resolveBrowserslistVersions'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function resolveNodeTarget(versions: PackageTargetVersions): string[] | undefined {
|
|
4
4
|
const target: string[] = []
|
|
5
5
|
|
|
6
6
|
if (versions.node.length) {
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import {PkgExport, PkgFormat, PkgRuntime,
|
|
4
|
-
import {
|
|
3
|
+
import {PkgExport, PkgFormat, PkgRuntime, BuildContext} from './core'
|
|
4
|
+
import {WatchTask, DtsWatchTask, RollupWatchTask, RollupTaskEntry} from './tasks'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
7
|
-
export function
|
|
7
|
+
export function resolveWatchTasks(ctx: BuildContext): WatchTask[] {
|
|
8
8
|
const {config, cwd, pkg, target} = ctx
|
|
9
|
-
const tasks:
|
|
9
|
+
const tasks: WatchTask[] = []
|
|
10
10
|
|
|
11
11
|
const exports = Object.entries(ctx.exports || {}).map(
|
|
12
12
|
([_path, exp]) => ({_path, ...exp} as PkgExport & {_path: string})
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
const dtsTask:
|
|
15
|
+
const dtsTask: DtsWatchTask = {
|
|
16
16
|
type: 'watch:dts',
|
|
17
17
|
entries: [],
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const rollupTasks: Record<string,
|
|
20
|
+
const rollupTasks: Record<string, RollupWatchTask> = {}
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
|
|
23
23
|
const buildId = `${format}:${runtime}`
|
|
24
24
|
|
|
25
25
|
if (rollupTasks[buildId]) {
|
|
@@ -56,7 +56,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
56
56
|
|
|
57
57
|
if (!output) continue
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
addRollupTaskEntry('commonjs', ctx.runtime, {
|
|
60
60
|
path: exp._path,
|
|
61
61
|
source: exp.source,
|
|
62
62
|
output,
|
|
@@ -69,7 +69,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
69
69
|
|
|
70
70
|
if (!output) continue
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
addRollupTaskEntry('commonjs', 'browser', {
|
|
73
73
|
path: exp._path,
|
|
74
74
|
source: exp.browser?.source || exp.source,
|
|
75
75
|
output,
|
|
@@ -82,7 +82,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
82
82
|
|
|
83
83
|
if (!output) continue
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
addRollupTaskEntry('esm', ctx.runtime, {
|
|
86
86
|
path: exp._path,
|
|
87
87
|
source: exp.source,
|
|
88
88
|
output,
|
|
@@ -95,7 +95,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
95
95
|
|
|
96
96
|
if (!output) continue
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
addRollupTaskEntry('esm', 'browser', {
|
|
99
99
|
path: exp._path,
|
|
100
100
|
source: exp.browser?.source || exp.source,
|
|
101
101
|
output,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
|
|
5
|
-
export function
|
|
5
|
+
export function createSpinner(msg: string): {complete: () => void; error: () => void} {
|
|
6
6
|
const startTime = Date.now()
|
|
7
7
|
|
|
8
8
|
console.log(`${chalk.yellow('run ')} ${msg}`)
|
package/src/node/{_tasks/dts/_createApiExtractorConfig.ts → tasks/dts/createApiExtractorConfig.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function createApiExtractorConfig(options: {
|
|
5
5
|
distPath: string
|
|
6
6
|
exportPath: string
|
|
7
7
|
filePath: string
|
|
@@ -10,7 +10,7 @@ export interface TSDocCustomTag {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/** @internal */
|
|
13
|
-
export async function
|
|
13
|
+
export async function createTSDocConfig(opts: {
|
|
14
14
|
customTags: TSDocCustomTag[]
|
|
15
15
|
}): Promise<TSDocConfigFile | undefined> {
|
|
16
16
|
const {customTags} = opts
|
|
@@ -2,11 +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 {
|
|
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'
|
|
10
10
|
|
|
11
11
|
const rimraf = promisify(rimrafCallback)
|
|
12
12
|
|
|
@@ -15,10 +15,10 @@ const rimraf = promisify(rimrafCallback)
|
|
|
15
15
|
* - Create a type definition bundle for each export entry.
|
|
16
16
|
* - When done, remove the temporary directory.
|
|
17
17
|
*/
|
|
18
|
-
export async function
|
|
19
|
-
ctx:
|
|
20
|
-
task:
|
|
21
|
-
): Promise<
|
|
18
|
+
export async function doExtract(
|
|
19
|
+
ctx: BuildContext,
|
|
20
|
+
task: DtsTask | DtsWatchTask
|
|
21
|
+
): Promise<DtsResult> {
|
|
22
22
|
const {config, cwd, files, strict, ts} = ctx
|
|
23
23
|
|
|
24
24
|
if (!ts.config || !ts.configPath) {
|
|
@@ -33,7 +33,7 @@ export async function _doExtract(
|
|
|
33
33
|
|
|
34
34
|
const tmpPath = path.resolve(outDir, '__tmp__')
|
|
35
35
|
|
|
36
|
-
await
|
|
36
|
+
await buildTypes({cwd, outDir: tmpPath, strict, tsconfig: ts.config})
|
|
37
37
|
const messages: ExtractorMessage[] = []
|
|
38
38
|
|
|
39
39
|
const results: {sourcePath: string; filePath: string}[] = []
|
|
@@ -48,7 +48,7 @@ export async function _doExtract(
|
|
|
48
48
|
|
|
49
49
|
const targetPath = path.resolve(cwd, entry.targetPath)
|
|
50
50
|
const filePath = path.relative(outDir, targetPath)
|
|
51
|
-
const result = await
|
|
51
|
+
const result = await extractTypes({
|
|
52
52
|
customTags: config?.extract?.customTags,
|
|
53
53
|
cwd,
|
|
54
54
|
distPath: outDir,
|
|
@@ -67,7 +67,7 @@ export async function _doExtract(
|
|
|
67
67
|
if (result.messages.some((msg) => msg.logLevel === 'error')) {
|
|
68
68
|
await rimraf(tmpPath)
|
|
69
69
|
|
|
70
|
-
throw new
|
|
70
|
+
throw new DtsError('encountered errors when extracting types', result.messages)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
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
|
}
|