@sanity/pkg-utils 3.3.8 → 4.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.
Files changed (44) hide show
  1. package/dist/_chunks/{build-7mn5THX6.cjs → build-xtvcN4rn.cjs} +50 -61
  2. package/dist/_chunks/build-xtvcN4rn.cjs.map +1 -0
  3. package/dist/_chunks/{buildAction-fRHTIDmx.cjs → buildAction-lOl6hAY8.cjs} +5 -3
  4. package/dist/_chunks/{buildAction-fRHTIDmx.cjs.map → buildAction-lOl6hAY8.cjs.map} +1 -1
  5. package/dist/_chunks/check-5On74q2h.cjs +222 -0
  6. package/dist/_chunks/check-5On74q2h.cjs.map +1 -0
  7. package/dist/_chunks/{checkAction-0xA1q64g.cjs → checkAction-RYG9-Wqo.cjs} +5 -3
  8. package/dist/_chunks/checkAction-RYG9-Wqo.cjs.map +1 -0
  9. package/dist/_chunks/{consoleSpy-g4ZadSyB.cjs → consoleSpy-bV4ZI2h8.cjs} +181 -179
  10. package/dist/_chunks/{consoleSpy-g4ZadSyB.cjs.map → consoleSpy-bV4ZI2h8.cjs.map} +1 -1
  11. package/dist/_chunks/{handleError-esTdSrHu.cjs → handleError-fVK262CU.cjs} +6 -6
  12. package/dist/_chunks/handleError-fVK262CU.cjs.map +1 -0
  13. package/dist/_chunks/index-YSy1xob6.cjs +36038 -0
  14. package/dist/_chunks/{index-1Mfz_QDA.cjs.map → index-YSy1xob6.cjs.map} +1 -1
  15. package/dist/_chunks/init-tT7f7xkO.cjs +646 -0
  16. package/dist/_chunks/{init-U-HiL7BD.cjs.map → init-tT7f7xkO.cjs.map} +1 -1
  17. package/dist/_chunks/{initAction-QVQEhQh6.cjs → initAction-zkJJWu4U.cjs} +5 -3
  18. package/dist/_chunks/initAction-zkJJWu4U.cjs.map +1 -0
  19. package/dist/_chunks/{logger-iA0nC-kL.cjs → logger-c-JGqYo_.cjs} +45 -43
  20. package/dist/_chunks/logger-c-JGqYo_.cjs.map +1 -0
  21. package/dist/_chunks/watch-Mo2KRBJf.cjs +226 -0
  22. package/dist/_chunks/watch-Mo2KRBJf.cjs.map +1 -0
  23. package/dist/_chunks/{watchAction-JfAFOHP0.cjs → watchAction-7JsrPTEX.cjs} +5 -3
  24. package/dist/_chunks/watchAction-7JsrPTEX.cjs.map +1 -0
  25. package/dist/cli.cjs +14 -30
  26. package/dist/cli.cjs.map +1 -1
  27. package/dist/index.cjs +11 -10
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +37229 -1530
  30. package/dist/index.js.map +1 -1
  31. package/package.json +14 -15
  32. package/src/node/tasks/rollup/resolveRollupConfig.ts +6 -11
  33. package/dist/_chunks/build-7mn5THX6.cjs.map +0 -1
  34. package/dist/_chunks/check-pxYRC97N.cjs +0 -250
  35. package/dist/_chunks/check-pxYRC97N.cjs.map +0 -1
  36. package/dist/_chunks/checkAction-0xA1q64g.cjs.map +0 -1
  37. package/dist/_chunks/handleError-esTdSrHu.cjs.map +0 -1
  38. package/dist/_chunks/index-1Mfz_QDA.cjs +0 -2159
  39. package/dist/_chunks/init-U-HiL7BD.cjs +0 -500
  40. package/dist/_chunks/initAction-QVQEhQh6.cjs.map +0 -1
  41. package/dist/_chunks/logger-iA0nC-kL.cjs.map +0 -1
  42. package/dist/_chunks/watch-6xc8QXJF.cjs +0 -233
  43. package/dist/_chunks/watch-6xc8QXJF.cjs.map +0 -1
  44. package/dist/_chunks/watchAction-JfAFOHP0.cjs.map +0 -1
@@ -4,7 +4,7 @@ var node = require('esbuild-register/dist/node');
4
4
  var path = require('path');
5
5
  var pkgUp = require('pkg-up');
6
6
  var findConfig = require('find-config');
7
- var logger = require('./logger-iA0nC-kL.cjs');
7
+ var logger = require('./logger-c-JGqYo_.cjs');
8
8
  var chalk = require('chalk');
9
9
  var zod = require('zod');
10
10
  var fs = require('fs/promises');
@@ -13,11 +13,9 @@ require('mkdirp');
13
13
  require('prompts');
14
14
  var ts = require('typescript');
15
15
  var browserslist = require('browserslist');
16
- function _interopDefaultCompat(e) {
17
- return e && typeof e === 'object' && 'default' in e ? e : {
18
- default: e
19
- };
20
- }
16
+
17
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
18
+
21
19
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
22
20
  var pkgUp__default = /*#__PURE__*/_interopDefaultCompat(pkgUp);
23
21
  var findConfig__default = /*#__PURE__*/_interopDefaultCompat(findConfig);
@@ -25,12 +23,17 @@ var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
25
23
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
26
24
  var ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
27
25
  var browserslist__default = /*#__PURE__*/_interopDefaultCompat(browserslist);
28
- const CONFIG_FILE_NAMES = ["package.config.ts", "package.config.js", "package.config.cjs", "package.config.mjs"];
26
+
27
+ const CONFIG_FILE_NAMES = [
28
+ "package.config.ts",
29
+ "package.config.js",
30
+ "package.config.cjs",
31
+ "package.config.mjs"
32
+ ];
29
33
  function findConfigFile(cwd) {
30
- const pkgJsonPath = findConfig__default.default("package.json", {
31
- cwd
32
- });
33
- if (!pkgJsonPath) return void 0;
34
+ const pkgJsonPath = findConfig__default.default("package.json", { cwd });
35
+ if (!pkgJsonPath)
36
+ return void 0;
34
37
  const pkgPath = path__default.default.dirname(pkgJsonPath);
35
38
  for (const fileName of CONFIG_FILE_NAMES) {
36
39
  const configPath = path__default.default.resolve(pkgPath, fileName);
@@ -41,14 +44,12 @@ function findConfigFile(cwd) {
41
44
  }
42
45
  return void 0;
43
46
  }
47
+
44
48
  async function loadConfig(options) {
45
- const {
46
- cwd
47
- } = options;
48
- const pkgPath = await pkgUp__default.default({
49
- cwd
50
- });
51
- if (!pkgPath) return void 0;
49
+ const { cwd } = options;
50
+ const pkgPath = await pkgUp__default.default({ cwd });
51
+ if (!pkgPath)
52
+ return void 0;
52
53
  const root = path__default.default.dirname(pkgPath);
53
54
  const configFile = await findConfigFile(root);
54
55
  if (!configFile) {
@@ -57,39 +58,40 @@ async function loadConfig(options) {
57
58
  if (!configFile.startsWith(cwd)) {
58
59
  return void 0;
59
60
  }
60
- const esbuildOptions = {
61
- extensions: [".js", ".mjs", ".ts"]
62
- };
63
- const {
64
- unregister
65
- } = globalThis.__DEV__ ? {
66
- unregister: () => void 0
67
- } : node.register(esbuildOptions);
61
+ const esbuildOptions = { extensions: [".js", ".mjs", ".ts"] };
62
+ const { unregister } = globalThis.__DEV__ ? { unregister: () => void 0 } : node.register(esbuildOptions);
68
63
  const mod = require(configFile);
69
64
  unregister();
70
- return (mod === null || mod === void 0 ? void 0 : mod.default) || mod || void 0;
65
+ return mod?.default || mod || void 0;
71
66
  }
67
+
72
68
  function resolveConfigProperty(prop, initialValue) {
73
- if (!prop) return initialValue;
69
+ if (!prop)
70
+ return initialValue;
74
71
  if (typeof prop === "function") {
75
72
  return prop(initialValue);
76
73
  }
77
74
  return prop;
78
75
  }
79
- const DEFAULT_BROWSERSLIST_QUERY = ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"];
76
+
77
+ const DEFAULT_BROWSERSLIST_QUERY = [
78
+ "> 0.2% and supports es6-module and supports es6-module-dynamic-import",
79
+ "not dead",
80
+ "not IE 11",
81
+ "maintained node versions"
82
+ ];
83
+
80
84
  async function loadPkg(options) {
81
- const {
82
- cwd
83
- } = options;
84
- const pkgPath = await pkgUp__default.default({
85
- cwd
86
- });
87
- if (!pkgPath) throw new Error("no package.json found");
85
+ const { cwd } = options;
86
+ const pkgPath = await pkgUp__default.default({ cwd });
87
+ if (!pkgPath)
88
+ throw new Error("no package.json found");
88
89
  const buf = await fs__default.default.readFile(pkgPath);
89
90
  const raw = JSON.parse(buf.toString());
90
91
  logger.validatePkg(raw);
91
92
  return raw;
92
93
  }
94
+
93
95
  function assertFirst(a, arr) {
94
96
  const aIdx = arr.indexOf(a);
95
97
  if (aIdx === -1) {
@@ -112,15 +114,11 @@ function assertOrder(a, b, arr) {
112
114
  }
113
115
  return aIdx < bIdx;
114
116
  }
117
+
115
118
  async function loadPkgWithReporting(options) {
116
- const {
117
- cwd,
118
- logger
119
- } = options;
119
+ const { cwd, logger } = options;
120
120
  try {
121
- const pkg = await loadPkg({
122
- cwd
123
- });
121
+ const pkg = await loadPkg({ cwd });
124
122
  let shouldError = false;
125
123
  if (pkg.exports) {
126
124
  const _exports = Object.entries(pkg.exports);
@@ -131,50 +129,72 @@ async function loadPkgWithReporting(options) {
131
129
  const keys = Object.keys(exp);
132
130
  if (!assertFirst("types", keys)) {
133
131
  shouldError = true;
134
- logger.error("exports[\"".concat(expPath, "\"]: the `types` property should be the first property"));
132
+ logger.error(`exports["${expPath}"]: the \`types\` property should be the first property`);
135
133
  }
136
134
  if (exp.node) {
137
135
  const nodeKeys = Object.keys(exp.node);
138
136
  if (!assertOrder("module", "import", nodeKeys)) {
139
137
  shouldError = true;
140
- logger.error("exports[\"".concat(expPath, "\"]: the `node.module` property should come before the `node.import` property"));
138
+ logger.error(
139
+ `exports["${expPath}"]: the \`node.module\` property should come before the \`node.import\` property`
140
+ );
141
141
  }
142
142
  if (!assertOrder("import", "require", nodeKeys)) {
143
- logger.warn("exports[\"".concat(expPath, "\"]: the `node.import` property should come before the `node.require` property"));
143
+ logger.warn(
144
+ `exports["${expPath}"]: the \`node.import\` property should come before the \`node.require\` property`
145
+ );
144
146
  }
145
147
  if (!assertOrder("module", "require", nodeKeys)) {
146
- logger.warn("exports[\"".concat(expPath, "\"]: the `node.module` property should come before `node.require` property"));
148
+ logger.warn(
149
+ `exports["${expPath}"]: the \`node.module\` property should come before \`node.require\` property`
150
+ );
147
151
  }
148
152
  if (exp.import && exp.node.import && !assertOrder("node", "import", keys)) {
149
153
  shouldError = true;
150
- logger.error("exports[\"".concat(expPath, "\"]: the `node` property should come before the `import` property"));
154
+ logger.error(
155
+ `exports["${expPath}"]: the \`node\` property should come before the \`import\` property`
156
+ );
151
157
  }
152
158
  if (exp.module && exp.node.module && !assertOrder("node", "module", keys)) {
153
159
  shouldError = true;
154
- logger.error("exports[\"".concat(expPath, "\"]: the `node` property should come before the `module` property"));
160
+ logger.error(
161
+ `exports["${expPath}"]: the \`node\` property should come before the \`module\` property`
162
+ );
155
163
  }
156
164
  if (exp.node.import && !exp.node.require && exp.node.module && exp.import && exp.node.module !== exp.import) {
157
165
  shouldError = true;
158
- logger.error("exports[\"".concat(expPath, "\"]: the `node.module` property should match `import`"));
166
+ logger.error(
167
+ `exports["${expPath}"]: the \`node.module\` property should match \`import\``
168
+ );
159
169
  }
160
170
  if (exp.require && exp.node.require && exp.require === exp.node.require) {
161
171
  shouldError = true;
162
- logger.error("exports[\"".concat(expPath, "\"]: the `node.require` property isn't necessary as it's identical to `require`"));
172
+ logger.error(
173
+ `exports["${expPath}"]: the \`node.require\` property isn't necessary as it's identical to \`require\``
174
+ );
163
175
  } else if (exp.require && exp.node.require && !assertOrder("node", "require", keys)) {
164
176
  shouldError = true;
165
- logger.error("exports[\"".concat(expPath, "\"]: the `node` property should come before the `require` property"));
177
+ logger.error(
178
+ `exports["${expPath}"]: the \`node\` property should come before the \`require\` property`
179
+ );
166
180
  }
167
181
  } else {
168
182
  if (!assertOrder("import", "require", keys)) {
169
- logger.warn("exports[\"".concat(expPath, "\"]: the `import` property should come before the `require` property"));
183
+ logger.warn(
184
+ `exports["${expPath}"]: the \`import\` property should come before the \`require\` property`
185
+ );
170
186
  }
171
187
  if (!assertOrder("module", "import", keys)) {
172
- logger.warn("exports[\"".concat(expPath, "\"]: the `module` property should come before `import` property"));
188
+ logger.warn(
189
+ `exports["${expPath}"]: the \`module\` property should come before \`import\` property`
190
+ );
173
191
  }
174
192
  }
175
193
  if (!assertLast("default", keys)) {
176
194
  shouldError = true;
177
- logger.error("exports[\"".concat(expPath, "\"]: the `default` property should be the last property"));
195
+ logger.error(
196
+ `exports["${expPath}"]: the \`default\` property should be the last property`
197
+ );
178
198
  }
179
199
  }
180
200
  }
@@ -186,7 +206,13 @@ async function loadPkgWithReporting(options) {
186
206
  if (err instanceof zod.ZodError) {
187
207
  for (const issue of err.issues) {
188
208
  if (issue.code === "invalid_type") {
189
- logger.error(["`".concat(formatPath(issue.path), "` "), "in `./package.json` must be of type ".concat(chalk__default.default.magenta(issue.expected), " "), "(received ".concat(chalk__default.default.magenta(issue.received), ")")].join(""));
209
+ logger.error(
210
+ [
211
+ `\`${formatPath(issue.path)}\` `,
212
+ `in \`./package.json\` must be of type ${chalk__default.default.magenta(issue.expected)} `,
213
+ `(received ${chalk__default.default.magenta(issue.received)})`
214
+ ].join("")
215
+ );
190
216
  continue;
191
217
  }
192
218
  logger.error(issue);
@@ -199,39 +225,39 @@ async function loadPkgWithReporting(options) {
199
225
  }
200
226
  function formatPath(segments) {
201
227
  return segments.map((s, idx) => {
202
- if (idx === 0) return s;
228
+ if (idx === 0)
229
+ return s;
203
230
  if (typeof s === "number") {
204
- return "[".concat(s, "]");
231
+ return `[${s}]`;
205
232
  }
206
233
  if (s.startsWith(".")) {
207
- return "[\"".concat(s, "\"]");
234
+ return `["${s}"]`;
208
235
  }
209
- return ".".concat(s);
236
+ return `.${s}`;
210
237
  }).join("");
211
238
  }
239
+
212
240
  function validateExports(_exports, options) {
213
- const {
214
- extMap,
215
- pkg
216
- } = options;
241
+ const { extMap, pkg } = options;
217
242
  const ext = extMap[pkg.type || "commonjs"];
218
243
  const errors = [];
219
244
  for (const exp of _exports) {
220
245
  if (exp.require && !exp.require.endsWith(ext.commonjs)) {
221
- errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].require` must end with \"").concat(ext.commonjs, "\""));
246
+ errors.push(
247
+ `package.json with \`type: "${pkg.type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`
248
+ );
222
249
  }
223
250
  if (exp.import && !exp.import.endsWith(ext.esm)) {
224
- errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].import` must end with \"").concat(ext.esm, "\""));
251
+ errors.push(
252
+ `package.json with \`type: "${pkg.type}"\` - \`exports["${exp._path}"].import\` must end with "${ext.esm}"`
253
+ );
225
254
  }
226
255
  }
227
256
  return errors;
228
257
  }
258
+
229
259
  function parseExports(options) {
230
- const {
231
- extMap,
232
- pkg,
233
- strict
234
- } = options;
260
+ const { extMap, pkg, strict } = options;
235
261
  const rootExport = {
236
262
  _exported: true,
237
263
  _path: ".",
@@ -262,16 +288,24 @@ function parseExports(options) {
262
288
  } else if (logger.isRecord(exportEntry)) {
263
289
  if (exportPath === ".") {
264
290
  if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require) {
265
- errors.push('package.json: mismatch between "main" and "exports.require". These must be equal.');
291
+ errors.push(
292
+ 'package.json: mismatch between "main" and "exports.require". These must be equal.'
293
+ );
266
294
  }
267
295
  if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
268
- errors.push('package.json: mismatch between "module" and "exports.import" These must be equal.');
296
+ errors.push(
297
+ 'package.json: mismatch between "module" and "exports.import" These must be equal.'
298
+ );
269
299
  }
270
300
  if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
271
- errors.push('package.json: mismatch between "types" and "exports.types". These must be equal.');
301
+ errors.push(
302
+ 'package.json: mismatch between "types" and "exports.types". These must be equal.'
303
+ );
272
304
  }
273
305
  if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
274
- errors.push('package.json: mismatch between "source" and "exports.source". These must be equal.');
306
+ errors.push(
307
+ 'package.json: mismatch between "source" and "exports.source". These must be equal.'
308
+ );
275
309
  }
276
310
  Object.assign(rootExport, exportEntry);
277
311
  } else {
@@ -288,15 +322,13 @@ function parseExports(options) {
288
322
  }
289
323
  }
290
324
  const _exports = [rootExport, ...extraExports];
291
- errors.push(...validateExports(_exports, {
292
- extMap,
293
- pkg
294
- }));
325
+ errors.push(...validateExports(_exports, { extMap, pkg }));
295
326
  if (errors.length) {
296
327
  throw new Error("\n- " + errors.join("\n- "));
297
328
  }
298
329
  return _exports;
299
330
  }
331
+
300
332
  const DEFAULT_PKG_EXT_MAP = {
301
333
  // pkg.type: "commonjs"
302
334
  commonjs: {
@@ -310,12 +342,8 @@ const DEFAULT_PKG_EXT_MAP = {
310
342
  }
311
343
  };
312
344
  function getPkgExtMap(options) {
313
- const {
314
- legacyExports
315
- } = options;
316
- const ret = {
317
- ...DEFAULT_PKG_EXT_MAP
318
- };
345
+ const { legacyExports } = options;
346
+ const ret = { ...DEFAULT_PKG_EXT_MAP };
319
347
  if (legacyExports) {
320
348
  ret["commonjs"] = {
321
349
  commonjs: ".js",
@@ -324,11 +352,9 @@ function getPkgExtMap(options) {
324
352
  }
325
353
  return ret;
326
354
  }
355
+
327
356
  async function loadTSConfig(options) {
328
- const {
329
- cwd,
330
- tsconfigPath
331
- } = options;
357
+ const { cwd, tsconfigPath } = options;
332
358
  const configPath = ts__default.default.findConfigFile(cwd, ts__default.default.sys.fileExists, tsconfigPath);
333
359
  if (!configPath) {
334
360
  return void 0;
@@ -336,6 +362,7 @@ async function loadTSConfig(options) {
336
362
  const configFile = ts__default.default.readConfigFile(configPath, ts__default.default.sys.readFile);
337
363
  return ts__default.default.parseJsonConfigFileContent(configFile.config, ts__default.default.sys, cwd);
338
364
  }
365
+
339
366
  function pathContains(containerPath, itemPath) {
340
367
  return !path__default.default.relative(containerPath, itemPath).startsWith("..");
341
368
  }
@@ -356,11 +383,13 @@ function findCommonDirPath(filePaths) {
356
383
  ret = dirPath;
357
384
  break;
358
385
  }
359
- if (dirPath === ".") return void 0;
386
+ if (dirPath === ".")
387
+ return void 0;
360
388
  }
361
389
  }
362
390
  return ret;
363
391
  }
392
+
364
393
  function sortAsNumber(a, b) {
365
394
  const aVersion = Number(a);
366
395
  const bVersion = Number(b);
@@ -368,30 +397,27 @@ function sortAsNumber(a, b) {
368
397
  }
369
398
  function resolveBrowserslistVersions(query) {
370
399
  const result = browserslist__default.default(query);
371
- const entries = result.map(key => {
400
+ const entries = result.map((key) => {
372
401
  const [name, version] = key.split(" ");
373
- return {
374
- name,
375
- version: version.split("-")[0].split(".")[0]
376
- };
402
+ return { name, version: version.split("-")[0].split(".")[0] };
377
403
  });
378
- const andChr = entries.filter(b => b.name === "and_chr");
379
- const andFf = entries.filter(b => b.name === "and_ff");
380
- const chrome = entries.filter(b => b.name === "chrome");
381
- const edge = entries.filter(b => b.name === "edge");
382
- const ff = entries.filter(b => b.name === "firefox");
383
- const iosSaf = entries.filter(b => b.name === "ios_saf");
384
- const saf = entries.filter(b => b.name === "safari");
385
- const opera = entries.filter(b => b.name === "opera");
386
- const node = entries.filter(b => b.name === "node");
404
+ const andChr = entries.filter((b) => b.name === "and_chr");
405
+ const andFf = entries.filter((b) => b.name === "and_ff");
406
+ const chrome = entries.filter((b) => b.name === "chrome");
407
+ const edge = entries.filter((b) => b.name === "edge");
408
+ const ff = entries.filter((b) => b.name === "firefox");
409
+ const iosSaf = entries.filter((b) => b.name === "ios_saf");
410
+ const saf = entries.filter((b) => b.name === "safari");
411
+ const opera = entries.filter((b) => b.name === "opera");
412
+ const node = entries.filter((b) => b.name === "node");
387
413
  const versions = {
388
- chrome: andChr.concat(chrome).map(b => b.version),
389
- ff: andFf.concat(ff).map(b => b.version),
390
- edge: edge.map(b => b.version),
391
- iosSaf: iosSaf.map(b => b.version),
392
- saf: saf.map(b => b.version),
393
- opera: opera.map(b => b.version),
394
- node: node.map(b => b.version)
414
+ chrome: andChr.concat(chrome).map((b) => b.version),
415
+ ff: andFf.concat(ff).map((b) => b.version),
416
+ edge: edge.map((b) => b.version),
417
+ iosSaf: iosSaf.map((b) => b.version),
418
+ saf: saf.map((b) => b.version),
419
+ opera: opera.map((b) => b.version),
420
+ node: node.map((b) => b.version)
395
421
  };
396
422
  versions.chrome.sort(sortAsNumber);
397
423
  versions.ff.sort(sortAsNumber);
@@ -402,43 +428,45 @@ function resolveBrowserslistVersions(query) {
402
428
  versions.node.sort(sortAsNumber);
403
429
  return versions;
404
430
  }
431
+
405
432
  function resolveBrowserTarget(versions) {
406
433
  const target = [];
407
434
  if (versions.chrome.length) {
408
- target.push("chrome".concat(versions.chrome[0]));
435
+ target.push(`chrome${versions.chrome[0]}`);
409
436
  }
410
437
  if (versions.ff.length) {
411
- target.push("firefox".concat(versions.ff[0]));
438
+ target.push(`firefox${versions.ff[0]}`);
412
439
  }
413
440
  if (versions.edge.length) {
414
- target.push("edge".concat(versions.edge[0]));
441
+ target.push(`edge${versions.edge[0]}`);
415
442
  }
416
443
  if (versions.iosSaf.length) {
417
- target.push("ios".concat(versions.iosSaf[0]));
444
+ target.push(`ios${versions.iosSaf[0]}`);
418
445
  }
419
446
  if (versions.saf.length) {
420
- target.push("safari".concat(versions.saf[0]));
447
+ target.push(`safari${versions.saf[0]}`);
421
448
  }
422
449
  if (versions.opera.length) {
423
- target.push("opera".concat(versions.opera[0]));
450
+ target.push(`opera${versions.opera[0]}`);
424
451
  }
425
452
  if (target.length === 0) {
426
453
  return void 0;
427
454
  }
428
455
  return target;
429
456
  }
457
+
430
458
  function resolveNodeTarget(versions) {
431
459
  const target = [];
432
460
  if (versions.node.length) {
433
- target.push("node".concat(versions.node[0]));
461
+ target.push(`node${versions.node[0]}`);
434
462
  }
435
463
  if (target.length === 0) {
436
464
  return void 0;
437
465
  }
438
466
  return target;
439
467
  }
468
+
440
469
  async function resolveBuildContext(options) {
441
- var _config$runtime;
442
470
  const {
443
471
  config,
444
472
  cwd,
@@ -449,10 +477,7 @@ async function resolveBuildContext(options) {
449
477
  strict,
450
478
  tsconfig: tsconfigPath
451
479
  } = options;
452
- const tsconfig = await loadTSConfig({
453
- cwd,
454
- tsconfigPath
455
- });
480
+ const tsconfig = await loadTSConfig({ cwd, tsconfigPath });
456
481
  const targetVersions = resolveBrowserslistVersions(pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY);
457
482
  const nodeTarget = resolveNodeTarget(targetVersions);
458
483
  const webTarget = resolveBrowserTarget(targetVersions);
@@ -467,37 +492,38 @@ async function resolveBuildContext(options) {
467
492
  "browser": webTarget,
468
493
  "node": nodeTarget
469
494
  };
470
- const parsedExports = parseExports({
471
- extMap,
472
- pkg,
473
- strict
474
- }).reduce((acc, x) => {
475
- const {
476
- _path: exportPath,
477
- ...exportEntry
478
- } = x;
479
- return {
480
- ...acc,
481
- [exportPath]: exportEntry
482
- };
495
+ const parsedExports = parseExports({ extMap, pkg, strict }).reduce((acc, x) => {
496
+ const { _path: exportPath, ...exportEntry } = x;
497
+ return { ...acc, [exportPath]: exportEntry };
483
498
  }, {});
484
- const exports = resolveConfigProperty(config === null || config === void 0 ? void 0 : config.exports, parsedExports);
485
- const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
486
- const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config === null || config === void 0 ? void 0 : config.external, parsedExternal);
487
- const outputPaths = Object.values(exports).flatMap(exportEntry => {
488
- var _exportEntry$browser, _exportEntry$browser2, _exportEntry$node, _exportEntry$node2;
489
- return [exportEntry.import, exportEntry.require, (_exportEntry$browser = exportEntry.browser) === null || _exportEntry$browser === void 0 ? void 0 : _exportEntry$browser.import, (_exportEntry$browser2 = exportEntry.browser) === null || _exportEntry$browser2 === void 0 ? void 0 : _exportEntry$browser2.require, ((_exportEntry$node = exportEntry.node) === null || _exportEntry$node === void 0 ? void 0 : _exportEntry$node.source) && exportEntry.node.import, ((_exportEntry$node2 = exportEntry.node) === null || _exportEntry$node2 === void 0 ? void 0 : _exportEntry$node2.source) && exportEntry.node.require].filter(Boolean);
490
- }).map(p => path__default.default.resolve(cwd, p));
499
+ const exports = resolveConfigProperty(config?.exports, parsedExports);
500
+ const parsedExternal = [
501
+ ...pkg.dependencies ? Object.keys(pkg.dependencies) : [],
502
+ ...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []
503
+ ];
504
+ const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config?.external, parsedExternal);
505
+ const outputPaths = Object.values(exports).flatMap((exportEntry) => {
506
+ return [
507
+ exportEntry.import,
508
+ exportEntry.require,
509
+ exportEntry.browser?.import,
510
+ exportEntry.browser?.require,
511
+ exportEntry.node?.source && exportEntry.node.import,
512
+ exportEntry.node?.source && exportEntry.node.require
513
+ ].filter(Boolean);
514
+ }).map((p) => path__default.default.resolve(cwd, p));
491
515
  const commonDistPath = findCommonDirPath(outputPaths);
492
516
  if (commonDistPath === cwd) {
493
- throw new Error("all output files must share a common parent directory which is not the root package directory");
517
+ throw new Error(
518
+ "all output files must share a common parent directory which is not the root package directory"
519
+ );
494
520
  }
495
521
  if (commonDistPath && !pathContains(cwd, commonDistPath)) {
496
522
  throw new Error("all output files must be located within the package");
497
523
  }
498
- const configDistPath = config !== null && config !== void 0 && config.dist ? path__default.default.resolve(cwd, config.dist) : void 0;
524
+ const configDistPath = config?.dist ? path__default.default.resolve(cwd, config.dist) : void 0;
499
525
  if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath)) {
500
- logger.log("did you mean to configure `dist: './".concat(path__default.default.relative(cwd, commonDistPath), "'`?"));
526
+ logger.log(`did you mean to configure \`dist: './${path__default.default.relative(cwd, commonDistPath)}'\`?`);
501
527
  throw new Error("all output files must be located with the configured `dist` path");
502
528
  }
503
529
  const distPath = configDistPath || commonDistPath;
@@ -515,7 +541,7 @@ async function resolveBuildContext(options) {
515
541
  files: [],
516
542
  logger,
517
543
  pkg,
518
- runtime: (_config$runtime = config === null || config === void 0 ? void 0 : config.runtime) !== null && _config$runtime !== void 0 ? _config$runtime : "*",
544
+ runtime: config?.runtime ?? "*",
519
545
  strict,
520
546
  target,
521
547
  ts: {
@@ -525,53 +551,29 @@ async function resolveBuildContext(options) {
525
551
  };
526
552
  return ctx;
527
553
  }
554
+
528
555
  function createConsoleSpy(options) {
529
- const {
530
- onRestored
531
- } = options || {};
556
+ const { onRestored } = options || {};
532
557
  const original = {
533
558
  log: console.log,
534
559
  warn: console.warn,
535
560
  error: console.error
536
561
  };
537
562
  const messages = [];
538
- console.log = function () {
539
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
540
- args[_key] = arguments[_key];
541
- }
542
- return messages.push({
543
- type: "log",
544
- args
545
- });
546
- };
547
- console.warn = function () {
548
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
549
- args[_key2] = arguments[_key2];
550
- }
551
- return messages.push({
552
- type: "warn",
553
- args
554
- });
555
- };
556
- console.error = function () {
557
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
558
- args[_key3] = arguments[_key3];
559
- }
560
- return messages.push({
561
- type: "error",
562
- args
563
- });
564
- };
563
+ console.log = (...args) => messages.push({ type: "log", args });
564
+ console.warn = (...args) => messages.push({ type: "warn", args });
565
+ console.error = (...args) => messages.push({ type: "error", args });
565
566
  return {
566
567
  messages,
567
568
  restore: () => {
568
569
  console.log = original.log;
569
570
  console.warn = original.warn;
570
571
  console.error = original.error;
571
- onRestored === null || onRestored === void 0 || onRestored(messages);
572
+ onRestored?.(messages);
572
573
  }
573
574
  };
574
575
  }
576
+
575
577
  exports.DEFAULT_BROWSERSLIST_QUERY = DEFAULT_BROWSERSLIST_QUERY;
576
578
  exports.DEFAULT_PKG_EXT_MAP = DEFAULT_PKG_EXT_MAP;
577
579
  exports.createConsoleSpy = createConsoleSpy;
@@ -583,4 +585,4 @@ exports.loadTSConfig = loadTSConfig;
583
585
  exports.parseExports = parseExports;
584
586
  exports.resolveBuildContext = resolveBuildContext;
585
587
  exports.resolveConfigProperty = resolveConfigProperty;
586
- //# sourceMappingURL=consoleSpy-g4ZadSyB.cjs.map
588
+ //# sourceMappingURL=consoleSpy-bV4ZI2h8.cjs.map