Skip to content

Commit 57f0695

Browse files
committed
core: bump nsfw to ^2.1.2
Improvements have been made to the library. Notably a bug was fixed where some folders were not picked up by the watchers if created too quickly and an issue on Windows was fixed where watching didn't work at all. This commit updates our code to use the new typings distributed by `nsfw` itself and re-enables file watching testing on Windows. Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
1 parent 7310d88 commit 57f0695

8 files changed

+28
-71
lines changed

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"jschardet": "^2.1.1",
3838
"lodash.debounce": "^4.0.8",
3939
"lodash.throttle": "^4.1.1",
40-
"nsfw": "^1.2.9",
40+
"nsfw": "^2.1.2",
4141
"p-debounce": "^2.1.0",
4242
"perfect-scrollbar": "^1.3.0",
4343
"react": "^16.8.0",

packages/core/src/node/logger-cli-contribution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class LogLevelCliContribution implements CliContribution {
9090
}
9191

9292
protected watchLogConfigFile(filename: string): Promise<void> {
93-
return nsfw(filename, async (events: nsfw.ChangeEvent[]) => {
93+
return nsfw(filename, async (events: nsfw.FileChangeEvent[]) => {
9494
try {
9595
for (const event of events) {
9696
switch (event.action) {

packages/core/src/typings/nsfw/index.d.ts

-49
This file was deleted.

packages/filesystem/compile.tsconfig.json

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"mv": [
1010
"src/typings/mv"
1111
],
12-
"nsfw": [
13-
"src/typings/nsfw"
14-
],
1512
"trash": [
1613
"src/typings/trash"
1714
]

packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class NsfwWatcher {
242242
});
243243
}
244244

245-
protected handleNsfwEvents(events: nsfw.ChangeEvent[]): void {
245+
protected handleNsfwEvents(events: nsfw.FileChangeEvent[]): void {
246246
// Only process events if someone is listening.
247247
if (this.isInUse()) {
248248
// This callback is async, but nsfw won't wait for it to finish before firing the next one.

packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-watcher.spec.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import * as temp from 'temp';
1818
import * as chai from 'chai';
19+
import * as cp from 'child_process';
1920
import * as fs from 'fs-extra';
2021
import * as assert from 'assert';
2122
import URI from '@theia/core/lib/common/uri';
@@ -36,7 +37,16 @@ describe('nsfw-filesystem-watcher', function (): void {
3637
this.timeout(10000);
3738

3839
beforeEach(async () => {
39-
root = FileUri.create(fs.realpathSync(temp.mkdirSync('node-fs-root')));
40+
let tempPath = temp.mkdirSync('node-fs-root');
41+
// Sometimes tempPath will use some Windows 8.3 short name in its path. This is a problem
42+
// since NSFW always returns paths with long names. We need to convert here.
43+
// See: https://stackoverflow.com/a/34473971/7983255
44+
if (process.platform === 'win32') {
45+
tempPath = cp.execSync(`powershell "(Get-Item -LiteralPath '${tempPath}').FullName"`, {
46+
encoding: 'utf8',
47+
}).trim();
48+
}
49+
root = FileUri.create(fs.realpathSync(tempPath));
4050
watcherService = createNsfwFileSystemWatcherService();
4151
watcherId = await watcherService.watchFileChanges(0, root.toString());
4252
await sleep(2000);
@@ -48,9 +58,6 @@ describe('nsfw-filesystem-watcher', function (): void {
4858
});
4959

5060
it('Should receive file changes events from in the workspace by default.', async function (): Promise<void> {
51-
if (process.platform === 'win32') {
52-
this.skip();
53-
}
5461
const actualUris = new Set<string>();
5562

5663
const watcherClient = {
@@ -80,13 +87,10 @@ describe('nsfw-filesystem-watcher', function (): void {
8087
expect(fs.readFileSync(FileUri.fsPath(root.resolve('foo').resolve('bar').resolve('baz.txt')), 'utf8')).to.be.equal('baz');
8188
await sleep(2000);
8289

83-
assert.deepStrictEqual(expectedUris, [...actualUris]);
90+
assert.deepStrictEqual([...actualUris], expectedUris);
8491
});
8592

8693
it('Should not receive file changes events from in the workspace by default if unwatched', async function (): Promise<void> {
87-
if (process.platform === 'win32') {
88-
this.skip();
89-
}
9094
const actualUris = new Set<string>();
9195

9296
const watcherClient = {
@@ -113,7 +117,7 @@ describe('nsfw-filesystem-watcher', function (): void {
113117
expect(fs.readFileSync(FileUri.fsPath(root.resolve('foo').resolve('bar').resolve('baz.txt')), 'utf8')).to.be.equal('baz');
114118
await sleep(2000);
115119

116-
assert.deepStrictEqual(0, actualUris.size);
120+
assert.deepStrictEqual(actualUris.size, 0);
117121
});
118122

119123
function createNsfwFileSystemWatcherService(): NsfwFileSystemWatcherService {

packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-watcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class NsfwFileSystemWatcherServer implements FileSystemWatcherServer {
117117
this.debug('Files ignored for watching', options.ignored);
118118
}
119119

120-
let watcher: nsfw.NSFW | undefined = await nsfw(fs.realpathSync(basePath), (events: nsfw.ChangeEvent[]) => {
120+
let watcher: nsfw.NSFW | undefined = await nsfw(fs.realpathSync(basePath), (events: nsfw.FileChangeEvent[]) => {
121121
for (const event of events) {
122122
if (event.action === nsfw.actions.CREATED) {
123123
this.pushAdded(watcherId, this.resolvePath(event.directory, event.file!));

yarn.lock

+11-6
Original file line numberDiff line numberDiff line change
@@ -9599,7 +9599,7 @@ mute-stream@0.0.8:
95999599
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
96009600
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
96019601

9602-
nan@^2.0.0, nan@^2.12.1, nan@^2.14.0:
9602+
nan@^2.12.1, nan@^2.14.0:
96039603
version "2.14.2"
96049604
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
96059605
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
@@ -9684,6 +9684,11 @@ node-abi@^2.11.0, node-abi@^2.18.0, node-abi@^2.7.0:
96849684
dependencies:
96859685
semver "^5.4.1"
96869686

9687+
node-addon-api@*:
9688+
version "3.1.0"
9689+
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.1.0.tgz#98b21931557466c6729e51cb77cd39c965f42239"
9690+
integrity sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw==
9691+
96879692
node-dir@0.1.8:
96889693
version "0.1.8"
96899694
resolved "https://registry.yarnpkg.com/node-dir/-/node-dir-0.1.8.tgz#55fb8deb699070707fb67f91a460f0448294c77d"
@@ -9917,12 +9922,12 @@ npmlog@^4.0.1, npmlog@^4.1.2:
99179922
gauge "~2.7.3"
99189923
set-blocking "~2.0.0"
99199924

9920-
nsfw@^1.2.9:
9921-
version "1.2.9"
9922-
resolved "https://registry.yarnpkg.com/nsfw/-/nsfw-1.2.9.tgz#e49ff5c12593cbcce3fcc90c533947eb4f15a99a"
9923-
integrity sha512-/2o89nygBRTTnGRxSHt2wjagbszyh36HlgF61Ec2iaJBTIIQ6QKcqp92EzVxxZX9U/6Qpy+LZL5i8532hXzAHg==
9925+
nsfw@^2.1.2:
9926+
version "2.1.2"
9927+
resolved "https://registry.yarnpkg.com/nsfw/-/nsfw-2.1.2.tgz#4fa841e7f7122b60b2e1f61187d1b57ad3403428"
9928+
integrity sha512-zGPdt32aJ5b1laK9rvgXQmXGAagrx3VkcMt0JePtu6wBfzC1o4xLCM3kq7FxZxUnxyxYhODyBYzpt3H16FhaGA==
99249929
dependencies:
9925-
nan "^2.0.0"
9930+
node-addon-api "*"
99269931

99279932
nugget@^2.0.1:
99289933
version "2.0.1"

0 commit comments

Comments
 (0)