@sanity/pkg-utils 7.2.10-canary.0 → 7.2.10-canary.2
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 +10 -105
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/resolveRolldownConfig.cjs +114 -0
- package/dist/_chunks-cjs/resolveRolldownConfig.cjs.map +1 -0
- package/dist/_chunks-es/index.js +2311 -0
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/_chunks-es/resolveRolldownConfig.js +117 -0
- package/dist/_chunks-es/resolveRolldownConfig.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/index.d.cts +486 -443
- package/dist/index.d.ts +486 -443
- package/dist/index.js +1 -2389
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/cli/buildAction.ts +0 -21
- package/src/cli/checkAction.ts +0 -14
- package/src/cli/handleError.ts +0 -11
- package/src/cli/index.ts +0 -65
- package/src/cli/initAction.ts +0 -13
- package/src/cli/watchAction.ts +0 -14
- package/src/global.ts +0 -5
- package/src/node/__snapshots__/strict.test.ts.snap +0 -154
- package/src/node/build.ts +0 -100
- package/src/node/check.ts +0 -188
- package/src/node/consoleSpy.ts +0 -39
- package/src/node/core/config/defineConfig.ts +0 -6
- package/src/node/core/config/findConfigFile.ts +0 -31
- package/src/node/core/config/index.ts +0 -4
- package/src/node/core/config/loadConfig.ts +0 -37
- package/src/node/core/config/resolveConfigProperty.ts +0 -15
- package/src/node/core/config/types.ts +0 -315
- package/src/node/core/contexts/buildContext.ts +0 -32
- package/src/node/core/contexts/index.ts +0 -1
- package/src/node/core/defaults.ts +0 -4
- package/src/node/core/findCommonPath.ts +0 -35
- package/src/node/core/isRecord.ts +0 -4
- package/src/node/core/pkg/helpers.ts +0 -36
- package/src/node/core/pkg/index.ts +0 -5
- package/src/node/core/pkg/loadPkg.ts +0 -21
- package/src/node/core/pkg/loadPkgWithReporting.ts +0 -154
- package/src/node/core/pkg/parseExports.ts +0 -233
- package/src/node/core/pkg/pkgExt.ts +0 -22
- package/src/node/core/pkg/types.ts +0 -60
- package/src/node/core/pkg/validateExports.ts +0 -30
- package/src/node/core/pkg/validatePkg.ts +0 -82
- package/src/node/core/template/createFromTemplate.ts +0 -84
- package/src/node/core/template/define.ts +0 -6
- package/src/node/core/template/index.ts +0 -3
- package/src/node/core/template/types.ts +0 -45
- package/src/node/core/ts/index.ts +0 -1
- package/src/node/core/ts/loadTSConfig.ts +0 -19
- package/src/node/fileExists.ts +0 -12
- package/src/node/getFilesize.ts +0 -8
- package/src/node/globFiles.ts +0 -6
- package/src/node/index.ts +0 -48
- package/src/node/init.ts +0 -54
- package/src/node/isEmptyDirectory.ts +0 -5
- package/src/node/logger.ts +0 -32
- package/src/node/printExtractMessages.ts +0 -59
- package/src/node/printPackageTree.ts +0 -95
- package/src/node/resolveBrowserTarget.ts +0 -17
- package/src/node/resolveBuildContext.ts +0 -202
- package/src/node/resolveBuildTasks.ts +0 -199
- package/src/node/resolveNodeTarget.ts +0 -9
- package/src/node/resolveWatchTasks.ts +0 -132
- package/src/node/spinner.ts +0 -17
- package/src/node/strict.test-d.ts +0 -6
- package/src/node/strict.ts +0 -84
- package/src/node/tasks/dts/DtsError.ts +0 -11
- package/src/node/tasks/dts/buildTypes.ts +0 -42
- package/src/node/tasks/dts/createApiExtractorConfig.ts +0 -67
- package/src/node/tasks/dts/createTSDocConfig.ts +0 -53
- package/src/node/tasks/dts/doExtract.ts +0 -80
- package/src/node/tasks/dts/dtsTask.ts +0 -50
- package/src/node/tasks/dts/dtsWatchTask.ts +0 -165
- package/src/node/tasks/dts/extractModuleBlocks.ts +0 -45
- package/src/node/tasks/dts/extractTypes.ts +0 -128
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +0 -109
- package/src/node/tasks/dts/getTargetPaths.ts +0 -72
- package/src/node/tasks/dts/printDiagnostic.ts +0 -42
- package/src/node/tasks/dts/types.ts +0 -30
- package/src/node/tasks/index.ts +0 -19
- package/src/node/tasks/rolldown/resolveRolldownConfig.ts +0 -202
- package/src/node/tasks/rolldown/rolldownDtsTask.ts +0 -155
- package/src/node/tasks/rollup/resolveRollupConfig.ts +0 -264
- package/src/node/tasks/rollup/rollupTask.ts +0 -154
- package/src/node/tasks/rollup/rollupWatchTask.ts +0 -77
- package/src/node/tasks/types.ts +0 -69
- package/src/node/templates/default/index.ts +0 -1
- package/src/node/templates/default/template.ts +0 -547
- package/src/node/templates/index.ts +0 -1
- package/src/node/watch.ts +0 -66
- package/src/node/watchConfigFiles.ts +0 -53
- package/src/node/watchFiles.ts +0 -31
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import type {PluginItem as BabelPluginItem} from '@babel/core'
|
|
2
|
-
import type {OptimizeLodashOptions} from '@optimize-lodash/rollup-plugin'
|
|
3
|
-
import type {NormalizedOutputOptions, Plugin as RollupPlugin, TreeshakingOptions} from 'rollup'
|
|
4
|
-
import type {StrictOptions} from '../../strict'
|
|
5
|
-
|
|
6
|
-
/** @public */
|
|
7
|
-
export type PkgFormat = 'commonjs' | 'esm'
|
|
8
|
-
|
|
9
|
-
/** @public */
|
|
10
|
-
export type PkgRuntime = '*' | 'browser' | 'node'
|
|
11
|
-
|
|
12
|
-
/** @public */
|
|
13
|
-
export interface PkgExport {
|
|
14
|
-
/** @internal */
|
|
15
|
-
_exported?: boolean
|
|
16
|
-
browser?: {
|
|
17
|
-
source: string
|
|
18
|
-
import?: string
|
|
19
|
-
require?: string
|
|
20
|
-
}
|
|
21
|
-
// electron?: {
|
|
22
|
-
// node?: string
|
|
23
|
-
// default?: string
|
|
24
|
-
// }
|
|
25
|
-
node?: {
|
|
26
|
-
source?: string
|
|
27
|
-
import?: string
|
|
28
|
-
require?: string
|
|
29
|
-
}
|
|
30
|
-
types?: string
|
|
31
|
-
source: string
|
|
32
|
-
import?: string
|
|
33
|
-
require?: string
|
|
34
|
-
default: string
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @public */
|
|
38
|
-
export type PkgConfigPropertyResolver<T> = (prev: T) => T
|
|
39
|
-
|
|
40
|
-
/** @public */
|
|
41
|
-
export type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T
|
|
42
|
-
|
|
43
|
-
/** @public */
|
|
44
|
-
export interface PkgBundle {
|
|
45
|
-
source: string
|
|
46
|
-
import?: string
|
|
47
|
-
require?: string
|
|
48
|
-
runtime?: PkgRuntime
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** @public */
|
|
52
|
-
export interface PkgExports {
|
|
53
|
-
[path: string]: PkgExport
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @public */
|
|
57
|
-
export type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off'
|
|
58
|
-
|
|
59
|
-
/** @public */
|
|
60
|
-
export interface TSDocCustomTag {
|
|
61
|
-
name: string
|
|
62
|
-
syntaxKind: 'block' | 'modifier'
|
|
63
|
-
allowMultiple?: boolean
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Until these types are on npm: https://github.com/facebook/react/blob/0bc30748730063e561d87a24a4617526fdd38349/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts#L39-L122
|
|
68
|
-
* @alpha
|
|
69
|
-
*/
|
|
70
|
-
export interface ReactCompilerOptions {
|
|
71
|
-
logger?: ReactCompilerLogger | null
|
|
72
|
-
|
|
73
|
-
panicThreshold?: 'ALL_ERRORS' | 'CRITICAL_ERRORS' | 'NONE'
|
|
74
|
-
|
|
75
|
-
compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all'
|
|
76
|
-
|
|
77
|
-
/*
|
|
78
|
-
* If enabled, Forget will import `useMemoCache` from the given module
|
|
79
|
-
* instead of `react/compiler-runtime`.
|
|
80
|
-
*
|
|
81
|
-
* ```
|
|
82
|
-
* // If set to "react-compiler-runtime"
|
|
83
|
-
* import {c as useMemoCache} from 'react-compiler-runtime';
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
runtimeModule?: string | null | undefined
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* By default React Compiler will skip compilation of code that suppresses the default
|
|
90
|
-
* React ESLint rules, since this is a strong indication that the code may be breaking React rules
|
|
91
|
-
* in some way.
|
|
92
|
-
*
|
|
93
|
-
* Use eslintSuppressionRules to pass a custom set of rule names: any code which suppresses the
|
|
94
|
-
* provided rules will skip compilation. To disable this feature (never bailout of compilation
|
|
95
|
-
* even if the default ESLint is suppressed), pass an empty array.
|
|
96
|
-
*/
|
|
97
|
-
eslintSuppressionRules?: Array<string> | null | undefined
|
|
98
|
-
|
|
99
|
-
sources?: Array<string> | ((filename: string) => boolean) | null
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The minimum major version of React that the compiler should emit code for. If the target is 19
|
|
103
|
-
* or higher, the compiler emits direct imports of React runtime APIs needed by the compiler. On
|
|
104
|
-
* versions prior to 19, an extra runtime package react-compiler-runtime is necessary to provide
|
|
105
|
-
* a userspace approximation of runtime APIs.
|
|
106
|
-
*/
|
|
107
|
-
target: '17' | '18' | '19'
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @alpha
|
|
112
|
-
* Represents 'events' that may occur during compilation. Events are only
|
|
113
|
-
* recorded when a logger is set (through the config).
|
|
114
|
-
* These are the different types of events:
|
|
115
|
-
* CompileError:
|
|
116
|
-
* Forget skipped compilation of a function / file due to a known todo,
|
|
117
|
-
* invalid input, or compiler invariant being broken.
|
|
118
|
-
* CompileSuccess:
|
|
119
|
-
* Forget successfully compiled a function.
|
|
120
|
-
* PipelineError:
|
|
121
|
-
* Unexpected errors that occurred during compilation (e.g. failures in
|
|
122
|
-
* babel or other unhandled exceptions).
|
|
123
|
-
*/
|
|
124
|
-
export type ReactCompilerLoggerEvent =
|
|
125
|
-
| {
|
|
126
|
-
kind: 'CompileError'
|
|
127
|
-
fnLoc: unknown
|
|
128
|
-
detail: unknown
|
|
129
|
-
}
|
|
130
|
-
| {
|
|
131
|
-
kind: 'CompileDiagnostic'
|
|
132
|
-
fnLoc: unknown
|
|
133
|
-
detail: unknown
|
|
134
|
-
}
|
|
135
|
-
| {
|
|
136
|
-
kind: 'CompileSuccess'
|
|
137
|
-
fnLoc: unknown
|
|
138
|
-
fnName: string | null
|
|
139
|
-
memoSlots: number
|
|
140
|
-
memoBlocks: number
|
|
141
|
-
memoValues: number
|
|
142
|
-
prunedMemoBlocks: number
|
|
143
|
-
prunedMemoValues: number
|
|
144
|
-
}
|
|
145
|
-
| {
|
|
146
|
-
kind: 'PipelineError'
|
|
147
|
-
fnLoc: unknown
|
|
148
|
-
data: string
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @alpha
|
|
153
|
-
*/
|
|
154
|
-
export type ReactCompilerLogger = {
|
|
155
|
-
logEvent: (filename: string | null, event: ReactCompilerLoggerEvent) => void
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export type DtsType = 'api-extractor' | 'rolldown'
|
|
159
|
-
|
|
160
|
-
/** @public */
|
|
161
|
-
export interface PkgConfigOptions {
|
|
162
|
-
/** @alpha */
|
|
163
|
-
babel?: {
|
|
164
|
-
plugins?: BabelPluginItem[] | null | undefined
|
|
165
|
-
/** @alpha */
|
|
166
|
-
reactCompiler?: boolean
|
|
167
|
-
/** @alpha */
|
|
168
|
-
styledComponents?:
|
|
169
|
-
| boolean
|
|
170
|
-
| {
|
|
171
|
-
/** @defaultValue true */
|
|
172
|
-
displayName?: boolean
|
|
173
|
-
/**
|
|
174
|
-
* @defaultValue []
|
|
175
|
-
* @example ["\@xstyled/styled-components", "\@xstyled/styled-components/*"]
|
|
176
|
-
*/
|
|
177
|
-
topLevelImportPaths?: string[]
|
|
178
|
-
/** @defaultValue true */
|
|
179
|
-
ssr?: boolean
|
|
180
|
-
/** @defaultValue fale */
|
|
181
|
-
fileName?: boolean
|
|
182
|
-
/** @defaultValue ["index"] */
|
|
183
|
-
meaninglessFileNames?: string[]
|
|
184
|
-
/** @defaultValue true */
|
|
185
|
-
minify?: boolean
|
|
186
|
-
/** @defaultValue false */
|
|
187
|
-
transpileTemplateLiterals?: boolean
|
|
188
|
-
namespace?: string
|
|
189
|
-
/** @defaultValue true */
|
|
190
|
-
pure?: boolean
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Configure the React Compiler.
|
|
195
|
-
* To enable it, either:
|
|
196
|
-
* - set `babel.reactCompiler` to `true`
|
|
197
|
-
* - add a `react-compiler` export condition, before any `browser`, `require` or `import` conditions. After any `react-server` and `node` conditions
|
|
198
|
-
* @alpha */
|
|
199
|
-
reactCompilerOptions?: ReactCompilerOptions
|
|
200
|
-
bundles?: PkgBundle[]
|
|
201
|
-
/** @alpha */
|
|
202
|
-
define?: Record<string, string | number | boolean | undefined | null>
|
|
203
|
-
/**
|
|
204
|
-
* Directory of distributed & bundled files.
|
|
205
|
-
*/
|
|
206
|
-
dist?: string
|
|
207
|
-
exports?: PkgConfigProperty<PkgExports>
|
|
208
|
-
/**
|
|
209
|
-
* Runs `@microsoft/api-extractor` to check that TSDoc tags are valid, and release tags are correct.
|
|
210
|
-
* This is useful for packages that need to be consumed by TSDoc-based tooling.
|
|
211
|
-
* It's enabled by default, it can be disabled by setting `extract: {enabled: false}`
|
|
212
|
-
*/
|
|
213
|
-
extract?: {
|
|
214
|
-
/**
|
|
215
|
-
* @defaultValue true
|
|
216
|
-
*/
|
|
217
|
-
enabled?: boolean
|
|
218
|
-
/**
|
|
219
|
-
* Packages in `devDependencies` that are not in `external` are automatically added to the `bundledPackages` config.
|
|
220
|
-
* You can exclude a package from being bundled by using a callback:
|
|
221
|
-
* ```
|
|
222
|
-
* bundledPackages: (prev) => prev.filter(package => package !== 'sanity')
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
bundledPackages?: PkgConfigProperty<string[]>
|
|
226
|
-
customTags?: TSDocCustomTag[]
|
|
227
|
-
rules?: {
|
|
228
|
-
/**
|
|
229
|
-
* @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
|
|
230
|
-
*/
|
|
231
|
-
'ae-forgotten-export'?: never
|
|
232
|
-
'ae-incompatible-release-tags'?: PkgRuleLevel
|
|
233
|
-
'ae-internal-missing-underscore'?: PkgRuleLevel
|
|
234
|
-
'ae-missing-release-tag'?: PkgRuleLevel
|
|
235
|
-
'tsdoc-link-tag-unescaped-text'?: PkgRuleLevel
|
|
236
|
-
'tsdoc-undefined-tag'?: PkgRuleLevel
|
|
237
|
-
'tsdoc-unsupported-tag'?: PkgRuleLevel
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Packages to exclude from bundles.
|
|
242
|
-
* Provide an array to merge with default exclusions, use a function to replace them:
|
|
243
|
-
* ```
|
|
244
|
-
* exclude: (prev) => prev.filter(package => package !== 'foo')
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
external?: PkgConfigProperty<string[]>
|
|
248
|
-
/**
|
|
249
|
-
* Defaults to `"automatic"`
|
|
250
|
-
*/
|
|
251
|
-
jsx?: 'transform' | 'preserve' | 'automatic'
|
|
252
|
-
/**
|
|
253
|
-
* Defaults to `"createElement"`
|
|
254
|
-
*/
|
|
255
|
-
jsxFactory?: string
|
|
256
|
-
/**
|
|
257
|
-
* Defaults to `"Fragment"`
|
|
258
|
-
*/
|
|
259
|
-
jsxFragment?: string
|
|
260
|
-
/**
|
|
261
|
-
* Defaults to `"react"`
|
|
262
|
-
*/
|
|
263
|
-
jsxImportSource?: string
|
|
264
|
-
/**
|
|
265
|
-
* @deprecated no longer supported
|
|
266
|
-
*/
|
|
267
|
-
legacyExports?: never
|
|
268
|
-
minify?: boolean
|
|
269
|
-
/** @alpha */
|
|
270
|
-
rollup?: {
|
|
271
|
-
plugins?: PkgConfigProperty<RollupPlugin[]>
|
|
272
|
-
output?: Partial<NormalizedOutputOptions>
|
|
273
|
-
/**
|
|
274
|
-
* Default options are `preset: 'recommended'` and `propertyReadSideEffects: false`
|
|
275
|
-
* @alpha
|
|
276
|
-
*/
|
|
277
|
-
treeshake?: TreeshakingOptions
|
|
278
|
-
/** @alpha */
|
|
279
|
-
experimentalLogSideEffects?: boolean
|
|
280
|
-
/**
|
|
281
|
-
* Adds [hash] to chunk filenames, generally only useful if `@sanity/pkg-utils` is used to deploy a package directly to a CDN.
|
|
282
|
-
* It's not needed when publishing to npm for consumption by other libraries, bundlers and frameworks.
|
|
283
|
-
* @defaultValue false
|
|
284
|
-
*/
|
|
285
|
-
hashChunkFileNames?: boolean
|
|
286
|
-
/**
|
|
287
|
-
* Optimizes lodash imports using `@optimize-lodash/rollup-plugin` when set to `true`.
|
|
288
|
-
* It's enabled if `lodash` is found in `dependencies` or `peerDependencies`.
|
|
289
|
-
* It will use `lodash-es` for ESM targets if found in `dependencies` or `peerDependencies`.
|
|
290
|
-
* @defaultValue true
|
|
291
|
-
* @alpha
|
|
292
|
-
*/
|
|
293
|
-
optimizeLodash?: boolean | OptimizeLodashOptions
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Default runtime of package exports
|
|
297
|
-
*/
|
|
298
|
-
runtime?: PkgRuntime
|
|
299
|
-
sourcemap?: boolean
|
|
300
|
-
/**
|
|
301
|
-
* Directory of source files.
|
|
302
|
-
*/
|
|
303
|
-
src?: string
|
|
304
|
-
tsconfig?: string
|
|
305
|
-
/**
|
|
306
|
-
* Configure what checks are made when running `--strict` builds and checks
|
|
307
|
-
*/
|
|
308
|
-
strictOptions?: StrictOptions
|
|
309
|
-
/**
|
|
310
|
-
* .d.ts files can be generated either by using `@microsoft/api-extractor` or `rolldown`.
|
|
311
|
-
* `rolldown` is the faster option, but is not yet stable.
|
|
312
|
-
* @defaultValue 'api-extractor'
|
|
313
|
-
*/
|
|
314
|
-
dts?: DtsType
|
|
315
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type ts from 'typescript'
|
|
2
|
-
import type {Logger} from '../../logger'
|
|
3
|
-
import type {DtsType, PkgConfigOptions, PkgExports, PkgRuntime} from '../config/types'
|
|
4
|
-
import type {PackageJSON} from '../pkg/types'
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
export interface BuildFile {
|
|
8
|
-
type: 'asset' | 'chunk' | 'types'
|
|
9
|
-
path: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** @internal */
|
|
13
|
-
export interface BuildContext {
|
|
14
|
-
config?: PkgConfigOptions
|
|
15
|
-
cwd: string
|
|
16
|
-
distPath: string
|
|
17
|
-
emitDeclarationOnly: boolean
|
|
18
|
-
exports: PkgExports | undefined
|
|
19
|
-
external: string[]
|
|
20
|
-
bundledPackages: string[]
|
|
21
|
-
files: BuildFile[]
|
|
22
|
-
logger: Logger
|
|
23
|
-
pkg: PackageJSON
|
|
24
|
-
runtime: PkgRuntime
|
|
25
|
-
strict: boolean
|
|
26
|
-
target: Record<PkgRuntime, string[]>
|
|
27
|
-
ts: {
|
|
28
|
-
config?: ts.ParsedCommandLine
|
|
29
|
-
configPath?: string
|
|
30
|
-
}
|
|
31
|
-
dts: DtsType
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './buildContext'
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
export function pathContains(containerPath: string, itemPath: string): boolean {
|
|
4
|
-
return !path.relative(containerPath, itemPath).startsWith('..')
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function findCommonDirPath(filePaths: string[]): string | undefined {
|
|
8
|
-
let ret: string | undefined = undefined
|
|
9
|
-
|
|
10
|
-
for (const filePath of filePaths) {
|
|
11
|
-
let dirPath = path.dirname(filePath)
|
|
12
|
-
|
|
13
|
-
if (!ret) {
|
|
14
|
-
ret = dirPath
|
|
15
|
-
continue
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
while (dirPath !== ret) {
|
|
19
|
-
dirPath = path.dirname(dirPath)
|
|
20
|
-
|
|
21
|
-
if (dirPath === ret) {
|
|
22
|
-
break
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (pathContains(dirPath, ret)) {
|
|
26
|
-
ret = dirPath
|
|
27
|
-
break
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (dirPath === '.') return undefined
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return ret
|
|
35
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/** @internal */
|
|
2
|
-
export function assertFirst<T>(a: T, arr: T[]): boolean {
|
|
3
|
-
const aIdx = arr.indexOf(a)
|
|
4
|
-
|
|
5
|
-
// if not found, then we don't care
|
|
6
|
-
if (aIdx === -1) {
|
|
7
|
-
return true
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return aIdx === 0
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** @internal */
|
|
14
|
-
export function assertLast<T>(a: T, arr: T[]): boolean {
|
|
15
|
-
const aIdx = arr.indexOf(a)
|
|
16
|
-
|
|
17
|
-
// if not found, then we don't care
|
|
18
|
-
if (aIdx === -1) {
|
|
19
|
-
return true
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return aIdx === arr.length - 1
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** @internal */
|
|
26
|
-
export function assertOrder<T>(a: T, b: T, arr: T[]): boolean {
|
|
27
|
-
const aIdx = arr.indexOf(a)
|
|
28
|
-
const bIdx = arr.indexOf(b)
|
|
29
|
-
|
|
30
|
-
// if either is not found, then we don't care
|
|
31
|
-
if (aIdx === -1 || bIdx === -1) {
|
|
32
|
-
return true
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return aIdx < bIdx
|
|
36
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises'
|
|
2
|
-
import pkgUp from 'pkg-up'
|
|
3
|
-
import type {PackageJSON} from './types'
|
|
4
|
-
import {validatePkg} from './validatePkg'
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
export async function loadPkg(options: {cwd: string}): Promise<PackageJSON> {
|
|
8
|
-
const {cwd} = options
|
|
9
|
-
|
|
10
|
-
const pkgPath = await pkgUp({cwd})
|
|
11
|
-
|
|
12
|
-
if (!pkgPath) throw new Error('no package.json found')
|
|
13
|
-
|
|
14
|
-
const buf = await fs.readFile(pkgPath)
|
|
15
|
-
|
|
16
|
-
const raw = JSON.parse(buf.toString())
|
|
17
|
-
|
|
18
|
-
validatePkg(raw)
|
|
19
|
-
|
|
20
|
-
return raw
|
|
21
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import {ZodError} from 'zod'
|
|
3
|
-
import type {Logger} from '../../logger'
|
|
4
|
-
import {assertLast, assertOrder} from './helpers'
|
|
5
|
-
import {loadPkg} from './loadPkg'
|
|
6
|
-
import type {PackageJSON} from './types'
|
|
7
|
-
|
|
8
|
-
/** @alpha */
|
|
9
|
-
export async function loadPkgWithReporting(options: {
|
|
10
|
-
cwd: string
|
|
11
|
-
logger: Logger
|
|
12
|
-
strict: boolean
|
|
13
|
-
}): Promise<PackageJSON> {
|
|
14
|
-
const {cwd, logger, strict} = options
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const pkg = await loadPkg({cwd})
|
|
18
|
-
let shouldError = false
|
|
19
|
-
|
|
20
|
-
if (strict) {
|
|
21
|
-
if (!pkg.type) {
|
|
22
|
-
shouldError = true
|
|
23
|
-
logger.error(
|
|
24
|
-
`the \`type\` field in \`./package.json\` must be either "module" or "commonjs")`,
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// validate exports
|
|
30
|
-
if (pkg.exports) {
|
|
31
|
-
const _exports = Object.entries(pkg.exports)
|
|
32
|
-
|
|
33
|
-
for (const [expPath, exp] of _exports) {
|
|
34
|
-
if (typeof exp === 'string' || 'svelte' in exp) {
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const keys = Object.keys(exp)
|
|
39
|
-
|
|
40
|
-
if (exp.types) {
|
|
41
|
-
shouldError = true
|
|
42
|
-
logger.error(
|
|
43
|
-
`exports["${expPath}"]: the \`types\` condition shouldn't be used as dts files are generated in such a way that both CJS and ESM is supported`,
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (exp.module) {
|
|
48
|
-
shouldError = true
|
|
49
|
-
logger.error(
|
|
50
|
-
`exports["${expPath}"]: the \`module\` condition shouldn't be used as it's not well supported in all bundlers.`,
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (exp.node) {
|
|
55
|
-
if (exp.import && exp.node.import && !assertOrder('node', 'import', keys)) {
|
|
56
|
-
shouldError = true
|
|
57
|
-
logger.error(
|
|
58
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`import\` property`,
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (exp.node.module) {
|
|
63
|
-
shouldError = true
|
|
64
|
-
logger.error(
|
|
65
|
-
`exports["${expPath}"]: the \`node.module\` condition shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the "dual package hazard"`,
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
!exp.node.source &&
|
|
71
|
-
exp.node.import &&
|
|
72
|
-
(exp.node.require || exp.require) &&
|
|
73
|
-
(exp.node.import.endsWith('.cjs.js') || exp.node.import.endsWith('.cjs.mjs'))
|
|
74
|
-
) {
|
|
75
|
-
shouldError = true
|
|
76
|
-
logger.error(
|
|
77
|
-
`exports["${expPath}"]: the \`node.import\` re-export pattern shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the "dual package hazard"`,
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (exp.require && exp.node.require && exp.require === exp.node.require) {
|
|
82
|
-
shouldError = true
|
|
83
|
-
logger.error(
|
|
84
|
-
`exports["${expPath}"]: the \`node.require\` property isn't necessary as it's identical to \`require\``,
|
|
85
|
-
)
|
|
86
|
-
} else if (exp.require && exp.node.require && !assertOrder('node', 'require', keys)) {
|
|
87
|
-
shouldError = true
|
|
88
|
-
logger.error(
|
|
89
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`require\` property`,
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
if (!assertOrder('import', 'require', keys)) {
|
|
94
|
-
logger.warn(
|
|
95
|
-
`exports["${expPath}"]: the \`import\` property should come before the \`require\` property`,
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!assertLast('default', keys)) {
|
|
101
|
-
shouldError = true
|
|
102
|
-
logger.error(
|
|
103
|
-
`exports["${expPath}"]: the \`default\` property should be the last property`,
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (shouldError) {
|
|
110
|
-
process.exit(1)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return pkg
|
|
114
|
-
} catch (err) {
|
|
115
|
-
if (err instanceof ZodError) {
|
|
116
|
-
for (const issue of err.issues) {
|
|
117
|
-
if (issue.code === 'invalid_type') {
|
|
118
|
-
logger.error(
|
|
119
|
-
[
|
|
120
|
-
`\`${formatPath(issue.path)}\` `,
|
|
121
|
-
`in \`./package.json\` must be of type ${chalk.magenta(issue.expected)} `,
|
|
122
|
-
`(received ${chalk.magenta(issue.received)})`,
|
|
123
|
-
].join(''),
|
|
124
|
-
)
|
|
125
|
-
continue
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
logger.error(issue)
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
logger.error(err)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
process.exit(1)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function formatPath(segments: Array<string | number>) {
|
|
139
|
-
return segments
|
|
140
|
-
.map((s, idx) => {
|
|
141
|
-
if (idx === 0) return s
|
|
142
|
-
|
|
143
|
-
if (typeof s === 'number') {
|
|
144
|
-
return `[${s}]`
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (s.startsWith('.')) {
|
|
148
|
-
return `["${s}"]`
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return `.${s}`
|
|
152
|
-
})
|
|
153
|
-
.join('')
|
|
154
|
-
}
|