@sanity/pkg-utils 2.2.17 → 2.3.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 (46) hide show
  1. package/README.md +16 -7
  2. package/dist/_chunks/{build-45e5ded8.cjs → build-0aed2000.cjs} +11 -8
  3. package/dist/_chunks/{build-45e5ded8.cjs.map → build-0aed2000.cjs.map} +1 -1
  4. package/dist/_chunks/{buildAction-afc0a1a6.cjs → buildAction-196fba7b.cjs} +2 -2
  5. package/dist/_chunks/{buildAction-afc0a1a6.cjs.map → buildAction-196fba7b.cjs.map} +1 -1
  6. package/dist/_chunks/{check-33e163bb.cjs → check-2deafe2a.cjs} +22 -19
  7. package/dist/_chunks/{check-33e163bb.cjs.map → check-2deafe2a.cjs.map} +1 -1
  8. package/dist/_chunks/{checkAction-6fd7b2bc.cjs → checkAction-7ac5a05e.cjs} +2 -2
  9. package/dist/_chunks/{checkAction-6fd7b2bc.cjs.map → checkAction-7ac5a05e.cjs.map} +1 -1
  10. package/dist/_chunks/{index-f3c22a05.cjs → index-984e18d1.cjs} +4 -2
  11. package/dist/_chunks/{index-f3c22a05.cjs.map → index-984e18d1.cjs.map} +1 -1
  12. package/dist/_chunks/init-ab36343b.cjs +469 -0
  13. package/dist/_chunks/init-ab36343b.cjs.map +1 -0
  14. package/dist/_chunks/initAction-d18cf4f2.cjs +16 -0
  15. package/dist/_chunks/initAction-d18cf4f2.cjs.map +1 -0
  16. package/dist/_chunks/logger-c593f06b.cjs +97 -0
  17. package/dist/_chunks/logger-c593f06b.cjs.map +1 -0
  18. package/dist/_chunks/{resolveBuildContext-6666f1ab.cjs → resolveBuildContext-5ef90110.cjs} +10 -91
  19. package/dist/_chunks/resolveBuildContext-5ef90110.cjs.map +1 -0
  20. package/dist/_chunks/{watch-2bff1357.cjs → watch-63a93eb0.cjs} +10 -7
  21. package/dist/_chunks/{watch-2bff1357.cjs.map → watch-63a93eb0.cjs.map} +1 -1
  22. package/dist/_chunks/{watchAction-39b0210b.cjs → watchAction-95c0b481.cjs} +2 -2
  23. package/dist/_chunks/{watchAction-39b0210b.cjs.map → watchAction-95c0b481.cjs.map} +1 -1
  24. package/dist/cli.cjs +14 -4
  25. package/dist/cli.cjs.map +1 -1
  26. package/dist/index.cjs +12 -7
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +87 -0
  29. package/dist/index.js +449 -8
  30. package/dist/index.js.map +1 -1
  31. package/package.json +10 -2
  32. package/src/cli/index.ts +8 -0
  33. package/src/cli/initAction.ts +13 -0
  34. package/src/node/core/index.ts +1 -0
  35. package/src/node/core/pkg/types.ts +13 -0
  36. package/src/node/core/template/createFromTemplate.ts +85 -0
  37. package/src/node/core/template/define.ts +6 -0
  38. package/src/node/core/template/index.ts +3 -0
  39. package/src/node/core/template/types.ts +45 -0
  40. package/src/node/index.ts +1 -0
  41. package/src/node/init.ts +55 -0
  42. package/src/node/isEmptyDirectory.ts +5 -0
  43. package/src/node/templates/default/index.ts +1 -0
  44. package/src/node/templates/default/template.ts +553 -0
  45. package/src/node/templates/index.ts +1 -0
  46. package/dist/_chunks/resolveBuildContext-6666f1ab.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,17 +1,20 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
1
3
  import { register } from 'esbuild-register/dist/node';
2
- import path from 'path';
4
+ import path, { relative, resolve, dirname } from 'path';
3
5
  import pkgUp from 'pkg-up';
4
6
  import findConfig from 'find-config';
5
7
  import fs$1, { statSync } from 'fs';
6
- import fs, { readFile, writeFile } from 'fs/promises';
8
+ import fs, { writeFile, readFile, readdir, lstat } from 'fs/promises';
7
9
  import { z, ZodError } from 'zod';
8
10
  import chalk from 'chalk';
11
+ import { mkdirp } from 'mkdirp';
12
+ import prompts from 'prompts';
9
13
  import ts from 'typescript';
10
14
  import browserslist from 'browserslist';
11
15
  import { Observable, from, switchMap } from 'rxjs';
12
16
  import { rimraf } from 'rimraf';
13
17
  import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
14
- import { mkdirp } from 'mkdirp';
15
18
  import prettier from 'prettier';
16
19
  import { TSDocConfigFile } from '@microsoft/tsdoc-config';
17
20
  import { parse } from 'jsonc-parser';
@@ -29,6 +32,10 @@ import esbuild from 'rollup-plugin-esbuild';
29
32
  import esbuild$1 from 'esbuild';
30
33
  import treeify from 'treeify';
31
34
  import prettyBytes from 'pretty-bytes';
35
+ import getLatestVersion from 'get-latest-version';
36
+ import gitUrlParse from 'git-url-parse';
37
+ import { outdent } from 'outdent';
38
+ import parseGitConfig from 'parse-git-config';
32
39
  import { scan, startWith, distinctUntilChanged } from 'rxjs/operators';
33
40
  import globby from 'globby';
34
41
  import chokidar from 'chokidar';
@@ -345,6 +352,62 @@ function getPkgExtMap(options) {
345
352
  }
346
353
  return ret;
347
354
  }
355
+ const promptsTypes = {
356
+ string: "text"
357
+ };
358
+ async function createFromTemplate(options) {
359
+ const {
360
+ cwd,
361
+ logger,
362
+ packagePath,
363
+ template: templateOrResolver
364
+ } = options;
365
+ const template = typeof templateOrResolver === "function" ? await templateOrResolver({
366
+ cwd,
367
+ logger,
368
+ packagePath
369
+ }) : templateOrResolver;
370
+ logger.log("create new package at", relative(cwd, packagePath));
371
+ const templateOptions = {};
372
+ for (const templateOption of template.options) {
373
+ const templateValidate = templateOption.validate;
374
+ const res = await prompts({
375
+ type: promptsTypes[templateOption.type],
376
+ name: templateOption.name,
377
+ message: templateOption.description,
378
+ validate: templateValidate ? prev => templateValidate(prev) : void 0,
379
+ initial: typeof templateOption.initial === "function" ? templateOption.initial(templateOptions) : templateOption.initial
380
+ }, {
381
+ onCancel: () => process.exit(0)
382
+ });
383
+ templateOptions[templateOption.name] = templateOption.parse ? templateOption.parse(res[templateOption.name]) : res[templateOption.name];
384
+ }
385
+ const features = {};
386
+ for (const templateFeature of template.features) {
387
+ const res = templateFeature.optional ? await prompts({
388
+ type: "confirm",
389
+ name: "confirm",
390
+ message: "use ".concat(templateFeature.name, "?"),
391
+ initial: templateFeature.initial
392
+ }, {
393
+ onCancel: () => process.exit(0)
394
+ }) : void 0;
395
+ features[templateFeature.name] = (res == null ? void 0 : res.confirm) || !templateFeature.optional;
396
+ }
397
+ const files = await template.getFiles(templateOptions, features);
398
+ files.sort((a, b) => {
399
+ return a.name.localeCompare(b.name);
400
+ });
401
+ for (const file of files) {
402
+ const filePath = resolve(packagePath, file.name);
403
+ await mkdirp(dirname(filePath));
404
+ await writeFile(filePath, file.contents.trim() + "\n");
405
+ logger.success("wrote ".concat(relative(cwd, filePath)));
406
+ }
407
+ }
408
+ function defineTemplateOption(option) {
409
+ return option;
410
+ }
348
411
  async function loadTSConfig(options) {
349
412
  const {
350
413
  cwd,
@@ -1830,6 +1893,384 @@ async function check(options) {
1830
1893
  }
1831
1894
  }
1832
1895
  }
1896
+ async function isEmptyDirectory(dirPath) {
1897
+ return (await readdir(dirPath)).length === 0;
1898
+ }
1899
+ const RE_NAME = /^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)\/)?[a-z0-9-~][a-z0-9-._~]*$/i;
1900
+ const defaultTemplate = async _ref17 => {
1901
+ let {
1902
+ cwd,
1903
+ logger,
1904
+ packagePath
1905
+ } = _ref17;
1906
+ var _a, _b;
1907
+ const gitConfig = await parseGitConfig({
1908
+ cwd,
1909
+ type: "global"
1910
+ });
1911
+ return {
1912
+ options: [defineTemplateOption({
1913
+ name: "repo",
1914
+ type: "string",
1915
+ description: "git url",
1916
+ validate: v => {
1917
+ if (!v) return true;
1918
+ try {
1919
+ gitUrlParse(v);
1920
+ return true;
1921
+ } catch (err) {
1922
+ return "invalid git url";
1923
+ }
1924
+ },
1925
+ parse: v => {
1926
+ if (!v) return null;
1927
+ const result = gitUrlParse(v);
1928
+ return {
1929
+ source: result.source,
1930
+ owner: result.owner,
1931
+ name: result.name
1932
+ };
1933
+ }
1934
+ }), defineTemplateOption({
1935
+ name: "pkgName",
1936
+ type: "string",
1937
+ description: "package name",
1938
+ initial: options => {
1939
+ var _a2;
1940
+ return ((_a2 = options.repo) == null ? void 0 : _a2.name) || void 0;
1941
+ },
1942
+ validate: v => {
1943
+ if (!v) return "package name is required";
1944
+ const match = RE_NAME.exec(v);
1945
+ if (!match) {
1946
+ return "invalid package name";
1947
+ }
1948
+ return true;
1949
+ },
1950
+ parse: v => {
1951
+ if (!v) {
1952
+ throw new Error("package name is required");
1953
+ }
1954
+ const match = RE_NAME.exec(v);
1955
+ if (!match) {
1956
+ throw new Error("invalid package name");
1957
+ }
1958
+ const [scope, name] = v.split("/");
1959
+ return {
1960
+ scope,
1961
+ name,
1962
+ fullName: v
1963
+ };
1964
+ }
1965
+ }), defineTemplateOption({
1966
+ name: "description",
1967
+ type: "string",
1968
+ description: "package description"
1969
+ }), defineTemplateOption({
1970
+ name: "authorName",
1971
+ type: "string",
1972
+ description: "package author name",
1973
+ initial: (_a = gitConfig == null ? void 0 : gitConfig.user) == null ? void 0 : _a.name
1974
+ }), defineTemplateOption({
1975
+ name: "authorEmail",
1976
+ type: "string",
1977
+ description: "package author email",
1978
+ initial: (_b = gitConfig == null ? void 0 : gitConfig.user) == null ? void 0 : _b.email
1979
+ }), defineTemplateOption({
1980
+ name: "license",
1981
+ type: "string",
1982
+ description: "package license",
1983
+ initial: "MIT",
1984
+ validate: v => {
1985
+ if (!v) return "license is required";
1986
+ return true;
1987
+ }
1988
+ })],
1989
+ features: [{
1990
+ name: "eslint",
1991
+ optional: true,
1992
+ initial: true
1993
+ }, {
1994
+ name: "typescript",
1995
+ optional: true,
1996
+ initial: true
1997
+ }],
1998
+ async getFiles(options, features) {
1999
+ var _filter$join, _options$description;
2000
+ var _a2;
2001
+ const {
2002
+ pkgName,
2003
+ repo
2004
+ } = options;
2005
+ const {
2006
+ fullName: name
2007
+ } = pkgName;
2008
+ const author = (_filter$join = [options.authorName, options.authorEmail && "<".concat(options.authorEmail, ">")].filter(Boolean).join(" ")) !== null && _filter$join !== void 0 ? _filter$join : void 0;
2009
+ const prettierConfig = {
2010
+ bracketSpacing: false,
2011
+ printWidth: 100,
2012
+ semi: false,
2013
+ singleQuote: true,
2014
+ tabWidth: 2,
2015
+ plugins: ["prettier-plugin-packagejson"],
2016
+ overrides: [{
2017
+ files: ["*.yml"],
2018
+ options: {
2019
+ singleQuote: false
2020
+ }
2021
+ }]
2022
+ };
2023
+ const pkgJson = {
2024
+ name,
2025
+ version: "0.0.0",
2026
+ description: (_options$description = options.description) !== null && _options$description !== void 0 ? _options$description : void 0,
2027
+ keywords: [],
2028
+ license: options.license,
2029
+ author,
2030
+ type: "module",
2031
+ exports: {
2032
+ ".": {
2033
+ types: void 0,
2034
+ source: features.typescript ? "./src/index.ts" : "./src/index.js",
2035
+ require: "./dist/index.cjs",
2036
+ import: "./dist/index.js",
2037
+ default: "./dist/index.js"
2038
+ },
2039
+ "./package.json": "./package.json"
2040
+ },
2041
+ main: "./dist/index.cjs",
2042
+ module: "./dist/index.js",
2043
+ source: features.typescript ? "./src/index.ts" : "./src/index.js",
2044
+ files: ["dist", "src"],
2045
+ scripts: {
2046
+ build: "run-s clean pkg:build pkg:check",
2047
+ clean: "rimraf dist",
2048
+ format: "prettier --write --cache --ignore-unknown .",
2049
+ "pkg:build": "pkg build --strict",
2050
+ "pkg:check": "pkg check --strict"
2051
+ },
2052
+ prettier: prettierConfig,
2053
+ "lint-staged": {
2054
+ "*": ["prettier --write --cache --ignore-unknown"]
2055
+ },
2056
+ dependencies: {},
2057
+ devDependencies: {
2058
+ "@sanity/pkg-utils": "*",
2059
+ "lint-staged": "*",
2060
+ "npm-run-all": "*",
2061
+ prettier: "*",
2062
+ "prettier-plugin-packagejson": "*",
2063
+ rimraf: "*"
2064
+ },
2065
+ engines: {
2066
+ node: ">=18.0.0"
2067
+ }
2068
+ };
2069
+ const files = [];
2070
+ files.push({
2071
+ name: ".editorconfig",
2072
+ contents: outdent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n root = true\n\n [*]\n charset = utf-8\n indent_style = space\n indent_size = 2\n end_of_line = lf\n insert_final_newline = true\n trim_trailing_whitespace = true\n "])))
2073
+ });
2074
+ files.push({
2075
+ name: ".gitignore",
2076
+ contents: outdent(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n *.local\n *.log\n\n .DS_Store\n etc\n dist\n node_modules\n "])))
2077
+ });
2078
+ files.push({
2079
+ name: ".prettierignore",
2080
+ contents: outdent(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n /dist\n /pnpm-lock.yaml\n "])))
2081
+ });
2082
+ if (repo) {
2083
+ pkgJson.repository = {
2084
+ type: "git",
2085
+ url: "git+ssh://git@".concat(repo.source, "/").concat(repo.owner, "/").concat(repo.name, ".git")
2086
+ };
2087
+ pkgJson.bugs = {
2088
+ url: "https://".concat(repo.source, "/").concat(repo.owner, "/").concat(repo.name, "/issues")
2089
+ };
2090
+ pkgJson.homepage = "https://".concat(repo.source, "/").concat(repo.owner, "/").concat(repo.name, "#readme");
2091
+ }
2092
+ if (features.typescript) {
2093
+ pkgJson.types = "./dist/index.d.ts";
2094
+ const mainExport = (_a2 = pkgJson.exports) == null ? void 0 : _a2["."];
2095
+ if (isRecord(mainExport)) {
2096
+ mainExport.types = "./dist/index.d.ts";
2097
+ }
2098
+ pkgJson.scripts = {
2099
+ ...pkgJson.scripts,
2100
+ ["type:check"]: "tsc --build"
2101
+ };
2102
+ const devDependencies = pkgJson.devDependencies;
2103
+ if (isRecord(devDependencies)) {
2104
+ devDependencies["typescript"] = "*";
2105
+ }
2106
+ }
2107
+ if (features.eslint) {
2108
+ const eslintConfig = {
2109
+ root: true,
2110
+ env: {
2111
+ browser: true,
2112
+ es6: true,
2113
+ node: true
2114
+ },
2115
+ extends: ["eslint:recommended", "plugin:prettier/recommended"],
2116
+ parserOptions: {
2117
+ ecmaVersion: 2020,
2118
+ sourceType: "module"
2119
+ },
2120
+ plugins: ["import", "prettier"],
2121
+ rules: {
2122
+ "no-console": "error",
2123
+ "no-shadow": "error",
2124
+ "no-warning-comments": ["warn", {
2125
+ location: "start",
2126
+ terms: ["todo", "fixme"]
2127
+ }]
2128
+ }
2129
+ };
2130
+ files.push({
2131
+ name: ".eslintignore",
2132
+ contents: outdent(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n /dist\n "])))
2133
+ });
2134
+ pkgJson.scripts = {
2135
+ ...pkgJson.scripts,
2136
+ lint: features.typescript ? "eslint . --ext .cjs,.js,.ts,.tsx" : "eslint . --ext .cjs,.js"
2137
+ };
2138
+ pkgJson.devDependencies = {
2139
+ ...pkgJson.devDependencies,
2140
+ eslint: "*",
2141
+ "eslint-config-prettier": "*",
2142
+ "eslint-plugin-import": "*",
2143
+ "eslint-plugin-prettier": "*"
2144
+ };
2145
+ if (features.typescript) {
2146
+ pkgJson.devDependencies = {
2147
+ ...pkgJson.devDependencies,
2148
+ "@typescript-eslint/eslint-plugin": "*",
2149
+ "@typescript-eslint/parser": "*"
2150
+ };
2151
+ const eslintConfigOverride = {
2152
+ files: ["**/*.ts", "**/*.tsx"],
2153
+ parser: "@typescript-eslint/parser",
2154
+ parserOptions: {
2155
+ project: ["./tsconfig.json"]
2156
+ },
2157
+ extends: ["eslint:recommended", "plugin:prettier/recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"].filter(Boolean),
2158
+ plugins: ["import", "@typescript-eslint", "prettier"].filter(Boolean),
2159
+ rules: {
2160
+ "@typescript-eslint/explicit-module-boundary-types": "error",
2161
+ "@typescript-eslint/interface-name-prefix": "off",
2162
+ "@typescript-eslint/member-delimiter-style": "off",
2163
+ "@typescript-eslint/no-empty-interface": "off"
2164
+ }
2165
+ };
2166
+ eslintConfig.overrides = [eslintConfigOverride];
2167
+ }
2168
+ files.push({
2169
+ name: ".eslintrc.cjs",
2170
+ contents: format(resolve(packagePath, ".eslintrc.cjs"), outdent(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n 'use strict'\n\n /** @type import('eslint').Linter.Config */\n module.exports = ", "\n "])), JSON.stringify(eslintConfig, null, 2)), prettierConfig)
2171
+ });
2172
+ }
2173
+ if (features.typescript) {
2174
+ files.push({
2175
+ name: "tsconfig.settings.json",
2176
+ contents: format(resolve(packagePath, "tsconfig.settings.json"), outdent(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n {\n \"compilerOptions\": {\n \"module\": \"ES2020\",\n \"target\": \"ES2020\",\n \"declaration\": true,\n \"declarationMap\": true,\n \"sourceMap\": true,\n\n // Strict type-checking\n \"strict\": true,\n \"noImplicitAny\": true,\n \"strictNullChecks\": true,\n \"strictFunctionTypes\": true,\n \"strictPropertyInitialization\": true,\n \"noImplicitThis\": true,\n \"alwaysStrict\": true,\n\n // Additional checks\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"noImplicitReturns\": true,\n \"noFallthroughCasesInSwitch\": true,\n \"skipLibCheck\": true,\n\n // Module resolution\n \"moduleResolution\": \"node\",\n \"allowSyntheticDefaultImports\": true,\n \"esModuleInterop\": true\n }\n }\n "]))), prettierConfig)
2177
+ });
2178
+ files.push({
2179
+ name: "tsconfig.dist.json",
2180
+ contents: format(resolve(packagePath, "tsconfig.dist.json"), outdent(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./src\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./dist\",\n \"emitDeclarationOnly\": true,\n \"resolveJsonModule\": true\n }\n }\n "]))), prettierConfig)
2181
+ });
2182
+ files.push({
2183
+ name: "tsconfig.json",
2184
+ contents: format(resolve(packagePath, "tsconfig.json"), outdent(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n {\n \"extends\": \"./tsconfig.settings\",\n \"include\": [\"./*.cjs\", \"./*.ts\", \"./package.config.ts\", \"./src\"],\n \"compilerOptions\": {\n \"rootDir\": \".\",\n \"outDir\": \"./dist\",\n \"noEmit\": true,\n \"allowJs\": true,\n \"resolveJsonModule\": true,\n }\n }\n "]))), prettierConfig)
2185
+ });
2186
+ }
2187
+ if (features.typescript) {
2188
+ files.push({
2189
+ name: "package.config.ts",
2190
+ contents: format(resolve(packagePath, "package.config.ts"), outdent(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n extract: {\n rules: {\n // do not require internal members to be prefixed with `_`\n 'ae-internal-missing-underscore': 'off',\n },\n },\n\n // the path to the tsconfig file for distributed builds\n tsconfig: 'tsconfig.dist.json',\n })\n "], ["\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n extract: {\n rules: {\n // do not require internal members to be prefixed with \\`_\\`\n 'ae-internal-missing-underscore': 'off',\n },\n },\n\n // the path to the tsconfig file for distributed builds\n tsconfig: 'tsconfig.dist.json',\n })\n "]))), prettierConfig)
2191
+ });
2192
+ files.push({
2193
+ name: "src/index.ts",
2194
+ contents: format(resolve(packagePath, "src/index.ts"), outdent(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n /** @public */\n export function main(): void {\n //\n }\n "]))), prettierConfig)
2195
+ });
2196
+ } else {
2197
+ files.push({
2198
+ name: "package.config.js",
2199
+ contents: format(resolve(packagePath, "package.config.js"), outdent(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n extract: {\n rules: {\n // do not require internal members to be prefixed with `_`\n 'ae-internal-missing-underscore': 'off',\n },\n },\n })\n "], ["\n import {defineConfig} from '@sanity/pkg-utils'\n\n export default defineConfig({\n extract: {\n rules: {\n // do not require internal members to be prefixed with \\`_\\`\n 'ae-internal-missing-underscore': 'off',\n },\n },\n })\n "]))), prettierConfig)
2200
+ });
2201
+ files.push({
2202
+ name: "src/index.js",
2203
+ contents: format(resolve(packagePath, "src/index.js"), outdent(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n /** @public */\n export function main() {\n //\n }\n "]))), prettierConfig)
2204
+ });
2205
+ }
2206
+ try {
2207
+ var _pkgJson$dependencies;
2208
+ pkgJson.dependencies = await resolveLatestDeps((_pkgJson$dependencies = pkgJson.dependencies) !== null && _pkgJson$dependencies !== void 0 ? _pkgJson$dependencies : {});
2209
+ } catch (error) {
2210
+ logger.warn(error instanceof Error ? error.message : error);
2211
+ }
2212
+ try {
2213
+ var _pkgJson$devDependenc;
2214
+ pkgJson.devDependencies = await resolveLatestDeps((_pkgJson$devDependenc = pkgJson.devDependencies) !== null && _pkgJson$devDependenc !== void 0 ? _pkgJson$devDependenc : {});
2215
+ } catch (error) {
2216
+ logger.warn(error instanceof Error ? error.message : error);
2217
+ }
2218
+ files.push({
2219
+ name: "package.json",
2220
+ contents: format(resolve(packagePath, "package.json"), JSON.stringify(pkgJson, null, 2), prettierConfig)
2221
+ });
2222
+ return files;
2223
+ }
2224
+ };
2225
+ };
2226
+ function format(filepath, input, prettierOptions) {
2227
+ return prettier.format(input, {
2228
+ ...prettierOptions,
2229
+ filepath
2230
+ });
2231
+ }
2232
+ async function resolveLatestDeps(deps) {
2233
+ const depsEntries = Object.entries(deps);
2234
+ const latestDeps = {};
2235
+ for (const entry of depsEntries) {
2236
+ const [name, version] = entry;
2237
+ const latestVersion = await getLatestVersion(name, version);
2238
+ latestDeps[name] = latestVersion ? "^".concat(latestVersion) : version;
2239
+ }
2240
+ return latestDeps;
2241
+ }
2242
+ async function init(options) {
2243
+ if (!options.cwd) {
2244
+ throw new Error("Missing required option: cwd");
2245
+ }
2246
+ if (!options.path) {
2247
+ throw new Error("Missing required option: path");
2248
+ }
2249
+ const logger = createLogger();
2250
+ const packagePath = resolve(options.cwd, options.path);
2251
+ await ensurePackagePath(packagePath);
2252
+ await createFromTemplate({
2253
+ cwd: options.cwd,
2254
+ logger,
2255
+ template: defaultTemplate,
2256
+ packagePath
2257
+ });
2258
+ }
2259
+ async function ensurePackagePath(packagePath) {
2260
+ const exists = fileExists(packagePath);
2261
+ if (!exists) {
2262
+ await mkdirp(packagePath);
2263
+ return;
2264
+ }
2265
+ const dir = (await lstat(packagePath)).isDirectory();
2266
+ if (!dir) {
2267
+ throw new Error("the package path is a file, not a directory");
2268
+ }
2269
+ const empty = await isEmptyDirectory(packagePath);
2270
+ if (!empty) {
2271
+ throw new Error("the package directory is not empty");
2272
+ }
2273
+ }
1833
2274
  function resolveWatchTasks(ctx) {
1834
2275
  var _a, _b, _c, _d, _e;
1835
2276
  const {
@@ -1839,8 +2280,8 @@ function resolveWatchTasks(ctx) {
1839
2280
  target
1840
2281
  } = ctx;
1841
2282
  const tasks = [];
1842
- const exports = Object.entries(ctx.exports || {}).map(_ref17 => {
1843
- let [_path, exp] = _ref17;
2283
+ const exports = Object.entries(ctx.exports || {}).map(_ref18 => {
2284
+ let [_path, exp] = _ref18;
1844
2285
  return {
1845
2286
  _path,
1846
2287
  ...exp
@@ -1985,7 +2426,7 @@ async function watch(options) {
1985
2426
  logger
1986
2427
  });
1987
2428
  const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
1988
- var _ref18;
2429
+ var _ref19;
1989
2430
  const files = configFiles.map(f => path.relative(cwd, f));
1990
2431
  const packageJsonPath = files.find(f => f === "package.json");
1991
2432
  if (!packageJsonPath) {
@@ -1999,7 +2440,7 @@ async function watch(options) {
1999
2440
  cwd
2000
2441
  });
2001
2442
  const extMap = getPkgExtMap({
2002
- legacyExports: (_ref18 = config == null ? void 0 : config.legacyExports) !== null && _ref18 !== void 0 ? _ref18 : false
2443
+ legacyExports: (_ref19 = config == null ? void 0 : config.legacyExports) !== null && _ref19 !== void 0 ? _ref19 : false
2003
2444
  });
2004
2445
  const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
2005
2446
  return resolveBuildContext({
@@ -2034,5 +2475,5 @@ async function watch(options) {
2034
2475
  }
2035
2476
  });
2036
2477
  }
2037
- export { DEFAULT_BROWSERSLIST_QUERY, DEFAULT_PKG_EXT_MAP, build, buildTaskHandlers, check, createLogger, defineConfig, dtsTask, dtsWatchTask, getExtractMessagesConfig, getPkgExtMap, isRecord, loadConfig, loadPkg, loadPkgWithReporting, loadTSConfig, parseExports, resolveBuildTasks, resolveConfigProperty, rollupTask, rollupWatchTask, watch, watchTaskHandlers };
2478
+ export { DEFAULT_BROWSERSLIST_QUERY, DEFAULT_PKG_EXT_MAP, build, buildTaskHandlers, check, createFromTemplate, createLogger, defineConfig, defineTemplateOption, dtsTask, dtsWatchTask, getExtractMessagesConfig, getPkgExtMap, init, isRecord, loadConfig, loadPkg, loadPkgWithReporting, loadTSConfig, parseExports, resolveBuildTasks, resolveConfigProperty, rollupTask, rollupWatchTask, watch, watchTaskHandlers };
2038
2479
  //# sourceMappingURL=index.js.map