@sanity/pkg-utils 1.7.3 → 1.8.1

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 (144) hide show
  1. package/bin/{pkg-utils → pkg-utils.cjs} +0 -0
  2. package/dist/{__resolveBuildContext-56b6b816.cjs → __resolveBuildContext-17992a0e.cjs} +59 -7
  3. package/dist/__resolveBuildContext-17992a0e.cjs.map +1 -0
  4. package/dist/{_build-49dd667f.cjs → _build-0377061e.cjs} +7 -3
  5. package/dist/{_build-49dd667f.cjs.map → _build-0377061e.cjs.map} +1 -1
  6. package/dist/{_buildAction-b58e3a4b.cjs → _buildAction-68633427.cjs} +12 -4
  7. package/dist/{_buildAction-b58e3a4b.cjs.map → _buildAction-68633427.cjs.map} +1 -1
  8. package/dist/{_check-0871d90f.cjs → _check-11811a4d.cjs} +18 -4
  9. package/dist/_check-11811a4d.cjs.map +1 -0
  10. package/dist/{_checkAction-0510605b.cjs → _checkAction-386fe8d4.cjs} +3 -3
  11. package/dist/{_checkAction-0510605b.cjs.map → _checkAction-386fe8d4.cjs.map} +1 -1
  12. package/dist/_index-8cd98d8d.cjs +4244 -0
  13. package/dist/_index-8cd98d8d.cjs.map +1 -0
  14. package/dist/{_watch-e1c86797.cjs → _watch-259b1e4f.cjs} +7 -3
  15. package/dist/{_watch-e1c86797.cjs.map → _watch-259b1e4f.cjs.map} +1 -1
  16. package/dist/{_watchAction-cfe36cbc.cjs → _watchAction-a48d3934.cjs} +12 -4
  17. package/dist/{_watchAction-cfe36cbc.cjs.map → _watchAction-a48d3934.cjs.map} +1 -1
  18. package/dist/cli.cjs +4 -4
  19. package/dist/index.cjs +13 -5
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.js +3786 -227
  22. package/dist/index.js.map +1 -1
  23. package/dist/types/src/node/index.d.ts +18 -3
  24. package/package.json +8 -7
  25. package/src/node/_core/config/types.ts +6 -1
  26. package/src/node/_core/pkg/_loadPkg.ts +2 -41
  27. package/src/node/_core/pkg/_parseExports.ts +27 -3
  28. package/src/node/_core/pkg/_types.ts +8 -2
  29. package/src/node/_core/pkg/_validateExports.ts +29 -0
  30. package/src/node/_core/pkg/_validatePkg.ts +50 -0
  31. package/src/node/_printPackageTree.ts +10 -2
  32. package/src/node/_tasks/dts/_doExtract.ts +38 -7
  33. package/src/node/_tasks/dts/_types.ts +1 -0
  34. package/dist/__resolveBuildContext-56b6b816.cjs.map +0 -1
  35. package/dist/_check-0871d90f.cjs.map +0 -1
  36. package/dist/_index-e3dda92a.cjs +0 -733
  37. package/dist/_index-e3dda92a.cjs.map +0 -1
  38. package/dist/types/src/cli/buildAction.d.ts +0 -4
  39. package/dist/types/src/cli/buildAction.d.ts.map +0 -1
  40. package/dist/types/src/cli/checkAction.d.ts +0 -5
  41. package/dist/types/src/cli/checkAction.d.ts.map +0 -1
  42. package/dist/types/src/cli/index.d.ts +0 -2
  43. package/dist/types/src/cli/index.d.ts.map +0 -1
  44. package/dist/types/src/cli/watchAction.d.ts +0 -4
  45. package/dist/types/src/cli/watchAction.d.ts.map +0 -1
  46. package/dist/types/src/node/_core/_defaults.d.ts +0 -5
  47. package/dist/types/src/node/_core/_defaults.d.ts.map +0 -1
  48. package/dist/types/src/node/_core/_isRecord.d.ts +0 -3
  49. package/dist/types/src/node/_core/_isRecord.d.ts.map +0 -1
  50. package/dist/types/src/node/_core/config/_loadConfig.d.ts +0 -6
  51. package/dist/types/src/node/_core/config/_loadConfig.d.ts.map +0 -1
  52. package/dist/types/src/node/_core/config/_resolveConfigProperty.d.ts +0 -4
  53. package/dist/types/src/node/_core/config/_resolveConfigProperty.d.ts.map +0 -1
  54. package/dist/types/src/node/_core/config/defineConfig.d.ts +0 -4
  55. package/dist/types/src/node/_core/config/defineConfig.d.ts.map +0 -1
  56. package/dist/types/src/node/_core/config/index.d.ts +0 -5
  57. package/dist/types/src/node/_core/config/index.d.ts.map +0 -1
  58. package/dist/types/src/node/_core/config/types.d.ts +0 -76
  59. package/dist/types/src/node/_core/config/types.d.ts.map +0 -1
  60. package/dist/types/src/node/_core/contexts/buildContext.d.ts +0 -33
  61. package/dist/types/src/node/_core/contexts/buildContext.d.ts.map +0 -1
  62. package/dist/types/src/node/_core/contexts/index.d.ts +0 -2
  63. package/dist/types/src/node/_core/contexts/index.d.ts.map +0 -1
  64. package/dist/types/src/node/_core/index.d.ts +0 -7
  65. package/dist/types/src/node/_core/index.d.ts.map +0 -1
  66. package/dist/types/src/node/_core/pkg/_loadPkg.d.ts +0 -6
  67. package/dist/types/src/node/_core/pkg/_loadPkg.d.ts.map +0 -1
  68. package/dist/types/src/node/_core/pkg/_loadPkgWithReporting.d.ts +0 -6
  69. package/dist/types/src/node/_core/pkg/_loadPkgWithReporting.d.ts.map +0 -1
  70. package/dist/types/src/node/_core/pkg/_parseExports.d.ts +0 -9
  71. package/dist/types/src/node/_core/pkg/_parseExports.d.ts.map +0 -1
  72. package/dist/types/src/node/_core/pkg/_types.d.ts +0 -29
  73. package/dist/types/src/node/_core/pkg/_types.d.ts.map +0 -1
  74. package/dist/types/src/node/_core/pkg/index.d.ts +0 -5
  75. package/dist/types/src/node/_core/pkg/index.d.ts.map +0 -1
  76. package/dist/types/src/node/_core/ts/_loadTSConfig.d.ts +0 -7
  77. package/dist/types/src/node/_core/ts/_loadTSConfig.d.ts.map +0 -1
  78. package/dist/types/src/node/_core/ts/index.d.ts +0 -2
  79. package/dist/types/src/node/_core/ts/index.d.ts.map +0 -1
  80. package/dist/types/src/node/_getFilesize.d.ts +0 -2
  81. package/dist/types/src/node/_getFilesize.d.ts.map +0 -1
  82. package/dist/types/src/node/_globFiles.d.ts +0 -2
  83. package/dist/types/src/node/_globFiles.d.ts.map +0 -1
  84. package/dist/types/src/node/_printExtractMessages.d.ts +0 -4
  85. package/dist/types/src/node/_printExtractMessages.d.ts.map +0 -1
  86. package/dist/types/src/node/_printPackageTree.d.ts +0 -4
  87. package/dist/types/src/node/_printPackageTree.d.ts.map +0 -1
  88. package/dist/types/src/node/_resolveBrowserTarget.d.ts +0 -3
  89. package/dist/types/src/node/_resolveBrowserTarget.d.ts.map +0 -1
  90. package/dist/types/src/node/_resolveBrowserslistVersions.d.ts +0 -11
  91. package/dist/types/src/node/_resolveBrowserslistVersions.d.ts.map +0 -1
  92. package/dist/types/src/node/_resolveBuildContext.d.ts +0 -8
  93. package/dist/types/src/node/_resolveBuildContext.d.ts.map +0 -1
  94. package/dist/types/src/node/_resolveBuildTasks.d.ts +0 -5
  95. package/dist/types/src/node/_resolveBuildTasks.d.ts.map +0 -1
  96. package/dist/types/src/node/_resolveNodeTarget.d.ts +0 -3
  97. package/dist/types/src/node/_resolveNodeTarget.d.ts.map +0 -1
  98. package/dist/types/src/node/_resolveWatchTasks.d.ts +0 -5
  99. package/dist/types/src/node/_resolveWatchTasks.d.ts.map +0 -1
  100. package/dist/types/src/node/_spinner.d.ts +0 -5
  101. package/dist/types/src/node/_spinner.d.ts.map +0 -1
  102. package/dist/types/src/node/_tasks/_types.d.ts +0 -50
  103. package/dist/types/src/node/_tasks/_types.d.ts.map +0 -1
  104. package/dist/types/src/node/_tasks/dts/_DtsError.d.ts +0 -7
  105. package/dist/types/src/node/_tasks/dts/_DtsError.d.ts.map +0 -1
  106. package/dist/types/src/node/_tasks/dts/_buildTypes.d.ts +0 -9
  107. package/dist/types/src/node/_tasks/dts/_buildTypes.d.ts.map +0 -1
  108. package/dist/types/src/node/_tasks/dts/_createApiExtractorConfig.d.ts +0 -11
  109. package/dist/types/src/node/_tasks/dts/_createApiExtractorConfig.d.ts.map +0 -1
  110. package/dist/types/src/node/_tasks/dts/_createTSDocConfig.d.ts +0 -12
  111. package/dist/types/src/node/_tasks/dts/_createTSDocConfig.d.ts.map +0 -1
  112. package/dist/types/src/node/_tasks/dts/_doExtract.d.ts +0 -4
  113. package/dist/types/src/node/_tasks/dts/_doExtract.d.ts.map +0 -1
  114. package/dist/types/src/node/_tasks/dts/_dtsTask.d.ts +0 -5
  115. package/dist/types/src/node/_tasks/dts/_dtsTask.d.ts.map +0 -1
  116. package/dist/types/src/node/_tasks/dts/_dtsWatchTask.d.ts +0 -5
  117. package/dist/types/src/node/_tasks/dts/_dtsWatchTask.d.ts.map +0 -1
  118. package/dist/types/src/node/_tasks/dts/_extractTypes.d.ts +0 -17
  119. package/dist/types/src/node/_tasks/dts/_extractTypes.d.ts.map +0 -1
  120. package/dist/types/src/node/_tasks/dts/_types.d.ts +0 -27
  121. package/dist/types/src/node/_tasks/dts/_types.d.ts.map +0 -1
  122. package/dist/types/src/node/_tasks/dts/index.d.ts +0 -4
  123. package/dist/types/src/node/_tasks/dts/index.d.ts.map +0 -1
  124. package/dist/types/src/node/_tasks/index.d.ts +0 -9
  125. package/dist/types/src/node/_tasks/index.d.ts.map +0 -1
  126. package/dist/types/src/node/_tasks/rollup/_resolveRollupConfig.d.ts +0 -10
  127. package/dist/types/src/node/_tasks/rollup/_resolveRollupConfig.d.ts.map +0 -1
  128. package/dist/types/src/node/_tasks/rollup/_rollupTask.d.ts +0 -4
  129. package/dist/types/src/node/_tasks/rollup/_rollupTask.d.ts.map +0 -1
  130. package/dist/types/src/node/_tasks/rollup/_rollupWatchTask.d.ts +0 -5
  131. package/dist/types/src/node/_tasks/rollup/_rollupWatchTask.d.ts.map +0 -1
  132. package/dist/types/src/node/_tasks/rollup/index.d.ts +0 -3
  133. package/dist/types/src/node/_tasks/rollup/index.d.ts.map +0 -1
  134. package/dist/types/src/node/_watchConfigFiles.d.ts +0 -5
  135. package/dist/types/src/node/_watchConfigFiles.d.ts.map +0 -1
  136. package/dist/types/src/node/_watchFiles.d.ts +0 -7
  137. package/dist/types/src/node/_watchFiles.d.ts.map +0 -1
  138. package/dist/types/src/node/build.d.ts +0 -6
  139. package/dist/types/src/node/build.d.ts.map +0 -1
  140. package/dist/types/src/node/check.d.ts +0 -7
  141. package/dist/types/src/node/check.d.ts.map +0 -1
  142. package/dist/types/src/node/index.d.ts.map +0 -1
  143. package/dist/types/src/node/watch.d.ts +0 -6
  144. package/dist/types/src/node/watch.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -10,16 +10,20 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
 
11
11
  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; }
12
12
 
13
- import path from 'path';
13
+ import path$1 from 'path';
14
14
  import { register } from 'esbuild-register/dist/node';
15
15
  import findConfig from 'find-config';
16
16
  import pkgUp from 'pkg-up';
17
- import fs, { readFile } from 'fs/promises';
17
+ import fs$1, { readFile, rename } from 'fs/promises';
18
18
  import { z, ZodError } from 'zod';
19
19
  import chalk from 'chalk';
20
20
  import ts from 'typescript';
21
- import fs$1, { statSync } from 'fs';
21
+ import fs$2, { statSync } from 'fs';
22
22
  import { Observable, switchMap } from 'rxjs';
23
+ import { promisify } from 'util';
24
+ import cpx from 'cpx';
25
+ import require$$5 from 'assert';
26
+ import require$$3 from 'events';
23
27
  import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
24
28
  import mkdirp from 'mkdirp';
25
29
  import prettier from 'prettier';
@@ -57,7 +61,7 @@ async function _loadConfig(options) {
57
61
  cwd
58
62
  });
59
63
  if (!pkgPath) return void 0;
60
- const root = path.dirname(pkgPath);
64
+ const root = path$1.dirname(pkgPath);
61
65
 
62
66
  const configFile = _findConfigFile(root);
63
67
 
@@ -120,14 +124,15 @@ function defineConfig(configOptions) {
120
124
  }
121
125
 
122
126
  const pkgSchema = z.object({
123
- type: z.optional(z.enum(["module"])),
127
+ type: z.optional(z.enum(["commonjs", "module"])),
124
128
  name: z.string(),
125
129
  version: z.string(),
130
+ license: z.string(),
126
131
  bin: z.optional(z.record(z.string())),
127
132
  dependencies: z.optional(z.record(z.string())),
128
133
  devDependencies: z.optional(z.record(z.string())),
129
134
  peerDependencies: z.optional(z.record(z.string())),
130
- source: z.string(),
135
+ source: z.optional(z.string()),
131
136
  main: z.optional(z.string()),
132
137
  browser: z.optional(z.record(z.string())),
133
138
  module: z.optional(z.string()),
@@ -136,10 +141,12 @@ const pkgSchema = z.object({
136
141
  types: z.optional(z.string()),
137
142
  source: z.string(),
138
143
  browser: z.optional(z.object({
144
+ source: z.string(),
139
145
  require: z.optional(z.string()),
140
146
  import: z.optional(z.string())
141
147
  })),
142
148
  node: z.optional(z.object({
149
+ source: z.string(),
143
150
  require: z.optional(z.string()),
144
151
  import: z.optional(z.string())
145
152
  })),
@@ -150,6 +157,13 @@ const pkgSchema = z.object({
150
157
  browserslist: z.optional(z.array(z.string()))
151
158
  });
152
159
 
160
+ function _validatePkg(input) {
161
+ const pkg = pkgSchema.parse(input);
162
+ return _objectSpread(_objectSpread({}, pkg), {}, {
163
+ type: pkg.type || "commonjs"
164
+ });
165
+ }
166
+
153
167
  async function _loadPkg(options) {
154
168
  const {
155
169
  cwd
@@ -158,235 +172,3746 @@ async function _loadPkg(options) {
158
172
  cwd
159
173
  });
160
174
  if (!pkgPath) throw new Error("no package.json found");
161
- const buf = await fs.readFile(pkgPath);
162
- return pkgSchema.parse(JSON.parse(buf.toString()));
175
+ const buf = await fs$1.readFile(pkgPath);
176
+ return _validatePkg(JSON.parse(buf.toString()));
177
+ }
178
+
179
+ async function _loadPkgWithReporting(options) {
180
+ try {
181
+ return await _loadPkg(options);
182
+ } catch (err) {
183
+ if (err instanceof ZodError) {
184
+ for (const issue of err.issues) {
185
+ if (issue.code === "invalid_type") {
186
+ console.log("".concat(chalk.red("invalid type"), " in ./package.json at ").concat(chalk.magenta("`".concat(issue.path.join("."), "`")), " (expected ").concat(issue.expected, ", received ").concat(issue.received, ")"));
187
+ }
188
+ }
189
+ } else {
190
+ console.error(err);
191
+ }
192
+
193
+ process.exit(1);
194
+ }
195
+ }
196
+
197
+ function _validateExports(_exports, options) {
198
+ const {
199
+ pkg
200
+ } = options;
201
+
202
+ for (const exp of _exports) {
203
+ if (pkg.type === "commonjs") {
204
+ if (exp.require && !exp.require.endsWith(".js")) {
205
+ throw new Error("package.json with `\"type\": \"commonjs\"` - `exports[\"".concat(exp._path, "\"].require` must end with \".js\""));
206
+ }
207
+ }
208
+
209
+ if (pkg.type === "module") {
210
+ if (exp.require && !exp.require.endsWith(".cjs")) {
211
+ throw new Error("package.json with `\"type\": \"module\"` - `exports[\"".concat(exp._path, "\"].require` must end with \".cjs\""));
212
+ }
213
+ }
214
+ }
215
+
216
+ return _exports;
217
+ }
218
+
219
+ function _parseExports(options) {
220
+ const {
221
+ pkg
222
+ } = options;
223
+ const rootExport = {
224
+ _exported: true,
225
+ _path: ".",
226
+ types: pkg.types,
227
+ source: pkg.source || "",
228
+ browser: pkg.browser && {
229
+ source: pkg.source || "",
230
+ require: pkg.main && pkg.browser[pkg.main],
231
+ import: pkg.module && pkg.browser[pkg.module]
232
+ },
233
+ import: pkg.module,
234
+ require: pkg.main,
235
+ default: pkg.module || pkg.main || ""
236
+ };
237
+ const extraExports = [];
238
+
239
+ if (pkg.exports) {
240
+ for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
241
+ if (_isRecord(exportEntry)) {
242
+ if (exportPath === ".") {
243
+ if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require) {
244
+ throw new Error('mismatch between "main" and "require"');
245
+ }
246
+
247
+ if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
248
+ throw new Error('mismatch between "module" and "import"');
249
+ }
250
+
251
+ if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
252
+ throw new Error('mismatch between "types" and "types"');
253
+ }
254
+
255
+ if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
256
+ throw new Error('mismatch between "source" and "source"');
257
+ }
258
+
259
+ Object.assign(rootExport, exportEntry);
260
+ } else {
261
+ const extraExport = _objectSpread({
262
+ _exported: true,
263
+ _path: exportPath
264
+ }, exportEntry);
265
+
266
+ extraExports.push(extraExport);
267
+ }
268
+ } else {
269
+ throw new Error("string entries are not supported");
270
+ }
271
+ }
272
+ }
273
+
274
+ const _exports = [rootExport, ...extraExports];
275
+ return _validateExports(_exports, {
276
+ pkg
277
+ });
278
+ }
279
+
280
+ async function _loadTSConfig(options) {
281
+ const {
282
+ cwd,
283
+ tsconfigPath
284
+ } = options;
285
+ const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
286
+
287
+ if (!configPath) {
288
+ throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
289
+ }
290
+
291
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
292
+ return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
293
+ }
294
+
295
+ function _resolveBuildTasks(ctx) {
296
+ var _a, _b, _c, _d, _e;
297
+
298
+ const {
299
+ cwd,
300
+ pkg,
301
+ target
302
+ } = ctx;
303
+ const tasks = [];
304
+ const exports = Object.entries(ctx.exports || {}).map(_ref => {
305
+ let [_path, exp] = _ref;
306
+ return _objectSpread({
307
+ _path
308
+ }, exp);
309
+ });
310
+ const dtsTask = {
311
+ type: "build:dts",
312
+ entries: []
313
+ };
314
+ const rollupTasks = {};
315
+
316
+ function _addRollupTaskEntry(format, runtime, entry) {
317
+ const buildId = "".concat(format, ":").concat(runtime);
318
+
319
+ if (rollupTasks[buildId]) {
320
+ rollupTasks[buildId].entries.push(entry);
321
+ } else {
322
+ rollupTasks[buildId] = {
323
+ type: "build:js",
324
+ buildId,
325
+ entries: [entry],
326
+ runtime,
327
+ format,
328
+ target: target[runtime]
329
+ };
330
+ }
331
+ }
332
+
333
+ for (const exp of exports) {
334
+ const importId = path$1.join(pkg.name, exp._path);
335
+
336
+ if (exp.types) {
337
+ dtsTask.entries.push({
338
+ importId,
339
+ exportPath: exp._path,
340
+ sourcePath: exp.source,
341
+ targetPath: exp.types
342
+ });
343
+ }
344
+ }
345
+
346
+ for (const exp of exports) {
347
+ const output = exp.require;
348
+ if (!output) continue;
349
+
350
+ _addRollupTaskEntry("commonjs", ctx.runtime, {
351
+ path: exp._path,
352
+ source: exp.source,
353
+ output
354
+ });
355
+ }
356
+
357
+ for (const exp of exports) {
358
+ const output = (_a = exp.browser) == null ? void 0 : _a.require;
359
+ if (!output) continue;
360
+
361
+ _addRollupTaskEntry("commonjs", "browser", {
362
+ path: exp._path,
363
+ source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
364
+ output
365
+ });
366
+ }
367
+
368
+ for (const exp of exports) {
369
+ const output = exp.import;
370
+ if (!output) continue;
371
+
372
+ _addRollupTaskEntry("esm", ctx.runtime, {
373
+ path: exp._path,
374
+ source: exp.source,
375
+ output
376
+ });
377
+ }
378
+
379
+ for (const exp of exports) {
380
+ const output = (_c = exp.browser) == null ? void 0 : _c.import;
381
+ if (!output) continue;
382
+
383
+ _addRollupTaskEntry("esm", "browser", {
384
+ path: exp._path,
385
+ source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
386
+ output
387
+ });
388
+ }
389
+
390
+ if (dtsTask.entries.length) {
391
+ tasks.push(dtsTask);
392
+ }
393
+
394
+ tasks.push(...Object.values(rollupTasks));
395
+
396
+ for (const exp of exports) {
397
+ if (exp._exported && exp._path !== ".") {
398
+ const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
399
+
400
+ if (relativeTargetPath) {
401
+ fs$2.writeFileSync(path$1.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
402
+ }
403
+ }
404
+ }
405
+
406
+ return tasks;
407
+ }
408
+
409
+ function _printExtractMessages(ctx, messages) {
410
+ const {
411
+ cwd,
412
+ logger
413
+ } = ctx;
414
+ const warnings = messages.filter(msg => msg.logLevel === "warning");
415
+
416
+ if (warnings.length) {
417
+ logger.log();
418
+ }
419
+
420
+ for (const msg of warnings) {
421
+ const sourceFilePath = msg.sourceFilePath && path$1.relative(cwd, msg.sourceFilePath);
422
+
423
+ if (msg.messageId === "TS6307") {
424
+ continue;
425
+ }
426
+
427
+ logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.yellow("warning"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
428
+ }
429
+
430
+ const errors = messages.filter(msg => msg.logLevel === "error");
431
+
432
+ if (!warnings.length && errors.length) {
433
+ logger.log("");
434
+ }
435
+
436
+ for (const msg of errors) {
437
+ const sourceFilePath = msg.sourceFilePath && path$1.relative(cwd, msg.sourceFilePath);
438
+ logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.red("error"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
439
+ }
440
+
441
+ if (errors.length) {
442
+ process.exit(1);
443
+ }
163
444
  }
164
445
 
165
- async function _loadPkgWithReporting(options) {
166
- try {
167
- return await _loadPkg(options);
168
- } catch (err) {
169
- if (err instanceof ZodError) {
170
- for (const issue of err.issues) {
171
- if (issue.code === "invalid_type") {
172
- console.log("".concat(chalk.red("invalid type"), " in ./package.json at ").concat(chalk.magenta("`".concat(issue.path.join("."), "`")), " (expected ").concat(issue.expected, ", received ").concat(issue.received, ")"));
173
- }
446
+ var old = {};
447
+ var hasRequiredOld;
448
+
449
+ function requireOld() {
450
+ if (hasRequiredOld) return old;
451
+ hasRequiredOld = 1; // Copyright Joyent, Inc. and other Node contributors.
452
+ //
453
+ // Permission is hereby granted, free of charge, to any person obtaining a
454
+ // copy of this software and associated documentation files (the
455
+ // "Software"), to deal in the Software without restriction, including
456
+ // without limitation the rights to use, copy, modify, merge, publish,
457
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
458
+ // persons to whom the Software is furnished to do so, subject to the
459
+ // following conditions:
460
+ //
461
+ // The above copyright notice and this permission notice shall be included
462
+ // in all copies or substantial portions of the Software.
463
+ //
464
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
465
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
466
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
467
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
468
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
469
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
470
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
471
+
472
+ var pathModule = path$1;
473
+ var isWindows = process.platform === 'win32';
474
+ var fs = fs$2; // JavaScript implementation of realpath, ported from node pre-v6
475
+
476
+ var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
477
+
478
+ function rethrow() {
479
+ // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
480
+ // is fairly slow to generate.
481
+ var callback;
482
+
483
+ if (DEBUG) {
484
+ var backtrace = new Error();
485
+ callback = debugCallback;
486
+ } else callback = missingCallback;
487
+
488
+ return callback;
489
+
490
+ function debugCallback(err) {
491
+ if (err) {
492
+ backtrace.message = err.message;
493
+ err = backtrace;
494
+ missingCallback(err);
495
+ }
496
+ }
497
+
498
+ function missingCallback(err) {
499
+ if (err) {
500
+ if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
501
+ else if (!process.noDeprecation) {
502
+ var msg = 'fs: missing callback ' + (err.stack || err.message);
503
+ if (process.traceDeprecation) console.trace(msg);else console.error(msg);
504
+ }
505
+ }
506
+ }
507
+ }
508
+
509
+ function maybeCallback(cb) {
510
+ return typeof cb === 'function' ? cb : rethrow();
511
+ } // Regexp that finds the next partion of a (partial) path
512
+ // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
513
+
514
+
515
+ if (isWindows) {
516
+ var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
517
+ } else {
518
+ var nextPartRe = /(.*?)(?:[\/]+|$)/g;
519
+ } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
520
+
521
+
522
+ if (isWindows) {
523
+ var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
524
+ } else {
525
+ var splitRootRe = /^[\/]*/;
526
+ }
527
+
528
+ old.realpathSync = function realpathSync(p, cache) {
529
+ // make p is absolute
530
+ p = pathModule.resolve(p);
531
+
532
+ if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
533
+ return cache[p];
534
+ }
535
+
536
+ var original = p,
537
+ seenLinks = {},
538
+ knownHard = {}; // current character position in p
539
+
540
+ var pos; // the partial path so far, including a trailing slash if any
541
+
542
+ var current; // the partial path without a trailing slash (except when pointing at a root)
543
+
544
+ var base; // the partial path scanned in the previous round, with slash
545
+
546
+ var previous;
547
+ start();
548
+
549
+ function start() {
550
+ // Skip over roots
551
+ var m = splitRootRe.exec(p);
552
+ pos = m[0].length;
553
+ current = m[0];
554
+ base = m[0];
555
+ previous = ''; // On windows, check that the root exists. On unix there is no need.
556
+
557
+ if (isWindows && !knownHard[base]) {
558
+ fs.lstatSync(base);
559
+ knownHard[base] = true;
560
+ }
561
+ } // walk down the path, swapping out linked pathparts for their real
562
+ // values
563
+ // NB: p.length changes.
564
+
565
+
566
+ while (pos < p.length) {
567
+ // find the next part
568
+ nextPartRe.lastIndex = pos;
569
+ var result = nextPartRe.exec(p);
570
+ previous = current;
571
+ current += result[0];
572
+ base = previous + result[1];
573
+ pos = nextPartRe.lastIndex; // continue if not a symlink
574
+
575
+ if (knownHard[base] || cache && cache[base] === base) {
576
+ continue;
577
+ }
578
+
579
+ var resolvedLink;
580
+
581
+ if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
582
+ // some known symbolic link. no need to stat again.
583
+ resolvedLink = cache[base];
584
+ } else {
585
+ var stat = fs.lstatSync(base);
586
+
587
+ if (!stat.isSymbolicLink()) {
588
+ knownHard[base] = true;
589
+ if (cache) cache[base] = base;
590
+ continue;
591
+ } // read the link if it wasn't read before
592
+ // dev/ino always return 0 on windows, so skip the check.
593
+
594
+
595
+ var linkTarget = null;
596
+
597
+ if (!isWindows) {
598
+ var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
599
+
600
+ if (seenLinks.hasOwnProperty(id)) {
601
+ linkTarget = seenLinks[id];
602
+ }
603
+ }
604
+
605
+ if (linkTarget === null) {
606
+ fs.statSync(base);
607
+ linkTarget = fs.readlinkSync(base);
608
+ }
609
+
610
+ resolvedLink = pathModule.resolve(previous, linkTarget); // track this, if given a cache.
611
+
612
+ if (cache) cache[base] = resolvedLink;
613
+ if (!isWindows) seenLinks[id] = linkTarget;
614
+ } // resolve the link, then start over
615
+
616
+
617
+ p = pathModule.resolve(resolvedLink, p.slice(pos));
618
+ start();
619
+ }
620
+
621
+ if (cache) cache[original] = p;
622
+ return p;
623
+ };
624
+
625
+ old.realpath = function realpath(p, cache, cb) {
626
+ if (typeof cb !== 'function') {
627
+ cb = maybeCallback(cache);
628
+ cache = null;
629
+ } // make p is absolute
630
+
631
+
632
+ p = pathModule.resolve(p);
633
+
634
+ if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
635
+ return process.nextTick(cb.bind(null, null, cache[p]));
636
+ }
637
+
638
+ var original = p,
639
+ seenLinks = {},
640
+ knownHard = {}; // current character position in p
641
+
642
+ var pos; // the partial path so far, including a trailing slash if any
643
+
644
+ var current; // the partial path without a trailing slash (except when pointing at a root)
645
+
646
+ var base; // the partial path scanned in the previous round, with slash
647
+
648
+ var previous;
649
+ start();
650
+
651
+ function start() {
652
+ // Skip over roots
653
+ var m = splitRootRe.exec(p);
654
+ pos = m[0].length;
655
+ current = m[0];
656
+ base = m[0];
657
+ previous = ''; // On windows, check that the root exists. On unix there is no need.
658
+
659
+ if (isWindows && !knownHard[base]) {
660
+ fs.lstat(base, function (err) {
661
+ if (err) return cb(err);
662
+ knownHard[base] = true;
663
+ LOOP();
664
+ });
665
+ } else {
666
+ process.nextTick(LOOP);
667
+ }
668
+ } // walk down the path, swapping out linked pathparts for their real
669
+ // values
670
+
671
+
672
+ function LOOP() {
673
+ // stop if scanned past end of path
674
+ if (pos >= p.length) {
675
+ if (cache) cache[original] = p;
676
+ return cb(null, p);
677
+ } // find the next part
678
+
679
+
680
+ nextPartRe.lastIndex = pos;
681
+ var result = nextPartRe.exec(p);
682
+ previous = current;
683
+ current += result[0];
684
+ base = previous + result[1];
685
+ pos = nextPartRe.lastIndex; // continue if not a symlink
686
+
687
+ if (knownHard[base] || cache && cache[base] === base) {
688
+ return process.nextTick(LOOP);
689
+ }
690
+
691
+ if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
692
+ // known symbolic link. no need to stat again.
693
+ return gotResolvedLink(cache[base]);
694
+ }
695
+
696
+ return fs.lstat(base, gotStat);
697
+ }
698
+
699
+ function gotStat(err, stat) {
700
+ if (err) return cb(err); // if not a symlink, skip to the next path part
701
+
702
+ if (!stat.isSymbolicLink()) {
703
+ knownHard[base] = true;
704
+ if (cache) cache[base] = base;
705
+ return process.nextTick(LOOP);
706
+ } // stat & read the link if not read before
707
+ // call gotTarget as soon as the link target is known
708
+ // dev/ino always return 0 on windows, so skip the check.
709
+
710
+
711
+ if (!isWindows) {
712
+ var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
713
+
714
+ if (seenLinks.hasOwnProperty(id)) {
715
+ return gotTarget(null, seenLinks[id], base);
716
+ }
717
+ }
718
+
719
+ fs.stat(base, function (err) {
720
+ if (err) return cb(err);
721
+ fs.readlink(base, function (err, target) {
722
+ if (!isWindows) seenLinks[id] = target;
723
+ gotTarget(err, target);
724
+ });
725
+ });
726
+ }
727
+
728
+ function gotTarget(err, target, base) {
729
+ if (err) return cb(err);
730
+ var resolvedLink = pathModule.resolve(previous, target);
731
+ if (cache) cache[base] = resolvedLink;
732
+ gotResolvedLink(resolvedLink);
733
+ }
734
+
735
+ function gotResolvedLink(resolvedLink) {
736
+ // resolve the link, then start over
737
+ p = pathModule.resolve(resolvedLink, p.slice(pos));
738
+ start();
739
+ }
740
+ };
741
+
742
+ return old;
743
+ }
744
+
745
+ var fs_realpath;
746
+ var hasRequiredFs_realpath;
747
+
748
+ function requireFs_realpath() {
749
+ if (hasRequiredFs_realpath) return fs_realpath;
750
+ hasRequiredFs_realpath = 1;
751
+ fs_realpath = realpath;
752
+ realpath.realpath = realpath;
753
+ realpath.sync = realpathSync;
754
+ realpath.realpathSync = realpathSync;
755
+ realpath.monkeypatch = monkeypatch;
756
+ realpath.unmonkeypatch = unmonkeypatch;
757
+ var fs = fs$2;
758
+ var origRealpath = fs.realpath;
759
+ var origRealpathSync = fs.realpathSync;
760
+ var version = process.version;
761
+ var ok = /^v[0-5]\./.test(version);
762
+ var old = requireOld();
763
+
764
+ function newError(er) {
765
+ return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
766
+ }
767
+
768
+ function realpath(p, cache, cb) {
769
+ if (ok) {
770
+ return origRealpath(p, cache, cb);
771
+ }
772
+
773
+ if (typeof cache === 'function') {
774
+ cb = cache;
775
+ cache = null;
776
+ }
777
+
778
+ origRealpath(p, cache, function (er, result) {
779
+ if (newError(er)) {
780
+ old.realpath(p, cache, cb);
781
+ } else {
782
+ cb(er, result);
783
+ }
784
+ });
785
+ }
786
+
787
+ function realpathSync(p, cache) {
788
+ if (ok) {
789
+ return origRealpathSync(p, cache);
790
+ }
791
+
792
+ try {
793
+ return origRealpathSync(p, cache);
794
+ } catch (er) {
795
+ if (newError(er)) {
796
+ return old.realpathSync(p, cache);
797
+ } else {
798
+ throw er;
799
+ }
800
+ }
801
+ }
802
+
803
+ function monkeypatch() {
804
+ fs.realpath = realpath;
805
+ fs.realpathSync = realpathSync;
806
+ }
807
+
808
+ function unmonkeypatch() {
809
+ fs.realpath = origRealpath;
810
+ fs.realpathSync = origRealpathSync;
811
+ }
812
+
813
+ return fs_realpath;
814
+ }
815
+
816
+ var concatMap;
817
+ var hasRequiredConcatMap;
818
+
819
+ function requireConcatMap() {
820
+ if (hasRequiredConcatMap) return concatMap;
821
+ hasRequiredConcatMap = 1;
822
+
823
+ concatMap = function (xs, fn) {
824
+ var res = [];
825
+
826
+ for (var i = 0; i < xs.length; i++) {
827
+ var x = fn(xs[i], i);
828
+ if (isArray(x)) res.push.apply(res, x);else res.push(x);
829
+ }
830
+
831
+ return res;
832
+ };
833
+
834
+ var isArray = Array.isArray || function (xs) {
835
+ return Object.prototype.toString.call(xs) === '[object Array]';
836
+ };
837
+
838
+ return concatMap;
839
+ }
840
+
841
+ var balancedMatch;
842
+ var hasRequiredBalancedMatch;
843
+
844
+ function requireBalancedMatch() {
845
+ if (hasRequiredBalancedMatch) return balancedMatch;
846
+ hasRequiredBalancedMatch = 1;
847
+ balancedMatch = balanced;
848
+
849
+ function balanced(a, b, str) {
850
+ if (a instanceof RegExp) a = maybeMatch(a, str);
851
+ if (b instanceof RegExp) b = maybeMatch(b, str);
852
+ var r = range(a, b, str);
853
+ return r && {
854
+ start: r[0],
855
+ end: r[1],
856
+ pre: str.slice(0, r[0]),
857
+ body: str.slice(r[0] + a.length, r[1]),
858
+ post: str.slice(r[1] + b.length)
859
+ };
860
+ }
861
+
862
+ function maybeMatch(reg, str) {
863
+ var m = str.match(reg);
864
+ return m ? m[0] : null;
865
+ }
866
+
867
+ balanced.range = range;
868
+
869
+ function range(a, b, str) {
870
+ var begs, beg, left, right, result;
871
+ var ai = str.indexOf(a);
872
+ var bi = str.indexOf(b, ai + 1);
873
+ var i = ai;
874
+
875
+ if (ai >= 0 && bi > 0) {
876
+ if (a === b) {
877
+ return [ai, bi];
878
+ }
879
+
880
+ begs = [];
881
+ left = str.length;
882
+
883
+ while (i >= 0 && !result) {
884
+ if (i == ai) {
885
+ begs.push(i);
886
+ ai = str.indexOf(a, i + 1);
887
+ } else if (begs.length == 1) {
888
+ result = [begs.pop(), bi];
889
+ } else {
890
+ beg = begs.pop();
891
+
892
+ if (beg < left) {
893
+ left = beg;
894
+ right = bi;
895
+ }
896
+
897
+ bi = str.indexOf(b, i + 1);
898
+ }
899
+
900
+ i = ai < bi && ai >= 0 ? ai : bi;
901
+ }
902
+
903
+ if (begs.length) {
904
+ result = [left, right];
905
+ }
906
+ }
907
+
908
+ return result;
909
+ }
910
+
911
+ return balancedMatch;
912
+ }
913
+
914
+ var braceExpansion;
915
+ var hasRequiredBraceExpansion;
916
+
917
+ function requireBraceExpansion() {
918
+ if (hasRequiredBraceExpansion) return braceExpansion;
919
+ hasRequiredBraceExpansion = 1;
920
+ var concatMap = requireConcatMap();
921
+ var balanced = requireBalancedMatch();
922
+ braceExpansion = expandTop;
923
+ var escSlash = '\0SLASH' + Math.random() + '\0';
924
+ var escOpen = '\0OPEN' + Math.random() + '\0';
925
+ var escClose = '\0CLOSE' + Math.random() + '\0';
926
+ var escComma = '\0COMMA' + Math.random() + '\0';
927
+ var escPeriod = '\0PERIOD' + Math.random() + '\0';
928
+
929
+ function numeric(str) {
930
+ return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
931
+ }
932
+
933
+ function escapeBraces(str) {
934
+ return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
935
+ }
936
+
937
+ function unescapeBraces(str) {
938
+ return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
939
+ } // Basically just str.split(","), but handling cases
940
+ // where we have nested braced sections, which should be
941
+ // treated as individual members, like {a,{b,c},d}
942
+
943
+
944
+ function parseCommaParts(str) {
945
+ if (!str) return [''];
946
+ var parts = [];
947
+ var m = balanced('{', '}', str);
948
+ if (!m) return str.split(',');
949
+ var pre = m.pre;
950
+ var body = m.body;
951
+ var post = m.post;
952
+ var p = pre.split(',');
953
+ p[p.length - 1] += '{' + body + '}';
954
+ var postParts = parseCommaParts(post);
955
+
956
+ if (post.length) {
957
+ p[p.length - 1] += postParts.shift();
958
+ p.push.apply(p, postParts);
959
+ }
960
+
961
+ parts.push.apply(parts, p);
962
+ return parts;
963
+ }
964
+
965
+ function expandTop(str) {
966
+ if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
967
+ // Anything starting with {} will have the first two bytes preserved
968
+ // but *only* at the top level, so {},a}b will not expand to anything,
969
+ // but a{},b}c will be expanded to [a}c,abc].
970
+ // One could argue that this is a bug in Bash, but since the goal of
971
+ // this module is to match Bash's rules, we escape a leading {}
972
+
973
+ if (str.substr(0, 2) === '{}') {
974
+ str = '\\{\\}' + str.substr(2);
975
+ }
976
+
977
+ return expand(escapeBraces(str), true).map(unescapeBraces);
978
+ }
979
+
980
+ function embrace(str) {
981
+ return '{' + str + '}';
982
+ }
983
+
984
+ function isPadded(el) {
985
+ return /^-?0\d/.test(el);
986
+ }
987
+
988
+ function lte(i, y) {
989
+ return i <= y;
990
+ }
991
+
992
+ function gte(i, y) {
993
+ return i >= y;
994
+ }
995
+
996
+ function expand(str, isTop) {
997
+ var expansions = [];
998
+ var m = balanced('{', '}', str);
999
+ if (!m || /\$$/.test(m.pre)) return [str];
1000
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
1001
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
1002
+ var isSequence = isNumericSequence || isAlphaSequence;
1003
+ var isOptions = m.body.indexOf(',') >= 0;
1004
+
1005
+ if (!isSequence && !isOptions) {
1006
+ // {a},b}
1007
+ if (m.post.match(/,.*\}/)) {
1008
+ str = m.pre + '{' + m.body + escClose + m.post;
1009
+ return expand(str);
1010
+ }
1011
+
1012
+ return [str];
1013
+ }
1014
+
1015
+ var n;
1016
+
1017
+ if (isSequence) {
1018
+ n = m.body.split(/\.\./);
1019
+ } else {
1020
+ n = parseCommaParts(m.body);
1021
+
1022
+ if (n.length === 1) {
1023
+ // x{{a,b}}y ==> x{a}y x{b}y
1024
+ n = expand(n[0], false).map(embrace);
1025
+
1026
+ if (n.length === 1) {
1027
+ var post = m.post.length ? expand(m.post, false) : [''];
1028
+ return post.map(function (p) {
1029
+ return m.pre + n[0] + p;
1030
+ });
1031
+ }
1032
+ }
1033
+ } // at this point, n is the parts, and we know it's not a comma set
1034
+ // with a single entry.
1035
+ // no need to expand pre, since it is guaranteed to be free of brace-sets
1036
+
1037
+
1038
+ var pre = m.pre;
1039
+ var post = m.post.length ? expand(m.post, false) : [''];
1040
+ var N;
1041
+
1042
+ if (isSequence) {
1043
+ var x = numeric(n[0]);
1044
+ var y = numeric(n[1]);
1045
+ var width = Math.max(n[0].length, n[1].length);
1046
+ var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
1047
+ var test = lte;
1048
+ var reverse = y < x;
1049
+
1050
+ if (reverse) {
1051
+ incr *= -1;
1052
+ test = gte;
1053
+ }
1054
+
1055
+ var pad = n.some(isPadded);
1056
+ N = [];
1057
+
1058
+ for (var i = x; test(i, y); i += incr) {
1059
+ var c;
1060
+
1061
+ if (isAlphaSequence) {
1062
+ c = String.fromCharCode(i);
1063
+ if (c === '\\') c = '';
1064
+ } else {
1065
+ c = String(i);
1066
+
1067
+ if (pad) {
1068
+ var need = width - c.length;
1069
+
1070
+ if (need > 0) {
1071
+ var z = new Array(need + 1).join('0');
1072
+ if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
1073
+ }
1074
+ }
1075
+ }
1076
+
1077
+ N.push(c);
1078
+ }
1079
+ } else {
1080
+ N = concatMap(n, function (el) {
1081
+ return expand(el, false);
1082
+ });
1083
+ }
1084
+
1085
+ for (var j = 0; j < N.length; j++) {
1086
+ for (var k = 0; k < post.length; k++) {
1087
+ var expansion = pre + N[j] + post[k];
1088
+ if (!isTop || isSequence || expansion) expansions.push(expansion);
1089
+ }
1090
+ }
1091
+
1092
+ return expansions;
1093
+ }
1094
+
1095
+ return braceExpansion;
1096
+ }
1097
+
1098
+ var minimatch_1;
1099
+ var hasRequiredMinimatch;
1100
+
1101
+ function requireMinimatch() {
1102
+ if (hasRequiredMinimatch) return minimatch_1;
1103
+ hasRequiredMinimatch = 1;
1104
+ minimatch_1 = minimatch;
1105
+ minimatch.Minimatch = Minimatch;
1106
+
1107
+ var path = function () {
1108
+ try {
1109
+ return require('path');
1110
+ } catch (e) {}
1111
+ }() || {
1112
+ sep: '/'
1113
+ };
1114
+
1115
+ minimatch.sep = path.sep;
1116
+ var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
1117
+ var expand = requireBraceExpansion();
1118
+ var plTypes = {
1119
+ '!': {
1120
+ open: '(?:(?!(?:',
1121
+ close: '))[^/]*?)'
1122
+ },
1123
+ '?': {
1124
+ open: '(?:',
1125
+ close: ')?'
1126
+ },
1127
+ '+': {
1128
+ open: '(?:',
1129
+ close: ')+'
1130
+ },
1131
+ '*': {
1132
+ open: '(?:',
1133
+ close: ')*'
1134
+ },
1135
+ '@': {
1136
+ open: '(?:',
1137
+ close: ')'
1138
+ }
1139
+ }; // any single thing other than /
1140
+ // don't need to escape / when using new RegExp()
1141
+
1142
+ var qmark = '[^/]'; // * => any number of characters
1143
+
1144
+ var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
1145
+ // not (^ or / followed by one or two dots followed by $ or /),
1146
+ // followed by anything, any number of times.
1147
+
1148
+ var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
1149
+ // followed by anything, any number of times.
1150
+
1151
+ var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
1152
+
1153
+ var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
1154
+
1155
+ function charSet(s) {
1156
+ return s.split('').reduce(function (set, c) {
1157
+ set[c] = true;
1158
+ return set;
1159
+ }, {});
1160
+ } // normalizes slashes.
1161
+
1162
+
1163
+ var slashSplit = /\/+/;
1164
+ minimatch.filter = filter;
1165
+
1166
+ function filter(pattern, options) {
1167
+ options = options || {};
1168
+ return function (p, i, list) {
1169
+ return minimatch(p, pattern, options);
1170
+ };
1171
+ }
1172
+
1173
+ function ext(a, b) {
1174
+ b = b || {};
1175
+ var t = {};
1176
+ Object.keys(a).forEach(function (k) {
1177
+ t[k] = a[k];
1178
+ });
1179
+ Object.keys(b).forEach(function (k) {
1180
+ t[k] = b[k];
1181
+ });
1182
+ return t;
1183
+ }
1184
+
1185
+ minimatch.defaults = function (def) {
1186
+ if (!def || typeof def !== 'object' || !Object.keys(def).length) {
1187
+ return minimatch;
1188
+ }
1189
+
1190
+ var orig = minimatch;
1191
+
1192
+ var m = function minimatch(p, pattern, options) {
1193
+ return orig(p, pattern, ext(def, options));
1194
+ };
1195
+
1196
+ m.Minimatch = function Minimatch(pattern, options) {
1197
+ return new orig.Minimatch(pattern, ext(def, options));
1198
+ };
1199
+
1200
+ m.Minimatch.defaults = function defaults(options) {
1201
+ return orig.defaults(ext(def, options)).Minimatch;
1202
+ };
1203
+
1204
+ m.filter = function filter(pattern, options) {
1205
+ return orig.filter(pattern, ext(def, options));
1206
+ };
1207
+
1208
+ m.defaults = function defaults(options) {
1209
+ return orig.defaults(ext(def, options));
1210
+ };
1211
+
1212
+ m.makeRe = function makeRe(pattern, options) {
1213
+ return orig.makeRe(pattern, ext(def, options));
1214
+ };
1215
+
1216
+ m.braceExpand = function braceExpand(pattern, options) {
1217
+ return orig.braceExpand(pattern, ext(def, options));
1218
+ };
1219
+
1220
+ m.match = function (list, pattern, options) {
1221
+ return orig.match(list, pattern, ext(def, options));
1222
+ };
1223
+
1224
+ return m;
1225
+ };
1226
+
1227
+ Minimatch.defaults = function (def) {
1228
+ return minimatch.defaults(def).Minimatch;
1229
+ };
1230
+
1231
+ function minimatch(p, pattern, options) {
1232
+ assertValidPattern(pattern);
1233
+ if (!options) options = {}; // shortcut: comments match nothing.
1234
+
1235
+ if (!options.nocomment && pattern.charAt(0) === '#') {
1236
+ return false;
1237
+ }
1238
+
1239
+ return new Minimatch(pattern, options).match(p);
1240
+ }
1241
+
1242
+ function Minimatch(pattern, options) {
1243
+ if (!(this instanceof Minimatch)) {
1244
+ return new Minimatch(pattern, options);
1245
+ }
1246
+
1247
+ assertValidPattern(pattern);
1248
+ if (!options) options = {};
1249
+ pattern = pattern.trim(); // windows support: need to use /, not \
1250
+
1251
+ if (!options.allowWindowsEscape && path.sep !== '/') {
1252
+ pattern = pattern.split(path.sep).join('/');
1253
+ }
1254
+
1255
+ this.options = options;
1256
+ this.set = [];
1257
+ this.pattern = pattern;
1258
+ this.regexp = null;
1259
+ this.negate = false;
1260
+ this.comment = false;
1261
+ this.empty = false;
1262
+ this.partial = !!options.partial; // make the set of regexps etc.
1263
+
1264
+ this.make();
1265
+ }
1266
+
1267
+ Minimatch.prototype.debug = function () {};
1268
+
1269
+ Minimatch.prototype.make = make;
1270
+
1271
+ function make() {
1272
+ var pattern = this.pattern;
1273
+ var options = this.options; // empty patterns and comments match nothing.
1274
+
1275
+ if (!options.nocomment && pattern.charAt(0) === '#') {
1276
+ this.comment = true;
1277
+ return;
1278
+ }
1279
+
1280
+ if (!pattern) {
1281
+ this.empty = true;
1282
+ return;
1283
+ } // step 1: figure out negation, etc.
1284
+
1285
+
1286
+ this.parseNegate(); // step 2: expand braces
1287
+
1288
+ var set = this.globSet = this.braceExpand();
1289
+ if (options.debug) this.debug = function debug() {
1290
+ console.error.apply(console, arguments);
1291
+ };
1292
+ this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
1293
+ // matching patterns.
1294
+ // These will be regexps, except in the case of "**", which is
1295
+ // set to the GLOBSTAR object for globstar behavior,
1296
+ // and will not contain any / characters
1297
+
1298
+ set = this.globParts = set.map(function (s) {
1299
+ return s.split(slashSplit);
1300
+ });
1301
+ this.debug(this.pattern, set); // glob --> regexps
1302
+
1303
+ set = set.map(function (s, si, set) {
1304
+ return s.map(this.parse, this);
1305
+ }, this);
1306
+ this.debug(this.pattern, set); // filter out everything that didn't compile properly.
1307
+
1308
+ set = set.filter(function (s) {
1309
+ return s.indexOf(false) === -1;
1310
+ });
1311
+ this.debug(this.pattern, set);
1312
+ this.set = set;
1313
+ }
1314
+
1315
+ Minimatch.prototype.parseNegate = parseNegate;
1316
+
1317
+ function parseNegate() {
1318
+ var pattern = this.pattern;
1319
+ var negate = false;
1320
+ var options = this.options;
1321
+ var negateOffset = 0;
1322
+ if (options.nonegate) return;
1323
+
1324
+ for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
1325
+ negate = !negate;
1326
+ negateOffset++;
1327
+ }
1328
+
1329
+ if (negateOffset) this.pattern = pattern.substr(negateOffset);
1330
+ this.negate = negate;
1331
+ } // Brace expansion:
1332
+ // a{b,c}d -> abd acd
1333
+ // a{b,}c -> abc ac
1334
+ // a{0..3}d -> a0d a1d a2d a3d
1335
+ // a{b,c{d,e}f}g -> abg acdfg acefg
1336
+ // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
1337
+ //
1338
+ // Invalid sets are not expanded.
1339
+ // a{2..}b -> a{2..}b
1340
+ // a{b}c -> a{b}c
1341
+
1342
+
1343
+ minimatch.braceExpand = function (pattern, options) {
1344
+ return braceExpand(pattern, options);
1345
+ };
1346
+
1347
+ Minimatch.prototype.braceExpand = braceExpand;
1348
+
1349
+ function braceExpand(pattern, options) {
1350
+ if (!options) {
1351
+ if (this instanceof Minimatch) {
1352
+ options = this.options;
1353
+ } else {
1354
+ options = {};
1355
+ }
1356
+ }
1357
+
1358
+ pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
1359
+ assertValidPattern(pattern); // Thanks to Yeting Li <https://github.com/yetingli> for
1360
+ // improving this regexp to avoid a ReDOS vulnerability.
1361
+
1362
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
1363
+ // shortcut. no need to expand.
1364
+ return [pattern];
1365
+ }
1366
+
1367
+ return expand(pattern);
1368
+ }
1369
+
1370
+ var MAX_PATTERN_LENGTH = 1024 * 64;
1371
+
1372
+ var assertValidPattern = function (pattern) {
1373
+ if (typeof pattern !== 'string') {
1374
+ throw new TypeError('invalid pattern');
1375
+ }
1376
+
1377
+ if (pattern.length > MAX_PATTERN_LENGTH) {
1378
+ throw new TypeError('pattern is too long');
1379
+ }
1380
+ }; // parse a component of the expanded set.
1381
+ // At this point, no pattern may contain "/" in it
1382
+ // so we're going to return a 2d array, where each entry is the full
1383
+ // pattern, split on '/', and then turned into a regular expression.
1384
+ // A regexp is made at the end which joins each array with an
1385
+ // escaped /, and another full one which joins each regexp with |.
1386
+ //
1387
+ // Following the lead of Bash 4.1, note that "**" only has special meaning
1388
+ // when it is the *only* thing in a path portion. Otherwise, any series
1389
+ // of * is equivalent to a single *. Globstar behavior is enabled by
1390
+ // default, and can be disabled by setting options.noglobstar.
1391
+
1392
+
1393
+ Minimatch.prototype.parse = parse;
1394
+ var SUBPARSE = {};
1395
+
1396
+ function parse(pattern, isSub) {
1397
+ assertValidPattern(pattern);
1398
+ var options = this.options; // shortcuts
1399
+
1400
+ if (pattern === '**') {
1401
+ if (!options.noglobstar) return GLOBSTAR;else pattern = '*';
1402
+ }
1403
+
1404
+ if (pattern === '') return '';
1405
+ var re = '';
1406
+ var hasMagic = !!options.nocase;
1407
+ var escaping = false; // ? => one single character
1408
+
1409
+ var patternListStack = [];
1410
+ var negativeLists = [];
1411
+ var stateChar;
1412
+ var inClass = false;
1413
+ var reClassStart = -1;
1414
+ var classStart = -1; // . and .. never match anything that doesn't start with .,
1415
+ // even when options.dot is set.
1416
+
1417
+ var patternStart = pattern.charAt(0) === '.' ? '' // anything
1418
+ // not (start or / followed by . or .. followed by / or end)
1419
+ : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
1420
+ var self = this;
1421
+
1422
+ function clearStateChar() {
1423
+ if (stateChar) {
1424
+ // we had some state-tracking character
1425
+ // that wasn't consumed by this pass.
1426
+ switch (stateChar) {
1427
+ case '*':
1428
+ re += star;
1429
+ hasMagic = true;
1430
+ break;
1431
+
1432
+ case '?':
1433
+ re += qmark;
1434
+ hasMagic = true;
1435
+ break;
1436
+
1437
+ default:
1438
+ re += '\\' + stateChar;
1439
+ break;
1440
+ }
1441
+
1442
+ self.debug('clearStateChar %j %j', stateChar, re);
1443
+ stateChar = false;
1444
+ }
1445
+ }
1446
+
1447
+ for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
1448
+ this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
1449
+
1450
+ if (escaping && reSpecials[c]) {
1451
+ re += '\\' + c;
1452
+ escaping = false;
1453
+ continue;
1454
+ }
1455
+
1456
+ switch (c) {
1457
+ /* istanbul ignore next */
1458
+ case '/':
1459
+ {
1460
+ // completely not allowed, even escaped.
1461
+ // Should already be path-split by now.
1462
+ return false;
1463
+ }
1464
+
1465
+ case '\\':
1466
+ clearStateChar();
1467
+ escaping = true;
1468
+ continue;
1469
+ // the various stateChar values
1470
+ // for the "extglob" stuff.
1471
+
1472
+ case '?':
1473
+ case '*':
1474
+ case '+':
1475
+ case '@':
1476
+ case '!':
1477
+ this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
1478
+ // the glob [!a] means [^a] in regexp
1479
+
1480
+ if (inClass) {
1481
+ this.debug(' in class');
1482
+ if (c === '!' && i === classStart + 1) c = '^';
1483
+ re += c;
1484
+ continue;
1485
+ } // if we already have a stateChar, then it means
1486
+ // that there was something like ** or +? in there.
1487
+ // Handle the stateChar, then proceed with this one.
1488
+
1489
+
1490
+ self.debug('call clearStateChar %j', stateChar);
1491
+ clearStateChar();
1492
+ stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
1493
+ // just clear the statechar *now*, rather than even diving into
1494
+ // the patternList stuff.
1495
+
1496
+ if (options.noext) clearStateChar();
1497
+ continue;
1498
+
1499
+ case '(':
1500
+ if (inClass) {
1501
+ re += '(';
1502
+ continue;
1503
+ }
1504
+
1505
+ if (!stateChar) {
1506
+ re += '\\(';
1507
+ continue;
1508
+ }
1509
+
1510
+ patternListStack.push({
1511
+ type: stateChar,
1512
+ start: i - 1,
1513
+ reStart: re.length,
1514
+ open: plTypes[stateChar].open,
1515
+ close: plTypes[stateChar].close
1516
+ }); // negation is (?:(?!js)[^/]*)
1517
+
1518
+ re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
1519
+ this.debug('plType %j %j', stateChar, re);
1520
+ stateChar = false;
1521
+ continue;
1522
+
1523
+ case ')':
1524
+ if (inClass || !patternListStack.length) {
1525
+ re += '\\)';
1526
+ continue;
1527
+ }
1528
+
1529
+ clearStateChar();
1530
+ hasMagic = true;
1531
+ var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
1532
+ // The others are (?:<pattern>)<type>
1533
+
1534
+ re += pl.close;
1535
+
1536
+ if (pl.type === '!') {
1537
+ negativeLists.push(pl);
1538
+ }
1539
+
1540
+ pl.reEnd = re.length;
1541
+ continue;
1542
+
1543
+ case '|':
1544
+ if (inClass || !patternListStack.length || escaping) {
1545
+ re += '\\|';
1546
+ escaping = false;
1547
+ continue;
1548
+ }
1549
+
1550
+ clearStateChar();
1551
+ re += '|';
1552
+ continue;
1553
+ // these are mostly the same in regexp and glob
1554
+
1555
+ case '[':
1556
+ // swallow any state-tracking char before the [
1557
+ clearStateChar();
1558
+
1559
+ if (inClass) {
1560
+ re += '\\' + c;
1561
+ continue;
1562
+ }
1563
+
1564
+ inClass = true;
1565
+ classStart = i;
1566
+ reClassStart = re.length;
1567
+ re += c;
1568
+ continue;
1569
+
1570
+ case ']':
1571
+ // a right bracket shall lose its special
1572
+ // meaning and represent itself in
1573
+ // a bracket expression if it occurs
1574
+ // first in the list. -- POSIX.2 2.8.3.2
1575
+ if (i === classStart + 1 || !inClass) {
1576
+ re += '\\' + c;
1577
+ escaping = false;
1578
+ continue;
1579
+ } // handle the case where we left a class open.
1580
+ // "[z-a]" is valid, equivalent to "\[z-a\]"
1581
+ // split where the last [ was, make sure we don't have
1582
+ // an invalid re. if so, re-walk the contents of the
1583
+ // would-be class to re-translate any characters that
1584
+ // were passed through as-is
1585
+ // TODO: It would probably be faster to determine this
1586
+ // without a try/catch and a new RegExp, but it's tricky
1587
+ // to do safely. For now, this is safe and works.
1588
+
1589
+
1590
+ var cs = pattern.substring(classStart + 1, i);
1591
+
1592
+ try {
1593
+ RegExp('[' + cs + ']');
1594
+ } catch (er) {
1595
+ // not a valid class!
1596
+ var sp = this.parse(cs, SUBPARSE);
1597
+ re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
1598
+ hasMagic = hasMagic || sp[1];
1599
+ inClass = false;
1600
+ continue;
1601
+ } // finish up the class.
1602
+
1603
+
1604
+ hasMagic = true;
1605
+ inClass = false;
1606
+ re += c;
1607
+ continue;
1608
+
1609
+ default:
1610
+ // swallow any state char that wasn't consumed
1611
+ clearStateChar();
1612
+
1613
+ if (escaping) {
1614
+ // no need
1615
+ escaping = false;
1616
+ } else if (reSpecials[c] && !(c === '^' && inClass)) {
1617
+ re += '\\';
1618
+ }
1619
+
1620
+ re += c;
1621
+ } // switch
1622
+
1623
+ } // for
1624
+ // handle the case where we left a class open.
1625
+ // "[abc" is valid, equivalent to "\[abc"
1626
+
1627
+
1628
+ if (inClass) {
1629
+ // split where the last [ was, and escape it
1630
+ // this is a huge pita. We now have to re-walk
1631
+ // the contents of the would-be class to re-translate
1632
+ // any characters that were passed through as-is
1633
+ cs = pattern.substr(classStart + 1);
1634
+ sp = this.parse(cs, SUBPARSE);
1635
+ re = re.substr(0, reClassStart) + '\\[' + sp[0];
1636
+ hasMagic = hasMagic || sp[1];
1637
+ } // handle the case where we had a +( thing at the *end*
1638
+ // of the pattern.
1639
+ // each pattern list stack adds 3 chars, and we need to go through
1640
+ // and escape any | chars that were passed through as-is for the regexp.
1641
+ // Go through and escape them, taking care not to double-escape any
1642
+ // | chars that were already escaped.
1643
+
1644
+
1645
+ for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
1646
+ var tail = re.slice(pl.reStart + pl.open.length);
1647
+ this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
1648
+
1649
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
1650
+ if (!$2) {
1651
+ // the | isn't already escaped, so escape it.
1652
+ $2 = '\\';
1653
+ } // need to escape all those slashes *again*, without escaping the
1654
+ // one that we need for escaping the | character. As it works out,
1655
+ // escaping an even number of slashes can be done by simply repeating
1656
+ // it exactly after itself. That's why this trick works.
1657
+ //
1658
+ // I am sorry that you have to see this.
1659
+
1660
+
1661
+ return $1 + $1 + $2 + '|';
1662
+ });
1663
+ this.debug('tail=%j\n %s', tail, tail, pl, re);
1664
+ var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
1665
+ hasMagic = true;
1666
+ re = re.slice(0, pl.reStart) + t + '\\(' + tail;
1667
+ } // handle trailing things that only matter at the very end.
1668
+
1669
+
1670
+ clearStateChar();
1671
+
1672
+ if (escaping) {
1673
+ // trailing \\
1674
+ re += '\\\\';
1675
+ } // only need to apply the nodot start if the re starts with
1676
+ // something that could conceivably capture a dot
1677
+
1678
+
1679
+ var addPatternStart = false;
1680
+
1681
+ switch (re.charAt(0)) {
1682
+ case '[':
1683
+ case '.':
1684
+ case '(':
1685
+ addPatternStart = true;
1686
+ } // Hack to work around lack of negative lookbehind in JS
1687
+ // A pattern like: *.!(x).!(y|z) needs to ensure that a name
1688
+ // like 'a.xyz.yz' doesn't match. So, the first negative
1689
+ // lookahead, has to look ALL the way ahead, to the end of
1690
+ // the pattern.
1691
+
1692
+
1693
+ for (var n = negativeLists.length - 1; n > -1; n--) {
1694
+ var nl = negativeLists[n];
1695
+ var nlBefore = re.slice(0, nl.reStart);
1696
+ var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
1697
+ var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
1698
+ var nlAfter = re.slice(nl.reEnd);
1699
+ nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
1700
+ // mean that we should *not* include the ) in the bit that is considered
1701
+ // "after" the negated section.
1702
+
1703
+ var openParensBefore = nlBefore.split('(').length - 1;
1704
+ var cleanAfter = nlAfter;
1705
+
1706
+ for (i = 0; i < openParensBefore; i++) {
1707
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
1708
+ }
1709
+
1710
+ nlAfter = cleanAfter;
1711
+ var dollar = '';
1712
+
1713
+ if (nlAfter === '' && isSub !== SUBPARSE) {
1714
+ dollar = '$';
1715
+ }
1716
+
1717
+ var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
1718
+ re = newRe;
1719
+ } // if the re is not "" at this point, then we need to make sure
1720
+ // it doesn't match against an empty path part.
1721
+ // Otherwise a/* will match a/, which it should not.
1722
+
1723
+
1724
+ if (re !== '' && hasMagic) {
1725
+ re = '(?=.)' + re;
1726
+ }
1727
+
1728
+ if (addPatternStart) {
1729
+ re = patternStart + re;
1730
+ } // parsing just a piece of a larger pattern.
1731
+
1732
+
1733
+ if (isSub === SUBPARSE) {
1734
+ return [re, hasMagic];
1735
+ } // skip the regexp for non-magical patterns
1736
+ // unescape anything in it, though, so that it'll be
1737
+ // an exact match against a file etc.
1738
+
1739
+
1740
+ if (!hasMagic) {
1741
+ return globUnescape(pattern);
1742
+ }
1743
+
1744
+ var flags = options.nocase ? 'i' : '';
1745
+
1746
+ try {
1747
+ var regExp = new RegExp('^' + re + '$', flags);
1748
+ } catch (er)
1749
+ /* istanbul ignore next - should be impossible */
1750
+ {
1751
+ // If it was an invalid regular expression, then it can't match
1752
+ // anything. This trick looks for a character after the end of
1753
+ // the string, which is of course impossible, except in multi-line
1754
+ // mode, but it's not a /m regex.
1755
+ return new RegExp('$.');
1756
+ }
1757
+
1758
+ regExp._glob = pattern;
1759
+ regExp._src = re;
1760
+ return regExp;
1761
+ }
1762
+
1763
+ minimatch.makeRe = function (pattern, options) {
1764
+ return new Minimatch(pattern, options || {}).makeRe();
1765
+ };
1766
+
1767
+ Minimatch.prototype.makeRe = makeRe;
1768
+
1769
+ function makeRe() {
1770
+ if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
1771
+ // pattern strings, or "**".
1772
+ //
1773
+ // It's better to use .match(). This function shouldn't
1774
+ // be used, really, but it's pretty convenient sometimes,
1775
+ // when you just want to work with a regex.
1776
+
1777
+ var set = this.set;
1778
+
1779
+ if (!set.length) {
1780
+ this.regexp = false;
1781
+ return this.regexp;
1782
+ }
1783
+
1784
+ var options = this.options;
1785
+ var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
1786
+ var flags = options.nocase ? 'i' : '';
1787
+ var re = set.map(function (pattern) {
1788
+ return pattern.map(function (p) {
1789
+ return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
1790
+ }).join('\\\/');
1791
+ }).join('|'); // must match entire pattern
1792
+ // ending in a * or ** will make it less strict.
1793
+
1794
+ re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
1795
+
1796
+ if (this.negate) re = '^(?!' + re + ').*$';
1797
+
1798
+ try {
1799
+ this.regexp = new RegExp(re, flags);
1800
+ } catch (ex)
1801
+ /* istanbul ignore next - should be impossible */
1802
+ {
1803
+ this.regexp = false;
1804
+ }
1805
+
1806
+ return this.regexp;
1807
+ }
1808
+
1809
+ minimatch.match = function (list, pattern, options) {
1810
+ options = options || {};
1811
+ var mm = new Minimatch(pattern, options);
1812
+ list = list.filter(function (f) {
1813
+ return mm.match(f);
1814
+ });
1815
+
1816
+ if (mm.options.nonull && !list.length) {
1817
+ list.push(pattern);
1818
+ }
1819
+
1820
+ return list;
1821
+ };
1822
+
1823
+ Minimatch.prototype.match = function match(f, partial) {
1824
+ if (typeof partial === 'undefined') partial = this.partial;
1825
+ this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
1826
+ // comments, etc.
1827
+
1828
+ if (this.comment) return false;
1829
+ if (this.empty) return f === '';
1830
+ if (f === '/' && partial) return true;
1831
+ var options = this.options; // windows: need to use /, not \
1832
+
1833
+ if (path.sep !== '/') {
1834
+ f = f.split(path.sep).join('/');
1835
+ } // treat the test path as a set of pathparts.
1836
+
1837
+
1838
+ f = f.split(slashSplit);
1839
+ this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
1840
+ // in order for it to be valid. If negating, then just one
1841
+ // match means that we have failed.
1842
+ // Either way, return on the first hit.
1843
+
1844
+ var set = this.set;
1845
+ this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
1846
+
1847
+ var filename;
1848
+ var i;
1849
+
1850
+ for (i = f.length - 1; i >= 0; i--) {
1851
+ filename = f[i];
1852
+ if (filename) break;
1853
+ }
1854
+
1855
+ for (i = 0; i < set.length; i++) {
1856
+ var pattern = set[i];
1857
+ var file = f;
1858
+
1859
+ if (options.matchBase && pattern.length === 1) {
1860
+ file = [filename];
1861
+ }
1862
+
1863
+ var hit = this.matchOne(file, pattern, partial);
1864
+
1865
+ if (hit) {
1866
+ if (options.flipNegate) return true;
1867
+ return !this.negate;
1868
+ }
1869
+ } // didn't get any hits. this is success if it's a negative
1870
+ // pattern, failure otherwise.
1871
+
1872
+
1873
+ if (options.flipNegate) return false;
1874
+ return this.negate;
1875
+ }; // set partial to true to test if, for example,
1876
+ // "/a/b" matches the start of "/*/b/*/d"
1877
+ // Partial means, if you run out of file before you run
1878
+ // out of pattern, then that's fine, as long as all
1879
+ // the parts match.
1880
+
1881
+
1882
+ Minimatch.prototype.matchOne = function (file, pattern, partial) {
1883
+ var options = this.options;
1884
+ this.debug('matchOne', {
1885
+ 'this': this,
1886
+ file: file,
1887
+ pattern: pattern
1888
+ });
1889
+ this.debug('matchOne', file.length, pattern.length);
1890
+
1891
+ for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
1892
+ this.debug('matchOne loop');
1893
+ var p = pattern[pi];
1894
+ var f = file[fi];
1895
+ this.debug(pattern, p, f); // should be impossible.
1896
+ // some invalid regexp stuff in the set.
1897
+
1898
+ /* istanbul ignore if */
1899
+
1900
+ if (p === false) return false;
1901
+
1902
+ if (p === GLOBSTAR) {
1903
+ this.debug('GLOBSTAR', [pattern, p, f]); // "**"
1904
+ // a/**/b/**/c would match the following:
1905
+ // a/b/x/y/z/c
1906
+ // a/x/y/z/b/c
1907
+ // a/b/x/b/x/c
1908
+ // a/b/c
1909
+ // To do this, take the rest of the pattern after
1910
+ // the **, and see if it would match the file remainder.
1911
+ // If so, return success.
1912
+ // If not, the ** "swallows" a segment, and try again.
1913
+ // This is recursively awful.
1914
+ //
1915
+ // a/**/b/**/c matching a/b/x/y/z/c
1916
+ // - a matches a
1917
+ // - doublestar
1918
+ // - matchOne(b/x/y/z/c, b/**/c)
1919
+ // - b matches b
1920
+ // - doublestar
1921
+ // - matchOne(x/y/z/c, c) -> no
1922
+ // - matchOne(y/z/c, c) -> no
1923
+ // - matchOne(z/c, c) -> no
1924
+ // - matchOne(c, c) yes, hit
1925
+
1926
+ var fr = fi;
1927
+ var pr = pi + 1;
1928
+
1929
+ if (pr === pl) {
1930
+ this.debug('** at the end'); // a ** at the end will just swallow the rest.
1931
+ // We have found a match.
1932
+ // however, it will not swallow /.x, unless
1933
+ // options.dot is set.
1934
+ // . and .. are *never* matched by **, for explosively
1935
+ // exponential reasons.
1936
+
1937
+ for (; fi < fl; fi++) {
1938
+ if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
1939
+ }
1940
+
1941
+ return true;
1942
+ } // ok, let's see if we can swallow whatever we can.
1943
+
1944
+
1945
+ while (fr < fl) {
1946
+ var swallowee = file[fr];
1947
+ this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
1948
+
1949
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
1950
+ this.debug('globstar found match!', fr, fl, swallowee); // found a match.
1951
+
1952
+ return true;
1953
+ } else {
1954
+ // can't swallow "." or ".." ever.
1955
+ // can only swallow ".foo" when explicitly asked.
1956
+ if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
1957
+ this.debug('dot detected!', file, fr, pattern, pr);
1958
+ break;
1959
+ } // ** swallows a segment, and continue.
1960
+
1961
+
1962
+ this.debug('globstar swallow a segment, and continue');
1963
+ fr++;
1964
+ }
1965
+ } // no match was found.
1966
+ // However, in partial mode, we can't say this is necessarily over.
1967
+ // If there's more *pattern* left, then
1968
+
1969
+ /* istanbul ignore if */
1970
+
1971
+
1972
+ if (partial) {
1973
+ // ran out of file
1974
+ this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
1975
+ if (fr === fl) return true;
1976
+ }
1977
+
1978
+ return false;
1979
+ } // something other than **
1980
+ // non-magic patterns just have to match exactly
1981
+ // patterns with magic have been turned into regexps.
1982
+
1983
+
1984
+ var hit;
1985
+
1986
+ if (typeof p === 'string') {
1987
+ hit = f === p;
1988
+ this.debug('string match', p, f, hit);
1989
+ } else {
1990
+ hit = f.match(p);
1991
+ this.debug('pattern match', p, f, hit);
1992
+ }
1993
+
1994
+ if (!hit) return false;
1995
+ } // Note: ending in / means that we'll get a final ""
1996
+ // at the end of the pattern. This can only match a
1997
+ // corresponding "" at the end of the file.
1998
+ // If the file ends in /, then it can only match a
1999
+ // a pattern that ends in /, unless the pattern just
2000
+ // doesn't have any more for it. But, a/b/ should *not*
2001
+ // match "a/b/*", even though "" matches against the
2002
+ // [^/]*? pattern, except in partial mode, where it might
2003
+ // simply not be reached yet.
2004
+ // However, a/b/ should still satisfy a/*
2005
+ // now either we fell off the end of the pattern, or we're done.
2006
+
2007
+
2008
+ if (fi === fl && pi === pl) {
2009
+ // ran out of pattern and filename at the same time.
2010
+ // an exact hit!
2011
+ return true;
2012
+ } else if (fi === fl) {
2013
+ // ran out of file, but still had pattern left.
2014
+ // this is ok if we're doing the match as part of
2015
+ // a glob fs traversal.
2016
+ return partial;
2017
+ } else
2018
+ /* istanbul ignore else */
2019
+ if (pi === pl) {
2020
+ // ran out of pattern, still have file left.
2021
+ // this is only acceptable if we're on the very last
2022
+ // empty segment of a file with a trailing slash.
2023
+ // a/* should match a/b/
2024
+ return fi === fl - 1 && file[fi] === '';
2025
+ } // should be unreachable.
2026
+
2027
+ /* istanbul ignore next */
2028
+
2029
+
2030
+ throw new Error('wtf?');
2031
+ }; // replace stuff like \* with *
2032
+
2033
+
2034
+ function globUnescape(s) {
2035
+ return s.replace(/\\(.)/g, '$1');
2036
+ }
2037
+
2038
+ function regExpEscape(s) {
2039
+ return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
2040
+ }
2041
+
2042
+ return minimatch_1;
2043
+ }
2044
+
2045
+ var inherits = {
2046
+ exports: {}
2047
+ };
2048
+ var inherits_browser = {
2049
+ exports: {}
2050
+ };
2051
+ var hasRequiredInherits_browser;
2052
+
2053
+ function requireInherits_browser() {
2054
+ if (hasRequiredInherits_browser) return inherits_browser.exports;
2055
+ hasRequiredInherits_browser = 1;
2056
+
2057
+ if (typeof Object.create === 'function') {
2058
+ // implementation from standard node.js 'util' module
2059
+ inherits_browser.exports = function inherits(ctor, superCtor) {
2060
+ if (superCtor) {
2061
+ ctor.super_ = superCtor;
2062
+ ctor.prototype = Object.create(superCtor.prototype, {
2063
+ constructor: {
2064
+ value: ctor,
2065
+ enumerable: false,
2066
+ writable: true,
2067
+ configurable: true
2068
+ }
2069
+ });
2070
+ }
2071
+ };
2072
+ } else {
2073
+ // old school shim for old browsers
2074
+ inherits_browser.exports = function inherits(ctor, superCtor) {
2075
+ if (superCtor) {
2076
+ ctor.super_ = superCtor;
2077
+
2078
+ var TempCtor = function () {};
2079
+
2080
+ TempCtor.prototype = superCtor.prototype;
2081
+ ctor.prototype = new TempCtor();
2082
+ ctor.prototype.constructor = ctor;
2083
+ }
2084
+ };
2085
+ }
2086
+
2087
+ return inherits_browser.exports;
2088
+ }
2089
+
2090
+ var hasRequiredInherits;
2091
+
2092
+ function requireInherits() {
2093
+ if (hasRequiredInherits) return inherits.exports;
2094
+ hasRequiredInherits = 1;
2095
+
2096
+ (function (module) {
2097
+ try {
2098
+ var util = require('util');
2099
+ /* istanbul ignore next */
2100
+
2101
+
2102
+ if (typeof util.inherits !== 'function') throw '';
2103
+ module.exports = util.inherits;
2104
+ } catch (e) {
2105
+ /* istanbul ignore next */
2106
+ module.exports = requireInherits_browser();
2107
+ }
2108
+ })(inherits);
2109
+
2110
+ return inherits.exports;
2111
+ }
2112
+
2113
+ var pathIsAbsolute = {
2114
+ exports: {}
2115
+ };
2116
+ var hasRequiredPathIsAbsolute;
2117
+
2118
+ function requirePathIsAbsolute() {
2119
+ if (hasRequiredPathIsAbsolute) return pathIsAbsolute.exports;
2120
+ hasRequiredPathIsAbsolute = 1;
2121
+
2122
+ function posix(path) {
2123
+ return path.charAt(0) === '/';
2124
+ }
2125
+
2126
+ function win32(path) {
2127
+ // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
2128
+ var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
2129
+ var result = splitDeviceRe.exec(path);
2130
+ var device = result[1] || '';
2131
+ var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
2132
+
2133
+ return Boolean(result[2] || isUnc);
2134
+ }
2135
+
2136
+ pathIsAbsolute.exports = process.platform === 'win32' ? win32 : posix;
2137
+ pathIsAbsolute.exports.posix = posix;
2138
+ pathIsAbsolute.exports.win32 = win32;
2139
+ return pathIsAbsolute.exports;
2140
+ }
2141
+
2142
+ var common = {};
2143
+ var hasRequiredCommon;
2144
+
2145
+ function requireCommon() {
2146
+ if (hasRequiredCommon) return common;
2147
+ hasRequiredCommon = 1;
2148
+ common.setopts = setopts;
2149
+ common.ownProp = ownProp;
2150
+ common.makeAbs = makeAbs;
2151
+ common.finish = finish;
2152
+ common.mark = mark;
2153
+ common.isIgnored = isIgnored;
2154
+ common.childrenIgnored = childrenIgnored;
2155
+
2156
+ function ownProp(obj, field) {
2157
+ return Object.prototype.hasOwnProperty.call(obj, field);
2158
+ }
2159
+
2160
+ var fs = fs$2;
2161
+ var path = path$1;
2162
+ var minimatch = requireMinimatch();
2163
+ var isAbsolute = requirePathIsAbsolute();
2164
+ var Minimatch = minimatch.Minimatch;
2165
+
2166
+ function alphasort(a, b) {
2167
+ return a.localeCompare(b, 'en');
2168
+ }
2169
+
2170
+ function setupIgnores(self, options) {
2171
+ self.ignore = options.ignore || [];
2172
+ if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
2173
+
2174
+ if (self.ignore.length) {
2175
+ self.ignore = self.ignore.map(ignoreMap);
2176
+ }
2177
+ } // ignore patterns are always in dot:true mode.
2178
+
2179
+
2180
+ function ignoreMap(pattern) {
2181
+ var gmatcher = null;
2182
+
2183
+ if (pattern.slice(-3) === '/**') {
2184
+ var gpattern = pattern.replace(/(\/\*\*)+$/, '');
2185
+ gmatcher = new Minimatch(gpattern, {
2186
+ dot: true
2187
+ });
2188
+ }
2189
+
2190
+ return {
2191
+ matcher: new Minimatch(pattern, {
2192
+ dot: true
2193
+ }),
2194
+ gmatcher: gmatcher
2195
+ };
2196
+ }
2197
+
2198
+ function setopts(self, pattern, options) {
2199
+ if (!options) options = {}; // base-matching: just use globstar for that.
2200
+
2201
+ if (options.matchBase && -1 === pattern.indexOf("/")) {
2202
+ if (options.noglobstar) {
2203
+ throw new Error("base matching requires globstar");
2204
+ }
2205
+
2206
+ pattern = "**/" + pattern;
2207
+ }
2208
+
2209
+ self.silent = !!options.silent;
2210
+ self.pattern = pattern;
2211
+ self.strict = options.strict !== false;
2212
+ self.realpath = !!options.realpath;
2213
+ self.realpathCache = options.realpathCache || Object.create(null);
2214
+ self.follow = !!options.follow;
2215
+ self.dot = !!options.dot;
2216
+ self.mark = !!options.mark;
2217
+ self.nodir = !!options.nodir;
2218
+ if (self.nodir) self.mark = true;
2219
+ self.sync = !!options.sync;
2220
+ self.nounique = !!options.nounique;
2221
+ self.nonull = !!options.nonull;
2222
+ self.nosort = !!options.nosort;
2223
+ self.nocase = !!options.nocase;
2224
+ self.stat = !!options.stat;
2225
+ self.noprocess = !!options.noprocess;
2226
+ self.absolute = !!options.absolute;
2227
+ self.fs = options.fs || fs;
2228
+ self.maxLength = options.maxLength || Infinity;
2229
+ self.cache = options.cache || Object.create(null);
2230
+ self.statCache = options.statCache || Object.create(null);
2231
+ self.symlinks = options.symlinks || Object.create(null);
2232
+ setupIgnores(self, options);
2233
+ self.changedCwd = false;
2234
+ var cwd = process.cwd();
2235
+ if (!ownProp(options, "cwd")) self.cwd = cwd;else {
2236
+ self.cwd = path.resolve(options.cwd);
2237
+ self.changedCwd = self.cwd !== cwd;
2238
+ }
2239
+ self.root = options.root || path.resolve(self.cwd, "/");
2240
+ self.root = path.resolve(self.root);
2241
+ if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
2242
+ // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
2243
+
2244
+ self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
2245
+ if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
2246
+ self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
2247
+ // Note that they are not supported in Glob itself anyway.
2248
+
2249
+ options.nonegate = true;
2250
+ options.nocomment = true; // always treat \ in patterns as escapes, not path separators
2251
+
2252
+ options.allowWindowsEscape = false;
2253
+ self.minimatch = new Minimatch(pattern, options);
2254
+ self.options = self.minimatch.options;
2255
+ }
2256
+
2257
+ function finish(self) {
2258
+ var nou = self.nounique;
2259
+ var all = nou ? [] : Object.create(null);
2260
+
2261
+ for (var i = 0, l = self.matches.length; i < l; i++) {
2262
+ var matches = self.matches[i];
2263
+
2264
+ if (!matches || Object.keys(matches).length === 0) {
2265
+ if (self.nonull) {
2266
+ // do like the shell, and spit out the literal glob
2267
+ var literal = self.minimatch.globSet[i];
2268
+ if (nou) all.push(literal);else all[literal] = true;
2269
+ }
2270
+ } else {
2271
+ // had matches
2272
+ var m = Object.keys(matches);
2273
+ if (nou) all.push.apply(all, m);else m.forEach(function (m) {
2274
+ all[m] = true;
2275
+ });
2276
+ }
2277
+ }
2278
+
2279
+ if (!nou) all = Object.keys(all);
2280
+ if (!self.nosort) all = all.sort(alphasort); // at *some* point we statted all of these
2281
+
2282
+ if (self.mark) {
2283
+ for (var i = 0; i < all.length; i++) {
2284
+ all[i] = self._mark(all[i]);
2285
+ }
2286
+
2287
+ if (self.nodir) {
2288
+ all = all.filter(function (e) {
2289
+ var notDir = !/\/$/.test(e);
2290
+ var c = self.cache[e] || self.cache[makeAbs(self, e)];
2291
+ if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
2292
+ return notDir;
2293
+ });
2294
+ }
2295
+ }
2296
+
2297
+ if (self.ignore.length) all = all.filter(function (m) {
2298
+ return !isIgnored(self, m);
2299
+ });
2300
+ self.found = all;
2301
+ }
2302
+
2303
+ function mark(self, p) {
2304
+ var abs = makeAbs(self, p);
2305
+ var c = self.cache[abs];
2306
+ var m = p;
2307
+
2308
+ if (c) {
2309
+ var isDir = c === 'DIR' || Array.isArray(c);
2310
+ var slash = p.slice(-1) === '/';
2311
+ if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
2312
+
2313
+ if (m !== p) {
2314
+ var mabs = makeAbs(self, m);
2315
+ self.statCache[mabs] = self.statCache[abs];
2316
+ self.cache[mabs] = self.cache[abs];
2317
+ }
2318
+ }
2319
+
2320
+ return m;
2321
+ } // lotta situps...
2322
+
2323
+
2324
+ function makeAbs(self, f) {
2325
+ var abs = f;
2326
+
2327
+ if (f.charAt(0) === '/') {
2328
+ abs = path.join(self.root, f);
2329
+ } else if (isAbsolute(f) || f === '') {
2330
+ abs = f;
2331
+ } else if (self.changedCwd) {
2332
+ abs = path.resolve(self.cwd, f);
2333
+ } else {
2334
+ abs = path.resolve(f);
2335
+ }
2336
+
2337
+ if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
2338
+ return abs;
2339
+ } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
2340
+ // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
2341
+
2342
+
2343
+ function isIgnored(self, path) {
2344
+ if (!self.ignore.length) return false;
2345
+ return self.ignore.some(function (item) {
2346
+ return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path));
2347
+ });
2348
+ }
2349
+
2350
+ function childrenIgnored(self, path) {
2351
+ if (!self.ignore.length) return false;
2352
+ return self.ignore.some(function (item) {
2353
+ return !!(item.gmatcher && item.gmatcher.match(path));
2354
+ });
2355
+ }
2356
+
2357
+ return common;
2358
+ }
2359
+
2360
+ var sync;
2361
+ var hasRequiredSync;
2362
+
2363
+ function requireSync() {
2364
+ if (hasRequiredSync) return sync;
2365
+ hasRequiredSync = 1;
2366
+ sync = globSync;
2367
+ globSync.GlobSync = GlobSync;
2368
+ var rp = requireFs_realpath();
2369
+ var minimatch = requireMinimatch();
2370
+ requireGlob().Glob;
2371
+ var path = path$1;
2372
+ var assert = require$$5;
2373
+ var isAbsolute = requirePathIsAbsolute();
2374
+ var common = requireCommon();
2375
+ var setopts = common.setopts;
2376
+ var ownProp = common.ownProp;
2377
+ var childrenIgnored = common.childrenIgnored;
2378
+ var isIgnored = common.isIgnored;
2379
+
2380
+ function globSync(pattern, options) {
2381
+ if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
2382
+ return new GlobSync(pattern, options).found;
2383
+ }
2384
+
2385
+ function GlobSync(pattern, options) {
2386
+ if (!pattern) throw new Error('must provide pattern');
2387
+ if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
2388
+ if (!(this instanceof GlobSync)) return new GlobSync(pattern, options);
2389
+ setopts(this, pattern, options);
2390
+ if (this.noprocess) return this;
2391
+ var n = this.minimatch.set.length;
2392
+ this.matches = new Array(n);
2393
+
2394
+ for (var i = 0; i < n; i++) {
2395
+ this._process(this.minimatch.set[i], i, false);
2396
+ }
2397
+
2398
+ this._finish();
2399
+ }
2400
+
2401
+ GlobSync.prototype._finish = function () {
2402
+ assert.ok(this instanceof GlobSync);
2403
+
2404
+ if (this.realpath) {
2405
+ var self = this;
2406
+ this.matches.forEach(function (matchset, index) {
2407
+ var set = self.matches[index] = Object.create(null);
2408
+
2409
+ for (var p in matchset) {
2410
+ try {
2411
+ p = self._makeAbs(p);
2412
+ var real = rp.realpathSync(p, self.realpathCache);
2413
+ set[real] = true;
2414
+ } catch (er) {
2415
+ if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
2416
+ }
2417
+ }
2418
+ });
2419
+ }
2420
+
2421
+ common.finish(this);
2422
+ };
2423
+
2424
+ GlobSync.prototype._process = function (pattern, index, inGlobStar) {
2425
+ assert.ok(this instanceof GlobSync); // Get the first [n] parts of pattern that are all strings.
2426
+
2427
+ var n = 0;
2428
+
2429
+ while (typeof pattern[n] === 'string') {
2430
+ n++;
2431
+ } // now n is the index of the first one that is *not* a string.
2432
+ // See if there's anything else
2433
+
2434
+
2435
+ var prefix;
2436
+
2437
+ switch (n) {
2438
+ // if not, then this is rather simple
2439
+ case pattern.length:
2440
+ this._processSimple(pattern.join('/'), index);
2441
+
2442
+ return;
2443
+
2444
+ case 0:
2445
+ // pattern *starts* with some non-trivial item.
2446
+ // going to readdir(cwd), but not include the prefix in matches.
2447
+ prefix = null;
2448
+ break;
2449
+
2450
+ default:
2451
+ // pattern has some string bits in the front.
2452
+ // whatever it starts with, whether that's 'absolute' like /foo/bar,
2453
+ // or 'relative' like '../baz'
2454
+ prefix = pattern.slice(0, n).join('/');
2455
+ break;
2456
+ }
2457
+
2458
+ var remain = pattern.slice(n); // get the list of entries.
2459
+
2460
+ var read;
2461
+ if (prefix === null) read = '.';else if (isAbsolute(prefix) || isAbsolute(pattern.map(function (p) {
2462
+ return typeof p === 'string' ? p : '[*]';
2463
+ }).join('/'))) {
2464
+ if (!prefix || !isAbsolute(prefix)) prefix = '/' + prefix;
2465
+ read = prefix;
2466
+ } else read = prefix;
2467
+
2468
+ var abs = this._makeAbs(read); //if ignored, skip processing
2469
+
2470
+
2471
+ if (childrenIgnored(this, read)) return;
2472
+ var isGlobStar = remain[0] === minimatch.GLOBSTAR;
2473
+ if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
2474
+ };
2475
+
2476
+ GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
2477
+ var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
2478
+
2479
+
2480
+ if (!entries) return; // It will only match dot entries if it starts with a dot, or if
2481
+ // dot is set. Stuff like @(.foo|.bar) isn't allowed.
2482
+
2483
+ var pn = remain[0];
2484
+ var negate = !!this.minimatch.negate;
2485
+ var rawGlob = pn._glob;
2486
+ var dotOk = this.dot || rawGlob.charAt(0) === '.';
2487
+ var matchedEntries = [];
2488
+
2489
+ for (var i = 0; i < entries.length; i++) {
2490
+ var e = entries[i];
2491
+
2492
+ if (e.charAt(0) !== '.' || dotOk) {
2493
+ var m;
2494
+
2495
+ if (negate && !prefix) {
2496
+ m = !e.match(pn);
2497
+ } else {
2498
+ m = e.match(pn);
2499
+ }
2500
+
2501
+ if (m) matchedEntries.push(e);
2502
+ }
2503
+ }
2504
+
2505
+ var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
2506
+
2507
+ if (len === 0) return; // if this is the last remaining pattern bit, then no need for
2508
+ // an additional stat *unless* the user has specified mark or
2509
+ // stat explicitly. We know they exist, since readdir returned
2510
+ // them.
2511
+
2512
+ if (remain.length === 1 && !this.mark && !this.stat) {
2513
+ if (!this.matches[index]) this.matches[index] = Object.create(null);
2514
+
2515
+ for (var i = 0; i < len; i++) {
2516
+ var e = matchedEntries[i];
2517
+
2518
+ if (prefix) {
2519
+ if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
2520
+ }
2521
+
2522
+ if (e.charAt(0) === '/' && !this.nomount) {
2523
+ e = path.join(this.root, e);
2524
+ }
2525
+
2526
+ this._emitMatch(index, e);
2527
+ } // This was the last one, and no stats were needed
2528
+
2529
+
2530
+ return;
2531
+ } // now test all matched entries as stand-ins for that part
2532
+ // of the pattern.
2533
+
2534
+
2535
+ remain.shift();
2536
+
2537
+ for (var i = 0; i < len; i++) {
2538
+ var e = matchedEntries[i];
2539
+ var newPattern;
2540
+ if (prefix) newPattern = [prefix, e];else newPattern = [e];
2541
+
2542
+ this._process(newPattern.concat(remain), index, inGlobStar);
2543
+ }
2544
+ };
2545
+
2546
+ GlobSync.prototype._emitMatch = function (index, e) {
2547
+ if (isIgnored(this, e)) return;
2548
+
2549
+ var abs = this._makeAbs(e);
2550
+
2551
+ if (this.mark) e = this._mark(e);
2552
+
2553
+ if (this.absolute) {
2554
+ e = abs;
2555
+ }
2556
+
2557
+ if (this.matches[index][e]) return;
2558
+
2559
+ if (this.nodir) {
2560
+ var c = this.cache[abs];
2561
+ if (c === 'DIR' || Array.isArray(c)) return;
2562
+ }
2563
+
2564
+ this.matches[index][e] = true;
2565
+ if (this.stat) this._stat(e);
2566
+ };
2567
+
2568
+ GlobSync.prototype._readdirInGlobStar = function (abs) {
2569
+ // follow all symlinked directories forever
2570
+ // just proceed as if this is a non-globstar situation
2571
+ if (this.follow) return this._readdir(abs, false);
2572
+ var entries;
2573
+ var lstat;
2574
+
2575
+ try {
2576
+ lstat = this.fs.lstatSync(abs);
2577
+ } catch (er) {
2578
+ if (er.code === 'ENOENT') {
2579
+ // lstat failed, doesn't exist
2580
+ return null;
2581
+ }
2582
+ }
2583
+
2584
+ var isSym = lstat && lstat.isSymbolicLink();
2585
+ this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
2586
+ // don't bother doing a readdir in that case.
2587
+
2588
+ if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
2589
+ return entries;
2590
+ };
2591
+
2592
+ GlobSync.prototype._readdir = function (abs, inGlobStar) {
2593
+ if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs);
2594
+
2595
+ if (ownProp(this.cache, abs)) {
2596
+ var c = this.cache[abs];
2597
+ if (!c || c === 'FILE') return null;
2598
+ if (Array.isArray(c)) return c;
2599
+ }
2600
+
2601
+ try {
2602
+ return this._readdirEntries(abs, this.fs.readdirSync(abs));
2603
+ } catch (er) {
2604
+ this._readdirError(abs, er);
2605
+
2606
+ return null;
2607
+ }
2608
+ };
2609
+
2610
+ GlobSync.prototype._readdirEntries = function (abs, entries) {
2611
+ // if we haven't asked to stat everything, then just
2612
+ // assume that everything in there exists, so we can avoid
2613
+ // having to stat it a second time.
2614
+ if (!this.mark && !this.stat) {
2615
+ for (var i = 0; i < entries.length; i++) {
2616
+ var e = entries[i];
2617
+ if (abs === '/') e = abs + e;else e = abs + '/' + e;
2618
+ this.cache[e] = true;
2619
+ }
2620
+ }
2621
+
2622
+ this.cache[abs] = entries; // mark and cache dir-ness
2623
+
2624
+ return entries;
2625
+ };
2626
+
2627
+ GlobSync.prototype._readdirError = function (f, er) {
2628
+ // handle errors, and cache the information
2629
+ switch (er.code) {
2630
+ case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
2631
+
2632
+ case 'ENOTDIR':
2633
+ // totally normal. means it *does* exist.
2634
+ var abs = this._makeAbs(f);
2635
+
2636
+ this.cache[abs] = 'FILE';
2637
+
2638
+ if (abs === this.cwdAbs) {
2639
+ var error = new Error(er.code + ' invalid cwd ' + this.cwd);
2640
+ error.path = this.cwd;
2641
+ error.code = er.code;
2642
+ throw error;
2643
+ }
2644
+
2645
+ break;
2646
+
2647
+ case 'ENOENT': // not terribly unusual
2648
+
2649
+ case 'ELOOP':
2650
+ case 'ENAMETOOLONG':
2651
+ case 'UNKNOWN':
2652
+ this.cache[this._makeAbs(f)] = false;
2653
+ break;
2654
+
2655
+ default:
2656
+ // some unusual error. Treat as failure.
2657
+ this.cache[this._makeAbs(f)] = false;
2658
+ if (this.strict) throw er;
2659
+ if (!this.silent) console.error('glob error', er);
2660
+ break;
2661
+ }
2662
+ };
2663
+
2664
+ GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
2665
+ var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
2666
+ // foo.txt/** doesn't match foo.txt
2667
+
2668
+
2669
+ if (!entries) return; // test without the globstar, and with every child both below
2670
+ // and replacing the globstar.
2671
+
2672
+ var remainWithoutGlobStar = remain.slice(1);
2673
+ var gspref = prefix ? [prefix] : [];
2674
+ var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
2675
+
2676
+ this._process(noGlobStar, index, false);
2677
+
2678
+ var len = entries.length;
2679
+ var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
2680
+
2681
+ if (isSym && inGlobStar) return;
2682
+
2683
+ for (var i = 0; i < len; i++) {
2684
+ var e = entries[i];
2685
+ if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
2686
+
2687
+ var instead = gspref.concat(entries[i], remainWithoutGlobStar);
2688
+
2689
+ this._process(instead, index, true);
2690
+
2691
+ var below = gspref.concat(entries[i], remain);
2692
+
2693
+ this._process(below, index, true);
2694
+ }
2695
+ };
2696
+
2697
+ GlobSync.prototype._processSimple = function (prefix, index) {
2698
+ // XXX review this. Shouldn't it be doing the mounting etc
2699
+ // before doing stat? kinda weird?
2700
+ var exists = this._stat(prefix);
2701
+
2702
+ if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
2703
+
2704
+ if (!exists) return;
2705
+
2706
+ if (prefix && isAbsolute(prefix) && !this.nomount) {
2707
+ var trail = /[\/\\]$/.test(prefix);
2708
+
2709
+ if (prefix.charAt(0) === '/') {
2710
+ prefix = path.join(this.root, prefix);
2711
+ } else {
2712
+ prefix = path.resolve(this.root, prefix);
2713
+ if (trail) prefix += '/';
2714
+ }
2715
+ }
2716
+
2717
+ if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
2718
+
2719
+ this._emitMatch(index, prefix);
2720
+ }; // Returns either 'DIR', 'FILE', or false
2721
+
2722
+
2723
+ GlobSync.prototype._stat = function (f) {
2724
+ var abs = this._makeAbs(f);
2725
+
2726
+ var needDir = f.slice(-1) === '/';
2727
+ if (f.length > this.maxLength) return false;
2728
+
2729
+ if (!this.stat && ownProp(this.cache, abs)) {
2730
+ var c = this.cache[abs];
2731
+ if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
2732
+
2733
+ if (!needDir || c === 'DIR') return c;
2734
+ if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
2735
+ // if we know it exists, but not what it is.
2736
+ }
2737
+
2738
+ var stat = this.statCache[abs];
2739
+
2740
+ if (!stat) {
2741
+ var lstat;
2742
+
2743
+ try {
2744
+ lstat = this.fs.lstatSync(abs);
2745
+ } catch (er) {
2746
+ if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
2747
+ this.statCache[abs] = false;
2748
+ return false;
2749
+ }
2750
+ }
2751
+
2752
+ if (lstat && lstat.isSymbolicLink()) {
2753
+ try {
2754
+ stat = this.fs.statSync(abs);
2755
+ } catch (er) {
2756
+ stat = lstat;
2757
+ }
2758
+ } else {
2759
+ stat = lstat;
2760
+ }
2761
+ }
2762
+
2763
+ this.statCache[abs] = stat;
2764
+ var c = true;
2765
+ if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
2766
+ this.cache[abs] = this.cache[abs] || c;
2767
+ if (needDir && c === 'FILE') return false;
2768
+ return c;
2769
+ };
2770
+
2771
+ GlobSync.prototype._mark = function (p) {
2772
+ return common.mark(this, p);
2773
+ };
2774
+
2775
+ GlobSync.prototype._makeAbs = function (f) {
2776
+ return common.makeAbs(this, f);
2777
+ };
2778
+
2779
+ return sync;
2780
+ }
2781
+
2782
+ var wrappy_1;
2783
+ var hasRequiredWrappy;
2784
+
2785
+ function requireWrappy() {
2786
+ if (hasRequiredWrappy) return wrappy_1;
2787
+ hasRequiredWrappy = 1; // Returns a wrapper function that returns a wrapped callback
2788
+ // The wrapper function should do some stuff, and return a
2789
+ // presumably different callback function.
2790
+ // This makes sure that own properties are retained, so that
2791
+ // decorations and such are not lost along the way.
2792
+
2793
+ wrappy_1 = wrappy;
2794
+
2795
+ function wrappy(fn, cb) {
2796
+ if (fn && cb) return wrappy(fn)(cb);
2797
+ if (typeof fn !== 'function') throw new TypeError('need wrapper function');
2798
+ Object.keys(fn).forEach(function (k) {
2799
+ wrapper[k] = fn[k];
2800
+ });
2801
+ return wrapper;
2802
+
2803
+ function wrapper() {
2804
+ var args = new Array(arguments.length);
2805
+
2806
+ for (var i = 0; i < args.length; i++) {
2807
+ args[i] = arguments[i];
2808
+ }
2809
+
2810
+ var ret = fn.apply(this, args);
2811
+ var cb = args[args.length - 1];
2812
+
2813
+ if (typeof ret === 'function' && ret !== cb) {
2814
+ Object.keys(cb).forEach(function (k) {
2815
+ ret[k] = cb[k];
2816
+ });
2817
+ }
2818
+
2819
+ return ret;
2820
+ }
2821
+ }
2822
+
2823
+ return wrappy_1;
2824
+ }
2825
+
2826
+ var once = {
2827
+ exports: {}
2828
+ };
2829
+ var hasRequiredOnce;
2830
+
2831
+ function requireOnce() {
2832
+ if (hasRequiredOnce) return once.exports;
2833
+ hasRequiredOnce = 1;
2834
+ var wrappy = requireWrappy();
2835
+ once.exports = wrappy(once$1);
2836
+ once.exports.strict = wrappy(onceStrict);
2837
+ once$1.proto = once$1(function () {
2838
+ Object.defineProperty(Function.prototype, 'once', {
2839
+ value: function () {
2840
+ return once$1(this);
2841
+ },
2842
+ configurable: true
2843
+ });
2844
+ Object.defineProperty(Function.prototype, 'onceStrict', {
2845
+ value: function () {
2846
+ return onceStrict(this);
2847
+ },
2848
+ configurable: true
2849
+ });
2850
+ });
2851
+
2852
+ function once$1(fn) {
2853
+ var f = function () {
2854
+ if (f.called) return f.value;
2855
+ f.called = true;
2856
+ return f.value = fn.apply(this, arguments);
2857
+ };
2858
+
2859
+ f.called = false;
2860
+ return f;
2861
+ }
2862
+
2863
+ function onceStrict(fn) {
2864
+ var f = function () {
2865
+ if (f.called) throw new Error(f.onceError);
2866
+ f.called = true;
2867
+ return f.value = fn.apply(this, arguments);
2868
+ };
2869
+
2870
+ var name = fn.name || 'Function wrapped with `once`';
2871
+ f.onceError = name + " shouldn't be called more than once";
2872
+ f.called = false;
2873
+ return f;
2874
+ }
2875
+
2876
+ return once.exports;
2877
+ }
2878
+
2879
+ var inflight_1;
2880
+ var hasRequiredInflight;
2881
+
2882
+ function requireInflight() {
2883
+ if (hasRequiredInflight) return inflight_1;
2884
+ hasRequiredInflight = 1;
2885
+ var wrappy = requireWrappy();
2886
+ var reqs = Object.create(null);
2887
+ var once = requireOnce();
2888
+ inflight_1 = wrappy(inflight);
2889
+
2890
+ function inflight(key, cb) {
2891
+ if (reqs[key]) {
2892
+ reqs[key].push(cb);
2893
+ return null;
2894
+ } else {
2895
+ reqs[key] = [cb];
2896
+ return makeres(key);
2897
+ }
2898
+ }
2899
+
2900
+ function makeres(key) {
2901
+ return once(function RES() {
2902
+ var cbs = reqs[key];
2903
+ var len = cbs.length;
2904
+ var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
2905
+ // pass should be queued for later execution if something in the
2906
+ // list of callbacks throws, or if it should just be discarded.
2907
+ // However, it's such an edge case that it hardly matters, and either
2908
+ // choice is likely as surprising as the other.
2909
+ // As it happens, we do go ahead and schedule it for later execution.
2910
+
2911
+ try {
2912
+ for (var i = 0; i < len; i++) {
2913
+ cbs[i].apply(null, args);
2914
+ }
2915
+ } finally {
2916
+ if (cbs.length > len) {
2917
+ // added more in the interim.
2918
+ // de-zalgo, just in case, but don't call again.
2919
+ cbs.splice(0, len);
2920
+ process.nextTick(function () {
2921
+ RES.apply(null, args);
2922
+ });
2923
+ } else {
2924
+ delete reqs[key];
2925
+ }
2926
+ }
2927
+ });
2928
+ }
2929
+
2930
+ function slice(args) {
2931
+ var length = args.length;
2932
+ var array = [];
2933
+
2934
+ for (var i = 0; i < length; i++) array[i] = args[i];
2935
+
2936
+ return array;
2937
+ }
2938
+
2939
+ return inflight_1;
2940
+ }
2941
+
2942
+ var glob_1;
2943
+ var hasRequiredGlob;
2944
+
2945
+ function requireGlob() {
2946
+ if (hasRequiredGlob) return glob_1;
2947
+ hasRequiredGlob = 1; // Approach:
2948
+ //
2949
+ // 1. Get the minimatch set
2950
+ // 2. For each pattern in the set, PROCESS(pattern, false)
2951
+ // 3. Store matches per-set, then uniq them
2952
+ //
2953
+ // PROCESS(pattern, inGlobStar)
2954
+ // Get the first [n] items from pattern that are all strings
2955
+ // Join these together. This is PREFIX.
2956
+ // If there is no more remaining, then stat(PREFIX) and
2957
+ // add to matches if it succeeds. END.
2958
+ //
2959
+ // If inGlobStar and PREFIX is symlink and points to dir
2960
+ // set ENTRIES = []
2961
+ // else readdir(PREFIX) as ENTRIES
2962
+ // If fail, END
2963
+ //
2964
+ // with ENTRIES
2965
+ // If pattern[n] is GLOBSTAR
2966
+ // // handle the case where the globstar match is empty
2967
+ // // by pruning it out, and testing the resulting pattern
2968
+ // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
2969
+ // // handle other cases.
2970
+ // for ENTRY in ENTRIES (not dotfiles)
2971
+ // // attach globstar + tail onto the entry
2972
+ // // Mark that this entry is a globstar match
2973
+ // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
2974
+ //
2975
+ // else // not globstar
2976
+ // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
2977
+ // Test ENTRY against pattern[n]
2978
+ // If fails, continue
2979
+ // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
2980
+ //
2981
+ // Caveat:
2982
+ // Cache all stats and readdirs results to minimize syscall. Since all
2983
+ // we ever care about is existence and directory-ness, we can just keep
2984
+ // `true` for files, and [children,...] for directories, or `false` for
2985
+ // things that don't exist.
2986
+
2987
+ glob_1 = glob;
2988
+ var rp = requireFs_realpath();
2989
+ var minimatch = requireMinimatch();
2990
+ var inherits = requireInherits();
2991
+ var EE = require$$3.EventEmitter;
2992
+ var path = path$1;
2993
+ var assert = require$$5;
2994
+ var isAbsolute = requirePathIsAbsolute();
2995
+ var globSync = requireSync();
2996
+ var common = requireCommon();
2997
+ var setopts = common.setopts;
2998
+ var ownProp = common.ownProp;
2999
+ var inflight = requireInflight();
3000
+ var childrenIgnored = common.childrenIgnored;
3001
+ var isIgnored = common.isIgnored;
3002
+ var once = requireOnce();
3003
+
3004
+ function glob(pattern, options, cb) {
3005
+ if (typeof options === 'function') cb = options, options = {};
3006
+ if (!options) options = {};
3007
+
3008
+ if (options.sync) {
3009
+ if (cb) throw new TypeError('callback provided to sync glob');
3010
+ return globSync(pattern, options);
3011
+ }
3012
+
3013
+ return new Glob(pattern, options, cb);
3014
+ }
3015
+
3016
+ glob.sync = globSync;
3017
+ var GlobSync = glob.GlobSync = globSync.GlobSync; // old api surface
3018
+
3019
+ glob.glob = glob;
3020
+
3021
+ function extend(origin, add) {
3022
+ if (add === null || typeof add !== 'object') {
3023
+ return origin;
3024
+ }
3025
+
3026
+ var keys = Object.keys(add);
3027
+ var i = keys.length;
3028
+
3029
+ while (i--) {
3030
+ origin[keys[i]] = add[keys[i]];
3031
+ }
3032
+
3033
+ return origin;
3034
+ }
3035
+
3036
+ glob.hasMagic = function (pattern, options_) {
3037
+ var options = extend({}, options_);
3038
+ options.noprocess = true;
3039
+ var g = new Glob(pattern, options);
3040
+ var set = g.minimatch.set;
3041
+ if (!pattern) return false;
3042
+ if (set.length > 1) return true;
3043
+
3044
+ for (var j = 0; j < set[0].length; j++) {
3045
+ if (typeof set[0][j] !== 'string') return true;
3046
+ }
3047
+
3048
+ return false;
3049
+ };
3050
+
3051
+ glob.Glob = Glob;
3052
+ inherits(Glob, EE);
3053
+
3054
+ function Glob(pattern, options, cb) {
3055
+ if (typeof options === 'function') {
3056
+ cb = options;
3057
+ options = null;
3058
+ }
3059
+
3060
+ if (options && options.sync) {
3061
+ if (cb) throw new TypeError('callback provided to sync glob');
3062
+ return new GlobSync(pattern, options);
3063
+ }
3064
+
3065
+ if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
3066
+ setopts(this, pattern, options);
3067
+ this._didRealPath = false; // process each pattern in the minimatch set
3068
+
3069
+ var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
3070
+ // duplicates are automagically pruned.
3071
+ // Later, we do an Object.keys() on these.
3072
+ // Keep them as a list so we can fill in when nonull is set.
3073
+
3074
+ this.matches = new Array(n);
3075
+
3076
+ if (typeof cb === 'function') {
3077
+ cb = once(cb);
3078
+ this.on('error', cb);
3079
+ this.on('end', function (matches) {
3080
+ cb(null, matches);
3081
+ });
3082
+ }
3083
+
3084
+ var self = this;
3085
+ this._processing = 0;
3086
+ this._emitQueue = [];
3087
+ this._processQueue = [];
3088
+ this.paused = false;
3089
+ if (this.noprocess) return this;
3090
+ if (n === 0) return done();
3091
+ var sync = true;
3092
+
3093
+ for (var i = 0; i < n; i++) {
3094
+ this._process(this.minimatch.set[i], i, false, done);
3095
+ }
3096
+
3097
+ sync = false;
3098
+
3099
+ function done() {
3100
+ --self._processing;
3101
+
3102
+ if (self._processing <= 0) {
3103
+ if (sync) {
3104
+ process.nextTick(function () {
3105
+ self._finish();
3106
+ });
3107
+ } else {
3108
+ self._finish();
3109
+ }
3110
+ }
3111
+ }
3112
+ }
3113
+
3114
+ Glob.prototype._finish = function () {
3115
+ assert(this instanceof Glob);
3116
+ if (this.aborted) return;
3117
+ if (this.realpath && !this._didRealpath) return this._realpath();
3118
+ common.finish(this);
3119
+ this.emit('end', this.found);
3120
+ };
3121
+
3122
+ Glob.prototype._realpath = function () {
3123
+ if (this._didRealpath) return;
3124
+ this._didRealpath = true;
3125
+ var n = this.matches.length;
3126
+ if (n === 0) return this._finish();
3127
+ var self = this;
3128
+
3129
+ for (var i = 0; i < this.matches.length; i++) this._realpathSet(i, next);
3130
+
3131
+ function next() {
3132
+ if (--n === 0) self._finish();
3133
+ }
3134
+ };
3135
+
3136
+ Glob.prototype._realpathSet = function (index, cb) {
3137
+ var matchset = this.matches[index];
3138
+ if (!matchset) return cb();
3139
+ var found = Object.keys(matchset);
3140
+ var self = this;
3141
+ var n = found.length;
3142
+ if (n === 0) return cb();
3143
+ var set = this.matches[index] = Object.create(null);
3144
+ found.forEach(function (p, i) {
3145
+ // If there's a problem with the stat, then it means that
3146
+ // one or more of the links in the realpath couldn't be
3147
+ // resolved. just return the abs value in that case.
3148
+ p = self._makeAbs(p);
3149
+ rp.realpath(p, self.realpathCache, function (er, real) {
3150
+ if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
3151
+
3152
+ if (--n === 0) {
3153
+ self.matches[index] = set;
3154
+ cb();
3155
+ }
3156
+ });
3157
+ });
3158
+ };
3159
+
3160
+ Glob.prototype._mark = function (p) {
3161
+ return common.mark(this, p);
3162
+ };
3163
+
3164
+ Glob.prototype._makeAbs = function (f) {
3165
+ return common.makeAbs(this, f);
3166
+ };
3167
+
3168
+ Glob.prototype.abort = function () {
3169
+ this.aborted = true;
3170
+ this.emit('abort');
3171
+ };
3172
+
3173
+ Glob.prototype.pause = function () {
3174
+ if (!this.paused) {
3175
+ this.paused = true;
3176
+ this.emit('pause');
3177
+ }
3178
+ };
3179
+
3180
+ Glob.prototype.resume = function () {
3181
+ if (this.paused) {
3182
+ this.emit('resume');
3183
+ this.paused = false;
3184
+
3185
+ if (this._emitQueue.length) {
3186
+ var eq = this._emitQueue.slice(0);
3187
+
3188
+ this._emitQueue.length = 0;
3189
+
3190
+ for (var i = 0; i < eq.length; i++) {
3191
+ var e = eq[i];
3192
+
3193
+ this._emitMatch(e[0], e[1]);
3194
+ }
3195
+ }
3196
+
3197
+ if (this._processQueue.length) {
3198
+ var pq = this._processQueue.slice(0);
3199
+
3200
+ this._processQueue.length = 0;
3201
+
3202
+ for (var i = 0; i < pq.length; i++) {
3203
+ var p = pq[i];
3204
+ this._processing--;
3205
+
3206
+ this._process(p[0], p[1], p[2], p[3]);
3207
+ }
3208
+ }
3209
+ }
3210
+ };
3211
+
3212
+ Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
3213
+ assert(this instanceof Glob);
3214
+ assert(typeof cb === 'function');
3215
+ if (this.aborted) return;
3216
+ this._processing++;
3217
+
3218
+ if (this.paused) {
3219
+ this._processQueue.push([pattern, index, inGlobStar, cb]);
3220
+
3221
+ return;
3222
+ } //console.error('PROCESS %d', this._processing, pattern)
3223
+ // Get the first [n] parts of pattern that are all strings.
3224
+
3225
+
3226
+ var n = 0;
3227
+
3228
+ while (typeof pattern[n] === 'string') {
3229
+ n++;
3230
+ } // now n is the index of the first one that is *not* a string.
3231
+ // see if there's anything else
3232
+
3233
+
3234
+ var prefix;
3235
+
3236
+ switch (n) {
3237
+ // if not, then this is rather simple
3238
+ case pattern.length:
3239
+ this._processSimple(pattern.join('/'), index, cb);
3240
+
3241
+ return;
3242
+
3243
+ case 0:
3244
+ // pattern *starts* with some non-trivial item.
3245
+ // going to readdir(cwd), but not include the prefix in matches.
3246
+ prefix = null;
3247
+ break;
3248
+
3249
+ default:
3250
+ // pattern has some string bits in the front.
3251
+ // whatever it starts with, whether that's 'absolute' like /foo/bar,
3252
+ // or 'relative' like '../baz'
3253
+ prefix = pattern.slice(0, n).join('/');
3254
+ break;
3255
+ }
3256
+
3257
+ var remain = pattern.slice(n); // get the list of entries.
3258
+
3259
+ var read;
3260
+ if (prefix === null) read = '.';else if (isAbsolute(prefix) || isAbsolute(pattern.map(function (p) {
3261
+ return typeof p === 'string' ? p : '[*]';
3262
+ }).join('/'))) {
3263
+ if (!prefix || !isAbsolute(prefix)) prefix = '/' + prefix;
3264
+ read = prefix;
3265
+ } else read = prefix;
3266
+
3267
+ var abs = this._makeAbs(read); //if ignored, skip _processing
3268
+
3269
+
3270
+ if (childrenIgnored(this, read)) return cb();
3271
+ var isGlobStar = remain[0] === minimatch.GLOBSTAR;
3272
+ if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
3273
+ };
3274
+
3275
+ Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
3276
+ var self = this;
3277
+
3278
+ this._readdir(abs, inGlobStar, function (er, entries) {
3279
+ return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
3280
+ });
3281
+ };
3282
+
3283
+ Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
3284
+ // if the abs isn't a dir, then nothing can match!
3285
+ if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
3286
+ // dot is set. Stuff like @(.foo|.bar) isn't allowed.
3287
+
3288
+ var pn = remain[0];
3289
+ var negate = !!this.minimatch.negate;
3290
+ var rawGlob = pn._glob;
3291
+ var dotOk = this.dot || rawGlob.charAt(0) === '.';
3292
+ var matchedEntries = [];
3293
+
3294
+ for (var i = 0; i < entries.length; i++) {
3295
+ var e = entries[i];
3296
+
3297
+ if (e.charAt(0) !== '.' || dotOk) {
3298
+ var m;
3299
+
3300
+ if (negate && !prefix) {
3301
+ m = !e.match(pn);
3302
+ } else {
3303
+ m = e.match(pn);
3304
+ }
3305
+
3306
+ if (m) matchedEntries.push(e);
3307
+ }
3308
+ } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
3309
+
3310
+
3311
+ var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
3312
+
3313
+ if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
3314
+ // an additional stat *unless* the user has specified mark or
3315
+ // stat explicitly. We know they exist, since readdir returned
3316
+ // them.
3317
+
3318
+ if (remain.length === 1 && !this.mark && !this.stat) {
3319
+ if (!this.matches[index]) this.matches[index] = Object.create(null);
3320
+
3321
+ for (var i = 0; i < len; i++) {
3322
+ var e = matchedEntries[i];
3323
+
3324
+ if (prefix) {
3325
+ if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
3326
+ }
3327
+
3328
+ if (e.charAt(0) === '/' && !this.nomount) {
3329
+ e = path.join(this.root, e);
3330
+ }
3331
+
3332
+ this._emitMatch(index, e);
3333
+ } // This was the last one, and no stats were needed
3334
+
3335
+
3336
+ return cb();
3337
+ } // now test all matched entries as stand-ins for that part
3338
+ // of the pattern.
3339
+
3340
+
3341
+ remain.shift();
3342
+
3343
+ for (var i = 0; i < len; i++) {
3344
+ var e = matchedEntries[i];
3345
+
3346
+ if (prefix) {
3347
+ if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
3348
+ }
3349
+
3350
+ this._process([e].concat(remain), index, inGlobStar, cb);
3351
+ }
3352
+
3353
+ cb();
3354
+ };
3355
+
3356
+ Glob.prototype._emitMatch = function (index, e) {
3357
+ if (this.aborted) return;
3358
+ if (isIgnored(this, e)) return;
3359
+
3360
+ if (this.paused) {
3361
+ this._emitQueue.push([index, e]);
3362
+
3363
+ return;
3364
+ }
3365
+
3366
+ var abs = isAbsolute(e) ? e : this._makeAbs(e);
3367
+ if (this.mark) e = this._mark(e);
3368
+ if (this.absolute) e = abs;
3369
+ if (this.matches[index][e]) return;
3370
+
3371
+ if (this.nodir) {
3372
+ var c = this.cache[abs];
3373
+ if (c === 'DIR' || Array.isArray(c)) return;
3374
+ }
3375
+
3376
+ this.matches[index][e] = true;
3377
+ var st = this.statCache[abs];
3378
+ if (st) this.emit('stat', e, st);
3379
+ this.emit('match', e);
3380
+ };
3381
+
3382
+ Glob.prototype._readdirInGlobStar = function (abs, cb) {
3383
+ if (this.aborted) return; // follow all symlinked directories forever
3384
+ // just proceed as if this is a non-globstar situation
3385
+
3386
+ if (this.follow) return this._readdir(abs, false, cb);
3387
+ var lstatkey = 'lstat\0' + abs;
3388
+ var self = this;
3389
+ var lstatcb = inflight(lstatkey, lstatcb_);
3390
+ if (lstatcb) self.fs.lstat(abs, lstatcb);
3391
+
3392
+ function lstatcb_(er, lstat) {
3393
+ if (er && er.code === 'ENOENT') return cb();
3394
+ var isSym = lstat && lstat.isSymbolicLink();
3395
+ self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
3396
+ // don't bother doing a readdir in that case.
3397
+
3398
+ if (!isSym && lstat && !lstat.isDirectory()) {
3399
+ self.cache[abs] = 'FILE';
3400
+ cb();
3401
+ } else self._readdir(abs, false, cb);
3402
+ }
3403
+ };
3404
+
3405
+ Glob.prototype._readdir = function (abs, inGlobStar, cb) {
3406
+ if (this.aborted) return;
3407
+ cb = inflight('readdir\0' + abs + '\0' + inGlobStar, cb);
3408
+ if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
3409
+
3410
+ if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
3411
+
3412
+ if (ownProp(this.cache, abs)) {
3413
+ var c = this.cache[abs];
3414
+ if (!c || c === 'FILE') return cb();
3415
+ if (Array.isArray(c)) return cb(null, c);
3416
+ }
3417
+
3418
+ var self = this;
3419
+ self.fs.readdir(abs, readdirCb(this, abs, cb));
3420
+ };
3421
+
3422
+ function readdirCb(self, abs, cb) {
3423
+ return function (er, entries) {
3424
+ if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
3425
+ };
3426
+ }
3427
+
3428
+ Glob.prototype._readdirEntries = function (abs, entries, cb) {
3429
+ if (this.aborted) return; // if we haven't asked to stat everything, then just
3430
+ // assume that everything in there exists, so we can avoid
3431
+ // having to stat it a second time.
3432
+
3433
+ if (!this.mark && !this.stat) {
3434
+ for (var i = 0; i < entries.length; i++) {
3435
+ var e = entries[i];
3436
+ if (abs === '/') e = abs + e;else e = abs + '/' + e;
3437
+ this.cache[e] = true;
3438
+ }
3439
+ }
3440
+
3441
+ this.cache[abs] = entries;
3442
+ return cb(null, entries);
3443
+ };
3444
+
3445
+ Glob.prototype._readdirError = function (f, er, cb) {
3446
+ if (this.aborted) return; // handle errors, and cache the information
3447
+
3448
+ switch (er.code) {
3449
+ case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
3450
+
3451
+ case 'ENOTDIR':
3452
+ // totally normal. means it *does* exist.
3453
+ var abs = this._makeAbs(f);
3454
+
3455
+ this.cache[abs] = 'FILE';
3456
+
3457
+ if (abs === this.cwdAbs) {
3458
+ var error = new Error(er.code + ' invalid cwd ' + this.cwd);
3459
+ error.path = this.cwd;
3460
+ error.code = er.code;
3461
+ this.emit('error', error);
3462
+ this.abort();
3463
+ }
3464
+
3465
+ break;
3466
+
3467
+ case 'ENOENT': // not terribly unusual
3468
+
3469
+ case 'ELOOP':
3470
+ case 'ENAMETOOLONG':
3471
+ case 'UNKNOWN':
3472
+ this.cache[this._makeAbs(f)] = false;
3473
+ break;
3474
+
3475
+ default:
3476
+ // some unusual error. Treat as failure.
3477
+ this.cache[this._makeAbs(f)] = false;
3478
+
3479
+ if (this.strict) {
3480
+ this.emit('error', er); // If the error is handled, then we abort
3481
+ // if not, we threw out of here
3482
+
3483
+ this.abort();
3484
+ }
3485
+
3486
+ if (!this.silent) console.error('glob error', er);
3487
+ break;
3488
+ }
3489
+
3490
+ return cb();
3491
+ };
3492
+
3493
+ Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
3494
+ var self = this;
3495
+
3496
+ this._readdir(abs, inGlobStar, function (er, entries) {
3497
+ self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
3498
+ });
3499
+ };
3500
+
3501
+ Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
3502
+ //console.error('pgs2', prefix, remain[0], entries)
3503
+ // no entries means not a dir, so it can never have matches
3504
+ // foo.txt/** doesn't match foo.txt
3505
+ if (!entries) return cb(); // test without the globstar, and with every child both below
3506
+ // and replacing the globstar.
3507
+
3508
+ var remainWithoutGlobStar = remain.slice(1);
3509
+ var gspref = prefix ? [prefix] : [];
3510
+ var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
3511
+
3512
+ this._process(noGlobStar, index, false, cb);
3513
+
3514
+ var isSym = this.symlinks[abs];
3515
+ var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
3516
+
3517
+ if (isSym && inGlobStar) return cb();
3518
+
3519
+ for (var i = 0; i < len; i++) {
3520
+ var e = entries[i];
3521
+ if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
3522
+
3523
+ var instead = gspref.concat(entries[i], remainWithoutGlobStar);
3524
+
3525
+ this._process(instead, index, true, cb);
3526
+
3527
+ var below = gspref.concat(entries[i], remain);
3528
+
3529
+ this._process(below, index, true, cb);
3530
+ }
3531
+
3532
+ cb();
3533
+ };
3534
+
3535
+ Glob.prototype._processSimple = function (prefix, index, cb) {
3536
+ // XXX review this. Shouldn't it be doing the mounting etc
3537
+ // before doing stat? kinda weird?
3538
+ var self = this;
3539
+
3540
+ this._stat(prefix, function (er, exists) {
3541
+ self._processSimple2(prefix, index, er, exists, cb);
3542
+ });
3543
+ };
3544
+
3545
+ Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
3546
+ //console.error('ps2', prefix, exists)
3547
+ if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
3548
+
3549
+ if (!exists) return cb();
3550
+
3551
+ if (prefix && isAbsolute(prefix) && !this.nomount) {
3552
+ var trail = /[\/\\]$/.test(prefix);
3553
+
3554
+ if (prefix.charAt(0) === '/') {
3555
+ prefix = path.join(this.root, prefix);
3556
+ } else {
3557
+ prefix = path.resolve(this.root, prefix);
3558
+ if (trail) prefix += '/';
174
3559
  }
175
- } else {
176
- console.error(err);
177
3560
  }
178
3561
 
179
- process.exit(1);
180
- }
181
- }
3562
+ if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
182
3563
 
183
- function _parseExports(options) {
184
- const {
185
- pkg
186
- } = options;
187
- const rootExport = {
188
- _exported: true,
189
- _path: ".",
190
- types: pkg.types,
191
- source: pkg.source || "index.js",
192
- browser: pkg.browser && {
193
- require: pkg.main && pkg.browser[pkg.main],
194
- import: pkg.module && pkg.browser[pkg.module]
195
- },
196
- import: pkg.module,
197
- require: pkg.main,
198
- default: pkg.module || pkg.main || "./index.js"
199
- };
200
- const extraExports = [];
3564
+ this._emitMatch(index, prefix);
201
3565
 
202
- if (pkg.exports) {
203
- for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
204
- if (_isRecord(exportEntry)) {
205
- if (exportPath === ".") {
206
- Object.assign(rootExport, exportEntry);
207
- } else {
208
- const extraExport = _objectSpread({
209
- _exported: true,
210
- _path: exportPath
211
- }, exportEntry);
3566
+ cb();
3567
+ }; // Returns either 'DIR', 'FILE', or false
212
3568
 
213
- extraExports.push(extraExport);
214
- }
3569
+
3570
+ Glob.prototype._stat = function (f, cb) {
3571
+ var abs = this._makeAbs(f);
3572
+
3573
+ var needDir = f.slice(-1) === '/';
3574
+ if (f.length > this.maxLength) return cb();
3575
+
3576
+ if (!this.stat && ownProp(this.cache, abs)) {
3577
+ var c = this.cache[abs];
3578
+ if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
3579
+
3580
+ if (!needDir || c === 'DIR') return cb(null, c);
3581
+ if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
3582
+ // if we know it exists, but not what it is.
3583
+ }
3584
+
3585
+ var stat = this.statCache[abs];
3586
+
3587
+ if (stat !== undefined) {
3588
+ if (stat === false) return cb(null, stat);else {
3589
+ var type = stat.isDirectory() ? 'DIR' : 'FILE';
3590
+ if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
3591
+ }
3592
+ }
3593
+
3594
+ var self = this;
3595
+ var statcb = inflight('stat\0' + abs, lstatcb_);
3596
+ if (statcb) self.fs.lstat(abs, statcb);
3597
+
3598
+ function lstatcb_(er, lstat) {
3599
+ if (lstat && lstat.isSymbolicLink()) {
3600
+ // If it's a symlink, then treat it as the target, unless
3601
+ // the target does not exist, then treat it as a file.
3602
+ return self.fs.stat(abs, function (er, stat) {
3603
+ if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
3604
+ });
215
3605
  } else {
216
- throw new Error("string entries are not supported");
3606
+ self._stat2(f, abs, er, lstat, cb);
217
3607
  }
218
3608
  }
219
- }
3609
+ };
220
3610
 
221
- return [rootExport, ...extraExports];
222
- }
3611
+ Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
3612
+ if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
3613
+ this.statCache[abs] = false;
3614
+ return cb();
3615
+ }
223
3616
 
224
- async function _loadTSConfig(options) {
225
- const {
226
- cwd,
227
- tsconfigPath
228
- } = options;
229
- const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
3617
+ var needDir = f.slice(-1) === '/';
3618
+ this.statCache[abs] = stat;
3619
+ if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
3620
+ var c = true;
3621
+ if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
3622
+ this.cache[abs] = this.cache[abs] || c;
3623
+ if (needDir && c === 'FILE') return cb();
3624
+ return cb(null, c, stat);
3625
+ };
230
3626
 
231
- if (!configPath) {
232
- throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
233
- }
3627
+ return glob_1;
3628
+ }
234
3629
 
235
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
236
- return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
3630
+ const assert = require$$5;
3631
+ const path = path$1;
3632
+ const fs = fs$2;
3633
+ let glob = undefined;
3634
+
3635
+ try {
3636
+ glob = requireGlob();
3637
+ } catch (_err) {// treat glob as optional.
237
3638
  }
238
3639
 
239
- function _resolveBuildTasks(ctx) {
240
- var _a, _b, _c, _d, _e;
3640
+ const defaultGlobOpts = {
3641
+ nosort: true,
3642
+ silent: true
3643
+ }; // for EMFILE handling
241
3644
 
242
- const {
243
- cwd,
244
- pkg,
245
- target
246
- } = ctx;
247
- const tasks = [];
248
- const exports = Object.entries(ctx.exports || {}).map(_ref => {
249
- let [_path, exp] = _ref;
250
- return _objectSpread({
251
- _path
252
- }, exp);
3645
+ let timeout = 0;
3646
+ const isWindows = process.platform === "win32";
3647
+
3648
+ const defaults = options => {
3649
+ const methods = ['unlink', 'chmod', 'stat', 'lstat', 'rmdir', 'readdir'];
3650
+ methods.forEach(m => {
3651
+ options[m] = options[m] || fs[m];
3652
+ m = m + 'Sync';
3653
+ options[m] = options[m] || fs[m];
253
3654
  });
254
- const dtsTask = {
255
- type: "build:dts",
256
- entries: []
257
- };
258
- const rollupTasks = {};
3655
+ options.maxBusyTries = options.maxBusyTries || 3;
3656
+ options.emfileWait = options.emfileWait || 1000;
259
3657
 
260
- function _addRollupTaskEntry(format, runtime, entry) {
261
- const buildId = "".concat(format, ":").concat(runtime);
3658
+ if (options.glob === false) {
3659
+ options.disableGlob = true;
3660
+ }
262
3661
 
263
- if (rollupTasks[buildId]) {
264
- rollupTasks[buildId].entries.push(entry);
265
- } else {
266
- rollupTasks[buildId] = {
267
- type: "build:js",
268
- buildId,
269
- entries: [entry],
270
- runtime,
271
- format,
272
- target: target[runtime]
273
- };
274
- }
3662
+ if (options.disableGlob !== true && glob === undefined) {
3663
+ throw Error('glob dependency not found, set `options.disableGlob = true` if intentional');
275
3664
  }
276
3665
 
277
- for (const exp of exports) {
278
- const importId = path.join(pkg.name, exp._path);
3666
+ options.disableGlob = options.disableGlob || false;
3667
+ options.glob = options.glob || defaultGlobOpts;
3668
+ };
279
3669
 
280
- if (exp.types) {
281
- dtsTask.entries.push({
282
- importId,
283
- exportPath: exp._path,
284
- sourcePath: exp.source,
285
- targetPath: exp.types
286
- });
287
- }
3670
+ const rimraf$1 = (p, options, cb) => {
3671
+ if (typeof options === 'function') {
3672
+ cb = options;
3673
+ options = {};
288
3674
  }
289
3675
 
290
- for (const exp of exports) {
291
- const output = exp.require;
292
- if (!output) continue;
3676
+ assert(p, 'rimraf: missing path');
3677
+ assert.equal(typeof p, 'string', 'rimraf: path should be a string');
3678
+ assert.equal(typeof cb, 'function', 'rimraf: callback function required');
3679
+ assert(options, 'rimraf: invalid options argument provided');
3680
+ assert.equal(typeof options, 'object', 'rimraf: options should be object');
3681
+ defaults(options);
3682
+ let busyTries = 0;
3683
+ let errState = null;
3684
+ let n = 0;
3685
+
3686
+ const next = er => {
3687
+ errState = errState || er;
3688
+ if (--n === 0) cb(errState);
3689
+ };
293
3690
 
294
- _addRollupTaskEntry("commonjs", ctx.runtime, {
295
- path: exp._path,
296
- source: exp.source,
297
- output
298
- });
299
- }
3691
+ const afterGlob = (er, results) => {
3692
+ if (er) return cb(er);
3693
+ n = results.length;
3694
+ if (n === 0) return cb();
3695
+ results.forEach(p => {
3696
+ const CB = er => {
3697
+ if (er) {
3698
+ if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") && busyTries < options.maxBusyTries) {
3699
+ busyTries++; // try again, with the same exact callback as this one.
300
3700
 
301
- for (const exp of exports) {
302
- const output = (_a = exp.browser) == null ? void 0 : _a.require;
303
- if (!output) continue;
3701
+ return setTimeout(() => rimraf_(p, options, CB), busyTries * 100);
3702
+ } // this one won't happen if graceful-fs is used.
304
3703
 
305
- _addRollupTaskEntry("commonjs", "browser", {
306
- path: exp._path,
307
- source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
308
- output
309
- });
310
- }
311
3704
 
312
- for (const exp of exports) {
313
- const output = exp.import;
314
- if (!output) continue;
3705
+ if (er.code === "EMFILE" && timeout < options.emfileWait) {
3706
+ return setTimeout(() => rimraf_(p, options, CB), timeout++);
3707
+ } // already gone
315
3708
 
316
- _addRollupTaskEntry("esm", ctx.runtime, {
317
- path: exp._path,
318
- source: exp.source,
319
- output
3709
+
3710
+ if (er.code === "ENOENT") er = null;
3711
+ }
3712
+
3713
+ timeout = 0;
3714
+ next(er);
3715
+ };
3716
+
3717
+ rimraf_(p, options, CB);
320
3718
  });
321
- }
3719
+ };
322
3720
 
323
- for (const exp of exports) {
324
- const output = (_c = exp.browser) == null ? void 0 : _c.import;
325
- if (!output) continue;
3721
+ if (options.disableGlob || !glob.hasMagic(p)) return afterGlob(null, [p]);
3722
+ options.lstat(p, (er, stat) => {
3723
+ if (!er) return afterGlob(null, [p]);
3724
+ glob(p, options.glob, afterGlob);
3725
+ });
3726
+ }; // Two possible strategies.
3727
+ // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
3728
+ // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
3729
+ //
3730
+ // Both result in an extra syscall when you guess wrong. However, there
3731
+ // are likely far more normal files in the world than directories. This
3732
+ // is based on the assumption that a the average number of files per
3733
+ // directory is >= 1.
3734
+ //
3735
+ // If anyone ever complains about this, then I guess the strategy could
3736
+ // be made configurable somehow. But until then, YAGNI.
3737
+
3738
+
3739
+ const rimraf_ = (p, options, cb) => {
3740
+ assert(p);
3741
+ assert(options);
3742
+ assert(typeof cb === 'function'); // sunos lets the root user unlink directories, which is... weird.
3743
+ // so we have to lstat here and make sure it's not a dir.
3744
+
3745
+ options.lstat(p, (er, st) => {
3746
+ if (er && er.code === "ENOENT") return cb(null); // Windows can EPERM on stat. Life is suffering.
3747
+
3748
+ if (er && er.code === "EPERM" && isWindows) fixWinEPERM(p, options, er, cb);
3749
+ if (st && st.isDirectory()) return rmdir(p, options, er, cb);
3750
+ options.unlink(p, er => {
3751
+ if (er) {
3752
+ if (er.code === "ENOENT") return cb(null);
3753
+ if (er.code === "EPERM") return isWindows ? fixWinEPERM(p, options, er, cb) : rmdir(p, options, er, cb);
3754
+ if (er.code === "EISDIR") return rmdir(p, options, er, cb);
3755
+ }
326
3756
 
327
- _addRollupTaskEntry("esm", "browser", {
328
- path: exp._path,
329
- source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
330
- output
3757
+ return cb(er);
3758
+ });
3759
+ });
3760
+ };
3761
+
3762
+ const fixWinEPERM = (p, options, er, cb) => {
3763
+ assert(p);
3764
+ assert(options);
3765
+ assert(typeof cb === 'function');
3766
+ options.chmod(p, 0o666, er2 => {
3767
+ if (er2) cb(er2.code === "ENOENT" ? null : er);else options.stat(p, (er3, stats) => {
3768
+ if (er3) cb(er3.code === "ENOENT" ? null : er);else if (stats.isDirectory()) rmdir(p, options, er, cb);else options.unlink(p, cb);
331
3769
  });
3770
+ });
3771
+ };
3772
+
3773
+ const fixWinEPERMSync = (p, options, er) => {
3774
+ assert(p);
3775
+ assert(options);
3776
+
3777
+ try {
3778
+ options.chmodSync(p, 0o666);
3779
+ } catch (er2) {
3780
+ if (er2.code === "ENOENT") return;else throw er;
332
3781
  }
333
3782
 
334
- if (dtsTask.entries.length) {
335
- tasks.push(dtsTask);
3783
+ let stats;
3784
+
3785
+ try {
3786
+ stats = options.statSync(p);
3787
+ } catch (er3) {
3788
+ if (er3.code === "ENOENT") return;else throw er;
336
3789
  }
337
3790
 
338
- tasks.push(...Object.values(rollupTasks));
3791
+ if (stats.isDirectory()) rmdirSync(p, options, er);else options.unlinkSync(p);
3792
+ };
339
3793
 
340
- for (const exp of exports) {
341
- if (exp._exported && exp._path !== ".") {
342
- const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
3794
+ const rmdir = (p, options, originalEr, cb) => {
3795
+ assert(p);
3796
+ assert(options);
3797
+ assert(typeof cb === 'function'); // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
3798
+ // if we guessed wrong, and it's not a directory, then
3799
+ // raise the original error.
343
3800
 
344
- if (relativeTargetPath) {
345
- fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
346
- }
3801
+ options.rmdir(p, er => {
3802
+ if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")) rmkids(p, options, cb);else if (er && er.code === "ENOTDIR") cb(originalEr);else cb(er);
3803
+ });
3804
+ };
3805
+
3806
+ const rmkids = (p, options, cb) => {
3807
+ assert(p);
3808
+ assert(options);
3809
+ assert(typeof cb === 'function');
3810
+ options.readdir(p, (er, files) => {
3811
+ if (er) return cb(er);
3812
+ let n = files.length;
3813
+ if (n === 0) return options.rmdir(p, cb);
3814
+ let errState;
3815
+ files.forEach(f => {
3816
+ rimraf$1(path.join(p, f), options, er => {
3817
+ if (errState) return;
3818
+ if (er) return cb(errState = er);
3819
+ if (--n === 0) options.rmdir(p, cb);
3820
+ });
3821
+ });
3822
+ });
3823
+ }; // this looks simpler, and is strictly *faster*, but will
3824
+ // tie up the JavaScript thread and fail on excessively
3825
+ // deep directory trees.
3826
+
3827
+
3828
+ const rimrafSync = (p, options) => {
3829
+ options = options || {};
3830
+ defaults(options);
3831
+ assert(p, 'rimraf: missing path');
3832
+ assert.equal(typeof p, 'string', 'rimraf: path should be a string');
3833
+ assert(options, 'rimraf: missing options');
3834
+ assert.equal(typeof options, 'object', 'rimraf: options should be object');
3835
+ let results;
3836
+
3837
+ if (options.disableGlob || !glob.hasMagic(p)) {
3838
+ results = [p];
3839
+ } else {
3840
+ try {
3841
+ options.lstatSync(p);
3842
+ results = [p];
3843
+ } catch (er) {
3844
+ results = glob.sync(p, options.glob);
347
3845
  }
348
3846
  }
349
3847
 
350
- return tasks;
351
- }
352
-
353
- function _printExtractMessages(ctx, messages) {
354
- const {
355
- cwd,
356
- logger
357
- } = ctx;
358
- const warnings = messages.filter(msg => msg.logLevel === "warning");
3848
+ if (!results.length) return;
359
3849
 
360
- if (warnings.length) {
361
- logger.log();
362
- }
3850
+ for (let i = 0; i < results.length; i++) {
3851
+ const p = results[i];
3852
+ let st;
363
3853
 
364
- for (const msg of warnings) {
365
- const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
3854
+ try {
3855
+ st = options.lstatSync(p);
3856
+ } catch (er) {
3857
+ if (er.code === "ENOENT") return; // Windows can EPERM on stat. Life is suffering.
366
3858
 
367
- if (msg.messageId === "TS6307") {
368
- continue;
3859
+ if (er.code === "EPERM" && isWindows) fixWinEPERMSync(p, options, er);
369
3860
  }
370
3861
 
371
- logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.yellow("warning"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
3862
+ try {
3863
+ // sunos lets the root user unlink directories, which is... weird.
3864
+ if (st && st.isDirectory()) rmdirSync(p, options, null);else options.unlinkSync(p);
3865
+ } catch (er) {
3866
+ if (er.code === "ENOENT") return;
3867
+ if (er.code === "EPERM") return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er);
3868
+ if (er.code !== "EISDIR") throw er;
3869
+ rmdirSync(p, options, er);
3870
+ }
372
3871
  }
3872
+ };
373
3873
 
374
- const errors = messages.filter(msg => msg.logLevel === "error");
3874
+ const rmdirSync = (p, options, originalEr) => {
3875
+ assert(p);
3876
+ assert(options);
375
3877
 
376
- if (!warnings.length && errors.length) {
377
- logger.log("");
3878
+ try {
3879
+ options.rmdirSync(p);
3880
+ } catch (er) {
3881
+ if (er.code === "ENOENT") return;
3882
+ if (er.code === "ENOTDIR") throw originalEr;
3883
+ if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM") rmkidsSync(p, options);
378
3884
  }
3885
+ };
379
3886
 
380
- for (const msg of errors) {
381
- const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
382
- logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.red("error"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
383
- }
3887
+ const rmkidsSync = (p, options) => {
3888
+ assert(p);
3889
+ assert(options);
3890
+ options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options)); // We only end up here once we got ENOTEMPTY at least once, and
3891
+ // at this point, we are guaranteed to have removed all the kids.
3892
+ // So, we know that it won't be ENOENT or ENOTDIR or anything else.
3893
+ // try really hard to delete stuff on windows, because it has a
3894
+ // PROFOUNDLY annoying habit of not closing handles promptly when
3895
+ // files are deleted, resulting in spurious ENOTEMPTY errors.
384
3896
 
385
- if (errors.length) {
386
- process.exit(1);
387
- }
388
- }
3897
+ const retries = isWindows ? 100 : 1;
3898
+ let i = 0;
3899
+
3900
+ do {
3901
+ let threw = true;
3902
+
3903
+ try {
3904
+ const ret = options.rmdirSync(p, options);
3905
+ threw = false;
3906
+ return ret;
3907
+ } finally {
3908
+ if (++i < retries && threw) continue;
3909
+ }
3910
+ } while (true);
3911
+ };
389
3912
 
3913
+ var rimraf_1 = rimraf$1;
3914
+ rimraf$1.sync = rimrafSync;
390
3915
  const formatHost = {
391
3916
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
392
3917
  getNewLine: () => ts.sys.newLine,
@@ -461,11 +3986,11 @@ function _createApiExtractorConfig(options) {
461
3986
  },
462
3987
  docModel: {
463
3988
  enabled: false,
464
- apiJsonFilePath: path.resolve(distPath, "".concat(exportPath, ".api.json"))
3989
+ apiJsonFilePath: path$1.resolve(distPath, "".concat(exportPath, ".api.json"))
465
3990
  },
466
3991
  dtsRollup: {
467
3992
  enabled: true,
468
- untrimmedFilePath: path.resolve(distPath, filePath)
3993
+ untrimmedFilePath: path$1.resolve(distPath, filePath)
469
3994
  },
470
3995
  tsdocMetadata: {
471
3996
  enabled: false
@@ -584,7 +4109,7 @@ async function _extractTypes(options) {
584
4109
  }),
585
4110
  configObjectFullPath: void 0,
586
4111
  tsdocConfigFile,
587
- packageJsonFullPath: path.resolve(projectPath, "package.json")
4112
+ packageJsonFullPath: path$1.resolve(projectPath, "package.json")
588
4113
  });
589
4114
  const messages = [];
590
4115
  const extractorResult = Extractor.invoke(extractorConfig, {
@@ -597,11 +4122,11 @@ async function _extractTypes(options) {
597
4122
  }
598
4123
 
599
4124
  });
600
- const typesPath = path.resolve(distPath, filePath);
601
- const typesBuf = await fs.readFile(typesPath);
4125
+ const typesPath = path$1.resolve(distPath, filePath);
4126
+ const typesBuf = await fs$1.readFile(typesPath);
602
4127
  const prettierConfig = await prettier.resolveConfig(typesPath);
603
- await mkdirp(path.dirname(typesPath));
604
- await fs.writeFile(typesPath, prettier.format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
4128
+ await mkdirp(path$1.dirname(typesPath));
4129
+ await fs$1.writeFile(typesPath, prettier.format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
605
4130
  filepath: typesPath
606
4131
  })));
607
4132
  files.push({
@@ -614,6 +4139,8 @@ async function _extractTypes(options) {
614
4139
  };
615
4140
  }
616
4141
 
4142
+ const rimraf = promisify(rimraf_1);
4143
+
617
4144
  async function _doExtract(ctx, task) {
618
4145
  var _a;
619
4146
 
@@ -624,11 +4151,16 @@ async function _doExtract(ctx, task) {
624
4151
  files,
625
4152
  ts
626
4153
  } = ctx;
627
- if (!ts.config || !ts.configPath) return {
628
- type: "dts",
629
- messages: []
630
- };
631
- const distPath = path.resolve(cwd, dist);
4154
+
4155
+ if (!ts.config || !ts.configPath) {
4156
+ return {
4157
+ type: "dts",
4158
+ messages: [],
4159
+ results: []
4160
+ };
4161
+ }
4162
+
4163
+ const distPath = path$1.resolve(cwd, dist);
632
4164
  const {
633
4165
  outDir = distPath,
634
4166
  rootDir = cwd
@@ -639,10 +4171,12 @@ async function _doExtract(ctx, task) {
639
4171
  tsconfig: ts.config
640
4172
  });
641
4173
  const messages = [];
4174
+ const results = [];
642
4175
 
643
4176
  for (const entry of task.entries) {
644
4177
  const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
645
- const filePath = path.relative(distPath, path.resolve(cwd, entry.targetPath));
4178
+ const sourcePath = path$1.resolve(outDir, path$1.relative(cwd, rootDir), entry.sourcePath.replace(/\.ts$/, ".d.ts"));
4179
+ const filePath = path$1.relative(distPath, path$1.resolve(cwd, entry.targetPath));
646
4180
  const result = await _extractTypes({
647
4181
  cwd,
648
4182
  exportPath,
@@ -650,10 +4184,14 @@ async function _doExtract(ctx, task) {
650
4184
  filePath,
651
4185
  projectPath: cwd,
652
4186
  rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
653
- sourcePath: path.resolve(outDir, path.relative(cwd, rootDir), entry.sourcePath.replace(/\.ts$/, ".d.ts")),
654
- tsconfigPath: path.resolve(cwd, ts.configPath),
4187
+ sourcePath,
4188
+ tsconfigPath: path$1.resolve(cwd, ts.configPath),
655
4189
  distPath
656
4190
  });
4191
+ results.push({
4192
+ sourcePath,
4193
+ filePath
4194
+ });
657
4195
  messages.push(...result.messages);
658
4196
 
659
4197
  if (result.messages.some(msg => msg.logLevel === "error")) {
@@ -661,9 +4199,20 @@ async function _doExtract(ctx, task) {
661
4199
  }
662
4200
  }
663
4201
 
4202
+ const tmpPath = path$1.resolve(distPath, "__tmp__");
4203
+ await rename(outDir, tmpPath);
4204
+
4205
+ for (const result of results) {
4206
+ const fromPath = path$1.resolve(tmpPath, path$1.relative(outDir, path$1.resolve(distPath, result.filePath)));
4207
+ const toPath = path$1.resolve(distPath, result.filePath);
4208
+ cpx.copySync(fromPath, path$1.dirname(toPath));
4209
+ }
4210
+
4211
+ await rimraf(tmpPath);
664
4212
  return {
665
4213
  type: "dts",
666
- messages
4214
+ messages,
4215
+ results
667
4216
  };
668
4217
  }
669
4218
 
@@ -754,17 +4303,17 @@ function _resolveRollupConfig(ctx, buildTask) {
754
4303
 
755
4304
  var _a2;
756
4305
 
757
- return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
4306
+ return [key, path$1.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
758
4307
  }));
759
4308
  const entries = buildTask.entries.map(entry => {
760
4309
  return _objectSpread(_objectSpread({}, entry), {}, {
761
- name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
4310
+ name: path$1.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
762
4311
  });
763
4312
  }, {});
764
4313
 
765
- const exportIds = _exports && Object.keys(_exports).map(exportPath => path.join(pkg.name, exportPath));
4314
+ const exportIds = _exports && Object.keys(_exports).map(exportPath => path$1.join(pkg.name, exportPath));
766
4315
 
767
- const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
4316
+ const sourcePaths = _exports && Object.values(_exports).map(e => path$1.resolve(cwd, e.source));
768
4317
 
769
4318
  return {
770
4319
  inputOptions: {
@@ -775,10 +4324,10 @@ function _resolveRollupConfig(ctx, buildTask) {
775
4324
  }
776
4325
 
777
4326
  if (importer && (id.startsWith(".") || id.startsWith("/"))) {
778
- const idPath = path.resolve(path.dirname(importer), id);
4327
+ const idPath = path$1.resolve(path$1.dirname(importer), id);
779
4328
 
780
4329
  if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
781
- logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path.relative(cwd, idPath)));
4330
+ logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path$1.relative(cwd, idPath)));
782
4331
  return true;
783
4332
  }
784
4333
  }
@@ -808,14 +4357,14 @@ function _resolveRollupConfig(ctx, buildTask) {
808
4357
  preventAssignment: true,
809
4358
  values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
810
4359
  "process.env.PKG_FILE_PATH": arg => {
811
- const sourcePath = "./" + path.relative(cwd, arg);
4360
+ const sourcePath = "./" + path$1.relative(cwd, arg);
812
4361
  const entry = entries.find(e => e.source === sourcePath);
813
4362
 
814
4363
  if (!entry) {
815
4364
  throw new Error("could not find source entry: ".concat(sourcePath));
816
4365
  }
817
4366
 
818
- return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
4367
+ return JSON.stringify(path$1.relative(cwd, path$1.resolve(outDir, entry.name + outputExt)));
819
4368
  },
820
4369
  "process.env.PKG_FORMAT": JSON.stringify(format),
821
4370
  "process.env.PKG_RUNTIME": JSON.stringify(runtime),
@@ -873,7 +4422,7 @@ function _resolveRollupConfig(ctx, buildTask) {
873
4422
  }
874
4423
 
875
4424
  const _rollupTask = {
876
- name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
4425
+ name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path$1.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
877
4426
  exec: (ctx, task) => {
878
4427
  return new Observable(observer => {
879
4428
  _execPromise(ctx, task).then(result => {
@@ -910,12 +4459,12 @@ async function _execPromise(ctx, task) {
910
4459
  if (chunkOrAsset.type === "asset") {
911
4460
  files.push({
912
4461
  type: "asset",
913
- path: path.resolve(outDir, chunkOrAsset.fileName)
4462
+ path: path$1.resolve(outDir, chunkOrAsset.fileName)
914
4463
  });
915
4464
  } else {
916
4465
  files.push({
917
4466
  type: "chunk",
918
- path: path.resolve(outDir, chunkOrAsset.fileName)
4467
+ path: path$1.resolve(outDir, chunkOrAsset.fileName)
919
4468
  });
920
4469
  }
921
4470
  }
@@ -925,7 +4474,7 @@ async function _execPromise(ctx, task) {
925
4474
  }
926
4475
 
927
4476
  const _rollupWatchTask = {
928
- name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
4477
+ name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path$1.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
929
4478
  exec: (ctx, task) => {
930
4479
  const {
931
4480
  inputOptions,
@@ -952,7 +4501,7 @@ const _rollupWatchTask = {
952
4501
  } = ctx;
953
4502
 
954
4503
  if (event.code === "BUNDLE_END") {
955
- logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
4504
+ logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path$1.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
956
4505
  logger.log("");
957
4506
  return;
958
4507
  }
@@ -1100,8 +4649,8 @@ async function _resolveBuildContext(options) {
1100
4649
 
1101
4650
  const targetVersions = _resolveBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
1102
4651
 
1103
- const srcPath = path.resolve(cwd, (config == null ? void 0 : config.src) || "src");
1104
- const distPath = path.resolve(cwd, (config == null ? void 0 : config.dist) || "dist");
4652
+ const srcPath = path$1.resolve(cwd, (config == null ? void 0 : config.src) || "src");
4653
+ const distPath = path$1.resolve(cwd, (config == null ? void 0 : config.dist) || "dist");
1105
4654
 
1106
4655
  const nodeTarget = _resolveNodeTarget(targetVersions);
1107
4656
 
@@ -1143,7 +4692,7 @@ async function _resolveBuildContext(options) {
1143
4692
  const ctx = {
1144
4693
  config,
1145
4694
  cwd,
1146
- dist: path.relative(cwd, distPath),
4695
+ dist: path$1.relative(cwd, distPath),
1147
4696
  exports,
1148
4697
  external,
1149
4698
  files: [],
@@ -1181,7 +4730,7 @@ async function _resolveBuildContext(options) {
1181
4730
  }
1182
4731
  },
1183
4732
  pkg,
1184
- src: path.relative(cwd, srcPath),
4733
+ src: path$1.relative(cwd, srcPath),
1185
4734
  runtime: (_ref9 = config == null ? void 0 : config.runtime) !== null && _ref9 !== void 0 ? _ref9 : "*",
1186
4735
  target,
1187
4736
  ts: {
@@ -1258,7 +4807,7 @@ function _getFilesize(file) {
1258
4807
 
1259
4808
  function _fileExists(file) {
1260
4809
  try {
1261
- fs$1.accessSync(file);
4810
+ fs$2.accessSync(file);
1262
4811
  return true;
1263
4812
  } catch (_) {
1264
4813
  return false;
@@ -1266,7 +4815,7 @@ function _fileExists(file) {
1266
4815
  }
1267
4816
 
1268
4817
  function _getFileInfo(cwd, filePath) {
1269
- const p = path.resolve(cwd, filePath);
4818
+ const p = path$1.resolve(cwd, filePath);
1270
4819
 
1271
4820
  const exists = _fileExists(p);
1272
4821
 
@@ -1311,18 +4860,28 @@ function _printPackageTree(ctx) {
1311
4860
  source: entry.source,
1312
4861
  default: entry.default
1313
4862
  };
4863
+ if (entry.types) exp.types = _fileInfo(entry.types);
1314
4864
 
1315
4865
  if (entry.browser) {
1316
- exp.browser = {};
4866
+ exp.browser = {
4867
+ source: entry.browser.source
4868
+ };
1317
4869
  if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import);
1318
4870
  if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require);
1319
4871
  }
1320
4872
 
4873
+ if (entry.node) {
4874
+ exp.node = {
4875
+ source: entry.node.source
4876
+ };
4877
+ if (entry.node.import) exp.node.import = _fileInfo(entry.node.import);
4878
+ if (entry.node.require) exp.node.import = _fileInfo(entry.node.require);
4879
+ }
4880
+
1321
4881
  if (entry.import) exp.import = _fileInfo(entry.import);
1322
4882
  if (entry.require) exp.require = _fileInfo(entry.require);
1323
- if (entry.types) exp.types = _fileInfo(entry.types);
1324
4883
  exp.default = _fileInfo(entry.default);
1325
- return [chalk.green(path.join(pkg.name, exportPath)), exp];
4884
+ return [chalk.green(path$1.join(pkg.name, exportPath)), exp];
1326
4885
  }));
1327
4886
  logger.log(treeify.asTree(tree, true, true));
1328
4887
  }
@@ -1352,19 +4911,19 @@ async function check(options) {
1352
4911
  const missingFiles = [];
1353
4912
 
1354
4913
  for (const [, exp] of Object.entries(ctx.exports || {})) {
1355
- if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
4914
+ if (exp.source && !_fileExists(path$1.resolve(cwd, exp.source))) {
1356
4915
  missingFiles.push(exp.source);
1357
4916
  }
1358
4917
 
1359
- if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
4918
+ if (exp.require && !_fileExists(path$1.resolve(cwd, exp.require))) {
1360
4919
  missingFiles.push(exp.require);
1361
4920
  }
1362
4921
 
1363
- if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
4922
+ if (exp.import && !_fileExists(path$1.resolve(cwd, exp.import))) {
1364
4923
  missingFiles.push(exp.import);
1365
4924
  }
1366
4925
 
1367
- if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
4926
+ if (exp.types && !_fileExists(path$1.resolve(cwd, exp.types))) {
1368
4927
  missingFiles.push(exp.types);
1369
4928
  }
1370
4929
  }
@@ -1494,7 +5053,7 @@ function _resolveWatchTasks(ctx) {
1494
5053
  }
1495
5054
 
1496
5055
  for (const exp of exports) {
1497
- const importId = path.join(pkg.name, exp._path);
5056
+ const importId = path$1.join(pkg.name, exp._path);
1498
5057
 
1499
5058
  if (exp.types) {
1500
5059
  dtsTask.entries.push({
@@ -1561,7 +5120,7 @@ function _resolveWatchTasks(ctx) {
1561
5120
  const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
1562
5121
 
1563
5122
  if (relativeTargetPath) {
1564
- fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
5123
+ fs$2.writeFileSync(path$1.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
1565
5124
  }
1566
5125
  }
1567
5126
  }
@@ -1598,9 +5157,9 @@ async function _watchConfigFiles(options) {
1598
5157
  const {
1599
5158
  cwd
1600
5159
  } = options;
1601
- const initialFiles = await _globFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
5160
+ const initialFiles = await _globFiles([path$1.resolve(cwd, "package.json"), path$1.resolve(cwd, "package.config.cjs"), path$1.resolve(cwd, "package.config.js"), path$1.resolve(cwd, "package.config.ts")]);
1602
5161
 
1603
- const fileEvent$ = _watchFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
5162
+ const fileEvent$ = _watchFiles([path$1.resolve(cwd, "package.json"), path$1.resolve(cwd, "package.config.cjs"), path$1.resolve(cwd, "package.config.js"), path$1.resolve(cwd, "package.config.ts")]);
1604
5163
 
1605
5164
  return fileEvent$.pipe(scan((files, fileEvent) => {
1606
5165
  if (fileEvent.type === "add") {
@@ -1613,7 +5172,7 @@ async function _watchConfigFiles(options) {
1613
5172
 
1614
5173
  if (fileEvent.type === "change") {
1615
5174
  console.log("--------------------------------------------------------------------------------");
1616
- console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
5175
+ console.log(chalk.blue("info "), path$1.relative(cwd, fileEvent.file), "changed");
1617
5176
  console.log("");
1618
5177
  return files.slice(0);
1619
5178
  }
@@ -1631,7 +5190,7 @@ async function watch(options) {
1631
5190
  cwd
1632
5191
  });
1633
5192
  const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
1634
- const _files = configFiles.map(f => path.relative(cwd, f));
5193
+ const _files = configFiles.map(f => path$1.relative(cwd, f));
1635
5194
 
1636
5195
  const packageJsonPath = _files.find(f => f === "package.json");
1637
5196