@sanity/pkg-utils 5.0.7 → 5.0.8-canary.1
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-cjs/index.cjs +29 -2
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.d.cts +535 -0
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/package.json +28 -24
- package/src/node/printExtractMessages.ts +2 -2
- package/src/node/tasks/dts/buildTypes.ts +12 -1
- package/src/node/tasks/dts/createApiExtractorConfig.ts +23 -3
- package/src/node/tasks/dts/doExtract.ts +1 -0
- package/src/node/tasks/dts/extractModuleBlocks.ts +2 -2
- package/src/node/tasks/dts/extractTypes.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.8-canary.1",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
28
|
"source": "./src/node/index.ts",
|
|
30
29
|
"import": "./dist/index.js",
|
|
31
30
|
"require": "./dist/index.cjs",
|
|
@@ -47,6 +46,23 @@
|
|
|
47
46
|
"!dist/stats.html",
|
|
48
47
|
"src"
|
|
49
48
|
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "run-s clean build:pkg check:pkg",
|
|
51
|
+
"build:pkg": "node -r esbuild-register scripts/build",
|
|
52
|
+
"check:pkg": "node -r esbuild-register scripts/check",
|
|
53
|
+
"check:types": "tsc --build",
|
|
54
|
+
"clean": "rimraf dist test/env/__tmp__",
|
|
55
|
+
"commit": "cz",
|
|
56
|
+
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
57
|
+
"format": "prettier --write --cache --ignore-unknown . && eslint . --ext .cjs,.js,.ts,.tsx --fix --quiet",
|
|
58
|
+
"lint": "eslint . --ext .cjs,.js,.ts,.tsx",
|
|
59
|
+
"playground:build": "pnpm --filter './playground/**' build",
|
|
60
|
+
"playground:clean": "pnpm --filter './playground/**' --silent clean",
|
|
61
|
+
"test": "run-s playground:clean test:clean vitest:run",
|
|
62
|
+
"test:clean": "rimraf test/env/__tmp__",
|
|
63
|
+
"vitest:run": "vitest run",
|
|
64
|
+
"watch": "node -r esbuild-register scripts/watch"
|
|
65
|
+
},
|
|
50
66
|
"commitlint": {
|
|
51
67
|
"extends": [
|
|
52
68
|
"@commitlint/config-conventional"
|
|
@@ -62,7 +78,7 @@
|
|
|
62
78
|
"dependencies": {
|
|
63
79
|
"@babel/core": "^7.24.1",
|
|
64
80
|
"@babel/types": "^7.24.0",
|
|
65
|
-
"@microsoft/api-extractor": "
|
|
81
|
+
"@microsoft/api-extractor": "7.43.0",
|
|
66
82
|
"@microsoft/tsdoc-config": "^0.16.2",
|
|
67
83
|
"@rollup/plugin-alias": "^5.1.0",
|
|
68
84
|
"@rollup/plugin-babel": "^6.0.4",
|
|
@@ -102,6 +118,7 @@
|
|
|
102
118
|
"devDependencies": {
|
|
103
119
|
"@commitlint/cli": "^19.2.1",
|
|
104
120
|
"@commitlint/config-conventional": "^19.1.0",
|
|
121
|
+
"@sanity/pkg-utils": "workspace:*",
|
|
105
122
|
"@types/babel__core": "^7.20.5",
|
|
106
123
|
"@types/cpx": "^1.5.5",
|
|
107
124
|
"@types/find-config": "^1.0.4",
|
|
@@ -130,13 +147,12 @@
|
|
|
130
147
|
"recast": "^0.23.6",
|
|
131
148
|
"rollup-plugin-visualizer": "^5.12.0",
|
|
132
149
|
"ts-node": "^10.9.2",
|
|
133
|
-
"typescript": "
|
|
150
|
+
"typescript": "5.4.2",
|
|
134
151
|
"vitest": "^1.4.0",
|
|
135
|
-
"vitest-github-actions-reporter": "^0.11.1"
|
|
136
|
-
"@sanity/pkg-utils": "5.0.7"
|
|
152
|
+
"vitest-github-actions-reporter": "^0.11.1"
|
|
137
153
|
},
|
|
138
154
|
"peerDependencies": {
|
|
139
|
-
"typescript": "
|
|
155
|
+
"typescript": "5.4.2"
|
|
140
156
|
},
|
|
141
157
|
"packageManager": "pnpm@8.15.5",
|
|
142
158
|
"engines": {
|
|
@@ -145,21 +161,9 @@
|
|
|
145
161
|
"publishConfig": {
|
|
146
162
|
"access": "public"
|
|
147
163
|
},
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
"check:types": "tsc --build",
|
|
153
|
-
"clean": "rimraf dist test/env/__tmp__",
|
|
154
|
-
"commit": "cz",
|
|
155
|
-
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
156
|
-
"format": "prettier --write --cache --ignore-unknown . && eslint . --ext .cjs,.js,.ts,.tsx --fix --quiet",
|
|
157
|
-
"lint": "eslint . --ext .cjs,.js,.ts,.tsx",
|
|
158
|
-
"playground:build": "pnpm --filter './playground/**' build",
|
|
159
|
-
"playground:clean": "pnpm --filter './playground/**' --silent clean",
|
|
160
|
-
"test": "run-s playground:clean test:clean vitest:run",
|
|
161
|
-
"test:clean": "rimraf test/env/__tmp__",
|
|
162
|
-
"vitest:run": "vitest run",
|
|
163
|
-
"watch": "node -r esbuild-register scripts/watch"
|
|
164
|
+
"pnpm": {
|
|
165
|
+
"overrides": {
|
|
166
|
+
"@sanity/pkg-utils": "workspace:*"
|
|
167
|
+
}
|
|
164
168
|
}
|
|
165
|
-
}
|
|
169
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
1
|
+
import type {ExtractorMessage} from '@microsoft/api-extractor'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
5
|
-
import {BuildContext} from './core'
|
|
5
|
+
import type {BuildContext} from './core'
|
|
6
6
|
|
|
7
7
|
export function printExtractMessages(ctx: BuildContext, messages: ExtractorMessage[]): void {
|
|
8
8
|
const {cwd, logger} = ctx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript'
|
|
2
2
|
|
|
3
|
-
import {Logger} from '../../logger'
|
|
3
|
+
import type {Logger} from '../../logger'
|
|
4
4
|
import {printDiagnostic} from './printDiagnostic'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
@@ -20,6 +20,17 @@ export async function buildTypes(options: {
|
|
|
20
20
|
emitDeclarationOnly: true,
|
|
21
21
|
noEmit: false,
|
|
22
22
|
outDir,
|
|
23
|
+
// Support the new `module: 'preserve'` option in TypeScript 5.4
|
|
24
|
+
...(tsconfig.options.module === ts.ModuleKind.Preserve
|
|
25
|
+
? {
|
|
26
|
+
// Set the equivalent options to `module: 'Preserve'`
|
|
27
|
+
// https://github.com/microsoft/TypeScript/pull/56785/files?file-filters%5B%5D=.js&file-filters%5B%5D=.json&file-filters%5B%5D=.symbols&file-filters%5B%5D=.ts&file-filters%5B%5D=.types&show-viewed-files=true#diff-31d3c12bafea26bc9e8c8a77920c41af0c593206442add70c45a06c063767445
|
|
28
|
+
module: ts.ModuleKind.ESNext,
|
|
29
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
30
|
+
esModuleInterop: true,
|
|
31
|
+
resolveJsonModule: true,
|
|
32
|
+
}
|
|
33
|
+
: {}),
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
2
2
|
import path from 'path'
|
|
3
|
+
import ts from 'typescript'
|
|
3
4
|
|
|
4
5
|
export function createApiExtractorConfig(options: {
|
|
5
6
|
bundledPackages?: string[]
|
|
@@ -9,6 +10,7 @@ export function createApiExtractorConfig(options: {
|
|
|
9
10
|
messages: IExtractorMessagesConfig
|
|
10
11
|
projectFolder: string
|
|
11
12
|
mainEntryPointFilePath: string
|
|
13
|
+
tsconfig: ts.ParsedCommandLine
|
|
12
14
|
tsconfigPath: string
|
|
13
15
|
}): IConfigFile {
|
|
14
16
|
const {
|
|
@@ -19,6 +21,7 @@ export function createApiExtractorConfig(options: {
|
|
|
19
21
|
messages,
|
|
20
22
|
projectFolder,
|
|
21
23
|
mainEntryPointFilePath,
|
|
24
|
+
tsconfig,
|
|
22
25
|
tsconfigPath,
|
|
23
26
|
} = options
|
|
24
27
|
|
|
@@ -28,9 +31,26 @@ export function createApiExtractorConfig(options: {
|
|
|
28
31
|
reportFileName: '<unscopedPackageName>.api.md',
|
|
29
32
|
},
|
|
30
33
|
bundledPackages,
|
|
31
|
-
compiler:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
compiler:
|
|
35
|
+
tsconfig.options.module === ts.ModuleKind.Preserve
|
|
36
|
+
? {
|
|
37
|
+
// When the module is 'preserve' it's necessary to override the tsconfig file as api-extractor doesn't handle it out of the box
|
|
38
|
+
overrideTsconfig: {
|
|
39
|
+
extends: tsconfigPath,
|
|
40
|
+
compilerOptions: {
|
|
41
|
+
// Set the equivalent options to `module: 'Preserve'`
|
|
42
|
+
// https://github.com/microsoft/TypeScript/pull/56785/files?file-filters%5B%5D=.js&file-filters%5B%5D=.json&file-filters%5B%5D=.symbols&file-filters%5B%5D=.ts&file-filters%5B%5D=.types&show-viewed-files=true#diff-31d3c12bafea26bc9e8c8a77920c41af0c593206442add70c45a06c063767445
|
|
43
|
+
module: 'ESNext',
|
|
44
|
+
moduleResolution: 'Bundler',
|
|
45
|
+
esModuleInterop: true,
|
|
46
|
+
resolveJsonModule: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
: {
|
|
51
|
+
// If the module is not 'preserve', use the tsconfig file directly
|
|
52
|
+
tsconfigFilePath: tsconfigPath,
|
|
53
|
+
},
|
|
34
54
|
docModel: {
|
|
35
55
|
enabled: false,
|
|
36
56
|
apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {File} from '@babel/types'
|
|
2
|
-
import {ExtractorResult} from '@microsoft/api-extractor'
|
|
2
|
+
import type {ExtractorResult} from '@microsoft/api-extractor'
|
|
3
3
|
import {parse, print} from 'recast'
|
|
4
4
|
import typeScriptParser from 'recast/parsers/typescript'
|
|
5
|
-
import {Program} from 'typescript'
|
|
5
|
+
import type {Program} from 'typescript'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A workaround to find all module blocks in extract TS files.
|
|
@@ -8,6 +8,7 @@ import fs from 'fs/promises'
|
|
|
8
8
|
import {mkdirp} from 'mkdirp'
|
|
9
9
|
import path from 'path'
|
|
10
10
|
import prettier from 'prettier'
|
|
11
|
+
import ts from 'typescript'
|
|
11
12
|
|
|
12
13
|
import type {BuildFile, PkgConfigOptions} from '../../core'
|
|
13
14
|
import {createApiExtractorConfig} from './createApiExtractorConfig'
|
|
@@ -27,6 +28,7 @@ export async function extractTypes(options: {
|
|
|
27
28
|
rules?: NonNullable<PkgConfigOptions['extract']>['rules']
|
|
28
29
|
sourceTypesPath: string
|
|
29
30
|
tmpPath: string
|
|
31
|
+
tsconfig: ts.ParsedCommandLine
|
|
30
32
|
tsconfigPath: string
|
|
31
33
|
}): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
|
|
32
34
|
const {
|
|
@@ -40,6 +42,7 @@ export async function extractTypes(options: {
|
|
|
40
42
|
rules,
|
|
41
43
|
sourceTypesPath,
|
|
42
44
|
tmpPath,
|
|
45
|
+
tsconfig,
|
|
43
46
|
tsconfigPath,
|
|
44
47
|
} = options
|
|
45
48
|
|
|
@@ -56,6 +59,7 @@ export async function extractTypes(options: {
|
|
|
56
59
|
messages: getExtractMessagesConfig({rules}),
|
|
57
60
|
projectFolder: projectPath,
|
|
58
61
|
mainEntryPointFilePath: sourceTypesPath,
|
|
62
|
+
tsconfig,
|
|
59
63
|
tsconfigPath,
|
|
60
64
|
}),
|
|
61
65
|
configObjectFullPath: undefined,
|