@parcel/watcher-watchman-js 2.12.1-canary.3337 → 2.12.1-canary.3339
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.js.map +1 -1
- package/lib/wrapper.js +42 -1
- package/package.json +4 -3
- package/src/wrapper.js +48 -5
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;ACwCO,MAAMA;IAIXW,aAAc;QACZ,IAAI,CAACC,gBAAgB,GAAG,iCAAiCC,KAAKC,GAAG;QACjE,IAAI,CAACC,MAAM,GAAG,IAAIN;IACpB;IAEAQ,aAAaC,IAAW,EAAgB;QACtC,OAAO,IAAIC,QAAQ,CAACC,SAASC;YAC3B,MAAMN,SAAS,IAAI,CAACA,MAAM;YAC1B,aAAA;YACAA,OAAOO,OAAO,CAACJ,MAAM,CAACK,KAA+BC;gBACnD,IAAID,KAAKF,OAAOE;qBACXH,QAAQI;YACf;QACF;IACF;IAEA,mDAAA;IACA,MAAMtB,cAAcuB,GAAW,EAAEC,QAAkB,EAAmB;QACpE,MAAMF,WAAW,MAAM,IAAI,CAACP,YAAY,CAAC;YAAC;YAASQ;SAAI;QACvDlB,wBAAiBmB,UAAUF,SAASI,KAAK,EAAE;YACzCC,UAAU;QACZ;QACA,OAAOL,SAASI,KAAK;IACvB;IAEA,MAAMxB,eACJqB,GAAW,EACXC,QAAkB,EAClBI,IAAc,EACI;QAClB,MAAMF,QAAQrB,uBAAgBmB,UAAU;YACtCG,UAAU;QACZ;QAEA,MAAML,WAAW,MAAM,IAAI,CAACP,YAAY,CAAC;YACvC;YACAQ;YACA;gBACEO,YAAY,IAAI,CAACC,iBAAiB,CAACR,KAAKK,MAAMI;gBAC9CC,QAAQ;oBAAC;oBAAQ;oBAAQ;oBAAU;iBAAM;gBACzCC,OAAOR;YACT;SACD;QAED,OAAO,AAACJ,CAAAA,SAASa,KAAK,IAAI,EAAE,AAAF,EAAIC,GAAG,CAAEC,CAAAA,OAAe,CAAA;gBAChD/B,MAAM+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G,CAAEC,CAAAA;gBACd,OAAO;oBACL/B,MAAMA,iBAAUiB,KAAKc,KAAKC,IAAI;oBAC9BC,MAAMF,KAAKG,GAAG,GAAG,WAAWH,KAAKI,MAAM,GAAG,WAAW;gBACvD;YACF;QAEJ;QAEA,MAAMrC,cAAc;YAClB,MAAM,IAAI,CAACW,YAAY,CAAC;gBAAC;gBAAeQ;gBAAKb;aAAiB;QAChE;QAEA,OAAO;yBACLN;QACF;IACF;IAEA,MAAMA,YAAYmB,GAAW,EAAiB;QAC5C,MAAM,IAAI,CAACR,YAAY,CAAC;YAAC;YAAeQ;YAAK,IAAI,CAACb,gBAAgB;SAAC;IACrE;AACF;;;AD9KA,MAAMX,gCAAU,IAAID,CAAAA,GAAAA,wCAAAA;AAEb,MAAME,4CAAgBD,8BAAQC,aAAa,CAACC,IAAI,CAACF;AACjD,MAAMG,4CAAiBH,8BAAQG,cAAc,CAACD,IAAI,CAACF;AACnD,MAAMI,4CAAYJ,8BAAQI,SAAS,CAACF,IAAI,CAACF;AACzC,MAAMK,4CAAcL,8BAAQK,WAAW,CAACH,IAAI,CAACF","sources":["packages/utils/parcel-watcher-watchman-js/src/index.js","packages/utils/parcel-watcher-watchman-js/src/wrapper.js"],"sourcesContent":["import {ParcelWatcherWatchmanJS} from './wrapper';\n\nconst wrapper = new ParcelWatcherWatchmanJS();\n\nexport const writeSnapshot = wrapper.writeSnapshot.bind(wrapper);\nexport const getEventsSince = wrapper.getEventsSince.bind(wrapper);\nexport const subscribe = wrapper.subscribe.bind(wrapper);\nexport const unsubscribe = wrapper.unsubscribe.bind(wrapper);\n","// @flow\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as watchman from 'fb-watchman';\nimport {isGlob} from '@parcel/utils';\nimport type {\n Options,\n Event,\n SubscribeCallback,\n AsyncSubscription,\n} from '@parcel/watcher';\n\ntype WatchmanArgs = any;\ntype FilePath = string;\ntype GlobPattern = string;\n\n// Matches the Watcher API from \"@parcel/watcher\"\nexport interface Watcher {\n getEventsSince(\n dir: FilePath,\n snapshot: FilePath,\n opts?: Options,\n ): Promise<Array<Event>>;\n subscribe(\n dir: FilePath,\n fn: SubscribeCallback,\n opts?: Options,\n ): Promise<AsyncSubscription>;\n unsubscribe(\n dir: FilePath,\n fn: SubscribeCallback,\n opts?: Options,\n ): Promise<void>;\n writeSnapshot(\n dir: FilePath,\n snapshot: FilePath,\n opts?: Options,\n ): Promise<FilePath>;\n}\n\nexport class ParcelWatcherWatchmanJS implements Watcher {\n subscriptionName: string;\n client: watchman.Client;\n\n constructor() {\n this.subscriptionName = 'parcel-watcher-subscription-' + Date.now();\n this.client = new watchman.Client();\n }\n\n commandAsync(args: any[]): Promise<any> {\n return new Promise((resolve, reject) => {\n const client = this.client;\n // $FlowFixMe\n client.command(args, (err: Error | null | undefined, response: any) => {\n if (err) reject(err);\n else resolve(response);\n });\n });\n }\n\n // Types should match @parcel/watcher/index.js.flow\n async writeSnapshot(dir: string, snapshot: FilePath): Promise<string> {\n const response = await this.commandAsync(['clock', dir]);\n fs.writeFileSync(snapshot, response.clock, {\n encoding: 'utf-8',\n });\n return response.clock;\n }\n\n async getEventsSince(\n dir: string,\n snapshot: FilePath,\n opts?: Options,\n ): Promise<Event[]> {\n const clock = fs.readFileSync(snapshot, {\n encoding: 'utf-8',\n });\n\n const response = await this.commandAsync([\n 'query',\n dir,\n {\n expression: this._createExpression(dir, opts?.ignore),\n fields: ['name', 'mode', 'exists', 'new'],\n since: clock,\n },\n ]);\n\n return (response.files || []).map((file: any) => ({\n path: file.name,\n type: file.new ? 'create' : file.exists ? 'update' : 'delete',\n }));\n }\n\n _createExpression(\n dir: string,\n ignore?: Array<FilePath | GlobPattern>,\n ): WatchmanArgs {\n const ignores = [\n // Ignore the watchman cookie\n ['match', '.watchman-cookie-*'],\n // Ignore directory changes as they are just noise\n ['type', 'd'],\n ];\n\n if (ignore) {\n const customIgnores = ignore?.map(filePathOrGlob => {\n const relative = path.relative(dir, filePathOrGlob);\n\n if (isGlob(filePathOrGlob)) {\n return ['match', relative, 'wholename'];\n }\n\n // If pattern is not a glob, then assume it's a directory.\n // Ignoring single files is not currently supported\n return ['dirname', relative];\n });\n\n ignores.push(...customIgnores);\n }\n\n return ['not', ['anyof', ...ignores]];\n }\n\n async subscribe(\n dir: string,\n fn: SubscribeCallback,\n opts?: Options,\n ): Promise<AsyncSubscription> {\n const {subscriptionName} = this;\n const {clock} = await this.commandAsync(['clock', dir]);\n\n await this.commandAsync([\n 'subscribe',\n dir,\n subscriptionName,\n {\n // `defer` can be used here if you want to pause the\n // notification stream until something has finished.\n //\n // https://facebook.github.io/watchman/docs/cmd/subscribe#defer\n // defer: ['my-company-example'],\n expression: this._createExpression(dir, opts?.ignore),\n fields: ['name', 'mode', 'exists', 'new'],\n since: clock,\n },\n ]);\n\n this.client.on('subscription', function (resp) {\n if (!resp.files || resp.subscription !== subscriptionName) {\n return;\n }\n\n fn(\n null /* err */,\n resp.files.map((file: any) => {\n return {\n path: path.join(dir, file.name),\n type: file.new ? 'create' : file.exists ? 'update' : 'delete',\n };\n }),\n );\n });\n\n const unsubscribe = async () => {\n await this.commandAsync(['unsubscribe', dir, subscriptionName]);\n };\n\n return {\n unsubscribe,\n };\n }\n\n async unsubscribe(dir: string): Promise<void> {\n await this.commandAsync(['unsubscribe', dir, this.subscriptionName]);\n }\n}\n"],"names":["ParcelWatcherWatchmanJS","wrapper","writeSnapshot","bind","getEventsSince","subscribe","unsubscribe","fs","path","watchman","isGlob","constructor","subscriptionName","Date","now","client","Client","commandAsync","args","Promise","resolve","reject","command","err","response","dir","snapshot","writeFileSync","clock","encoding","opts","readFileSync","expression","_createExpression","ignore","fields","since","files","map","file","name","type","new","exists","ignores","customIgnores","filePathOrGlob","relative","push","fn","on","resp","subscription","join"],"version":3,"file":"index.js.map"}
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACyCO,MAAMA;IAKXY,aAAc;QACZ,IAAI,CAACC,gBAAgB,GAAG,iCAAiCC,KA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,CAACF","sources":["packages/utils/parcel-watcher-watchman-js/src/index.js","packages/utils/parcel-watcher-watchman-js/src/wrapper.js"],"sourcesContent":["import {ParcelWatcherWatchmanJS} from './wrapper';\n\nconst wrapper = new ParcelWatcherWatchmanJS();\n\nexport const writeSnapshot = wrapper.writeSnapshot.bind(wrapper);\nexport const getEventsSince = wrapper.getEventsSince.bind(wrapper);\nexport const subscribe = wrapper.subscribe.bind(wrapper);\nexport const unsubscribe = wrapper.unsubscribe.bind(wrapper);\n","// @flow\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as watchman from 'fb-watchman';\nimport {isGlob} from '@parcel/utils';\nimport logger from '@parcel/logger';\nimport type {\n Options,\n Event,\n SubscribeCallback,\n AsyncSubscription,\n} from '@parcel/watcher';\n\ntype WatchmanArgs = any;\ntype FilePath = string;\ntype GlobPattern = string;\n\n// Matches the Watcher API from \"@parcel/watcher\"\nexport interface Watcher {\n getEventsSince(\n dir: FilePath,\n snapshot: FilePath,\n opts?: Options,\n ): Promise<Array<Event>>;\n subscribe(\n dir: FilePath,\n fn: SubscribeCallback,\n opts?: Options,\n ): Promise<AsyncSubscription>;\n unsubscribe(\n dir: FilePath,\n fn: SubscribeCallback,\n opts?: Options,\n ): Promise<void>;\n writeSnapshot(\n dir: FilePath,\n snapshot: FilePath,\n opts?: Options,\n ): Promise<FilePath>;\n}\n\nexport class ParcelWatcherWatchmanJS implements Watcher {\n subscriptionName: string;\n client: watchman.Client;\n initPromise: Promise<void> | void;\n\n constructor() {\n this.subscriptionName = 'parcel-watcher-subscription-' + Date.now();\n this.client = new watchman.Client();\n }\n\n commandAsync(args: any[]): Promise<any> {\n return new Promise((resolve, reject) => {\n const client = this.client;\n client.command(\n args,\n // $FlowFixMe\n (err: Error | null | undefined, response: any) => {\n if (err) reject(err);\n else resolve(response);\n },\n );\n });\n }\n\n capabilityCheckAsync(args: any): Promise<any> {\n return new Promise((resolve, reject) => {\n const client = this.client;\n client.capabilityCheck(\n args,\n // $FlowFixMe\n (err: Error | null | undefined, response: any) => {\n if (err) reject(err);\n else resolve(response);\n },\n );\n });\n }\n async _init(watchDir: string): Promise<void> {\n await this.capabilityCheckAsync({optional: [], required: []});\n const resp = await this.commandAsync(['watch-project', watchDir]);\n\n if ('warning' in resp) {\n logger.warn({message: resp.warning});\n }\n }\n\n init(watchDir: string): Promise<void> {\n if (this.initPromise) {\n return this.initPromise;\n }\n\n this.initPromise = this._init(watchDir);\n\n return this.initPromise;\n }\n\n // Types should match @parcel/watcher/index.js.flow\n async writeSnapshot(dir: string, snapshot: FilePath): Promise<string> {\n await this.init(dir);\n\n const response = await this.commandAsync(['clock', dir]);\n fs.writeFileSync(snapshot, response.clock, {\n encoding: 'utf-8',\n });\n return response.clock;\n }\n\n async getEventsSince(\n dir: string,\n snapshot: FilePath,\n opts?: Options,\n ): Promise<Event[]> {\n await this.init(dir);\n\n const clock = fs.readFileSync(snapshot, {\n encoding: 'utf-8',\n });\n\n const response = await this.commandAsync([\n 'query',\n dir,\n {\n expression: this._createExpression(dir, opts?.ignore),\n fields: ['name', 'mode', 'exists', 'new'],\n since: clock,\n },\n ]);\n\n return (response.files || []).map((file: any) => ({\n path: file.name,\n type: file.new ? 'create' : file.exists ? 'update' : 'delete',\n }));\n }\n\n _createExpression(\n dir: string,\n ignore?: Array<FilePath | GlobPattern>,\n ): WatchmanArgs {\n const ignores = [\n // Ignore the watchman cookie\n ['match', '.watchman-cookie-*'],\n // Ignore directory changes as they are just noise\n ['type', 'd'],\n ];\n\n if (ignore) {\n const customIgnores = ignore?.map(filePathOrGlob => {\n const relative = path.relative(dir, filePathOrGlob);\n\n if (isGlob(filePathOrGlob)) {\n return ['match', relative, 'wholename'];\n }\n\n // If pattern is not a glob, then assume it's a directory.\n // Ignoring single files is not currently supported\n return ['dirname', relative];\n });\n\n ignores.push(...customIgnores);\n }\n\n return ['not', ['anyof', ...ignores]];\n }\n\n async subscribe(\n dir: string,\n fn: SubscribeCallback,\n opts?: Options,\n ): Promise<AsyncSubscription> {\n await this.init(dir);\n\n const {subscriptionName} = this;\n const {clock} = await this.commandAsync(['clock', dir]);\n\n await this.commandAsync([\n 'subscribe',\n dir,\n subscriptionName,\n {\n // `defer` can be used here if you want to pause the\n // notification stream until something has finished.\n //\n // https://facebook.github.io/watchman/docs/cmd/subscribe#defer\n // defer: ['my-company-example'],\n expression: this._createExpression(dir, opts?.ignore),\n fields: ['name', 'mode', 'exists', 'new'],\n since: clock,\n },\n ]);\n\n this.client.on('subscription', function (resp) {\n if (!resp.files || resp.subscription !== subscriptionName) {\n return;\n }\n\n fn(\n null /* err */,\n resp.files.map((file: any) => {\n return {\n path: path.join(dir, file.name),\n type: file.new ? 'create' : file.exists ? 'update' : 'delete',\n };\n }),\n );\n });\n\n const unsubscribe = async () => {\n await this.commandAsync(['unsubscribe', dir, subscriptionName]);\n };\n\n return {\n unsubscribe,\n };\n }\n\n async unsubscribe(dir: string): Promise<void> {\n await this.commandAsync(['unsubscribe', dir, this.subscriptionName]);\n }\n}\n"],"names":["ParcelWatcherWatchmanJS","wrapper","writeSnapshot","bind","getEventsSince","subscribe","unsubscribe","fs","path","watchman","isGlob","logger","constructor","subscriptionName","Date","now","client","Client","commandAsync","args","Promise","resolve","reject","command","err","response","capabilityCheckAsync","capabilityCheck","_init","watchDir","optional","required","resp","warn","message","warning","init","initPromise","dir","snapshot","writeFileSync","clock","encoding","opts","readFileSync","expression","_createExpression","ignore","fields","since","files","map","file","name","type","new","exists","ignores","customIgnores","filePathOrGlob","relative","push","fn","on","subscription","join"],"version":3,"file":"index.js.map"}
|
package/lib/wrapper.js
CHANGED
@@ -32,6 +32,14 @@ function _utils() {
|
|
32
32
|
};
|
33
33
|
return data;
|
34
34
|
}
|
35
|
+
function _logger() {
|
36
|
+
const data = _interopRequireDefault(require("@parcel/logger"));
|
37
|
+
_logger = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35
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); }
|
36
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; }
|
37
45
|
// Matches the Watcher API from "@parcel/watcher"
|
@@ -43,15 +51,46 @@ class ParcelWatcherWatchmanJS {
|
|
43
51
|
commandAsync(args) {
|
44
52
|
return new Promise((resolve, reject) => {
|
45
53
|
const client = this.client;
|
54
|
+
client.command(args,
|
46
55
|
// $FlowFixMe
|
47
|
-
|
56
|
+
(err, response) => {
|
48
57
|
if (err) reject(err);else resolve(response);
|
49
58
|
});
|
50
59
|
});
|
51
60
|
}
|
61
|
+
capabilityCheckAsync(args) {
|
62
|
+
return new Promise((resolve, reject) => {
|
63
|
+
const client = this.client;
|
64
|
+
client.capabilityCheck(args,
|
65
|
+
// $FlowFixMe
|
66
|
+
(err, response) => {
|
67
|
+
if (err) reject(err);else resolve(response);
|
68
|
+
});
|
69
|
+
});
|
70
|
+
}
|
71
|
+
async _init(watchDir) {
|
72
|
+
await this.capabilityCheckAsync({
|
73
|
+
optional: [],
|
74
|
+
required: []
|
75
|
+
});
|
76
|
+
const resp = await this.commandAsync(['watch-project', watchDir]);
|
77
|
+
if ('warning' in resp) {
|
78
|
+
_logger().default.warn({
|
79
|
+
message: resp.warning
|
80
|
+
});
|
81
|
+
}
|
82
|
+
}
|
83
|
+
init(watchDir) {
|
84
|
+
if (this.initPromise) {
|
85
|
+
return this.initPromise;
|
86
|
+
}
|
87
|
+
this.initPromise = this._init(watchDir);
|
88
|
+
return this.initPromise;
|
89
|
+
}
|
52
90
|
|
53
91
|
// Types should match @parcel/watcher/index.js.flow
|
54
92
|
async writeSnapshot(dir, snapshot) {
|
93
|
+
await this.init(dir);
|
55
94
|
const response = await this.commandAsync(['clock', dir]);
|
56
95
|
fs().writeFileSync(snapshot, response.clock, {
|
57
96
|
encoding: 'utf-8'
|
@@ -59,6 +98,7 @@ class ParcelWatcherWatchmanJS {
|
|
59
98
|
return response.clock;
|
60
99
|
}
|
61
100
|
async getEventsSince(dir, snapshot, opts) {
|
101
|
+
await this.init(dir);
|
62
102
|
const clock = fs().readFileSync(snapshot, {
|
63
103
|
encoding: 'utf-8'
|
64
104
|
});
|
@@ -94,6 +134,7 @@ class ParcelWatcherWatchmanJS {
|
|
94
134
|
return ['not', ['anyof', ...ignores]];
|
95
135
|
}
|
96
136
|
async subscribe(dir, fn, opts) {
|
137
|
+
await this.init(dir);
|
97
138
|
const {
|
98
139
|
subscriptionName
|
99
140
|
} = this;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/watcher-watchman-js",
|
3
|
-
"version": "2.12.1-canary.
|
3
|
+
"version": "2.12.1-canary.3339+d6a89da31",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"source": "src/index.js",
|
@@ -8,11 +8,12 @@
|
|
8
8
|
"access": "public"
|
9
9
|
},
|
10
10
|
"dependencies": {
|
11
|
-
"@parcel/
|
11
|
+
"@parcel/logger": "2.0.0-canary.1716+d6a89da31",
|
12
|
+
"@parcel/utils": "2.0.0-canary.1716+d6a89da31",
|
12
13
|
"fb-watchman": "^2.0.2"
|
13
14
|
},
|
14
15
|
"devDependencies": {
|
15
16
|
"@parcel/watcher": "^2.4.1"
|
16
17
|
},
|
17
|
-
"gitHead": "
|
18
|
+
"gitHead": "d6a89da31a2a79f9ad420865b83078777ca01406"
|
18
19
|
}
|
package/src/wrapper.js
CHANGED
@@ -3,6 +3,7 @@ import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
4
4
|
import * as watchman from 'fb-watchman';
|
5
5
|
import {isGlob} from '@parcel/utils';
|
6
|
+
import logger from '@parcel/logger';
|
6
7
|
import type {
|
7
8
|
Options,
|
8
9
|
Event,
|
@@ -41,6 +42,7 @@ export interface Watcher {
|
|
41
42
|
export class ParcelWatcherWatchmanJS implements Watcher {
|
42
43
|
subscriptionName: string;
|
43
44
|
client: watchman.Client;
|
45
|
+
initPromise: Promise<void> | void;
|
44
46
|
|
45
47
|
constructor() {
|
46
48
|
this.subscriptionName = 'parcel-watcher-subscription-' + Date.now();
|
@@ -50,16 +52,53 @@ export class ParcelWatcherWatchmanJS implements Watcher {
|
|
50
52
|
commandAsync(args: any[]): Promise<any> {
|
51
53
|
return new Promise((resolve, reject) => {
|
52
54
|
const client = this.client;
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
client.command(
|
56
|
+
args,
|
57
|
+
// $FlowFixMe
|
58
|
+
(err: Error | null | undefined, response: any) => {
|
59
|
+
if (err) reject(err);
|
60
|
+
else resolve(response);
|
61
|
+
},
|
62
|
+
);
|
63
|
+
});
|
64
|
+
}
|
65
|
+
|
66
|
+
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
|
+
);
|
58
77
|
});
|
59
78
|
}
|
79
|
+
async _init(watchDir: string): Promise<void> {
|
80
|
+
await this.capabilityCheckAsync({optional: [], required: []});
|
81
|
+
const resp = await this.commandAsync(['watch-project', watchDir]);
|
82
|
+
|
83
|
+
if ('warning' in resp) {
|
84
|
+
logger.warn({message: resp.warning});
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
init(watchDir: string): Promise<void> {
|
89
|
+
if (this.initPromise) {
|
90
|
+
return this.initPromise;
|
91
|
+
}
|
92
|
+
|
93
|
+
this.initPromise = this._init(watchDir);
|
94
|
+
|
95
|
+
return this.initPromise;
|
96
|
+
}
|
60
97
|
|
61
98
|
// Types should match @parcel/watcher/index.js.flow
|
62
99
|
async writeSnapshot(dir: string, snapshot: FilePath): Promise<string> {
|
100
|
+
await this.init(dir);
|
101
|
+
|
63
102
|
const response = await this.commandAsync(['clock', dir]);
|
64
103
|
fs.writeFileSync(snapshot, response.clock, {
|
65
104
|
encoding: 'utf-8',
|
@@ -72,6 +111,8 @@ export class ParcelWatcherWatchmanJS implements Watcher {
|
|
72
111
|
snapshot: FilePath,
|
73
112
|
opts?: Options,
|
74
113
|
): Promise<Event[]> {
|
114
|
+
await this.init(dir);
|
115
|
+
|
75
116
|
const clock = fs.readFileSync(snapshot, {
|
76
117
|
encoding: 'utf-8',
|
77
118
|
});
|
@@ -127,6 +168,8 @@ export class ParcelWatcherWatchmanJS implements Watcher {
|
|
127
168
|
fn: SubscribeCallback,
|
128
169
|
opts?: Options,
|
129
170
|
): Promise<AsyncSubscription> {
|
171
|
+
await this.init(dir);
|
172
|
+
|
130
173
|
const {subscriptionName} = this;
|
131
174
|
const {clock} = await this.commandAsync(['clock', dir]);
|
132
175
|
|