@sanity/pkg-utils 1.3.1 → 1.4.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-793a302b.cjs +75 -0
  3. package/dist/__printPackageTree-793a302b.cjs.map +1 -0
  4. package/dist/__resolveBuildContext-1b29cff2.cjs +336 -0
  5. package/dist/__resolveBuildContext-1b29cff2.cjs.map +1 -0
  6. package/dist/_build-08236974.cjs +169 -0
  7. package/dist/_build-08236974.cjs.map +1 -0
  8. package/dist/_buildAction-586dfb5f.cjs +43 -0
  9. package/dist/_buildAction-586dfb5f.cjs.map +1 -0
  10. package/dist/_check-9d180462.cjs +16 -0
  11. package/dist/_check-9d180462.cjs.map +1 -0
  12. package/dist/_index-c5bd1bc8.cjs +565 -0
  13. package/dist/_index-c5bd1bc8.cjs.map +1 -0
  14. package/dist/_statusAction-385b72dd.cjs +27 -0
  15. package/dist/_statusAction-385b72dd.cjs.map +1 -0
  16. package/dist/_watch-0623c005.cjs +217 -0
  17. package/dist/_watch-0623c005.cjs.map +1 -0
  18. package/dist/_watchAction-4b8d7301.cjs +42 -0
  19. package/dist/_watchAction-4b8d7301.cjs.map +1 -0
  20. package/dist/cli.cjs +14 -31
  21. package/dist/cli.cjs.map +1 -1
  22. package/dist/index.cjs +41 -16
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +278 -152
  25. package/dist/index.js +947 -5201
  26. package/dist/index.js.map +1 -1
  27. package/package.json +24 -9
  28. package/src/cli/buildAction.ts +8 -0
  29. package/src/cli/index.ts +41 -0
  30. package/src/cli/statusAction.ts +8 -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 +54 -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 +20 -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 +46 -0
  66. package/src/node/_tasks/dts/_dtsTask.ts +38 -0
  67. package/src/node/_tasks/dts/_dtsWatchTask.ts +43 -0
  68. package/src/node/_tasks/dts/_extractTypes.ts +161 -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 +71 -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 +14 -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,278 @@
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: {cwd: string; tsconfig?: string}): Promise<void>
54
+
55
+ /** @internal */
56
+ export declare const _DEFAULTS: {
57
+ browserslist: string[]
58
+ }
59
+
60
+ /** @public */
61
+ export declare function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions
62
+
63
+ /** @internal */
64
+ export declare interface _DtsResult {
65
+ type: 'dts'
66
+ messages: ExtractorMessage[]
67
+ }
68
+
69
+ /** @internal */
70
+ export declare interface _DtsTask {
71
+ type: 'build:dts'
72
+ exportPath: string
73
+ importId: string
74
+ source: string
75
+ output: string
76
+ }
77
+
78
+ /** @internal */
79
+ export declare const _dtsTask: _TaskHandler<_DtsTask, _DtsResult>
80
+
81
+ /** @internal */
82
+ export declare interface _DtsWatchTask {
83
+ type: 'watch:dts'
84
+ exportPath: string
85
+ importId: string
86
+ source: string
87
+ output: string
88
+ }
89
+
90
+ /** @internal */
91
+ export declare const _dtsWatchTask: _TaskHandler<_DtsWatchTask, _DtsResult>
92
+
93
+ /** @internal */
94
+ export declare function _isRecord(value: unknown): value is Record<string, unknown>
95
+
96
+ /** @internal */
97
+ export declare function _loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined>
98
+
99
+ /** @internal */
100
+ export declare function _loadPkg(options: {cwd: string}): Promise<_PackageJSON>
101
+
102
+ /** @internal */
103
+ export declare function _loadPkgWithReporting(options: {cwd: string}): Promise<_PackageJSON>
104
+
105
+ /** @internal */
106
+ export declare function _loadTSConfig(options: {
107
+ cwd: string
108
+ tsconfigPath: string
109
+ }): Promise<ts.ParsedCommandLine>
110
+
111
+ /** @internal */
112
+ export declare interface _PackageJSON {
113
+ type?: 'module'
114
+ version: string
115
+ private?: boolean
116
+ name: string
117
+ bin?: Record<string, string>
118
+ dependencies?: Record<string, string>
119
+ devDependencies?: Record<string, string>
120
+ peerDependencies?: Record<string, string>
121
+ exports?: Record<
122
+ string,
123
+ {
124
+ source: string
125
+ browser?: {
126
+ require?: string
127
+ import?: string
128
+ }
129
+ require?: string
130
+ import?: string
131
+ types?: string
132
+ }
133
+ >
134
+ main?: string
135
+ browser?: Record<string, string>
136
+ source: string
137
+ module?: string
138
+ types?: string
139
+ browserslist?: string[]
140
+ }
141
+
142
+ /** @internal */
143
+ export declare function _parseExports(options: {pkg: _PackageJSON}): (PkgExport & {
144
+ _path: string
145
+ })[]
146
+
147
+ /** @public */
148
+ export declare interface PkgConfigOptions {
149
+ /**
150
+ * Directory of distributed & bundled files.
151
+ */
152
+ dist?: string
153
+ exports?: PkgConfigProperty<PkgExports>
154
+ extract?: {
155
+ rules?: {
156
+ 'ae-forgotten-export'?: PkgRuleLevel
157
+ 'ae-incompatible-release-tags'?: PkgRuleLevel
158
+ 'ae-internal-missing-underscore'?: PkgRuleLevel
159
+ 'ae-missing-release-tag'?: PkgRuleLevel
160
+ }
161
+ }
162
+ /**
163
+ * Packages to exclude from the bundles.
164
+ */
165
+ external?: PkgConfigProperty<string[]>
166
+ minify?: boolean
167
+ /**
168
+ * Default runtime of package exports
169
+ */
170
+ runtime?: PkgRuntime
171
+ sourcemap?: boolean
172
+ /**
173
+ * Directory of source files.
174
+ */
175
+ src?: string
176
+ }
177
+
178
+ /** @public */
179
+ export declare type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T
180
+
181
+ /** @public */
182
+ export declare type PkgConfigPropertyResolver<T> = (prev: T) => T
183
+
184
+ /** @public */
185
+ export declare interface PkgExport {
186
+ /** @internal */
187
+ _exported?: boolean
188
+ browser?: {
189
+ source?: string
190
+ import?: string
191
+ require?: string
192
+ }
193
+ import?: string
194
+ require?: string
195
+ source: string
196
+ types?: string
197
+ }
198
+
199
+ /** @public */
200
+ export declare interface PkgExports {
201
+ [path: string]: PkgExport
202
+ }
203
+
204
+ /** @public */
205
+ export declare type PkgFormat = 'commonjs' | 'esm'
206
+
207
+ /** @public */
208
+ export declare type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off'
209
+
210
+ /** @public */
211
+ export declare type PkgRuntime = '*' | 'browser' | 'node'
212
+
213
+ /** @internal */
214
+ export declare function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[]
215
+
216
+ /** @internal */
217
+ export declare function _resolveConfigProperty<T>(
218
+ prop: PkgConfigProperty<T> | undefined,
219
+ initialValue: T
220
+ ): T
221
+
222
+ /** @internal */
223
+ export declare interface _RollupTask {
224
+ type: 'build:js'
225
+ buildId: string
226
+ entries: _RollupTaskEntry[]
227
+ runtime: PkgRuntime
228
+ format: 'commonjs' | 'esm'
229
+ target: string[]
230
+ }
231
+
232
+ /** @internal */
233
+ export declare const _rollupTask: _TaskHandler<_RollupTask>
234
+
235
+ /** @internal */
236
+ export declare interface _RollupTaskEntry {
237
+ path: string
238
+ source: string
239
+ output: string
240
+ }
241
+
242
+ /** @internal */
243
+ export declare interface _RollupWatchTask {
244
+ type: 'watch:js'
245
+ buildId: string
246
+ entries: _RollupTaskEntry[]
247
+ runtime: PkgRuntime
248
+ format: 'commonjs' | 'esm'
249
+ target: string[]
250
+ }
251
+
252
+ /** @internal */
253
+ export declare const _rollupWatchTask: _TaskHandler<_RollupWatchTask, RollupWatcherEvent>
254
+
255
+ /** @internal */
256
+ export declare type _TaskHandler<Task, Result = void> = {
257
+ name: (ctx: _BuildContext, task: Task) => string
258
+ exec: (ctx: _BuildContext, task: Task) => Observable<Result>
259
+ complete: (ctx: _BuildContext, task: Task, result: Result) => void
260
+ error: (ctx: _BuildContext, task: Task, error: unknown) => void
261
+ }
262
+
263
+ /** @public */
264
+ export declare function watch(options: {cwd: string; tsconfig?: string}): Promise<void>
265
+
266
+ /** @internal */
267
+ export declare type _WatchTask = _DtsWatchTask | _RollupWatchTask
268
+
269
+ /** @internal */
270
+ export declare interface _WatchTaskHandlers {
271
+ 'watch:dts': _TaskHandler<_DtsWatchTask, _DtsResult>
272
+ 'watch:js': _TaskHandler<_RollupWatchTask, RollupWatcherEvent>
273
+ }
274
+
275
+ /** @internal */
276
+ export declare const _watchTaskHandlers: _WatchTaskHandlers
277
+
278
+ export {}