@sanity/pkg-utils 7.2.10-canary.1 → 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 -106
- 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 +487 -408
- package/dist/index.d.ts +487 -408
- package/dist/index.js +1 -2390
- 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 -208
- 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,233 +0,0 @@
|
|
|
1
|
-
import {existsSync} from 'node:fs'
|
|
2
|
-
import {resolve as resolvePath} from 'node:path'
|
|
3
|
-
import type {Logger} from '../../logger'
|
|
4
|
-
import type {InferredStrictOptions} from '../../strict'
|
|
5
|
-
import {defaultEnding, fileEnding} from '../../tasks/dts/getTargetPaths'
|
|
6
|
-
import type {PkgExport} from '../config/types'
|
|
7
|
-
import {isRecord} from '../isRecord'
|
|
8
|
-
import {pkgExtMap} from './pkgExt'
|
|
9
|
-
import type {PackageJSON} from './types'
|
|
10
|
-
import {validateExports} from './validateExports'
|
|
11
|
-
|
|
12
|
-
/** @alpha */
|
|
13
|
-
export function parseExports(options: {
|
|
14
|
-
cwd: string
|
|
15
|
-
pkg: PackageJSON
|
|
16
|
-
strict: boolean
|
|
17
|
-
strictOptions: InferredStrictOptions
|
|
18
|
-
logger: Logger
|
|
19
|
-
}): (PkgExport & {_path: string})[] {
|
|
20
|
-
const {cwd, pkg, strict, strictOptions, logger} = options
|
|
21
|
-
const type = pkg.type || 'commonjs'
|
|
22
|
-
const errors: string[] = []
|
|
23
|
-
|
|
24
|
-
const report = (kind: 'warn' | 'error', message: string) => {
|
|
25
|
-
if (kind === 'warn') {
|
|
26
|
-
logger.warn(message)
|
|
27
|
-
} else {
|
|
28
|
-
errors.push(message)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!pkg.main && strict && strictOptions.alwaysPackageJsonMain !== 'off') {
|
|
33
|
-
report(strictOptions.alwaysPackageJsonMain, 'package.json: `main` must be declared')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!Array.isArray(pkg.files) && strict && strictOptions.alwaysPackageJsonFiles !== 'off') {
|
|
37
|
-
report(
|
|
38
|
-
strictOptions.alwaysPackageJsonFiles,
|
|
39
|
-
'package.json: `files` should be used over `.npmignore`',
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (pkg.source) {
|
|
44
|
-
if (
|
|
45
|
-
strict &&
|
|
46
|
-
pkg.exports?.['.'] &&
|
|
47
|
-
typeof pkg.exports['.'] === 'object' &&
|
|
48
|
-
'source' in pkg.exports['.'] &&
|
|
49
|
-
pkg.exports['.'].source === pkg.source
|
|
50
|
-
) {
|
|
51
|
-
errors.push(
|
|
52
|
-
'package.json: the "source" property can be removed, as it is equal to exports["."].source.',
|
|
53
|
-
)
|
|
54
|
-
} else if (!pkg.exports && pkg.main) {
|
|
55
|
-
const extMap = pkgExtMap[type]
|
|
56
|
-
const importExport = pkg.main.replace(fileEnding, extMap.esm)
|
|
57
|
-
const requireExport = pkg.main.replace(fileEnding, extMap.commonjs)
|
|
58
|
-
const defaultExport = pkg.main.replace(fileEnding, defaultEnding)
|
|
59
|
-
|
|
60
|
-
const maybeBrowserCondition = []
|
|
61
|
-
|
|
62
|
-
if (pkg.browser) {
|
|
63
|
-
const browserConditions = []
|
|
64
|
-
|
|
65
|
-
if (pkg.module && pkg.browser?.[pkg.module]) {
|
|
66
|
-
browserConditions.push(
|
|
67
|
-
` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`,
|
|
68
|
-
)
|
|
69
|
-
} else if (pkg.browser?.[pkg.main]) {
|
|
70
|
-
browserConditions.push(
|
|
71
|
-
` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`,
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (pkg.browser?.[pkg.main]) {
|
|
76
|
-
browserConditions.push(
|
|
77
|
-
` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`,
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (browserConditions.length) {
|
|
82
|
-
maybeBrowserCondition.push(
|
|
83
|
-
` "browser": {`,
|
|
84
|
-
` "source": ${JSON.stringify(pkg.browser?.[pkg.source] || pkg.source)},`,
|
|
85
|
-
...browserConditions,
|
|
86
|
-
` }`,
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
errors.push(
|
|
92
|
-
...([
|
|
93
|
-
'package.json: `exports` are missing, it should be:',
|
|
94
|
-
`"exports": {`,
|
|
95
|
-
` ".": {`,
|
|
96
|
-
` "source": ${JSON.stringify(pkg.source)},`,
|
|
97
|
-
// If browser conditions are detected then add them to the suggestion
|
|
98
|
-
...(maybeBrowserCondition.length > 0 ? maybeBrowserCondition : []),
|
|
99
|
-
type === 'commonjs' && ` "import": ${JSON.stringify(importExport)},`,
|
|
100
|
-
type === 'module' && ` "require": ${JSON.stringify(requireExport)},`,
|
|
101
|
-
` "default": ${JSON.stringify(defaultExport)}`,
|
|
102
|
-
` },`,
|
|
103
|
-
` "./package.json": "./package.json"`,
|
|
104
|
-
`}`,
|
|
105
|
-
].filter(Boolean) as string[]),
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (errors.length) {
|
|
111
|
-
throw new Error('\n- ' + errors.join('\n- '))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!pkg.exports) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
'\n- ' +
|
|
117
|
-
[
|
|
118
|
-
'package.json: `exports` are missing, please set a minimal configuration, for example:',
|
|
119
|
-
`"exports": {`,
|
|
120
|
-
` ".": {`,
|
|
121
|
-
` "source": "./src/index.js",`,
|
|
122
|
-
` "default": "./dist/index.js"`,
|
|
123
|
-
` },`,
|
|
124
|
-
` "./package.json": "./package.json"`,
|
|
125
|
-
`}`,
|
|
126
|
-
].join('\n- '),
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const _exports: (PkgExport & {_path: string})[] = []
|
|
131
|
-
|
|
132
|
-
if (strict && strictOptions.noPackageJsonTypings !== 'off' && 'typings' in pkg) {
|
|
133
|
-
report(strictOptions.noPackageJsonTypings, 'package.json: `typings` should be `types`')
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
strict &&
|
|
138
|
-
strictOptions.alwaysPackageJsonTypes !== 'off' &&
|
|
139
|
-
!pkg.types &&
|
|
140
|
-
typeof pkg.exports?.['.'] === 'object' &&
|
|
141
|
-
'source' in pkg.exports['.'] &&
|
|
142
|
-
pkg.exports['.'].source?.endsWith('.ts')
|
|
143
|
-
) {
|
|
144
|
-
report(
|
|
145
|
-
strictOptions.alwaysPackageJsonTypes,
|
|
146
|
-
'package.json: `types` must be declared for the npm listing to show as a TypeScript module.',
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (strict && !pkg.exports['./package.json']) {
|
|
151
|
-
errors.push('package.json: `exports["./package.json"] must be declared.')
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
155
|
-
if (
|
|
156
|
-
exportPath.endsWith('.json') ||
|
|
157
|
-
(typeof exportEntry === 'string' && exportEntry.endsWith('.json'))
|
|
158
|
-
) {
|
|
159
|
-
if (exportPath === './package.json') {
|
|
160
|
-
if (exportEntry !== './package.json') {
|
|
161
|
-
errors.push('package.json: `exports["./package.json"]` must be "./package.json".')
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} else if (exportPath.endsWith('.css')) {
|
|
165
|
-
if (typeof exportEntry === 'string' && !existsSync(resolvePath(cwd, exportEntry))) {
|
|
166
|
-
errors.push(
|
|
167
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}]\`: file does not exist.`,
|
|
168
|
-
)
|
|
169
|
-
} else if (typeof exportEntry !== 'string') {
|
|
170
|
-
errors.push(
|
|
171
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}]\`: export conditions not supported for CSS files.`,
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
} else if (isRecord(exportEntry) && 'svelte' in exportEntry) {
|
|
175
|
-
// @TODO should we report a warning or a debug message here about a detected svelte export that is ignored?
|
|
176
|
-
} else if (isPkgExport(exportEntry)) {
|
|
177
|
-
const exp = {
|
|
178
|
-
_exported: true,
|
|
179
|
-
_path: exportPath,
|
|
180
|
-
...exportEntry,
|
|
181
|
-
} satisfies PkgExport & {_path: string}
|
|
182
|
-
|
|
183
|
-
// Infer the `default` condition based on the `type` and other conditions
|
|
184
|
-
if (!exp.default) {
|
|
185
|
-
const fallback = type === 'module' ? exp.import : exp.require
|
|
186
|
-
|
|
187
|
-
if (fallback) {
|
|
188
|
-
exp.default = fallback
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Infer the `require` condition based on the `type` and other conditions
|
|
193
|
-
if (!exp.require && type === 'commonjs' && exp.default) {
|
|
194
|
-
exp.require = exp.default
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Infer the `import` condition based on the `type` and other conditions
|
|
198
|
-
if (!exp.import && type === 'module' && exp.default) {
|
|
199
|
-
exp.import = exp.default
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (exportPath === '.') {
|
|
203
|
-
if (exportEntry.require && pkg.main && exportEntry.require !== pkg.main) {
|
|
204
|
-
errors.push(
|
|
205
|
-
'package.json: mismatch between "main" and "exports.require". These must be equal.',
|
|
206
|
-
)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (exportEntry.import && pkg.module && exportEntry.import !== pkg.module) {
|
|
210
|
-
errors.push(
|
|
211
|
-
'package.json: mismatch between "module" and "exports.import" These must be equal.',
|
|
212
|
-
)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
_exports.push(exp)
|
|
217
|
-
} else if (!isRecord(exportEntry)) {
|
|
218
|
-
errors.push('package.json: exports must be an object')
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
errors.push(...validateExports(_exports, {pkg}))
|
|
223
|
-
|
|
224
|
-
if (errors.length) {
|
|
225
|
-
throw new Error('\n- ' + errors.join('\n- '))
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return _exports
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function isPkgExport(value: unknown): value is PkgExport {
|
|
232
|
-
return isRecord(value) && 'source' in value && typeof value['source'] === 'string'
|
|
233
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {cjsEnding, defaultEnding, mjsEnding} from '../../tasks/dts/getTargetPaths'
|
|
2
|
-
|
|
3
|
-
/** @internal */
|
|
4
|
-
export interface PkgExtMap {
|
|
5
|
-
commonjs: {commonjs: string; esm: string}
|
|
6
|
-
module: {commonjs: string; esm: string}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** @internal */
|
|
10
|
-
export const pkgExtMap = {
|
|
11
|
-
// pkg.type: "commonjs"
|
|
12
|
-
commonjs: {
|
|
13
|
-
commonjs: defaultEnding,
|
|
14
|
-
esm: mjsEnding,
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
// pkg.type: "module"
|
|
18
|
-
module: {
|
|
19
|
-
commonjs: cjsEnding,
|
|
20
|
-
esm: defaultEnding,
|
|
21
|
-
},
|
|
22
|
-
} satisfies PkgExtMap
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/** @alpha */
|
|
2
|
-
export interface PackageJSON {
|
|
3
|
-
type?: 'commonjs' | 'module'
|
|
4
|
-
version: string
|
|
5
|
-
private?: boolean
|
|
6
|
-
author?: string | {name: string; email?: string; url?: string}
|
|
7
|
-
name: string
|
|
8
|
-
description?: string
|
|
9
|
-
keywords?: string[]
|
|
10
|
-
bin?: Record<string, string>
|
|
11
|
-
dependencies?: Record<string, string | undefined>
|
|
12
|
-
devDependencies?: Record<string, string | undefined>
|
|
13
|
-
peerDependencies?: Record<string, string | undefined>
|
|
14
|
-
exports?: Record<
|
|
15
|
-
string,
|
|
16
|
-
| `./${string}.json`
|
|
17
|
-
| `./${string}.css`
|
|
18
|
-
| {
|
|
19
|
-
source?: string
|
|
20
|
-
types?: string
|
|
21
|
-
browser?: {
|
|
22
|
-
source: string
|
|
23
|
-
import?: string
|
|
24
|
-
require?: string
|
|
25
|
-
}
|
|
26
|
-
node?: {
|
|
27
|
-
source?: string
|
|
28
|
-
module?: string
|
|
29
|
-
import?: string
|
|
30
|
-
require?: string
|
|
31
|
-
}
|
|
32
|
-
module?: string
|
|
33
|
-
import?: string
|
|
34
|
-
require?: string
|
|
35
|
-
default: string
|
|
36
|
-
}
|
|
37
|
-
| {
|
|
38
|
-
types?: string
|
|
39
|
-
svelte: string
|
|
40
|
-
default?: string
|
|
41
|
-
}
|
|
42
|
-
>
|
|
43
|
-
main?: string
|
|
44
|
-
browser?: Record<string, string>
|
|
45
|
-
source?: string
|
|
46
|
-
module?: string
|
|
47
|
-
types?: string
|
|
48
|
-
files?: string[]
|
|
49
|
-
scripts?: Record<string, string | undefined>
|
|
50
|
-
browserslist?: string | string[]
|
|
51
|
-
sideEffects?: boolean | string[]
|
|
52
|
-
engines?: {
|
|
53
|
-
node?: string
|
|
54
|
-
npm?: string
|
|
55
|
-
}
|
|
56
|
-
repository?: string | {type: 'git'; url: string}
|
|
57
|
-
bugs?: string | {url: string; email?: string}
|
|
58
|
-
homepage?: string
|
|
59
|
-
license?: string
|
|
60
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type {PkgExport} from '../config/types'
|
|
2
|
-
import {pkgExtMap as extMap} from './pkgExt'
|
|
3
|
-
import type {PackageJSON} from './types'
|
|
4
|
-
|
|
5
|
-
export function validateExports(
|
|
6
|
-
_exports: (PkgExport & {_path: string})[],
|
|
7
|
-
options: {pkg: PackageJSON},
|
|
8
|
-
): string[] {
|
|
9
|
-
const {pkg} = options
|
|
10
|
-
const type = pkg.type || 'commonjs'
|
|
11
|
-
const ext = extMap[type]
|
|
12
|
-
|
|
13
|
-
const errors: string[] = []
|
|
14
|
-
|
|
15
|
-
for (const exp of _exports) {
|
|
16
|
-
if (exp.require && !exp.require.endsWith(ext.commonjs)) {
|
|
17
|
-
errors.push(
|
|
18
|
-
`package.json with \`type: "${type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`,
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (exp.import && !exp.import.endsWith(ext.esm)) {
|
|
23
|
-
errors.push(
|
|
24
|
-
`package.json with \`type: "${type}"\` - \`exports["${exp._path}"].import\` must end with "${ext.esm}"`,
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return errors
|
|
30
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import type {PackageJSON} from './types'
|
|
3
|
-
|
|
4
|
-
const pkgSchema = z.object({
|
|
5
|
-
type: z.optional(z.enum(['commonjs', 'module'])),
|
|
6
|
-
name: z.string(),
|
|
7
|
-
version: z.string(),
|
|
8
|
-
license: z.string(),
|
|
9
|
-
bin: z.optional(z.record(z.string())),
|
|
10
|
-
dependencies: z.optional(z.record(z.string())),
|
|
11
|
-
devDependencies: z.optional(z.record(z.string())),
|
|
12
|
-
peerDependencies: z.optional(z.record(z.string())),
|
|
13
|
-
source: z.optional(z.string()),
|
|
14
|
-
main: z.optional(z.string()),
|
|
15
|
-
browser: z.optional(z.record(z.string())),
|
|
16
|
-
module: z.optional(z.string()),
|
|
17
|
-
types: z.optional(z.string()),
|
|
18
|
-
exports: z.optional(
|
|
19
|
-
z.record(
|
|
20
|
-
z.union([
|
|
21
|
-
z.custom<`./${string}.json`>((val) => /^\.\/.*\.json$/.test(val as string)),
|
|
22
|
-
z.custom<`./${string}.css`>((val) => /^\.\/.*\.css$/.test(val as string)),
|
|
23
|
-
z.object({
|
|
24
|
-
types: z.optional(z.string()),
|
|
25
|
-
source: z.optional(z.string()),
|
|
26
|
-
browser: z.optional(
|
|
27
|
-
z.object({
|
|
28
|
-
source: z.string(),
|
|
29
|
-
import: z.optional(z.string()),
|
|
30
|
-
require: z.optional(z.string()),
|
|
31
|
-
}),
|
|
32
|
-
),
|
|
33
|
-
node: z.optional(
|
|
34
|
-
z.object({
|
|
35
|
-
source: z.optional(z.string()),
|
|
36
|
-
import: z.optional(z.string()),
|
|
37
|
-
require: z.optional(z.string()),
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
import: z.optional(z.string()),
|
|
41
|
-
require: z.optional(z.string()),
|
|
42
|
-
default: z.string(),
|
|
43
|
-
}),
|
|
44
|
-
z.object({
|
|
45
|
-
types: z.optional(z.string()),
|
|
46
|
-
svelte: z.string(),
|
|
47
|
-
default: z.optional(z.string()),
|
|
48
|
-
}),
|
|
49
|
-
]),
|
|
50
|
-
),
|
|
51
|
-
),
|
|
52
|
-
browserslist: z.optional(z.union([z.string(), z.array(z.string())])),
|
|
53
|
-
sideEffects: z.optional(z.union([z.boolean(), z.array(z.string())])),
|
|
54
|
-
// @TODO type this properly
|
|
55
|
-
typesVersions: z.optional(z.any()),
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// Create a map over known keys to catch casing mistakes
|
|
59
|
-
const typoMap = new Map<string, string>()
|
|
60
|
-
|
|
61
|
-
for (const key of pkgSchema.keyof()._def.values) {
|
|
62
|
-
typoMap.set(key.toUpperCase(), key)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function validatePkg(input: unknown): PackageJSON {
|
|
66
|
-
const pkg = pkgSchema.parse(input)
|
|
67
|
-
|
|
68
|
-
const invalidKey = Object.keys(input as PackageJSON).find((key) => {
|
|
69
|
-
const needle = key.toUpperCase()
|
|
70
|
-
|
|
71
|
-
return typoMap.has(needle) ? typoMap.get(needle) !== key : false
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
if (invalidKey) {
|
|
75
|
-
throw new TypeError(
|
|
76
|
-
`
|
|
77
|
-
- package.json: "${invalidKey}" is not a valid key. Did you mean "${typoMap.get(invalidKey.toUpperCase())}"?`,
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return pkg
|
|
82
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {writeFile} from 'node:fs/promises'
|
|
2
|
-
import {dirname, relative, resolve} from 'node:path'
|
|
3
|
-
import {mkdirp} from 'mkdirp'
|
|
4
|
-
import prompts from 'prompts'
|
|
5
|
-
import type {Logger} from '../../logger'
|
|
6
|
-
import type {PkgTemplate} from './types'
|
|
7
|
-
|
|
8
|
-
const promptsTypes = {
|
|
9
|
-
string: 'text' as const,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** @internal */
|
|
13
|
-
export async function createFromTemplate(options: {
|
|
14
|
-
cwd: string
|
|
15
|
-
logger: Logger
|
|
16
|
-
packagePath: string
|
|
17
|
-
template: PkgTemplate
|
|
18
|
-
}): Promise<void> {
|
|
19
|
-
const {cwd, logger, packagePath, template: templateOrResolver} = options
|
|
20
|
-
|
|
21
|
-
const template =
|
|
22
|
-
typeof templateOrResolver === 'function'
|
|
23
|
-
? await templateOrResolver({cwd, logger, packagePath})
|
|
24
|
-
: templateOrResolver
|
|
25
|
-
|
|
26
|
-
logger.log('create new package at', relative(cwd, packagePath))
|
|
27
|
-
|
|
28
|
-
const templateOptions: Record<string, string> = {}
|
|
29
|
-
|
|
30
|
-
for (const templateOption of template.options) {
|
|
31
|
-
const templateValidate = templateOption.validate
|
|
32
|
-
|
|
33
|
-
const res = await prompts(
|
|
34
|
-
{
|
|
35
|
-
type: promptsTypes[templateOption.type],
|
|
36
|
-
name: templateOption.name,
|
|
37
|
-
message: templateOption.description,
|
|
38
|
-
validate: templateValidate ? (prev) => templateValidate(prev) : undefined,
|
|
39
|
-
initial:
|
|
40
|
-
typeof templateOption.initial === 'function'
|
|
41
|
-
? templateOption.initial(templateOptions)
|
|
42
|
-
: templateOption.initial,
|
|
43
|
-
},
|
|
44
|
-
{onCancel: () => process.exit(0)},
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
templateOptions[templateOption.name] = templateOption.parse
|
|
48
|
-
? templateOption.parse(res[templateOption.name])
|
|
49
|
-
: res[templateOption.name]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const features: Record<string, boolean> = {}
|
|
53
|
-
|
|
54
|
-
for (const templateFeature of template.features) {
|
|
55
|
-
const res = templateFeature.optional
|
|
56
|
-
? await prompts(
|
|
57
|
-
{
|
|
58
|
-
type: 'confirm',
|
|
59
|
-
name: 'confirm',
|
|
60
|
-
message: `use ${templateFeature.name}?`,
|
|
61
|
-
initial: templateFeature.initial,
|
|
62
|
-
},
|
|
63
|
-
{onCancel: () => process.exit(0)},
|
|
64
|
-
)
|
|
65
|
-
: undefined
|
|
66
|
-
|
|
67
|
-
features[templateFeature.name] = res?.confirm || !templateFeature.optional
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const files = await template.getFiles(templateOptions, features)
|
|
71
|
-
|
|
72
|
-
files.sort((a, b) => {
|
|
73
|
-
return a.name.localeCompare(b.name)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
for (const file of files) {
|
|
77
|
-
const filePath = resolve(packagePath, file.name)
|
|
78
|
-
|
|
79
|
-
await mkdirp(dirname(filePath))
|
|
80
|
-
await writeFile(filePath, file.contents.trim() + '\n')
|
|
81
|
-
|
|
82
|
-
logger.success(`wrote ${relative(cwd, filePath)}`)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type {Logger} from '../../logger'
|
|
2
|
-
|
|
3
|
-
/** @public */
|
|
4
|
-
export interface PkgTemplateFile {
|
|
5
|
-
name: string
|
|
6
|
-
contents: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** @public */
|
|
10
|
-
export interface PkgTemplateStringOption<T = string> {
|
|
11
|
-
name: string
|
|
12
|
-
type: 'string'
|
|
13
|
-
description: string
|
|
14
|
-
initial?: T | ((options: Record<string, any>) => T)
|
|
15
|
-
parse?: (v: string) => T | null
|
|
16
|
-
validate?: (v: string) => string | true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @public */
|
|
20
|
-
export type PkgTemplateOption<T = string> = PkgTemplateStringOption<T>
|
|
21
|
-
|
|
22
|
-
/** @public */
|
|
23
|
-
export interface PkgTemplateDefinition {
|
|
24
|
-
options: PkgTemplateStringOption<any>[]
|
|
25
|
-
features: {
|
|
26
|
-
name: string
|
|
27
|
-
optional: boolean
|
|
28
|
-
initial: boolean
|
|
29
|
-
}[]
|
|
30
|
-
getFiles: (
|
|
31
|
-
options: Record<string, any>,
|
|
32
|
-
features: Record<string, boolean>,
|
|
33
|
-
) => Promise<PkgTemplateFile[]>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** @public */
|
|
37
|
-
export type PkgTemplateResolver = (options: {
|
|
38
|
-
cwd: string
|
|
39
|
-
/** @internal */
|
|
40
|
-
logger: Logger
|
|
41
|
-
packagePath: string
|
|
42
|
-
}) => PkgTemplateDefinition | Promise<PkgTemplateDefinition>
|
|
43
|
-
|
|
44
|
-
/** @public */
|
|
45
|
-
export type PkgTemplate = PkgTemplateDefinition | PkgTemplateResolver
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './loadTSConfig'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript'
|
|
2
|
-
|
|
3
|
-
/** @internal */
|
|
4
|
-
export async function loadTSConfig(options: {
|
|
5
|
-
cwd: string
|
|
6
|
-
tsconfigPath: string
|
|
7
|
-
}): Promise<ts.ParsedCommandLine | undefined> {
|
|
8
|
-
const {cwd, tsconfigPath} = options
|
|
9
|
-
|
|
10
|
-
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath)
|
|
11
|
-
|
|
12
|
-
if (!configPath) {
|
|
13
|
-
return undefined
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
17
|
-
|
|
18
|
-
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd)
|
|
19
|
-
}
|
package/src/node/fileExists.ts
DELETED
package/src/node/getFilesize.ts
DELETED
package/src/node/globFiles.ts
DELETED
package/src/node/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export {build} from './build'
|
|
2
|
-
export {check} from './check'
|
|
3
|
-
export {defineConfig} from './core/config/defineConfig'
|
|
4
|
-
export {loadConfig} from './core/config/loadConfig'
|
|
5
|
-
export type {
|
|
6
|
-
PkgFormat,
|
|
7
|
-
PkgRuntime,
|
|
8
|
-
PkgExport,
|
|
9
|
-
PkgConfigPropertyResolver,
|
|
10
|
-
PkgConfigProperty,
|
|
11
|
-
PkgBundle,
|
|
12
|
-
PkgExports,
|
|
13
|
-
PkgRuleLevel,
|
|
14
|
-
TSDocCustomTag,
|
|
15
|
-
ReactCompilerOptions,
|
|
16
|
-
ReactCompilerLoggerEvent,
|
|
17
|
-
ReactCompilerLogger,
|
|
18
|
-
PkgConfigOptions,
|
|
19
|
-
} from './core/config/types'
|
|
20
|
-
export {DEFAULT_BROWSERSLIST_QUERY} from './core/defaults'
|
|
21
|
-
export {loadPkg} from './core/pkg/loadPkg'
|
|
22
|
-
export {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting'
|
|
23
|
-
export {parseExports} from './core/pkg/parseExports'
|
|
24
|
-
export * from './core/pkg/types'
|
|
25
|
-
export {defineTemplateOption} from './core/template/define'
|
|
26
|
-
export {
|
|
27
|
-
type PkgTemplateFile,
|
|
28
|
-
type PkgTemplateStringOption,
|
|
29
|
-
type PkgTemplateOption,
|
|
30
|
-
type PkgTemplateDefinition,
|
|
31
|
-
type PkgTemplateResolver,
|
|
32
|
-
type PkgTemplate,
|
|
33
|
-
} from './core/template/types'
|
|
34
|
-
|
|
35
|
-
export {init} from './init'
|
|
36
|
-
export {createLogger} from './logger'
|
|
37
|
-
export {
|
|
38
|
-
type StrictOptions,
|
|
39
|
-
type InferredStrictOptions,
|
|
40
|
-
parseStrictOptions,
|
|
41
|
-
strictOptions,
|
|
42
|
-
toggle,
|
|
43
|
-
type ToggleType,
|
|
44
|
-
} from './strict'
|
|
45
|
-
export {getExtractMessagesConfig} from './tasks/dts/getExtractMessagesConfig'
|
|
46
|
-
export {watch} from './watch'
|
|
47
|
-
|
|
48
|
-
export type {Plugin as RollupPlugin} from 'rollup'
|