vite 2.8.0-beta.1 → 2.8.0-beta.5

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

Files changed (89) hide show
  1. package/CHANGELOG.md +79 -1
  2. package/LICENSE.md +65 -57
  3. package/bin/vite.js +3 -1
  4. package/client.d.ts +4 -0
  5. package/dist/client/client.mjs +10 -5
  6. package/dist/client/client.mjs.map +1 -1
  7. package/dist/node/chunks/dep-0ebab0df.js +0 -1
  8. package/dist/node/chunks/dep-2056ae8a.js +0 -1
  9. package/dist/node/chunks/{dep-fccf00e1.js → dep-6c133e83.js} +147 -482
  10. package/dist/node/chunks/{dep-e4a9e288.js → dep-ae5bfd1c.js} +1 -2
  11. package/dist/node/chunks/{dep-e4dc9ea2.js → dep-aff09a4c.js} +3423 -2774
  12. package/dist/node/chunks/{dep-51191982.js → dep-ba706304.js} +16 -5
  13. package/dist/node/cli.js +4 -6
  14. package/dist/node/index.d.ts +20 -18
  15. package/dist/node/index.js +1 -3
  16. package/package.json +22 -22
  17. package/src/client/client.ts +12 -6
  18. package/types/chokidar.d.ts +27 -18
  19. package/types/importMeta.d.ts +17 -2
  20. package/dist/node/build.d.ts +0 -200
  21. package/dist/node/certificate.d.ts +0 -2
  22. package/dist/node/chunks/dep-0ebab0df.js.map +0 -1
  23. package/dist/node/chunks/dep-2056ae8a.js.map +0 -1
  24. package/dist/node/chunks/dep-51191982.js.map +0 -1
  25. package/dist/node/chunks/dep-e4a9e288.js.map +0 -1
  26. package/dist/node/chunks/dep-e4dc9ea2.js.map +0 -1
  27. package/dist/node/chunks/dep-fccf00e1.js.map +0 -1
  28. package/dist/node/cli.d.ts +0 -1
  29. package/dist/node/cli.js.map +0 -1
  30. package/dist/node/config.d.ts +0 -227
  31. package/dist/node/constants.d.ts +0 -33
  32. package/dist/node/http.d.ts +0 -88
  33. package/dist/node/importGlob.d.ts +0 -14
  34. package/dist/node/index.js.map +0 -1
  35. package/dist/node/logger.d.ts +0 -35
  36. package/dist/node/optimizer/esbuildDepPlugin.d.ts +0 -4
  37. package/dist/node/optimizer/index.d.ts +0 -66
  38. package/dist/node/optimizer/registerMissing.d.ts +0 -2
  39. package/dist/node/optimizer/scan.d.ts +0 -9
  40. package/dist/node/packages.d.ts +0 -25
  41. package/dist/node/plugin.d.ts +0 -115
  42. package/dist/node/plugins/asset.d.ts +0 -40
  43. package/dist/node/plugins/assetImportMetaUrl.d.ts +0 -13
  44. package/dist/node/plugins/clientInjections.d.ts +0 -7
  45. package/dist/node/plugins/css.d.ts +0 -71
  46. package/dist/node/plugins/dataUri.d.ts +0 -5
  47. package/dist/node/plugins/define.d.ts +0 -3
  48. package/dist/node/plugins/esbuild.d.ts +0 -15
  49. package/dist/node/plugins/html.d.ts +0 -105
  50. package/dist/node/plugins/importAnalysis.d.ts +0 -46
  51. package/dist/node/plugins/importAnalysisBuild.d.ts +0 -15
  52. package/dist/node/plugins/index.d.ts +0 -3
  53. package/dist/node/plugins/json.d.ts +0 -22
  54. package/dist/node/plugins/loadFallback.d.ts +0 -5
  55. package/dist/node/plugins/manifest.d.ts +0 -14
  56. package/dist/node/plugins/modulePreloadPolyfill.d.ts +0 -4
  57. package/dist/node/plugins/preAlias.d.ts +0 -5
  58. package/dist/node/plugins/reporter.d.ts +0 -3
  59. package/dist/node/plugins/resolve.d.ts +0 -38
  60. package/dist/node/plugins/ssrRequireHook.d.ts +0 -12
  61. package/dist/node/plugins/terser.d.ts +0 -3
  62. package/dist/node/plugins/wasm.d.ts +0 -3
  63. package/dist/node/plugins/worker.d.ts +0 -5
  64. package/dist/node/plugins/workerImportMetaUrl.d.ts +0 -3
  65. package/dist/node/preview.d.ts +0 -31
  66. package/dist/node/server/hmr.d.ts +0 -37
  67. package/dist/node/server/index.d.ts +0 -222
  68. package/dist/node/server/middlewares/base.d.ts +0 -3
  69. package/dist/node/server/middlewares/error.d.ts +0 -8
  70. package/dist/node/server/middlewares/indexHtml.d.ts +0 -4
  71. package/dist/node/server/middlewares/proxy.d.ts +0 -20
  72. package/dist/node/server/middlewares/spaFallback.d.ts +0 -2
  73. package/dist/node/server/middlewares/static.d.ts +0 -6
  74. package/dist/node/server/middlewares/time.d.ts +0 -2
  75. package/dist/node/server/middlewares/transform.d.ts +0 -3
  76. package/dist/node/server/moduleGraph.d.ts +0 -53
  77. package/dist/node/server/openBrowser.d.ts +0 -15
  78. package/dist/node/server/pluginContainer.d.ts +0 -37
  79. package/dist/node/server/searchRoot.d.ts +0 -8
  80. package/dist/node/server/send.d.ts +0 -10
  81. package/dist/node/server/sourcemap.d.ts +0 -8
  82. package/dist/node/server/transformRequest.d.ts +0 -14
  83. package/dist/node/server/ws.d.ts +0 -14
  84. package/dist/node/ssr/ssrExternal.d.ts +0 -7
  85. package/dist/node/ssr/ssrManifestPlugin.d.ts +0 -3
  86. package/dist/node/ssr/ssrModuleLoader.d.ts +0 -7
  87. package/dist/node/ssr/ssrStacktrace.d.ts +0 -3
  88. package/dist/node/ssr/ssrTransform.d.ts +0 -8
  89. package/dist/node/utils.d.ts +0 -115
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var build = require('./dep-e4dc9ea2.js');
3
+ var build = require('./dep-aff09a4c.js');
4
4
 
5
5
  function _mergeNamespaces(n, m) {
6
6
  for (var i = 0; i < m.length; i++) {
@@ -340,8 +340,20 @@ const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,col
340
340
  'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
341
341
  'text,textPath,title,tspan,unknown,use,view';
342
342
  const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
343
+ /**
344
+ * Compiler only.
345
+ * Do NOT use in runtime code paths unless behind `(process.env.NODE_ENV !== 'production')` flag.
346
+ */
343
347
  const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
348
+ /**
349
+ * Compiler only.
350
+ * Do NOT use in runtime code paths unless behind `(process.env.NODE_ENV !== 'production')` flag.
351
+ */
344
352
  const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
353
+ /**
354
+ * Compiler only.
355
+ * Do NOT use in runtime code paths unless behind `(process.env.NODE_ENV !== 'production')` flag.
356
+ */
345
357
  const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
346
358
 
347
359
  const escapeRE = /["'&<>]/;
@@ -1942,7 +1954,7 @@ function parseAttributes(context, type) {
1942
1954
  }
1943
1955
  const attr = parseAttribute(context, attributeNames);
1944
1956
  // Trim whitespace between class
1945
- // https://github.com/vuejs/vue-next/issues/4251
1957
+ // https://github.com/vuejs/core/issues/4251
1946
1958
  if (attr.type === 6 /* ATTRIBUTE */ &&
1947
1959
  attr.value &&
1948
1960
  attr.name === 'class') {
@@ -2178,7 +2190,7 @@ function parseTextData(context, length, mode) {
2178
2190
  advanceBy(context, length);
2179
2191
  if (mode === 2 /* RAWTEXT */ ||
2180
2192
  mode === 3 /* CDATA */ ||
2181
- rawText.indexOf('&') === -1) {
2193
+ !rawText.includes('&')) {
2182
2194
  return rawText;
2183
2195
  }
2184
2196
  else {
@@ -3802,6 +3814,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
3802
3814
  const renderExp = createCallExpression(helper(RENDER_LIST), [
3803
3815
  forNode.source
3804
3816
  ]);
3817
+ const isTemplate = isTemplateNode(node);
3805
3818
  const memo = findDir(node, 'memo');
3806
3819
  const keyProp = findProp(node, `key`);
3807
3820
  const keyExp = keyProp &&
@@ -3821,7 +3834,6 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
3821
3834
  return () => {
3822
3835
  // finish the codegen now that all children have been traversed
3823
3836
  let childBlock;
3824
- const isTemplate = isTemplateNode(node);
3825
3837
  const { children } = forNode;
3826
3838
  // check <template v-for> key placement
3827
3839
  if (((process.env.NODE_ENV !== 'production') || !true) && isTemplate) {
@@ -8738,4 +8750,3 @@ var compilerDom_cjs$1 = /*#__PURE__*/_mergeNamespaces({
8738
8750
  }, [compilerDom_cjs$2]);
8739
8751
 
8740
8752
  exports.compilerDom_cjs = compilerDom_cjs$1;
8741
- //# sourceMappingURL=dep-51191982.js.map
package/dist/node/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var require$$0 = require('events');
4
- var build = require('./chunks/dep-e4dc9ea2.js');
4
+ var build = require('./chunks/dep-aff09a4c.js');
5
5
  var perf_hooks = require('perf_hooks');
6
6
  require('fs');
7
7
  require('path');
@@ -22,7 +22,6 @@ require('assert');
22
22
  require('buffer');
23
23
  require('querystring');
24
24
  require('esbuild');
25
- require('json5');
26
25
  require('child_process');
27
26
  require('worker_threads');
28
27
  require('readline');
@@ -684,7 +683,7 @@ cli
684
683
  .action(async (root, options) => {
685
684
  // output structure is preserved even after bundling so require()
686
685
  // is ok here
687
- const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-e4dc9ea2.js'); }).then(function (n) { return n.index$1; });
686
+ const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-aff09a4c.js'); }).then(function (n) { return n.index$1; });
688
687
  try {
689
688
  const server = await createServer({
690
689
  root,
@@ -733,7 +732,7 @@ cli
733
732
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
734
733
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
735
734
  .action(async (root, options) => {
736
- const { build: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-e4dc9ea2.js'); }).then(function (n) { return n.build$1; });
735
+ const { build: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-aff09a4c.js'); }).then(function (n) { return n.build$1; });
737
736
  const buildOptions = cleanOptions(options);
738
737
  try {
739
738
  await build$1({
@@ -756,7 +755,7 @@ cli
756
755
  .command('optimize [root]')
757
756
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
758
757
  .action(async (root, options) => {
759
- const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-e4dc9ea2.js'); }).then(function (n) { return n.index; });
758
+ const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-aff09a4c.js'); }).then(function (n) { return n.index; });
760
759
  try {
761
760
  const config = await build.resolveConfig({
762
761
  root,
@@ -804,4 +803,3 @@ cli
804
803
  cli.help();
805
804
  cli.version(require('../../package.json').version);
806
805
  cli.parse();
807
- //# sourceMappingURL=cli.js.map
@@ -74,6 +74,18 @@ export declare type AnymatchFn = (testString: string) => boolean
74
74
 
75
75
  export declare type AnymatchPattern = string | RegExp | AnymatchFn
76
76
 
77
+ export declare interface AwaitWriteFinishOptions {
78
+ /**
79
+ * Amount of time in milliseconds for a file size to remain constant before emitting its event.
80
+ */
81
+ stabilityThreshold?: number
82
+
83
+ /**
84
+ * File size polling interval.
85
+ */
86
+ pollInterval?: number
87
+ }
88
+
77
89
  /**
78
90
  * Bundles the app for production.
79
91
  * Returns a Promise containing the build result.
@@ -601,25 +613,25 @@ export declare interface FileSystemServeOptions {
601
613
  deny?: string[];
602
614
  }
603
615
 
604
- export declare interface FSWatcher extends fs.FSWatcher {
616
+ export declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
605
617
  options: WatchOptions
606
618
 
607
619
  /**
608
620
  * Constructs a new FSWatcher instance with optional WatchOptions parameter.
609
621
  */
610
- (options?: WatchOptions): void
622
+ constructor(options?: WatchOptions)
611
623
 
612
624
  /**
613
625
  * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
614
626
  * string.
615
627
  */
616
- add(paths: string | ReadonlyArray<string>): void
628
+ add(paths: string | ReadonlyArray<string>): this
617
629
 
618
630
  /**
619
631
  * Stop watching files, directories, or glob patterns. Takes an array of strings or just one
620
632
  * string.
621
633
  */
622
- unwatch(paths: string | ReadonlyArray<string>): void
634
+ unwatch(paths: string | ReadonlyArray<string>): this
623
635
 
624
636
  /**
625
637
  * Returns an object representing all the paths on the file system being watched by this
@@ -1333,6 +1345,7 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'alia
1333
1345
  root: string;
1334
1346
  base: string;
1335
1347
  publicDir: string;
1348
+ cacheDir: string;
1336
1349
  command: 'build' | 'serve';
1337
1350
  mode: string;
1338
1351
  isProduction: boolean;
@@ -1894,6 +1907,7 @@ export declare interface UserConfig {
1894
1907
  * the performance. You can use `--force` flag or manually delete the directory
1895
1908
  * to regenerate the cache files. The value can be either an absolute file
1896
1909
  * system path or a path relative to <root>.
1910
+ * Default to `.vite` when no package.json is detected.
1897
1911
  * @default 'node_modules/.vite'
1898
1912
  */
1899
1913
  cacheDir?: string;
@@ -2161,7 +2175,7 @@ export declare interface WatchOptions {
2161
2175
 
2162
2176
  /**
2163
2177
  * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
2164
- * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
2178
+ * and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on
2165
2179
  * OS X, `usePolling: true` becomes the default.
2166
2180
  */
2167
2181
  useFsEvents?: boolean
@@ -2208,19 +2222,7 @@ export declare interface WatchOptions {
2208
2222
  /**
2209
2223
  * can be set to an object in order to adjust timing params:
2210
2224
  */
2211
- awaitWriteFinish?:
2212
- | {
2213
- /**
2214
- * Amount of time in milliseconds for a file size to remain constant before emitting its event.
2215
- */
2216
- stabilityThreshold?: number
2217
-
2218
- /**
2219
- * File size polling interval.
2220
- */
2221
- pollInterval?: number
2222
- }
2223
- | boolean
2225
+ awaitWriteFinish?: AwaitWriteFinishOptions | boolean
2224
2226
  }
2225
2227
 
2226
2228
  export declare class WebSocket extends EventEmitter {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var build = require('./chunks/dep-e4dc9ea2.js');
5
+ var build = require('./chunks/dep-aff09a4c.js');
6
6
  require('fs');
7
7
  require('path');
8
8
  require('tty');
@@ -24,7 +24,6 @@ require('assert');
24
24
  require('buffer');
25
25
  require('querystring');
26
26
  require('esbuild');
27
- require('json5');
28
27
  require('child_process');
29
28
  require('worker_threads');
30
29
  require('readline');
@@ -50,4 +49,3 @@ exports.searchForWorkspaceRoot = build.searchForWorkspaceRoot;
50
49
  exports.send = build.send;
51
50
  exports.sortUserPlugins = build.sortUserPlugins;
52
51
  exports.transformWithEsbuild = build.transformWithEsbuild;
53
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "2.8.0-beta.1",
3
+ "version": "2.8.0-beta.5",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "Native-ESM powered web dev build tool",
@@ -44,24 +44,23 @@
44
44
  },
45
45
  "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
46
46
  "dependencies": {
47
- "esbuild": "0.14.3",
48
- "json5": "^2.2.0",
47
+ "esbuild": "^0.14.14",
49
48
  "postcss": "^8.4.5",
50
- "resolve": "^1.20.0",
49
+ "resolve": "^1.22.0",
51
50
  "rollup": "^2.59.0"
52
51
  },
53
52
  "optionalDependencies": {
54
53
  "fsevents": "~2.3.2"
55
54
  },
56
55
  "devDependencies": {
57
- "@ampproject/remapping": "^1.0.2",
58
- "@babel/parser": "^7.16.6",
59
- "@babel/types": "^7.16.0",
60
- "@rollup/plugin-alias": "^3.1.8",
56
+ "@ampproject/remapping": "^1.1.1",
57
+ "@babel/parser": "^7.16.12",
58
+ "@babel/types": "^7.16.8",
59
+ "@rollup/plugin-alias": "^3.1.9",
61
60
  "@rollup/plugin-commonjs": "^21.0.1",
62
61
  "@rollup/plugin-dynamic-import-vars": "^1.4.2",
63
62
  "@rollup/plugin-json": "^4.1.0",
64
- "@rollup/plugin-node-resolve": "13.1.1",
63
+ "@rollup/plugin-node-resolve": "13.1.3",
65
64
  "@rollup/plugin-typescript": "^8.3.0",
66
65
  "@rollup/pluginutils": "^4.1.2",
67
66
  "@types/convert-source-map": "^1.5.2",
@@ -72,15 +71,15 @@
72
71
  "@types/less": "^3.0.3",
73
72
  "@types/micromatch": "^4.0.2",
74
73
  "@types/mime": "^2.0.3",
75
- "@types/node": "^16.11.17",
74
+ "@types/node": "^16.11.21",
76
75
  "@types/resolve": "^1.20.1",
77
76
  "@types/sass": "~1.43.1",
78
77
  "@types/stylus": "^0.48.36",
79
78
  "@types/ws": "^8.2.2",
80
- "@vue/compiler-dom": "^3.2.26",
79
+ "@vue/compiler-dom": "^3.2.29",
81
80
  "acorn": "^8.7.0",
82
81
  "cac": "6.7.9",
83
- "chokidar": "^3.5.2",
82
+ "chokidar": "^3.5.3",
84
83
  "compression": "^1.7.4",
85
84
  "connect": "^3.7.0",
86
85
  "connect-history-api-fallback": "^1.6.0",
@@ -88,36 +87,37 @@
88
87
  "cors": "^2.8.5",
89
88
  "cross-spawn": "^7.0.3",
90
89
  "debug": "^4.3.3",
91
- "dotenv": "^10.0.0",
92
- "dotenv-expand": "^5.1.0",
90
+ "dotenv": "^14.3.2",
91
+ "dotenv-expand": "^6.0.1",
93
92
  "es-module-lexer": "^0.9.3",
94
93
  "estree-walker": "^2.0.2",
95
94
  "etag": "^1.8.1",
96
- "fast-glob": "^3.2.7",
95
+ "fast-glob": "^3.2.11",
97
96
  "http-proxy": "^1.18.1",
97
+ "json5": "^2.2.0",
98
98
  "launch-editor-middleware": "^2.3.0",
99
99
  "magic-string": "^0.25.7",
100
100
  "micromatch": "^4.0.4",
101
101
  "mrmime": "^1.0.0",
102
- "node-forge": "^0.10.0",
102
+ "node-forge": "^1.2.1",
103
103
  "okie": "^1.0.1",
104
104
  "open": "^8.4.0",
105
105
  "periscopic": "^2.0.3",
106
106
  "picocolors": "^1.0.0",
107
107
  "postcss-import": "^14.0.2",
108
- "postcss-load-config": "^3.1.0",
108
+ "postcss-load-config": "^3.1.1",
109
109
  "postcss-modules": "^4.3.0",
110
110
  "resolve.exports": "^1.1.0",
111
- "rollup-plugin-license": "^2.6.0",
112
- "sirv": "^2.0.0",
113
- "source-map": "^0.6.1",
111
+ "rollup-plugin-license": "^2.6.1",
112
+ "sirv": "^2.0.2",
113
+ "source-map-js": "^1.0.2",
114
114
  "source-map-support": "^0.5.21",
115
115
  "strip-ansi": "^6.0.1",
116
116
  "terser": "^5.10.0",
117
- "tsconfck": "1.1.1",
117
+ "tsconfck": "1.1.2",
118
118
  "tslib": "^2.3.1",
119
119
  "types": "link:./types",
120
- "ws": "^8.4.0"
120
+ "ws": "^8.4.2"
121
121
  },
122
122
  "peerDependencies": {
123
123
  "less": "*",
@@ -39,6 +39,12 @@ function warnFailedFetch(err: Error, path: string | string[]) {
39
39
  )
40
40
  }
41
41
 
42
+ function cleanUrl(pathname: string): string {
43
+ const url = new URL(pathname, location.toString())
44
+ url.searchParams.delete('direct')
45
+ return url.pathname + url.search
46
+ }
47
+
42
48
  // Listen for messages
43
49
  socket.addEventListener('message', async ({ data }) => {
44
50
  handleMessage(JSON.parse(data))
@@ -73,21 +79,21 @@ async function handleMessage(payload: HMRPayload) {
73
79
  } else {
74
80
  // css-update
75
81
  // this is only sent when a css file referenced with <link> is updated
76
- let { path, timestamp } = update
77
- path = path.replace(/\?.*/, '')
82
+ const { path, timestamp } = update
83
+ const searchUrl = cleanUrl(path)
78
84
  // can't use querySelector with `[href*=]` here since the link may be
79
85
  // using relative paths so we need to use link.href to grab the full
80
86
  // URL for the include check.
81
87
  const el = Array.from(
82
88
  document.querySelectorAll<HTMLLinkElement>('link')
83
- ).find((e) => e.href.includes(path))
89
+ ).find((e) => cleanUrl(e.href).includes(searchUrl))
84
90
  if (el) {
85
- const newPath = `${base}${path.slice(1)}${
86
- path.includes('?') ? '&' : '?'
91
+ const newPath = `${base}${searchUrl.slice(1)}${
92
+ searchUrl.includes('?') ? '&' : '?'
87
93
  }t=${timestamp}`
88
94
  el.href = new URL(newPath, el.href).href
89
95
  }
90
- console.log(`[vite] css hot updated: ${path}`)
96
+ console.log(`[vite] css hot updated: ${searchUrl}`)
91
97
  }
92
98
  })
93
99
  break
@@ -29,27 +29,28 @@ THE SOFTWARE.
29
29
  /// <reference types="node" />
30
30
 
31
31
  import type * as fs from 'fs'
32
+ import { EventEmitter } from 'events'
32
33
  import type { Matcher } from './anymatch'
33
34
 
34
- export interface FSWatcher extends fs.FSWatcher {
35
+ export class FSWatcher extends EventEmitter implements fs.FSWatcher {
35
36
  options: WatchOptions
36
37
 
37
38
  /**
38
39
  * Constructs a new FSWatcher instance with optional WatchOptions parameter.
39
40
  */
40
- (options?: WatchOptions): void
41
+ constructor(options?: WatchOptions)
41
42
 
42
43
  /**
43
44
  * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
44
45
  * string.
45
46
  */
46
- add(paths: string | ReadonlyArray<string>): void
47
+ add(paths: string | ReadonlyArray<string>): this
47
48
 
48
49
  /**
49
50
  * Stop watching files, directories, or glob patterns. Takes an array of strings or just one
50
51
  * string.
51
52
  */
52
- unwatch(paths: string | ReadonlyArray<string>): void
53
+ unwatch(paths: string | ReadonlyArray<string>): this
53
54
 
54
55
  /**
55
56
  * Returns an object representing all the paths on the file system being watched by this
@@ -155,7 +156,7 @@ export interface WatchOptions {
155
156
 
156
157
  /**
157
158
  * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
158
- * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
159
+ * and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on
159
160
  * OS X, `usePolling: true` becomes the default.
160
161
  */
161
162
  useFsEvents?: boolean
@@ -202,17 +203,25 @@ export interface WatchOptions {
202
203
  /**
203
204
  * can be set to an object in order to adjust timing params:
204
205
  */
205
- awaitWriteFinish?:
206
- | {
207
- /**
208
- * Amount of time in milliseconds for a file size to remain constant before emitting its event.
209
- */
210
- stabilityThreshold?: number
211
-
212
- /**
213
- * File size polling interval.
214
- */
215
- pollInterval?: number
216
- }
217
- | boolean
206
+ awaitWriteFinish?: AwaitWriteFinishOptions | boolean
218
207
  }
208
+
209
+ export interface AwaitWriteFinishOptions {
210
+ /**
211
+ * Amount of time in milliseconds for a file size to remain constant before emitting its event.
212
+ */
213
+ stabilityThreshold?: number
214
+
215
+ /**
216
+ * File size polling interval.
217
+ */
218
+ pollInterval?: number
219
+ }
220
+
221
+ /**
222
+ * produces an instance of `FSWatcher`.
223
+ */
224
+ export function watch(
225
+ paths: string | ReadonlyArray<string>,
226
+ options?: WatchOptions
227
+ ): FSWatcher
@@ -4,6 +4,15 @@
4
4
 
5
5
  /* eslint-disable @typescript-eslint/consistent-type-imports */
6
6
 
7
+ // Duplicate import('../src/node/importGlob').AssertOptions
8
+ // Avoid breaking the production client type because this file is referenced
9
+ // in vite/client.d.ts and in production src/node/importGlob.ts doesn't exist
10
+ interface AssertOptions {
11
+ assert?: {
12
+ type: string
13
+ }
14
+ }
15
+
7
16
  interface ImportMeta {
8
17
  url: string
9
18
 
@@ -50,14 +59,20 @@ interface ImportMeta {
50
59
 
51
60
  readonly env: ImportMetaEnv
52
61
 
53
- glob(pattern: string): Record<
62
+ glob(
63
+ pattern: string,
64
+ options?: AssertOptions
65
+ ): Record<
54
66
  string,
55
67
  () => Promise<{
56
68
  [key: string]: any
57
69
  }>
58
70
  >
59
71
 
60
- globEager(pattern: string): Record<
72
+ globEager(
73
+ pattern: string,
74
+ options?: AssertOptions
75
+ ): Record<
61
76
  string,
62
77
  {
63
78
  [key: string]: any