@sanity/pkg-utils 2.3.3 → 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-d0c6973f.cjs → build-61901816.cjs} +11 -10
- package/dist/_chunks/build-61901816.cjs.map +1 -0
- package/dist/_chunks/{buildAction-52a6a47b.cjs → buildAction-2e2ae058.cjs} +2 -2
- package/dist/_chunks/{buildAction-52a6a47b.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-d2e6a8eb.cjs → index-07125387.cjs} +16 -56
- package/dist/_chunks/index-07125387.cjs.map +1 -0
- package/dist/_chunks/{watch-63d39de0.cjs → watch-8c2aec77.cjs} +7 -7
- package/dist/_chunks/{watch-63d39de0.cjs.map → watch-8c2aec77.cjs.map} +1 -1
- package/dist/_chunks/{watchAction-a5e231d9.cjs → watchAction-994967c6.cjs} +2 -2
- package/dist/_chunks/{watchAction-a5e231d9.cjs.map → watchAction-994967c6.cjs.map} +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +14 -14
- package/dist/index.js +85 -64
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- 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-d0c6973f.cjs.map +0 -1
- package/dist/_chunks/check-2deafe2a.cjs.map +0 -1
- package/dist/_chunks/index-d2e6a8eb.cjs.map +0 -1
- package/dist/_chunks/resolveBuildContext-5ef90110.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -735,16 +735,17 @@ function resolveBuildTasks(ctx) {
|
|
|
735
735
|
});
|
|
736
736
|
}
|
|
737
737
|
for (const bundle of bundles) {
|
|
738
|
+
const idx = bundles.indexOf(bundle);
|
|
738
739
|
if (bundle.require) {
|
|
739
740
|
addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
740
|
-
path: "
|
|
741
|
+
path: "__$$bundle_cjs_".concat(idx, "$$__"),
|
|
741
742
|
source: bundle.source,
|
|
742
743
|
output: bundle.require
|
|
743
744
|
});
|
|
744
745
|
}
|
|
745
746
|
if (bundle.import) {
|
|
746
|
-
addRollupTaskEntry("
|
|
747
|
-
path: "
|
|
747
|
+
addRollupTaskEntry("esm", bundle.runtime || ctx.runtime, {
|
|
748
|
+
path: "__$$bundle_esm_".concat(idx, "$$__"),
|
|
748
749
|
source: bundle.source,
|
|
749
750
|
output: bundle.import
|
|
750
751
|
});
|
|
@@ -1282,7 +1283,7 @@ function compileESMWrapper(mod, relativeImport) {
|
|
|
1282
1283
|
function createConsoleSpy(options) {
|
|
1283
1284
|
const {
|
|
1284
1285
|
onRestored
|
|
1285
|
-
} = options;
|
|
1286
|
+
} = options || {};
|
|
1286
1287
|
const original = {
|
|
1287
1288
|
log: console.log,
|
|
1288
1289
|
warn: console.warn,
|
|
@@ -1322,7 +1323,7 @@ function createConsoleSpy(options) {
|
|
|
1322
1323
|
console.log = original.log;
|
|
1323
1324
|
console.warn = original.warn;
|
|
1324
1325
|
console.error = original.error;
|
|
1325
|
-
onRestored(messages);
|
|
1326
|
+
onRestored == null ? void 0 : onRestored(messages);
|
|
1326
1327
|
}
|
|
1327
1328
|
};
|
|
1328
1329
|
}
|
|
@@ -1488,7 +1489,14 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
1488
1489
|
};
|
|
1489
1490
|
}
|
|
1490
1491
|
const rollupTask = {
|
|
1491
|
-
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
|
+
},
|
|
1492
1500
|
exec: (ctx, task) => {
|
|
1493
1501
|
return new Observable(observer => {
|
|
1494
1502
|
execPromise(ctx, task).then(result => {
|
|
@@ -1825,76 +1833,89 @@ async function check(options) {
|
|
|
1825
1833
|
logger.error("missing files");
|
|
1826
1834
|
process.exit(1);
|
|
1827
1835
|
}
|
|
1828
|
-
const
|
|
1836
|
+
const exportPaths = {
|
|
1829
1837
|
require: [],
|
|
1830
1838
|
import: []
|
|
1831
1839
|
};
|
|
1832
1840
|
for (const exp of Object.values(ctx.exports || {})) {
|
|
1833
1841
|
if (!exp._exported) continue;
|
|
1834
|
-
if (exp.require)
|
|
1835
|
-
if (exp.import)
|
|
1836
|
-
}
|
|
1837
|
-
const external = Object.keys(pkg.dependencies || {})
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
resolveDir: cwd
|
|
1847
|
-
},
|
|
1848
|
-
format: "esm",
|
|
1849
|
-
bundle: true,
|
|
1850
|
-
logLevel: "silent",
|
|
1851
|
-
// otherwise output maps to stdout as we're using stdin
|
|
1852
|
-
outfile: "/dev/null",
|
|
1853
|
-
platform: "node"
|
|
1854
|
-
});
|
|
1855
|
-
if (esbuildResult.warnings.length > 0) {
|
|
1856
|
-
logger.warn(...esbuildResult.warnings);
|
|
1857
|
-
}
|
|
1858
|
-
} catch (err) {
|
|
1859
|
-
const {
|
|
1860
|
-
errors
|
|
1861
|
-
} = err;
|
|
1862
|
-
for (const _err of errors) {
|
|
1863
|
-
if (_err.location) {
|
|
1864
|
-
logger.error(_err.detail || _err.text);
|
|
1865
|
-
logger.error("".concat(_err.location.line, " | ").concat(_err.location.lineText));
|
|
1866
|
-
logger.error("in", "./".concat(_err.location.file, ":").concat(_err.location.line, ":").concat(_err.location.column));
|
|
1867
|
-
} else {
|
|
1868
|
-
logger.error(_err.detail || _err.text);
|
|
1869
|
-
}
|
|
1870
|
-
logger.log();
|
|
1871
|
-
}
|
|
1872
|
-
process.exit(1);
|
|
1873
|
-
}
|
|
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
|
+
});
|
|
1874
1854
|
}
|
|
1875
|
-
if (
|
|
1876
|
-
|
|
1877
|
-
|
|
1855
|
+
if (exportPaths.require.length) {
|
|
1856
|
+
checkExports(exportPaths.require, {
|
|
1857
|
+
cwd,
|
|
1878
1858
|
external,
|
|
1879
|
-
stdin: {
|
|
1880
|
-
contents: code,
|
|
1881
|
-
loader: "js",
|
|
1882
|
-
resolveDir: cwd
|
|
1883
|
-
},
|
|
1884
1859
|
format: "cjs",
|
|
1885
|
-
|
|
1886
|
-
// otherwise output maps to stdout as we're using stdin
|
|
1887
|
-
outfile: "/dev/null",
|
|
1888
|
-
platform: "node"
|
|
1860
|
+
logger
|
|
1889
1861
|
});
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
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
|
|
1893
1887
|
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1888
|
+
});
|
|
1889
|
+
if (esbuildResult.errors.length > 0) {
|
|
1890
|
+
for (const msg of esbuildResult.errors) {
|
|
1891
|
+
printEsbuildMessage(logger.warn, msg);
|
|
1892
|
+
logger.log();
|
|
1896
1893
|
}
|
|
1894
|
+
process.exit(1);
|
|
1897
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);
|
|
1898
1919
|
}
|
|
1899
1920
|
}
|
|
1900
1921
|
async function isEmptyDirectory(dirPath) {
|