@sanity/pkg-utils 1.17.3 → 1.19.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 (108) hide show
  1. package/dist/_chunks/{build-6fac40bf.js → build-bcb33ba5.js} +19 -63
  2. package/dist/_chunks/build-bcb33ba5.js.map +1 -0
  3. package/dist/_chunks/{buildAction-ff3e6d24.js → buildAction-f240dab8.js} +8 -38
  4. package/dist/_chunks/buildAction-f240dab8.js.map +1 -0
  5. package/dist/_chunks/{check-87cbb6cc.js → check-1ea361f5.js} +26 -81
  6. package/dist/_chunks/check-1ea361f5.js.map +1 -0
  7. package/dist/_chunks/{checkAction-e7e455d4.js → checkAction-16be1201.js} +5 -22
  8. package/dist/_chunks/checkAction-16be1201.js.map +1 -0
  9. package/dist/_chunks/{_handleError-869dec25.js → handleError-65cf3242.js} +3 -8
  10. package/dist/_chunks/handleError-65cf3242.js.map +1 -0
  11. package/dist/_chunks/{index-fbba5480.js → index-79fdb33f.js} +105 -282
  12. package/dist/_chunks/index-79fdb33f.js.map +1 -0
  13. package/dist/_chunks/{_resolveBuildContext-7ca7e64e.js → resolveBuildContext-f2feec19.js} +63 -184
  14. package/dist/_chunks/resolveBuildContext-f2feec19.js.map +1 -0
  15. package/dist/_chunks/{watch-2ea1243e.js → watch-02c85f8a.js} +25 -80
  16. package/dist/_chunks/watch-02c85f8a.js.map +1 -0
  17. package/dist/_chunks/{watchAction-10e52cbc.js → watchAction-9cb9681b.js} +8 -41
  18. package/dist/_chunks/watchAction-9cb9681b.js.map +1 -0
  19. package/dist/cli.js +4 -7
  20. package/dist/cli.js.map +1 -1
  21. package/dist/index.d.ts +44 -46
  22. package/dist/index.esm.js +217 -560
  23. package/dist/index.esm.js.map +1 -1
  24. package/dist/index.js +24 -62
  25. package/dist/index.js.map +1 -1
  26. package/package.json +50 -1
  27. package/src/cli/buildAction.ts +2 -2
  28. package/src/cli/checkAction.ts +2 -2
  29. package/src/cli/{_handleError.ts → handleError.ts} +1 -1
  30. package/src/cli/watchAction.ts +2 -2
  31. package/src/node/build.ts +11 -11
  32. package/src/node/check.ts +11 -11
  33. package/src/node/{_core → core}/config/defineConfig.ts +0 -0
  34. package/src/node/{_core/config/_findConfigFile.ts → core/config/findConfigFile.ts} +3 -3
  35. package/src/node/core/config/index.ts +4 -0
  36. package/src/node/{_core/config/_loadConfig.ts → core/config/loadConfig.ts} +3 -3
  37. package/src/node/{_core/config/_resolveConfigProperty.ts → core/config/resolveConfigProperty.ts} +1 -1
  38. package/src/node/{_core → core}/config/types.ts +0 -0
  39. package/src/node/{_core/_constants.ts → core/constants.ts} +1 -1
  40. package/src/node/{_core → core}/contexts/buildContext.ts +5 -5
  41. package/src/node/{_core → core}/contexts/index.ts +0 -0
  42. package/src/node/core/defaults.ts +7 -0
  43. package/src/node/core/findCommonPath.test.ts +9 -0
  44. package/src/node/{_core/_findCommonPath.ts → core/findCommonPath.ts} +3 -3
  45. package/src/node/{_core → core}/index.ts +3 -3
  46. package/src/node/{_core/_isRecord.ts → core/isRecord.ts} +1 -1
  47. package/src/node/core/pkg/index.ts +4 -0
  48. package/src/node/{_core/pkg/_loadPkg.ts → core/pkg/loadPkg.ts} +4 -4
  49. package/src/node/{_core/pkg/_loadPkgWithReporting.ts → core/pkg/loadPkgWithReporting.ts} +6 -6
  50. package/src/node/{_core/pkg/_parseExports.ts → core/pkg/parseExports.ts} +7 -7
  51. package/src/node/{_core/pkg/_types.ts → core/pkg/types.ts} +1 -1
  52. package/src/node/{_core/pkg/_validateExports.ts → core/pkg/validateExports.ts} +5 -5
  53. package/src/node/{_core/pkg/_validatePkg.ts → core/pkg/validatePkg.ts} +2 -2
  54. package/src/node/core/ts/index.ts +1 -0
  55. package/src/node/{_core/ts/_loadTSConfig.ts → core/ts/loadTSConfig.ts} +1 -1
  56. package/src/node/{_getFilesize.ts → getFilesize.ts} +1 -1
  57. package/src/node/globFiles.ts +5 -0
  58. package/src/node/index.ts +3 -3
  59. package/src/node/{_printExtractMessages.ts → printExtractMessages.ts} +2 -2
  60. package/src/node/{_printPackageTree.ts → printPackageTree.ts} +17 -17
  61. package/src/node/{_resolveBrowserTarget.ts → resolveBrowserTarget.ts} +2 -2
  62. package/src/node/{_resolveBrowserslistVersions.ts → resolveBrowserslistVersions.ts} +11 -11
  63. package/src/node/{_resolveBuildContext.ts → resolveBuildContext.ts} +28 -28
  64. package/src/node/{_resolveBuildTasks.ts → resolveBuildTasks.ts} +13 -13
  65. package/src/node/{_resolveNodeTarget.ts → resolveNodeTarget.ts} +2 -2
  66. package/src/node/{_resolveWatchTasks.ts → resolveWatchTasks.ts} +11 -11
  67. package/src/node/{_spinner.ts → spinner.ts} +1 -1
  68. package/src/node/{_tasks/dts/_DtsError.ts → tasks/dts/DtsError.ts} +1 -1
  69. package/src/node/{_tasks/dts/_buildTypes.ts → tasks/dts/buildTypes.ts} +1 -1
  70. package/src/node/{_tasks/dts/_createApiExtractorConfig.ts → tasks/dts/createApiExtractorConfig.ts} +1 -1
  71. package/src/node/{_tasks/dts/_createTSDocConfig.ts → tasks/dts/createTSDocConfig.ts} +1 -1
  72. package/src/node/{_tasks/dts/_doExtract.ts → tasks/dts/doExtract.ts} +14 -20
  73. package/src/node/{_tasks/dts/_dtsTask.ts → tasks/dts/dtsTask.ts} +10 -10
  74. package/src/node/{_tasks/dts/_dtsWatchTask.ts → tasks/dts/dtsWatchTask.ts} +10 -10
  75. package/src/node/tasks/dts/extractModuleBlocks.ts +45 -0
  76. package/src/node/{_tasks/dts/_extractTypes.ts → tasks/dts/extractTypes.ts} +20 -10
  77. package/src/node/{_tasks/dts/_getExtractMessagesConfig.ts → tasks/dts/getExtractMessagesConfig.ts} +12 -12
  78. package/src/node/tasks/dts/index.ts +4 -0
  79. package/src/node/{_tasks/dts/_types.ts → tasks/dts/types.ts} +3 -3
  80. package/src/node/tasks/index.ts +19 -0
  81. package/src/node/tasks/rollup/index.ts +2 -0
  82. package/src/node/{_tasks/rollup/_resolveRollupConfig.ts → tasks/rollup/resolveRollupConfig.ts} +16 -11
  83. package/src/node/{_tasks/rollup/_rollupTask.ts → tasks/rollup/rollupTask.ts} +7 -7
  84. package/src/node/{_tasks/rollup/_rollupWatchTask.ts → tasks/rollup/rollupWatchTask.ts} +4 -4
  85. package/src/node/tasks/types.ts +57 -0
  86. package/src/node/watch.ts +13 -13
  87. package/src/node/{_watchConfigFiles.ts → watchConfigFiles.ts} +5 -5
  88. package/src/node/{_watchFiles.ts → watchFiles.ts} +5 -5
  89. package/dist/_chunks/_handleError-869dec25.js.map +0 -1
  90. package/dist/_chunks/_resolveBuildContext-7ca7e64e.js.map +0 -1
  91. package/dist/_chunks/build-6fac40bf.js.map +0 -1
  92. package/dist/_chunks/buildAction-ff3e6d24.js.map +0 -1
  93. package/dist/_chunks/check-87cbb6cc.js.map +0 -1
  94. package/dist/_chunks/checkAction-e7e455d4.js.map +0 -1
  95. package/dist/_chunks/index-fbba5480.js.map +0 -1
  96. package/dist/_chunks/watch-2ea1243e.js.map +0 -1
  97. package/dist/_chunks/watchAction-10e52cbc.js.map +0 -1
  98. package/src/node/_core/_defaults.ts +0 -9
  99. package/src/node/_core/_findCommonPath.test.ts +0 -9
  100. package/src/node/_core/config/index.ts +0 -4
  101. package/src/node/_core/pkg/index.ts +0 -4
  102. package/src/node/_core/ts/index.ts +0 -1
  103. package/src/node/_globFiles.ts +0 -5
  104. package/src/node/_tasks/_types.ts +0 -57
  105. package/src/node/_tasks/dts/_declareModuleFix.ts +0 -99
  106. package/src/node/_tasks/dts/index.ts +0 -4
  107. package/src/node/_tasks/index.ts +0 -19
  108. package/src/node/_tasks/rollup/index.ts +0 -2
@@ -1,56 +1,33 @@
1
1
  'use strict';
2
2
 
3
3
  const _excluded = ["_path"];
4
-
5
4
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
-
7
5
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
-
9
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
-
11
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
-
13
8
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
-
15
9
  var path = require('path');
16
-
17
10
  var node = require('esbuild-register/dist/node');
18
-
19
11
  var pkgUp = require('pkg-up');
20
-
21
12
  var fs = require('fs/promises');
22
-
23
13
  var findConfig = require('find-config');
24
-
25
14
  var chalk = require('chalk');
26
-
27
15
  var zod = require('zod');
28
-
29
16
  var ts = require('typescript');
30
-
31
17
  var browserslist = require('browserslist');
32
-
33
18
  function _interopDefaultLegacy(e) {
34
19
  return e && typeof e === 'object' && 'default' in e ? e : {
35
20
  'default': e
36
21
  };
37
22
  }
38
-
39
23
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
40
-
41
24
  var pkgUp__default = /*#__PURE__*/_interopDefaultLegacy(pkgUp);
42
-
43
25
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
44
-
45
26
  var findConfig__default = /*#__PURE__*/_interopDefaultLegacy(findConfig);
46
-
47
27
  var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
48
-
49
28
  var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
50
-
51
29
  var browserslist__default = /*#__PURE__*/_interopDefaultLegacy(browserslist);
52
-
53
- const _MODULE_EXT = {
30
+ const MODULE_EXT = {
54
31
  commonjs: {
55
32
  commonjs: ".js",
56
33
  esm: ".esm.js"
@@ -60,36 +37,27 @@ const _MODULE_EXT = {
60
37
  esm: ".js"
61
38
  }
62
39
  };
63
- const _DEFAULTS = {
64
- browserslist: ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"]
65
- };
66
-
67
- function _isRecord(value) {
40
+ const DEFAULT_BROWSERSLIST_QUERY = ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"];
41
+ function isRecord(value) {
68
42
  return Boolean(value) && !Array.isArray(value) && typeof value === "object";
69
43
  }
70
-
71
44
  const CONFIG_FILE_NAMES = ["package.config.ts", "package.config.js", "package.config.cjs", "package.config.mjs"];
72
-
73
- async function _findConfigFile(cwd) {
45
+ async function findConfigFile(cwd) {
74
46
  const pkgJsonPath = findConfig__default["default"]("package.json", {
75
47
  cwd
76
48
  });
77
49
  if (!pkgJsonPath) return void 0;
78
50
  const pkgPath = path__default["default"].dirname(pkgJsonPath);
79
-
80
51
  for (const fileName of CONFIG_FILE_NAMES) {
81
52
  const configPath = path__default["default"].resolve(pkgPath, fileName);
82
- const exists = await _fileExists(configPath);
83
-
53
+ const exists = await fileExists(configPath);
84
54
  if (exists) {
85
55
  return configPath;
86
56
  }
87
57
  }
88
-
89
58
  return void 0;
90
59
  }
91
-
92
- async function _fileExists(filePath) {
60
+ async function fileExists(filePath) {
93
61
  try {
94
62
  await fs.stat(filePath);
95
63
  return true;
@@ -97,8 +65,7 @@ async function _fileExists(filePath) {
97
65
  return false;
98
66
  }
99
67
  }
100
-
101
- async function _loadConfig(options) {
68
+ async function loadConfig(options) {
102
69
  const {
103
70
  cwd
104
71
  } = options;
@@ -107,42 +74,33 @@ async function _loadConfig(options) {
107
74
  });
108
75
  if (!pkgPath) return void 0;
109
76
  const root = path__default["default"].dirname(pkgPath);
110
- const configFile = await _findConfigFile(root);
111
-
77
+ const configFile = await findConfigFile(root);
112
78
  if (!configFile) {
113
79
  return void 0;
114
80
  }
115
-
116
81
  if (!configFile.startsWith(cwd)) {
117
82
  return void 0;
118
83
  }
119
-
120
84
  try {
121
85
  const {
122
86
  unregister
123
87
  } = node.register({
124
88
  extensions: [".js", ".mjs", ".ts"]
125
89
  });
126
-
127
90
  const mod = require(configFile);
128
-
129
91
  unregister();
130
92
  return (mod == null ? void 0 : mod.default) || mod || void 0;
131
93
  } catch (_) {
132
94
  return void 0;
133
95
  }
134
96
  }
135
-
136
- function _resolveConfigProperty(prop, initialValue) {
97
+ function resolveConfigProperty(prop, initialValue) {
137
98
  if (!prop) return initialValue;
138
-
139
99
  if (typeof prop === "function") {
140
100
  return prop(initialValue);
141
101
  }
142
-
143
102
  return prop;
144
103
  }
145
-
146
104
  const pkgSchema = zod.z.object({
147
105
  type: zod.z.optional(zod.z.enum(["commonjs", "module"])),
148
106
  name: zod.z.string(),
@@ -176,15 +134,13 @@ const pkgSchema = zod.z.object({
176
134
  })]))),
177
135
  browserslist: zod.z.optional(zod.z.array(zod.z.string()))
178
136
  });
179
-
180
- function _validatePkg(input) {
137
+ function validatePkg(input) {
181
138
  const pkg = pkgSchema.parse(input);
182
139
  return _objectSpread(_objectSpread({}, pkg), {}, {
183
140
  type: pkg.type || "commonjs"
184
141
  });
185
142
  }
186
-
187
- async function _loadPkg(options) {
143
+ async function loadPkg(options) {
188
144
  const {
189
145
  cwd
190
146
  } = options;
@@ -193,64 +149,53 @@ async function _loadPkg(options) {
193
149
  });
194
150
  if (!pkgPath) throw new Error("no package.json found");
195
151
  const buf = await fs__default["default"].readFile(pkgPath);
196
- return _validatePkg(JSON.parse(buf.toString()));
152
+ return validatePkg(JSON.parse(buf.toString()));
197
153
  }
198
-
199
- async function _loadPkgWithReporting(options) {
154
+ async function loadPkgWithReporting(options) {
200
155
  try {
201
- return await _loadPkg(options);
156
+ return await loadPkg(options);
202
157
  } catch (err) {
203
158
  if (err instanceof zod.ZodError) {
204
159
  for (const issue of err.issues) {
205
160
  if (issue.code === "invalid_type") {
206
- console.log(["".concat(chalk__default["default"].red("fail"), " `").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(""));
161
+ console.log(["".concat(chalk__default["default"].red("fail"), " `").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(""));
207
162
  }
208
163
  }
209
164
  } else {
210
165
  console.error(err);
211
166
  }
212
-
213
167
  process.exit(1);
214
168
  }
215
169
  }
216
-
217
- function _formatPath(segments) {
170
+ function formatPath(segments) {
218
171
  return segments.map((s, idx) => {
219
172
  if (idx === 0) return s;
220
-
221
173
  if (typeof s === "number") {
222
174
  return "[".concat(s, "]");
223
175
  }
224
-
225
176
  if (s.startsWith(".")) {
226
177
  return "[\"".concat(s, "\"]");
227
178
  }
228
-
229
179
  return ".".concat(s);
230
180
  }).join("");
231
181
  }
232
-
233
- function _validateExports(_exports, options) {
182
+ function validateExports(_exports, options) {
234
183
  const {
235
184
  pkg
236
185
  } = options;
237
- const ext = _MODULE_EXT[pkg.type];
186
+ const ext = MODULE_EXT[pkg.type];
238
187
  const errors = [];
239
-
240
188
  for (const exp of _exports) {
241
189
  if (exp.require && !exp.require.endsWith(ext.commonjs)) {
242
190
  errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].require` must end with \"").concat(ext.commonjs, "\""));
243
191
  }
244
-
245
192
  if (exp.import && !exp.import.endsWith(ext.esm)) {
246
193
  errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].import` must end with \"").concat(ext.esm, "\""));
247
194
  }
248
195
  }
249
-
250
196
  return errors;
251
197
  }
252
-
253
- function _parseExports(options) {
198
+ function parseExports(options) {
254
199
  const {
255
200
  pkg,
256
201
  strict
@@ -271,12 +216,10 @@ function _parseExports(options) {
271
216
  };
272
217
  const extraExports = [];
273
218
  const errors = [];
274
-
275
219
  if (pkg.exports) {
276
220
  if (strict && !pkg.exports["./package.json"]) {
277
221
  errors.push('package.json: `exports["./package.json"] must be declared.');
278
222
  }
279
-
280
223
  for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
281
224
  if (exportPath.endsWith(".json")) {
282
225
  if (exportPath === "./package.json") {
@@ -284,31 +227,26 @@ function _parseExports(options) {
284
227
  errors.push('package.json: `exports["./package.json"] must be "./package.json".');
285
228
  }
286
229
  }
287
- } else if (_isRecord(exportEntry)) {
230
+ } else if (isRecord(exportEntry)) {
288
231
  if (exportPath === ".") {
289
232
  if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require) {
290
233
  errors.push('package.json: mismatch between "main" and "exports.require". These must be equal.');
291
234
  }
292
-
293
235
  if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
294
236
  errors.push('package.json: mismatch between "module" and "exports.import" These must be equal.');
295
237
  }
296
-
297
238
  if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
298
239
  errors.push('package.json: mismatch between "types" and "exports.types". These must be equal.');
299
240
  }
300
-
301
241
  if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
302
242
  errors.push('package.json: mismatch between "source" and "exports.source". These must be equal.');
303
243
  }
304
-
305
244
  Object.assign(rootExport, exportEntry);
306
245
  } else {
307
246
  const extraExport = _objectSpread({
308
247
  _exported: true,
309
248
  _path: exportPath
310
249
  }, exportEntry);
311
-
312
250
  extraExports.push(extraExport);
313
251
  }
314
252
  } else {
@@ -316,75 +254,58 @@ function _parseExports(options) {
316
254
  }
317
255
  }
318
256
  }
319
-
320
257
  const _exports = [rootExport, ...extraExports];
321
- errors.push(..._validateExports(_exports, {
258
+ errors.push(...validateExports(_exports, {
322
259
  pkg
323
260
  }));
324
-
325
261
  if (errors.length) {
326
262
  throw new Error("\n- " + errors.join("\n- "));
327
263
  }
328
-
329
264
  return _exports;
330
265
  }
331
-
332
- async function _loadTSConfig(options) {
266
+ async function loadTSConfig(options) {
333
267
  const {
334
268
  cwd,
335
269
  tsconfigPath
336
270
  } = options;
337
271
  const configPath = ts__default["default"].findConfigFile(cwd, ts__default["default"].sys.fileExists, tsconfigPath);
338
-
339
272
  if (!configPath) {
340
273
  throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
341
274
  }
342
-
343
275
  const configFile = ts__default["default"].readConfigFile(configPath, ts__default["default"].sys.readFile);
344
276
  return ts__default["default"].parseJsonConfigFileContent(configFile.config, ts__default["default"].sys, cwd);
345
277
  }
346
-
347
- function _pathContains(containerPath, itemPath) {
278
+ function pathContains(containerPath, itemPath) {
348
279
  return !path__default["default"].relative(containerPath, itemPath).startsWith("..");
349
280
  }
350
-
351
- function _findCommonDirPath(filePaths) {
281
+ function findCommonDirPath(filePaths) {
352
282
  let ret = void 0;
353
-
354
283
  for (const filePath of filePaths) {
355
284
  let dirPath = path__default["default"].dirname(filePath);
356
-
357
285
  if (!ret) {
358
286
  ret = dirPath;
359
287
  continue;
360
288
  }
361
-
362
289
  while (dirPath !== ret) {
363
290
  dirPath = path__default["default"].dirname(dirPath);
364
-
365
291
  if (dirPath === ret) {
366
292
  break;
367
293
  }
368
-
369
- if (_pathContains(dirPath, ret)) {
294
+ if (pathContains(dirPath, ret)) {
370
295
  ret = dirPath;
371
296
  break;
372
297
  }
373
-
374
298
  if (dirPath === ".") return void 0;
375
299
  }
376
300
  }
377
-
378
301
  return ret;
379
302
  }
380
-
381
- function _sortAsNumber(a, b) {
303
+ function sortAsNumber(a, b) {
382
304
  const aVersion = Number(a);
383
305
  const bVersion = Number(b);
384
306
  return aVersion - bVersion;
385
307
  }
386
-
387
- function _resolveBrowserslistVersions(query) {
308
+ function resolveBrowserslistVersions(query) {
388
309
  const result = browserslist__default["default"](query);
389
310
  const entries = result.map(key => {
390
311
  const [name, version] = key.split(" ");
@@ -411,65 +332,51 @@ function _resolveBrowserslistVersions(query) {
411
332
  opera: opera.map(b => b.version),
412
333
  node: node.map(b => b.version)
413
334
  };
414
- versions.chrome.sort(_sortAsNumber);
415
- versions.ff.sort(_sortAsNumber);
416
- versions.edge.sort(_sortAsNumber);
417
- versions.iosSaf.sort(_sortAsNumber);
418
- versions.saf.sort(_sortAsNumber);
419
- versions.opera.sort(_sortAsNumber);
420
- versions.node.sort(_sortAsNumber);
335
+ versions.chrome.sort(sortAsNumber);
336
+ versions.ff.sort(sortAsNumber);
337
+ versions.edge.sort(sortAsNumber);
338
+ versions.iosSaf.sort(sortAsNumber);
339
+ versions.saf.sort(sortAsNumber);
340
+ versions.opera.sort(sortAsNumber);
341
+ versions.node.sort(sortAsNumber);
421
342
  return versions;
422
343
  }
423
-
424
- function _resolveBrowserTarget(versions) {
344
+ function resolveBrowserTarget(versions) {
425
345
  const target = [];
426
-
427
346
  if (versions.chrome.length) {
428
347
  target.push("chrome".concat(versions.chrome[0]));
429
348
  }
430
-
431
349
  if (versions.ff.length) {
432
350
  target.push("firefox".concat(versions.ff[0]));
433
351
  }
434
-
435
352
  if (versions.edge.length) {
436
353
  target.push("edge".concat(versions.edge[0]));
437
354
  }
438
-
439
355
  if (versions.iosSaf.length) {
440
356
  target.push("ios".concat(versions.iosSaf[0]));
441
357
  }
442
-
443
358
  if (versions.saf.length) {
444
359
  target.push("safari".concat(versions.saf[0]));
445
360
  }
446
-
447
361
  if (versions.opera.length) {
448
362
  target.push("opera".concat(versions.opera[0]));
449
363
  }
450
-
451
364
  if (target.length === 0) {
452
365
  return void 0;
453
366
  }
454
-
455
367
  return target;
456
368
  }
457
-
458
- function _resolveNodeTarget(versions) {
369
+ function resolveNodeTarget(versions) {
459
370
  const target = [];
460
-
461
371
  if (versions.node.length) {
462
372
  target.push("node".concat(versions.node[0]));
463
373
  }
464
-
465
374
  if (target.length === 0) {
466
375
  return void 0;
467
376
  }
468
-
469
377
  return target;
470
378
  }
471
-
472
- function _createLogger() {
379
+ function createLogger() {
473
380
  return {
474
381
  log: function () {
475
382
  console.log(...arguments);
@@ -478,36 +385,30 @@ function _createLogger() {
478
385
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
479
386
  args[_key] = arguments[_key];
480
387
  }
481
-
482
388
  console.log(chalk__default["default"].blue(" info"), ...args);
483
389
  },
484
390
  warn: function () {
485
391
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
486
392
  args[_key2] = arguments[_key2];
487
393
  }
488
-
489
394
  console.log(chalk__default["default"].yellow(" warn"), ...args);
490
395
  },
491
396
  error: function () {
492
397
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
493
398
  args[_key3] = arguments[_key3];
494
399
  }
495
-
496
400
  console.log(chalk__default["default"].red(" fail"), ...args);
497
401
  },
498
402
  success: function () {
499
403
  for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
500
404
  args[_key4] = arguments[_key4];
501
405
  }
502
-
503
406
  console.log(chalk__default["default"].green(" ok "), ...args);
504
407
  }
505
408
  };
506
409
  }
507
-
508
- async function _resolveBuildContext(options) {
410
+ async function resolveBuildContext(options) {
509
411
  var _ref;
510
-
511
412
  const {
512
413
  config,
513
414
  cwd,
@@ -516,81 +417,60 @@ async function _resolveBuildContext(options) {
516
417
  strict,
517
418
  tsconfig: tsconfigPath
518
419
  } = options;
519
-
520
- const logger = _createLogger();
521
-
522
- const tsconfig = await _loadTSConfig({
420
+ const logger = createLogger();
421
+ const tsconfig = await loadTSConfig({
523
422
  cwd,
524
423
  tsconfigPath
525
424
  });
526
-
527
- const targetVersions = _resolveBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
528
-
529
- const nodeTarget = _resolveNodeTarget(targetVersions);
530
-
531
- const webTarget = _resolveBrowserTarget(targetVersions);
532
-
425
+ const targetVersions = resolveBrowserslistVersions(pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY);
426
+ const nodeTarget = resolveNodeTarget(targetVersions);
427
+ const webTarget = resolveBrowserTarget(targetVersions);
533
428
  if (!nodeTarget) {
534
429
  throw new Error("no matching `node` target");
535
430
  }
536
-
537
431
  if (!webTarget) {
538
432
  throw new Error("no matching `web` target");
539
433
  }
540
-
541
434
  const target = {
542
435
  "*": webTarget.concat(nodeTarget),
543
436
  browser: webTarget,
544
437
  node: nodeTarget
545
438
  };
546
-
547
- const parsedExports = _parseExports({
439
+ const parsedExports = parseExports({
548
440
  pkg,
549
441
  strict
550
442
  }).reduce((acc, x) => {
551
443
  const {
552
- _path: exportPath
553
- } = x,
554
- exportEntry = _objectWithoutProperties(x, _excluded);
555
-
444
+ _path: exportPath
445
+ } = x,
446
+ exportEntry = _objectWithoutProperties(x, _excluded);
556
447
  return _objectSpread(_objectSpread({}, acc), {}, {
557
448
  [exportPath]: exportEntry
558
449
  });
559
450
  }, {});
560
-
561
- const exports = _resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
562
-
451
+ const exports = resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
563
452
  const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
564
- const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : _resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
453
+ const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
565
454
  const outputPaths = Object.values(exports).flatMap(exportEntry => {
566
455
  var _a, _b, _c, _d;
567
-
568
456
  return [exportEntry.import, exportEntry.require, (_a = exportEntry.browser) == null ? void 0 : _a.import, (_b = exportEntry.browser) == null ? void 0 : _b.require, (_c = exportEntry.node) == null ? void 0 : _c.import, (_d = exportEntry.node) == null ? void 0 : _d.require].filter(Boolean);
569
457
  }).map(p => path__default["default"].resolve(cwd, p));
570
-
571
- const commonDistPath = _findCommonDirPath(outputPaths);
572
-
458
+ const commonDistPath = findCommonDirPath(outputPaths);
573
459
  if (commonDistPath === cwd) {
574
460
  throw new Error("all output files must share a common parent directory which is not the root package directory");
575
461
  }
576
-
577
- if (commonDistPath && !_pathContains(cwd, commonDistPath)) {
462
+ if (commonDistPath && !pathContains(cwd, commonDistPath)) {
578
463
  throw new Error("all output files must be located within the package");
579
464
  }
580
-
581
465
  const configDistPath = (config == null ? void 0 : config.dist) ? path__default["default"].resolve(cwd, config.dist) : void 0;
582
-
583
- if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !_pathContains(configDistPath, commonDistPath)) {
466
+ if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath)) {
584
467
  logger.log("did you mean to configure `dist: './".concat(path__default["default"].relative(cwd, commonDistPath), "'`?"));
585
468
  throw new Error("all output files must be located with the configured `dist` path");
586
469
  }
587
-
588
470
  const distPath = configDistPath || commonDistPath;
589
-
590
471
  if (!distPath) {
591
472
  throw new Error("could not detect `dist` path");
592
473
  }
593
-
594
474
  const ctx = {
595
475
  config,
596
476
  cwd,
@@ -611,15 +491,14 @@ async function _resolveBuildContext(options) {
611
491
  };
612
492
  return ctx;
613
493
  }
614
-
615
- exports._DEFAULTS = _DEFAULTS;
616
- exports._MODULE_EXT = _MODULE_EXT;
617
- exports._isRecord = _isRecord;
618
- exports._loadConfig = _loadConfig;
619
- exports._loadPkg = _loadPkg;
620
- exports._loadPkgWithReporting = _loadPkgWithReporting;
621
- exports._loadTSConfig = _loadTSConfig;
622
- exports._parseExports = _parseExports;
623
- exports._resolveBuildContext = _resolveBuildContext;
624
- exports._resolveConfigProperty = _resolveConfigProperty;
625
- //# sourceMappingURL=_resolveBuildContext-7ca7e64e.js.map
494
+ exports.DEFAULT_BROWSERSLIST_QUERY = DEFAULT_BROWSERSLIST_QUERY;
495
+ exports.MODULE_EXT = MODULE_EXT;
496
+ exports.isRecord = isRecord;
497
+ exports.loadConfig = loadConfig;
498
+ exports.loadPkg = loadPkg;
499
+ exports.loadPkgWithReporting = loadPkgWithReporting;
500
+ exports.loadTSConfig = loadTSConfig;
501
+ exports.parseExports = parseExports;
502
+ exports.resolveBuildContext = resolveBuildContext;
503
+ exports.resolveConfigProperty = resolveConfigProperty;
504
+ //# sourceMappingURL=resolveBuildContext-f2feec19.js.map