@sanity/pkg-utils 7.4.0 → 7.5.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/dist/_chunks-cjs/index.cjs +104 -21
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-es/build.js +1 -12
- package/dist/_chunks-es/build.js.map +1 -1
- package/dist/_chunks-es/check.js +87 -20
- package/dist/_chunks-es/check.js.map +1 -1
- package/dist/_chunks-es/index.js +20 -0
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_chunks-es/spinner.js +16 -0
- package/dist/_chunks-es/spinner.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.cts +408 -487
- package/dist/index.d.ts +408 -487
- package/package.json +2 -2
|
@@ -18,7 +18,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
18
18
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
19
19
|
mod
|
|
20
20
|
));
|
|
21
|
-
var path = require("node:path"), rimraf = require("rimraf"), node_module = require("node:module"), node = require("esbuild-register/dist/node"), pkgUp = require("pkg-up"), findConfig = require("find-config"), node_fs = require("node:fs"), chalk = require("chalk"), zod = require("zod"), fs = require("node:fs/promises"), browserslist = require("browserslist"), config$1 = require("@sanity/browserslist-config"), ts = require("typescript"), zodValidationError = require("zod-validation-error"), rxjs = require("rxjs"), apiExtractor = require("@microsoft/api-extractor"), mkdirp = require("mkdirp"), prettier = require("prettier"), tsdocConfig = require("@microsoft/tsdoc-config"), jsoncParser = require("jsonc-parser"), recast = require("recast"), typeScriptParser = require("recast/parsers/typescript.js"), rollup = require("rollup"), rollupPlugin = require("@optimize-lodash/rollup-plugin"), alias = require("@rollup/plugin-alias"), pluginBabel = require("@rollup/plugin-babel"), commonjs = require("@rollup/plugin-commonjs"), json = require("@rollup/plugin-json"), pluginNodeResolve = require("@rollup/plugin-node-resolve"), replace = require("@rollup/plugin-replace"), terser = require("@rollup/plugin-terser"), esbuild = require("rollup-plugin-esbuild"),
|
|
21
|
+
var path = require("node:path"), rimraf = require("rimraf"), node_module = require("node:module"), node = require("esbuild-register/dist/node"), pkgUp = require("pkg-up"), findConfig = require("find-config"), node_fs = require("node:fs"), chalk = require("chalk"), zod = require("zod"), fs = require("node:fs/promises"), browserslist = require("browserslist"), config$1 = require("@sanity/browserslist-config"), ts = require("typescript"), zodValidationError = require("zod-validation-error"), rxjs = require("rxjs"), apiExtractor = require("@microsoft/api-extractor"), mkdirp = require("mkdirp"), prettier = require("prettier"), tsdocConfig = require("@microsoft/tsdoc-config"), jsoncParser = require("jsonc-parser"), recast = require("recast"), typeScriptParser = require("recast/parsers/typescript.js"), rollup = require("rollup"), rollupPlugin = require("@optimize-lodash/rollup-plugin"), alias = require("@rollup/plugin-alias"), pluginBabel = require("@rollup/plugin-babel"), commonjs = require("@rollup/plugin-commonjs"), json = require("@rollup/plugin-json"), pluginNodeResolve = require("@rollup/plugin-node-resolve"), replace = require("@rollup/plugin-replace"), terser = require("@rollup/plugin-terser"), esbuild = require("rollup-plugin-esbuild"), treeify = require("treeify"), prettyBytes = require("pretty-bytes"), prompts = require("prompts"), node_child_process = require("node:child_process"), getLatestVersion = require("get-latest-version"), gitUrlParse = require("git-url-parse"), outdent = require("outdent"), operators = require("rxjs/operators"), globby = require("globby"), chokidar = require("chokidar"), _documentCurrentScript = typeof document < "u" ? document.currentScript : null;
|
|
22
22
|
function _interopDefaultCompat(e) {
|
|
23
23
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
24
24
|
}
|
|
@@ -37,7 +37,7 @@ function _interopNamespaceCompat(e) {
|
|
|
37
37
|
}
|
|
38
38
|
}), n.default = e, Object.freeze(n);
|
|
39
39
|
}
|
|
40
|
-
var path__default = /* @__PURE__ */ _interopDefaultCompat(path), rimraf__namespace = /* @__PURE__ */ _interopNamespaceCompat(rimraf), pkgUp__default = /* @__PURE__ */ _interopDefaultCompat(pkgUp), findConfig__default = /* @__PURE__ */ _interopDefaultCompat(findConfig), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), browserslist__default = /* @__PURE__ */ _interopDefaultCompat(browserslist), config__default = /* @__PURE__ */ _interopDefaultCompat(config$1), ts__default = /* @__PURE__ */ _interopDefaultCompat(ts), prettier__namespace = /* @__PURE__ */ _interopNamespaceCompat(prettier), typeScriptParser__default = /* @__PURE__ */ _interopDefaultCompat(typeScriptParser), alias__default = /* @__PURE__ */ _interopDefaultCompat(alias), commonjs__default = /* @__PURE__ */ _interopDefaultCompat(commonjs), json__default = /* @__PURE__ */ _interopDefaultCompat(json), replace__default = /* @__PURE__ */ _interopDefaultCompat(replace), terser__default = /* @__PURE__ */ _interopDefaultCompat(terser), esbuild__default = /* @__PURE__ */ _interopDefaultCompat(esbuild),
|
|
40
|
+
var path__default = /* @__PURE__ */ _interopDefaultCompat(path), rimraf__namespace = /* @__PURE__ */ _interopNamespaceCompat(rimraf), pkgUp__default = /* @__PURE__ */ _interopDefaultCompat(pkgUp), findConfig__default = /* @__PURE__ */ _interopDefaultCompat(findConfig), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), browserslist__default = /* @__PURE__ */ _interopDefaultCompat(browserslist), config__default = /* @__PURE__ */ _interopDefaultCompat(config$1), ts__default = /* @__PURE__ */ _interopDefaultCompat(ts), prettier__namespace = /* @__PURE__ */ _interopNamespaceCompat(prettier), typeScriptParser__default = /* @__PURE__ */ _interopDefaultCompat(typeScriptParser), alias__default = /* @__PURE__ */ _interopDefaultCompat(alias), commonjs__default = /* @__PURE__ */ _interopDefaultCompat(commonjs), json__default = /* @__PURE__ */ _interopDefaultCompat(json), replace__default = /* @__PURE__ */ _interopDefaultCompat(replace), terser__default = /* @__PURE__ */ _interopDefaultCompat(terser), esbuild__default = /* @__PURE__ */ _interopDefaultCompat(esbuild), treeify__default = /* @__PURE__ */ _interopDefaultCompat(treeify), prettyBytes__default = /* @__PURE__ */ _interopDefaultCompat(prettyBytes), prompts__default = /* @__PURE__ */ _interopDefaultCompat(prompts), getLatestVersion__default = /* @__PURE__ */ _interopDefaultCompat(getLatestVersion), gitUrlParse__default = /* @__PURE__ */ _interopDefaultCompat(gitUrlParse), globby__default = /* @__PURE__ */ _interopDefaultCompat(globby), chokidar__namespace = /* @__PURE__ */ _interopNamespaceCompat(chokidar);
|
|
41
41
|
function fileExists(filePath) {
|
|
42
42
|
try {
|
|
43
43
|
return node_fs.statSync(filePath), !0;
|
|
@@ -714,6 +714,10 @@ function printExtractMessages(ctx, messages) {
|
|
|
714
714
|
}
|
|
715
715
|
errors.length && process.exit(1);
|
|
716
716
|
}
|
|
717
|
+
var printExtractMessages$1 = /* @__PURE__ */ Object.freeze({
|
|
718
|
+
__proto__: null,
|
|
719
|
+
printExtractMessages
|
|
720
|
+
});
|
|
717
721
|
function printDiagnostic(options) {
|
|
718
722
|
const { cwd, logger, diagnostic } = options;
|
|
719
723
|
if (diagnostic.file && diagnostic.start) {
|
|
@@ -795,6 +799,10 @@ function createApiExtractorConfig(options) {
|
|
|
795
799
|
projectFolder
|
|
796
800
|
};
|
|
797
801
|
}
|
|
802
|
+
var createApiExtractorConfig$1 = /* @__PURE__ */ Object.freeze({
|
|
803
|
+
__proto__: null,
|
|
804
|
+
createApiExtractorConfig
|
|
805
|
+
});
|
|
798
806
|
const require$1 = node_module.createRequire(typeof document > "u" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("_chunks-cjs/index.cjs", document.baseURI).href);
|
|
799
807
|
async function createTSDocConfig(opts) {
|
|
800
808
|
const { customTags } = opts;
|
|
@@ -818,6 +826,10 @@ async function createTSDocConfig(opts) {
|
|
|
818
826
|
supportForTags
|
|
819
827
|
});
|
|
820
828
|
}
|
|
829
|
+
var createTSDocConfig$1 = /* @__PURE__ */ Object.freeze({
|
|
830
|
+
__proto__: null,
|
|
831
|
+
createTSDocConfig
|
|
832
|
+
});
|
|
821
833
|
async function extractModuleBlocksFromTypes({
|
|
822
834
|
tsOutDir,
|
|
823
835
|
extractResult
|
|
@@ -913,6 +925,10 @@ function getExtractMessagesConfig(options) {
|
|
|
913
925
|
}
|
|
914
926
|
};
|
|
915
927
|
}
|
|
928
|
+
var getExtractMessagesConfig$1 = /* @__PURE__ */ Object.freeze({
|
|
929
|
+
__proto__: null,
|
|
930
|
+
getExtractMessagesConfig
|
|
931
|
+
});
|
|
916
932
|
async function extractTypes(options) {
|
|
917
933
|
const {
|
|
918
934
|
bundledPackages,
|
|
@@ -1581,30 +1597,40 @@ function printPackageTree(ctx) {
|
|
|
1581
1597
|
), logger.log(treeify__default.default.asTree(tree, !0, !0));
|
|
1582
1598
|
}
|
|
1583
1599
|
async function check(options) {
|
|
1584
|
-
const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger = createLogger(),
|
|
1585
|
-
|
|
1586
|
-
const
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1600
|
+
const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger = createLogger(), spinner = createSpinner("");
|
|
1601
|
+
try {
|
|
1602
|
+
const config2 = await loadConfig({ cwd }), pkg = await loadPkgWithReporting({ cwd, logger, strict }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
|
|
1603
|
+
if (printPackageTree(ctx), strict) {
|
|
1604
|
+
const missingFiles = [];
|
|
1605
|
+
for (const [, exp] of Object.entries(ctx.exports || {}))
|
|
1606
|
+
exp.source && !fileExists(path__default.default.resolve(cwd, exp.source)) && missingFiles.push(exp.source), exp.require && !fileExists(path__default.default.resolve(cwd, exp.require)) && missingFiles.push(exp.require), exp.import && !fileExists(path__default.default.resolve(cwd, exp.import)) && missingFiles.push(exp.import);
|
|
1607
|
+
ctx.pkg.types && !fileExists(path__default.default.resolve(cwd, ctx.pkg.types)) && missingFiles.push(ctx.pkg.types), missingFiles.length && (logger.error(`missing files: ${missingFiles.join(", ")}`), process.exit(1));
|
|
1608
|
+
const exportPaths = {
|
|
1609
|
+
require: [],
|
|
1610
|
+
import: []
|
|
1611
|
+
};
|
|
1612
|
+
for (const exp of Object.values(ctx.exports || {}))
|
|
1613
|
+
exp._exported && (exp.require && exportPaths.require.push(exp.require), exp.import && exportPaths.import.push(exp.import));
|
|
1614
|
+
const external = [
|
|
1615
|
+
...Object.keys(pkg.dependencies || {}),
|
|
1616
|
+
...Object.keys(pkg.devDependencies || {})
|
|
1617
|
+
], consoleSpy = createConsoleSpy();
|
|
1618
|
+
exportPaths.import.length && checkExports(exportPaths.import, { cwd, external, format: "esm", logger }), exportPaths.require.length && checkExports(exportPaths.require, { cwd, external, format: "cjs", logger }), consoleSpy.restore();
|
|
1619
|
+
}
|
|
1620
|
+
ctx.dts === "rolldown" && ctx.config?.extract?.enabled !== !1 && await checkApiExtractorReleaseTags(ctx), spinner.complete();
|
|
1621
|
+
} catch (err) {
|
|
1622
|
+
if (spinner.error(), err instanceof Error) {
|
|
1623
|
+
const RE_CWD = new RegExp(`${cwd}`, "g");
|
|
1624
|
+
logger.error(err.message.replace(RE_CWD, ".")), logger.log();
|
|
1625
|
+
}
|
|
1626
|
+
process.exit(1);
|
|
1601
1627
|
}
|
|
1602
1628
|
}
|
|
1603
1629
|
async function checkExports(exportPaths, options) {
|
|
1604
|
-
const { cwd, external, format, logger } = options, code = exportPaths.map((id) => format ? `import('${id}');` : `require('${id}');`).join(`
|
|
1630
|
+
const { build: build2 } = await import("esbuild"), { cwd, external, format, logger } = options, code = exportPaths.map((id) => format ? `import('${id}');` : `require('${id}');`).join(`
|
|
1605
1631
|
`);
|
|
1606
1632
|
try {
|
|
1607
|
-
const esbuildResult = await
|
|
1633
|
+
const esbuildResult = await build2({
|
|
1608
1634
|
bundle: !0,
|
|
1609
1635
|
external,
|
|
1610
1636
|
format,
|
|
@@ -1654,6 +1680,63 @@ function isEsbuildFailure(err) {
|
|
|
1654
1680
|
function isEsbuildMessage(msg) {
|
|
1655
1681
|
return typeof msg == "object" && msg !== null && "text" in msg && typeof msg.text == "string" && "location" in msg && (msg.location === null || typeof msg.location == "object");
|
|
1656
1682
|
}
|
|
1683
|
+
async function checkApiExtractorReleaseTags(ctx) {
|
|
1684
|
+
const [
|
|
1685
|
+
{ Extractor, ExtractorConfig },
|
|
1686
|
+
{ createApiExtractorConfig: createApiExtractorConfig2 },
|
|
1687
|
+
{ createTSDocConfig: createTSDocConfig2 },
|
|
1688
|
+
{ getExtractMessagesConfig: getExtractMessagesConfig2 },
|
|
1689
|
+
{ printExtractMessages: printExtractMessages2 }
|
|
1690
|
+
] = await Promise.all([
|
|
1691
|
+
import("@microsoft/api-extractor"),
|
|
1692
|
+
Promise.resolve().then(function() {
|
|
1693
|
+
return createApiExtractorConfig$1;
|
|
1694
|
+
}),
|
|
1695
|
+
Promise.resolve().then(function() {
|
|
1696
|
+
return createTSDocConfig$1;
|
|
1697
|
+
}),
|
|
1698
|
+
Promise.resolve().then(function() {
|
|
1699
|
+
return getExtractMessagesConfig$1;
|
|
1700
|
+
}),
|
|
1701
|
+
Promise.resolve().then(function() {
|
|
1702
|
+
return printExtractMessages$1;
|
|
1703
|
+
})
|
|
1704
|
+
]), customTags = ctx.config?.extract?.customTags || [], bundledPackages = ctx.bundledPackages, distPath = ctx.distPath, outDir = ctx.ts.config?.options.outDir, rules = ctx.config?.extract?.rules || {};
|
|
1705
|
+
if (!outDir)
|
|
1706
|
+
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
1707
|
+
for (const exp of Object.values(ctx.exports || {})) {
|
|
1708
|
+
if (!exp._exported || !exp.default.endsWith(".js")) continue;
|
|
1709
|
+
const dtsPath = exp.default.replace(/\.js$/, ".d.ts"), exportPath = path__default.default.resolve(ctx.cwd, dtsPath), tsdocConfigFile = await createTSDocConfig2({
|
|
1710
|
+
customTags
|
|
1711
|
+
}), extractorConfig = ExtractorConfig.prepare({
|
|
1712
|
+
configObject: createApiExtractorConfig2({
|
|
1713
|
+
bundledPackages,
|
|
1714
|
+
distPath,
|
|
1715
|
+
exportPath,
|
|
1716
|
+
filePath: path__default.default.relative(outDir, dtsPath),
|
|
1717
|
+
messages: getExtractMessagesConfig2({ rules }),
|
|
1718
|
+
projectFolder: ctx.cwd,
|
|
1719
|
+
mainEntryPointFilePath: exportPath,
|
|
1720
|
+
tsconfig: ctx.ts.config,
|
|
1721
|
+
tsconfigPath: path__default.default.resolve(ctx.cwd, ctx.ts.configPath || "tsconfig.json"),
|
|
1722
|
+
dtsRollupEnabled: !1
|
|
1723
|
+
}),
|
|
1724
|
+
configObjectFullPath: void 0,
|
|
1725
|
+
tsdocConfigFile,
|
|
1726
|
+
packageJsonFullPath: path__default.default.resolve(ctx.cwd, "package.json")
|
|
1727
|
+
}), messages = [];
|
|
1728
|
+
Extractor.invoke(extractorConfig, {
|
|
1729
|
+
// Equivalent to the "--local" command-line parameter
|
|
1730
|
+
localBuild: !0,
|
|
1731
|
+
// Equivalent to the "--verbose" command-line parameter
|
|
1732
|
+
showVerboseMessages: !0,
|
|
1733
|
+
// handle messages
|
|
1734
|
+
messageCallback(message) {
|
|
1735
|
+
messages.push(message), message.handled = !0;
|
|
1736
|
+
}
|
|
1737
|
+
}), printExtractMessages2(ctx, messages);
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1657
1740
|
function defineConfig(configOptions) {
|
|
1658
1741
|
return configOptions;
|
|
1659
1742
|
}
|