@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,547 +0,0 @@
|
|
|
1
|
-
import {execSync} from 'node:child_process'
|
|
2
|
-
import {resolve} from 'node:path'
|
|
3
|
-
import prettierConfig from '@sanity/prettier-config'
|
|
4
|
-
import getLatestVersion from 'get-latest-version'
|
|
5
|
-
import gitUrlParse from 'git-url-parse'
|
|
6
|
-
import {outdent} from 'outdent'
|
|
7
|
-
import {format, type Config as PrettierConfig} from 'prettier'
|
|
8
|
-
import {isRecord} from '../../core/isRecord'
|
|
9
|
-
import type {PackageJSON} from '../../core/pkg/types'
|
|
10
|
-
import {defineTemplateOption} from '../../core/template/define'
|
|
11
|
-
import {type PkgTemplate, type PkgTemplateFile} from '../../core/template/types'
|
|
12
|
-
|
|
13
|
-
const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/i
|
|
14
|
-
|
|
15
|
-
export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) => {
|
|
16
|
-
const gitConfig = getGitUserConfig(cwd)
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
options: [
|
|
20
|
-
defineTemplateOption<{owner: string; name: string}>({
|
|
21
|
-
name: 'repo',
|
|
22
|
-
type: 'string',
|
|
23
|
-
description: 'git url',
|
|
24
|
-
validate: (v) => {
|
|
25
|
-
if (!v) return true
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
gitUrlParse(v)
|
|
29
|
-
|
|
30
|
-
return true
|
|
31
|
-
} catch {
|
|
32
|
-
return 'invalid git url'
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
parse: (v) => {
|
|
36
|
-
if (!v) return null
|
|
37
|
-
|
|
38
|
-
const result = gitUrlParse(v)
|
|
39
|
-
|
|
40
|
-
return {source: result.source, owner: result.owner, name: result.name}
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
defineTemplateOption({
|
|
44
|
-
name: 'pkgName',
|
|
45
|
-
type: 'string',
|
|
46
|
-
description: 'package name',
|
|
47
|
-
initial: (options) => options['repo']?.name || undefined,
|
|
48
|
-
validate: (v) => {
|
|
49
|
-
if (!v) return 'package name is required'
|
|
50
|
-
|
|
51
|
-
const match = RE_NAME.exec(v)
|
|
52
|
-
|
|
53
|
-
if (!match) {
|
|
54
|
-
return 'invalid package name'
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return true
|
|
58
|
-
},
|
|
59
|
-
parse: (v) => {
|
|
60
|
-
if (!v) {
|
|
61
|
-
throw new Error('package name is required')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const match = RE_NAME.exec(v)
|
|
65
|
-
|
|
66
|
-
if (!match) {
|
|
67
|
-
throw new Error('invalid package name')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const [scope, name] = v.split('/')
|
|
71
|
-
|
|
72
|
-
return {scope, name, fullName: v}
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
|
-
defineTemplateOption({
|
|
76
|
-
name: 'description',
|
|
77
|
-
type: 'string',
|
|
78
|
-
description: 'package description',
|
|
79
|
-
}),
|
|
80
|
-
defineTemplateOption({
|
|
81
|
-
name: 'authorName',
|
|
82
|
-
type: 'string',
|
|
83
|
-
description: 'package author name',
|
|
84
|
-
initial: gitConfig.user,
|
|
85
|
-
}),
|
|
86
|
-
defineTemplateOption({
|
|
87
|
-
name: 'authorEmail',
|
|
88
|
-
type: 'string',
|
|
89
|
-
description: 'package author email',
|
|
90
|
-
initial: gitConfig.email,
|
|
91
|
-
}),
|
|
92
|
-
defineTemplateOption({
|
|
93
|
-
name: 'license',
|
|
94
|
-
type: 'string',
|
|
95
|
-
description: 'package license',
|
|
96
|
-
initial: 'MIT',
|
|
97
|
-
validate: (v) => {
|
|
98
|
-
if (!v) return 'license is required'
|
|
99
|
-
|
|
100
|
-
return true
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
],
|
|
104
|
-
|
|
105
|
-
features: [
|
|
106
|
-
{
|
|
107
|
-
name: 'eslint',
|
|
108
|
-
optional: true,
|
|
109
|
-
initial: true,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'prettier',
|
|
113
|
-
optional: true,
|
|
114
|
-
initial: true,
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: 'typescript',
|
|
118
|
-
optional: true,
|
|
119
|
-
initial: true,
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
|
|
123
|
-
async getFiles(options, features) {
|
|
124
|
-
const {pkgName, repo} = options
|
|
125
|
-
const {fullName: name} = pkgName
|
|
126
|
-
|
|
127
|
-
const author =
|
|
128
|
-
[options['authorName'], options['authorEmail'] && `<${options['authorEmail']}>`]
|
|
129
|
-
.filter(Boolean)
|
|
130
|
-
.join(' ') ?? undefined
|
|
131
|
-
|
|
132
|
-
const pkgJson: PackageJSON & {
|
|
133
|
-
prettier?: '@sanity/prettier-config'
|
|
134
|
-
['lint-staged']?: Record<string, string[]>
|
|
135
|
-
} = {
|
|
136
|
-
name,
|
|
137
|
-
'version': '0.0.0',
|
|
138
|
-
'description': options['description'] ?? undefined,
|
|
139
|
-
'keywords': [],
|
|
140
|
-
'homepage': undefined,
|
|
141
|
-
'bugs': undefined,
|
|
142
|
-
'repository': undefined,
|
|
143
|
-
'license': options['license'],
|
|
144
|
-
author,
|
|
145
|
-
'sideEffects': false,
|
|
146
|
-
'type': 'module',
|
|
147
|
-
'exports': {
|
|
148
|
-
'.': {
|
|
149
|
-
source: features['typescript'] ? './src/index.ts' : './src/index.js',
|
|
150
|
-
require: './dist/index.cjs',
|
|
151
|
-
default: './dist/index.js',
|
|
152
|
-
},
|
|
153
|
-
'./package.json': './package.json',
|
|
154
|
-
},
|
|
155
|
-
'main': './dist/index.cjs',
|
|
156
|
-
'module': './dist/index.js',
|
|
157
|
-
'types': undefined,
|
|
158
|
-
'files': ['dist', 'src'],
|
|
159
|
-
'scripts': {
|
|
160
|
-
build: 'pkg build --strict --clean --check',
|
|
161
|
-
format: features['prettier'] ? 'prettier --write --cache --ignore-unknown .' : undefined,
|
|
162
|
-
},
|
|
163
|
-
'lint-staged': features['prettier']
|
|
164
|
-
? {
|
|
165
|
-
'*': ['prettier --write --cache --ignore-unknown'],
|
|
166
|
-
}
|
|
167
|
-
: undefined,
|
|
168
|
-
'browserslist': 'extends @sanity/browserslist-config',
|
|
169
|
-
'prettier': features['prettier'] ? '@sanity/prettier-config' : undefined,
|
|
170
|
-
'dependencies': {},
|
|
171
|
-
'devDependencies': {
|
|
172
|
-
'@sanity/pkg-utils': '^6',
|
|
173
|
-
'@sanity/prettier-config': features['prettier'] ? '^1' : undefined,
|
|
174
|
-
'@typescript-eslint/eslint-plugin': undefined,
|
|
175
|
-
'@typescript-eslint/parser': undefined,
|
|
176
|
-
'eslint': undefined,
|
|
177
|
-
'eslint-config-prettier': undefined,
|
|
178
|
-
'eslint-plugin-import': undefined,
|
|
179
|
-
'eslint-plugin-prettier': undefined,
|
|
180
|
-
'eslint-plugin-simple-import-sort': undefined,
|
|
181
|
-
'lint-staged': '^15',
|
|
182
|
-
'prettier': features['prettier'] ? '^3' : undefined,
|
|
183
|
-
'typescript': undefined,
|
|
184
|
-
},
|
|
185
|
-
'engines': {
|
|
186
|
-
node: '>=18.0.0',
|
|
187
|
-
},
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const files: PkgTemplateFile[] = []
|
|
191
|
-
|
|
192
|
-
// .editorconfig
|
|
193
|
-
files.push({
|
|
194
|
-
name: '.editorconfig',
|
|
195
|
-
contents: outdent`
|
|
196
|
-
root = true
|
|
197
|
-
|
|
198
|
-
[*]
|
|
199
|
-
charset = utf-8
|
|
200
|
-
indent_style = space
|
|
201
|
-
indent_size = 2
|
|
202
|
-
end_of_line = lf
|
|
203
|
-
insert_final_newline = true
|
|
204
|
-
trim_trailing_whitespace = true
|
|
205
|
-
`,
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
// .gitignore
|
|
209
|
-
files.push({
|
|
210
|
-
name: '.gitignore',
|
|
211
|
-
contents: outdent`
|
|
212
|
-
*.local
|
|
213
|
-
*.log
|
|
214
|
-
*.tgz
|
|
215
|
-
|
|
216
|
-
.DS_Store
|
|
217
|
-
dist
|
|
218
|
-
etc
|
|
219
|
-
node_modules
|
|
220
|
-
`,
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
if (features['prettier']) {
|
|
224
|
-
files.push({
|
|
225
|
-
name: '.prettierignore',
|
|
226
|
-
contents: outdent`
|
|
227
|
-
dist
|
|
228
|
-
pnpm-lock.yaml
|
|
229
|
-
`,
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (repo) {
|
|
234
|
-
pkgJson.repository = {
|
|
235
|
-
type: 'git',
|
|
236
|
-
url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`,
|
|
237
|
-
}
|
|
238
|
-
pkgJson.bugs = {
|
|
239
|
-
url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`,
|
|
240
|
-
}
|
|
241
|
-
pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (features['typescript']) {
|
|
245
|
-
pkgJson.types = './dist/index.d.ts'
|
|
246
|
-
|
|
247
|
-
pkgJson.scripts = {
|
|
248
|
-
...pkgJson.scripts,
|
|
249
|
-
['ts:check']: 'tsc --noEmit',
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const devDependencies = pkgJson.devDependencies
|
|
253
|
-
|
|
254
|
-
if (isRecord(devDependencies)) {
|
|
255
|
-
devDependencies['typescript'] = '^5.4'
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (features['eslint']) {
|
|
260
|
-
const eslintConfig: any = {
|
|
261
|
-
root: true,
|
|
262
|
-
env: {
|
|
263
|
-
browser: true,
|
|
264
|
-
es6: true,
|
|
265
|
-
node: true,
|
|
266
|
-
},
|
|
267
|
-
extends: [
|
|
268
|
-
'eslint:recommended',
|
|
269
|
-
features['prettier'] ? 'plugin:prettier/recommended' : undefined,
|
|
270
|
-
].filter(Boolean),
|
|
271
|
-
parserOptions: {
|
|
272
|
-
ecmaVersion: 2020,
|
|
273
|
-
sourceType: 'module',
|
|
274
|
-
},
|
|
275
|
-
plugins: [
|
|
276
|
-
'import',
|
|
277
|
-
'simple-import-sort',
|
|
278
|
-
features['prettier'] ? 'prettier' : undefined,
|
|
279
|
-
].filter(Boolean),
|
|
280
|
-
rules: {
|
|
281
|
-
'no-console': 'error',
|
|
282
|
-
'no-shadow': 'error',
|
|
283
|
-
'no-warning-comments': ['warn', {location: 'start', terms: ['todo', 'fixme']}],
|
|
284
|
-
'quote-props': ['warn', 'consistent-as-needed'],
|
|
285
|
-
'simple-import-sort/exports': 'warn',
|
|
286
|
-
'simple-import-sort/imports': 'warn',
|
|
287
|
-
'strict': ['warn', 'global'],
|
|
288
|
-
},
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
files.push({
|
|
292
|
-
name: '.eslintignore',
|
|
293
|
-
contents: outdent`
|
|
294
|
-
dist
|
|
295
|
-
`,
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
pkgJson.scripts = {
|
|
299
|
-
...pkgJson.scripts,
|
|
300
|
-
lint: features['typescript']
|
|
301
|
-
? 'eslint . --ext .cjs,.js,.ts,.tsx'
|
|
302
|
-
: 'eslint . --ext .cjs,.js',
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
pkgJson.devDependencies = {
|
|
306
|
-
...pkgJson.devDependencies,
|
|
307
|
-
'eslint': '^8',
|
|
308
|
-
'eslint-config-prettier': features['prettier'] ? '^9' : undefined,
|
|
309
|
-
'eslint-plugin-import': '^2',
|
|
310
|
-
'eslint-plugin-prettier': features['prettier'] ? '^5' : undefined,
|
|
311
|
-
'eslint-plugin-simple-import-sort': '^12',
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (features['typescript']) {
|
|
315
|
-
pkgJson.devDependencies = {
|
|
316
|
-
...pkgJson.devDependencies,
|
|
317
|
-
'@typescript-eslint/eslint-plugin': '^7',
|
|
318
|
-
'@typescript-eslint/parser': '^7',
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const eslintConfigOverride: any = {
|
|
322
|
-
files: ['**/*.ts', '**/*.tsx'],
|
|
323
|
-
parser: '@typescript-eslint/parser',
|
|
324
|
-
parserOptions: {
|
|
325
|
-
project: ['./tsconfig.json'],
|
|
326
|
-
},
|
|
327
|
-
extends: [
|
|
328
|
-
'eslint:recommended',
|
|
329
|
-
features['prettier'] ? 'plugin:prettier/recommended' : undefined,
|
|
330
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
331
|
-
'plugin:@typescript-eslint/recommended',
|
|
332
|
-
].filter(Boolean),
|
|
333
|
-
plugins: [
|
|
334
|
-
'import',
|
|
335
|
-
'@typescript-eslint',
|
|
336
|
-
'simple-import-sort',
|
|
337
|
-
features['prettier'] ? 'prettier' : undefined,
|
|
338
|
-
].filter(Boolean),
|
|
339
|
-
rules: {
|
|
340
|
-
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
|
341
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
342
|
-
'@typescript-eslint/member-delimiter-style': 'off',
|
|
343
|
-
'@typescript-eslint/no-empty-interface': 'off',
|
|
344
|
-
},
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
eslintConfig.overrides = [eslintConfigOverride]
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
files.push({
|
|
351
|
-
name: '.eslintrc.cjs',
|
|
352
|
-
contents: await prettierFormat(
|
|
353
|
-
resolve(packagePath, '.eslintrc.cjs'),
|
|
354
|
-
outdent`
|
|
355
|
-
'use strict'
|
|
356
|
-
|
|
357
|
-
/** @type import('eslint').Linter.Config */
|
|
358
|
-
module.exports = ${JSON.stringify(eslintConfig, null, 2)}
|
|
359
|
-
`,
|
|
360
|
-
prettierConfig,
|
|
361
|
-
),
|
|
362
|
-
})
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (features['typescript']) {
|
|
366
|
-
files.push({
|
|
367
|
-
name: 'tsconfig.settings.json',
|
|
368
|
-
contents: await prettierFormat(
|
|
369
|
-
resolve(packagePath, 'tsconfig.settings.json'),
|
|
370
|
-
outdent`
|
|
371
|
-
{
|
|
372
|
-
"extends": "@sanity/pkg-utils/tsconfig/strictest.json",
|
|
373
|
-
"compilerOptions": {
|
|
374
|
-
"rootDir": ".",
|
|
375
|
-
"outDir": "./dist"
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
`,
|
|
379
|
-
prettierConfig,
|
|
380
|
-
),
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
files.push({
|
|
384
|
-
name: 'tsconfig.dist.json',
|
|
385
|
-
contents: await prettierFormat(
|
|
386
|
-
resolve(packagePath, 'tsconfig.dist.json'),
|
|
387
|
-
outdent`
|
|
388
|
-
{
|
|
389
|
-
"extends": "./tsconfig.settings",
|
|
390
|
-
"include": ["./src"],
|
|
391
|
-
"exclude": ["./src/**/*.test.ts"]
|
|
392
|
-
}
|
|
393
|
-
`,
|
|
394
|
-
prettierConfig,
|
|
395
|
-
),
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
files.push({
|
|
399
|
-
name: 'tsconfig.json',
|
|
400
|
-
contents: await prettierFormat(
|
|
401
|
-
resolve(packagePath, 'tsconfig.json'),
|
|
402
|
-
outdent`
|
|
403
|
-
{
|
|
404
|
-
"extends": "./tsconfig.settings",
|
|
405
|
-
"include": ["./**/*.cjs", "./**/*.ts", "./**/*.tsx"],
|
|
406
|
-
"exclude": ["./node_modules"]
|
|
407
|
-
}
|
|
408
|
-
`,
|
|
409
|
-
prettierConfig,
|
|
410
|
-
),
|
|
411
|
-
})
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// source file
|
|
415
|
-
if (features['typescript']) {
|
|
416
|
-
files.push({
|
|
417
|
-
name: 'package.config.ts',
|
|
418
|
-
contents: await prettierFormat(
|
|
419
|
-
resolve(packagePath, 'package.config.ts'),
|
|
420
|
-
outdent`
|
|
421
|
-
import {defineConfig} from '@sanity/pkg-utils'
|
|
422
|
-
|
|
423
|
-
// https://github.com/sanity-io/pkg-utils#configuration
|
|
424
|
-
export default defineConfig({
|
|
425
|
-
// the path to the tsconfig file for distributed builds
|
|
426
|
-
tsconfig: 'tsconfig.dist.json',
|
|
427
|
-
})
|
|
428
|
-
`,
|
|
429
|
-
prettierConfig,
|
|
430
|
-
),
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
files.push({
|
|
434
|
-
name: 'src/index.ts',
|
|
435
|
-
contents: await prettierFormat(
|
|
436
|
-
resolve(packagePath, 'src/index.ts'),
|
|
437
|
-
outdent`
|
|
438
|
-
/** @public */
|
|
439
|
-
export function main(): void {
|
|
440
|
-
//
|
|
441
|
-
}
|
|
442
|
-
`,
|
|
443
|
-
prettierConfig,
|
|
444
|
-
),
|
|
445
|
-
})
|
|
446
|
-
} else {
|
|
447
|
-
files.push({
|
|
448
|
-
name: 'package.config.js',
|
|
449
|
-
contents: await prettierFormat(
|
|
450
|
-
resolve(packagePath, 'package.config.js'),
|
|
451
|
-
outdent`
|
|
452
|
-
import {defineConfig} from '@sanity/pkg-utils'
|
|
453
|
-
|
|
454
|
-
export default defineConfig({
|
|
455
|
-
extract: {
|
|
456
|
-
rules: {
|
|
457
|
-
// do not require internal members to be prefixed with \`_\`
|
|
458
|
-
'ae-internal-missing-underscore': 'off',
|
|
459
|
-
},
|
|
460
|
-
},
|
|
461
|
-
})
|
|
462
|
-
`,
|
|
463
|
-
prettierConfig,
|
|
464
|
-
),
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
files.push({
|
|
468
|
-
name: 'src/index.js',
|
|
469
|
-
contents: await prettierFormat(
|
|
470
|
-
resolve(packagePath, 'src/index.js'),
|
|
471
|
-
outdent`
|
|
472
|
-
/** @public */
|
|
473
|
-
export function main() {
|
|
474
|
-
//
|
|
475
|
-
}
|
|
476
|
-
`,
|
|
477
|
-
prettierConfig,
|
|
478
|
-
),
|
|
479
|
-
})
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// Resolve latest dependencies
|
|
483
|
-
try {
|
|
484
|
-
pkgJson.dependencies = await resolveLatestDeps(pkgJson.dependencies ?? {})
|
|
485
|
-
} catch (error) {
|
|
486
|
-
logger.warn(error instanceof Error ? error.message : error)
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// Resolve latest devDependencies
|
|
490
|
-
try {
|
|
491
|
-
pkgJson.devDependencies = await resolveLatestDeps(pkgJson.devDependencies ?? {})
|
|
492
|
-
} catch (error) {
|
|
493
|
-
logger.warn(error instanceof Error ? error.message : error)
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
files.push({
|
|
497
|
-
name: 'package.json',
|
|
498
|
-
contents: await prettierFormat(
|
|
499
|
-
resolve(packagePath, 'package.json'),
|
|
500
|
-
JSON.stringify(pkgJson, null, 2),
|
|
501
|
-
prettierConfig,
|
|
502
|
-
),
|
|
503
|
-
})
|
|
504
|
-
|
|
505
|
-
return files
|
|
506
|
-
},
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
function prettierFormat(
|
|
511
|
-
filepath: string,
|
|
512
|
-
input: string,
|
|
513
|
-
prettierOptions: PrettierConfig | undefined,
|
|
514
|
-
) {
|
|
515
|
-
return format(input, {...prettierOptions, plugins: [], filepath})
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
async function resolveLatestDeps(deps: Record<string, string | undefined>) {
|
|
519
|
-
const depsEntries = Object.entries(deps)
|
|
520
|
-
const latestDeps: Record<string, string> = {}
|
|
521
|
-
|
|
522
|
-
for (const entry of depsEntries) {
|
|
523
|
-
const [name, version] = entry
|
|
524
|
-
|
|
525
|
-
if (version) {
|
|
526
|
-
const latestVersion = await getLatestVersion(name, version)
|
|
527
|
-
|
|
528
|
-
latestDeps[name] = latestVersion ? `^${latestVersion}` : version
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
return latestDeps
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
function getGitUserConfig(cwd: string): {user?: string; email?: string} {
|
|
536
|
-
let user: string | undefined
|
|
537
|
-
let email: string | undefined
|
|
538
|
-
|
|
539
|
-
try {
|
|
540
|
-
user = execSync('git config user.name', {encoding: 'utf8', cwd}).trim() || undefined
|
|
541
|
-
email = execSync('git config user.email', {encoding: 'utf8', cwd}).trim() || undefined
|
|
542
|
-
} catch {
|
|
543
|
-
/* ignore */
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return {user, email}
|
|
547
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './default'
|
package/src/node/watch.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import {switchMap} from 'rxjs'
|
|
3
|
-
import {loadConfig} from './core/config/loadConfig'
|
|
4
|
-
import {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting'
|
|
5
|
-
import {createLogger} from './logger'
|
|
6
|
-
import {resolveBuildContext} from './resolveBuildContext'
|
|
7
|
-
import {resolveWatchTasks} from './resolveWatchTasks'
|
|
8
|
-
import {watchTaskHandlers} from './tasks'
|
|
9
|
-
import {type TaskHandler, type WatchTask} from './tasks/types'
|
|
10
|
-
import {watchConfigFiles} from './watchConfigFiles'
|
|
11
|
-
|
|
12
|
-
/** @public */
|
|
13
|
-
export async function watch(options: {
|
|
14
|
-
cwd: string
|
|
15
|
-
strict?: boolean
|
|
16
|
-
tsconfig?: string
|
|
17
|
-
}): Promise<void> {
|
|
18
|
-
const {cwd, strict = false, tsconfig: tsconfigOption} = options
|
|
19
|
-
|
|
20
|
-
const logger = createLogger()
|
|
21
|
-
|
|
22
|
-
const configFiles$ = await watchConfigFiles({cwd, logger})
|
|
23
|
-
|
|
24
|
-
const ctx$ = configFiles$.pipe(
|
|
25
|
-
switchMap(async (configFiles) => {
|
|
26
|
-
const files = configFiles.map((f) => path.relative(cwd, f))
|
|
27
|
-
|
|
28
|
-
const packageJsonPath = files.find((f) => f === 'package.json')
|
|
29
|
-
|
|
30
|
-
if (!packageJsonPath) {
|
|
31
|
-
throw new Error('missing package.json')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const config = await loadConfig({cwd})
|
|
35
|
-
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
36
|
-
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
37
|
-
|
|
38
|
-
return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|
|
39
|
-
}),
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
ctx$.subscribe(async (ctx) => {
|
|
43
|
-
const watchTasks = resolveWatchTasks(ctx)
|
|
44
|
-
|
|
45
|
-
for (const task of watchTasks) {
|
|
46
|
-
const handler = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>
|
|
47
|
-
const result$ = handler.exec(ctx, task)
|
|
48
|
-
|
|
49
|
-
result$.subscribe({
|
|
50
|
-
error: (err) => {
|
|
51
|
-
ctx.logger.error(err)
|
|
52
|
-
ctx.logger.log()
|
|
53
|
-
|
|
54
|
-
process.exit(1)
|
|
55
|
-
},
|
|
56
|
-
next: (result) => {
|
|
57
|
-
handler.complete(ctx, task, result)
|
|
58
|
-
},
|
|
59
|
-
complete: () => {
|
|
60
|
-
ctx.logger.success(handler.name(ctx, task))
|
|
61
|
-
ctx.logger.log()
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import type {Observable} from 'rxjs'
|
|
3
|
-
import {distinctUntilChanged, scan, startWith} from 'rxjs/operators'
|
|
4
|
-
import {globFiles} from './globFiles'
|
|
5
|
-
import type {Logger} from './logger'
|
|
6
|
-
import {watchFiles} from './watchFiles'
|
|
7
|
-
|
|
8
|
-
export async function watchConfigFiles(options: {
|
|
9
|
-
cwd: string
|
|
10
|
-
logger: Logger
|
|
11
|
-
}): Promise<Observable<string[]>> {
|
|
12
|
-
const {cwd, logger} = options
|
|
13
|
-
|
|
14
|
-
const initialFiles = await globFiles([
|
|
15
|
-
path.resolve(cwd, 'package.json'),
|
|
16
|
-
path.resolve(cwd, 'package.config.cjs'),
|
|
17
|
-
path.resolve(cwd, 'package.config.js'),
|
|
18
|
-
path.resolve(cwd, 'package.config.ts'),
|
|
19
|
-
])
|
|
20
|
-
|
|
21
|
-
const fileEvent$ = watchFiles([
|
|
22
|
-
path.resolve(cwd, 'package.json'),
|
|
23
|
-
path.resolve(cwd, 'package.config.cjs'),
|
|
24
|
-
path.resolve(cwd, 'package.config.js'),
|
|
25
|
-
path.resolve(cwd, 'package.config.ts'),
|
|
26
|
-
])
|
|
27
|
-
|
|
28
|
-
return fileEvent$.pipe(
|
|
29
|
-
scan((files, fileEvent) => {
|
|
30
|
-
if (fileEvent.type === 'add') {
|
|
31
|
-
return files.concat(fileEvent.file)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (fileEvent.type === 'unlink') {
|
|
35
|
-
return files.filter((f) => f !== fileEvent.file)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (fileEvent.type === 'change') {
|
|
39
|
-
logger.log(
|
|
40
|
-
'--------------------------------------------------------------------------------',
|
|
41
|
-
)
|
|
42
|
-
logger.info(path.relative(cwd, fileEvent.file), 'changed')
|
|
43
|
-
logger.log('')
|
|
44
|
-
|
|
45
|
-
return files.slice(0) // trigger update
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return files
|
|
49
|
-
}, initialFiles),
|
|
50
|
-
startWith(initialFiles),
|
|
51
|
-
distinctUntilChanged(),
|
|
52
|
-
)
|
|
53
|
-
}
|
package/src/node/watchFiles.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as chokidar from 'chokidar'
|
|
2
|
-
import type {EventName} from 'chokidar/handler.js'
|
|
3
|
-
import {Observable} from 'rxjs'
|
|
4
|
-
|
|
5
|
-
export interface FileEvent {
|
|
6
|
-
type: EventName
|
|
7
|
-
file: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function watchFiles(patterns: string[]): Observable<FileEvent> {
|
|
11
|
-
return new Observable((observer) => {
|
|
12
|
-
const watcher = chokidar.watch(patterns, {
|
|
13
|
-
ignoreInitial: true,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
function handleFileEvent(type: EventName, file: string | Error) {
|
|
17
|
-
if (type === 'error' || file instanceof Error) {
|
|
18
|
-
observer.error(file)
|
|
19
|
-
} else {
|
|
20
|
-
observer.next({type, file})
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
watcher.on('all', handleFileEvent)
|
|
25
|
-
|
|
26
|
-
return () => {
|
|
27
|
-
watcher.off('all', handleFileEvent)
|
|
28
|
-
watcher.close()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|