@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": "Sanity.io <hello@sanity.io>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Simple utilities for modern npm packages.",
|
|
@@ -13,53 +13,69 @@
|
|
|
13
13
|
"build",
|
|
14
14
|
"bundling"
|
|
15
15
|
],
|
|
16
|
-
"source": "./src/index.ts",
|
|
16
|
+
"source": "./src/node/index.ts",
|
|
17
17
|
"main": "./dist/index.cjs",
|
|
18
18
|
"module": "./dist/index.js",
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
|
-
"
|
|
22
|
+
"source": "./src/node/index.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
23
24
|
"require": "./dist/index.cjs",
|
|
24
25
|
"types": "./dist/index.d.ts"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
"bin": {
|
|
29
|
+
"pkg": "./bin/pkg-utils",
|
|
28
30
|
"pkg-utils": "./bin/pkg-utils"
|
|
29
31
|
},
|
|
30
32
|
"files": [
|
|
33
|
+
"bin",
|
|
31
34
|
"src",
|
|
32
35
|
"dist"
|
|
33
36
|
],
|
|
34
37
|
"scripts": {
|
|
35
|
-
"build": "node -r esbuild-register
|
|
38
|
+
"build": "node -r esbuild-register scripts/build",
|
|
39
|
+
"check:package": "node -r esbuild-register scripts/check",
|
|
40
|
+
"commit": "cz",
|
|
41
|
+
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
36
42
|
"format": "prettier --write --cache --ignore-unknown .",
|
|
37
43
|
"lint": "eslint . --ext .cjs,.js,.ts",
|
|
38
44
|
"prebuild": "rimraf dist",
|
|
39
45
|
"prepublishOnly": "pnpm run build",
|
|
40
46
|
"release": "semantic-release",
|
|
41
|
-
"test": "vitest run",
|
|
42
|
-
"type-check": "tsc --
|
|
47
|
+
"test": "node -r esbuild-register scripts/check && vitest run",
|
|
48
|
+
"type-check": "tsc --build",
|
|
49
|
+
"watch": "node -r esbuild-register scripts/watch"
|
|
43
50
|
},
|
|
44
51
|
"dependencies": {
|
|
45
52
|
"@microsoft/api-extractor": "^7.29.5",
|
|
46
53
|
"@microsoft/tsdoc-config": "^0.16.1",
|
|
54
|
+
"@rollup/plugin-alias": "^3.1.9",
|
|
47
55
|
"@rollup/plugin-commonjs": "^22.0.2",
|
|
48
56
|
"@rollup/plugin-json": "^4.1.0",
|
|
49
57
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
50
|
-
"@
|
|
58
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
51
59
|
"browserslist": "^4.21.3",
|
|
52
60
|
"cac": "^6.7.12",
|
|
53
61
|
"chalk": "^4.1.2",
|
|
62
|
+
"chokidar": "^3.5.3",
|
|
54
63
|
"esbuild": "^0.15.5",
|
|
55
64
|
"esbuild-register": "^3.3.3",
|
|
56
65
|
"find-config": "^1.0.0",
|
|
66
|
+
"globby": "^11.1.0",
|
|
57
67
|
"jsonc-parser": "^3.1.0",
|
|
58
68
|
"mkdirp": "^1.0.4",
|
|
69
|
+
"ora": "^5.4.1",
|
|
59
70
|
"pkg-up": "^3.1.0",
|
|
71
|
+
"prettier": "^2.7.1",
|
|
72
|
+
"pretty-bytes": "^5.6.0",
|
|
60
73
|
"rimraf": "^3.0.2",
|
|
61
74
|
"rollup": "^2.78.1",
|
|
62
|
-
"rollup-plugin-esbuild": "^4.9.3"
|
|
75
|
+
"rollup-plugin-esbuild": "^4.9.3",
|
|
76
|
+
"rxjs": "^7.5.6",
|
|
77
|
+
"treeify": "^1.1.0",
|
|
78
|
+
"zod": "^3.18.0"
|
|
63
79
|
},
|
|
64
80
|
"devDependencies": {
|
|
65
81
|
"@commitlint/cli": "^17.0.3",
|
|
@@ -67,21 +83,24 @@
|
|
|
67
83
|
"@sanity/semantic-release-preset": "^2.0.0",
|
|
68
84
|
"@types/cpx": "^1.5.2",
|
|
69
85
|
"@types/find-config": "^1.0.1",
|
|
86
|
+
"@types/globby": "^9.1.0",
|
|
70
87
|
"@types/mkdirp": "^1.0.2",
|
|
71
88
|
"@types/node": "^18.7.13",
|
|
89
|
+
"@types/prettier": "^2.7.0",
|
|
72
90
|
"@types/rimraf": "^3.0.2",
|
|
73
91
|
"@types/tmp": "^0.2.3",
|
|
92
|
+
"@types/treeify": "^1.0.0",
|
|
74
93
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
75
94
|
"@typescript-eslint/parser": "^5.35.1",
|
|
76
95
|
"commitizen": "^4.2.5",
|
|
77
96
|
"cpx": "^1.5.0",
|
|
97
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
78
98
|
"eslint": "^8.23.0",
|
|
79
99
|
"eslint-config-prettier": "^8.5.0",
|
|
80
100
|
"eslint-plugin-import": "^2.26.0",
|
|
81
101
|
"eslint-plugin-prettier": "^4.2.1",
|
|
82
102
|
"husky": "^8.0.1",
|
|
83
103
|
"lint-staged": "^12.5.0",
|
|
84
|
-
"prettier": "^2.7.1",
|
|
85
104
|
"semantic-release": "^19.0.5",
|
|
86
105
|
"tmp": "^0.2.1",
|
|
87
106
|
"ts-node": "^10.9.1",
|
|
@@ -91,6 +110,11 @@
|
|
|
91
110
|
"peerDependencies": {
|
|
92
111
|
"typescript": "^4.7"
|
|
93
112
|
},
|
|
113
|
+
"config": {
|
|
114
|
+
"commitizen": {
|
|
115
|
+
"path": "cz-conventional-changelog"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
94
118
|
"engines": {
|
|
95
119
|
"node": ">=12.0.0"
|
|
96
120
|
},
|
|
@@ -106,5 +130,8 @@
|
|
|
106
130
|
"bugs": {
|
|
107
131
|
"url": "https://github.com/sanity-io/pkg-utils/issues"
|
|
108
132
|
},
|
|
109
|
-
"homepage": "https://github.com/sanity-io/pkg-utils#readme"
|
|
133
|
+
"homepage": "https://github.com/sanity-io/pkg-utils#readme",
|
|
134
|
+
"publishConfig": {
|
|
135
|
+
"access": "public"
|
|
136
|
+
}
|
|
110
137
|
}
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import cac from 'cac'
|
|
2
|
+
import {version} from '../../package.json'
|
|
3
|
+
|
|
4
|
+
const cli = cac()
|
|
5
|
+
|
|
6
|
+
// default commands checks package status
|
|
7
|
+
cli
|
|
8
|
+
.command('', 'Check')
|
|
9
|
+
.option('--strict', 'Strict mode')
|
|
10
|
+
.option('--tsconfig [tsconfig]', '[string] tsconfig.json')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const {checkAction: statusAction} = await import('./checkAction')
|
|
13
|
+
|
|
14
|
+
return statusAction(options)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
cli
|
|
18
|
+
.command('build', 'Build package')
|
|
19
|
+
.option('--tsconfig [tsconfig]', '[string] tsconfig.json')
|
|
20
|
+
.action(async (options) => {
|
|
21
|
+
const {buildAction} = await import('./buildAction')
|
|
22
|
+
|
|
23
|
+
return buildAction(options)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
cli
|
|
27
|
+
.command('watch', 'Watch package')
|
|
28
|
+
.option('--tsconfig [tsconfig]', '[string] tsconfig.json')
|
|
29
|
+
.action(async (options) => {
|
|
30
|
+
const {watchAction} = await import('./watchAction')
|
|
31
|
+
|
|
32
|
+
return watchAction(options)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Display help message when `-h` or `--help` appears
|
|
36
|
+
cli.help()
|
|
37
|
+
|
|
38
|
+
// Display version number when `-v` or `--version` appears
|
|
39
|
+
// It's also used in help message
|
|
40
|
+
cli.version(version)
|
|
41
|
+
|
|
42
|
+
cli.parse()
|
|
@@ -4,9 +4,7 @@ import findConfig from 'find-config'
|
|
|
4
4
|
import pkgUp from 'pkg-up'
|
|
5
5
|
import {PkgConfigOptions} from './types'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
7
|
+
/** @internal */
|
|
10
8
|
export async function _loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {
|
|
11
9
|
const {cwd} = options
|
|
12
10
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {PkgConfigProperty, PkgConfigPropertyResolver} from './types'
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export function _resolveConfigProperty<T>(
|
|
5
|
+
prop: PkgConfigProperty<T> | undefined,
|
|
6
|
+
initialValue: T
|
|
7
|
+
): T {
|
|
8
|
+
if (!prop) return initialValue
|
|
9
|
+
|
|
10
|
+
if (typeof prop === 'function') {
|
|
11
|
+
return (prop as PkgConfigPropertyResolver<T>)(initialValue)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return prop
|
|
15
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** @public */
|
|
2
|
+
export type PkgFormat = 'commonjs' | 'esm'
|
|
3
|
+
|
|
4
|
+
/** @public */
|
|
5
|
+
export type PkgRuntime = '*' | 'browser' | 'node'
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
export interface PkgExport {
|
|
9
|
+
/** @internal */
|
|
10
|
+
_exported?: boolean
|
|
11
|
+
browser?: {
|
|
12
|
+
source?: string
|
|
13
|
+
import?: string
|
|
14
|
+
require?: string
|
|
15
|
+
}
|
|
16
|
+
// electron?: {
|
|
17
|
+
// node?: string
|
|
18
|
+
// default?: string
|
|
19
|
+
// }
|
|
20
|
+
import?: string
|
|
21
|
+
require?: string
|
|
22
|
+
source: string
|
|
23
|
+
types?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
export type PkgConfigPropertyResolver<T> = (prev: T) => T
|
|
28
|
+
|
|
29
|
+
/** @public */
|
|
30
|
+
export type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T
|
|
31
|
+
|
|
32
|
+
/** @public */
|
|
33
|
+
export interface PkgExports {
|
|
34
|
+
[path: string]: PkgExport
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @public */
|
|
38
|
+
export type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off'
|
|
39
|
+
|
|
40
|
+
/** @public */
|
|
41
|
+
export interface PkgConfigOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Directory of distributed & bundled files.
|
|
44
|
+
*/
|
|
45
|
+
dist?: string
|
|
46
|
+
exports?: PkgConfigProperty<PkgExports>
|
|
47
|
+
extract?: {
|
|
48
|
+
rules?: {
|
|
49
|
+
'ae-forgotten-export'?: PkgRuleLevel
|
|
50
|
+
'ae-incompatible-release-tags'?: PkgRuleLevel
|
|
51
|
+
'ae-internal-missing-underscore'?: PkgRuleLevel
|
|
52
|
+
'ae-missing-release-tag'?: PkgRuleLevel
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Packages to exclude from the bundles.
|
|
57
|
+
*/
|
|
58
|
+
external?: PkgConfigProperty<string[]>
|
|
59
|
+
minify?: boolean
|
|
60
|
+
/**
|
|
61
|
+
* Default runtime of package exports
|
|
62
|
+
*/
|
|
63
|
+
runtime?: PkgRuntime
|
|
64
|
+
sourcemap?: boolean
|
|
65
|
+
/**
|
|
66
|
+
* Directory of source files.
|
|
67
|
+
*/
|
|
68
|
+
src?: string
|
|
69
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ts from 'typescript'
|
|
2
|
+
import {PkgExports, PkgRuntime, PkgConfigOptions} from '../config'
|
|
3
|
+
import {_PackageJSON} from '../pkg'
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
6
|
+
export interface _BuildFile {
|
|
7
|
+
type: 'asset' | 'chunk' | 'types'
|
|
8
|
+
path: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export interface _BuildContext {
|
|
13
|
+
config?: PkgConfigOptions
|
|
14
|
+
cwd: string
|
|
15
|
+
dist: string
|
|
16
|
+
exports: PkgExports | undefined
|
|
17
|
+
external: string[]
|
|
18
|
+
files: _BuildFile[]
|
|
19
|
+
logger: {
|
|
20
|
+
log: (...args: unknown[]) => void
|
|
21
|
+
info: (...args: unknown[]) => void
|
|
22
|
+
warn: (...args: unknown[]) => void
|
|
23
|
+
error: (...args: unknown[]) => void
|
|
24
|
+
success: (...args: unknown[]) => void
|
|
25
|
+
}
|
|
26
|
+
pkg: _PackageJSON
|
|
27
|
+
runtime: PkgRuntime
|
|
28
|
+
src: string
|
|
29
|
+
target: Record<PkgRuntime, string[]>
|
|
30
|
+
ts: {
|
|
31
|
+
config?: ts.ParsedCommandLine
|
|
32
|
+
configPath?: string
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './buildContext'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fs from 'fs/promises'
|
|
2
|
+
import pkgUp from 'pkg-up'
|
|
3
|
+
import {z} from 'zod'
|
|
4
|
+
import {_PackageJSON} from './_types'
|
|
5
|
+
|
|
6
|
+
const pkgSchema = z.object({
|
|
7
|
+
type: z.optional(z.enum(['module'])),
|
|
8
|
+
name: z.string(),
|
|
9
|
+
version: z.string(),
|
|
10
|
+
bin: z.optional(z.record(z.string())),
|
|
11
|
+
dependencies: z.optional(z.record(z.string())),
|
|
12
|
+
devDependencies: z.optional(z.record(z.string())),
|
|
13
|
+
peerDependencies: z.optional(z.record(z.string())),
|
|
14
|
+
source: z.string(),
|
|
15
|
+
main: z.optional(z.string()),
|
|
16
|
+
browser: z.optional(z.record(z.string())),
|
|
17
|
+
module: z.optional(z.string()),
|
|
18
|
+
types: z.optional(z.string()),
|
|
19
|
+
exports: z.optional(
|
|
20
|
+
z.record(
|
|
21
|
+
z.object({
|
|
22
|
+
source: z.string(),
|
|
23
|
+
browser: z.optional(
|
|
24
|
+
z.object({
|
|
25
|
+
require: z.optional(z.string()),
|
|
26
|
+
import: z.optional(z.string()),
|
|
27
|
+
})
|
|
28
|
+
),
|
|
29
|
+
node: z.optional(
|
|
30
|
+
z.object({
|
|
31
|
+
require: z.optional(z.string()),
|
|
32
|
+
import: z.optional(z.string()),
|
|
33
|
+
})
|
|
34
|
+
),
|
|
35
|
+
require: z.optional(z.string()),
|
|
36
|
+
import: z.optional(z.string()),
|
|
37
|
+
types: z.optional(z.string()),
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
),
|
|
41
|
+
browserslist: z.optional(z.array(z.string())),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
|
|
46
|
+
const {cwd} = options
|
|
47
|
+
|
|
48
|
+
const pkgPath = await pkgUp({cwd})
|
|
49
|
+
|
|
50
|
+
if (!pkgPath) throw new Error('no package.json found')
|
|
51
|
+
|
|
52
|
+
const buf = await fs.readFile(pkgPath)
|
|
53
|
+
|
|
54
|
+
return pkgSchema.parse(JSON.parse(buf.toString()))
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import {ZodError} from 'zod'
|
|
5
|
+
import {_loadPkg} from './_loadPkg'
|
|
6
|
+
import {_PackageJSON} from './_types'
|
|
7
|
+
|
|
8
|
+
/** @internal */
|
|
9
|
+
export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_PackageJSON> {
|
|
10
|
+
try {
|
|
11
|
+
return await _loadPkg(options)
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (err instanceof ZodError) {
|
|
14
|
+
for (const issue of err.issues) {
|
|
15
|
+
if (issue.code === 'invalid_type') {
|
|
16
|
+
console.log(
|
|
17
|
+
`${chalk.red('invalid type')} in ./package.json at ${chalk.magenta(
|
|
18
|
+
`\`${issue.path.join('')}\``
|
|
19
|
+
)} (expected ${issue.expected}, received ${issue.received})`
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
console.error(err)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {_isRecord} from '../_isRecord'
|
|
2
|
+
import {PkgExport} from '../config'
|
|
3
|
+
import {_PackageJSON} from './_types'
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
6
|
+
export function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {_path: string})[] {
|
|
7
|
+
const {pkg} = options
|
|
8
|
+
|
|
9
|
+
const rootExport: PkgExport & {_path: string} = {
|
|
10
|
+
_exported: true,
|
|
11
|
+
_path: '.',
|
|
12
|
+
browser: pkg.browser && {
|
|
13
|
+
require: pkg.main && pkg.browser[pkg.main],
|
|
14
|
+
import: pkg.module && pkg.browser[pkg.module],
|
|
15
|
+
},
|
|
16
|
+
source: pkg.source || 'index.js',
|
|
17
|
+
require: pkg.main,
|
|
18
|
+
import: pkg.module,
|
|
19
|
+
types: pkg.types,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const extraExports: (PkgExport & {_path: string})[] = []
|
|
23
|
+
|
|
24
|
+
if (pkg.exports) {
|
|
25
|
+
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
26
|
+
if (_isRecord(exportEntry)) {
|
|
27
|
+
if (exportPath === '.') {
|
|
28
|
+
Object.assign(rootExport, exportEntry)
|
|
29
|
+
} else {
|
|
30
|
+
const extraExport: PkgExport & {_path: string} = {
|
|
31
|
+
_exported: true,
|
|
32
|
+
_path: exportPath,
|
|
33
|
+
...exportEntry,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
extraExports.push(extraExport)
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error('string entries are not supported')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [rootExport, ...extraExports]
|
|
45
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
1
|
+
/** @internal */
|
|
4
2
|
export interface _PackageJSON {
|
|
5
3
|
type?: 'module'
|
|
6
4
|
version: string
|
|
@@ -10,9 +8,22 @@ export interface _PackageJSON {
|
|
|
10
8
|
dependencies?: Record<string, string>
|
|
11
9
|
devDependencies?: Record<string, string>
|
|
12
10
|
peerDependencies?: Record<string, string>
|
|
13
|
-
exports?: Record<
|
|
11
|
+
exports?: Record<
|
|
12
|
+
string,
|
|
13
|
+
{
|
|
14
|
+
source: string
|
|
15
|
+
browser?: {
|
|
16
|
+
require?: string
|
|
17
|
+
import?: string
|
|
18
|
+
}
|
|
19
|
+
require?: string
|
|
20
|
+
import?: string
|
|
21
|
+
types?: string
|
|
22
|
+
}
|
|
23
|
+
>
|
|
14
24
|
main?: string
|
|
15
|
-
|
|
25
|
+
browser?: Record<string, string>
|
|
26
|
+
source: string
|
|
16
27
|
module?: string
|
|
17
28
|
types?: string
|
|
18
29
|
browserslist?: string[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './_loadTSConfig'
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import {_BuildContext} from './_core'
|
|
5
|
+
|
|
6
|
+
export function _printExtractMessages(ctx: _BuildContext, messages: ExtractorMessage[]): void {
|
|
7
|
+
const {cwd, logger} = ctx
|
|
8
|
+
|
|
9
|
+
const warnings = messages.filter((msg) => msg.logLevel === 'warning')
|
|
10
|
+
|
|
11
|
+
if (warnings.length) {
|
|
12
|
+
logger.log()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const msg of warnings) {
|
|
16
|
+
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
|
|
17
|
+
|
|
18
|
+
if (msg.messageId === 'TS6307') {
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
logger.log(
|
|
23
|
+
[
|
|
24
|
+
`${chalk.cyan(sourceFilePath || '?')}`,
|
|
25
|
+
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
26
|
+
` - ${chalk.yellow('warning')} ${chalk.gray(msg.messageId)}\n`,
|
|
27
|
+
msg.text,
|
|
28
|
+
'\n',
|
|
29
|
+
].join('')
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const errors: ExtractorMessage[] = messages.filter((msg) => msg.logLevel === 'error')
|
|
34
|
+
|
|
35
|
+
if (!warnings.length && errors.length) {
|
|
36
|
+
logger.log('')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const msg of errors) {
|
|
40
|
+
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath)
|
|
41
|
+
|
|
42
|
+
logger.log(
|
|
43
|
+
[
|
|
44
|
+
`${chalk.cyan(sourceFilePath || '?')}`,
|
|
45
|
+
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
46
|
+
` - ${chalk.red('error')} ${chalk.gray(msg.messageId)}\n`,
|
|
47
|
+
msg.text,
|
|
48
|
+
'\n',
|
|
49
|
+
].join('')
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (errors.length) {
|
|
54
|
+
process.exit(1)
|
|
55
|
+
}
|
|
56
|
+
}
|