@sanity/pkg-utils 1.7.2 → 1.8.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/bin/{pkg-utils → pkg-utils.cjs} +0 -0
- package/dist/{__resolveBuildContext-9b0aa9f9.cjs → __resolveBuildContext-7cb7c9a7.cjs} +59 -8
- package/dist/__resolveBuildContext-7cb7c9a7.cjs.map +1 -0
- package/dist/{_build-6e7deb31.cjs → _build-e82a508a.cjs} +24 -17
- package/dist/_build-e82a508a.cjs.map +1 -0
- package/dist/{_buildAction-d8841b41.cjs → _buildAction-727e661a.cjs} +9 -5
- package/dist/{_buildAction-d8841b41.cjs.map → _buildAction-727e661a.cjs.map} +1 -1
- package/dist/{_check-04a1f749.cjs → _check-a2eb014d.cjs} +6 -2
- package/dist/{_check-04a1f749.cjs.map → _check-a2eb014d.cjs.map} +1 -1
- package/dist/{_checkAction-09426a13.cjs → _checkAction-7cd9dfde.cjs} +3 -3
- package/dist/{_checkAction-09426a13.cjs.map → _checkAction-7cd9dfde.cjs.map} +1 -1
- package/dist/_index-a4fddb59.cjs +4244 -0
- package/dist/_index-a4fddb59.cjs.map +1 -0
- package/dist/{_watch-cf9c717f.cjs → _watch-b0a983e3.cjs} +25 -18
- package/dist/_watch-b0a983e3.cjs.map +1 -0
- package/dist/{_watchAction-5941527f.cjs → _watchAction-c44da6cb.cjs} +9 -5
- package/dist/{_watchAction-5941527f.cjs.map → _watchAction-c44da6cb.cjs.map} +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +10 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3823 -268
- package/dist/index.js.map +1 -1
- package/dist/{index.d.ts → types/src/node/index.d.ts} +24 -10
- package/package.json +13 -11
- package/src/node/_core/pkg/_loadPkg.ts +2 -41
- package/src/node/_core/pkg/_loadPkgWithReporting.ts +1 -1
- package/src/node/_core/pkg/_parseExports.ts +26 -3
- package/src/node/_core/pkg/_types.ts +8 -2
- package/src/node/_core/pkg/_validateExports.ts +29 -0
- package/src/node/_core/pkg/_validatePkg.ts +50 -0
- package/src/node/_resolveBuildTasks.ts +18 -14
- package/src/node/_resolveWatchTasks.ts +19 -15
- package/src/node/_tasks/dts/_buildTypes.ts +2 -25
- package/src/node/_tasks/dts/_doExtract.ts +59 -27
- package/src/node/_tasks/dts/_dtsTask.ts +4 -1
- package/src/node/_tasks/dts/_dtsWatchTask.ts +4 -1
- package/src/node/_tasks/dts/_types.ts +13 -8
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +30 -3
- package/dist/__resolveBuildContext-9b0aa9f9.cjs.map +0 -1
- package/dist/_build-6e7deb31.cjs.map +0 -1
- package/dist/_index-46cab21c.cjs +0 -736
- package/dist/_index-46cab21c.cjs.map +0 -1
- package/dist/_watch-cf9c717f.cjs.map +0 -1
|
@@ -68,15 +68,21 @@ export declare function defineConfig(configOptions: PkgConfigOptions): PkgConfig
|
|
|
68
68
|
export declare interface _DtsResult {
|
|
69
69
|
type: 'dts'
|
|
70
70
|
messages: ExtractorMessage[]
|
|
71
|
+
results: {
|
|
72
|
+
sourcePath: string
|
|
73
|
+
filePath: string
|
|
74
|
+
}[]
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
/** @internal */
|
|
74
78
|
export declare interface _DtsTask {
|
|
75
79
|
type: 'build:dts'
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
entries: {
|
|
81
|
+
exportPath: string
|
|
82
|
+
importId: string
|
|
83
|
+
sourcePath: string
|
|
84
|
+
targetPath: string
|
|
85
|
+
}[]
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
/** @internal */
|
|
@@ -85,10 +91,12 @@ export declare const _dtsTask: _TaskHandler<_DtsTask, _DtsResult>
|
|
|
85
91
|
/** @internal */
|
|
86
92
|
export declare interface _DtsWatchTask {
|
|
87
93
|
type: 'watch:dts'
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
entries: {
|
|
95
|
+
exportPath: string
|
|
96
|
+
importId: string
|
|
97
|
+
sourcePath: string
|
|
98
|
+
targetPath: string
|
|
99
|
+
}[]
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
/** @internal */
|
|
@@ -114,7 +122,7 @@ export declare function _loadTSConfig(options: {
|
|
|
114
122
|
|
|
115
123
|
/** @internal */
|
|
116
124
|
export declare interface _PackageJSON {
|
|
117
|
-
type
|
|
125
|
+
type: 'commonjs' | 'module'
|
|
118
126
|
version: string
|
|
119
127
|
private?: boolean
|
|
120
128
|
name: string
|
|
@@ -128,6 +136,12 @@ export declare interface _PackageJSON {
|
|
|
128
136
|
source: string
|
|
129
137
|
types?: string
|
|
130
138
|
browser?: {
|
|
139
|
+
source: string
|
|
140
|
+
require?: string
|
|
141
|
+
import?: string
|
|
142
|
+
}
|
|
143
|
+
node?: {
|
|
144
|
+
source: string
|
|
131
145
|
require?: string
|
|
132
146
|
import?: string
|
|
133
147
|
}
|
|
@@ -138,7 +152,7 @@ export declare interface _PackageJSON {
|
|
|
138
152
|
>
|
|
139
153
|
main?: string
|
|
140
154
|
browser?: Record<string, string>
|
|
141
|
-
source
|
|
155
|
+
source?: string
|
|
142
156
|
module?: string
|
|
143
157
|
types?: string
|
|
144
158
|
browserslist?: string[]
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0",
|
|
4
5
|
"author": "Sanity.io <hello@sanity.io>",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"description": "Simple utilities for modern npm packages.",
|
|
@@ -16,10 +17,10 @@
|
|
|
16
17
|
"source": "./src/node/index.ts",
|
|
17
18
|
"main": "./dist/index.cjs",
|
|
18
19
|
"module": "./dist/index.js",
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
|
+
"types": "./dist/types/src/node/index.d.ts",
|
|
20
21
|
"exports": {
|
|
21
22
|
".": {
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
|
+
"types": "./dist/types/src/node/index.d.ts",
|
|
23
24
|
"source": "./src/node/index.ts",
|
|
24
25
|
"import": "./dist/index.js",
|
|
25
26
|
"require": "./dist/index.cjs",
|
|
@@ -27,8 +28,8 @@
|
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
30
|
"bin": {
|
|
30
|
-
"pkg": "./bin/pkg-utils",
|
|
31
|
-
"pkg-utils": "./bin/pkg-utils"
|
|
31
|
+
"pkg": "./bin/pkg-utils.cjs",
|
|
32
|
+
"pkg-utils": "./bin/pkg-utils.cjs"
|
|
32
33
|
},
|
|
33
34
|
"files": [
|
|
34
35
|
"bin",
|
|
@@ -36,19 +37,20 @@
|
|
|
36
37
|
"dist"
|
|
37
38
|
],
|
|
38
39
|
"scripts": {
|
|
39
|
-
"build": "node -
|
|
40
|
-
"check:package": "node -r esbuild-register scripts/check",
|
|
40
|
+
"build": "node --experimental-loader ./scripts/_experimental-loader.js --no-warnings -r esbuild-register scripts/build",
|
|
41
|
+
"check:package": "node --experimental-loader ./scripts/_experimental-loader.js --no-warnings -r esbuild-register scripts/check",
|
|
41
42
|
"clean": "rimraf dist test/env/__tmp__",
|
|
42
43
|
"commit": "cz",
|
|
43
44
|
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
44
45
|
"format": "prettier --write --cache --ignore-unknown .",
|
|
45
46
|
"lint": "eslint . --ext .cjs,.js,.ts",
|
|
47
|
+
"postbuild": "pnpm run check:package",
|
|
46
48
|
"prebuild": "pnpm run clean",
|
|
47
49
|
"prepublishOnly": "pnpm run build",
|
|
48
50
|
"release": "semantic-release",
|
|
49
51
|
"test": "vitest run",
|
|
50
52
|
"type-check": "tsc --build",
|
|
51
|
-
"watch": "node -r esbuild-register scripts/watch"
|
|
53
|
+
"watch": "node --experimental-loader ./scripts/_experimental-loader.js --no-warnings -r esbuild-register scripts/watch"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
56
|
"@babel/core": "^7.19.0",
|
|
@@ -66,6 +68,7 @@
|
|
|
66
68
|
"cac": "^6.7.12",
|
|
67
69
|
"chalk": "^4.1.2",
|
|
68
70
|
"chokidar": "^3.5.3",
|
|
71
|
+
"cpx": "^1.5.0",
|
|
69
72
|
"esbuild": "^0.15.5",
|
|
70
73
|
"esbuild-register": "^3.3.3",
|
|
71
74
|
"find-config": "^1.0.0",
|
|
@@ -75,7 +78,6 @@
|
|
|
75
78
|
"pkg-up": "^3.1.0",
|
|
76
79
|
"prettier": "^2.7.1",
|
|
77
80
|
"pretty-bytes": "^5.6.0",
|
|
78
|
-
"rimraf": "^3.0.2",
|
|
79
81
|
"rollup": "^2.78.1",
|
|
80
82
|
"rollup-plugin-esbuild": "^4.9.3",
|
|
81
83
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -88,9 +90,9 @@
|
|
|
88
90
|
"@commitlint/cli": "^17.0.3",
|
|
89
91
|
"@commitlint/config-conventional": "^17.0.3",
|
|
90
92
|
"@sanity/semantic-release-preset": "^2.0.0",
|
|
93
|
+
"@types/babel__core": "^7.1.19",
|
|
91
94
|
"@types/cpx": "^1.5.2",
|
|
92
95
|
"@types/find-config": "^1.0.1",
|
|
93
|
-
"@types/globby": "^9.1.0",
|
|
94
96
|
"@types/mkdirp": "^1.0.2",
|
|
95
97
|
"@types/node": "^18.7.13",
|
|
96
98
|
"@types/prettier": "^2.7.0",
|
|
@@ -100,7 +102,6 @@
|
|
|
100
102
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
101
103
|
"@typescript-eslint/parser": "^5.35.1",
|
|
102
104
|
"commitizen": "^4.2.5",
|
|
103
|
-
"cpx": "^1.5.0",
|
|
104
105
|
"cz-conventional-changelog": "^3.3.0",
|
|
105
106
|
"eslint": "^8.23.0",
|
|
106
107
|
"eslint-config-prettier": "^8.5.0",
|
|
@@ -108,6 +109,7 @@
|
|
|
108
109
|
"eslint-plugin-prettier": "^4.2.1",
|
|
109
110
|
"husky": "^8.0.1",
|
|
110
111
|
"lint-staged": "^12.5.0",
|
|
112
|
+
"rimraf": "^3.0.2",
|
|
111
113
|
"semantic-release": "^19.0.5",
|
|
112
114
|
"ts-node": "^10.9.1",
|
|
113
115
|
"typescript": "^4.7.4",
|
|
@@ -1,46 +1,7 @@
|
|
|
1
1
|
import fs from 'fs/promises'
|
|
2
2
|
import pkgUp from 'pkg-up'
|
|
3
|
-
import {z} from 'zod'
|
|
4
3
|
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
|
-
types: z.optional(z.string()),
|
|
23
|
-
source: z.string(),
|
|
24
|
-
browser: z.optional(
|
|
25
|
-
z.object({
|
|
26
|
-
require: z.optional(z.string()),
|
|
27
|
-
import: z.optional(z.string()),
|
|
28
|
-
})
|
|
29
|
-
),
|
|
30
|
-
node: z.optional(
|
|
31
|
-
z.object({
|
|
32
|
-
require: z.optional(z.string()),
|
|
33
|
-
import: z.optional(z.string()),
|
|
34
|
-
})
|
|
35
|
-
),
|
|
36
|
-
require: z.optional(z.string()),
|
|
37
|
-
import: z.optional(z.string()),
|
|
38
|
-
default: z.string(),
|
|
39
|
-
})
|
|
40
|
-
)
|
|
41
|
-
),
|
|
42
|
-
browserslist: z.optional(z.array(z.string())),
|
|
43
|
-
})
|
|
4
|
+
import {_validatePkg} from './_validatePkg'
|
|
44
5
|
|
|
45
6
|
/** @internal */
|
|
46
7
|
export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
|
|
@@ -52,5 +13,5 @@ export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
|
|
|
52
13
|
|
|
53
14
|
const buf = await fs.readFile(pkgPath)
|
|
54
15
|
|
|
55
|
-
return
|
|
16
|
+
return _validatePkg(JSON.parse(buf.toString()))
|
|
56
17
|
}
|
|
@@ -15,7 +15,7 @@ export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_Pa
|
|
|
15
15
|
if (issue.code === 'invalid_type') {
|
|
16
16
|
console.log(
|
|
17
17
|
`${chalk.red('invalid type')} in ./package.json at ${chalk.magenta(
|
|
18
|
-
`\`${issue.path.join('')}\``
|
|
18
|
+
`\`${issue.path.join('.')}\``
|
|
19
19
|
)} (expected ${issue.expected}, received ${issue.received})`
|
|
20
20
|
)
|
|
21
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {_isRecord} from '../_isRecord'
|
|
2
2
|
import {PkgExport} from '../config'
|
|
3
3
|
import {_PackageJSON} from './_types'
|
|
4
|
+
import {_validateExports} from './_validateExports'
|
|
4
5
|
|
|
5
6
|
/** @internal */
|
|
6
7
|
export function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {_path: string})[] {
|
|
@@ -10,14 +11,14 @@ export function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {_path
|
|
|
10
11
|
_exported: true,
|
|
11
12
|
_path: '.',
|
|
12
13
|
types: pkg.types,
|
|
13
|
-
source: pkg.source || '
|
|
14
|
+
source: pkg.source || '',
|
|
14
15
|
browser: pkg.browser && {
|
|
15
16
|
require: pkg.main && pkg.browser[pkg.main],
|
|
16
17
|
import: pkg.module && pkg.browser[pkg.module],
|
|
17
18
|
},
|
|
18
19
|
import: pkg.module,
|
|
19
20
|
require: pkg.main,
|
|
20
|
-
default: pkg.module || pkg.main || '
|
|
21
|
+
default: pkg.module || pkg.main || '',
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const extraExports: (PkgExport & {_path: string})[] = []
|
|
@@ -26,6 +27,26 @@ export function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {_path
|
|
|
26
27
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
27
28
|
if (_isRecord(exportEntry)) {
|
|
28
29
|
if (exportPath === '.') {
|
|
30
|
+
if (
|
|
31
|
+
exportEntry.require &&
|
|
32
|
+
rootExport.require &&
|
|
33
|
+
exportEntry.require !== rootExport.require
|
|
34
|
+
) {
|
|
35
|
+
throw new Error('mismatch between "main" and "require"')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
|
|
39
|
+
throw new Error('mismatch between "module" and "import"')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
|
|
43
|
+
throw new Error('mismatch between "types" and "types"')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
|
|
47
|
+
throw new Error('mismatch between "source" and "source"')
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
Object.assign(rootExport, exportEntry)
|
|
30
51
|
} else {
|
|
31
52
|
const extraExport: PkgExport & {_path: string} = {
|
|
@@ -42,5 +63,7 @@ export function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {_path
|
|
|
42
63
|
}
|
|
43
64
|
}
|
|
44
65
|
|
|
45
|
-
|
|
66
|
+
const _exports = [rootExport, ...extraExports]
|
|
67
|
+
|
|
68
|
+
return _validateExports(_exports, {pkg})
|
|
46
69
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @internal */
|
|
2
2
|
export interface _PackageJSON {
|
|
3
|
-
type
|
|
3
|
+
type: 'commonjs' | 'module'
|
|
4
4
|
version: string
|
|
5
5
|
private?: boolean
|
|
6
6
|
name: string
|
|
@@ -14,6 +14,12 @@ export interface _PackageJSON {
|
|
|
14
14
|
source: string
|
|
15
15
|
types?: string
|
|
16
16
|
browser?: {
|
|
17
|
+
source: string
|
|
18
|
+
require?: string
|
|
19
|
+
import?: string
|
|
20
|
+
}
|
|
21
|
+
node?: {
|
|
22
|
+
source: string
|
|
17
23
|
require?: string
|
|
18
24
|
import?: string
|
|
19
25
|
}
|
|
@@ -24,7 +30,7 @@ export interface _PackageJSON {
|
|
|
24
30
|
>
|
|
25
31
|
main?: string
|
|
26
32
|
browser?: Record<string, string>
|
|
27
|
-
source
|
|
33
|
+
source?: string
|
|
28
34
|
module?: string
|
|
29
35
|
types?: string
|
|
30
36
|
browserslist?: string[]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {PkgExport} from '../config'
|
|
2
|
+
import {_PackageJSON} from './_types'
|
|
3
|
+
|
|
4
|
+
export function _validateExports(
|
|
5
|
+
_exports: (PkgExport & {_path: string})[],
|
|
6
|
+
options: {pkg: _PackageJSON}
|
|
7
|
+
): (PkgExport & {_path: string})[] {
|
|
8
|
+
const {pkg} = options
|
|
9
|
+
|
|
10
|
+
for (const exp of _exports) {
|
|
11
|
+
if (pkg.type === 'commonjs') {
|
|
12
|
+
if (exp.require && !exp.require.endsWith('.js')) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`package.json with \`"type": "commonjs"\` - \`exports["${exp._path}"].require\` must end with ".js"`
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (pkg.type === 'module') {
|
|
20
|
+
if (exp.require && !exp.require.endsWith('.cjs')) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`package.json with \`"type": "module"\` - \`exports["${exp._path}"].require\` must end with ".cjs"`
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return _exports
|
|
29
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {z} from 'zod'
|
|
2
|
+
import {_PackageJSON} from './_types'
|
|
3
|
+
|
|
4
|
+
const pkgSchema = z.object({
|
|
5
|
+
type: z.optional(z.enum(['commonjs', 'module'])),
|
|
6
|
+
name: z.string(),
|
|
7
|
+
version: z.string(),
|
|
8
|
+
license: z.string(),
|
|
9
|
+
bin: z.optional(z.record(z.string())),
|
|
10
|
+
dependencies: z.optional(z.record(z.string())),
|
|
11
|
+
devDependencies: z.optional(z.record(z.string())),
|
|
12
|
+
peerDependencies: z.optional(z.record(z.string())),
|
|
13
|
+
source: z.optional(z.string()),
|
|
14
|
+
main: z.optional(z.string()),
|
|
15
|
+
browser: z.optional(z.record(z.string())),
|
|
16
|
+
module: z.optional(z.string()),
|
|
17
|
+
types: z.optional(z.string()),
|
|
18
|
+
exports: z.optional(
|
|
19
|
+
z.record(
|
|
20
|
+
z.object({
|
|
21
|
+
types: z.optional(z.string()),
|
|
22
|
+
source: z.string(),
|
|
23
|
+
browser: z.optional(
|
|
24
|
+
z.object({
|
|
25
|
+
source: z.string(),
|
|
26
|
+
require: z.optional(z.string()),
|
|
27
|
+
import: z.optional(z.string()),
|
|
28
|
+
})
|
|
29
|
+
),
|
|
30
|
+
node: z.optional(
|
|
31
|
+
z.object({
|
|
32
|
+
source: z.string(),
|
|
33
|
+
require: z.optional(z.string()),
|
|
34
|
+
import: z.optional(z.string()),
|
|
35
|
+
})
|
|
36
|
+
),
|
|
37
|
+
require: z.optional(z.string()),
|
|
38
|
+
import: z.optional(z.string()),
|
|
39
|
+
default: z.string(),
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
),
|
|
43
|
+
browserslist: z.optional(z.array(z.string())),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export function _validatePkg(input: unknown): _PackageJSON {
|
|
47
|
+
const pkg = pkgSchema.parse(input)
|
|
48
|
+
|
|
49
|
+
return {...pkg, type: pkg.type || 'commonjs'}
|
|
50
|
+
}
|
|
@@ -13,13 +13,19 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
13
13
|
([_path, exp]) => ({_path, ...exp} as PkgExport & {_path: string})
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const dtsTask: _DtsTask = {
|
|
17
|
+
type: 'build:dts',
|
|
18
|
+
entries: [],
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
const rollupTasks: Record<string, _RollupTask> = {}
|
|
18
22
|
|
|
19
23
|
function _addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: _RollupTaskEntry) {
|
|
20
24
|
const buildId = `${format}:${runtime}`
|
|
21
25
|
|
|
22
|
-
if (
|
|
26
|
+
if (rollupTasks[buildId]) {
|
|
27
|
+
rollupTasks[buildId].entries.push(entry)
|
|
28
|
+
} else {
|
|
23
29
|
rollupTasks[buildId] = {
|
|
24
30
|
type: 'build:js',
|
|
25
31
|
buildId,
|
|
@@ -28,8 +34,6 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
28
34
|
format,
|
|
29
35
|
target: target[runtime],
|
|
30
36
|
}
|
|
31
|
-
} else {
|
|
32
|
-
rollupTasks[buildId].entries.push(entry)
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -38,15 +42,12 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
38
42
|
const importId = path.join(pkg.name, exp._path)
|
|
39
43
|
|
|
40
44
|
if (exp.types) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
targetPath: exp.types,
|
|
48
|
-
}
|
|
49
|
-
}
|
|
45
|
+
dtsTask.entries.push({
|
|
46
|
+
importId,
|
|
47
|
+
exportPath: exp._path,
|
|
48
|
+
sourcePath: exp.source,
|
|
49
|
+
targetPath: exp.types,
|
|
50
|
+
})
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -102,7 +103,10 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
102
103
|
})
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
if (dtsTask.entries.length) {
|
|
107
|
+
tasks.push(dtsTask)
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
tasks.push(...Object.values(rollupTasks))
|
|
107
111
|
|
|
108
112
|
// Parse rollup:esm:browser tasks
|
|
@@ -12,13 +12,19 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
12
12
|
([_path, exp]) => ({_path, ...exp} as PkgExport & {_path: string})
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const dtsTask: _DtsWatchTask = {
|
|
16
|
+
type: 'watch:dts',
|
|
17
|
+
entries: [],
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
const rollupTasks: Record<string, _RollupWatchTask> = {}
|
|
17
21
|
|
|
18
22
|
function _addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: _RollupTaskEntry) {
|
|
19
23
|
const buildId = `${format}:${runtime}`
|
|
20
24
|
|
|
21
|
-
if (
|
|
25
|
+
if (rollupTasks[buildId]) {
|
|
26
|
+
rollupTasks[buildId].entries.push(entry)
|
|
27
|
+
} else {
|
|
22
28
|
rollupTasks[buildId] = {
|
|
23
29
|
type: 'watch:js',
|
|
24
30
|
buildId,
|
|
@@ -27,8 +33,6 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
27
33
|
format,
|
|
28
34
|
target: target[runtime],
|
|
29
35
|
}
|
|
30
|
-
} else {
|
|
31
|
-
rollupTasks[buildId].entries.push(entry)
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -37,15 +41,12 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
37
41
|
const importId = path.join(pkg.name, exp._path)
|
|
38
42
|
|
|
39
43
|
if (exp.types) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
targetPath: exp.types,
|
|
47
|
-
}
|
|
48
|
-
}
|
|
44
|
+
dtsTask.entries.push({
|
|
45
|
+
importId,
|
|
46
|
+
exportPath: exp._path,
|
|
47
|
+
sourcePath: exp.source,
|
|
48
|
+
targetPath: exp.types,
|
|
49
|
+
})
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -101,7 +102,10 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
101
102
|
})
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
if (dtsTask.entries.length) {
|
|
106
|
+
tasks.push(dtsTask)
|
|
107
|
+
}
|
|
108
|
+
|
|
105
109
|
tasks.push(...Object.values(rollupTasks))
|
|
106
110
|
|
|
107
111
|
// Parse rollup:esm:browser tasks
|
|
@@ -115,7 +119,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
115
119
|
[
|
|
116
120
|
`// AUTO-GENERATED – DO NOT EDIT`,
|
|
117
121
|
``,
|
|
118
|
-
`export {default} from '${relativeTargetPath}'`,
|
|
122
|
+
// `export {default} from '${relativeTargetPath}'`,
|
|
119
123
|
`export * from '${relativeTargetPath}'`,
|
|
120
124
|
``,
|
|
121
125
|
].join('\n')
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
|
-
import path from 'path'
|
|
4
3
|
import ts from 'typescript'
|
|
5
4
|
|
|
6
5
|
export const formatHost: ts.FormatDiagnosticsHost = {
|
|
@@ -13,10 +12,9 @@ export const formatHost: ts.FormatDiagnosticsHost = {
|
|
|
13
12
|
export async function _buildTypes(options: {
|
|
14
13
|
cwd: string
|
|
15
14
|
outDir: string
|
|
16
|
-
sourcePath: string
|
|
17
15
|
tsconfig: ts.ParsedCommandLine
|
|
18
|
-
}): Promise<
|
|
19
|
-
const {
|
|
16
|
+
}): Promise<void> {
|
|
17
|
+
const {outDir, tsconfig} = options
|
|
20
18
|
|
|
21
19
|
const compilerOptions: ts.CompilerOptions = {
|
|
22
20
|
...tsconfig.options,
|
|
@@ -27,23 +25,8 @@ export async function _buildTypes(options: {
|
|
|
27
25
|
outDir,
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
const rootDir =
|
|
31
|
-
path.relative(
|
|
32
|
-
cwd,
|
|
33
|
-
compilerOptions.rootDir
|
|
34
|
-
? path.resolve(cwd, compilerOptions.rootDir)
|
|
35
|
-
: path.dirname(path.resolve(cwd, sourcePath))
|
|
36
|
-
) || '.'
|
|
37
|
-
|
|
38
28
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions)
|
|
39
29
|
|
|
40
|
-
const sourceFiles = program.getSourceFiles()
|
|
41
|
-
const sourceFile = sourceFiles.find((f) => f.fileName === path.resolve(cwd, sourcePath))
|
|
42
|
-
|
|
43
|
-
if (!sourceFile) {
|
|
44
|
-
throw new Error(`source file not found: ${sourcePath}`)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
30
|
const emitResult = program.emit()
|
|
48
31
|
|
|
49
32
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
|
|
@@ -68,10 +51,4 @@ export async function _buildTypes(options: {
|
|
|
68
51
|
throw new Error('failed to compile')
|
|
69
52
|
}
|
|
70
53
|
}
|
|
71
|
-
|
|
72
|
-
const typesPath = path
|
|
73
|
-
.resolve(outDir, path.relative(rootDir, path.resolve(cwd, sourcePath)))
|
|
74
|
-
.replace(/\.[jt]sx?$/, '.d.ts')
|
|
75
|
-
|
|
76
|
-
return {path: typesPath}
|
|
77
54
|
}
|