@sanity/pkg-utils 1.3.1 → 1.5.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/README.md +8 -0
- package/dist/__printPackageTree-3ff3ecd3.cjs +76 -0
- package/dist/__printPackageTree-3ff3ecd3.cjs.map +1 -0
- package/dist/__resolveBuildContext-85cfca8d.cjs +337 -0
- package/dist/__resolveBuildContext-85cfca8d.cjs.map +1 -0
- package/dist/_build-683d9922.cjs +168 -0
- package/dist/_build-683d9922.cjs.map +1 -0
- package/dist/_buildAction-f593323a.cjs +44 -0
- package/dist/_buildAction-f593323a.cjs.map +1 -0
- package/dist/_check-6843c26d.cjs +118 -0
- package/dist/_check-6843c26d.cjs.map +1 -0
- package/dist/_checkAction-0bca6a14.cjs +29 -0
- package/dist/_checkAction-0bca6a14.cjs.map +1 -0
- package/dist/_index-5765fada.cjs +584 -0
- package/dist/_index-5765fada.cjs.map +1 -0
- package/dist/_watch-ec1b35d6.cjs +217 -0
- package/dist/_watch-ec1b35d6.cjs.map +1 -0
- package/dist/_watchAction-a388fc00.cjs +43 -0
- package/dist/_watchAction-a388fc00.cjs.map +1 -0
- package/dist/cli.cjs +14 -31
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +43 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +282 -152
- package/dist/index.js +1055 -5198
- package/dist/index.js.map +1 -1
- package/package.json +37 -10
- package/src/cli/buildAction.ts +8 -0
- package/src/cli/checkAction.ts +9 -0
- package/src/cli/index.ts +42 -0
- package/src/cli/watchAction.ts +8 -0
- package/src/{core → node/_core}/_defaults.ts +1 -3
- package/src/{core → node/_core}/_isRecord.ts +1 -3
- package/src/{core → node/_core}/config/_loadConfig.ts +1 -3
- package/src/node/_core/config/_resolveConfigProperty.ts +15 -0
- package/src/{core → node/_core}/config/defineConfig.ts +1 -3
- package/src/{core → node/_core}/config/index.ts +0 -0
- package/src/node/_core/config/types.ts +69 -0
- package/src/node/_core/contexts/buildContext.ts +34 -0
- package/src/node/_core/contexts/index.ts +1 -0
- package/src/{core → node/_core}/index.ts +2 -0
- package/src/node/_core/pkg/_loadPkg.ts +55 -0
- package/src/node/_core/pkg/_loadPkgWithReporting.ts +29 -0
- package/src/node/_core/pkg/_parseExports.ts +45 -0
- package/src/{core → node/_core}/pkg/_types.ts +16 -5
- package/src/{core → node/_core}/pkg/index.ts +1 -0
- package/src/{build/tasks/dts → node/_core/ts}/_loadTSConfig.ts +1 -0
- package/src/node/_core/ts/index.ts +1 -0
- package/src/node/_getFilesize.ts +8 -0
- package/src/node/_globFiles.ts +5 -0
- package/src/node/_printExtractMessages.ts +56 -0
- package/src/node/_printPackageTree.ts +72 -0
- package/src/{build/_parseWebTarget.ts → node/_resolveBrowserTarget.ts} +2 -2
- package/src/{build/_parseBrowserslistVersions.ts → node/_resolveBrowserslistVersions.ts} +1 -1
- package/src/node/_resolveBuildContext.ts +104 -0
- package/src/node/_resolveBuildTasks.ts +129 -0
- package/src/{build/_parseNodeTarget.ts → node/_resolveNodeTarget.ts} +2 -2
- package/src/node/_resolveWatchTasks.ts +129 -0
- package/src/node/_spinner.ts +26 -0
- package/src/node/_tasks/_types.ts +57 -0
- package/src/node/_tasks/dts/_DtsError.ts +11 -0
- package/src/{build/tasks → node/_tasks}/dts/_buildTypes.ts +30 -16
- package/src/node/_tasks/dts/_createApiExtractorConfig.ts +41 -0
- package/src/{build/tasks → node/_tasks}/dts/_createTSDocConfig.ts +2 -6
- package/src/node/_tasks/dts/_doExtract.ts +57 -0
- package/src/node/_tasks/dts/_dtsTask.ts +40 -0
- package/src/node/_tasks/dts/_dtsWatchTask.ts +43 -0
- package/src/node/_tasks/dts/_extractTypes.ts +164 -0
- package/src/node/_tasks/dts/_types.ts +25 -0
- package/src/node/_tasks/dts/index.ts +3 -0
- package/src/node/_tasks/index.ts +19 -0
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +132 -0
- package/src/node/_tasks/rollup/_rollupTask.ts +73 -0
- package/src/node/_tasks/rollup/_rollupWatchTask.ts +78 -0
- package/src/node/_tasks/rollup/index.ts +2 -0
- package/src/node/_watchConfigFiles.ts +52 -0
- package/src/node/_watchFiles.ts +29 -0
- package/src/node/build.ts +47 -0
- package/src/node/check.ts +136 -0
- package/src/node/index.ts +6 -0
- package/src/node/watch.ts +56 -0
- package/dist/_build-5bf997de.cjs +0 -5549
- package/dist/_build-5bf997de.cjs.map +0 -1
- package/src/build/_parseTasks.ts +0 -87
- package/src/build/_types.ts +0 -26
- package/src/build/build.ts +0 -101
- package/src/build/index.ts +0 -2
- package/src/build/tasks/_types.ts +0 -8
- package/src/build/tasks/dts/_createApiExtractorConfig.ts +0 -88
- package/src/build/tasks/dts/_extractTypes.ts +0 -100
- package/src/build/tasks/dts/dts.ts +0 -59
- package/src/build/tasks/dts/index.ts +0 -1
- package/src/build/tasks/extract/_extractTask.ts +0 -49
- package/src/build/tasks/extract/index.ts +0 -1
- package/src/build/tasks/index.ts +0 -4
- package/src/build/tasks/rollup/_resolveRollupConfig.ts +0 -95
- package/src/build/tasks/rollup/index.ts +0 -1
- package/src/build/tasks/rollup/rollup.ts +0 -96
- package/src/cli.ts +0 -25
- package/src/core/config/_resolveConfigProperty.ts +0 -14
- package/src/core/config/types.ts +0 -52
- package/src/core/pkg/_loadPkg.ts +0 -13
- package/src/core/pkg/_parseExports.ts +0 -40
- package/src/index.ts +0 -2
package/src/build/_parseTasks.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import {PackageSubPathExportEntry} from '../core'
|
|
3
|
-
import {_BuildContext} from './_types'
|
|
4
|
-
import {_BuildTask, _DtsTask, _RollupTask} from './tasks'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export function _parseTasks(ctx: _BuildContext): _BuildTask[] {
|
|
10
|
-
const {config, pkg} = ctx
|
|
11
|
-
|
|
12
|
-
const entries = Object.entries(ctx.exports || {}).map(
|
|
13
|
-
([path, entry]) => ({path, ...entry} as PackageSubPathExportEntry & {path: string})
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
const dtsTasks: Record<string, _DtsTask> = {}
|
|
17
|
-
const rollupTasks: Record<string, _RollupTask> = {}
|
|
18
|
-
|
|
19
|
-
// Parse `dts` tasks
|
|
20
|
-
for (const entry of entries) {
|
|
21
|
-
const exportId = path.join(pkg.name, entry.path)
|
|
22
|
-
|
|
23
|
-
if (entry.types) {
|
|
24
|
-
if (!dtsTasks[exportId]) {
|
|
25
|
-
dtsTasks[exportId] = {
|
|
26
|
-
type: 'dts',
|
|
27
|
-
exportId,
|
|
28
|
-
exportPath: entry.path === '.' ? './index' : entry.path,
|
|
29
|
-
source: entry.source,
|
|
30
|
-
output: entry.types,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Parse `rollup` tasks
|
|
37
|
-
for (const entry of entries) {
|
|
38
|
-
const runtime = entry.runtime || config?.runtime || 'web'
|
|
39
|
-
|
|
40
|
-
const format: ('commonjs' | 'esm')[] = []
|
|
41
|
-
const target: string[] = []
|
|
42
|
-
|
|
43
|
-
if (entry.require) {
|
|
44
|
-
format.push('commonjs')
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (entry.default) {
|
|
48
|
-
format.push('esm')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (runtime === 'node') {
|
|
52
|
-
target.push(...ctx.target.node)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (runtime === 'web') {
|
|
56
|
-
target.push(...ctx.target.web)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (const f of format) {
|
|
60
|
-
const buildId = `${runtime}:${f}:${target.join(',')}`
|
|
61
|
-
|
|
62
|
-
if (!rollupTasks[buildId]) {
|
|
63
|
-
rollupTasks[buildId] = {
|
|
64
|
-
type: 'rollup',
|
|
65
|
-
buildId,
|
|
66
|
-
entries: [entry],
|
|
67
|
-
runtime,
|
|
68
|
-
format: f,
|
|
69
|
-
target,
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
rollupTasks[buildId].entries.push(entry)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const tasks: _BuildTask[] = [...Object.values(dtsTasks), ...Object.values(rollupTasks)]
|
|
78
|
-
|
|
79
|
-
if (ctx.extract && pkg.types) {
|
|
80
|
-
tasks.push({
|
|
81
|
-
type: 'extract',
|
|
82
|
-
mainEntryPointPath: pkg.types,
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return tasks
|
|
87
|
-
}
|
package/src/build/_types.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {PackageExports, PkgConfigOptions, _PackageJSON} from '../core'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export interface _BuildFile {
|
|
7
|
-
type: 'asset' | 'chunk' | 'types'
|
|
8
|
-
path: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export interface _BuildContext {
|
|
15
|
-
config?: PkgConfigOptions
|
|
16
|
-
cwd: string
|
|
17
|
-
exports: PackageExports | undefined
|
|
18
|
-
external: string[]
|
|
19
|
-
extract: boolean
|
|
20
|
-
files: _BuildFile[]
|
|
21
|
-
dist: string
|
|
22
|
-
pkg: _PackageJSON
|
|
23
|
-
src: string
|
|
24
|
-
target: {node: string[]; web: string[]}
|
|
25
|
-
tsconfig?: string
|
|
26
|
-
}
|
package/src/build/build.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import chalk from 'chalk'
|
|
5
|
-
import {
|
|
6
|
-
PackageExports,
|
|
7
|
-
_DEFAULTS,
|
|
8
|
-
_loadConfig,
|
|
9
|
-
_loadPkg,
|
|
10
|
-
_parseExports,
|
|
11
|
-
_resolveConfigProperty,
|
|
12
|
-
} from '../core'
|
|
13
|
-
import {_parseBrowserslistVersions} from './_parseBrowserslistVersions'
|
|
14
|
-
import {_parseNodeTarget} from './_parseNodeTarget'
|
|
15
|
-
import {_parseTasks} from './_parseTasks'
|
|
16
|
-
import {_parseWebTarget} from './_parseWebTarget'
|
|
17
|
-
import {_BuildContext} from './_types'
|
|
18
|
-
import {_dtsTask, _extractTask, _rollupTask} from './tasks'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
export async function build(options: {
|
|
24
|
-
cwd: string
|
|
25
|
-
extract?: boolean
|
|
26
|
-
tsconfig?: string
|
|
27
|
-
}): Promise<void> {
|
|
28
|
-
const {cwd, extract = false, tsconfig = 'tsconfig.json'} = options
|
|
29
|
-
const pkg = await _loadPkg({cwd})
|
|
30
|
-
const config = await _loadConfig({cwd})
|
|
31
|
-
|
|
32
|
-
const parsedExports = _parseExports(pkg).reduce<PackageExports>((acc, x) => {
|
|
33
|
-
const {path: exportPath, ...exportEntry} = x
|
|
34
|
-
|
|
35
|
-
return {...acc, [exportPath]: exportEntry}
|
|
36
|
-
}, {})
|
|
37
|
-
|
|
38
|
-
const exports = _resolveConfigProperty(config?.exports, parsedExports)
|
|
39
|
-
|
|
40
|
-
const parsedExternal = [
|
|
41
|
-
...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
|
|
42
|
-
...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []),
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
const external = _resolveConfigProperty(config?.external, parsedExternal)
|
|
46
|
-
|
|
47
|
-
const targetVersions = _parseBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist)
|
|
48
|
-
|
|
49
|
-
const srcPath = path.resolve(cwd, config?.src || 'src')
|
|
50
|
-
const distPath = path.resolve(cwd, config?.dist || 'dist')
|
|
51
|
-
|
|
52
|
-
const nodeTarget = _parseNodeTarget(targetVersions)
|
|
53
|
-
const webTarget = _parseWebTarget(targetVersions)
|
|
54
|
-
|
|
55
|
-
if (!nodeTarget) {
|
|
56
|
-
throw new Error('no matching `node` target')
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!webTarget) {
|
|
60
|
-
throw new Error('no matching `web` target')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const context: _BuildContext = {
|
|
64
|
-
config,
|
|
65
|
-
cwd,
|
|
66
|
-
exports,
|
|
67
|
-
extract,
|
|
68
|
-
files: [],
|
|
69
|
-
external,
|
|
70
|
-
dist: path.relative(cwd, distPath),
|
|
71
|
-
pkg,
|
|
72
|
-
src: path.relative(cwd, srcPath),
|
|
73
|
-
target: {node: nodeTarget, web: webTarget},
|
|
74
|
-
tsconfig,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log(chalk.gray('cwd '), context.cwd)
|
|
78
|
-
console.log(chalk.gray('src '), context.src)
|
|
79
|
-
console.log(chalk.gray('dist '), context.dist)
|
|
80
|
-
console.log(chalk.gray('tsconfig '), context.tsconfig)
|
|
81
|
-
|
|
82
|
-
if (exports) {
|
|
83
|
-
const buildTasks = _parseTasks(context)
|
|
84
|
-
|
|
85
|
-
for (const task of buildTasks) {
|
|
86
|
-
if (task.type === 'dts') {
|
|
87
|
-
await _dtsTask(context, task)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (task.type === 'extract') {
|
|
91
|
-
await _extractTask(context, task)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (task.type === 'rollup') {
|
|
95
|
-
await _rollupTask(context, task)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
throw new Error('no exports')
|
|
100
|
-
}
|
|
101
|
-
}
|
package/src/build/index.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import {ExtractorLogLevel, IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
3
|
-
|
|
4
|
-
export const DEFAULT_MESSAGES_CONFIG: IExtractorMessagesConfig = {
|
|
5
|
-
compilerMessageReporting: {
|
|
6
|
-
default: {
|
|
7
|
-
logLevel: 'warning' as ExtractorLogLevel,
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
extractorMessageReporting: {
|
|
12
|
-
default: {
|
|
13
|
-
logLevel: 'warning' as ExtractorLogLevel,
|
|
14
|
-
addToApiReportFile: false,
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
// 'ae-extra-release-tag': {
|
|
18
|
-
// logLevel: 'error' as ExtractorLogLevel,
|
|
19
|
-
// addToApiReportFile: false
|
|
20
|
-
// },
|
|
21
|
-
|
|
22
|
-
// 'ae-forgotten-export': {
|
|
23
|
-
// logLevel: 'error' as ExtractorLogLevel,
|
|
24
|
-
// addToApiReportFile: false
|
|
25
|
-
// }
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
tsdocMessageReporting: {
|
|
29
|
-
default: {
|
|
30
|
-
logLevel: 'warning' as ExtractorLogLevel,
|
|
31
|
-
addToApiReportFile: false,
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
// 'tsdoc-link-tag-unescaped-text': {
|
|
35
|
-
// logLevel: 'warning' as ExtractorLogLevel,
|
|
36
|
-
// addToApiReportFile: false
|
|
37
|
-
// },
|
|
38
|
-
|
|
39
|
-
// 'tsdoc-unsupported-tag': {
|
|
40
|
-
// logLevel: 'none' as ExtractorLogLevel,
|
|
41
|
-
// addToApiReportFile: false
|
|
42
|
-
// },
|
|
43
|
-
|
|
44
|
-
// 'tsdoc-undefined-tag': {
|
|
45
|
-
// logLevel: 'none' as ExtractorLogLevel,
|
|
46
|
-
// addToApiReportFile: false
|
|
47
|
-
// }
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function _createApiExtractorConfig(options: {
|
|
52
|
-
exportPath: string
|
|
53
|
-
projectPath: string
|
|
54
|
-
sourcePath: string
|
|
55
|
-
tsconfigPath: string
|
|
56
|
-
distPath: string
|
|
57
|
-
}): IConfigFile {
|
|
58
|
-
const {exportPath, projectPath, sourcePath, tsconfigPath, distPath} = options
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
apiReport: {
|
|
62
|
-
enabled: false,
|
|
63
|
-
reportFileName: '<unscopedPackageName>.api.md',
|
|
64
|
-
// reportFileName: path.resolve(distPath, `${exportPath}.api.md`)
|
|
65
|
-
},
|
|
66
|
-
// bundledPackages: [],
|
|
67
|
-
compiler: {
|
|
68
|
-
tsconfigFilePath: tsconfigPath,
|
|
69
|
-
},
|
|
70
|
-
docModel: {
|
|
71
|
-
enabled: false,
|
|
72
|
-
// apiJsonFilePath: '<unscopedPackageName>.api.json'
|
|
73
|
-
apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),
|
|
74
|
-
},
|
|
75
|
-
dtsRollup: {
|
|
76
|
-
enabled: true,
|
|
77
|
-
untrimmedFilePath: path.resolve(distPath, `${exportPath}.d.ts`),
|
|
78
|
-
// betaTrimmedFilePath: path.resolve(distPath, `${exportPath}-beta.d.ts`),
|
|
79
|
-
// publicTrimmedFilePath: path.resolve(distPath, `${exportPath}-public.d.ts`)
|
|
80
|
-
},
|
|
81
|
-
tsdocMetadata: {
|
|
82
|
-
enabled: false,
|
|
83
|
-
},
|
|
84
|
-
messages: DEFAULT_MESSAGES_CONFIG,
|
|
85
|
-
mainEntryPointFilePath: sourcePath,
|
|
86
|
-
projectFolder: projectPath,
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import {
|
|
3
|
-
Extractor,
|
|
4
|
-
ExtractorConfig,
|
|
5
|
-
ExtractorMessage,
|
|
6
|
-
ExtractorResult,
|
|
7
|
-
} from '@microsoft/api-extractor'
|
|
8
|
-
import chalk from 'chalk'
|
|
9
|
-
import {_BuildFile} from '../../_types'
|
|
10
|
-
import {_createApiExtractorConfig} from './_createApiExtractorConfig'
|
|
11
|
-
import {_createTSDocConfig} from './_createTSDocConfig'
|
|
12
|
-
|
|
13
|
-
export async function _extractTypes(options: {
|
|
14
|
-
cwd: string
|
|
15
|
-
distPath: string
|
|
16
|
-
exportPath: string
|
|
17
|
-
files: _BuildFile[]
|
|
18
|
-
projectPath: string
|
|
19
|
-
quiet?: boolean
|
|
20
|
-
sourcePath: string
|
|
21
|
-
tsconfigPath: string
|
|
22
|
-
}): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
|
|
23
|
-
const {cwd, distPath, exportPath, files, projectPath, quiet, sourcePath, tsconfigPath} = options
|
|
24
|
-
|
|
25
|
-
const tsdocConfigFile = await _createTSDocConfig({
|
|
26
|
-
customTags: [],
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
|
|
30
|
-
configObject: _createApiExtractorConfig({
|
|
31
|
-
exportPath,
|
|
32
|
-
projectPath,
|
|
33
|
-
sourcePath,
|
|
34
|
-
distPath,
|
|
35
|
-
tsconfigPath,
|
|
36
|
-
}),
|
|
37
|
-
configObjectFullPath: undefined,
|
|
38
|
-
tsdocConfigFile,
|
|
39
|
-
packageJsonFullPath: path.resolve(projectPath, 'package.json'),
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const messages: ExtractorMessage[] = []
|
|
43
|
-
|
|
44
|
-
// Invoke API Extractor
|
|
45
|
-
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
46
|
-
// Equivalent to the "--local" command-line parameter
|
|
47
|
-
localBuild: true,
|
|
48
|
-
// Equivalent to the "--verbose" command-line parameter
|
|
49
|
-
showVerboseMessages: true,
|
|
50
|
-
// handle messages
|
|
51
|
-
messageCallback(message: ExtractorMessage) {
|
|
52
|
-
messages.push(message)
|
|
53
|
-
message.handled = true
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
if (!quiet) {
|
|
58
|
-
const warnings: ExtractorMessage[] = messages.filter((msg) => msg.logLevel === 'warning')
|
|
59
|
-
|
|
60
|
-
for (const msg of warnings) {
|
|
61
|
-
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
|
|
62
|
-
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
console.log(
|
|
65
|
-
[
|
|
66
|
-
`${chalk.cyan(sourceFilePath || '?')}`,
|
|
67
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
68
|
-
` - ${chalk.yellow('warning')} ${chalk.gray(msg.messageId)}\n`,
|
|
69
|
-
msg.text,
|
|
70
|
-
'\n',
|
|
71
|
-
].join('')
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const errors: ExtractorMessage[] = messages.filter((msg) => msg.logLevel === 'error')
|
|
77
|
-
|
|
78
|
-
for (const msg of errors) {
|
|
79
|
-
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
|
|
80
|
-
|
|
81
|
-
// eslint-disable-next-line no-console
|
|
82
|
-
console.log(
|
|
83
|
-
[
|
|
84
|
-
`${chalk.cyan(sourceFilePath || '?')}`,
|
|
85
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
86
|
-
` - ${chalk.red('error')} ${chalk.gray(msg.messageId)}\n`,
|
|
87
|
-
msg.text,
|
|
88
|
-
'\n',
|
|
89
|
-
].join('')
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Add to `files` in context
|
|
94
|
-
files.push({
|
|
95
|
-
type: 'types',
|
|
96
|
-
path: path.resolve(distPath, `${exportPath}.d.ts`),
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
return {extractorResult, messages}
|
|
100
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import {promisify} from 'util'
|
|
5
|
-
import chalk from 'chalk'
|
|
6
|
-
import rimrafCallback from 'rimraf'
|
|
7
|
-
import {_BuildContext} from '../../_types'
|
|
8
|
-
import {_buildTypes} from './_buildTypes'
|
|
9
|
-
import {_extractTypes} from './_extractTypes'
|
|
10
|
-
|
|
11
|
-
const rimraf = promisify(rimrafCallback)
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export interface _DtsTask {
|
|
17
|
-
type: 'dts'
|
|
18
|
-
exportId: string
|
|
19
|
-
exportPath: string
|
|
20
|
-
source: string
|
|
21
|
-
output: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export async function _dtsTask(ctx: _BuildContext, task: _DtsTask): Promise<void> {
|
|
28
|
-
const {cwd, dist, files, tsconfig} = ctx
|
|
29
|
-
const exportPath = task.exportPath === '.' ? './index' : task.exportPath
|
|
30
|
-
const distPath = path.resolve(cwd, dist)
|
|
31
|
-
const tmpPath = path.resolve(cwd, dist, 'tmp')
|
|
32
|
-
const tsconfigPath = path.resolve(cwd, tsconfig || 'tsconfig.json')
|
|
33
|
-
|
|
34
|
-
console.log('=================================================================================')
|
|
35
|
-
console.log(chalk.gray('task '), 'd.ts')
|
|
36
|
-
console.log(chalk.gray('source '), path.join('', task.source))
|
|
37
|
-
console.log(chalk.gray('export '), path.join(dist, `${exportPath}.d.ts`))
|
|
38
|
-
console.log(chalk.gray('tsconfig '), path.relative(cwd, tsconfigPath))
|
|
39
|
-
|
|
40
|
-
const types = await _buildTypes({
|
|
41
|
-
cwd,
|
|
42
|
-
outDir: tmpPath,
|
|
43
|
-
sourcePath: task.source,
|
|
44
|
-
tsconfigPath,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
await _extractTypes({
|
|
48
|
-
cwd,
|
|
49
|
-
exportPath,
|
|
50
|
-
files,
|
|
51
|
-
projectPath: cwd,
|
|
52
|
-
sourcePath: types.path,
|
|
53
|
-
tsconfigPath,
|
|
54
|
-
distPath,
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
// Delete tmp directory
|
|
58
|
-
await rimraf(tmpPath)
|
|
59
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './dts'
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import fs from 'fs/promises'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import {extract, transform} from '@sanity/tsdoc-to-portable-text'
|
|
6
|
-
import chalk from 'chalk'
|
|
7
|
-
import mkdirp from 'mkdirp'
|
|
8
|
-
import {_BuildContext} from '../../_types'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export interface _ExtractTask {
|
|
14
|
-
type: 'extract'
|
|
15
|
-
mainEntryPointPath: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function _extractTask(ctx: _BuildContext, task: _ExtractTask): Promise<void> {
|
|
19
|
-
const {mainEntryPointPath} = task
|
|
20
|
-
|
|
21
|
-
console.log('=================================================================================')
|
|
22
|
-
console.log(chalk.gray('task '), 'extract')
|
|
23
|
-
console.log(
|
|
24
|
-
chalk.gray('source '),
|
|
25
|
-
path.relative(ctx.cwd, path.resolve(ctx.cwd, mainEntryPointPath))
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
const extracted = await extract(ctx.cwd, {
|
|
29
|
-
tsconfigPath: path.resolve(ctx.cwd, ctx.tsconfig || 'tsconfig.json'),
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const transformed = transform(extracted, {
|
|
33
|
-
package: {
|
|
34
|
-
version: ctx.pkg.version,
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const apiJsonDirPath = path.resolve(ctx.cwd, 'etc/api', ctx.pkg.name)
|
|
39
|
-
|
|
40
|
-
await mkdirp(apiJsonDirPath)
|
|
41
|
-
|
|
42
|
-
const jsonPath = path.resolve(apiJsonDirPath, `${ctx.pkg.version}.json`)
|
|
43
|
-
|
|
44
|
-
if (transformed.length) {
|
|
45
|
-
await fs.writeFile(jsonPath, JSON.stringify(transformed, null, 2) + '\n')
|
|
46
|
-
|
|
47
|
-
console.log(chalk.gray('result '), path.relative(ctx.cwd, jsonPath))
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './_extractTask'
|
package/src/build/tasks/index.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
2
|
-
import json from '@rollup/plugin-json'
|
|
3
|
-
import {nodeResolve} from '@rollup/plugin-node-resolve'
|
|
4
|
-
import {InputOptions, OutputOptions} from 'rollup'
|
|
5
|
-
import esbuild from 'rollup-plugin-esbuild'
|
|
6
|
-
import {_BuildContext} from '../../_types'
|
|
7
|
-
import {_RollupTask} from './rollup'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export function _resolveRollupConfig(
|
|
13
|
-
ctx: _BuildContext,
|
|
14
|
-
buildTask: _RollupTask
|
|
15
|
-
): {
|
|
16
|
-
inputOptions: InputOptions
|
|
17
|
-
outputOptions: OutputOptions
|
|
18
|
-
} {
|
|
19
|
-
const {format, runtime, target} = buildTask
|
|
20
|
-
const {cwd, external, dist: outDir, pkg, tsconfig} = ctx
|
|
21
|
-
const outputExt = format === 'commonjs' ? '.cjs' : pkg.type === 'module' ? '.mjs' : '.js'
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
inputOptions: {
|
|
25
|
-
context: cwd,
|
|
26
|
-
|
|
27
|
-
external,
|
|
28
|
-
|
|
29
|
-
input: buildTask.entries.reduce<{[entryAlias: string]: string}>((acc, entry) => {
|
|
30
|
-
const key = entry.path === '.' ? 'index' : entry.path.slice(2)
|
|
31
|
-
|
|
32
|
-
return {...acc, [key]: entry.source || ''}
|
|
33
|
-
}, {}),
|
|
34
|
-
|
|
35
|
-
plugins: [
|
|
36
|
-
nodeResolve({
|
|
37
|
-
mainFields: ['module', 'jsnext', 'main'],
|
|
38
|
-
browser: runtime !== 'node',
|
|
39
|
-
exportConditions: [runtime === 'node' ? 'node' : 'browser'],
|
|
40
|
-
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.json', '.node'],
|
|
41
|
-
preferBuiltins: runtime === 'node',
|
|
42
|
-
}),
|
|
43
|
-
commonjs({
|
|
44
|
-
esmExternals: false,
|
|
45
|
-
include: /\/node_modules\//,
|
|
46
|
-
// requireReturnsDefault: 'namespace',
|
|
47
|
-
}),
|
|
48
|
-
json(),
|
|
49
|
-
esbuild({
|
|
50
|
-
// include: /\.[jt]sx?$/, // default, inferred from `loaders` option
|
|
51
|
-
// exclude: /node_modules/, // default
|
|
52
|
-
// sourceMap: false, // by default inferred from rollup's `output.sourcemap` option
|
|
53
|
-
minify: false, // process.env.NODE_ENV === 'production',
|
|
54
|
-
// target: 'es2017', // default, or 'es20XX', 'esnext'
|
|
55
|
-
jsx: 'transform', // default, or 'preserve'
|
|
56
|
-
jsxFactory: 'React.createElement',
|
|
57
|
-
jsxFragment: 'React.Fragment',
|
|
58
|
-
// // Like @rollup/plugin-replace
|
|
59
|
-
// define: {
|
|
60
|
-
// __VERSION__: '"x.y.z"',
|
|
61
|
-
// },
|
|
62
|
-
// plugins: [],
|
|
63
|
-
target,
|
|
64
|
-
// target:
|
|
65
|
-
// target === 'node'
|
|
66
|
-
// ? ['node12']
|
|
67
|
-
// : ['es2020', 'chrome104', 'edge104', 'firefox103', 'safari15'],
|
|
68
|
-
tsconfig: tsconfig || 'tsconfig.json', // 'tsconfig.json', // default
|
|
69
|
-
// Add extra loaders
|
|
70
|
-
loaders: {
|
|
71
|
-
// Add .json files support
|
|
72
|
-
// require @rollup/plugin-commonjs
|
|
73
|
-
'.json': 'json',
|
|
74
|
-
// Enable JSX in .js files too
|
|
75
|
-
// '.js': 'jsx',
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
],
|
|
79
|
-
|
|
80
|
-
treeshake: {
|
|
81
|
-
propertyReadSideEffects: false,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
outputOptions: {
|
|
85
|
-
chunkFileNames: () => `_[name]-[hash]${outputExt}`,
|
|
86
|
-
dir: outDir,
|
|
87
|
-
entryFileNames: () => `[name]${outputExt}`,
|
|
88
|
-
format,
|
|
89
|
-
esModule: false,
|
|
90
|
-
exports: 'auto',
|
|
91
|
-
freeze: false,
|
|
92
|
-
sourcemap: true,
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './rollup'
|