@sanity/pkg-utils 5.0.6 → 5.0.8-canary.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-cjs/index.cjs +29 -2
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/package.json +27 -21
- 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.0",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -47,6 +47,24 @@
|
|
|
47
47
|
"!dist/stats.html",
|
|
48
48
|
"src"
|
|
49
49
|
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "run-s clean build:pkg check:pkg",
|
|
52
|
+
"build:pkg": "node -r esbuild-register scripts/build",
|
|
53
|
+
"check:pkg": "node -r esbuild-register scripts/check",
|
|
54
|
+
"check:types": "tsc --build",
|
|
55
|
+
"clean": "rimraf dist test/env/__tmp__",
|
|
56
|
+
"commit": "cz",
|
|
57
|
+
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
58
|
+
"format": "prettier --write --cache --ignore-unknown . && eslint . --ext .cjs,.js,.ts,.tsx --fix --quiet",
|
|
59
|
+
"lint": "eslint . --ext .cjs,.js,.ts,.tsx",
|
|
60
|
+
"playground:build": "pnpm --filter './playground/**' build",
|
|
61
|
+
"playground:clean": "pnpm --filter './playground/**' --silent clean",
|
|
62
|
+
"prepublishOnly": "pnpm run build",
|
|
63
|
+
"test": "run-s playground:clean test:clean vitest:run",
|
|
64
|
+
"test:clean": "rimraf test/env/__tmp__",
|
|
65
|
+
"vitest:run": "vitest run",
|
|
66
|
+
"watch": "node -r esbuild-register scripts/watch"
|
|
67
|
+
},
|
|
50
68
|
"commitlint": {
|
|
51
69
|
"extends": [
|
|
52
70
|
"@commitlint/config-conventional"
|
|
@@ -60,7 +78,7 @@
|
|
|
60
78
|
},
|
|
61
79
|
"browserslist": "extends @sanity/browserslist-config",
|
|
62
80
|
"dependencies": {
|
|
63
|
-
"@babel/core": "^7.24.
|
|
81
|
+
"@babel/core": "^7.24.1",
|
|
64
82
|
"@babel/types": "^7.24.0",
|
|
65
83
|
"@microsoft/api-extractor": "^7.43.0",
|
|
66
84
|
"@microsoft/tsdoc-config": "^0.16.2",
|
|
@@ -102,6 +120,7 @@
|
|
|
102
120
|
"devDependencies": {
|
|
103
121
|
"@commitlint/cli": "^19.2.1",
|
|
104
122
|
"@commitlint/config-conventional": "^19.1.0",
|
|
123
|
+
"@sanity/pkg-utils": "workspace:*",
|
|
105
124
|
"@types/babel__core": "^7.20.5",
|
|
106
125
|
"@types/cpx": "^1.5.5",
|
|
107
126
|
"@types/find-config": "^1.0.4",
|
|
@@ -132,8 +151,7 @@
|
|
|
132
151
|
"ts-node": "^10.9.2",
|
|
133
152
|
"typescript": "^5.4.2",
|
|
134
153
|
"vitest": "^1.4.0",
|
|
135
|
-
"vitest-github-actions-reporter": "^0.11.1"
|
|
136
|
-
"@sanity/pkg-utils": "5.0.6"
|
|
154
|
+
"vitest-github-actions-reporter": "^0.11.1"
|
|
137
155
|
},
|
|
138
156
|
"peerDependencies": {
|
|
139
157
|
"typescript": "^4.7 || ^5"
|
|
@@ -145,21 +163,9 @@
|
|
|
145
163
|
"publishConfig": {
|
|
146
164
|
"access": "public"
|
|
147
165
|
},
|
|
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"
|
|
166
|
+
"pnpm": {
|
|
167
|
+
"overrides": {
|
|
168
|
+
"@sanity/pkg-utils": "workspace:*"
|
|
169
|
+
}
|
|
164
170
|
}
|
|
165
|
-
}
|
|
171
|
+
}
|
|
@@ -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,
|