@sanity/pkg-utils 4.2.6 → 4.2.7
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-Dvr5eKKV.cjs +158 -0
- package/dist/_chunks/{build-BxYgJfQq.cjs.map → build-Dvr5eKKV.cjs.map} +1 -1
- package/dist/_chunks/{buildAction-KZkR53RZ.cjs → buildAction-BqdY-x5D.cjs} +3 -7
- package/dist/_chunks/{buildAction-KZkR53RZ.cjs.map → buildAction-BqdY-x5D.cjs.map} +1 -1
- package/dist/_chunks/check-BSN1yLfm.cjs +118 -0
- package/dist/_chunks/check-BSN1yLfm.cjs.map +1 -0
- package/dist/_chunks/{checkAction-B86PejBD.cjs → checkAction-CplEAcgR.cjs} +3 -7
- package/dist/_chunks/{checkAction-B86PejBD.cjs.map → checkAction-CplEAcgR.cjs.map} +1 -1
- package/dist/_chunks/consoleSpy-1_g1SPGc.cjs +369 -0
- package/dist/_chunks/{consoleSpy-DnlN7UBk.cjs.map → consoleSpy-1_g1SPGc.cjs.map} +1 -1
- package/dist/_chunks/handleError-CGQ2DXMR.cjs +11 -0
- package/dist/_chunks/handleError-CGQ2DXMR.cjs.map +1 -0
- package/dist/_chunks/index-Dxhh31D_.cjs +19997 -0
- package/dist/_chunks/{index-RwgAZs-y.cjs.map → index-Dxhh31D_.cjs.map} +1 -1
- package/dist/_chunks/{init-CZQh-Q_y.cjs → init-2mlaoNTF.cjs} +174 -261
- package/dist/_chunks/{init-CZQh-Q_y.cjs.map → init-2mlaoNTF.cjs.map} +1 -1
- package/dist/_chunks/{initAction-BYVnsbAj.cjs → initAction-BlTz_X1p.cjs} +3 -7
- package/dist/_chunks/{initAction-BYVnsbAj.cjs.map → initAction-BlTz_X1p.cjs.map} +1 -1
- package/dist/_chunks/{logger-CpjNjxqG.cjs → logger-CwHVwB-b.cjs} +11 -20
- package/dist/_chunks/logger-CwHVwB-b.cjs.map +1 -0
- package/dist/_chunks/watch-Dqp3kWd_.cjs +156 -0
- package/dist/_chunks/{watch-JoaJL851.cjs.map → watch-Dqp3kWd_.cjs.map} +1 -1
- package/dist/_chunks/{watchAction-DcoHeR8f.cjs → watchAction-4vv-wSLV.cjs} +3 -7
- package/dist/_chunks/{watchAction-DcoHeR8f.cjs.map → watchAction-4vv-wSLV.cjs.map} +1 -1
- package/dist/cli.cjs +18 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +3 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19893 -35944
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/tasks/rollup/resolveRollupConfig.ts +1 -1
- package/dist/_chunks/build-BxYgJfQq.cjs +0 -216
- package/dist/_chunks/check-Do7O9Mjo.cjs +0 -223
- package/dist/_chunks/check-Do7O9Mjo.cjs.map +0 -1
- package/dist/_chunks/consoleSpy-DnlN7UBk.cjs +0 -632
- package/dist/_chunks/handleError-DB8KmYKe.cjs +0 -19
- package/dist/_chunks/handleError-DB8KmYKe.cjs.map +0 -1
- package/dist/_chunks/index-RwgAZs-y.cjs +0 -35564
- package/dist/_chunks/logger-CpjNjxqG.cjs.map +0 -1
- package/dist/_chunks/watch-JoaJL851.cjs +0 -227
|
@@ -1,632 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node = require('esbuild-register/dist/node');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var pkgUp = require('pkg-up');
|
|
6
|
-
var findConfig = require('find-config');
|
|
7
|
-
var logger = require('./logger-CpjNjxqG.cjs');
|
|
8
|
-
var chalk = require('chalk');
|
|
9
|
-
var zod = require('zod');
|
|
10
|
-
var fs = require('fs/promises');
|
|
11
|
-
var browserslist = require('browserslist');
|
|
12
|
-
require('fs');
|
|
13
|
-
var config = require('@sanity/browserslist-config');
|
|
14
|
-
require('mkdirp');
|
|
15
|
-
require('prompts');
|
|
16
|
-
var ts = require('typescript');
|
|
17
|
-
|
|
18
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
19
|
-
|
|
20
|
-
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
21
|
-
var pkgUp__default = /*#__PURE__*/_interopDefaultCompat(pkgUp);
|
|
22
|
-
var findConfig__default = /*#__PURE__*/_interopDefaultCompat(findConfig);
|
|
23
|
-
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
24
|
-
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
25
|
-
var browserslist__default = /*#__PURE__*/_interopDefaultCompat(browserslist);
|
|
26
|
-
var config__default = /*#__PURE__*/_interopDefaultCompat(config);
|
|
27
|
-
var ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
28
|
-
|
|
29
|
-
const CONFIG_FILE_NAMES = [
|
|
30
|
-
"package.config.ts",
|
|
31
|
-
"package.config.js",
|
|
32
|
-
"package.config.cjs",
|
|
33
|
-
"package.config.mjs"
|
|
34
|
-
];
|
|
35
|
-
function findConfigFile(cwd) {
|
|
36
|
-
const pkgJsonPath = findConfig__default.default("package.json", { cwd });
|
|
37
|
-
if (!pkgJsonPath)
|
|
38
|
-
return void 0;
|
|
39
|
-
const pkgPath = path__default.default.dirname(pkgJsonPath);
|
|
40
|
-
for (const fileName of CONFIG_FILE_NAMES) {
|
|
41
|
-
const configPath = path__default.default.resolve(pkgPath, fileName);
|
|
42
|
-
const exists = logger.fileExists(configPath);
|
|
43
|
-
if (exists) {
|
|
44
|
-
return configPath;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return void 0;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function loadConfig(options) {
|
|
51
|
-
const { cwd } = options;
|
|
52
|
-
const pkgPath = await pkgUp__default.default({ cwd });
|
|
53
|
-
if (!pkgPath)
|
|
54
|
-
return void 0;
|
|
55
|
-
const root = path__default.default.dirname(pkgPath);
|
|
56
|
-
const configFile = await findConfigFile(root);
|
|
57
|
-
if (!configFile) {
|
|
58
|
-
return void 0;
|
|
59
|
-
}
|
|
60
|
-
if (!configFile.startsWith(cwd)) {
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
const esbuildOptions = { extensions: [".js", ".mjs", ".ts"] };
|
|
64
|
-
const { unregister } = globalThis.__DEV__ ? { unregister: () => void 0 } : node.register(esbuildOptions);
|
|
65
|
-
const mod = require(configFile);
|
|
66
|
-
unregister();
|
|
67
|
-
return mod?.default || mod || void 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function resolveConfigProperty(prop, initialValue) {
|
|
71
|
-
if (!prop)
|
|
72
|
-
return initialValue;
|
|
73
|
-
if (typeof prop === "function") {
|
|
74
|
-
return prop(initialValue);
|
|
75
|
-
}
|
|
76
|
-
return prop;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const DEFAULT_BROWSERSLIST_QUERY = config__default.default;
|
|
80
|
-
|
|
81
|
-
async function loadPkg(options) {
|
|
82
|
-
const { cwd } = options;
|
|
83
|
-
const pkgPath = await pkgUp__default.default({ cwd });
|
|
84
|
-
if (!pkgPath)
|
|
85
|
-
throw new Error("no package.json found");
|
|
86
|
-
const buf = await fs__default.default.readFile(pkgPath);
|
|
87
|
-
const raw = JSON.parse(buf.toString());
|
|
88
|
-
logger.validatePkg(raw);
|
|
89
|
-
return raw;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function assertFirst(a, arr) {
|
|
93
|
-
const aIdx = arr.indexOf(a);
|
|
94
|
-
if (aIdx === -1) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
return aIdx === 0;
|
|
98
|
-
}
|
|
99
|
-
function assertLast(a, arr) {
|
|
100
|
-
const aIdx = arr.indexOf(a);
|
|
101
|
-
if (aIdx === -1) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
return aIdx === arr.length - 1;
|
|
105
|
-
}
|
|
106
|
-
function assertOrder(a, b, arr) {
|
|
107
|
-
const aIdx = arr.indexOf(a);
|
|
108
|
-
const bIdx = arr.indexOf(b);
|
|
109
|
-
if (aIdx === -1 || bIdx === -1) {
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
return aIdx < bIdx;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function loadPkgWithReporting(options) {
|
|
116
|
-
const { cwd, logger } = options;
|
|
117
|
-
try {
|
|
118
|
-
const pkg = await loadPkg({ cwd });
|
|
119
|
-
let shouldError = false;
|
|
120
|
-
if (pkg.exports) {
|
|
121
|
-
const _exports = Object.entries(pkg.exports);
|
|
122
|
-
for (const [expPath, exp] of _exports) {
|
|
123
|
-
if (typeof exp === "string") {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
const keys = Object.keys(exp);
|
|
127
|
-
if (!assertFirst("types", keys)) {
|
|
128
|
-
shouldError = true;
|
|
129
|
-
logger.error(`exports["${expPath}"]: the \`types\` property should be the first property`);
|
|
130
|
-
}
|
|
131
|
-
if (exp.node) {
|
|
132
|
-
const nodeKeys = Object.keys(exp.node);
|
|
133
|
-
if (!assertOrder("module", "import", nodeKeys)) {
|
|
134
|
-
shouldError = true;
|
|
135
|
-
logger.error(
|
|
136
|
-
`exports["${expPath}"]: the \`node.module\` property should come before the \`node.import\` property`
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
if (!assertOrder("import", "require", nodeKeys)) {
|
|
140
|
-
logger.warn(
|
|
141
|
-
`exports["${expPath}"]: the \`node.import\` property should come before the \`node.require\` property`
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
if (!assertOrder("module", "require", nodeKeys)) {
|
|
145
|
-
logger.warn(
|
|
146
|
-
`exports["${expPath}"]: the \`node.module\` property should come before \`node.require\` property`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
if (exp.import && exp.node.import && !assertOrder("node", "import", keys)) {
|
|
150
|
-
shouldError = true;
|
|
151
|
-
logger.error(
|
|
152
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`import\` property`
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
if (exp.module && exp.node.module && !assertOrder("node", "module", keys)) {
|
|
156
|
-
shouldError = true;
|
|
157
|
-
logger.error(
|
|
158
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`module\` property`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
if (exp.node.import && !exp.node.require && exp.node.module && exp.import && exp.node.module !== exp.import) {
|
|
162
|
-
shouldError = true;
|
|
163
|
-
logger.error(
|
|
164
|
-
`exports["${expPath}"]: the \`node.module\` property should match \`import\``
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
if (exp.require && exp.node.require && exp.require === exp.node.require) {
|
|
168
|
-
shouldError = true;
|
|
169
|
-
logger.error(
|
|
170
|
-
`exports["${expPath}"]: the \`node.require\` property isn't necessary as it's identical to \`require\``
|
|
171
|
-
);
|
|
172
|
-
} else if (exp.require && exp.node.require && !assertOrder("node", "require", keys)) {
|
|
173
|
-
shouldError = true;
|
|
174
|
-
logger.error(
|
|
175
|
-
`exports["${expPath}"]: the \`node\` property should come before the \`require\` property`
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
if (!assertOrder("import", "require", keys)) {
|
|
180
|
-
logger.warn(
|
|
181
|
-
`exports["${expPath}"]: the \`import\` property should come before the \`require\` property`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
if (!assertOrder("module", "import", keys)) {
|
|
185
|
-
logger.warn(
|
|
186
|
-
`exports["${expPath}"]: the \`module\` property should come before \`import\` property`
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (!assertLast("default", keys)) {
|
|
191
|
-
shouldError = true;
|
|
192
|
-
logger.error(
|
|
193
|
-
`exports["${expPath}"]: the \`default\` property should be the last property`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (shouldError) {
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
|
-
return pkg;
|
|
202
|
-
} catch (err) {
|
|
203
|
-
if (err instanceof zod.ZodError) {
|
|
204
|
-
for (const issue of err.issues) {
|
|
205
|
-
if (issue.code === "invalid_type") {
|
|
206
|
-
logger.error(
|
|
207
|
-
[
|
|
208
|
-
`\`${formatPath(issue.path)}\` `,
|
|
209
|
-
`in \`./package.json\` must be of type ${chalk__default.default.magenta(issue.expected)} `,
|
|
210
|
-
`(received ${chalk__default.default.magenta(issue.received)})`
|
|
211
|
-
].join("")
|
|
212
|
-
);
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
logger.error(issue);
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
logger.error(err);
|
|
219
|
-
}
|
|
220
|
-
process.exit(1);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function formatPath(segments) {
|
|
224
|
-
return segments.map((s, idx) => {
|
|
225
|
-
if (idx === 0)
|
|
226
|
-
return s;
|
|
227
|
-
if (typeof s === "number") {
|
|
228
|
-
return `[${s}]`;
|
|
229
|
-
}
|
|
230
|
-
if (s.startsWith(".")) {
|
|
231
|
-
return `["${s}"]`;
|
|
232
|
-
}
|
|
233
|
-
return `.${s}`;
|
|
234
|
-
}).join("");
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function validateExports(_exports, options) {
|
|
238
|
-
const { extMap, pkg } = options;
|
|
239
|
-
const ext = extMap[pkg.type || "commonjs"];
|
|
240
|
-
const errors = [];
|
|
241
|
-
for (const exp of _exports) {
|
|
242
|
-
if (exp.require && !exp.require.endsWith(ext.commonjs)) {
|
|
243
|
-
errors.push(
|
|
244
|
-
`package.json with \`type: "${pkg.type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
if (exp.import && !exp.import.endsWith(ext.esm)) {
|
|
248
|
-
errors.push(
|
|
249
|
-
`package.json with \`type: "${pkg.type}"\` - \`exports["${exp._path}"].import\` must end with "${ext.esm}"`
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return errors;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function parseExports(options) {
|
|
257
|
-
const { extMap, pkg, strict } = options;
|
|
258
|
-
const rootExport = {
|
|
259
|
-
_exported: true,
|
|
260
|
-
_path: ".",
|
|
261
|
-
types: pkg.types,
|
|
262
|
-
source: pkg.source || "",
|
|
263
|
-
browser: pkg.browser && {
|
|
264
|
-
source: pkg.source || "",
|
|
265
|
-
require: pkg.main && pkg.browser[pkg.main],
|
|
266
|
-
import: pkg.module && pkg.browser[pkg.module]
|
|
267
|
-
},
|
|
268
|
-
require: pkg.main,
|
|
269
|
-
import: pkg.module,
|
|
270
|
-
default: pkg.module || pkg.main || ""
|
|
271
|
-
};
|
|
272
|
-
const extraExports = [];
|
|
273
|
-
const errors = [];
|
|
274
|
-
if (pkg.exports) {
|
|
275
|
-
if (strict && !pkg.exports["./package.json"]) {
|
|
276
|
-
errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
277
|
-
}
|
|
278
|
-
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
279
|
-
if (exportPath.endsWith(".json")) {
|
|
280
|
-
if (exportPath === "./package.json") {
|
|
281
|
-
if (exportEntry !== "./package.json") {
|
|
282
|
-
errors.push('package.json: `exports["./package.json"] must be "./package.json".');
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
} else if (logger.isRecord(exportEntry)) {
|
|
286
|
-
if (exportPath === ".") {
|
|
287
|
-
if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require) {
|
|
288
|
-
errors.push(
|
|
289
|
-
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
|
|
293
|
-
errors.push(
|
|
294
|
-
'package.json: mismatch between "module" and "exports.import" These must be equal.'
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
|
|
298
|
-
errors.push(
|
|
299
|
-
'package.json: mismatch between "types" and "exports.types". These must be equal.'
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
|
|
303
|
-
errors.push(
|
|
304
|
-
'package.json: mismatch between "source" and "exports.source". These must be equal.'
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
Object.assign(rootExport, exportEntry);
|
|
308
|
-
} else {
|
|
309
|
-
const extraExport = {
|
|
310
|
-
_exported: true,
|
|
311
|
-
_path: exportPath,
|
|
312
|
-
...exportEntry
|
|
313
|
-
};
|
|
314
|
-
extraExports.push(extraExport);
|
|
315
|
-
}
|
|
316
|
-
} else {
|
|
317
|
-
errors.push("package.json: exports must be an object");
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const _exports = [rootExport, ...extraExports];
|
|
322
|
-
errors.push(...validateExports(_exports, { extMap, pkg }));
|
|
323
|
-
if (errors.length) {
|
|
324
|
-
throw new Error("\n- " + errors.join("\n- "));
|
|
325
|
-
}
|
|
326
|
-
return _exports;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const DEFAULT_PKG_EXT_MAP = {
|
|
330
|
-
// pkg.type: "commonjs"
|
|
331
|
-
commonjs: {
|
|
332
|
-
commonjs: ".js",
|
|
333
|
-
esm: ".mjs"
|
|
334
|
-
},
|
|
335
|
-
// pkg.type: "module"
|
|
336
|
-
module: {
|
|
337
|
-
commonjs: ".cjs",
|
|
338
|
-
esm: ".js"
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
function getPkgExtMap(options) {
|
|
342
|
-
const { legacyExports } = options;
|
|
343
|
-
const ret = { ...DEFAULT_PKG_EXT_MAP };
|
|
344
|
-
if (legacyExports) {
|
|
345
|
-
ret["commonjs"] = {
|
|
346
|
-
commonjs: ".js",
|
|
347
|
-
esm: ".esm.js"
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
return ret;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
async function loadTSConfig(options) {
|
|
354
|
-
const { cwd, tsconfigPath } = options;
|
|
355
|
-
const configPath = ts__default.default.findConfigFile(cwd, ts__default.default.sys.fileExists, tsconfigPath);
|
|
356
|
-
if (!configPath) {
|
|
357
|
-
return void 0;
|
|
358
|
-
}
|
|
359
|
-
const configFile = ts__default.default.readConfigFile(configPath, ts__default.default.sys.readFile);
|
|
360
|
-
return ts__default.default.parseJsonConfigFileContent(configFile.config, ts__default.default.sys, cwd);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// convert the browserslist field in package.json to
|
|
364
|
-
// esbuild compatible array of browsers
|
|
365
|
-
function browserslistToEsbuild(browserslistConfig, options = {}) {
|
|
366
|
-
if (!browserslistConfig) {
|
|
367
|
-
// the path from where the script is run
|
|
368
|
-
const path = process.cwd();
|
|
369
|
-
|
|
370
|
-
// read config if none is passed
|
|
371
|
-
browserslistConfig = browserslist__default.default.loadConfig({ path, ...options });
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const SUPPORTED_ESBUILD_TARGETS = [
|
|
375
|
-
'es',
|
|
376
|
-
'chrome',
|
|
377
|
-
'edge',
|
|
378
|
-
'firefox',
|
|
379
|
-
'ios',
|
|
380
|
-
'node',
|
|
381
|
-
'safari',
|
|
382
|
-
'opera',
|
|
383
|
-
'ie',
|
|
384
|
-
];
|
|
385
|
-
|
|
386
|
-
// https://github.com/eBay/browserslist-config/issues/16#issuecomment-863870093
|
|
387
|
-
const UNSUPPORTED = ['android 4'];
|
|
388
|
-
|
|
389
|
-
const replaces = {
|
|
390
|
-
ios_saf: 'ios',
|
|
391
|
-
android: 'chrome',
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const separator = ' ';
|
|
395
|
-
|
|
396
|
-
return (
|
|
397
|
-
browserslist__default.default(browserslistConfig, options)
|
|
398
|
-
// filter out the unsupported ones
|
|
399
|
-
.filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u)))
|
|
400
|
-
// replaces safari TP with latest safari version
|
|
401
|
-
.map((b) => {
|
|
402
|
-
if (b === 'safari TP') {
|
|
403
|
-
return browserslist__default.default('last 1 safari version')[0]
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return b
|
|
407
|
-
})
|
|
408
|
-
// transform into ['chrome', '88']
|
|
409
|
-
.map((b) => b.split(separator))
|
|
410
|
-
// replace the similar browser
|
|
411
|
-
.map((b) => {
|
|
412
|
-
if (replaces[b[0]]) {
|
|
413
|
-
b[0] = replaces[b[0]];
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return b
|
|
417
|
-
})
|
|
418
|
-
// 11.0-12.0 --> 11.0
|
|
419
|
-
.map((b) => {
|
|
420
|
-
if (b[1].includes('-')) {
|
|
421
|
-
b[1] = b[1].slice(0, b[1].indexOf('-'));
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return b
|
|
425
|
-
})
|
|
426
|
-
// 11.0 --> 11
|
|
427
|
-
.map((b) => {
|
|
428
|
-
if (b[1].endsWith('.0')) {
|
|
429
|
-
b[1] = b[1].slice(0, -2);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
return b
|
|
433
|
-
})
|
|
434
|
-
// removes invalid versions that will break esbuild
|
|
435
|
-
// https://github.com/evanw/esbuild/blob/35c0d65b9d4f29a26176404d2890d1b499634e9f/compat-table/src/caniuse.ts#L119-L122
|
|
436
|
-
.filter((b) => /^\d+(\.\d+)*$/.test(b[1]))
|
|
437
|
-
// only get the targets supported by esbuild
|
|
438
|
-
.filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0]))
|
|
439
|
-
// only get the oldest version, assuming that the older version
|
|
440
|
-
// is last in the array
|
|
441
|
-
.reduce((acc, b) => {
|
|
442
|
-
const existingIndex = acc.findIndex((br) => br[0] === b[0]);
|
|
443
|
-
|
|
444
|
-
if (existingIndex !== -1) {
|
|
445
|
-
acc[existingIndex][1] = b[1];
|
|
446
|
-
} else {
|
|
447
|
-
acc.push(b);
|
|
448
|
-
}
|
|
449
|
-
return acc
|
|
450
|
-
}, [])
|
|
451
|
-
// remove separator
|
|
452
|
-
.map((b) => b.join(''))
|
|
453
|
-
)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function pathContains(containerPath, itemPath) {
|
|
457
|
-
return !path__default.default.relative(containerPath, itemPath).startsWith("..");
|
|
458
|
-
}
|
|
459
|
-
function findCommonDirPath(filePaths) {
|
|
460
|
-
let ret = void 0;
|
|
461
|
-
for (const filePath of filePaths) {
|
|
462
|
-
let dirPath = path__default.default.dirname(filePath);
|
|
463
|
-
if (!ret) {
|
|
464
|
-
ret = dirPath;
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
while (dirPath !== ret) {
|
|
468
|
-
dirPath = path__default.default.dirname(dirPath);
|
|
469
|
-
if (dirPath === ret) {
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
if (pathContains(dirPath, ret)) {
|
|
473
|
-
ret = dirPath;
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
if (dirPath === ".")
|
|
477
|
-
return void 0;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return ret;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function resolveBrowserTarget(versions) {
|
|
484
|
-
const target = versions.filter(
|
|
485
|
-
(version) => version.startsWith("chrome") || version.startsWith("edge") || version.startsWith("firefox") || version.startsWith("ios") || version.startsWith("safari") || version.startsWith("opera")
|
|
486
|
-
);
|
|
487
|
-
if (target.length === 0) {
|
|
488
|
-
return void 0;
|
|
489
|
-
}
|
|
490
|
-
return target;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function resolveNodeTarget(versions) {
|
|
494
|
-
const target = versions.filter((version) => version.startsWith("node"));
|
|
495
|
-
if (target.length === 0) {
|
|
496
|
-
return void 0;
|
|
497
|
-
}
|
|
498
|
-
return target;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
async function resolveBuildContext(options) {
|
|
502
|
-
const {
|
|
503
|
-
config,
|
|
504
|
-
cwd,
|
|
505
|
-
emitDeclarationOnly = false,
|
|
506
|
-
extMap,
|
|
507
|
-
logger,
|
|
508
|
-
pkg,
|
|
509
|
-
strict,
|
|
510
|
-
tsconfig: tsconfigPath
|
|
511
|
-
} = options;
|
|
512
|
-
const tsconfig = await loadTSConfig({ cwd, tsconfigPath });
|
|
513
|
-
let browserslist = pkg.browserslist;
|
|
514
|
-
if (strict && !browserslist) {
|
|
515
|
-
logger.warn(
|
|
516
|
-
'Could not detect a `browserslist` property in `package.json`, using default configuration. Add `"browserslist": "extends @sanity/browserslist-config"` to silence this warning.'
|
|
517
|
-
);
|
|
518
|
-
browserslist = DEFAULT_BROWSERSLIST_QUERY;
|
|
519
|
-
}
|
|
520
|
-
const targetVersions = browserslistToEsbuild(browserslist);
|
|
521
|
-
if (strict && typeof pkg.sideEffects === "undefined") {
|
|
522
|
-
logger.error(
|
|
523
|
-
'No `sideEffects` field in `package.json`, assuming all files are side-effectful. Add `"sideEffects": true` to silence this warning. See https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects for how to define `sideEffects`.'
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
const nodeTarget = resolveNodeTarget(targetVersions);
|
|
527
|
-
const webTarget = resolveBrowserTarget(targetVersions);
|
|
528
|
-
if (!nodeTarget) {
|
|
529
|
-
throw new Error("no matching `node` target");
|
|
530
|
-
}
|
|
531
|
-
if (!webTarget) {
|
|
532
|
-
throw new Error("no matching `web` target");
|
|
533
|
-
}
|
|
534
|
-
const target = {
|
|
535
|
-
"*": webTarget.concat(nodeTarget),
|
|
536
|
-
"browser": webTarget,
|
|
537
|
-
"node": nodeTarget
|
|
538
|
-
};
|
|
539
|
-
const parsedExports = parseExports({ extMap, pkg, strict }).reduce((acc, x) => {
|
|
540
|
-
const { _path: exportPath, ...exportEntry } = x;
|
|
541
|
-
return { ...acc, [exportPath]: exportEntry };
|
|
542
|
-
}, {});
|
|
543
|
-
const exports = resolveConfigProperty(config?.exports, parsedExports);
|
|
544
|
-
const parsedExternal = [
|
|
545
|
-
...pkg.dependencies ? Object.keys(pkg.dependencies) : [],
|
|
546
|
-
...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []
|
|
547
|
-
];
|
|
548
|
-
const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config?.external, parsedExternal);
|
|
549
|
-
const outputPaths = Object.values(exports).flatMap((exportEntry) => {
|
|
550
|
-
return [
|
|
551
|
-
exportEntry.import,
|
|
552
|
-
exportEntry.require,
|
|
553
|
-
exportEntry.browser?.import,
|
|
554
|
-
exportEntry.browser?.require,
|
|
555
|
-
exportEntry.node?.source && exportEntry.node.import,
|
|
556
|
-
exportEntry.node?.source && exportEntry.node.require
|
|
557
|
-
].filter(Boolean);
|
|
558
|
-
}).map((p) => path__default.default.resolve(cwd, p));
|
|
559
|
-
const commonDistPath = findCommonDirPath(outputPaths);
|
|
560
|
-
if (commonDistPath === cwd) {
|
|
561
|
-
throw new Error(
|
|
562
|
-
"all output files must share a common parent directory which is not the root package directory"
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
if (commonDistPath && !pathContains(cwd, commonDistPath)) {
|
|
566
|
-
throw new Error("all output files must be located within the package");
|
|
567
|
-
}
|
|
568
|
-
const configDistPath = config?.dist ? path__default.default.resolve(cwd, config.dist) : void 0;
|
|
569
|
-
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath)) {
|
|
570
|
-
logger.log(`did you mean to configure \`dist: './${path__default.default.relative(cwd, commonDistPath)}'\`?`);
|
|
571
|
-
throw new Error("all output files must be located with the configured `dist` path");
|
|
572
|
-
}
|
|
573
|
-
const distPath = configDistPath || commonDistPath;
|
|
574
|
-
if (!distPath) {
|
|
575
|
-
throw new Error("could not detect `dist` path");
|
|
576
|
-
}
|
|
577
|
-
const ctx = {
|
|
578
|
-
config,
|
|
579
|
-
cwd,
|
|
580
|
-
distPath,
|
|
581
|
-
emitDeclarationOnly,
|
|
582
|
-
exports,
|
|
583
|
-
external,
|
|
584
|
-
extMap,
|
|
585
|
-
files: [],
|
|
586
|
-
logger,
|
|
587
|
-
pkg,
|
|
588
|
-
runtime: config?.runtime ?? "*",
|
|
589
|
-
strict,
|
|
590
|
-
target,
|
|
591
|
-
ts: {
|
|
592
|
-
config: tsconfig,
|
|
593
|
-
configPath: tsconfigPath
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
return ctx;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function createConsoleSpy(options) {
|
|
600
|
-
const { onRestored } = options || {};
|
|
601
|
-
const original = {
|
|
602
|
-
log: console.log,
|
|
603
|
-
warn: console.warn,
|
|
604
|
-
error: console.error
|
|
605
|
-
};
|
|
606
|
-
const messages = [];
|
|
607
|
-
console.log = (...args) => messages.push({ type: "log", args });
|
|
608
|
-
console.warn = (...args) => messages.push({ type: "warn", args });
|
|
609
|
-
console.error = (...args) => messages.push({ type: "error", args });
|
|
610
|
-
return {
|
|
611
|
-
messages,
|
|
612
|
-
restore: () => {
|
|
613
|
-
console.log = original.log;
|
|
614
|
-
console.warn = original.warn;
|
|
615
|
-
console.error = original.error;
|
|
616
|
-
onRestored?.(messages);
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
exports.DEFAULT_BROWSERSLIST_QUERY = DEFAULT_BROWSERSLIST_QUERY;
|
|
622
|
-
exports.DEFAULT_PKG_EXT_MAP = DEFAULT_PKG_EXT_MAP;
|
|
623
|
-
exports.createConsoleSpy = createConsoleSpy;
|
|
624
|
-
exports.getPkgExtMap = getPkgExtMap;
|
|
625
|
-
exports.loadConfig = loadConfig;
|
|
626
|
-
exports.loadPkg = loadPkg;
|
|
627
|
-
exports.loadPkgWithReporting = loadPkgWithReporting;
|
|
628
|
-
exports.loadTSConfig = loadTSConfig;
|
|
629
|
-
exports.parseExports = parseExports;
|
|
630
|
-
exports.resolveBuildContext = resolveBuildContext;
|
|
631
|
-
exports.resolveConfigProperty = resolveConfigProperty;
|
|
632
|
-
//# sourceMappingURL=consoleSpy-DnlN7UBk.cjs.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chalk = require('chalk');
|
|
4
|
-
|
|
5
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
-
|
|
7
|
-
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
8
|
-
|
|
9
|
-
function handleError(err) {
|
|
10
|
-
if (err instanceof Error) {
|
|
11
|
-
console.error(chalk__default.default.red("error"), err.message);
|
|
12
|
-
} else {
|
|
13
|
-
console.error(err);
|
|
14
|
-
}
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.handleError = handleError;
|
|
19
|
-
//# sourceMappingURL=handleError-DB8KmYKe.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleError-DB8KmYKe.cjs","sources":["../../src/cli/handleError.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function handleError(err: unknown): void {\n if (err instanceof Error) {\n console.error(chalk.red('error'), err.message)\n } else {\n console.error(err)\n }\n\n process.exit(1)\n}\n"],"names":["chalk"],"mappings":";;;;;;;;AAIO,SAAS,YAAY,GAAoB,EAAA;AAC9C,EAAA,IAAI,eAAe,KAAO,EAAA;AACxB,IAAA,OAAA,CAAQ,MAAMA,sBAAM,CAAA,GAAA,CAAI,OAAO,CAAA,EAAG,IAAI,OAAO,CAAA,CAAA;AAAA,GACxC,MAAA;AACL,IAAA,OAAA,CAAQ,MAAM,GAAG,CAAA,CAAA;AAAA,GACnB;AAEA,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAChB;;;;"}
|