@sanity/pkg-utils 5.1.2 → 5.1.3-canary.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 +1 -1
- package/dist/_chunks-cjs/build.cjs +33 -12
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +1 -1
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +53 -21
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +76 -31
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +4 -4
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +156 -60
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/build.ts +1 -1
- package/src/node/check.ts +1 -1
- package/src/node/core/pkg/parseExports.ts +35 -10
- package/src/node/core/pkg/pkgExt.ts +12 -17
- package/src/node/core/pkg/validateExports.ts +4 -3
- package/src/node/resolveBuildContext.ts +6 -1
- package/src/node/resolveBuildTasks.ts +49 -7
- package/src/node/tasks/dts/buildTypes.ts +5 -1
- package/src/node/tasks/dts/getTargetPaths.ts +6 -2
- package/src/node/tasks/index.ts +3 -2
- package/src/node/tasks/rollup/index.ts +1 -0
- package/src/node/tasks/rollup/resolveRollupConfig.ts +26 -26
- package/src/node/tasks/rollup/rollupLegacyTask.ts +144 -0
- package/src/node/tasks/rollup/rollupTask.ts +2 -2
- package/src/node/tasks/types.ts +16 -5
- package/src/node/watch.ts +2 -2
|
@@ -30,25 +30,6 @@ function _interopDefaultCompat(e) {
|
|
|
30
30
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
31
31
|
}
|
|
32
32
|
var chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), path__default = /* @__PURE__ */ _interopDefaultCompat(path$1), rimraf__default = /* @__PURE__ */ _interopDefaultCompat(rimraf), ts__default = /* @__PURE__ */ _interopDefaultCompat(ts), fs__default$1 = /* @__PURE__ */ _interopDefaultCompat(fs), prettier__default = /* @__PURE__ */ _interopDefaultCompat(prettier), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs$1), require$$4__default = /* @__PURE__ */ _interopDefaultCompat(require$$4), 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);
|
|
33
|
-
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
34
|
-
function getTargetPaths(_type, expOrBundle) {
|
|
35
|
-
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
36
|
-
return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
|
|
37
|
-
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
38
|
-
), expOrBundle.browser?.require && set.add(
|
|
39
|
-
expOrBundle.browser.require.replace(
|
|
40
|
-
fileEnding,
|
|
41
|
-
type === "commonjs" ? dtsEnding : ctsEnding
|
|
42
|
-
)
|
|
43
|
-
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
44
|
-
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
45
|
-
), expOrBundle.node?.require && set.add(
|
|
46
|
-
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
47
|
-
))), Array.from(set);
|
|
48
|
-
}
|
|
49
|
-
function isPkgExport(exp) {
|
|
50
|
-
return exp?.browser || exp?.node || exp?.default;
|
|
51
|
-
}
|
|
52
33
|
function printExtractMessages(ctx, messages) {
|
|
53
34
|
const { cwd, logger } = ctx, warnings = messages.filter((msg) => msg.logLevel === "warning");
|
|
54
35
|
warnings.length && logger.log();
|
|
@@ -116,7 +97,7 @@ async function buildTypes(options2) {
|
|
|
116
97
|
} : {}
|
|
117
98
|
}, program = ts__default.default.createProgram(tsconfig.fileNames, compilerOptions), emitResult = program.emit(), allDiagnostics = ts__default.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
118
99
|
for (const diagnostic of allDiagnostics)
|
|
119
|
-
printDiagnostic({ cwd, logger, diagnostic });
|
|
100
|
+
diagnostic.code !== 2307 && printDiagnostic({ cwd, logger, diagnostic });
|
|
120
101
|
if (emitResult.emitSkipped && allDiagnostics.filter((diag) => diag.category === ts__default.default.DiagnosticCategory.Error).length && strict)
|
|
121
102
|
throw new Error("failed to compile TypeScript definitions");
|
|
122
103
|
}
|
|
@@ -19775,7 +19756,7 @@ const dtsTask = {
|
|
|
19775
19756
|
}
|
|
19776
19757
|
};
|
|
19777
19758
|
function resolveRollupConfig(ctx, buildTask) {
|
|
19778
|
-
const { format, runtime, target } = buildTask, { config, cwd, exports: _exports,
|
|
19759
|
+
const { format, runtime, target } = buildTask, { config, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, isLegacyExports = buildTask.type === "build:legacy", outputExt = isLegacyExports ? consoleSpy.pkgExtMap.legacy : consoleSpy.pkgExtMap[pkg.type || "commonjs"][format], minify = config?.minify ?? !1, outDir = path__default.default.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
19779
19760
|
Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path__default.default.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
|
|
19780
19761
|
), entries = buildTask.entries.map((entry) => ({
|
|
19781
19762
|
...entry,
|
|
@@ -19840,6 +19821,11 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
19840
19821
|
}
|
|
19841
19822
|
})
|
|
19842
19823
|
].filter(Boolean), userPlugins = config?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : consoleSpy.resolveConfigProperty(config?.rollup?.plugins, defaultPlugins);
|
|
19824
|
+
if (config?.rollup?.hashChunkFileNames === !1 && config.legacyExports)
|
|
19825
|
+
throw new TypeError(
|
|
19826
|
+
"when `legacyExports: true` you can't set `rollup.hashChunkFileNames: false` \u2013 this would cause chunks to overwrite each other. Please remove the `hashChunkFileNames` option or set it to `true"
|
|
19827
|
+
);
|
|
19828
|
+
const hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${isLegacyExports ? "_legacy" : hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = isLegacyExports ? "[name].js" : `[name]${outputExt}`;
|
|
19843
19829
|
return {
|
|
19844
19830
|
inputOptions: {
|
|
19845
19831
|
context: cwd,
|
|
@@ -19874,16 +19860,10 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
19874
19860
|
experimentalLogSideEffects: config?.rollup?.experimentalLogSideEffects
|
|
19875
19861
|
},
|
|
19876
19862
|
outputOptions: {
|
|
19877
|
-
chunkFileNames
|
|
19878
|
-
const parts = outputExt.split("."), prefix = config?.rollup?.hashChunkFileNames ? "[name]-[hash]" : "[name]", folder = config?.rollup?.hashChunkFileNames ? "_chunks" : "_chunks-[format]";
|
|
19879
|
-
return parts.length === 3 ? `${folder}/${prefix}.${parts[2]}` : `${folder}/${prefix}${outputExt}`;
|
|
19880
|
-
},
|
|
19863
|
+
chunkFileNames,
|
|
19881
19864
|
compact: minify,
|
|
19882
19865
|
dir: outDir,
|
|
19883
|
-
entryFileNames
|
|
19884
|
-
const parts = outputExt.split(".");
|
|
19885
|
-
return parts.length === 3 ? `[name].${parts[2]}` : `[name]${outputExt}`;
|
|
19886
|
-
},
|
|
19866
|
+
entryFileNames,
|
|
19887
19867
|
esModule: !0,
|
|
19888
19868
|
format,
|
|
19889
19869
|
interop: "compat",
|
|
@@ -19893,6 +19873,70 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
19893
19873
|
}
|
|
19894
19874
|
};
|
|
19895
19875
|
}
|
|
19876
|
+
const rollupLegacyTask = {
|
|
19877
|
+
name: (ctx, task) => {
|
|
19878
|
+
const entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk__default.default.yellow(t)}`)] : [], entriesLines = entries.length ? [
|
|
19879
|
+
" entries:",
|
|
19880
|
+
...entries.map(
|
|
19881
|
+
(e) => [
|
|
19882
|
+
" - ",
|
|
19883
|
+
`${chalk__default.default.cyan(path__default.default.join(ctx.pkg.name, e.path))}: `,
|
|
19884
|
+
`${chalk__default.default.yellow(e.source)} ${chalk__default.default.gray("\u2192")} ${chalk__default.default.yellow(e.output)}`
|
|
19885
|
+
].join("")
|
|
19886
|
+
)
|
|
19887
|
+
] : [];
|
|
19888
|
+
return [
|
|
19889
|
+
"Build legacy exports...",
|
|
19890
|
+
` format: ${chalk__default.default.yellow(task.format)}`,
|
|
19891
|
+
...targetLines,
|
|
19892
|
+
...entriesLines
|
|
19893
|
+
].join(`
|
|
19894
|
+
`);
|
|
19895
|
+
},
|
|
19896
|
+
exec: (ctx, task) => new rxjs.Observable((observer) => {
|
|
19897
|
+
execPromise$1(ctx, task).then((result) => {
|
|
19898
|
+
observer.next(result), observer.complete();
|
|
19899
|
+
}).catch((err) => observer.error(err));
|
|
19900
|
+
}),
|
|
19901
|
+
complete: () => {
|
|
19902
|
+
},
|
|
19903
|
+
error: (_ctx, _task, err) => {
|
|
19904
|
+
console.error(err);
|
|
19905
|
+
}
|
|
19906
|
+
};
|
|
19907
|
+
async function execPromise$1(ctx, task) {
|
|
19908
|
+
const { distPath, files, logger } = ctx, outDir = path__default.default.relative(ctx.cwd, distPath), consoleSpy$1 = consoleSpy.createConsoleSpy({
|
|
19909
|
+
onRestored: (messages) => {
|
|
19910
|
+
for (const msg of messages) {
|
|
19911
|
+
const text = String(msg.args[0]);
|
|
19912
|
+
msg.code !== "CIRCULAR_DEPENDENCY" && (text.startsWith("Dynamic import can only") || text.startsWith("Sourcemap is likely to be incorrect") || (msg.type === "log" && logger.info(...msg.args), msg.type === "warn" && logger.warn(...msg.args), msg.type === "error" && logger.error(...msg.args)));
|
|
19913
|
+
}
|
|
19914
|
+
}
|
|
19915
|
+
});
|
|
19916
|
+
try {
|
|
19917
|
+
const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup.rollup({
|
|
19918
|
+
...inputOptions,
|
|
19919
|
+
onwarn(warning) {
|
|
19920
|
+
consoleSpy$1.messages.push({
|
|
19921
|
+
type: "warn",
|
|
19922
|
+
code: warning.code,
|
|
19923
|
+
args: [warning.message]
|
|
19924
|
+
});
|
|
19925
|
+
}
|
|
19926
|
+
}), { output } = await bundle.generate(outputOptions);
|
|
19927
|
+
for (const chunkOrAsset of output)
|
|
19928
|
+
chunkOrAsset.type === "asset" ? files.push({
|
|
19929
|
+
type: "asset",
|
|
19930
|
+
path: path__default.default.resolve(outDir, chunkOrAsset.fileName)
|
|
19931
|
+
}) : files.push({
|
|
19932
|
+
type: "chunk",
|
|
19933
|
+
path: path__default.default.resolve(outDir, chunkOrAsset.fileName)
|
|
19934
|
+
});
|
|
19935
|
+
await bundle.write(outputOptions), await bundle.close(), consoleSpy$1.restore();
|
|
19936
|
+
} catch (err) {
|
|
19937
|
+
throw consoleSpy$1.restore(), err;
|
|
19938
|
+
}
|
|
19939
|
+
}
|
|
19896
19940
|
const rollupTask = {
|
|
19897
19941
|
name: (ctx, task) => {
|
|
19898
19942
|
const bundleEntries = task.entries.filter((e) => e.path.includes("__$$bundle_")), entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk__default.default.yellow(t)}`)] : [], bundlesLines = bundleEntries.length ? [
|
|
@@ -20005,7 +20049,8 @@ const rollupWatchTask = {
|
|
|
20005
20049
|
}
|
|
20006
20050
|
}, buildTaskHandlers = {
|
|
20007
20051
|
"build:dts": dtsTask,
|
|
20008
|
-
"build:js": rollupTask
|
|
20052
|
+
"build:js": rollupTask,
|
|
20053
|
+
"build:legacy": rollupLegacyTask
|
|
20009
20054
|
}, watchTaskHandlers = {
|
|
20010
20055
|
"watch:dts": dtsWatchTask,
|
|
20011
20056
|
"watch:js": rollupWatchTask
|
|
@@ -20014,7 +20059,7 @@ exports.buildTaskHandlers = buildTaskHandlers;
|
|
|
20014
20059
|
exports.dtsTask = dtsTask;
|
|
20015
20060
|
exports.dtsWatchTask = dtsWatchTask;
|
|
20016
20061
|
exports.getExtractMessagesConfig = getExtractMessagesConfig;
|
|
20017
|
-
exports.
|
|
20062
|
+
exports.rollupLegacyTask = rollupLegacyTask;
|
|
20018
20063
|
exports.rollupTask = rollupTask;
|
|
20019
20064
|
exports.rollupWatchTask = rollupWatchTask;
|
|
20020
20065
|
exports.watchTaskHandlers = watchTaskHandlers;
|