@sanity/pkg-utils 4.2.6 → 4.2.7
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-Dvr5eKKV.cjs +158 -0
- package/dist/_chunks/{build-BxYgJfQq.cjs.map → build-Dvr5eKKV.cjs.map} +1 -1
- package/dist/_chunks/{buildAction-KZkR53RZ.cjs → buildAction-BqdY-x5D.cjs} +3 -7
- package/dist/_chunks/{buildAction-KZkR53RZ.cjs.map → buildAction-BqdY-x5D.cjs.map} +1 -1
- package/dist/_chunks/check-BSN1yLfm.cjs +118 -0
- package/dist/_chunks/check-BSN1yLfm.cjs.map +1 -0
- package/dist/_chunks/{checkAction-B86PejBD.cjs → checkAction-CplEAcgR.cjs} +3 -7
- package/dist/_chunks/{checkAction-B86PejBD.cjs.map → checkAction-CplEAcgR.cjs.map} +1 -1
- package/dist/_chunks/consoleSpy-1_g1SPGc.cjs +369 -0
- package/dist/_chunks/{consoleSpy-DnlN7UBk.cjs.map → consoleSpy-1_g1SPGc.cjs.map} +1 -1
- package/dist/_chunks/handleError-CGQ2DXMR.cjs +11 -0
- package/dist/_chunks/handleError-CGQ2DXMR.cjs.map +1 -0
- package/dist/_chunks/index-Dxhh31D_.cjs +19997 -0
- package/dist/_chunks/{index-RwgAZs-y.cjs.map → index-Dxhh31D_.cjs.map} +1 -1
- package/dist/_chunks/{init-CZQh-Q_y.cjs → init-2mlaoNTF.cjs} +174 -261
- package/dist/_chunks/{init-CZQh-Q_y.cjs.map → init-2mlaoNTF.cjs.map} +1 -1
- package/dist/_chunks/{initAction-BYVnsbAj.cjs → initAction-BlTz_X1p.cjs} +3 -7
- package/dist/_chunks/{initAction-BYVnsbAj.cjs.map → initAction-BlTz_X1p.cjs.map} +1 -1
- package/dist/_chunks/{logger-CpjNjxqG.cjs → logger-CwHVwB-b.cjs} +11 -20
- package/dist/_chunks/logger-CwHVwB-b.cjs.map +1 -0
- package/dist/_chunks/watch-Dqp3kWd_.cjs +156 -0
- package/dist/_chunks/{watch-JoaJL851.cjs.map → watch-Dqp3kWd_.cjs.map} +1 -1
- package/dist/_chunks/{watchAction-DcoHeR8f.cjs → watchAction-4vv-wSLV.cjs} +3 -7
- package/dist/_chunks/{watchAction-DcoHeR8f.cjs.map → watchAction-4vv-wSLV.cjs.map} +1 -1
- package/dist/cli.cjs +18 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +3 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19893 -35944
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/tasks/rollup/resolveRollupConfig.ts +1 -1
- package/dist/_chunks/build-BxYgJfQq.cjs +0 -216
- package/dist/_chunks/check-Do7O9Mjo.cjs +0 -223
- package/dist/_chunks/check-Do7O9Mjo.cjs.map +0 -1
- package/dist/_chunks/consoleSpy-DnlN7UBk.cjs +0 -632
- package/dist/_chunks/handleError-DB8KmYKe.cjs +0 -19
- package/dist/_chunks/handleError-DB8KmYKe.cjs.map +0 -1
- package/dist/_chunks/index-RwgAZs-y.cjs +0 -35564
- package/dist/_chunks/logger-CpjNjxqG.cjs.map +0 -1
- package/dist/_chunks/watch-JoaJL851.cjs +0 -227
|
@@ -1,49 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
require('find-config');
|
|
16
|
-
require('fs');
|
|
17
|
-
require('@sanity/browserslist-config');
|
|
18
|
-
require('chalk');
|
|
19
|
-
require('zod');
|
|
20
|
-
require('typescript');
|
|
21
|
-
|
|
22
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
23
|
-
|
|
24
|
-
var prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
|
|
25
|
-
var getLatestVersion__default = /*#__PURE__*/_interopDefaultCompat(getLatestVersion);
|
|
26
|
-
var gitUrlParse__default = /*#__PURE__*/_interopDefaultCompat(gitUrlParse);
|
|
27
|
-
var parseGitConfig__default = /*#__PURE__*/_interopDefaultCompat(parseGitConfig);
|
|
28
|
-
var prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
|
|
29
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var fs = require("fs/promises"), mkdirp = require("mkdirp"), path = require("path"), prompts = require("prompts"), logger = require("./logger-CwHVwB-b.cjs"), getLatestVersion = require("get-latest-version"), gitUrlParse = require("git-url-parse"), outdent = require("outdent"), parseGitConfig = require("parse-git-config"), prettier = require("prettier");
|
|
3
|
+
require("esbuild-register/dist/node");
|
|
4
|
+
require("pkg-up");
|
|
5
|
+
require("find-config");
|
|
6
|
+
require("fs");
|
|
7
|
+
require("@sanity/browserslist-config");
|
|
8
|
+
require("chalk");
|
|
9
|
+
require("zod");
|
|
10
|
+
require("typescript");
|
|
11
|
+
function _interopDefaultCompat(e) {
|
|
12
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
13
|
+
}
|
|
14
|
+
var prompts__default = /* @__PURE__ */ _interopDefaultCompat(prompts), getLatestVersion__default = /* @__PURE__ */ _interopDefaultCompat(getLatestVersion), gitUrlParse__default = /* @__PURE__ */ _interopDefaultCompat(gitUrlParse), parseGitConfig__default = /* @__PURE__ */ _interopDefaultCompat(parseGitConfig), prettier__default = /* @__PURE__ */ _interopDefaultCompat(prettier);
|
|
30
15
|
const promptsTypes = {
|
|
31
16
|
string: "text"
|
|
32
17
|
};
|
|
33
18
|
async function createFromTemplate(options) {
|
|
34
|
-
const { cwd, logger, packagePath, template: templateOrResolver } = options;
|
|
35
|
-
|
|
36
|
-
logger.log("create new package at", path.relative(cwd, packagePath));
|
|
19
|
+
const { cwd, logger: logger2, packagePath, template: templateOrResolver } = options, template = typeof templateOrResolver == "function" ? await templateOrResolver({ cwd, logger: logger2, packagePath }) : templateOrResolver;
|
|
20
|
+
logger2.log("create new package at", path.relative(cwd, packagePath));
|
|
37
21
|
const templateOptions = {};
|
|
38
22
|
for (const templateOption of template.options) {
|
|
39
|
-
const templateValidate = templateOption.validate
|
|
40
|
-
const res = await prompts__default.default(
|
|
23
|
+
const templateValidate = templateOption.validate, res = await prompts__default.default(
|
|
41
24
|
{
|
|
42
25
|
type: promptsTypes[templateOption.type],
|
|
43
26
|
name: templateOption.name,
|
|
44
27
|
message: templateOption.description,
|
|
45
28
|
validate: templateValidate ? (prev) => templateValidate(prev) : void 0,
|
|
46
|
-
initial: typeof templateOption.initial
|
|
29
|
+
initial: typeof templateOption.initial == "function" ? templateOption.initial(templateOptions) : templateOption.initial
|
|
47
30
|
},
|
|
48
31
|
{ onCancel: () => process.exit(0) }
|
|
49
32
|
);
|
|
@@ -63,41 +46,33 @@ async function createFromTemplate(options) {
|
|
|
63
46
|
features[templateFeature.name] = res?.confirm || !templateFeature.optional;
|
|
64
47
|
}
|
|
65
48
|
const files = await template.getFiles(templateOptions, features);
|
|
66
|
-
files.sort((a, b) =>
|
|
67
|
-
return a.name.localeCompare(b.name);
|
|
68
|
-
});
|
|
49
|
+
files.sort((a, b) => a.name.localeCompare(b.name));
|
|
69
50
|
for (const file of files) {
|
|
70
51
|
const filePath = path.resolve(packagePath, file.name);
|
|
71
|
-
await mkdirp.mkdirp(path.dirname(filePath))
|
|
72
|
-
|
|
73
|
-
logger.success(`wrote ${path.relative(cwd, filePath)}`);
|
|
52
|
+
await mkdirp.mkdirp(path.dirname(filePath)), await fs.writeFile(filePath, file.contents.trim() + `
|
|
53
|
+
`), logger2.success(`wrote ${path.relative(cwd, filePath)}`);
|
|
74
54
|
}
|
|
75
55
|
}
|
|
76
|
-
|
|
77
56
|
function defineTemplateOption(option) {
|
|
78
57
|
return option;
|
|
79
58
|
}
|
|
80
|
-
|
|
81
59
|
async function isEmptyDirectory(dirPath) {
|
|
82
60
|
return (await fs.readdir(dirPath)).length === 0;
|
|
83
61
|
}
|
|
84
|
-
|
|
85
|
-
const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/i;
|
|
86
|
-
const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
62
|
+
const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/i, defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
87
63
|
const gitConfig = await parseGitConfig__default.default({ cwd, type: "global" });
|
|
88
64
|
return {
|
|
89
65
|
options: [
|
|
90
|
-
|
|
66
|
+
{
|
|
91
67
|
name: "repo",
|
|
92
68
|
type: "string",
|
|
93
69
|
description: "git url",
|
|
94
70
|
validate: (v) => {
|
|
95
71
|
if (!v)
|
|
96
|
-
return
|
|
72
|
+
return !0;
|
|
97
73
|
try {
|
|
98
|
-
gitUrlParse__default.default(v);
|
|
99
|
-
|
|
100
|
-
} catch (err) {
|
|
74
|
+
return gitUrlParse__default.default(v), !0;
|
|
75
|
+
} catch {
|
|
101
76
|
return "invalid git url";
|
|
102
77
|
}
|
|
103
78
|
},
|
|
@@ -107,113 +82,94 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
107
82
|
const result = gitUrlParse__default.default(v);
|
|
108
83
|
return { source: result.source, owner: result.owner, name: result.name };
|
|
109
84
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
85
|
+
},
|
|
86
|
+
{
|
|
112
87
|
name: "pkgName",
|
|
113
88
|
type: "string",
|
|
114
89
|
description: "package name",
|
|
115
90
|
initial: (options) => options.repo?.name || void 0,
|
|
116
|
-
validate: (v) =>
|
|
117
|
-
if (!v)
|
|
118
|
-
return "package name is required";
|
|
119
|
-
const match = RE_NAME.exec(v);
|
|
120
|
-
if (!match) {
|
|
121
|
-
return "invalid package name";
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
},
|
|
91
|
+
validate: (v) => v ? RE_NAME.exec(v) ? !0 : "invalid package name" : "package name is required",
|
|
125
92
|
parse: (v) => {
|
|
126
|
-
if (!v)
|
|
93
|
+
if (!v)
|
|
127
94
|
throw new Error("package name is required");
|
|
128
|
-
|
|
129
|
-
const match = RE_NAME.exec(v);
|
|
130
|
-
if (!match) {
|
|
95
|
+
if (!RE_NAME.exec(v))
|
|
131
96
|
throw new Error("invalid package name");
|
|
132
|
-
}
|
|
133
97
|
const [scope, name] = v.split("/");
|
|
134
98
|
return { scope, name, fullName: v };
|
|
135
99
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
100
|
+
},
|
|
101
|
+
{
|
|
138
102
|
name: "description",
|
|
139
103
|
type: "string",
|
|
140
104
|
description: "package description"
|
|
141
|
-
}
|
|
142
|
-
|
|
105
|
+
},
|
|
106
|
+
{
|
|
143
107
|
name: "authorName",
|
|
144
108
|
type: "string",
|
|
145
109
|
description: "package author name",
|
|
146
110
|
initial: gitConfig?.user?.name
|
|
147
|
-
}
|
|
148
|
-
|
|
111
|
+
},
|
|
112
|
+
{
|
|
149
113
|
name: "authorEmail",
|
|
150
114
|
type: "string",
|
|
151
115
|
description: "package author email",
|
|
152
116
|
initial: gitConfig?.user?.email
|
|
153
|
-
}
|
|
154
|
-
|
|
117
|
+
},
|
|
118
|
+
{
|
|
155
119
|
name: "license",
|
|
156
120
|
type: "string",
|
|
157
121
|
description: "package license",
|
|
158
122
|
initial: "MIT",
|
|
159
|
-
validate: (v) =>
|
|
160
|
-
|
|
161
|
-
return "license is required";
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
})
|
|
123
|
+
validate: (v) => v ? !0 : "license is required"
|
|
124
|
+
}
|
|
165
125
|
],
|
|
166
126
|
features: [
|
|
167
127
|
{
|
|
168
128
|
name: "eslint",
|
|
169
|
-
optional:
|
|
170
|
-
initial:
|
|
129
|
+
optional: !0,
|
|
130
|
+
initial: !0
|
|
171
131
|
},
|
|
172
132
|
{
|
|
173
133
|
name: "prettier",
|
|
174
|
-
optional:
|
|
175
|
-
initial:
|
|
134
|
+
optional: !0,
|
|
135
|
+
initial: !0
|
|
176
136
|
},
|
|
177
137
|
{
|
|
178
138
|
name: "typescript",
|
|
179
|
-
optional:
|
|
180
|
-
initial:
|
|
139
|
+
optional: !0,
|
|
140
|
+
initial: !0
|
|
181
141
|
}
|
|
182
142
|
],
|
|
183
143
|
async getFiles(options, features) {
|
|
184
|
-
const { pkgName, repo } = options
|
|
185
|
-
|
|
186
|
-
const author = [options.authorName, options.authorEmail && `<${options.authorEmail}>`].filter(Boolean).join(" ") ?? void 0;
|
|
187
|
-
const prettierConfig = features.prettier ? {
|
|
188
|
-
bracketSpacing: false,
|
|
144
|
+
const { pkgName, repo } = options, { fullName: name } = pkgName, author = [options.authorName, options.authorEmail && `<${options.authorEmail}>`].filter(Boolean).join(" ") ?? void 0, prettierConfig = features.prettier ? {
|
|
145
|
+
bracketSpacing: !1,
|
|
189
146
|
plugins: ["prettier-plugin-packagejson"],
|
|
190
147
|
printWidth: 100,
|
|
191
148
|
quoteProps: "consistent",
|
|
192
|
-
semi:
|
|
193
|
-
singleQuote:
|
|
149
|
+
semi: !1,
|
|
150
|
+
singleQuote: !0,
|
|
194
151
|
tabWidth: 2,
|
|
195
152
|
overrides: [
|
|
196
153
|
{
|
|
197
154
|
files: ["*.yml"],
|
|
198
155
|
options: {
|
|
199
|
-
singleQuote:
|
|
156
|
+
singleQuote: !1
|
|
200
157
|
}
|
|
201
158
|
}
|
|
202
159
|
]
|
|
203
|
-
} : void 0
|
|
204
|
-
const pkgJson = {
|
|
160
|
+
} : void 0, pkgJson = {
|
|
205
161
|
name,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
162
|
+
version: "0.0.0",
|
|
163
|
+
description: options.description ?? void 0,
|
|
164
|
+
keywords: [],
|
|
165
|
+
homepage: void 0,
|
|
166
|
+
bugs: void 0,
|
|
167
|
+
repository: void 0,
|
|
168
|
+
license: options.license,
|
|
213
169
|
author,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
170
|
+
sideEffects: !1,
|
|
171
|
+
type: "module",
|
|
172
|
+
exports: {
|
|
217
173
|
".": {
|
|
218
174
|
types: void 0,
|
|
219
175
|
source: features.typescript ? "./src/index.ts" : "./src/index.js",
|
|
@@ -223,15 +179,15 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
223
179
|
},
|
|
224
180
|
"./package.json": "./package.json"
|
|
225
181
|
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
182
|
+
main: "./dist/index.cjs",
|
|
183
|
+
module: "./dist/index.js",
|
|
184
|
+
source: features.typescript ? "./src/index.ts" : "./src/index.js",
|
|
185
|
+
types: void 0,
|
|
186
|
+
files: ["dist", "src"],
|
|
187
|
+
scripts: {
|
|
188
|
+
build: "run-s clean pkg:build pkg:check",
|
|
189
|
+
clean: "rimraf dist",
|
|
190
|
+
format: features.prettier ? "prettier --write --cache --ignore-unknown ." : void 0,
|
|
235
191
|
"pkg:build": "pkg build --strict",
|
|
236
192
|
"pkg:check": "pkg check --strict"
|
|
237
193
|
},
|
|
@@ -239,30 +195,29 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
239
195
|
"*": ["prettier --write --cache --ignore-unknown"]
|
|
240
196
|
} : void 0,
|
|
241
197
|
// prettier: prettierConfig,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
198
|
+
browserslist: "extends @sanity/browserslist-config",
|
|
199
|
+
dependencies: {},
|
|
200
|
+
devDependencies: {
|
|
245
201
|
"@sanity/pkg-utils": "*",
|
|
246
202
|
"@typescript-eslint/eslint-plugin": void 0,
|
|
247
203
|
"@typescript-eslint/parser": void 0,
|
|
248
|
-
|
|
204
|
+
eslint: void 0,
|
|
249
205
|
"eslint-config-prettier": void 0,
|
|
250
206
|
"eslint-plugin-import": void 0,
|
|
251
207
|
"eslint-plugin-prettier": void 0,
|
|
252
208
|
"eslint-plugin-simple-import-sort": void 0,
|
|
253
209
|
"lint-staged": "*",
|
|
254
210
|
"npm-run-all": "*",
|
|
255
|
-
|
|
211
|
+
prettier: features.prettier ? "*" : void 0,
|
|
256
212
|
"prettier-plugin-packagejson": features.prettier ? "*" : void 0,
|
|
257
|
-
|
|
258
|
-
|
|
213
|
+
rimraf: "*",
|
|
214
|
+
typescript: void 0
|
|
259
215
|
},
|
|
260
|
-
|
|
216
|
+
engines: {
|
|
261
217
|
node: ">=18.0.0"
|
|
262
218
|
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
files.push({
|
|
219
|
+
}, files = [];
|
|
220
|
+
if (files.push({
|
|
266
221
|
name: ".editorconfig",
|
|
267
222
|
contents: outdent.outdent`
|
|
268
223
|
root = true
|
|
@@ -275,8 +230,7 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
275
230
|
insert_final_newline = true
|
|
276
231
|
trim_trailing_whitespace = true
|
|
277
232
|
`
|
|
278
|
-
})
|
|
279
|
-
files.push({
|
|
233
|
+
}), files.push({
|
|
280
234
|
name: ".gitignore",
|
|
281
235
|
contents: outdent.outdent`
|
|
282
236
|
*.local
|
|
@@ -288,56 +242,42 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
288
242
|
etc
|
|
289
243
|
node_modules
|
|
290
244
|
`
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
name: ".prettierignore",
|
|
295
|
-
contents: outdent.outdent`
|
|
245
|
+
}), features.prettier && (files.push({
|
|
246
|
+
name: ".prettierignore",
|
|
247
|
+
contents: outdent.outdent`
|
|
296
248
|
dist
|
|
297
249
|
pnpm-lock.yaml
|
|
298
250
|
`
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
};
|
|
314
|
-
pkgJson.bugs = {
|
|
315
|
-
url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`
|
|
316
|
-
};
|
|
317
|
-
pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`;
|
|
318
|
-
}
|
|
319
|
-
if (features.typescript) {
|
|
251
|
+
}), files.push({
|
|
252
|
+
name: ".prettierrc",
|
|
253
|
+
contents: await format(
|
|
254
|
+
path.resolve(packagePath, ".prettierrc.json"),
|
|
255
|
+
JSON.stringify(prettierConfig, null, 2) + `
|
|
256
|
+
`,
|
|
257
|
+
prettierConfig
|
|
258
|
+
)
|
|
259
|
+
})), repo && (pkgJson.repository = {
|
|
260
|
+
type: "git",
|
|
261
|
+
url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`
|
|
262
|
+
}, pkgJson.bugs = {
|
|
263
|
+
url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`
|
|
264
|
+
}, pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`), features.typescript) {
|
|
320
265
|
pkgJson.types = "./dist/index.d.ts";
|
|
321
266
|
const mainExport = pkgJson.exports?.["."];
|
|
322
|
-
|
|
323
|
-
mainExport.types = "./dist/index.d.ts";
|
|
324
|
-
}
|
|
325
|
-
pkgJson.scripts = {
|
|
267
|
+
logger.isRecord(mainExport) && (mainExport.types = "./dist/index.d.ts"), pkgJson.scripts = {
|
|
326
268
|
...pkgJson.scripts,
|
|
327
|
-
|
|
269
|
+
"ts:check": "tsc --build"
|
|
328
270
|
};
|
|
329
271
|
const devDependencies = pkgJson.devDependencies;
|
|
330
|
-
|
|
331
|
-
devDependencies["typescript"] = "*";
|
|
332
|
-
}
|
|
272
|
+
logger.isRecord(devDependencies) && (devDependencies.typescript = "*");
|
|
333
273
|
}
|
|
334
274
|
if (features.eslint) {
|
|
335
275
|
const eslintConfig = {
|
|
336
|
-
root:
|
|
276
|
+
root: !0,
|
|
337
277
|
env: {
|
|
338
|
-
browser:
|
|
339
|
-
es6:
|
|
340
|
-
node:
|
|
278
|
+
browser: !0,
|
|
279
|
+
es6: !0,
|
|
280
|
+
node: !0
|
|
341
281
|
},
|
|
342
282
|
extends: [
|
|
343
283
|
"eslint:recommended",
|
|
@@ -359,28 +299,25 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
359
299
|
"quote-props": ["warn", "consistent-as-needed"],
|
|
360
300
|
"simple-import-sort/exports": "warn",
|
|
361
301
|
"simple-import-sort/imports": "warn",
|
|
362
|
-
|
|
302
|
+
strict: ["warn", "global"]
|
|
363
303
|
}
|
|
364
304
|
};
|
|
365
|
-
files.push({
|
|
305
|
+
if (files.push({
|
|
366
306
|
name: ".eslintignore",
|
|
367
307
|
contents: outdent.outdent`
|
|
368
308
|
dist
|
|
369
309
|
`
|
|
370
|
-
})
|
|
371
|
-
pkgJson.scripts = {
|
|
310
|
+
}), pkgJson.scripts = {
|
|
372
311
|
...pkgJson.scripts,
|
|
373
312
|
lint: features.typescript ? "eslint . --ext .cjs,.js,.ts,.tsx" : "eslint . --ext .cjs,.js"
|
|
374
|
-
}
|
|
375
|
-
pkgJson.devDependencies = {
|
|
313
|
+
}, pkgJson.devDependencies = {
|
|
376
314
|
...pkgJson.devDependencies,
|
|
377
|
-
|
|
315
|
+
eslint: "*",
|
|
378
316
|
"eslint-config-prettier": features.prettier ? "*" : void 0,
|
|
379
317
|
"eslint-plugin-simple-import-sort": "*",
|
|
380
318
|
"eslint-plugin-import": "*",
|
|
381
319
|
"eslint-plugin-prettier": features.prettier ? "*" : void 0
|
|
382
|
-
}
|
|
383
|
-
if (features.typescript) {
|
|
320
|
+
}, features.typescript) {
|
|
384
321
|
pkgJson.devDependencies = {
|
|
385
322
|
...pkgJson.devDependencies,
|
|
386
323
|
"@typescript-eslint/eslint-plugin": "*",
|
|
@@ -427,12 +364,11 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
427
364
|
)
|
|
428
365
|
});
|
|
429
366
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
outdent.outdent`
|
|
367
|
+
features.typescript && (files.push({
|
|
368
|
+
name: "tsconfig.settings.json",
|
|
369
|
+
contents: await format(
|
|
370
|
+
path.resolve(packagePath, "tsconfig.settings.json"),
|
|
371
|
+
outdent.outdent`
|
|
436
372
|
{
|
|
437
373
|
"compilerOptions": {
|
|
438
374
|
// Completeness
|
|
@@ -464,14 +400,13 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
464
400
|
}
|
|
465
401
|
}
|
|
466
402
|
`,
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
outdent.outdent`
|
|
403
|
+
prettierConfig
|
|
404
|
+
)
|
|
405
|
+
}), files.push({
|
|
406
|
+
name: "tsconfig.dist.json",
|
|
407
|
+
contents: await format(
|
|
408
|
+
path.resolve(packagePath, "tsconfig.dist.json"),
|
|
409
|
+
outdent.outdent`
|
|
475
410
|
{
|
|
476
411
|
"extends": "./tsconfig.settings",
|
|
477
412
|
"include": ["./src"],
|
|
@@ -483,14 +418,13 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
483
418
|
}
|
|
484
419
|
}
|
|
485
420
|
`,
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
outdent.outdent`
|
|
421
|
+
prettierConfig
|
|
422
|
+
)
|
|
423
|
+
}), files.push({
|
|
424
|
+
name: "tsconfig.json",
|
|
425
|
+
contents: await format(
|
|
426
|
+
path.resolve(packagePath, "tsconfig.json"),
|
|
427
|
+
outdent.outdent`
|
|
494
428
|
{
|
|
495
429
|
"extends": "./tsconfig.settings",
|
|
496
430
|
"include": ["./**/*.cjs", "./**/*.ts", "./**/*.tsx"],
|
|
@@ -504,16 +438,13 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
504
438
|
}
|
|
505
439
|
}
|
|
506
440
|
`,
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
contents: await format(
|
|
515
|
-
path.resolve(packagePath, "package.config.ts"),
|
|
516
|
-
outdent.outdent`
|
|
441
|
+
prettierConfig
|
|
442
|
+
)
|
|
443
|
+
})), features.typescript ? (files.push({
|
|
444
|
+
name: "package.config.ts",
|
|
445
|
+
contents: await format(
|
|
446
|
+
path.resolve(packagePath, "package.config.ts"),
|
|
447
|
+
outdent.outdent`
|
|
517
448
|
import {defineConfig} from '@sanity/pkg-utils'
|
|
518
449
|
|
|
519
450
|
// https://github.com/sanity-io/pkg-utils#configuration
|
|
@@ -522,28 +453,25 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
522
453
|
tsconfig: 'tsconfig.dist.json',
|
|
523
454
|
})
|
|
524
455
|
`,
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
outdent.outdent`
|
|
456
|
+
prettierConfig
|
|
457
|
+
)
|
|
458
|
+
}), files.push({
|
|
459
|
+
name: "src/index.ts",
|
|
460
|
+
contents: await format(
|
|
461
|
+
path.resolve(packagePath, "src/index.ts"),
|
|
462
|
+
outdent.outdent`
|
|
533
463
|
/** @public */
|
|
534
464
|
export function main(): void {
|
|
535
465
|
//
|
|
536
466
|
}
|
|
537
467
|
`,
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
path.resolve(packagePath, "package.config.js"),
|
|
546
|
-
outdent.outdent`
|
|
468
|
+
prettierConfig
|
|
469
|
+
)
|
|
470
|
+
})) : (files.push({
|
|
471
|
+
name: "package.config.js",
|
|
472
|
+
contents: await format(
|
|
473
|
+
path.resolve(packagePath, "package.config.js"),
|
|
474
|
+
outdent.outdent`
|
|
547
475
|
import {defineConfig} from '@sanity/pkg-utils'
|
|
548
476
|
|
|
549
477
|
export default defineConfig({
|
|
@@ -555,23 +483,21 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
555
483
|
},
|
|
556
484
|
})
|
|
557
485
|
`,
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
outdent.outdent`
|
|
486
|
+
prettierConfig
|
|
487
|
+
)
|
|
488
|
+
}), files.push({
|
|
489
|
+
name: "src/index.js",
|
|
490
|
+
contents: await format(
|
|
491
|
+
path.resolve(packagePath, "src/index.js"),
|
|
492
|
+
outdent.outdent`
|
|
566
493
|
/** @public */
|
|
567
494
|
export function main() {
|
|
568
495
|
//
|
|
569
496
|
}
|
|
570
497
|
`,
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
498
|
+
prettierConfig
|
|
499
|
+
)
|
|
500
|
+
}));
|
|
575
501
|
try {
|
|
576
502
|
pkgJson.dependencies = await resolveLatestDeps(pkgJson.dependencies ?? {});
|
|
577
503
|
} catch (error) {
|
|
@@ -582,15 +508,14 @@ const defaultTemplate = async ({ cwd, logger: logger$1, packagePath }) => {
|
|
|
582
508
|
} catch (error) {
|
|
583
509
|
logger$1.warn(error instanceof Error ? error.message : error);
|
|
584
510
|
}
|
|
585
|
-
files.push({
|
|
511
|
+
return files.push({
|
|
586
512
|
name: "package.json",
|
|
587
513
|
contents: await format(
|
|
588
514
|
path.resolve(packagePath, "package.json"),
|
|
589
515
|
JSON.stringify(pkgJson, null, 2),
|
|
590
516
|
prettierConfig
|
|
591
517
|
)
|
|
592
|
-
});
|
|
593
|
-
return files;
|
|
518
|
+
}), files;
|
|
594
519
|
}
|
|
595
520
|
};
|
|
596
521
|
};
|
|
@@ -598,8 +523,7 @@ function format(filepath, input, prettierOptions) {
|
|
|
598
523
|
return prettier__default.default.format(input, { ...prettierOptions, plugins: [], filepath });
|
|
599
524
|
}
|
|
600
525
|
async function resolveLatestDeps(deps) {
|
|
601
|
-
const depsEntries = Object.entries(deps);
|
|
602
|
-
const latestDeps = {};
|
|
526
|
+
const depsEntries = Object.entries(deps), latestDeps = {};
|
|
603
527
|
for (const entry of depsEntries) {
|
|
604
528
|
const [name, version] = entry;
|
|
605
529
|
if (version) {
|
|
@@ -609,18 +533,13 @@ async function resolveLatestDeps(deps) {
|
|
|
609
533
|
}
|
|
610
534
|
return latestDeps;
|
|
611
535
|
}
|
|
612
|
-
|
|
613
536
|
async function init(options) {
|
|
614
|
-
if (!options.cwd)
|
|
537
|
+
if (!options.cwd)
|
|
615
538
|
throw new Error("Missing required option: cwd");
|
|
616
|
-
|
|
617
|
-
if (!options.path) {
|
|
539
|
+
if (!options.path)
|
|
618
540
|
throw new Error("Missing required option: path");
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const packagePath = path.resolve(options.cwd, options.path);
|
|
622
|
-
await ensurePackagePath(packagePath);
|
|
623
|
-
await createFromTemplate({
|
|
541
|
+
const logger$1 = logger.createLogger(), packagePath = path.resolve(options.cwd, options.path);
|
|
542
|
+
await ensurePackagePath(packagePath), await createFromTemplate({
|
|
624
543
|
cwd: options.cwd,
|
|
625
544
|
logger: logger$1,
|
|
626
545
|
template: defaultTemplate,
|
|
@@ -628,22 +547,16 @@ async function init(options) {
|
|
|
628
547
|
});
|
|
629
548
|
}
|
|
630
549
|
async function ensurePackagePath(packagePath) {
|
|
631
|
-
|
|
632
|
-
if (!exists) {
|
|
550
|
+
if (!logger.fileExists(packagePath)) {
|
|
633
551
|
await mkdirp.mkdirp(packagePath);
|
|
634
552
|
return;
|
|
635
553
|
}
|
|
636
|
-
|
|
637
|
-
if (!dir) {
|
|
554
|
+
if (!(await fs.lstat(packagePath)).isDirectory())
|
|
638
555
|
throw new Error("the package path is a file, not a directory");
|
|
639
|
-
|
|
640
|
-
const empty = await isEmptyDirectory(packagePath);
|
|
641
|
-
if (!empty) {
|
|
556
|
+
if (!await isEmptyDirectory(packagePath))
|
|
642
557
|
throw new Error("the package directory is not empty");
|
|
643
|
-
}
|
|
644
558
|
}
|
|
645
|
-
|
|
646
559
|
exports.createFromTemplate = createFromTemplate;
|
|
647
560
|
exports.defineTemplateOption = defineTemplateOption;
|
|
648
561
|
exports.init = init;
|
|
649
|
-
//# sourceMappingURL=init-
|
|
562
|
+
//# sourceMappingURL=init-2mlaoNTF.cjs.map
|