@sanity/pkg-utils 11.0.16 → 12.0.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/MIGRATE.md +152 -0
- package/README.md +110 -55
- package/dist/buildAction-DFrmHzYY.js +146 -0
- package/dist/buildAction-DFrmHzYY.js.map +1 -0
- package/dist/checkAction-BMxszLZS.js +140 -0
- package/dist/checkAction-BMxszLZS.js.map +1 -0
- package/dist/cli.js +22 -28
- package/dist/cli.js.map +1 -1
- package/dist/createApiExtractorConfig-CJoZqw8e.js +30 -0
- package/dist/createApiExtractorConfig-CJoZqw8e.js.map +1 -0
- package/dist/createTSDocConfig-CwaWneTR.js +25 -0
- package/dist/createTSDocConfig-CwaWneTR.js.map +1 -0
- package/dist/getExtractMessagesConfig-CXljwFbQ.js +75 -0
- package/dist/getExtractMessagesConfig-CXljwFbQ.js.map +1 -0
- package/dist/handleError-83GwKIFM.js +40 -0
- package/dist/handleError-83GwKIFM.js.map +1 -0
- package/dist/index.d.ts +141 -195
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +203 -11
- package/dist/index.js.map +1 -1
- package/dist/initAction-Cv0oRwWP.js +618 -0
- package/dist/initAction-Cv0oRwWP.js.map +1 -0
- package/dist/printExtractMessages-DyaYtByp.js +33 -0
- package/dist/printExtractMessages-DyaYtByp.js.map +1 -0
- package/dist/resolveBuildContext-CwqbTV6p.js +713 -0
- package/dist/resolveBuildContext-CwqbTV6p.js.map +1 -0
- package/dist/resolveTsdownConfig-2OdGF-dM.js +258 -0
- package/dist/resolveTsdownConfig-2OdGF-dM.js.map +1 -0
- package/dist/spinner-DAHe7SuT.js +15 -0
- package/dist/spinner-DAHe7SuT.js.map +1 -0
- package/dist/watchAction-uRPAvgLE.js +179 -0
- package/dist/watchAction-uRPAvgLE.js.map +1 -0
- package/dist/watchConfigFiles-AGBDblwf.js +43 -0
- package/dist/watchConfigFiles-AGBDblwf.js.map +1 -0
- package/package.json +10 -24
- package/dist/_chunks-es/buildAction.js +0 -195
- package/dist/_chunks-es/buildAction.js.map +0 -1
- package/dist/_chunks-es/checkAction.js +0 -198
- package/dist/_chunks-es/checkAction.js.map +0 -1
- package/dist/_chunks-es/createApiExtractorConfig.js +0 -52
- package/dist/_chunks-es/createApiExtractorConfig.js.map +0 -1
- package/dist/_chunks-es/createTSDocConfig.js +0 -31
- package/dist/_chunks-es/createTSDocConfig.js.map +0 -1
- package/dist/_chunks-es/defaults.js +0 -36
- package/dist/_chunks-es/defaults.js.map +0 -1
- package/dist/_chunks-es/define.js +0 -7
- package/dist/_chunks-es/define.js.map +0 -1
- package/dist/_chunks-es/extractModuleBlocks.js +0 -48
- package/dist/_chunks-es/extractModuleBlocks.js.map +0 -1
- package/dist/_chunks-es/fileExists.js +0 -12
- package/dist/_chunks-es/fileExists.js.map +0 -1
- package/dist/_chunks-es/getExtractMessagesConfig.js +0 -83
- package/dist/_chunks-es/getExtractMessagesConfig.js.map +0 -1
- package/dist/_chunks-es/handleError.js +0 -32
- package/dist/_chunks-es/handleError.js.map +0 -1
- package/dist/_chunks-es/index.js +0 -825
- package/dist/_chunks-es/index.js.map +0 -1
- package/dist/_chunks-es/initAction.js +0 -654
- package/dist/_chunks-es/initAction.js.map +0 -1
- package/dist/_chunks-es/printExtractMessages.js +0 -44
- package/dist/_chunks-es/printExtractMessages.js.map +0 -1
- package/dist/_chunks-es/resolveBuildContext.js +0 -717
- package/dist/_chunks-es/resolveBuildContext.js.map +0 -1
- package/dist/_chunks-es/resolveRolldownConfig.js +0 -117
- package/dist/_chunks-es/resolveRolldownConfig.js.map +0 -1
- package/dist/_chunks-es/spinner.js +0 -16
- package/dist/_chunks-es/spinner.js.map +0 -1
- package/dist/_chunks-es/watchAction.js +0 -160
- package/dist/_chunks-es/watchAction.js.map +0 -1
- package/dist/_chunks-es/watchConfigFiles.js +0 -49
- package/dist/_chunks-es/watchConfigFiles.js.map +0 -1
|
@@ -1,717 +0,0 @@
|
|
|
1
|
-
import { parsePackage, _typoMap, ZodError, parseExports } from "@sanity/parse-package-json";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import path, { resolve } from "node:path";
|
|
5
|
-
import browserslist from "browserslist";
|
|
6
|
-
import { DEFAULT_BROWSERSLIST_QUERY } from "./defaults.js";
|
|
7
|
-
import { existsSync } from "node:fs";
|
|
8
|
-
import { isRecord } from "./handleError.js";
|
|
9
|
-
import ts from "@typescript/typescript6";
|
|
10
|
-
import { errorMap } from "zod-validation-error/v3";
|
|
11
|
-
import { z } from "zod/v3";
|
|
12
|
-
function createConsoleSpy(options) {
|
|
13
|
-
const { onRestored } = options || {}, original = {
|
|
14
|
-
log: console.log,
|
|
15
|
-
warn: console.warn,
|
|
16
|
-
error: console.error
|
|
17
|
-
}, messages = [];
|
|
18
|
-
return console.log = (...args) => messages.push({ type: "log", args }), console.warn = (...args) => messages.push({ type: "warn", args }), console.error = (...args) => messages.push({ type: "error", args }), {
|
|
19
|
-
messages,
|
|
20
|
-
restore: () => {
|
|
21
|
-
console.log = original.log, console.warn = original.warn, console.error = original.error, onRestored?.(messages);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const dependencyPlacementRules = [
|
|
26
|
-
{
|
|
27
|
-
name: "react-is",
|
|
28
|
-
option: "noReactIsPeerDependency",
|
|
29
|
-
disallowedIn: ["peerDependencies"],
|
|
30
|
-
allowedIn: ["dependencies", "devDependencies"]
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "@sanity/ui",
|
|
34
|
-
option: "noSanityUiPeerDependency",
|
|
35
|
-
disallowedIn: ["peerDependencies"],
|
|
36
|
-
allowedIn: ["dependencies", "devDependencies"]
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "@sanity/icons",
|
|
40
|
-
option: "noSanityIconsPeerDependency",
|
|
41
|
-
disallowedIn: ["peerDependencies"],
|
|
42
|
-
allowedIn: ["dependencies", "devDependencies"]
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: "sanity",
|
|
46
|
-
option: "noSanityDependency",
|
|
47
|
-
disallowedIn: ["dependencies"],
|
|
48
|
-
allowedIn: ["devDependencies", "peerDependencies"]
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "styled-components",
|
|
52
|
-
option: "noStyledComponentsDependency",
|
|
53
|
-
disallowedIn: ["dependencies"],
|
|
54
|
-
allowedIn: ["devDependencies", "peerDependencies"]
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "react",
|
|
58
|
-
option: "noReactDependency",
|
|
59
|
-
disallowedIn: ["dependencies"],
|
|
60
|
-
allowedIn: ["devDependencies", "peerDependencies"]
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: "react-dom",
|
|
64
|
-
option: "noReactDomDependency",
|
|
65
|
-
disallowedIn: ["dependencies"],
|
|
66
|
-
allowedIn: ["devDependencies", "peerDependencies"]
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: "@types/react",
|
|
70
|
-
option: "noReactTypesDependency",
|
|
71
|
-
disallowedIn: ["dependencies"],
|
|
72
|
-
allowedIn: ["devDependencies", "peerDependencies"],
|
|
73
|
-
requiredPeerVersion: "*"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "@types/react-dom",
|
|
77
|
-
option: "noReactDomTypesDependency",
|
|
78
|
-
disallowedIn: ["dependencies"],
|
|
79
|
-
allowedIn: ["devDependencies", "peerDependencies"],
|
|
80
|
-
requiredPeerVersion: "*"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "@types/node",
|
|
84
|
-
option: "noNodeTypesDependency",
|
|
85
|
-
disallowedIn: ["dependencies"],
|
|
86
|
-
allowedIn: ["devDependencies", "peerDependencies"],
|
|
87
|
-
requiredPeerVersion: "*"
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: "rxjs",
|
|
91
|
-
option: "noRxjsPeerDependency",
|
|
92
|
-
disallowedIn: ["peerDependencies"],
|
|
93
|
-
allowedIn: ["dependencies", "devDependencies"]
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: "@sanity/client",
|
|
97
|
-
option: "noSanityClientPeerDependency",
|
|
98
|
-
disallowedIn: ["peerDependencies"],
|
|
99
|
-
allowedIn: ["dependencies", "devDependencies"]
|
|
100
|
-
}
|
|
101
|
-
];
|
|
102
|
-
function formatFields(fields) {
|
|
103
|
-
const labels = fields.map((field) => `\`${field}\``);
|
|
104
|
-
return labels.length <= 1 ? labels.join("") : `${labels.slice(0, -1).join(", ")} or ${labels[labels.length - 1]}`;
|
|
105
|
-
}
|
|
106
|
-
function checkDependencyPlacement(options) {
|
|
107
|
-
const { pkg, logger, strictOptions: strictOptions2 } = options;
|
|
108
|
-
let shouldError = !1;
|
|
109
|
-
const report = (level, message) => {
|
|
110
|
-
level === "error" ? (shouldError = !0, logger.error(message)) : logger.warn(message);
|
|
111
|
-
};
|
|
112
|
-
for (const rule of dependencyPlacementRules) {
|
|
113
|
-
const level = strictOptions2[rule.option];
|
|
114
|
-
if (level !== "off") {
|
|
115
|
-
for (const field of rule.disallowedIn)
|
|
116
|
-
Object.hasOwn(pkg[field] ?? {}, rule.name) && report(
|
|
117
|
-
level,
|
|
118
|
-
`package.json: \`${rule.name}\` should not be in \`${field}\`. It should be in ${formatFields(
|
|
119
|
-
rule.allowedIn
|
|
120
|
-
)} instead.`
|
|
121
|
-
);
|
|
122
|
-
if (rule.requiredPeerVersion !== void 0) {
|
|
123
|
-
const peerDependencies = pkg.peerDependencies ?? {};
|
|
124
|
-
Object.hasOwn(peerDependencies, rule.name) && peerDependencies[rule.name] !== rule.requiredPeerVersion && report(
|
|
125
|
-
level,
|
|
126
|
-
`package.json: \`${rule.name}\` in \`peerDependencies\` should be set to "${rule.requiredPeerVersion}" (got "${peerDependencies[rule.name]}").`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return shouldError;
|
|
132
|
-
}
|
|
133
|
-
function assertLast(a, arr) {
|
|
134
|
-
const aIdx = arr.indexOf(a);
|
|
135
|
-
return aIdx === -1 ? !0 : aIdx === arr.length - 1;
|
|
136
|
-
}
|
|
137
|
-
function assertOrder(a, b, arr) {
|
|
138
|
-
const aIdx = arr.indexOf(a), bIdx = arr.indexOf(b);
|
|
139
|
-
return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
|
|
140
|
-
}
|
|
141
|
-
function validatePkg(input) {
|
|
142
|
-
const pkg = parsePackage(input), invalidKey = Object.keys(input).find((key) => {
|
|
143
|
-
const needle = key.toUpperCase();
|
|
144
|
-
return _typoMap.has(needle) ? _typoMap.get(needle) !== key : !1;
|
|
145
|
-
});
|
|
146
|
-
if (invalidKey)
|
|
147
|
-
throw new TypeError(
|
|
148
|
-
`
|
|
149
|
-
- package.json: "${invalidKey}" is not a valid key. Did you mean "${_typoMap.get(invalidKey.toUpperCase())}"?`
|
|
150
|
-
);
|
|
151
|
-
return pkg;
|
|
152
|
-
}
|
|
153
|
-
async function loadPkg(options) {
|
|
154
|
-
const { pkgPath } = options, raw = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
|
|
155
|
-
return validatePkg(raw), raw;
|
|
156
|
-
}
|
|
157
|
-
function areExportValuesEqual(value1, value2) {
|
|
158
|
-
if (typeof value1 == "string" && typeof value2 == "string")
|
|
159
|
-
return value1 === value2;
|
|
160
|
-
if (typeof value1 != typeof value2)
|
|
161
|
-
return !1;
|
|
162
|
-
if (typeof value1 == "object" && value1 !== null && typeof value2 == "object" && value2 !== null && !Array.isArray(value1) && !Array.isArray(value2)) {
|
|
163
|
-
const obj1 = value1, obj2 = value2, keys1 = Object.keys(obj1).filter(
|
|
164
|
-
(k) => k !== "source" && k !== "development" && k !== "monorepo"
|
|
165
|
-
), keys2 = Object.keys(obj2).filter(
|
|
166
|
-
(k) => k !== "source" && k !== "development" && k !== "monorepo"
|
|
167
|
-
);
|
|
168
|
-
if (keys1.length !== keys2.length)
|
|
169
|
-
return !1;
|
|
170
|
-
for (const key of keys1) {
|
|
171
|
-
if (!keys2.includes(key))
|
|
172
|
-
return !1;
|
|
173
|
-
const val1 = obj1[key], val2 = obj2[key];
|
|
174
|
-
if (val1 === void 0 || val2 === void 0 || !areExportValuesEqual(val1, val2))
|
|
175
|
-
return !1;
|
|
176
|
-
}
|
|
177
|
-
return !0;
|
|
178
|
-
}
|
|
179
|
-
return !1;
|
|
180
|
-
}
|
|
181
|
-
async function loadPkgWithReporting(options) {
|
|
182
|
-
const { pkgPath, logger, strict: strict2, strictOptions: strictOptions2 } = options;
|
|
183
|
-
try {
|
|
184
|
-
const pkg = await loadPkg({ pkgPath });
|
|
185
|
-
let shouldError = !1;
|
|
186
|
-
if (strict2) {
|
|
187
|
-
if (strictOptions2.preferModuleType !== "off")
|
|
188
|
-
if (pkg.type) {
|
|
189
|
-
if (pkg.type === "commonjs") {
|
|
190
|
-
const msg = 'package.json: `type` is set to "commonjs". Future versions of pkg-utils will require `"type": "module"`. Consider migrating to ES modules to prepare for this change.';
|
|
191
|
-
strictOptions2.preferModuleType === "error" ? (shouldError = !0, logger.error(msg)) : logger.warn(msg);
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
const msg = 'package.json: `type` field is missing. Future versions of pkg-utils will require `"type": "module"`. Consider adding `"type": "module"` to prepare for this change.';
|
|
195
|
-
strictOptions2.preferModuleType === "error" ? (shouldError = !0, logger.error(msg)) : logger.warn(msg);
|
|
196
|
-
}
|
|
197
|
-
if (strictOptions2.noPackageJsonBrowser !== "off" && pkg.browser) {
|
|
198
|
-
const msg = "package.json: the `browser` field is no longer needed. Use the `browser` condition in `exports` instead for better support across modern bundlers.";
|
|
199
|
-
strictOptions2.noPackageJsonBrowser === "error" ? (shouldError = !0, logger.error(msg)) : logger.warn(msg);
|
|
200
|
-
}
|
|
201
|
-
if (strictOptions2.noPackageJsonTypesVersions !== "off" && pkg.typesVersions) {
|
|
202
|
-
const msg = "package.json: the `typesVersions` field is no longer needed. TypeScript has long supported conditional exports and the `types` condition. Remove the `typesVersions` field and use the `types` condition in `exports` instead.";
|
|
203
|
-
strictOptions2.noPackageJsonTypesVersions === "error" ? (shouldError = !0, logger.error(msg)) : logger.warn(msg);
|
|
204
|
-
}
|
|
205
|
-
checkDependencyPlacement({ pkg, logger, strictOptions: strictOptions2 }) && (shouldError = !0);
|
|
206
|
-
}
|
|
207
|
-
if (pkg.exports) {
|
|
208
|
-
const _exports = Object.entries(pkg.exports);
|
|
209
|
-
for (const [expPath, exp] of _exports) {
|
|
210
|
-
if (typeof exp == "string" || expPath.endsWith(".css") || "svelte" in exp)
|
|
211
|
-
continue;
|
|
212
|
-
const keys = Object.keys(exp);
|
|
213
|
-
exp.types && (shouldError = !0, logger.error(
|
|
214
|
-
`exports["${expPath}"]: the \`types\` condition shouldn't be used as dts files are generated in such a way that both CJS and ESM is supported`
|
|
215
|
-
)), exp.module && (shouldError = !0, logger.error(
|
|
216
|
-
`exports["${expPath}"]: the \`module\` condition shouldn't be used as it's not well supported in all bundlers.`
|
|
217
|
-
)), exp.development && exp.source && exp.development !== exp.source && (shouldError = !0, logger.error(
|
|
218
|
-
`exports["${expPath}"]: the \`development\` condition must have the same value as \`source\` when both are present. Expected "${exp.source}" but got "${exp.development}"`
|
|
219
|
-
)), exp.monorepo && exp.source && exp.monorepo !== exp.source && (shouldError = !0, logger.error(
|
|
220
|
-
`exports["${expPath}"]: the \`monorepo\` condition must have the same value as \`source\` when both are present. Expected "${exp.source}" but got "${exp.monorepo}"`
|
|
221
|
-
)), exp.node ? (exp.import && exp.node.import && !assertOrder("node", "import", keys) && (shouldError = !0, logger.error(
|
|
222
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`import\` property`
|
|
223
|
-
)), exp.node.module && (shouldError = !0, logger.error(
|
|
224
|
-
`exports["${expPath}"]: the \`node.module\` condition shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the "dual package hazard"`
|
|
225
|
-
)), !exp.node.source && exp.node.import && (exp.node.require || exp.require) && (exp.node.import.endsWith(".cjs.js") || exp.node.import.endsWith(".cjs.mjs")) && (shouldError = !0, logger.error(
|
|
226
|
-
`exports["${expPath}"]: the \`node.import\` re-export pattern shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the "dual package hazard"`
|
|
227
|
-
)), exp.require && exp.node.require && exp.require === exp.node.require ? (shouldError = !0, logger.error(
|
|
228
|
-
`exports["${expPath}"]: the \`node.require\` property isn't necessary as it's identical to \`require\``
|
|
229
|
-
)) : exp.require && exp.node.require && !assertOrder("node", "require", keys) && (shouldError = !0, logger.error(
|
|
230
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`require\` property`
|
|
231
|
-
))) : assertOrder("import", "require", keys) || logger.warn(
|
|
232
|
-
`exports["${expPath}"]: the \`import\` property should come before the \`require\` property`
|
|
233
|
-
), assertLast("default", keys) || (shouldError = !0, logger.error(
|
|
234
|
-
`exports["${expPath}"]: the \`default\` property should be the last property`
|
|
235
|
-
));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (strict2 && pkg.exports && Object.keys(pkg.exports).length > 0 && Object.entries(pkg.exports).some(([, exp]) => typeof exp == "string" || typeof exp == "object" && "svelte" in exp ? !1 : !!(exp.source || exp.development || exp.monorepo)))
|
|
239
|
-
if (pkg.publishConfig?.exports) {
|
|
240
|
-
const publishExports = pkg.publishConfig.exports;
|
|
241
|
-
for (const exportPath of Object.keys(pkg.exports))
|
|
242
|
-
exportPath in publishExports || (shouldError = !0, logger.error(
|
|
243
|
-
`publishConfig.exports: missing export path "${exportPath}" that exists in exports`
|
|
244
|
-
));
|
|
245
|
-
for (const exportPath of Object.keys(publishExports))
|
|
246
|
-
exportPath in pkg.exports || (shouldError = !0, logger.error(
|
|
247
|
-
`publishConfig.exports: unexpected export path "${exportPath}" that does not exist in exports`
|
|
248
|
-
));
|
|
249
|
-
for (const [exportPath, exp] of Object.entries(pkg.exports)) {
|
|
250
|
-
if (typeof exp == "string" || "svelte" in exp) {
|
|
251
|
-
const publishExp2 = publishExports[exportPath];
|
|
252
|
-
typeof publishExp2 != "string" && (typeof publishExp2 != "object" || !("svelte" in publishExp2)) && (shouldError = !0, logger.error(
|
|
253
|
-
`publishConfig.exports["${exportPath}"]: should be a string matching exports["${exportPath}"]`
|
|
254
|
-
));
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
const publishExp = publishExports[exportPath];
|
|
258
|
-
if (!publishExp)
|
|
259
|
-
continue;
|
|
260
|
-
if (typeof publishExp == "string") {
|
|
261
|
-
const conditions = Object.keys(exp).filter(
|
|
262
|
-
(k) => k !== "source" && k !== "development" && k !== "monorepo"
|
|
263
|
-
);
|
|
264
|
-
if (conditions.length !== 1 || conditions[0] !== "default")
|
|
265
|
-
shouldError = !0, logger.error(
|
|
266
|
-
`publishConfig.exports["${exportPath}"]: is a string but exports["${exportPath}"] has multiple conditions besides source/development/monorepo: ${conditions.join(", ")}`
|
|
267
|
-
);
|
|
268
|
-
else {
|
|
269
|
-
const expectedValue = exp.default;
|
|
270
|
-
publishExp !== expectedValue && (shouldError = !0, logger.error(
|
|
271
|
-
`publishConfig.exports["${exportPath}"]: should be "${expectedValue}" but got "${publishExp}"`
|
|
272
|
-
));
|
|
273
|
-
}
|
|
274
|
-
continue;
|
|
275
|
-
}
|
|
276
|
-
if ("svelte" in publishExp)
|
|
277
|
-
continue;
|
|
278
|
-
const exportConditions = Object.keys(exp).filter(
|
|
279
|
-
(k) => k !== "source" && k !== "development" && k !== "monorepo"
|
|
280
|
-
), publishConditions = Object.keys(publishExp);
|
|
281
|
-
"source" in publishExp && (shouldError = !0, logger.error(
|
|
282
|
-
`publishConfig.exports["${exportPath}"]: should not contain the \`source\` condition`
|
|
283
|
-
)), "development" in publishExp && (shouldError = !0, logger.error(
|
|
284
|
-
`publishConfig.exports["${exportPath}"]: should not contain the \`development\` condition`
|
|
285
|
-
)), "monorepo" in publishExp && (shouldError = !0, logger.error(
|
|
286
|
-
`publishConfig.exports["${exportPath}"]: should not contain the \`monorepo\` condition`
|
|
287
|
-
));
|
|
288
|
-
for (const condition of exportConditions)
|
|
289
|
-
condition in publishExp || (shouldError = !0, logger.error(
|
|
290
|
-
`publishConfig.exports["${exportPath}"]: missing \`${condition}\` condition that exists in exports["${exportPath}"]`
|
|
291
|
-
));
|
|
292
|
-
for (const condition of publishConditions)
|
|
293
|
-
exportConditions.includes(condition) || (shouldError = !0, logger.error(
|
|
294
|
-
`publishConfig.exports["${exportPath}"]: unexpected \`${condition}\` condition that does not exist in exports["${exportPath}"]`
|
|
295
|
-
));
|
|
296
|
-
for (const condition of exportConditions)
|
|
297
|
-
if (condition in publishExp) {
|
|
298
|
-
const exportValue = exp[condition], publishValue = publishExp[condition];
|
|
299
|
-
if (!areExportValuesEqual(exportValue, publishValue)) {
|
|
300
|
-
const exportValueStr = typeof exportValue == "string" ? exportValue : JSON.stringify(exportValue), publishValueStr = typeof publishValue == "string" ? publishValue : JSON.stringify(publishValue);
|
|
301
|
-
shouldError = !0, logger.error(
|
|
302
|
-
`publishConfig.exports["${exportPath}"].${condition}: should be ${exportValueStr} but got ${publishValueStr}`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
} else {
|
|
308
|
-
const msg = "package.json: `publishConfig.exports` is missing. Adding it helps avoid publishing to npm with the `source`, `development`, or `monorepo` condition that points to code that cannot be used by the resolver. See https://tsdown.dev/options/package-exports#dev-exports for more information.";
|
|
309
|
-
strictOptions2.noPublishConfigExports === "error" ? (shouldError = !0, logger.error(msg)) : strictOptions2.noPublishConfigExports !== "off" && logger.warn(msg);
|
|
310
|
-
}
|
|
311
|
-
return shouldError && process.exit(1), pkg;
|
|
312
|
-
} catch (err) {
|
|
313
|
-
if (err instanceof ZodError)
|
|
314
|
-
for (const issue of err.issues) {
|
|
315
|
-
if (issue.code === "invalid_type") {
|
|
316
|
-
logger.error(
|
|
317
|
-
[
|
|
318
|
-
`\`${formatPath(issue.path)}\` `,
|
|
319
|
-
`in \`./package.json\` must be of type ${chalk.magenta(issue.expected)} `,
|
|
320
|
-
`(received ${chalk.magenta(issue.received)})`
|
|
321
|
-
].join("")
|
|
322
|
-
);
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
logger.error(issue);
|
|
326
|
-
}
|
|
327
|
-
else
|
|
328
|
-
logger.error(err);
|
|
329
|
-
return process.exit(1);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
function formatPath(segments) {
|
|
333
|
-
return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
|
|
334
|
-
}
|
|
335
|
-
function browserslistToEsbuild(browserslistConfig, options = {}) {
|
|
336
|
-
if (!browserslistConfig) {
|
|
337
|
-
const path2 = process.cwd();
|
|
338
|
-
browserslistConfig = browserslist.loadConfig({ path: path2, ...options });
|
|
339
|
-
}
|
|
340
|
-
const SUPPORTED_ESBUILD_TARGETS = [
|
|
341
|
-
"es",
|
|
342
|
-
"chrome",
|
|
343
|
-
"edge",
|
|
344
|
-
"firefox",
|
|
345
|
-
"ios",
|
|
346
|
-
"node",
|
|
347
|
-
"safari",
|
|
348
|
-
"opera",
|
|
349
|
-
"ie"
|
|
350
|
-
], UNSUPPORTED = ["android 4"], replaces = {
|
|
351
|
-
ios_saf: "ios",
|
|
352
|
-
android: "chrome"
|
|
353
|
-
}, separator = " ";
|
|
354
|
-
return browserslist(browserslistConfig, options).filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u))).map((b) => b === "safari TP" ? browserslist("last 1 safari version")[0] : b).map((b) => b.split(separator)).map((b) => (replaces[b[0]] && (b[0] = replaces[b[0]]), b)).map((b) => (b[1].includes("-") && (b[1] = b[1].slice(0, b[1].indexOf("-"))), b)).map((b) => (b[1].endsWith(".0") && (b[1] = b[1].slice(0, -2)), b)).filter((b) => /^\d+(\.\d+)*$/.test(b[1])).filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0])).reduce((acc, b) => {
|
|
355
|
-
const existingIndex = acc.findIndex((br) => br[0] === b[0]);
|
|
356
|
-
return existingIndex !== -1 ? acc[existingIndex][1] = b[1] : acc.push(b), acc;
|
|
357
|
-
}, []).map((b) => b.join(""));
|
|
358
|
-
}
|
|
359
|
-
function isPkgConfigPropertyResolver(prop) {
|
|
360
|
-
return typeof prop == "function";
|
|
361
|
-
}
|
|
362
|
-
function resolveConfigProperty(prop, initialValue) {
|
|
363
|
-
return prop ? isPkgConfigPropertyResolver(prop) ? prop(initialValue) : prop : initialValue;
|
|
364
|
-
}
|
|
365
|
-
function pathContains(containerPath, itemPath) {
|
|
366
|
-
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
367
|
-
}
|
|
368
|
-
function findCommonDirPath(filePaths) {
|
|
369
|
-
let ret;
|
|
370
|
-
for (const filePath of filePaths) {
|
|
371
|
-
let dirPath = path.dirname(filePath);
|
|
372
|
-
if (!ret) {
|
|
373
|
-
ret = dirPath;
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
|
-
for (; dirPath !== ret; ) {
|
|
377
|
-
if (pathContains(dirPath, ret)) {
|
|
378
|
-
ret = dirPath;
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
if (dirPath = path.dirname(dirPath), dirPath === ret)
|
|
382
|
-
break;
|
|
383
|
-
if (dirPath === ".") return;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return ret;
|
|
387
|
-
}
|
|
388
|
-
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", defaultEnding = ".js", mjsEnding = ".mjs", cjsEnding = ".cjs", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
389
|
-
function getTargetPaths(_type, expOrBundle) {
|
|
390
|
-
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
391
|
-
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$1(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
|
|
392
|
-
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
393
|
-
), expOrBundle.browser?.require && set.add(
|
|
394
|
-
expOrBundle.browser.require.replace(
|
|
395
|
-
fileEnding,
|
|
396
|
-
type === "commonjs" ? dtsEnding : ctsEnding
|
|
397
|
-
)
|
|
398
|
-
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
399
|
-
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
400
|
-
), expOrBundle.node?.require && set.add(
|
|
401
|
-
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
402
|
-
))), Array.from(set);
|
|
403
|
-
}
|
|
404
|
-
function isPkgExport$1(exp) {
|
|
405
|
-
return exp?.browser || exp?.node || exp?.default;
|
|
406
|
-
}
|
|
407
|
-
const pkgExtMap = {
|
|
408
|
-
// pkg.type: "commonjs"
|
|
409
|
-
commonjs: {
|
|
410
|
-
commonjs: defaultEnding,
|
|
411
|
-
esm: mjsEnding
|
|
412
|
-
},
|
|
413
|
-
// pkg.type: "module"
|
|
414
|
-
module: {
|
|
415
|
-
commonjs: cjsEnding,
|
|
416
|
-
esm: defaultEnding
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
function validateExports(_exports, options) {
|
|
420
|
-
const { pkg } = options, type = pkg.type || "commonjs", ext = pkgExtMap[type], errors = [];
|
|
421
|
-
for (const exp of _exports)
|
|
422
|
-
exp._path === "." && (exp.require && pkg.main && exp.require !== pkg.main && errors.push(
|
|
423
|
-
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
424
|
-
), exp.import && pkg.module && exp.import !== pkg.module && errors.push(
|
|
425
|
-
'package.json: mismatch between "module" and "exports.import". These must be equal.'
|
|
426
|
-
)), exp.require && !exp.require.endsWith(ext.commonjs) && errors.push(
|
|
427
|
-
`package.json with \`type: "${type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`
|
|
428
|
-
), exp.import && !exp.import.endsWith(ext.esm) && errors.push(
|
|
429
|
-
`package.json with \`type: "${type}"\` - \`exports["${exp._path}"].import\` must end with "${ext.esm}"`
|
|
430
|
-
);
|
|
431
|
-
return errors;
|
|
432
|
-
}
|
|
433
|
-
function isTruthy$1(value) {
|
|
434
|
-
return !!value;
|
|
435
|
-
}
|
|
436
|
-
function parseAndValidateExports(options) {
|
|
437
|
-
const { cwd, pkg, strict: strict2, strictOptions: strictOptions2, logger } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
|
|
438
|
-
kind === "warn" ? logger.warn(message) : errors.push(message);
|
|
439
|
-
};
|
|
440
|
-
if (!Array.isArray(pkg.files) && strict2 && strictOptions2.alwaysPackageJsonFiles !== "off" && report(
|
|
441
|
-
strictOptions2.alwaysPackageJsonFiles,
|
|
442
|
-
"package.json: `files` should be used over `.npmignore`"
|
|
443
|
-
), pkg.source) {
|
|
444
|
-
if (strict2 && pkg.exports?.["."] && typeof pkg.exports["."] == "object" && "source" in pkg.exports["."] && pkg.exports["."].source === pkg.source)
|
|
445
|
-
errors.push(
|
|
446
|
-
'package.json: the "source" property can be removed, as it is equal to exports["."].source.'
|
|
447
|
-
);
|
|
448
|
-
else if (!pkg.exports && pkg.main) {
|
|
449
|
-
const extMap = pkgExtMap[type], importExport = pkg.main.replace(fileEnding, extMap.esm), requireExport = pkg.main.replace(fileEnding, extMap.commonjs), defaultExport = pkg.main.replace(fileEnding, defaultEnding), maybeBrowserCondition = [];
|
|
450
|
-
if (pkg.browser) {
|
|
451
|
-
const browserConditions = [];
|
|
452
|
-
pkg.module && pkg.browser?.[pkg.module] ? browserConditions.push(
|
|
453
|
-
` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`
|
|
454
|
-
) : pkg.browser?.[pkg.main] && browserConditions.push(
|
|
455
|
-
` "import": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.esm))}`
|
|
456
|
-
), pkg.browser?.[pkg.main] && browserConditions.push(
|
|
457
|
-
` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`
|
|
458
|
-
), browserConditions.length && maybeBrowserCondition.push(
|
|
459
|
-
' "browser": {',
|
|
460
|
-
` "source": ${JSON.stringify(pkg.browser?.[pkg.source] || pkg.source)},`,
|
|
461
|
-
...browserConditions,
|
|
462
|
-
" }"
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
errors.push(
|
|
466
|
-
...[
|
|
467
|
-
"package.json: `exports` are missing, it should be:",
|
|
468
|
-
'"exports": {',
|
|
469
|
-
' ".": {',
|
|
470
|
-
` "source": ${JSON.stringify(pkg.source)},`,
|
|
471
|
-
// If browser conditions are detected then add them to the suggestion
|
|
472
|
-
...maybeBrowserCondition.length > 0 ? maybeBrowserCondition : [],
|
|
473
|
-
type === "commonjs" && ` "import": ${JSON.stringify(importExport)},`,
|
|
474
|
-
type === "module" && ` "require": ${JSON.stringify(requireExport)},`,
|
|
475
|
-
` "default": ${JSON.stringify(defaultExport)}`,
|
|
476
|
-
" },",
|
|
477
|
-
' "./package.json": "./package.json"',
|
|
478
|
-
"}"
|
|
479
|
-
].filter(isTruthy$1)
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
if (errors.length)
|
|
484
|
-
throw new Error(`
|
|
485
|
-
- ` + errors.join(`
|
|
486
|
-
- `));
|
|
487
|
-
if (!pkg.exports)
|
|
488
|
-
throw new Error(
|
|
489
|
-
`
|
|
490
|
-
- ` + [
|
|
491
|
-
"package.json: `exports` are missing, please set a minimal configuration, for example:",
|
|
492
|
-
'"exports": {',
|
|
493
|
-
' ".": {',
|
|
494
|
-
' "source": "./src/index.js",',
|
|
495
|
-
' "default": "./dist/index.js"',
|
|
496
|
-
" },",
|
|
497
|
-
' "./package.json": "./package.json"',
|
|
498
|
-
"}"
|
|
499
|
-
].join(`
|
|
500
|
-
- `)
|
|
501
|
-
);
|
|
502
|
-
const _exports = parseExports({ pkg });
|
|
503
|
-
strict2 && strictOptions2.noPackageJsonTypings !== "off" && "typings" in pkg && report(strictOptions2.noPackageJsonTypings, "package.json: `typings` should be `types`"), strict2 && strictOptions2.alwaysPackageJsonTypes !== "off" && !pkg.types && typeof pkg.exports?.["."] == "object" && "source" in pkg.exports["."] && pkg.exports["."].source?.endsWith(".ts") && report(
|
|
504
|
-
strictOptions2.alwaysPackageJsonTypes,
|
|
505
|
-
"package.json: `types` must be declared for the npm listing to show as a TypeScript module."
|
|
506
|
-
), strict2 && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
507
|
-
for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
|
|
508
|
-
if (exportPath.endsWith(".json") || typeof exportEntry == "string" && exportEntry.endsWith(".json"))
|
|
509
|
-
exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"]` must be "./package.json".');
|
|
510
|
-
else if (exportPath.endsWith(".css"))
|
|
511
|
-
if (typeof exportEntry == "string")
|
|
512
|
-
existsSync(resolve(cwd, exportEntry)) || errors.push(
|
|
513
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}]\`: file does not exist.`
|
|
514
|
-
);
|
|
515
|
-
else if (isRecord(exportEntry))
|
|
516
|
-
for (const [condition, target] of Object.entries(exportEntry))
|
|
517
|
-
typeof target != "string" && errors.push(
|
|
518
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}][${JSON.stringify(condition)}]\`: must be a string path.`
|
|
519
|
-
);
|
|
520
|
-
else
|
|
521
|
-
errors.push(
|
|
522
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}]\`: must be a string path or an object of export conditions.`
|
|
523
|
-
);
|
|
524
|
-
else isRecord(exportEntry) && "svelte" in exportEntry || (isPkgExport(exportEntry) ? ({
|
|
525
|
-
...exportEntry
|
|
526
|
-
}, exportPath === "." && (exportEntry.require && pkg.main && exportEntry.require !== pkg.main && errors.push(
|
|
527
|
-
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
528
|
-
), exportEntry.import && pkg.module && exportEntry.import !== pkg.module && errors.push(
|
|
529
|
-
'package.json: mismatch between "module" and "exports.import" These must be equal.'
|
|
530
|
-
))) : isRecord(exportEntry) || errors.push("package.json: exports must be an object"));
|
|
531
|
-
if (errors.push(...validateExports(_exports, { pkg })), errors.length)
|
|
532
|
-
throw new Error(`
|
|
533
|
-
- ` + errors.join(`
|
|
534
|
-
- `));
|
|
535
|
-
return _exports;
|
|
536
|
-
}
|
|
537
|
-
function isPkgExport(value) {
|
|
538
|
-
return isRecord(value) && "source" in value && typeof value.source == "string";
|
|
539
|
-
}
|
|
540
|
-
async function loadTSConfig(options) {
|
|
541
|
-
const { cwd, tsconfigPath } = options, configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
542
|
-
if (!configPath)
|
|
543
|
-
return;
|
|
544
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
545
|
-
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
546
|
-
}
|
|
547
|
-
function resolveBrowserTarget(versions) {
|
|
548
|
-
const target = versions.filter(
|
|
549
|
-
(version) => version.startsWith("chrome") || version.startsWith("edge") || version.startsWith("firefox") || version.startsWith("ios") || version.startsWith("safari") || version.startsWith("opera")
|
|
550
|
-
);
|
|
551
|
-
if (target.length !== 0)
|
|
552
|
-
return target;
|
|
553
|
-
}
|
|
554
|
-
function resolveNodeTarget(versions) {
|
|
555
|
-
const target = versions.filter((version) => version.startsWith("node"));
|
|
556
|
-
if (target.length !== 0)
|
|
557
|
-
return target;
|
|
558
|
-
}
|
|
559
|
-
const toggle = z.union([z.literal("error"), z.literal("warn"), z.literal("off")]), strictOptions = z.object({
|
|
560
|
-
noPackageJsonTypings: toggle.default("error"),
|
|
561
|
-
noImplicitSideEffects: toggle.default("warn"),
|
|
562
|
-
noImplicitBrowsersList: toggle.default("warn"),
|
|
563
|
-
alwaysPackageJsonTypes: toggle.default("error"),
|
|
564
|
-
alwaysPackageJsonFiles: toggle.default("error"),
|
|
565
|
-
noCheckTypes: toggle.default("warn"),
|
|
566
|
-
noPackageJsonBrowser: toggle.default("warn"),
|
|
567
|
-
noPackageJsonTypesVersions: toggle.default("warn"),
|
|
568
|
-
preferModuleType: toggle.default("warn"),
|
|
569
|
-
noPublishConfigExports: toggle.default("warn"),
|
|
570
|
-
noReactIsPeerDependency: toggle.default("error"),
|
|
571
|
-
noSanityUiPeerDependency: toggle.default("error"),
|
|
572
|
-
noSanityIconsPeerDependency: toggle.default("error"),
|
|
573
|
-
noSanityDependency: toggle.default("error"),
|
|
574
|
-
noStyledComponentsDependency: toggle.default("error"),
|
|
575
|
-
noReactDependency: toggle.default("error"),
|
|
576
|
-
noReactDomDependency: toggle.default("error"),
|
|
577
|
-
noReactTypesDependency: toggle.default("error"),
|
|
578
|
-
noReactDomTypesDependency: toggle.default("error"),
|
|
579
|
-
noNodeTypesDependency: toggle.default("error"),
|
|
580
|
-
noRxjsPeerDependency: toggle.default("error"),
|
|
581
|
-
noSanityClientPeerDependency: toggle.default("error")
|
|
582
|
-
}).strict(), validationSchema = z.object({
|
|
583
|
-
strictOptions: strictOptions.default({})
|
|
584
|
-
});
|
|
585
|
-
function parseStrictOptions(input) {
|
|
586
|
-
return validationSchema.parse({ strictOptions: input }, { errorMap }).strictOptions;
|
|
587
|
-
}
|
|
588
|
-
var strict = /* @__PURE__ */ Object.freeze({
|
|
589
|
-
__proto__: null,
|
|
590
|
-
parseStrictOptions
|
|
591
|
-
});
|
|
592
|
-
function isTruthy(value) {
|
|
593
|
-
return !!value;
|
|
594
|
-
}
|
|
595
|
-
async function resolveBuildContext(options) {
|
|
596
|
-
const {
|
|
597
|
-
config,
|
|
598
|
-
cwd,
|
|
599
|
-
emitDeclarationOnly = !1,
|
|
600
|
-
logger,
|
|
601
|
-
pkg,
|
|
602
|
-
strict: strict2,
|
|
603
|
-
tsconfig: tsconfigPath
|
|
604
|
-
} = options, tsconfig = await loadTSConfig({ cwd, tsconfigPath }), strictOptions2 = parseStrictOptions(config?.strictOptions ?? {});
|
|
605
|
-
if (strictOptions2.noCheckTypes !== "off" && tsconfig?.options && config?.dts !== "rolldown" && tsconfig.options.noCheck !== !1 && !tsconfig.options.noCheck && config?.extract?.checkTypes !== !1) {
|
|
606
|
-
if (strictOptions2.noCheckTypes === "error")
|
|
607
|
-
throw new Error(
|
|
608
|
-
"`noCheck` is not set to `true` in the tsconfig.json file used by `package.config.ts`. This makes generating dts files slower than it needs to be, as it will perform type checking on the dts files while at it. You can set `noCheck: true` in tsconfig.json or set `extract: { checkTypes: false }` in package.config.ts to disable type checking."
|
|
609
|
-
);
|
|
610
|
-
logger.warn(
|
|
611
|
-
"`noCheck` is not set to `true` in the tsconfig.json file used by `package.config.ts`. This makes generating dts files slower than it needs to be, as it will perform type checking on the dts files while at it. You can set `noCheck: true` in tsconfig.json or set `extract: { checkTypes: false }` in package.config.ts to disable type checking."
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
let browserslist2 = pkg.browserslist;
|
|
615
|
-
if (!browserslist2) {
|
|
616
|
-
if (strict2 && strictOptions2.noImplicitBrowsersList !== "off") {
|
|
617
|
-
if (strictOptions2.noImplicitBrowsersList === "error")
|
|
618
|
-
throw new Error(
|
|
619
|
-
'\n- package.json: "browserslist" is missing, set it to `"browserslist": "extends @sanity/browserslist-config"`'
|
|
620
|
-
);
|
|
621
|
-
logger.warn(
|
|
622
|
-
'Could not detect a `browserslist` property in `package.json`, using default configuration. Add `"browserslist": "extends @sanity/browserslist-config"` to silence this warning.'
|
|
623
|
-
);
|
|
624
|
-
}
|
|
625
|
-
browserslist2 = DEFAULT_BROWSERSLIST_QUERY;
|
|
626
|
-
}
|
|
627
|
-
const targetVersions = browserslistToEsbuild(browserslist2);
|
|
628
|
-
if (strict2 && strictOptions2.noImplicitSideEffects !== "off" && typeof pkg.sideEffects > "u") {
|
|
629
|
-
const msg = "package.json: `sideEffects` is missing, see https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects for how to define `sideEffects`";
|
|
630
|
-
if (strictOptions2.noImplicitSideEffects === "error")
|
|
631
|
-
throw new Error(msg);
|
|
632
|
-
logger.warn(msg);
|
|
633
|
-
}
|
|
634
|
-
const nodeTarget = resolveNodeTarget(targetVersions), webTarget = resolveBrowserTarget(targetVersions);
|
|
635
|
-
if (!nodeTarget)
|
|
636
|
-
throw new Error("no matching `node` target");
|
|
637
|
-
if (!webTarget)
|
|
638
|
-
throw new Error("no matching `web` target");
|
|
639
|
-
const target = {
|
|
640
|
-
"*": webTarget.concat(nodeTarget),
|
|
641
|
-
browser: webTarget,
|
|
642
|
-
node: nodeTarget
|
|
643
|
-
}, parsedExports = parseAndValidateExports({
|
|
644
|
-
cwd,
|
|
645
|
-
pkg,
|
|
646
|
-
strict: strict2,
|
|
647
|
-
strictOptions: strictOptions2,
|
|
648
|
-
logger
|
|
649
|
-
}).reduce(
|
|
650
|
-
(acc, { _path: exportPath, ...exportEntry }) => Object.assign(acc, { [exportPath]: exportEntry }),
|
|
651
|
-
{}
|
|
652
|
-
), exports = resolveConfigProperty(config?.exports, parsedExports), parsedExternal = [
|
|
653
|
-
...pkg.dependencies ? Object.keys(pkg.dependencies) : [],
|
|
654
|
-
...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []
|
|
655
|
-
], external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config?.external, parsedExternal), externalWithTypes = /* @__PURE__ */ new Set([pkg.name, ...external, ...external.map(transformPackageName)]), bundledDependencies = (pkg.devDependencies ? Object.keys(pkg.devDependencies) : []).filter(
|
|
656
|
-
// Do not bundle anything that is marked as external
|
|
657
|
-
(_) => !externalWithTypes.has(_)
|
|
658
|
-
), bundledPackages = config && Array.isArray(config.extract?.bundledPackages) ? [...bundledDependencies, ...config.extract.bundledPackages] : resolveConfigProperty(config?.extract?.bundledPackages, bundledDependencies), outputPaths = Object.values(exports).flatMap((exportEntry) => [
|
|
659
|
-
exportEntry.import,
|
|
660
|
-
exportEntry.require,
|
|
661
|
-
exportEntry.browser?.import,
|
|
662
|
-
exportEntry.browser?.require,
|
|
663
|
-
exportEntry.node?.source && exportEntry.node.import,
|
|
664
|
-
exportEntry.node?.source && exportEntry.node.require
|
|
665
|
-
].filter(isTruthy)).map((p) => path.resolve(cwd, p)), commonDistPath = findCommonDirPath(outputPaths);
|
|
666
|
-
if (commonDistPath === cwd)
|
|
667
|
-
throw new Error(
|
|
668
|
-
"all output files must share a common parent directory which is not the root package directory"
|
|
669
|
-
);
|
|
670
|
-
if (commonDistPath && !pathContains(cwd, commonDistPath))
|
|
671
|
-
throw new Error("all output files must be located within the package");
|
|
672
|
-
const configDistPath = config?.dist ? path.resolve(cwd, config.dist) : void 0;
|
|
673
|
-
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath))
|
|
674
|
-
throw logger.log(`did you mean to configure \`dist: './${path.relative(cwd, commonDistPath)}'\`?`), new Error("all output files must be located with the configured `dist` path");
|
|
675
|
-
const distPath = configDistPath || commonDistPath;
|
|
676
|
-
if (!distPath)
|
|
677
|
-
throw new Error("could not detect `dist` path");
|
|
678
|
-
return {
|
|
679
|
-
config,
|
|
680
|
-
cwd,
|
|
681
|
-
distPath,
|
|
682
|
-
emitDeclarationOnly,
|
|
683
|
-
exports,
|
|
684
|
-
external,
|
|
685
|
-
bundledPackages,
|
|
686
|
-
files: [],
|
|
687
|
-
logger,
|
|
688
|
-
pkg,
|
|
689
|
-
runtime: config?.runtime ?? "*",
|
|
690
|
-
strict: strict2,
|
|
691
|
-
target,
|
|
692
|
-
ts: {
|
|
693
|
-
config: tsconfig,
|
|
694
|
-
configPath: tsconfigPath
|
|
695
|
-
},
|
|
696
|
-
dts: config?.dts === "rolldown" ? "rolldown" : "api-extractor"
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
function transformPackageName(packageName) {
|
|
700
|
-
if (packageName.startsWith("@types/"))
|
|
701
|
-
return packageName;
|
|
702
|
-
if (packageName.startsWith("@")) {
|
|
703
|
-
const [scope, name] = packageName.split("/");
|
|
704
|
-
return `@types/${scope?.slice(1)}__${name}`;
|
|
705
|
-
} else
|
|
706
|
-
return `@types/${packageName}`;
|
|
707
|
-
}
|
|
708
|
-
export {
|
|
709
|
-
createConsoleSpy,
|
|
710
|
-
getTargetPaths,
|
|
711
|
-
loadPkgWithReporting,
|
|
712
|
-
pkgExtMap,
|
|
713
|
-
resolveBuildContext,
|
|
714
|
-
resolveConfigProperty,
|
|
715
|
-
strict
|
|
716
|
-
};
|
|
717
|
-
//# sourceMappingURL=resolveBuildContext.js.map
|