@atlaspack/watcher-watchman-js 2.14.5-canary.138 → 2.14.5-canary.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const writeSnapshot: (dir: string, snapshot: string, opts?: import("@parcel/watcher").Options) => Promise<string>;
2
+ export declare const getEventsSince: (dir: string, snapshot: string, opts?: import("@parcel/watcher").Options) => Promise<Array<import("@parcel/watcher").Event>>;
3
+ export declare const subscribe: (dir: string, fn: import("@parcel/watcher").SubscribeCallback, opts?: import("@parcel/watcher").Options) => Promise<import("@parcel/watcher").AsyncSubscription>;
4
+ export declare const unsubscribe: (dir: string, fn: import("@parcel/watcher").SubscribeCallback, opts?: import("@parcel/watcher").Options) => Promise<void>;
@@ -0,0 +1,27 @@
1
+ import * as watchman from 'fb-watchman';
2
+ import type { Options, Event, SubscribeCallback, AsyncSubscription } from '@parcel/watcher';
3
+ type WatchmanArgs = any;
4
+ type FilePath = string;
5
+ type GlobPattern = string;
6
+ export interface Watcher {
7
+ getEventsSince(dir: FilePath, snapshot: FilePath, opts?: Options): Promise<Array<Event>>;
8
+ subscribe(dir: FilePath, fn: SubscribeCallback, opts?: Options): Promise<AsyncSubscription>;
9
+ unsubscribe(dir: FilePath, fn: SubscribeCallback, opts?: Options): Promise<void>;
10
+ writeSnapshot(dir: FilePath, snapshot: FilePath, opts?: Options): Promise<FilePath>;
11
+ }
12
+ export declare class AtlaspackWatcherWatchmanJS implements Watcher {
13
+ subscriptionName: string;
14
+ client: watchman.Client;
15
+ initPromise: Promise<void> | undefined;
16
+ constructor();
17
+ commandAsync(args: WatchmanArgs): Promise<any>;
18
+ capabilityCheckAsync(args: any): Promise<any>;
19
+ _init(watchDir: string): Promise<void>;
20
+ init(watchDir: string): Promise<void>;
21
+ writeSnapshot(dir: string, snapshot: FilePath): Promise<string>;
22
+ getEventsSince(dir: string, snapshot: FilePath, opts?: Options): Promise<Event[]>;
23
+ _createExpression(dir: string, ignore?: Array<FilePath | GlobPattern>): WatchmanArgs;
24
+ subscribe(dir: string, fn: SubscribeCallback, opts?: Options): Promise<AsyncSubscription>;
25
+ unsubscribe(dir: string): Promise<void>;
26
+ }
27
+ export {};
package/lib/wrapper.js CHANGED
@@ -42,7 +42,10 @@ function _logger() {
42
42
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
43
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
44
44
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
45
+ // @ts-expect-error TS7016
46
+
45
47
  // Matches the Watcher API from "@parcel/watcher"
48
+
46
49
  class AtlaspackWatcherWatchmanJS {
47
50
  constructor() {
48
51
  this.subscriptionName = 'parcel-watcher-subscription-' + Date.now();
@@ -51,9 +54,7 @@ class AtlaspackWatcherWatchmanJS {
51
54
  commandAsync(args) {
52
55
  return new Promise((resolve, reject) => {
53
56
  const client = this.client;
54
- client.command(args,
55
- // $FlowFixMe
56
- (err, response) => {
57
+ client.command(args, (err, response) => {
57
58
  if (err) reject(err);else resolve(response);
58
59
  });
59
60
  });
@@ -61,9 +62,7 @@ class AtlaspackWatcherWatchmanJS {
61
62
  capabilityCheckAsync(args) {
62
63
  return new Promise((resolve, reject) => {
63
64
  const client = this.client;
64
- client.capabilityCheck(args,
65
- // $FlowFixMe
66
- (err, response) => {
65
+ client.capabilityCheck(args, (err, response) => {
67
66
  if (err) reject(err);else resolve(response);
68
67
  });
69
68
  });
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "@atlaspack/watcher-watchman-js",
3
- "version": "2.14.5-canary.138+eda07caaf",
3
+ "version": "2.14.5-canary.139+d2fd84977",
4
4
  "license": "(MIT OR Apache-2.0)",
5
- "main": "lib/index.js",
6
- "source": "src/index.js",
5
+ "main": "./lib/index.js",
6
+ "source": "./src/index.ts",
7
+ "types": "./lib/index.d.ts",
7
8
  "publishConfig": {
8
9
  "access": "public"
9
10
  },
10
11
  "dependencies": {
11
- "@atlaspack/logger": "2.14.5-canary.138+eda07caaf",
12
- "@atlaspack/utils": "2.14.5-canary.138+eda07caaf",
12
+ "@atlaspack/logger": "2.14.5-canary.139+d2fd84977",
13
+ "@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
13
14
  "@parcel/watcher": "^2.4.1",
14
15
  "fb-watchman": "^2.0.2"
15
16
  },
16
17
  "type": "commonjs",
17
- "gitHead": "eda07caafd2ebb814bbdbfd0ec12fa63124e213f"
18
- }
18
+ "scripts": {
19
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
20
+ },
21
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
22
+ }
@@ -1,6 +1,7 @@
1
1
  import {AtlaspackWatcherWatchmanJS} from './wrapper';
2
+ import type {Watcher} from './wrapper';
2
3
 
3
- const wrapper = new AtlaspackWatcherWatchmanJS();
4
+ const wrapper: Watcher = new AtlaspackWatcherWatchmanJS();
4
5
 
5
6
  export const writeSnapshot = wrapper.writeSnapshot.bind(wrapper);
6
7
  export const getEventsSince = wrapper.getEventsSince.bind(wrapper);
@@ -1,6 +1,6 @@
1
- // @flow
2
1
  import * as fs from 'fs';
3
2
  import * as path from 'path';
3
+ // @ts-expect-error TS7016
4
4
  import * as watchman from 'fb-watchman';
5
5
  import {isGlob} from '@atlaspack/utils';
6
6
  import logger from '@atlaspack/logger';
@@ -42,39 +42,44 @@ export interface Watcher {
42
42
  export class AtlaspackWatcherWatchmanJS implements Watcher {
43
43
  subscriptionName: string;
44
44
  client: watchman.Client;
45
- initPromise: Promise<void> | void;
45
+ initPromise: Promise<void> | undefined;
46
46
 
47
47
  constructor() {
48
48
  this.subscriptionName = 'parcel-watcher-subscription-' + Date.now();
49
49
  this.client = new watchman.Client();
50
50
  }
51
51
 
52
- commandAsync(args: any[]): Promise<any> {
53
- return new Promise((resolve, reject) => {
54
- const client = this.client;
55
- client.command(
56
- args,
57
- // $FlowFixMe
58
- (err: Error | null | undefined, response: any) => {
52
+ commandAsync(args: WatchmanArgs): Promise<any> {
53
+ return new Promise(
54
+ (
55
+ resolve: (result: Promise<never>) => void,
56
+ reject: (error?: any) => void,
57
+ ) => {
58
+ const client = this.client;
59
+ client.command(args, (err: Error | null | undefined, response: any) => {
59
60
  if (err) reject(err);
60
61
  else resolve(response);
61
- },
62
- );
63
- });
62
+ });
63
+ },
64
+ );
64
65
  }
65
66
 
66
67
  capabilityCheckAsync(args: any): Promise<any> {
67
- return new Promise((resolve, reject) => {
68
- const client = this.client;
69
- client.capabilityCheck(
70
- args,
71
- // $FlowFixMe
72
- (err: Error | null | undefined, response: any) => {
73
- if (err) reject(err);
74
- else resolve(response);
75
- },
76
- );
77
- });
68
+ return new Promise(
69
+ (
70
+ resolve: (result: Promise<never>) => void,
71
+ reject: (error?: any) => void,
72
+ ) => {
73
+ const client = this.client;
74
+ client.capabilityCheck(
75
+ args,
76
+ (err: Error | null | undefined, response: any) => {
77
+ if (err) reject(err);
78
+ else resolve(response);
79
+ },
80
+ );
81
+ },
82
+ );
78
83
  }
79
84
  async _init(watchDir: string): Promise<void> {
80
85
  await this.capabilityCheckAsync({optional: [], required: []});
@@ -146,17 +151,19 @@ export class AtlaspackWatcherWatchmanJS implements Watcher {
146
151
  ];
147
152
 
148
153
  if (ignore) {
149
- const customIgnores = ignore?.map((filePathOrGlob) => {
150
- const relative = path.relative(dir, filePathOrGlob);
154
+ const customIgnores = ignore?.map(
155
+ (filePathOrGlob: FilePath | GlobPattern) => {
156
+ const relative = path.relative(dir, filePathOrGlob);
151
157
 
152
- if (isGlob(filePathOrGlob)) {
153
- return ['match', relative, 'wholename'];
154
- }
158
+ if (isGlob(filePathOrGlob)) {
159
+ return ['match', relative, 'wholename'];
160
+ }
155
161
 
156
- // If pattern is not a glob, then assume it's a directory.
157
- // Ignoring single files is not currently supported
158
- return ['dirname', relative];
159
- });
162
+ // If pattern is not a glob, then assume it's a directory.
163
+ // Ignoring single files is not currently supported
164
+ return ['dirname', relative];
165
+ },
166
+ );
160
167
 
161
168
  ignores.push(...customIgnores);
162
169
  }
@@ -190,7 +197,7 @@ export class AtlaspackWatcherWatchmanJS implements Watcher {
190
197
  },
191
198
  ]);
192
199
 
193
- this.client.on('subscription', function (resp) {
200
+ this.client.on('subscription', function (resp: any) {
194
201
  if (!resp.files || resp.subscription !== subscriptionName) {
195
202
  return;
196
203
  }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }