@sanity/pkg-utils 11.0.16 → 12.0.0

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