@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.
Files changed (104) hide show
  1. package/README.md +8 -0
  2. package/dist/__printPackageTree-3ff3ecd3.cjs +76 -0
  3. package/dist/__printPackageTree-3ff3ecd3.cjs.map +1 -0
  4. package/dist/__resolveBuildContext-85cfca8d.cjs +337 -0
  5. package/dist/__resolveBuildContext-85cfca8d.cjs.map +1 -0
  6. package/dist/_build-683d9922.cjs +168 -0
  7. package/dist/_build-683d9922.cjs.map +1 -0
  8. package/dist/_buildAction-f593323a.cjs +44 -0
  9. package/dist/_buildAction-f593323a.cjs.map +1 -0
  10. package/dist/_check-6843c26d.cjs +118 -0
  11. package/dist/_check-6843c26d.cjs.map +1 -0
  12. package/dist/_checkAction-0bca6a14.cjs +29 -0
  13. package/dist/_checkAction-0bca6a14.cjs.map +1 -0
  14. package/dist/_index-5765fada.cjs +584 -0
  15. package/dist/_index-5765fada.cjs.map +1 -0
  16. package/dist/_watch-ec1b35d6.cjs +217 -0
  17. package/dist/_watch-ec1b35d6.cjs.map +1 -0
  18. package/dist/_watchAction-a388fc00.cjs +43 -0
  19. package/dist/_watchAction-a388fc00.cjs.map +1 -0
  20. package/dist/cli.cjs +14 -31
  21. package/dist/cli.cjs.map +1 -1
  22. package/dist/index.cjs +43 -16
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +282 -152
  25. package/dist/index.js +1055 -5198
  26. package/dist/index.js.map +1 -1
  27. package/package.json +37 -10
  28. package/src/cli/buildAction.ts +8 -0
  29. package/src/cli/checkAction.ts +9 -0
  30. package/src/cli/index.ts +42 -0
  31. package/src/cli/watchAction.ts +8 -0
  32. package/src/{core → node/_core}/_defaults.ts +1 -3
  33. package/src/{core → node/_core}/_isRecord.ts +1 -3
  34. package/src/{core → node/_core}/config/_loadConfig.ts +1 -3
  35. package/src/node/_core/config/_resolveConfigProperty.ts +15 -0
  36. package/src/{core → node/_core}/config/defineConfig.ts +1 -3
  37. package/src/{core → node/_core}/config/index.ts +0 -0
  38. package/src/node/_core/config/types.ts +69 -0
  39. package/src/node/_core/contexts/buildContext.ts +34 -0
  40. package/src/node/_core/contexts/index.ts +1 -0
  41. package/src/{core → node/_core}/index.ts +2 -0
  42. package/src/node/_core/pkg/_loadPkg.ts +55 -0
  43. package/src/node/_core/pkg/_loadPkgWithReporting.ts +29 -0
  44. package/src/node/_core/pkg/_parseExports.ts +45 -0
  45. package/src/{core → node/_core}/pkg/_types.ts +16 -5
  46. package/src/{core → node/_core}/pkg/index.ts +1 -0
  47. package/src/{build/tasks/dts → node/_core/ts}/_loadTSConfig.ts +1 -0
  48. package/src/node/_core/ts/index.ts +1 -0
  49. package/src/node/_getFilesize.ts +8 -0
  50. package/src/node/_globFiles.ts +5 -0
  51. package/src/node/_printExtractMessages.ts +56 -0
  52. package/src/node/_printPackageTree.ts +72 -0
  53. package/src/{build/_parseWebTarget.ts → node/_resolveBrowserTarget.ts} +2 -2
  54. package/src/{build/_parseBrowserslistVersions.ts → node/_resolveBrowserslistVersions.ts} +1 -1
  55. package/src/node/_resolveBuildContext.ts +104 -0
  56. package/src/node/_resolveBuildTasks.ts +129 -0
  57. package/src/{build/_parseNodeTarget.ts → node/_resolveNodeTarget.ts} +2 -2
  58. package/src/node/_resolveWatchTasks.ts +129 -0
  59. package/src/node/_spinner.ts +26 -0
  60. package/src/node/_tasks/_types.ts +57 -0
  61. package/src/node/_tasks/dts/_DtsError.ts +11 -0
  62. package/src/{build/tasks → node/_tasks}/dts/_buildTypes.ts +30 -16
  63. package/src/node/_tasks/dts/_createApiExtractorConfig.ts +41 -0
  64. package/src/{build/tasks → node/_tasks}/dts/_createTSDocConfig.ts +2 -6
  65. package/src/node/_tasks/dts/_doExtract.ts +57 -0
  66. package/src/node/_tasks/dts/_dtsTask.ts +40 -0
  67. package/src/node/_tasks/dts/_dtsWatchTask.ts +43 -0
  68. package/src/node/_tasks/dts/_extractTypes.ts +164 -0
  69. package/src/node/_tasks/dts/_types.ts +25 -0
  70. package/src/node/_tasks/dts/index.ts +3 -0
  71. package/src/node/_tasks/index.ts +19 -0
  72. package/src/node/_tasks/rollup/_resolveRollupConfig.ts +132 -0
  73. package/src/node/_tasks/rollup/_rollupTask.ts +73 -0
  74. package/src/node/_tasks/rollup/_rollupWatchTask.ts +78 -0
  75. package/src/node/_tasks/rollup/index.ts +2 -0
  76. package/src/node/_watchConfigFiles.ts +52 -0
  77. package/src/node/_watchFiles.ts +29 -0
  78. package/src/node/build.ts +47 -0
  79. package/src/node/check.ts +136 -0
  80. package/src/node/index.ts +6 -0
  81. package/src/node/watch.ts +56 -0
  82. package/dist/_build-5bf997de.cjs +0 -5549
  83. package/dist/_build-5bf997de.cjs.map +0 -1
  84. package/src/build/_parseTasks.ts +0 -87
  85. package/src/build/_types.ts +0 -26
  86. package/src/build/build.ts +0 -101
  87. package/src/build/index.ts +0 -2
  88. package/src/build/tasks/_types.ts +0 -8
  89. package/src/build/tasks/dts/_createApiExtractorConfig.ts +0 -88
  90. package/src/build/tasks/dts/_extractTypes.ts +0 -100
  91. package/src/build/tasks/dts/dts.ts +0 -59
  92. package/src/build/tasks/dts/index.ts +0 -1
  93. package/src/build/tasks/extract/_extractTask.ts +0 -49
  94. package/src/build/tasks/extract/index.ts +0 -1
  95. package/src/build/tasks/index.ts +0 -4
  96. package/src/build/tasks/rollup/_resolveRollupConfig.ts +0 -95
  97. package/src/build/tasks/rollup/index.ts +0 -1
  98. package/src/build/tasks/rollup/rollup.ts +0 -96
  99. package/src/cli.ts +0 -25
  100. package/src/core/config/_resolveConfigProperty.ts +0 -14
  101. package/src/core/config/types.ts +0 -52
  102. package/src/core/pkg/_loadPkg.ts +0 -13
  103. package/src/core/pkg/_parseExports.ts +0 -40
  104. package/src/index.ts +0 -2
package/dist/index.d.ts CHANGED
@@ -1,152 +1,282 @@
1
- /**
2
- * @public
3
- */
4
- export declare function build(options: {
5
- cwd: string;
6
- extract?: boolean;
7
- tsconfig?: string;
8
- }): Promise<void>;
9
-
10
- /**
11
- * @internal
12
- */
13
- export declare interface _BuildContext {
14
- config?: PkgConfigOptions;
15
- cwd: string;
16
- exports: PackageExports | undefined;
17
- external: string[];
18
- extract: boolean;
19
- files: _BuildFile[];
20
- dist: string;
21
- pkg: _PackageJSON;
22
- src: string;
23
- target: {
24
- node: string[];
25
- web: string[];
26
- };
27
- tsconfig?: string;
28
- }
29
-
30
- /**
31
- * @internal
32
- */
33
- export declare interface _BuildFile {
34
- type: 'asset' | 'chunk' | 'types';
35
- path: string;
36
- }
37
-
38
- /**
39
- * @public
40
- */
41
- export declare type ConfigProperty<T> = ConfigPropertyResolver<T> | T;
42
-
43
- /**
44
- * @public
45
- */
46
- export declare type ConfigPropertyResolver<T> = (prev: T) => T;
47
-
48
- /**
49
- * @internal
50
- */
51
- export declare const _DEFAULTS: {
52
- browserslist: string[];
53
- };
54
-
55
- /**
56
- * @public
57
- */
58
- export declare function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions;
59
-
60
- /**
61
- * @internal
62
- */
63
- export declare function _isRecord(value: unknown): value is Record<string, unknown>;
64
-
65
- /**
66
- * @internal
67
- */
68
- export declare function _loadConfig(options: {
69
- cwd: string;
70
- }): Promise<PkgConfigOptions | undefined>;
71
-
72
- /**
73
- * @internal
74
- */
75
- export declare function _loadPkg(options: {
76
- cwd: string;
77
- }): Promise<_PackageJSON>;
78
-
79
- /**
80
- * @public
81
- */
82
- export declare interface PackageExports {
83
- [path: string]: PackageSubPathExportEntry;
84
- }
85
-
86
- /**
87
- * @internal
88
- */
89
- export declare interface _PackageJSON {
90
- type?: 'module';
91
- version: string;
92
- private?: boolean;
93
- name: string;
94
- bin?: Record<string, string>;
95
- dependencies?: Record<string, string>;
96
- devDependencies?: Record<string, string>;
97
- peerDependencies?: Record<string, string>;
98
- exports?: Record<string, string | Record<string, string>>;
99
- main?: string;
100
- source?: string;
101
- module?: string;
102
- types?: string;
103
- browserslist?: string[];
104
- }
105
-
106
- /**
107
- * @public
108
- */
109
- export declare interface PackageSubPathExportEntry {
110
- runtime?: 'node' | 'web';
111
- source: string;
112
- require?: string;
113
- default?: string;
114
- types?: string;
115
- }
116
-
117
- /**
118
- * @internal
119
- */
120
- export declare function _parseExports(pkg: _PackageJSON): (PackageSubPathExportEntry & {
121
- path: string;
122
- })[];
123
-
124
- /**
125
- * @public
126
- */
127
- export declare interface PkgConfigOptions {
128
- /**
129
- * Directory of distributed & bundled files.
130
- */
131
- dist?: string;
132
- exports?: ConfigProperty<PackageExports>;
133
- /**
134
- * Packages to exclude from the bundles.
135
- */
136
- external?: ConfigProperty<string[]>;
137
- /**
138
- * Default runtime of package exports
139
- */
140
- runtime?: 'node' | 'web';
141
- /**
142
- * Directory of source files.
143
- */
144
- src?: string;
145
- }
146
-
147
- /**
148
- * @internal
149
- */
150
- export declare function _resolveConfigProperty<T>(prop: ConfigProperty<T> | undefined, initialValue: T): T;
151
-
152
- export { }
1
+ import {ExtractorMessage} from '@microsoft/api-extractor'
2
+ import {Observable} from 'rxjs'
3
+ import {RollupWatcherEvent} from 'rollup'
4
+ import ts from 'typescript'
5
+
6
+ /** @public */
7
+ export declare function build(options: {cwd: string; tsconfig?: string}): Promise<void>
8
+
9
+ /** @internal */
10
+ export declare interface _BuildContext {
11
+ config?: PkgConfigOptions
12
+ cwd: string
13
+ dist: string
14
+ exports: PkgExports | undefined
15
+ external: string[]
16
+ files: _BuildFile[]
17
+ logger: {
18
+ log: (...args: unknown[]) => void
19
+ info: (...args: unknown[]) => void
20
+ warn: (...args: unknown[]) => void
21
+ error: (...args: unknown[]) => void
22
+ success: (...args: unknown[]) => void
23
+ }
24
+ pkg: _PackageJSON
25
+ runtime: PkgRuntime
26
+ src: string
27
+ target: Record<PkgRuntime, string[]>
28
+ ts: {
29
+ config?: ts.ParsedCommandLine
30
+ configPath?: string
31
+ }
32
+ }
33
+
34
+ /** @internal */
35
+ export declare interface _BuildFile {
36
+ type: 'asset' | 'chunk' | 'types'
37
+ path: string
38
+ }
39
+
40
+ /** @internal */
41
+ export declare type _BuildTask = _DtsTask | _RollupTask
42
+
43
+ /** @internal */
44
+ export declare interface _BuildTaskHandlers {
45
+ 'build:dts': _TaskHandler<_DtsTask, _DtsResult>
46
+ 'build:js': _TaskHandler<_RollupTask>
47
+ }
48
+
49
+ /** @internal */
50
+ export declare const _buildTaskHandlers: _BuildTaskHandlers
51
+
52
+ /** @public */
53
+ export declare function check(options: {
54
+ cwd: string
55
+ strict?: boolean
56
+ tsconfig?: string
57
+ }): Promise<void>
58
+
59
+ /** @internal */
60
+ export declare const _DEFAULTS: {
61
+ browserslist: string[]
62
+ }
63
+
64
+ /** @public */
65
+ export declare function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions
66
+
67
+ /** @internal */
68
+ export declare interface _DtsResult {
69
+ type: 'dts'
70
+ messages: ExtractorMessage[]
71
+ }
72
+
73
+ /** @internal */
74
+ export declare interface _DtsTask {
75
+ type: 'build:dts'
76
+ exportPath: string
77
+ importId: string
78
+ sourcePath: string
79
+ targetPath: string
80
+ }
81
+
82
+ /** @internal */
83
+ export declare const _dtsTask: _TaskHandler<_DtsTask, _DtsResult>
84
+
85
+ /** @internal */
86
+ export declare interface _DtsWatchTask {
87
+ type: 'watch:dts'
88
+ exportPath: string
89
+ importId: string
90
+ sourcePath: string
91
+ targetPath: string
92
+ }
93
+
94
+ /** @internal */
95
+ export declare const _dtsWatchTask: _TaskHandler<_DtsWatchTask, _DtsResult>
96
+
97
+ /** @internal */
98
+ export declare function _isRecord(value: unknown): value is Record<string, unknown>
99
+
100
+ /** @internal */
101
+ export declare function _loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined>
102
+
103
+ /** @internal */
104
+ export declare function _loadPkg(options: {cwd: string}): Promise<_PackageJSON>
105
+
106
+ /** @internal */
107
+ export declare function _loadPkgWithReporting(options: {cwd: string}): Promise<_PackageJSON>
108
+
109
+ /** @internal */
110
+ export declare function _loadTSConfig(options: {
111
+ cwd: string
112
+ tsconfigPath: string
113
+ }): Promise<ts.ParsedCommandLine>
114
+
115
+ /** @internal */
116
+ export declare interface _PackageJSON {
117
+ type?: 'module'
118
+ version: string
119
+ private?: boolean
120
+ name: string
121
+ bin?: Record<string, string>
122
+ dependencies?: Record<string, string>
123
+ devDependencies?: Record<string, string>
124
+ peerDependencies?: Record<string, string>
125
+ exports?: Record<
126
+ string,
127
+ {
128
+ source: string
129
+ browser?: {
130
+ require?: string
131
+ import?: string
132
+ }
133
+ require?: string
134
+ import?: string
135
+ types?: string
136
+ }
137
+ >
138
+ main?: string
139
+ browser?: Record<string, string>
140
+ source: string
141
+ module?: string
142
+ types?: string
143
+ browserslist?: string[]
144
+ }
145
+
146
+ /** @internal */
147
+ export declare function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {
148
+ _path: string
149
+ })[]
150
+
151
+ /** @public */
152
+ export declare interface PkgConfigOptions {
153
+ /**
154
+ * Directory of distributed & bundled files.
155
+ */
156
+ dist?: string
157
+ exports?: PkgConfigProperty<PkgExports>
158
+ extract?: {
159
+ rules?: {
160
+ 'ae-forgotten-export'?: PkgRuleLevel
161
+ 'ae-incompatible-release-tags'?: PkgRuleLevel
162
+ 'ae-internal-missing-underscore'?: PkgRuleLevel
163
+ 'ae-missing-release-tag'?: PkgRuleLevel
164
+ }
165
+ }
166
+ /**
167
+ * Packages to exclude from the bundles.
168
+ */
169
+ external?: PkgConfigProperty<string[]>
170
+ minify?: boolean
171
+ /**
172
+ * Default runtime of package exports
173
+ */
174
+ runtime?: PkgRuntime
175
+ sourcemap?: boolean
176
+ /**
177
+ * Directory of source files.
178
+ */
179
+ src?: string
180
+ }
181
+
182
+ /** @public */
183
+ export declare type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T
184
+
185
+ /** @public */
186
+ export declare type PkgConfigPropertyResolver<T> = (prev: T) => T
187
+
188
+ /** @public */
189
+ export declare interface PkgExport {
190
+ /** @internal */
191
+ _exported?: boolean
192
+ browser?: {
193
+ source?: string
194
+ import?: string
195
+ require?: string
196
+ }
197
+ import?: string
198
+ require?: string
199
+ source: string
200
+ types?: string
201
+ }
202
+
203
+ /** @public */
204
+ export declare interface PkgExports {
205
+ [path: string]: PkgExport
206
+ }
207
+
208
+ /** @public */
209
+ export declare type PkgFormat = 'commonjs' | 'esm'
210
+
211
+ /** @public */
212
+ export declare type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off'
213
+
214
+ /** @public */
215
+ export declare type PkgRuntime = '*' | 'browser' | 'node'
216
+
217
+ /** @internal */
218
+ export declare function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[]
219
+
220
+ /** @internal */
221
+ export declare function _resolveConfigProperty<T>(
222
+ prop: PkgConfigProperty<T> | undefined,
223
+ initialValue: T
224
+ ): T
225
+
226
+ /** @internal */
227
+ export declare interface _RollupTask {
228
+ type: 'build:js'
229
+ buildId: string
230
+ entries: _RollupTaskEntry[]
231
+ runtime: PkgRuntime
232
+ format: 'commonjs' | 'esm'
233
+ target: string[]
234
+ }
235
+
236
+ /** @internal */
237
+ export declare const _rollupTask: _TaskHandler<_RollupTask>
238
+
239
+ /** @internal */
240
+ export declare interface _RollupTaskEntry {
241
+ path: string
242
+ source: string
243
+ output: string
244
+ }
245
+
246
+ /** @internal */
247
+ export declare interface _RollupWatchTask {
248
+ type: 'watch:js'
249
+ buildId: string
250
+ entries: _RollupTaskEntry[]
251
+ runtime: PkgRuntime
252
+ format: 'commonjs' | 'esm'
253
+ target: string[]
254
+ }
255
+
256
+ /** @internal */
257
+ export declare const _rollupWatchTask: _TaskHandler<_RollupWatchTask, RollupWatcherEvent>
258
+
259
+ /** @internal */
260
+ export declare type _TaskHandler<Task, Result = void> = {
261
+ name: (ctx: _BuildContext, task: Task) => string
262
+ exec: (ctx: _BuildContext, task: Task) => Observable<Result>
263
+ complete: (ctx: _BuildContext, task: Task, result: Result) => void
264
+ error: (ctx: _BuildContext, task: Task, error: unknown) => void
265
+ }
266
+
267
+ /** @public */
268
+ export declare function watch(options: {cwd: string; tsconfig?: string}): Promise<void>
269
+
270
+ /** @internal */
271
+ export declare type _WatchTask = _DtsWatchTask | _RollupWatchTask
272
+
273
+ /** @internal */
274
+ export declare interface _WatchTaskHandlers {
275
+ 'watch:dts': _TaskHandler<_DtsWatchTask, _DtsResult>
276
+ 'watch:js': _TaskHandler<_RollupWatchTask, RollupWatcherEvent>
277
+ }
278
+
279
+ /** @internal */
280
+ export declare const _watchTaskHandlers: _WatchTaskHandlers
281
+
282
+ export {}