@sanity/pkg-utils 2.2.16 → 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.
- package/README.md +16 -7
- package/dist/_chunks/{build-ba8f4eab.cjs → build-0aed2000.cjs} +11 -8
- package/dist/_chunks/build-0aed2000.cjs.map +1 -0
- package/dist/_chunks/{buildAction-f35f5fe0.cjs → buildAction-196fba7b.cjs} +2 -2
- package/dist/_chunks/{buildAction-f35f5fe0.cjs.map → buildAction-196fba7b.cjs.map} +1 -1
- package/dist/_chunks/{check-c18ac13f.cjs → check-2deafe2a.cjs} +25 -31
- package/dist/_chunks/check-2deafe2a.cjs.map +1 -0
- package/dist/_chunks/{checkAction-be47c642.cjs → checkAction-7ac5a05e.cjs} +2 -2
- package/dist/_chunks/{checkAction-be47c642.cjs.map → checkAction-7ac5a05e.cjs.map} +1 -1
- package/dist/_chunks/{index-b295a336.cjs → index-984e18d1.cjs} +6 -3
- package/dist/_chunks/index-984e18d1.cjs.map +1 -0
- package/dist/_chunks/init-ab36343b.cjs +469 -0
- package/dist/_chunks/init-ab36343b.cjs.map +1 -0
- package/dist/_chunks/initAction-d18cf4f2.cjs +16 -0
- package/dist/_chunks/initAction-d18cf4f2.cjs.map +1 -0
- package/dist/_chunks/logger-c593f06b.cjs +97 -0
- package/dist/_chunks/logger-c593f06b.cjs.map +1 -0
- package/dist/_chunks/{resolveBuildContext-2239fc5e.cjs → resolveBuildContext-5ef90110.cjs} +13 -92
- package/dist/_chunks/resolveBuildContext-5ef90110.cjs.map +1 -0
- package/dist/_chunks/{watch-5bfb8b28.cjs → watch-63a93eb0.cjs} +10 -7
- package/dist/_chunks/watch-63a93eb0.cjs.map +1 -0
- package/dist/_chunks/{watchAction-788563ea.cjs → watchAction-95c0b481.cjs} +2 -2
- package/dist/_chunks/{watchAction-788563ea.cjs.map → watchAction-95c0b481.cjs.map} +1 -1
- package/dist/cli.cjs +17 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +12 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +87 -0
- package/dist/index.js +465 -32
- package/dist/index.js.map +1 -1
- package/package.json +93 -79
- package/src/cli/index.ts +12 -3
- package/src/cli/initAction.ts +13 -0
- package/src/node/build.ts +1 -1
- package/src/node/check.ts +4 -2
- package/src/node/core/config/findConfigFile.ts +6 -14
- package/src/node/core/config/index.ts +1 -1
- package/src/node/core/config/loadConfig.ts +2 -1
- package/src/node/core/contexts/buildContext.ts +2 -1
- package/src/node/core/findCommonPath.test.ts +1 -0
- package/src/node/core/index.ts +3 -2
- package/src/node/core/pkg/loadPkg.ts +1 -0
- package/src/node/core/pkg/loadPkgWithReporting.ts +1 -0
- package/src/node/core/pkg/types.ts +13 -0
- package/src/node/core/pkg/validatePkg.ts +1 -0
- package/src/node/core/template/createFromTemplate.ts +85 -0
- package/src/node/core/template/define.ts +6 -0
- package/src/node/core/template/index.ts +3 -0
- package/src/node/core/template/types.ts +45 -0
- package/src/node/fileExists.ts +12 -0
- package/src/node/globFiles.ts +1 -1
- package/src/node/index.ts +1 -0
- package/src/node/init.ts +55 -0
- package/src/node/isEmptyDirectory.ts +5 -0
- package/src/node/printExtractMessages.ts +2 -1
- package/src/node/printPackageTree.ts +4 -13
- package/src/node/resolveBuildContext.ts +5 -4
- package/src/node/resolveBuildTasks.ts +2 -1
- package/src/node/resolveWatchTasks.ts +3 -2
- package/src/node/tasks/dts/buildTypes.ts +1 -0
- package/src/node/tasks/dts/createApiExtractorConfig.ts +1 -1
- package/src/node/tasks/dts/createTSDocConfig.ts +1 -1
- package/src/node/tasks/dts/doExtract.ts +2 -1
- package/src/node/tasks/dts/dtsTask.ts +1 -0
- package/src/node/tasks/dts/dtsWatchTask.ts +1 -0
- package/src/node/tasks/dts/extractTypes.ts +4 -3
- package/src/node/tasks/dts/getExtractMessagesConfig.ts +2 -1
- package/src/node/tasks/dts/printDiagnostic.ts +2 -1
- package/src/node/tasks/index.ts +1 -1
- package/src/node/tasks/node/reexportCjsTask.ts +3 -2
- package/src/node/tasks/rollup/resolveRollupConfig.ts +2 -1
- package/src/node/tasks/rollup/rollupTask.ts +2 -1
- package/src/node/tasks/rollup/rollupWatchTask.ts +2 -1
- package/src/node/tasks/types.ts +2 -1
- package/src/node/templates/default/index.ts +1 -0
- package/src/node/templates/default/template.ts +553 -0
- package/src/node/templates/index.ts +1 -0
- package/src/node/watch.ts +2 -1
- package/src/node/watchConfigFiles.ts +1 -0
- package/dist/_chunks/build-ba8f4eab.cjs.map +0 -1
- package/dist/_chunks/check-c18ac13f.cjs.map +0 -1
- package/dist/_chunks/index-b295a336.cjs.map +0 -1
- package/dist/_chunks/resolveBuildContext-2239fc5e.cjs.map +0 -1
- package/dist/_chunks/watch-5bfb8b28.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
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) } })); }
|
|
2
3
|
import { register } from 'esbuild-register/dist/node';
|
|
4
|
+
import path, { relative, resolve, dirname } from 'path';
|
|
3
5
|
import pkgUp from 'pkg-up';
|
|
4
|
-
import fs, { stat, readFile, writeFile } from 'fs/promises';
|
|
5
6
|
import findConfig from 'find-config';
|
|
7
|
+
import fs$1, { statSync } from 'fs';
|
|
8
|
+
import fs, { writeFile, readFile, readdir, lstat } from 'fs/promises';
|
|
6
9
|
import { z, ZodError } from 'zod';
|
|
7
10
|
import chalk from 'chalk';
|
|
11
|
+
import { mkdirp } from 'mkdirp';
|
|
12
|
+
import prompts from 'prompts';
|
|
8
13
|
import ts from 'typescript';
|
|
9
14
|
import browserslist from 'browserslist';
|
|
10
|
-
import fs$1, { statSync } from 'fs';
|
|
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,15 +32,26 @@ 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';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
function defineConfig(configOptions) {
|
|
43
|
+
return configOptions;
|
|
44
|
+
}
|
|
45
|
+
function fileExists(filePath) {
|
|
46
|
+
try {
|
|
47
|
+
statSync(filePath);
|
|
48
|
+
return true;
|
|
49
|
+
} catch (_) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
53
|
const CONFIG_FILE_NAMES = ["package.config.ts", "package.config.js", "package.config.cjs", "package.config.mjs"];
|
|
40
|
-
|
|
54
|
+
function findConfigFile(cwd) {
|
|
41
55
|
const pkgJsonPath = findConfig("package.json", {
|
|
42
56
|
cwd
|
|
43
57
|
});
|
|
@@ -45,21 +59,13 @@ async function findConfigFile(cwd) {
|
|
|
45
59
|
const pkgPath = path.dirname(pkgJsonPath);
|
|
46
60
|
for (const fileName of CONFIG_FILE_NAMES) {
|
|
47
61
|
const configPath = path.resolve(pkgPath, fileName);
|
|
48
|
-
const exists =
|
|
62
|
+
const exists = fileExists(configPath);
|
|
49
63
|
if (exists) {
|
|
50
64
|
return configPath;
|
|
51
65
|
}
|
|
52
66
|
}
|
|
53
67
|
return void 0;
|
|
54
68
|
}
|
|
55
|
-
async function fileExists$1(filePath) {
|
|
56
|
-
try {
|
|
57
|
-
await stat(filePath);
|
|
58
|
-
return true;
|
|
59
|
-
} catch (_) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
69
|
async function loadConfig(options) {
|
|
64
70
|
const {
|
|
65
71
|
cwd
|
|
@@ -95,8 +101,9 @@ function resolveConfigProperty(prop, initialValue) {
|
|
|
95
101
|
}
|
|
96
102
|
return prop;
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
const DEFAULT_BROWSERSLIST_QUERY = ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"];
|
|
105
|
+
function isRecord(value) {
|
|
106
|
+
return Boolean(value) && !Array.isArray(value) && typeof value === "object";
|
|
100
107
|
}
|
|
101
108
|
const pkgSchema = z.object({
|
|
102
109
|
type: z.optional(z.enum(["commonjs", "module"])),
|
|
@@ -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,
|
|
@@ -1624,14 +1687,6 @@ function getFilesize(file) {
|
|
|
1624
1687
|
const stats = statSync(file);
|
|
1625
1688
|
return prettyBytes(stats.size);
|
|
1626
1689
|
}
|
|
1627
|
-
function fileExists(file) {
|
|
1628
|
-
try {
|
|
1629
|
-
fs$1.accessSync(file);
|
|
1630
|
-
return true;
|
|
1631
|
-
} catch (_) {
|
|
1632
|
-
return false;
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
1690
|
function getFileInfo(cwd, filePath) {
|
|
1636
1691
|
const p = path.resolve(cwd, filePath);
|
|
1637
1692
|
const exists = fileExists(p);
|
|
@@ -1838,6 +1893,384 @@ async function check(options) {
|
|
|
1838
1893
|
}
|
|
1839
1894
|
}
|
|
1840
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
|
+
}
|
|
1841
2274
|
function resolveWatchTasks(ctx) {
|
|
1842
2275
|
var _a, _b, _c, _d, _e;
|
|
1843
2276
|
const {
|
|
@@ -1847,8 +2280,8 @@ function resolveWatchTasks(ctx) {
|
|
|
1847
2280
|
target
|
|
1848
2281
|
} = ctx;
|
|
1849
2282
|
const tasks = [];
|
|
1850
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1851
|
-
let [_path, exp] =
|
|
2283
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref18 => {
|
|
2284
|
+
let [_path, exp] = _ref18;
|
|
1852
2285
|
return {
|
|
1853
2286
|
_path,
|
|
1854
2287
|
...exp
|
|
@@ -1993,7 +2426,7 @@ async function watch(options) {
|
|
|
1993
2426
|
logger
|
|
1994
2427
|
});
|
|
1995
2428
|
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
1996
|
-
var
|
|
2429
|
+
var _ref19;
|
|
1997
2430
|
const files = configFiles.map(f => path.relative(cwd, f));
|
|
1998
2431
|
const packageJsonPath = files.find(f => f === "package.json");
|
|
1999
2432
|
if (!packageJsonPath) {
|
|
@@ -2007,7 +2440,7 @@ async function watch(options) {
|
|
|
2007
2440
|
cwd
|
|
2008
2441
|
});
|
|
2009
2442
|
const extMap = getPkgExtMap({
|
|
2010
|
-
legacyExports: (
|
|
2443
|
+
legacyExports: (_ref19 = config == null ? void 0 : config.legacyExports) !== null && _ref19 !== void 0 ? _ref19 : false
|
|
2011
2444
|
});
|
|
2012
2445
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
2013
2446
|
return resolveBuildContext({
|
|
@@ -2042,5 +2475,5 @@ async function watch(options) {
|
|
|
2042
2475
|
}
|
|
2043
2476
|
});
|
|
2044
2477
|
}
|
|
2045
|
-
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 };
|
|
2046
2479
|
//# sourceMappingURL=index.js.map
|