@sanity/pkg-utils 2.3.2 → 2.3.4
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/{build-bef452fb.cjs → build-61901816.cjs} +11 -10
- package/dist/_chunks/build-61901816.cjs.map +1 -0
- package/dist/_chunks/{buildAction-e79650e5.cjs → buildAction-2e2ae058.cjs} +2 -2
- package/dist/_chunks/{buildAction-e79650e5.cjs.map → buildAction-2e2ae058.cjs.map} +1 -1
- package/dist/_chunks/{check-2deafe2a.cjs → check-0665cb35.cjs} +76 -63
- package/dist/_chunks/check-0665cb35.cjs.map +1 -0
- package/dist/_chunks/{checkAction-7ac5a05e.cjs → checkAction-c3e5da35.cjs} +2 -2
- package/dist/_chunks/{checkAction-7ac5a05e.cjs.map → checkAction-c3e5da35.cjs.map} +1 -1
- package/dist/_chunks/{resolveBuildContext-5ef90110.cjs → consoleSpy-d738cb9f.cjs} +49 -1
- package/dist/_chunks/consoleSpy-d738cb9f.cjs.map +1 -0
- package/dist/_chunks/{index-5afcbbd5.cjs → index-07125387.cjs} +20 -56
- package/dist/_chunks/index-07125387.cjs.map +1 -0
- package/dist/_chunks/{watch-a156090d.cjs → watch-8c2aec77.cjs} +7 -7
- package/dist/_chunks/{watch-a156090d.cjs.map → watch-8c2aec77.cjs.map} +1 -1
- package/dist/_chunks/{watchAction-9581bfe7.cjs → watchAction-994967c6.cjs} +2 -2
- package/dist/_chunks/{watchAction-9581bfe7.cjs.map → watchAction-994967c6.cjs.map} +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +14 -14
- package/dist/index.js +89 -64
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/node/check.ts +87 -73
- package/src/node/{tasks/rollup/consoleSpy.ts → consoleSpy.ts} +4 -4
- package/src/node/resolveBuildTasks.ts +5 -3
- package/src/node/tasks/rollup/rollupTask.ts +40 -14
- package/dist/_chunks/build-bef452fb.cjs.map +0 -1
- package/dist/_chunks/check-2deafe2a.cjs.map +0 -1
- package/dist/_chunks/index-5afcbbd5.cjs.map +0 -1
- package/dist/_chunks/resolveBuildContext-5ef90110.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
3
6
|
import { register } from 'esbuild-register/dist/node';
|
|
4
7
|
import path, { relative, resolve, dirname } from 'path';
|
|
5
8
|
import pkgUp from 'pkg-up';
|
|
@@ -732,16 +735,17 @@ function resolveBuildTasks(ctx) {
|
|
|
732
735
|
});
|
|
733
736
|
}
|
|
734
737
|
for (const bundle of bundles) {
|
|
738
|
+
const idx = bundles.indexOf(bundle);
|
|
735
739
|
if (bundle.require) {
|
|
736
740
|
addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
737
|
-
path: "
|
|
741
|
+
path: "__$$bundle_cjs_".concat(idx, "$$__"),
|
|
738
742
|
source: bundle.source,
|
|
739
743
|
output: bundle.require
|
|
740
744
|
});
|
|
741
745
|
}
|
|
742
746
|
if (bundle.import) {
|
|
743
|
-
addRollupTaskEntry("
|
|
744
|
-
path: "
|
|
747
|
+
addRollupTaskEntry("esm", bundle.runtime || ctx.runtime, {
|
|
748
|
+
path: "__$$bundle_esm_".concat(idx, "$$__"),
|
|
745
749
|
source: bundle.source,
|
|
746
750
|
output: bundle.import
|
|
747
751
|
});
|
|
@@ -886,6 +890,7 @@ async function buildTypes(options) {
|
|
|
886
890
|
class DtsError extends Error {
|
|
887
891
|
constructor(message, messages) {
|
|
888
892
|
super(message);
|
|
893
|
+
_defineProperty(this, "messages", void 0);
|
|
889
894
|
this.messages = messages;
|
|
890
895
|
}
|
|
891
896
|
}
|
|
@@ -1278,7 +1283,7 @@ function compileESMWrapper(mod, relativeImport) {
|
|
|
1278
1283
|
function createConsoleSpy(options) {
|
|
1279
1284
|
const {
|
|
1280
1285
|
onRestored
|
|
1281
|
-
} = options;
|
|
1286
|
+
} = options || {};
|
|
1282
1287
|
const original = {
|
|
1283
1288
|
log: console.log,
|
|
1284
1289
|
warn: console.warn,
|
|
@@ -1318,7 +1323,7 @@ function createConsoleSpy(options) {
|
|
|
1318
1323
|
console.log = original.log;
|
|
1319
1324
|
console.warn = original.warn;
|
|
1320
1325
|
console.error = original.error;
|
|
1321
|
-
onRestored(messages);
|
|
1326
|
+
onRestored == null ? void 0 : onRestored(messages);
|
|
1322
1327
|
}
|
|
1323
1328
|
};
|
|
1324
1329
|
}
|
|
@@ -1484,7 +1489,14 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
1484
1489
|
};
|
|
1485
1490
|
}
|
|
1486
1491
|
const rollupTask = {
|
|
1487
|
-
name: (ctx, task) =>
|
|
1492
|
+
name: (ctx, task) => {
|
|
1493
|
+
const bundleEntries = task.entries.filter(e => e.path.includes("__$$bundle_"));
|
|
1494
|
+
const entries = task.entries.filter(e => !e.path.includes("__$$bundle_"));
|
|
1495
|
+
const targetLines = task.target.length ? [" target:", ...task.target.map(t => " - ".concat(chalk.yellow(t)))] : [];
|
|
1496
|
+
const bundlesLines = bundleEntries.length ? [" bundles:", ...bundleEntries.map(e => [" - ", "".concat(chalk.yellow(e.source), " ").concat(chalk.gray("\u2192"), " ").concat(chalk.yellow(e.output))].join(""))] : [];
|
|
1497
|
+
const entriesLines = entries.length ? [" entries:", ...entries.map(e => [" - ", "".concat(chalk.cyan(path.join(ctx.pkg.name, e.path)), ": "), "".concat(chalk.yellow(e.source), " ").concat(chalk.gray("\u2192"), " ").concat(chalk.yellow(e.output))].join(""))] : [];
|
|
1498
|
+
return ["Build javascript files...", " format: ".concat(chalk.yellow(task.format)), ...targetLines, ...bundlesLines, ...entriesLines].join("\n");
|
|
1499
|
+
},
|
|
1488
1500
|
exec: (ctx, task) => {
|
|
1489
1501
|
return new Observable(observer => {
|
|
1490
1502
|
execPromise(ctx, task).then(result => {
|
|
@@ -1821,76 +1833,89 @@ async function check(options) {
|
|
|
1821
1833
|
logger.error("missing files");
|
|
1822
1834
|
process.exit(1);
|
|
1823
1835
|
}
|
|
1824
|
-
const
|
|
1836
|
+
const exportPaths = {
|
|
1825
1837
|
require: [],
|
|
1826
1838
|
import: []
|
|
1827
1839
|
};
|
|
1828
1840
|
for (const exp of Object.values(ctx.exports || {})) {
|
|
1829
1841
|
if (!exp._exported) continue;
|
|
1830
|
-
if (exp.require)
|
|
1831
|
-
if (exp.import)
|
|
1832
|
-
}
|
|
1833
|
-
const external = Object.keys(pkg.dependencies || {})
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
resolveDir: cwd
|
|
1843
|
-
},
|
|
1844
|
-
format: "esm",
|
|
1845
|
-
bundle: true,
|
|
1846
|
-
logLevel: "silent",
|
|
1847
|
-
// otherwise output maps to stdout as we're using stdin
|
|
1848
|
-
outfile: "/dev/null",
|
|
1849
|
-
platform: "node"
|
|
1850
|
-
});
|
|
1851
|
-
if (esbuildResult.warnings.length > 0) {
|
|
1852
|
-
logger.warn(...esbuildResult.warnings);
|
|
1853
|
-
}
|
|
1854
|
-
} catch (err) {
|
|
1855
|
-
const {
|
|
1856
|
-
errors
|
|
1857
|
-
} = err;
|
|
1858
|
-
for (const _err of errors) {
|
|
1859
|
-
if (_err.location) {
|
|
1860
|
-
logger.error(_err.detail || _err.text);
|
|
1861
|
-
logger.error("".concat(_err.location.line, " | ").concat(_err.location.lineText));
|
|
1862
|
-
logger.error("in", "./".concat(_err.location.file, ":").concat(_err.location.line, ":").concat(_err.location.column));
|
|
1863
|
-
} else {
|
|
1864
|
-
logger.error(_err.detail || _err.text);
|
|
1865
|
-
}
|
|
1866
|
-
logger.log();
|
|
1867
|
-
}
|
|
1868
|
-
process.exit(1);
|
|
1869
|
-
}
|
|
1842
|
+
if (exp.require) exportPaths.require.push(exp.require);
|
|
1843
|
+
if (exp.import) exportPaths.import.push(exp.import);
|
|
1844
|
+
}
|
|
1845
|
+
const external = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {})];
|
|
1846
|
+
const consoleSpy = createConsoleSpy();
|
|
1847
|
+
if (exportPaths.import.length) {
|
|
1848
|
+
checkExports(exportPaths.import, {
|
|
1849
|
+
cwd,
|
|
1850
|
+
external,
|
|
1851
|
+
format: "esm",
|
|
1852
|
+
logger
|
|
1853
|
+
});
|
|
1870
1854
|
}
|
|
1871
|
-
if (
|
|
1872
|
-
|
|
1873
|
-
|
|
1855
|
+
if (exportPaths.require.length) {
|
|
1856
|
+
checkExports(exportPaths.require, {
|
|
1857
|
+
cwd,
|
|
1874
1858
|
external,
|
|
1875
|
-
stdin: {
|
|
1876
|
-
contents: code,
|
|
1877
|
-
loader: "js",
|
|
1878
|
-
resolveDir: cwd
|
|
1879
|
-
},
|
|
1880
1859
|
format: "cjs",
|
|
1881
|
-
|
|
1882
|
-
// otherwise output maps to stdout as we're using stdin
|
|
1883
|
-
outfile: "/dev/null",
|
|
1884
|
-
platform: "node"
|
|
1860
|
+
logger
|
|
1885
1861
|
});
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1862
|
+
}
|
|
1863
|
+
consoleSpy.restore();
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
async function checkExports(exportPaths, options) {
|
|
1867
|
+
const {
|
|
1868
|
+
cwd,
|
|
1869
|
+
external,
|
|
1870
|
+
format,
|
|
1871
|
+
logger
|
|
1872
|
+
} = options;
|
|
1873
|
+
const code = exportPaths.map(id => format ? "import('".concat(id, "');") : "require('".concat(id, "');")).join("\n");
|
|
1874
|
+
try {
|
|
1875
|
+
const esbuildResult = await esbuild$1.build({
|
|
1876
|
+
bundle: true,
|
|
1877
|
+
external,
|
|
1878
|
+
format,
|
|
1879
|
+
logLevel: "silent",
|
|
1880
|
+
// otherwise output maps to stdout as we're using stdin
|
|
1881
|
+
outfile: "/dev/null",
|
|
1882
|
+
platform: "node",
|
|
1883
|
+
stdin: {
|
|
1884
|
+
contents: code,
|
|
1885
|
+
loader: "js",
|
|
1886
|
+
resolveDir: cwd
|
|
1889
1887
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1888
|
+
});
|
|
1889
|
+
if (esbuildResult.errors.length > 0) {
|
|
1890
|
+
for (const msg of esbuildResult.errors) {
|
|
1891
|
+
printEsbuildMessage(logger.warn, msg);
|
|
1892
|
+
logger.log();
|
|
1892
1893
|
}
|
|
1894
|
+
process.exit(1);
|
|
1893
1895
|
}
|
|
1896
|
+
const esbuildWarnings = esbuildResult.warnings.filter(msg => {
|
|
1897
|
+
!(msg.detail || msg.text).includes("does not affect esbuild's own target setting");
|
|
1898
|
+
});
|
|
1899
|
+
for (const msg of esbuildWarnings) {
|
|
1900
|
+
printEsbuildMessage(logger.warn, msg);
|
|
1901
|
+
logger.log();
|
|
1902
|
+
}
|
|
1903
|
+
} catch (err) {
|
|
1904
|
+
const {
|
|
1905
|
+
errors
|
|
1906
|
+
} = err;
|
|
1907
|
+
for (const msg of errors) {
|
|
1908
|
+
printEsbuildMessage(logger.error, msg);
|
|
1909
|
+
logger.log();
|
|
1910
|
+
}
|
|
1911
|
+
process.exit(1);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
function printEsbuildMessage(log, msg) {
|
|
1915
|
+
if (msg.location) {
|
|
1916
|
+
log(["".concat(msg.detail || msg.text, "\n"), "".concat(msg.location.line, " | ").concat(msg.location.lineText, "\n"), "in ./".concat(msg.location.file, ":").concat(msg.location.line, ":").concat(msg.location.column)].join(""));
|
|
1917
|
+
} else {
|
|
1918
|
+
log(msg.detail || msg.text);
|
|
1894
1919
|
}
|
|
1895
1920
|
}
|
|
1896
1921
|
async function isEmptyDirectory(dirPath) {
|