@sanity/pkg-utils 11.0.17 → 12.0.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.
Files changed (71) hide show
  1. package/MIGRATE.md +152 -0
  2. package/README.md +114 -55
  3. package/dist/buildAction-D-M3KYyN.js +146 -0
  4. package/dist/buildAction-D-M3KYyN.js.map +1 -0
  5. package/dist/checkAction-B8M5CP3j.js +141 -0
  6. package/dist/checkAction-B8M5CP3j.js.map +1 -0
  7. package/dist/cli.js +22 -28
  8. package/dist/cli.js.map +1 -1
  9. package/dist/createApiExtractorConfig-CJoZqw8e.js +30 -0
  10. package/dist/createApiExtractorConfig-CJoZqw8e.js.map +1 -0
  11. package/dist/createTSDocConfig-ylfirNWP.js +25 -0
  12. package/dist/createTSDocConfig-ylfirNWP.js.map +1 -0
  13. package/dist/getExtractMessagesConfig-CXljwFbQ.js +75 -0
  14. package/dist/getExtractMessagesConfig-CXljwFbQ.js.map +1 -0
  15. package/dist/handleError-83GwKIFM.js +40 -0
  16. package/dist/handleError-83GwKIFM.js.map +1 -0
  17. package/dist/index.d.ts +141 -195
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +203 -11
  20. package/dist/index.js.map +1 -1
  21. package/dist/initAction-CmOO8eod.js +618 -0
  22. package/dist/initAction-CmOO8eod.js.map +1 -0
  23. package/dist/printExtractMessages-DyaYtByp.js +33 -0
  24. package/dist/printExtractMessages-DyaYtByp.js.map +1 -0
  25. package/dist/resolveBuildContext-CbwvYKj1.js +714 -0
  26. package/dist/resolveBuildContext-CbwvYKj1.js.map +1 -0
  27. package/dist/resolveTsdownConfig-CGE_7cMM.js +283 -0
  28. package/dist/resolveTsdownConfig-CGE_7cMM.js.map +1 -0
  29. package/dist/spinner-DAHe7SuT.js +15 -0
  30. package/dist/spinner-DAHe7SuT.js.map +1 -0
  31. package/dist/watchAction-BQG5_hhl.js +179 -0
  32. package/dist/watchAction-BQG5_hhl.js.map +1 -0
  33. package/dist/watchConfigFiles-AGBDblwf.js +43 -0
  34. package/dist/watchConfigFiles-AGBDblwf.js.map +1 -0
  35. package/package.json +12 -26
  36. package/dist/_chunks-es/buildAction.js +0 -195
  37. package/dist/_chunks-es/buildAction.js.map +0 -1
  38. package/dist/_chunks-es/checkAction.js +0 -198
  39. package/dist/_chunks-es/checkAction.js.map +0 -1
  40. package/dist/_chunks-es/createApiExtractorConfig.js +0 -52
  41. package/dist/_chunks-es/createApiExtractorConfig.js.map +0 -1
  42. package/dist/_chunks-es/createTSDocConfig.js +0 -31
  43. package/dist/_chunks-es/createTSDocConfig.js.map +0 -1
  44. package/dist/_chunks-es/defaults.js +0 -36
  45. package/dist/_chunks-es/defaults.js.map +0 -1
  46. package/dist/_chunks-es/define.js +0 -7
  47. package/dist/_chunks-es/define.js.map +0 -1
  48. package/dist/_chunks-es/extractModuleBlocks.js +0 -48
  49. package/dist/_chunks-es/extractModuleBlocks.js.map +0 -1
  50. package/dist/_chunks-es/fileExists.js +0 -12
  51. package/dist/_chunks-es/fileExists.js.map +0 -1
  52. package/dist/_chunks-es/getExtractMessagesConfig.js +0 -83
  53. package/dist/_chunks-es/getExtractMessagesConfig.js.map +0 -1
  54. package/dist/_chunks-es/handleError.js +0 -32
  55. package/dist/_chunks-es/handleError.js.map +0 -1
  56. package/dist/_chunks-es/index.js +0 -825
  57. package/dist/_chunks-es/index.js.map +0 -1
  58. package/dist/_chunks-es/initAction.js +0 -654
  59. package/dist/_chunks-es/initAction.js.map +0 -1
  60. package/dist/_chunks-es/printExtractMessages.js +0 -44
  61. package/dist/_chunks-es/printExtractMessages.js.map +0 -1
  62. package/dist/_chunks-es/resolveBuildContext.js +0 -717
  63. package/dist/_chunks-es/resolveBuildContext.js.map +0 -1
  64. package/dist/_chunks-es/resolveRolldownConfig.js +0 -117
  65. package/dist/_chunks-es/resolveRolldownConfig.js.map +0 -1
  66. package/dist/_chunks-es/spinner.js +0 -16
  67. package/dist/_chunks-es/spinner.js.map +0 -1
  68. package/dist/_chunks-es/watchAction.js +0 -160
  69. package/dist/_chunks-es/watchAction.js.map +0 -1
  70. package/dist/_chunks-es/watchConfigFiles.js +0 -49
  71. package/dist/_chunks-es/watchConfigFiles.js.map +0 -1
@@ -0,0 +1,618 @@
1
+ import { i as fileExists, n as createLogger, r as isRecord, t as handleError } from "./handleError-83GwKIFM.js";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, relative, resolve } from "node:path";
4
+ import { lstat, readdir, writeFile } from "node:fs/promises";
5
+ import { mkdirp } from "mkdirp";
6
+ import prompts from "prompts";
7
+ import { execSync } from "node:child_process";
8
+ import { getLatestVersion } from "get-latest-version";
9
+ import { outdent } from "outdent";
10
+ import { format } from "prettier";
11
+ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports), __exportAll = (all, no_symbols) => {
12
+ let target = {};
13
+ for (var name in all) __defProp(target, name, {
14
+ get: all[name],
15
+ enumerable: !0
16
+ });
17
+ return no_symbols || __defProp(target, Symbol.toStringTag, { value: "Module" }), target;
18
+ }, __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from == "object" || typeof from == "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) key = keys[i], !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
20
+ get: ((k) => from[k]).bind(null, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ return to;
24
+ }, __toESM = (mod, isNodeMode, target) => (target = mod == null ? {} : __create(__getProtoOf(mod)), __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: !0
27
+ }) : target, mod)), __require = /* @__PURE__ */ createRequire(import.meta.url);
28
+ const promptsTypes = { string: "text" };
29
+ /** @internal */
30
+ async function createFromTemplate(options) {
31
+ let { cwd, logger, packagePath, template: templateOrResolver } = options, template = typeof templateOrResolver == "function" ? await templateOrResolver({
32
+ cwd,
33
+ logger,
34
+ packagePath
35
+ }) : templateOrResolver;
36
+ logger.log("create new package at", relative(cwd, packagePath));
37
+ let templateOptions = {};
38
+ for (let templateOption of template.options) {
39
+ let templateValidate = templateOption.validate, res = await prompts({
40
+ type: promptsTypes[templateOption.type],
41
+ name: templateOption.name,
42
+ message: templateOption.description,
43
+ validate: templateValidate ? (prev) => templateValidate(prev) : void 0,
44
+ initial: typeof templateOption.initial == "function" ? templateOption.initial(templateOptions) : templateOption.initial
45
+ }, { onCancel: () => process.exit(0) });
46
+ templateOptions[templateOption.name] = templateOption.parse ? templateOption.parse(res[templateOption.name]) : res[templateOption.name];
47
+ }
48
+ let features = {};
49
+ for (let templateFeature of template.features) {
50
+ let res = templateFeature.optional ? await prompts({
51
+ type: "confirm",
52
+ name: "confirm",
53
+ message: `use ${templateFeature.name}?`,
54
+ initial: templateFeature.initial
55
+ }, { onCancel: () => process.exit(0) }) : void 0;
56
+ features[templateFeature.name] = res?.confirm || !templateFeature.optional;
57
+ }
58
+ let files = await template.getFiles(templateOptions, features);
59
+ files.sort((a, b) => a.name.localeCompare(b.name));
60
+ for (let file of files) {
61
+ let filePath = resolve(packagePath, file.name);
62
+ await mkdirp(dirname(filePath)), await writeFile(filePath, file.contents.trim() + "\n"), logger.success(`wrote ${relative(cwd, filePath)}`);
63
+ }
64
+ }
65
+ /** @public */
66
+ function defineTemplateOption(option) {
67
+ return option;
68
+ }
69
+ async function isEmptyDirectory(dirPath) {
70
+ return (await readdir(dirPath)).length === 0;
71
+ }
72
+ const overridableDefaults = {
73
+ endOfLine: "lf",
74
+ tabWidth: 2,
75
+ useTabs: !1
76
+ }, json5 = {
77
+ files: ["*.json5"],
78
+ options: {
79
+ quoteProps: "preserve",
80
+ singleQuote: !1
81
+ }
82
+ }, yaml = {
83
+ files: ["*.yml"],
84
+ options: { singleQuote: !1 }
85
+ }, config = {
86
+ ...overridableDefaults,
87
+ printWidth: 100,
88
+ semi: !1,
89
+ singleQuote: !0,
90
+ quoteProps: "consistent",
91
+ bracketSpacing: !1,
92
+ plugins: ["prettier-plugin-packagejson"],
93
+ overrides: [json5, yaml]
94
+ };
95
+ var require_parse_url = /* @__PURE__ */ __commonJSMin(((exports, module) => {
96
+ var urlModule = __require("url"), URLCtor = typeof URL > "u" ? urlModule.URL || null : URL, legacyURLParse = URLCtor ? null : urlModule.parse;
97
+ function parseWHATWG(str) {
98
+ try {
99
+ var u = new URLCtor(str), auth = null;
100
+ u.username && (auth = u.password ? u.username + ":" + u.password : u.username);
101
+ var host = u.host || null, hostname = u.hostname || null, pathname = u.pathname || null, path = u.pathname + (u.search || "") || null;
102
+ if (!host && pathname && str.indexOf("//") === -1) {
103
+ var slashIdx = pathname.indexOf("/");
104
+ slashIdx === -1 ? (host = pathname, hostname = pathname, pathname = null, path = null) : (host = pathname.slice(0, slashIdx), hostname = host, pathname = pathname.slice(slashIdx), path = pathname + (u.search || ""));
105
+ }
106
+ return {
107
+ auth,
108
+ hash: u.hash || null,
109
+ host,
110
+ hostname,
111
+ href: u.href,
112
+ path,
113
+ pathname,
114
+ port: u.port || null,
115
+ protocol: u.protocol || null,
116
+ query: u.search ? u.search.slice(1) : null,
117
+ search: u.search || null,
118
+ slashes: str.indexOf("//") !== -1 || null
119
+ };
120
+ } catch {
121
+ var hashIdx = str.indexOf("#"), hash = hashIdx === -1 ? null : str.slice(hashIdx), pathPart = hashIdx === -1 ? str : str.slice(0, hashIdx), queryIdx = pathPart.indexOf("?"), search = queryIdx === -1 ? null : pathPart.slice(queryIdx), pathnamePart = queryIdx === -1 ? pathPart : pathPart.slice(0, queryIdx);
122
+ return {
123
+ auth: null,
124
+ hash,
125
+ host: null,
126
+ hostname: null,
127
+ href: str,
128
+ path: pathPart || null,
129
+ pathname: pathnamePart || null,
130
+ port: null,
131
+ protocol: null,
132
+ query: search ? search.slice(1) : null,
133
+ search,
134
+ slashes: null
135
+ };
136
+ }
137
+ }
138
+ module.exports = URLCtor ? parseWHATWG : legacyURLParse;
139
+ })), import_parse_github_url = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
140
+ /*!
141
+ * parse-github-url <https://github.com/jonschlinkert/parse-github-url>
142
+ *
143
+ * Copyright (c) 2015-2017, Jon Schlinkert.
144
+ * Released under the MIT License.
145
+ */
146
+ var parseURL = require_parse_url(), cache = { __proto__: null };
147
+ function isChecksum(str) {
148
+ return /^[a-f0-9]{40}$/i.test(str);
149
+ }
150
+ function getBranch(str, obj) {
151
+ var segs = str.split("#"), branch;
152
+ return segs.length > 1 && (branch = segs[segs.length - 1]), !branch && obj.hash && obj.hash.charAt(0) === "#" && (branch = obj.hash.slice(1)), branch || "master";
153
+ }
154
+ function trimSlash(path) {
155
+ return path.charAt(0) === "/" ? path.slice(1) : path;
156
+ }
157
+ function name(str) {
158
+ return str ? str.replace(/\.git$/, "") : null;
159
+ }
160
+ function owner(str) {
161
+ if (!str) return null;
162
+ var idx = str.indexOf(":");
163
+ return idx > -1 ? str.slice(idx + 1) : str;
164
+ }
165
+ /**
166
+ * Extract the host from a git@ URL using the WHATWG URL API.
167
+ */
168
+ function getGitAtHost(str) {
169
+ return parseURL("http://" + str.replace(/git@([^:]+):/, "$1/")).host || null;
170
+ }
171
+ function parse(str) {
172
+ if (typeof str != "string" || !str.length || str.indexOf("git@gist") !== -1 || str.indexOf("//gist") !== -1) return null;
173
+ var obj = parseURL(str);
174
+ if (typeof obj.path != "string" || !obj.path.length || typeof obj.pathname != "string" || !obj.pathname.length) return null;
175
+ !obj.host && /^git@/.test(str) === !0 && (obj.host = getGitAtHost(str)), obj.path = trimSlash(obj.path), obj.pathname = trimSlash(obj.pathname), obj.filepath = null, obj.path.indexOf("repos") === 0 && (obj.path = obj.path.slice(6));
176
+ var seg = obj.path.split("/").filter(Boolean), hasBlob = seg[2] === "blob";
177
+ hasBlob && !isChecksum(seg[3]) && (obj.branch = seg[3], seg.length > 4 && (obj.filepath = seg.slice(4).join("/")));
178
+ var blob = str.indexOf("blob");
179
+ hasBlob && blob !== -1 && (obj.blob = str.slice(blob + 5));
180
+ var hasTree = seg[2] === "tree", tree = str.indexOf("tree");
181
+ if (hasTree && tree !== -1) {
182
+ var idx = tree + 5, branch = str.slice(idx), slash = branch.indexOf("/");
183
+ slash !== -1 && (branch = branch.slice(0, slash)), obj.branch = branch;
184
+ }
185
+ if (obj.owner = owner(seg[0]), obj.name = name(seg[1]), seg.length > 1 && obj.owner && obj.name) obj.repo = obj.owner + "/" + obj.name;
186
+ else {
187
+ var href = obj.href.split(":");
188
+ if (href.length === 2 && obj.href.indexOf("//") === -1) {
189
+ obj.repo = obj.repo || href[href.length - 1];
190
+ var repoSegments = obj.repo.split("/");
191
+ obj.owner = repoSegments[0], obj.name = repoSegments[1];
192
+ } else {
193
+ var match = obj.href.match(/\/([^/]*)$/);
194
+ obj.owner = match ? match[1] : null, obj.repo = null;
195
+ }
196
+ if (obj.repo && (!obj.owner || !obj.name)) {
197
+ var segs = obj.repo.split("/");
198
+ segs.length === 2 && (obj.owner = segs[0], obj.name = segs[1]);
199
+ }
200
+ }
201
+ return obj.branch || (obj.branch = seg[2] || getBranch(obj.path, obj), seg.length > 3 && (obj.filepath = seg.slice(3).join("/"))), obj.host = obj.host || "github.com", obj.owner = obj.owner || null, obj.name = obj.name || null, obj.repository = obj.repo, obj;
202
+ }
203
+ module.exports = function parseGithubUrl(str) {
204
+ return cache[str] || (cache[str] = parse(str)), cache[str];
205
+ };
206
+ })))(), 1);
207
+ const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/i, defaultTemplate = async ({ cwd, logger, packagePath }) => {
208
+ let gitConfig = getGitUserConfig(cwd);
209
+ return {
210
+ options: [
211
+ defineTemplateOption({
212
+ name: "repo",
213
+ type: "string",
214
+ description: "git url",
215
+ validate: (v) => {
216
+ if (!v) return !0;
217
+ let result = (0, import_parse_github_url.default)(v);
218
+ return !result?.host || !result.owner || !result.name ? "invalid git url" : !0;
219
+ },
220
+ parse: (v) => {
221
+ if (!v) return null;
222
+ let result = (0, import_parse_github_url.default)(v);
223
+ if (!result?.host || !result.owner || !result.name) throw Error("invalid git url");
224
+ return {
225
+ source: result.host,
226
+ owner: result.owner,
227
+ name: result.name
228
+ };
229
+ }
230
+ }),
231
+ defineTemplateOption({
232
+ name: "pkgName",
233
+ type: "string",
234
+ description: "package name",
235
+ initial: (options) => options.repo?.name || void 0,
236
+ validate: (v) => v ? RE_NAME.exec(v) ? !0 : "invalid package name" : "package name is required",
237
+ parse: (v) => {
238
+ if (!v) throw Error("package name is required");
239
+ if (!RE_NAME.exec(v)) throw Error("invalid package name");
240
+ let [scope, name] = v.split("/");
241
+ return {
242
+ scope,
243
+ name,
244
+ fullName: v
245
+ };
246
+ }
247
+ }),
248
+ defineTemplateOption({
249
+ name: "description",
250
+ type: "string",
251
+ description: "package description"
252
+ }),
253
+ defineTemplateOption({
254
+ name: "authorName",
255
+ type: "string",
256
+ description: "package author name",
257
+ initial: gitConfig.user
258
+ }),
259
+ defineTemplateOption({
260
+ name: "authorEmail",
261
+ type: "string",
262
+ description: "package author email",
263
+ initial: gitConfig.email
264
+ }),
265
+ defineTemplateOption({
266
+ name: "license",
267
+ type: "string",
268
+ description: "package license",
269
+ initial: "MIT",
270
+ validate: (v) => v ? !0 : "license is required"
271
+ })
272
+ ],
273
+ features: [
274
+ {
275
+ name: "eslint",
276
+ optional: !0,
277
+ initial: !0
278
+ },
279
+ {
280
+ name: "prettier",
281
+ optional: !0,
282
+ initial: !0
283
+ },
284
+ {
285
+ name: "typescript",
286
+ optional: !0,
287
+ initial: !0
288
+ }
289
+ ],
290
+ async getFiles(options, features) {
291
+ let { pkgName, repo } = options, { fullName: name } = pkgName, author = [options.authorName, options.authorEmail && `<${options.authorEmail}>`].filter(Boolean).join(" ") ?? void 0, pkgJson = {
292
+ name,
293
+ version: "0.0.0",
294
+ description: options.description ?? void 0,
295
+ keywords: [],
296
+ homepage: void 0,
297
+ bugs: void 0,
298
+ repository: void 0,
299
+ license: options.license,
300
+ author,
301
+ sideEffects: !1,
302
+ type: "module",
303
+ exports: {
304
+ ".": {
305
+ source: features.typescript ? "./src/index.ts" : "./src/index.js",
306
+ require: "./dist/index.cjs",
307
+ default: "./dist/index.js"
308
+ },
309
+ "./package.json": "./package.json"
310
+ },
311
+ main: "./dist/index.cjs",
312
+ module: "./dist/index.js",
313
+ types: void 0,
314
+ files: ["dist", "src"],
315
+ scripts: {
316
+ build: "pkg build --strict --clean --check",
317
+ format: features.prettier ? "prettier --write --cache --ignore-unknown ." : void 0
318
+ },
319
+ "lint-staged": features.prettier ? { "*": ["prettier --write --cache --ignore-unknown"] } : void 0,
320
+ browserslist: "extends @sanity/browserslist-config",
321
+ prettier: features.prettier ? "@sanity/prettier-config" : void 0,
322
+ dependencies: {},
323
+ devDependencies: {
324
+ "@sanity/tsconfig": features.typescript ? "^1" : void 0,
325
+ "@sanity/pkg-utils": "^9",
326
+ "@sanity/prettier-config": features.prettier ? "^1" : void 0,
327
+ "@typescript-eslint/eslint-plugin": void 0,
328
+ "@typescript-eslint/parser": void 0,
329
+ eslint: void 0,
330
+ "eslint-config-prettier": void 0,
331
+ "eslint-plugin-import": void 0,
332
+ "eslint-plugin-prettier": void 0,
333
+ "eslint-plugin-simple-import-sort": void 0,
334
+ "lint-staged": "^15",
335
+ prettier: features.prettier ? "^3" : void 0,
336
+ typescript: void 0
337
+ },
338
+ engines: { node: ">=20.19 <22 || >=22.12" }
339
+ }, files = [];
340
+ if (files.push({
341
+ name: ".editorconfig",
342
+ contents: outdent`
343
+ root = true
344
+
345
+ [*]
346
+ charset = utf-8
347
+ indent_style = space
348
+ indent_size = 2
349
+ end_of_line = lf
350
+ insert_final_newline = true
351
+ trim_trailing_whitespace = true
352
+ `
353
+ }), files.push({
354
+ name: ".gitignore",
355
+ contents: outdent`
356
+ *.local
357
+ *.log
358
+ *.tgz
359
+
360
+ .DS_Store
361
+ dist
362
+ etc
363
+ node_modules
364
+ `
365
+ }), features.prettier && files.push({
366
+ name: ".prettierignore",
367
+ contents: outdent`
368
+ dist
369
+ pnpm-lock.yaml
370
+ `
371
+ }), repo && (pkgJson.repository = {
372
+ type: "git",
373
+ url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`
374
+ }, pkgJson.bugs = { url: `https://${repo.source}/${repo.owner}/${repo.name}/issues` }, pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`), features.typescript) {
375
+ pkgJson.types = "./dist/index.d.ts", pkgJson.scripts = {
376
+ ...pkgJson.scripts,
377
+ "ts:check": "tsc --noEmit"
378
+ };
379
+ let devDependencies = pkgJson.devDependencies;
380
+ isRecord(devDependencies) && (devDependencies.typescript = "^5.9");
381
+ }
382
+ if (features.eslint) {
383
+ let eslintConfig = {
384
+ root: !0,
385
+ env: {
386
+ browser: !0,
387
+ es6: !0,
388
+ node: !0
389
+ },
390
+ extends: ["eslint:recommended", features.prettier ? "plugin:prettier/recommended" : void 0].filter(Boolean),
391
+ parserOptions: {
392
+ ecmaVersion: 2020,
393
+ sourceType: "module"
394
+ },
395
+ plugins: [
396
+ "import",
397
+ "simple-import-sort",
398
+ features.prettier ? "prettier" : void 0
399
+ ].filter(Boolean),
400
+ rules: {
401
+ "no-console": "error",
402
+ "no-shadow": "error",
403
+ "no-warning-comments": ["warn", {
404
+ location: "start",
405
+ terms: ["todo", "fixme"]
406
+ }],
407
+ "quote-props": ["warn", "consistent-as-needed"],
408
+ "simple-import-sort/exports": "warn",
409
+ "simple-import-sort/imports": "warn",
410
+ strict: ["warn", "global"]
411
+ }
412
+ };
413
+ files.push({
414
+ name: ".eslintignore",
415
+ contents: outdent`
416
+ dist
417
+ `
418
+ }), pkgJson.scripts = {
419
+ ...pkgJson.scripts,
420
+ lint: features.typescript ? "eslint . --ext .cjs,.js,.ts,.tsx" : "eslint . --ext .cjs,.js"
421
+ }, pkgJson.devDependencies = {
422
+ ...pkgJson.devDependencies,
423
+ eslint: "^8",
424
+ "eslint-config-prettier": features.prettier ? "^9" : void 0,
425
+ "eslint-plugin-import": "^2",
426
+ "eslint-plugin-prettier": features.prettier ? "^5" : void 0,
427
+ "eslint-plugin-simple-import-sort": "^12"
428
+ }, features.typescript && (pkgJson.devDependencies = {
429
+ ...pkgJson.devDependencies,
430
+ "@typescript-eslint/eslint-plugin": "^7",
431
+ "@typescript-eslint/parser": "^7"
432
+ }, eslintConfig.overrides = [{
433
+ files: ["**/*.ts", "**/*.tsx"],
434
+ parser: "@typescript-eslint/parser",
435
+ parserOptions: { project: ["./tsconfig.json"] },
436
+ extends: [
437
+ "eslint:recommended",
438
+ features.prettier ? "plugin:prettier/recommended" : void 0,
439
+ "plugin:@typescript-eslint/eslint-recommended",
440
+ "plugin:@typescript-eslint/recommended"
441
+ ].filter(Boolean),
442
+ plugins: [
443
+ "import",
444
+ "@typescript-eslint",
445
+ "simple-import-sort",
446
+ features.prettier ? "prettier" : void 0
447
+ ].filter(Boolean),
448
+ rules: {
449
+ "@typescript-eslint/explicit-module-boundary-types": "error",
450
+ "@typescript-eslint/interface-name-prefix": "off",
451
+ "@typescript-eslint/member-delimiter-style": "off",
452
+ "@typescript-eslint/no-empty-interface": "off"
453
+ }
454
+ }]), files.push({
455
+ name: ".eslintrc.cjs",
456
+ contents: await prettierFormat(resolve(packagePath, ".eslintrc.cjs"), outdent`
457
+ 'use strict'
458
+
459
+ /** @type import('eslint').Linter.Config */
460
+ module.exports = ${JSON.stringify(eslintConfig, null, 2)}
461
+ `, config)
462
+ });
463
+ }
464
+ features.typescript && (files.push({
465
+ name: "tsconfig.settings.json",
466
+ contents: await prettierFormat(resolve(packagePath, "tsconfig.settings.json"), outdent`
467
+ {
468
+ "extends": "@sanity/tsconfig/strictest",
469
+ "compilerOptions": {
470
+ "rootDir": ".",
471
+ "outDir": "./dist"
472
+ }
473
+ }
474
+ `, config)
475
+ }), files.push({
476
+ name: "tsconfig.dist.json",
477
+ contents: await prettierFormat(resolve(packagePath, "tsconfig.dist.json"), outdent`
478
+ {
479
+ "extends": "./tsconfig.settings",
480
+ "include": ["./src"],
481
+ "exclude": ["./src/**/*.test.ts"]
482
+ }
483
+ `, config)
484
+ }), files.push({
485
+ name: "tsconfig.json",
486
+ contents: await prettierFormat(resolve(packagePath, "tsconfig.json"), outdent`
487
+ {
488
+ "extends": "./tsconfig.settings",
489
+ "include": ["./**/*.cjs", "./**/*.ts", "./**/*.tsx"],
490
+ "exclude": ["./node_modules"]
491
+ }
492
+ `, config)
493
+ })), features.typescript ? (files.push({
494
+ name: "package.config.ts",
495
+ contents: await prettierFormat(resolve(packagePath, "package.config.ts"), outdent`
496
+ import {defineConfig} from '@sanity/pkg-utils'
497
+
498
+ // https://github.com/sanity-io/pkg-utils#configuration
499
+ export default defineConfig({
500
+ // the path to the tsconfig file for distributed builds
501
+ tsconfig: 'tsconfig.dist.json',
502
+ })
503
+ `, config)
504
+ }), files.push({
505
+ name: "src/index.ts",
506
+ contents: await prettierFormat(resolve(packagePath, "src/index.ts"), outdent`
507
+ /** @public */
508
+ export function main(): void {
509
+ //
510
+ }
511
+ `, config)
512
+ })) : (files.push({
513
+ name: "package.config.js",
514
+ contents: await prettierFormat(resolve(packagePath, "package.config.js"), outdent`
515
+ import {defineConfig} from '@sanity/pkg-utils'
516
+
517
+ export default defineConfig({
518
+ extract: {
519
+ rules: {
520
+ // do not require internal members to be prefixed with \`_\`
521
+ 'ae-internal-missing-underscore': 'off',
522
+ },
523
+ },
524
+ })
525
+ `, config)
526
+ }), files.push({
527
+ name: "src/index.js",
528
+ contents: await prettierFormat(resolve(packagePath, "src/index.js"), outdent`
529
+ /** @public */
530
+ export function main() {
531
+ //
532
+ }
533
+ `, config)
534
+ }));
535
+ try {
536
+ pkgJson.dependencies = await resolveLatestDeps(pkgJson.dependencies ?? {});
537
+ } catch (error) {
538
+ logger.warn(error instanceof Error ? error.message : error);
539
+ }
540
+ try {
541
+ pkgJson.devDependencies = await resolveLatestDeps(pkgJson.devDependencies ?? {});
542
+ } catch (error) {
543
+ logger.warn(error instanceof Error ? error.message : error);
544
+ }
545
+ return files.push({
546
+ name: "package.json",
547
+ contents: await prettierFormat(resolve(packagePath, "package.json"), JSON.stringify(pkgJson, null, 2), config)
548
+ }), files;
549
+ }
550
+ };
551
+ };
552
+ function prettierFormat(filepath, input, prettierOptions) {
553
+ return format(input, {
554
+ ...prettierOptions,
555
+ plugins: [],
556
+ filepath
557
+ });
558
+ }
559
+ async function resolveLatestDeps(deps) {
560
+ let depsEntries = Object.entries(deps), latestDeps = {};
561
+ for (let entry of depsEntries) {
562
+ let [name, version] = entry;
563
+ if (version) {
564
+ let latestVersion = await getLatestVersion(name, { range: version });
565
+ latestDeps[name] = latestVersion ? `^${latestVersion}` : version;
566
+ }
567
+ }
568
+ return latestDeps;
569
+ }
570
+ function getGitUserConfig(cwd) {
571
+ let user, email;
572
+ try {
573
+ user = execSync("git config user.name", {
574
+ encoding: "utf8",
575
+ cwd
576
+ }).trim() || void 0, email = execSync("git config user.email", {
577
+ encoding: "utf8",
578
+ cwd
579
+ }).trim() || void 0;
580
+ } catch {}
581
+ return {
582
+ user,
583
+ email
584
+ };
585
+ }
586
+ /** @public */
587
+ async function init(options) {
588
+ if (!options.cwd) throw Error("Missing required option: cwd");
589
+ if (!options.path) throw Error("Missing required option: path");
590
+ let logger = createLogger(), packagePath = resolve(options.cwd, options.path);
591
+ await ensurePackagePath(packagePath), await createFromTemplate({
592
+ cwd: options.cwd,
593
+ logger,
594
+ template: defaultTemplate,
595
+ packagePath
596
+ });
597
+ }
598
+ async function ensurePackagePath(packagePath) {
599
+ if (!fileExists(packagePath)) {
600
+ await mkdirp(packagePath);
601
+ return;
602
+ }
603
+ if (!(await lstat(packagePath)).isDirectory()) throw Error("the package path is a file, not a directory");
604
+ if (!await isEmptyDirectory(packagePath)) throw Error("the package directory is not empty");
605
+ }
606
+ async function initAction(options) {
607
+ try {
608
+ await init({
609
+ cwd: process.cwd(),
610
+ path: options.path
611
+ });
612
+ } catch (err) {
613
+ handleError(err);
614
+ }
615
+ }
616
+ export { initAction, __exportAll as t };
617
+
618
+ //# sourceMappingURL=initAction-CmOO8eod.js.map