@sanity/pkg-utils 3.1.1 → 3.2.1
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/{build-ttL1gCQE.cjs → build-5-t0rNQ5.cjs} +3 -3
- package/dist/_chunks/{build-ttL1gCQE.cjs.map → build-5-t0rNQ5.cjs.map} +1 -1
- package/dist/_chunks/{buildAction-2FuCIzEr.cjs → buildAction-XzgSYD6h.cjs} +2 -2
- package/dist/_chunks/{buildAction-2FuCIzEr.cjs.map → buildAction-XzgSYD6h.cjs.map} +1 -1
- package/dist/_chunks/{check-X8xKPDnl.cjs → check-K-76aP0H.cjs} +2 -2
- package/dist/_chunks/{check-X8xKPDnl.cjs.map → check-K-76aP0H.cjs.map} +1 -1
- package/dist/_chunks/{checkAction-uQWLDlBA.cjs → checkAction-ovZpdoTW.cjs} +2 -2
- package/dist/_chunks/{checkAction-uQWLDlBA.cjs.map → checkAction-ovZpdoTW.cjs.map} +1 -1
- package/dist/_chunks/{consoleSpy--ReK-_gE.cjs → consoleSpy-Njnvw7-i.cjs} +4 -4
- package/dist/_chunks/consoleSpy-Njnvw7-i.cjs.map +1 -0
- package/dist/_chunks/{index-jC5AhNHb.cjs → index-jKQCY5H6.cjs} +4 -5
- package/dist/_chunks/index-jKQCY5H6.cjs.map +1 -0
- package/dist/_chunks/{init-gkPbG69g.cjs → init-F_vsNarH.cjs} +78 -49
- package/dist/_chunks/init-F_vsNarH.cjs.map +1 -0
- package/dist/_chunks/{initAction-bz-ok0LO.cjs → initAction-dKWPRJL7.cjs} +2 -2
- package/dist/_chunks/{initAction-bz-ok0LO.cjs.map → initAction-dKWPRJL7.cjs.map} +1 -1
- package/dist/_chunks/{watch-UrB-haEA.cjs → watch-8dkaWImB.cjs} +3 -3
- package/dist/_chunks/{watch-UrB-haEA.cjs.map → watch-8dkaWImB.cjs.map} +1 -1
- package/dist/_chunks/{watchAction-1U3Gh9UD.cjs → watchAction-MPezXdut.cjs} +2 -2
- package/dist/_chunks/{watchAction-1U3Gh9UD.cjs.map → watchAction-MPezXdut.cjs.map} +1 -1
- package/dist/cli.cjs +5 -5
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +6 -5
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +13 -42
- package/src/node/core/config/types.ts +1 -0
- package/src/node/core/pkg/types.ts +4 -4
- package/src/node/core/ts/loadTSConfig.ts +2 -2
- package/src/node/resolveBuildContext.ts +2 -2
- package/src/node/tasks/dts/createApiExtractorConfig.ts +3 -1
- package/src/node/tasks/dts/doExtract.ts +2 -0
- package/src/node/tasks/dts/extractTypes.ts +3 -0
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +2 -2
- package/src/node/templates/default/template.ts +139 -92
- package/dist/_chunks/consoleSpy--ReK-_gE.cjs.map +0 -1
- package/dist/_chunks/index-jC5AhNHb.cjs.map +0 -1
- package/dist/_chunks/init-gkPbG69g.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -57,35 +57,6 @@
|
|
|
57
57
|
"eslint --ext .cjs,.js,.ts,.tsx --fix"
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
|
-
"prettier": {
|
|
61
|
-
"bracketSpacing": false,
|
|
62
|
-
"plugins": [
|
|
63
|
-
"prettier-plugin-packagejson"
|
|
64
|
-
],
|
|
65
|
-
"printWidth": 100,
|
|
66
|
-
"semi": false,
|
|
67
|
-
"singleQuote": true,
|
|
68
|
-
"tabWidth": 2,
|
|
69
|
-
"overrides": [
|
|
70
|
-
{
|
|
71
|
-
"files": [
|
|
72
|
-
"*.json5"
|
|
73
|
-
],
|
|
74
|
-
"options": {
|
|
75
|
-
"quoteProps": "preserve",
|
|
76
|
-
"singleQuote": false
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"files": [
|
|
81
|
-
"*.yml"
|
|
82
|
-
],
|
|
83
|
-
"options": {
|
|
84
|
-
"singleQuote": false
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
60
|
"dependencies": {
|
|
90
61
|
"@babel/core": "^7.23.2",
|
|
91
62
|
"@babel/preset-env": "^7.23.2",
|
|
@@ -107,7 +78,7 @@
|
|
|
107
78
|
"esbuild-register": "^3.5.0",
|
|
108
79
|
"find-config": "^1.0.0",
|
|
109
80
|
"get-latest-version": "^5.1.0",
|
|
110
|
-
"git-url-parse": "^13.1.
|
|
81
|
+
"git-url-parse": "^13.1.1",
|
|
111
82
|
"globby": "^11.1.0",
|
|
112
83
|
"jsonc-parser": "^3.2.0",
|
|
113
84
|
"mkdirp": "^3.0.1",
|
|
@@ -127,8 +98,8 @@
|
|
|
127
98
|
"zod": "^3.22.4"
|
|
128
99
|
},
|
|
129
100
|
"devDependencies": {
|
|
130
|
-
"@commitlint/cli": "^
|
|
131
|
-
"@commitlint/config-conventional": "^
|
|
101
|
+
"@commitlint/cli": "^18.0.0",
|
|
102
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
132
103
|
"@types/babel__core": "^7.20.3",
|
|
133
104
|
"@types/cpx": "^1.5.4",
|
|
134
105
|
"@types/find-config": "^1.0.3",
|
|
@@ -138,19 +109,19 @@
|
|
|
138
109
|
"@types/prompts": "^2.4.7",
|
|
139
110
|
"@types/rimraf": "^3.0.2",
|
|
140
111
|
"@types/treeify": "^1.0.2",
|
|
141
|
-
"@types/uuid": "^9.0.
|
|
112
|
+
"@types/uuid": "^9.0.6",
|
|
142
113
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
143
114
|
"@typescript-eslint/parser": "^6.8.0",
|
|
144
115
|
"commitizen": "^4.3.0",
|
|
145
116
|
"cpx": "^1.5.0",
|
|
146
117
|
"cz-conventional-changelog": "^3.3.0",
|
|
147
|
-
"eslint": "^8.
|
|
118
|
+
"eslint": "^8.52.0",
|
|
148
119
|
"eslint-config-prettier": "^9.0.0",
|
|
149
|
-
"eslint-plugin-import": "^2.
|
|
120
|
+
"eslint-plugin-import": "^2.29.0",
|
|
150
121
|
"eslint-plugin-prettier": "^5.0.1",
|
|
151
122
|
"eslint-plugin-simple-import-sort": "10.0.0",
|
|
152
123
|
"husky": "^8.0.3",
|
|
153
|
-
"lint-staged": "^15.0.
|
|
124
|
+
"lint-staged": "^15.0.2",
|
|
154
125
|
"npm-run-all": "^4.1.5",
|
|
155
126
|
"outdent": "^0.8.0",
|
|
156
127
|
"recast": "^0.23.4",
|
|
@@ -159,7 +130,7 @@
|
|
|
159
130
|
"typescript": "^5.2.2",
|
|
160
131
|
"vitest": "^0.34.6",
|
|
161
132
|
"vitest-github-actions-reporter": "^0.10.0",
|
|
162
|
-
"@sanity/pkg-utils": "3.
|
|
133
|
+
"@sanity/pkg-utils": "3.2.1"
|
|
163
134
|
},
|
|
164
135
|
"peerDependencies": {
|
|
165
136
|
"typescript": "^4.7 || ^5"
|
|
@@ -173,10 +144,10 @@
|
|
|
173
144
|
},
|
|
174
145
|
"scripts": {
|
|
175
146
|
"build": "run-s clean build:pkg check:pkg",
|
|
176
|
-
"build:pkg": "node
|
|
177
|
-
"check:pkg": "node
|
|
147
|
+
"build:pkg": "node -r esbuild-register scripts/build",
|
|
148
|
+
"check:pkg": "node -r esbuild-register scripts/check",
|
|
178
149
|
"check:types": "tsc --build",
|
|
179
|
-
"clean": "rimraf dist",
|
|
150
|
+
"clean": "rimraf dist test/env/__tmp__",
|
|
180
151
|
"commit": "cz",
|
|
181
152
|
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
182
153
|
"format": "prettier --write --cache --ignore-unknown . && eslint . --ext .cjs,.js,.ts,.tsx --fix --quiet",
|
|
@@ -186,6 +157,6 @@
|
|
|
186
157
|
"test": "run-s playground:clean test:clean vitest:run",
|
|
187
158
|
"test:clean": "rimraf test/env/__tmp__",
|
|
188
159
|
"vitest:run": "vitest run",
|
|
189
|
-
"watch": "node
|
|
160
|
+
"watch": "node -r esbuild-register scripts/watch"
|
|
190
161
|
}
|
|
191
162
|
}
|
|
@@ -8,9 +8,9 @@ export interface PackageJSON {
|
|
|
8
8
|
description?: string
|
|
9
9
|
keywords?: string[]
|
|
10
10
|
bin?: Record<string, string>
|
|
11
|
-
dependencies?: Record<string, string>
|
|
12
|
-
devDependencies?: Record<string, string>
|
|
13
|
-
peerDependencies?: Record<string, string>
|
|
11
|
+
dependencies?: Record<string, string | undefined>
|
|
12
|
+
devDependencies?: Record<string, string | undefined>
|
|
13
|
+
peerDependencies?: Record<string, string | undefined>
|
|
14
14
|
exports?: Record<
|
|
15
15
|
string,
|
|
16
16
|
| `./${string}.json`
|
|
@@ -40,7 +40,7 @@ export interface PackageJSON {
|
|
|
40
40
|
module?: string
|
|
41
41
|
types?: string
|
|
42
42
|
files?: string[]
|
|
43
|
-
scripts?: Record<string, string>
|
|
43
|
+
scripts?: Record<string, string | undefined>
|
|
44
44
|
browserslist?: string[]
|
|
45
45
|
engines?: {
|
|
46
46
|
node?: string
|
|
@@ -4,13 +4,13 @@ import ts from 'typescript'
|
|
|
4
4
|
export async function loadTSConfig(options: {
|
|
5
5
|
cwd: string
|
|
6
6
|
tsconfigPath: string
|
|
7
|
-
}): Promise<ts.ParsedCommandLine> {
|
|
7
|
+
}): Promise<ts.ParsedCommandLine | undefined> {
|
|
8
8
|
const {cwd, tsconfigPath} = options
|
|
9
9
|
|
|
10
10
|
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath)
|
|
11
11
|
|
|
12
12
|
if (!configPath) {
|
|
13
|
-
|
|
13
|
+
return undefined
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
@@ -53,8 +53,8 @@ export async function resolveBuildContext(options: {
|
|
|
53
53
|
|
|
54
54
|
const target: Record<PkgRuntime, string[]> = {
|
|
55
55
|
'*': webTarget.concat(nodeTarget),
|
|
56
|
-
browser: webTarget,
|
|
57
|
-
node: nodeTarget,
|
|
56
|
+
'browser': webTarget,
|
|
57
|
+
'node': nodeTarget,
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const parsedExports = parseExports({extMap, pkg, strict}).reduce<PkgExports>((acc, x) => {
|
|
@@ -2,6 +2,7 @@ import {IConfigFile, IExtractorMessagesConfig} from '@microsoft/api-extractor'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
|
|
4
4
|
export function createApiExtractorConfig(options: {
|
|
5
|
+
bundledPackages?: string[]
|
|
5
6
|
distPath: string
|
|
6
7
|
exportPath: string
|
|
7
8
|
filePath: string
|
|
@@ -11,6 +12,7 @@ export function createApiExtractorConfig(options: {
|
|
|
11
12
|
tsconfigPath: string
|
|
12
13
|
}): IConfigFile {
|
|
13
14
|
const {
|
|
15
|
+
bundledPackages,
|
|
14
16
|
distPath,
|
|
15
17
|
exportPath,
|
|
16
18
|
filePath,
|
|
@@ -25,7 +27,7 @@ export function createApiExtractorConfig(options: {
|
|
|
25
27
|
enabled: false,
|
|
26
28
|
reportFileName: '<unscopedPackageName>.api.md',
|
|
27
29
|
},
|
|
28
|
-
|
|
30
|
+
bundledPackages,
|
|
29
31
|
compiler: {
|
|
30
32
|
tsconfigFilePath: tsconfigPath,
|
|
31
33
|
},
|
|
@@ -47,6 +47,7 @@ export async function doExtract(
|
|
|
47
47
|
const targetPath = path.resolve(cwd, entry.targetPath)
|
|
48
48
|
const filePath = path.relative(outDir, targetPath)
|
|
49
49
|
const result = await extractTypes({
|
|
50
|
+
bundledPackages: config?.extract?.bundledPackages || [],
|
|
50
51
|
customTags: config?.extract?.customTags,
|
|
51
52
|
cwd,
|
|
52
53
|
distPath: outDir,
|
|
@@ -63,6 +64,7 @@ export async function doExtract(
|
|
|
63
64
|
messages.push(...result.messages)
|
|
64
65
|
|
|
65
66
|
const errors = result.messages.filter((msg) => msg.logLevel === 'error')
|
|
67
|
+
|
|
66
68
|
if (errors.length > 0) {
|
|
67
69
|
await rimraf(tmpPath)
|
|
68
70
|
throw new DtsError(`encountered ${errors.length} errors when extracting types`, errors)
|
|
@@ -16,6 +16,7 @@ import {extractModuleBlocksFromTypes} from './extractModuleBlocks'
|
|
|
16
16
|
import {getExtractMessagesConfig} from './getExtractMessagesConfig'
|
|
17
17
|
|
|
18
18
|
export async function extractTypes(options: {
|
|
19
|
+
bundledPackages?: string[]
|
|
19
20
|
customTags: NonNullable<PkgConfigOptions['extract']>['customTags']
|
|
20
21
|
cwd: string
|
|
21
22
|
distPath: string
|
|
@@ -29,6 +30,7 @@ export async function extractTypes(options: {
|
|
|
29
30
|
tsconfigPath: string
|
|
30
31
|
}): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
|
|
31
32
|
const {
|
|
33
|
+
bundledPackages,
|
|
32
34
|
customTags,
|
|
33
35
|
distPath,
|
|
34
36
|
exportPath,
|
|
@@ -47,6 +49,7 @@ export async function extractTypes(options: {
|
|
|
47
49
|
|
|
48
50
|
const extractorConfig: ExtractorConfig = ExtractorConfig.prepare({
|
|
49
51
|
configObject: createApiExtractorConfig({
|
|
52
|
+
bundledPackages,
|
|
50
53
|
distPath,
|
|
51
54
|
exportPath,
|
|
52
55
|
filePath,
|
|
@@ -32,7 +32,7 @@ export function getExtractMessagesConfig(options: {
|
|
|
32
32
|
},
|
|
33
33
|
|
|
34
34
|
extractorMessageReporting: {
|
|
35
|
-
default: {
|
|
35
|
+
'default': {
|
|
36
36
|
logLevel: 'warning' as ExtractorLogLevel,
|
|
37
37
|
addToApiReportFile: false,
|
|
38
38
|
},
|
|
@@ -64,7 +64,7 @@ export function getExtractMessagesConfig(options: {
|
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
tsdocMessageReporting: {
|
|
67
|
-
default: {
|
|
67
|
+
'default': {
|
|
68
68
|
logLevel: 'warning' as ExtractorLogLevel,
|
|
69
69
|
addToApiReportFile: false,
|
|
70
70
|
},
|
|
@@ -105,6 +105,11 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
105
105
|
optional: true,
|
|
106
106
|
initial: true,
|
|
107
107
|
},
|
|
108
|
+
{
|
|
109
|
+
name: 'prettier',
|
|
110
|
+
optional: true,
|
|
111
|
+
initial: true,
|
|
112
|
+
},
|
|
108
113
|
{
|
|
109
114
|
name: 'typescript',
|
|
110
115
|
optional: true,
|
|
@@ -121,69 +126,86 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
121
126
|
.filter(Boolean)
|
|
122
127
|
.join(' ') ?? undefined
|
|
123
128
|
|
|
124
|
-
const prettierConfig: PrettierConfig =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
const prettierConfig: PrettierConfig | undefined = features.prettier
|
|
130
|
+
? {
|
|
131
|
+
bracketSpacing: false,
|
|
132
|
+
plugins: ['prettier-plugin-packagejson'],
|
|
133
|
+
printWidth: 100,
|
|
134
|
+
quoteProps: 'consistent',
|
|
135
|
+
semi: false,
|
|
136
|
+
singleQuote: true,
|
|
137
|
+
tabWidth: 2,
|
|
138
|
+
overrides: [
|
|
139
|
+
{
|
|
140
|
+
files: ['*.yml'],
|
|
141
|
+
options: {
|
|
142
|
+
singleQuote: false,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
}
|
|
147
|
+
: undefined
|
|
140
148
|
|
|
141
149
|
const pkgJson: PackageJSON & {
|
|
142
150
|
prettier?: PrettierConfig
|
|
143
151
|
['lint-staged']?: Record<string, string[]>
|
|
144
152
|
} = {
|
|
145
153
|
name,
|
|
146
|
-
version: '0.0.0',
|
|
147
|
-
description: options.description ?? undefined,
|
|
148
|
-
keywords: [],
|
|
149
|
-
|
|
154
|
+
'version': '0.0.0',
|
|
155
|
+
'description': options.description ?? undefined,
|
|
156
|
+
'keywords': [],
|
|
157
|
+
'homepage': undefined,
|
|
158
|
+
'bugs': undefined,
|
|
159
|
+
'repository': undefined,
|
|
160
|
+
'license': options.license,
|
|
150
161
|
author,
|
|
151
|
-
type: 'module',
|
|
152
|
-
exports: {
|
|
162
|
+
'type': 'module',
|
|
163
|
+
'exports': {
|
|
153
164
|
'.': {
|
|
154
165
|
types: undefined,
|
|
155
166
|
source: features.typescript ? './src/index.ts' : './src/index.js',
|
|
156
|
-
require: './dist/index.cjs',
|
|
157
167
|
import: './dist/index.js',
|
|
168
|
+
require: './dist/index.cjs',
|
|
158
169
|
default: './dist/index.js',
|
|
159
170
|
},
|
|
160
171
|
'./package.json': './package.json',
|
|
161
172
|
},
|
|
162
|
-
main: './dist/index.cjs',
|
|
163
|
-
module: './dist/index.js',
|
|
164
|
-
source: features.typescript ? './src/index.ts' : './src/index.js',
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
'main': './dist/index.cjs',
|
|
174
|
+
'module': './dist/index.js',
|
|
175
|
+
'source': features.typescript ? './src/index.ts' : './src/index.js',
|
|
176
|
+
'types': undefined,
|
|
177
|
+
'files': ['dist', 'src'],
|
|
178
|
+
'scripts': {
|
|
179
|
+
'build': 'run-s clean pkg:build pkg:check',
|
|
180
|
+
'clean': 'rimraf dist',
|
|
181
|
+
'format': features.prettier ? 'prettier --write --cache --ignore-unknown .' : undefined,
|
|
170
182
|
'pkg:build': 'pkg build --strict',
|
|
171
183
|
'pkg:check': 'pkg check --strict',
|
|
172
184
|
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
'lint-staged': features.prettier
|
|
186
|
+
? {
|
|
187
|
+
'*': ['prettier --write --cache --ignore-unknown'],
|
|
188
|
+
}
|
|
189
|
+
: undefined,
|
|
190
|
+
// prettier: prettierConfig,
|
|
191
|
+
'dependencies': {},
|
|
192
|
+
'devDependencies': {
|
|
179
193
|
'@sanity/pkg-utils': '*',
|
|
194
|
+
'@typescript-eslint/eslint-plugin': undefined,
|
|
195
|
+
'@typescript-eslint/parser': undefined,
|
|
196
|
+
'eslint': undefined,
|
|
197
|
+
'eslint-config-prettier': undefined,
|
|
198
|
+
'eslint-plugin-import': undefined,
|
|
199
|
+
'eslint-plugin-prettier': undefined,
|
|
200
|
+
'eslint-plugin-simple-import-sort': undefined,
|
|
180
201
|
'lint-staged': '*',
|
|
181
202
|
'npm-run-all': '*',
|
|
182
|
-
prettier: '*',
|
|
183
|
-
'prettier-plugin-packagejson': '*',
|
|
184
|
-
rimraf: '*',
|
|
203
|
+
'prettier': features.prettier ? '*' : undefined,
|
|
204
|
+
'prettier-plugin-packagejson': features.prettier ? '*' : undefined,
|
|
205
|
+
'rimraf': '*',
|
|
206
|
+
'typescript': undefined,
|
|
185
207
|
},
|
|
186
|
-
engines: {
|
|
208
|
+
'engines': {
|
|
187
209
|
node: '>=18.0.0',
|
|
188
210
|
},
|
|
189
211
|
}
|
|
@@ -212,21 +234,33 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
212
234
|
contents: outdent`
|
|
213
235
|
*.local
|
|
214
236
|
*.log
|
|
237
|
+
*.tgz
|
|
215
238
|
|
|
216
239
|
.DS_Store
|
|
217
|
-
etc
|
|
218
240
|
dist
|
|
241
|
+
etc
|
|
219
242
|
node_modules
|
|
220
243
|
`,
|
|
221
244
|
})
|
|
222
245
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
246
|
+
if (features.prettier) {
|
|
247
|
+
files.push({
|
|
248
|
+
name: '.prettierignore',
|
|
249
|
+
contents: outdent`
|
|
250
|
+
dist
|
|
251
|
+
pnpm-lock.yaml
|
|
252
|
+
`,
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
files.push({
|
|
256
|
+
name: '.prettierrc',
|
|
257
|
+
contents: await format(
|
|
258
|
+
resolve(packagePath, '.prettierrc.json'),
|
|
259
|
+
JSON.stringify(prettierConfig, null, 2) + '\n',
|
|
260
|
+
prettierConfig,
|
|
261
|
+
),
|
|
262
|
+
})
|
|
263
|
+
}
|
|
230
264
|
|
|
231
265
|
if (repo) {
|
|
232
266
|
pkgJson.repository = {
|
|
@@ -250,7 +284,7 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
250
284
|
|
|
251
285
|
pkgJson.scripts = {
|
|
252
286
|
...pkgJson.scripts,
|
|
253
|
-
['
|
|
287
|
+
['ts:check']: 'tsc --build',
|
|
254
288
|
}
|
|
255
289
|
|
|
256
290
|
const devDependencies = pkgJson.devDependencies
|
|
@@ -269,23 +303,32 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
269
303
|
es6: true,
|
|
270
304
|
node: true,
|
|
271
305
|
},
|
|
272
|
-
extends: [
|
|
306
|
+
extends: [
|
|
307
|
+
'eslint:recommended',
|
|
308
|
+
features.prettier ? 'plugin:prettier/recommended' : undefined,
|
|
309
|
+
].filter(Boolean),
|
|
273
310
|
parserOptions: {
|
|
274
311
|
ecmaVersion: 2020,
|
|
275
312
|
sourceType: 'module',
|
|
276
313
|
},
|
|
277
|
-
plugins: [
|
|
314
|
+
plugins: [
|
|
315
|
+
'import',
|
|
316
|
+
'simple-import-sort',
|
|
317
|
+
features.prettier ? 'prettier' : undefined,
|
|
318
|
+
].filter(Boolean),
|
|
278
319
|
rules: {
|
|
279
320
|
'no-console': 'error',
|
|
280
321
|
'no-shadow': 'error',
|
|
281
322
|
'no-warning-comments': ['warn', {location: 'start', terms: ['todo', 'fixme']}],
|
|
323
|
+
'quote-props': ['warn', 'consistent-as-needed'],
|
|
324
|
+
'strict': ['warn', 'global'],
|
|
282
325
|
},
|
|
283
326
|
}
|
|
284
327
|
|
|
285
328
|
files.push({
|
|
286
329
|
name: '.eslintignore',
|
|
287
330
|
contents: outdent`
|
|
288
|
-
|
|
331
|
+
dist
|
|
289
332
|
`,
|
|
290
333
|
})
|
|
291
334
|
|
|
@@ -298,10 +341,11 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
298
341
|
|
|
299
342
|
pkgJson.devDependencies = {
|
|
300
343
|
...pkgJson.devDependencies,
|
|
301
|
-
eslint: '*',
|
|
302
|
-
'eslint-config-prettier': '*',
|
|
344
|
+
'eslint': '*',
|
|
345
|
+
'eslint-config-prettier': features.prettier ? '*' : undefined,
|
|
346
|
+
'eslint-plugin-simple-import-sort': '*',
|
|
303
347
|
'eslint-plugin-import': '*',
|
|
304
|
-
'eslint-plugin-prettier': '*',
|
|
348
|
+
'eslint-plugin-prettier': features.prettier ? '*' : undefined,
|
|
305
349
|
}
|
|
306
350
|
|
|
307
351
|
if (features.typescript) {
|
|
@@ -320,11 +364,16 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
320
364
|
},
|
|
321
365
|
extends: [
|
|
322
366
|
'eslint:recommended',
|
|
323
|
-
'plugin:prettier/recommended',
|
|
367
|
+
features.prettier ? 'plugin:prettier/recommended' : undefined,
|
|
324
368
|
'plugin:@typescript-eslint/eslint-recommended',
|
|
325
369
|
'plugin:@typescript-eslint/recommended',
|
|
326
370
|
].filter(Boolean),
|
|
327
|
-
plugins: [
|
|
371
|
+
plugins: [
|
|
372
|
+
'import',
|
|
373
|
+
'@typescript-eslint',
|
|
374
|
+
'simple-import-sort',
|
|
375
|
+
features.prettier ? 'prettier' : undefined,
|
|
376
|
+
].filter(Boolean),
|
|
328
377
|
rules: {
|
|
329
378
|
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
|
330
379
|
'@typescript-eslint/interface-name-prefix': 'off',
|
|
@@ -359,32 +408,32 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
359
408
|
outdent`
|
|
360
409
|
{
|
|
361
410
|
"compilerOptions": {
|
|
362
|
-
|
|
411
|
+
// Completeness
|
|
412
|
+
"skipLibCheck": true,
|
|
413
|
+
|
|
414
|
+
// Interop constraints
|
|
415
|
+
"allowSyntheticDefaultImports": true,
|
|
416
|
+
"esModuleInterop": true,
|
|
417
|
+
|
|
418
|
+
// Language and environment
|
|
363
419
|
"target": "ES2020",
|
|
364
|
-
"declaration": true,
|
|
365
|
-
"declarationMap": true,
|
|
366
|
-
"sourceMap": true,
|
|
367
420
|
|
|
368
|
-
//
|
|
369
|
-
"
|
|
421
|
+
// Modules
|
|
422
|
+
"module": "ES2020",
|
|
423
|
+
"moduleResolution": "Node",
|
|
424
|
+
|
|
425
|
+
// Type checking
|
|
426
|
+
"alwaysStrict": true,
|
|
427
|
+
"noFallthroughCasesInSwitch": true,
|
|
370
428
|
"noImplicitAny": true,
|
|
371
|
-
"
|
|
372
|
-
"strictFunctionTypes": true,
|
|
373
|
-
"strictPropertyInitialization": true,
|
|
429
|
+
"noImplicitReturns": true,
|
|
374
430
|
"noImplicitThis": true,
|
|
375
|
-
"alwaysStrict": true,
|
|
376
|
-
|
|
377
|
-
// Additional checks
|
|
378
431
|
"noUnusedLocals": true,
|
|
379
432
|
"noUnusedParameters": true,
|
|
380
|
-
"
|
|
381
|
-
"
|
|
382
|
-
"
|
|
383
|
-
|
|
384
|
-
// Module resolution
|
|
385
|
-
"moduleResolution": "node",
|
|
386
|
-
"allowSyntheticDefaultImports": true,
|
|
387
|
-
"esModuleInterop": true
|
|
433
|
+
"strict": true,
|
|
434
|
+
"strictFunctionTypes": true,
|
|
435
|
+
"strictNullChecks": true,
|
|
436
|
+
"strictPropertyInitialization": true
|
|
388
437
|
}
|
|
389
438
|
}
|
|
390
439
|
`,
|
|
@@ -400,10 +449,10 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
400
449
|
{
|
|
401
450
|
"extends": "./tsconfig.settings",
|
|
402
451
|
"include": ["./src"],
|
|
452
|
+
"exclude": ["./src/**/*.test.ts"],
|
|
403
453
|
"compilerOptions": {
|
|
404
454
|
"rootDir": ".",
|
|
405
455
|
"outDir": "./dist",
|
|
406
|
-
"emitDeclarationOnly": true,
|
|
407
456
|
"resolveJsonModule": true
|
|
408
457
|
}
|
|
409
458
|
}
|
|
@@ -419,7 +468,8 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
419
468
|
outdent`
|
|
420
469
|
{
|
|
421
470
|
"extends": "./tsconfig.settings",
|
|
422
|
-
"include": ["
|
|
471
|
+
"include": ["./**/*.cjs", "./**/*.ts", "./**/*.tsx"],
|
|
472
|
+
"exclude": ["./node_modules"],
|
|
423
473
|
"compilerOptions": {
|
|
424
474
|
"rootDir": ".",
|
|
425
475
|
"outDir": "./dist",
|
|
@@ -443,14 +493,8 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
443
493
|
outdent`
|
|
444
494
|
import {defineConfig} from '@sanity/pkg-utils'
|
|
445
495
|
|
|
496
|
+
// https://github.com/sanity-io/pkg-utils#configuration
|
|
446
497
|
export default defineConfig({
|
|
447
|
-
extract: {
|
|
448
|
-
rules: {
|
|
449
|
-
// do not require internal members to be prefixed with \`_\`
|
|
450
|
-
'ae-internal-missing-underscore': 'off',
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
|
|
454
498
|
// the path to the tsconfig file for distributed builds
|
|
455
499
|
tsconfig: 'tsconfig.dist.json',
|
|
456
500
|
})
|
|
@@ -536,19 +580,22 @@ export const defaultTemplate: PkgTemplate = async ({cwd, logger, packagePath}) =
|
|
|
536
580
|
}
|
|
537
581
|
}
|
|
538
582
|
|
|
539
|
-
function format(filepath: string, input: string, prettierOptions: PrettierConfig) {
|
|
540
|
-
return prettier.format(input, {...prettierOptions, filepath})
|
|
583
|
+
function format(filepath: string, input: string, prettierOptions: PrettierConfig | undefined) {
|
|
584
|
+
return prettier.format(input, {...prettierOptions, plugins: [], filepath})
|
|
541
585
|
}
|
|
542
586
|
|
|
543
|
-
async function resolveLatestDeps(deps: Record<string, string>) {
|
|
587
|
+
async function resolveLatestDeps(deps: Record<string, string | undefined>) {
|
|
544
588
|
const depsEntries = Object.entries(deps)
|
|
545
589
|
const latestDeps: Record<string, string> = {}
|
|
546
590
|
|
|
547
591
|
for (const entry of depsEntries) {
|
|
548
592
|
const [name, version] = entry
|
|
549
|
-
const latestVersion = await getLatestVersion(name, version)
|
|
550
593
|
|
|
551
|
-
|
|
594
|
+
if (version) {
|
|
595
|
+
const latestVersion = await getLatestVersion(name, version)
|
|
596
|
+
|
|
597
|
+
latestDeps[name] = latestVersion ? `^${latestVersion}` : version
|
|
598
|
+
}
|
|
552
599
|
}
|
|
553
600
|
|
|
554
601
|
return latestDeps
|