Skip to content

Commit 2333a43

Browse files
author
winjo
committed
style: 更改 fs-extra export name
1 parent 55717bc commit 2333a43

11 files changed

Lines changed: 39 additions & 39 deletions

File tree

packages/alex/src/api/require.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function requireModule(module: '@ali/common-di'): typeof CommonDI;
100100
export function requireModule(module: '@alipay/alex-core'): typeof AlexCore;
101101

102102
export function requireModule(module: 'fs'): typeof AlexCore.fs;
103-
export function requireModule(module: 'fs-extra'): typeof AlexCore.fse;
103+
export function requireModule(module: 'fs-extra'): typeof AlexCore.fsExtra;
104104
export function requireModule(module: 'os'): typeof os;
105105
export function requireModule(module: 'crypto'): typeof crypto;
106106
export function requireModule(module: 'buffer'): typeof buffer;
@@ -199,7 +199,7 @@ export function requireModule(module: string): any {
199199
case 'fs':
200200
return AlexCore.fs;
201201
case 'fs-extra':
202-
return AlexCore.fse;
202+
return AlexCore.fsExtra;
203203
case 'os':
204204
return os;
205205
case 'crypto':

packages/core/src/server/core/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { INodeLogger, NodeLogger } from './node-logger';
1919
import { FCServiceCenter, initFCService, ServerPort } from '../../connection';
2020
import { IServerApp } from '../../common';
2121
import { initializeRootFileSystem, filesystemDeferred } from './filesystem';
22-
import { fse } from '../node';
22+
import { fsExtra as fse } from '../node';
2323
import { WORKSPACE_ROOT, STORAGE_DIR } from '../../common/constant';
2424
import { RootFS, RuntimeConfig } from '../../common/types';
2525
import { isBackServicesInServer } from '../../common/util';

packages/core/src/server/file-scheme/file-scheme-doc.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IFileService } from '../file-service/base';
1010
import md5 from 'md5';
1111
import { ISavingContent, IContentChange } from '@ali/ide-file-scheme/lib/common';
1212
import { IFileSchemeDocNodeService } from './base';
13-
import { fse } from '../node';
13+
import { fsExtra as fse } from '../node';
1414
import { encode, decode } from '../file-service/encoding';
1515

1616
@Injectable()

packages/core/src/server/file-service/disk-file-system.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import * as os from 'os';
2727
import { IDiskFileProvider } from './base';
2828
import { FCService } from '../../connection';
2929
import { FWFileSystemWatcherServer } from './file-service-watcher';
30-
import { fse, writeFileAtomic } from '../node';
30+
import { fsExtra as fse, writeFileAtomic } from '../node';
3131
import { decode, encode } from './encoding';
3232

3333
const debugLog = new DebugLog();

packages/core/src/server/file-service/encoding.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO: iconv-lite-umd 和 jschardet 使用异步加载,加快主应用启动速度
2-
import { fse as fs } from '../node';
2+
// import { fs } from '../node';
33
// import * as jschardet from 'jschardet';
44
import * as iconv from 'iconv-lite-umd';
55
import { URI } from '@ali/ide-core-common';
@@ -161,18 +161,18 @@ export function detectEncodingByBuffer(buffer: Buffer): string | null {
161161
return mapped || normalizedEncodingName;
162162
}
163163

164-
export function detectEncodingByURI(uri: URI): string | null {
165-
const filePath = FileUri.fsPath(uri);
166-
const fd = fs.openSync(filePath, 'r');
167-
const maxLength = 100;
168-
let buffer = Buffer.allocUnsafe(maxLength);
169-
const readLength = fs.readSync(fd, buffer, 0, maxLength, null);
170-
171-
// Reset real length
172-
buffer = buffer.slice(0, readLength);
173-
fs.closeSync(fd);
174-
return detectEncodingByBuffer(buffer);
175-
}
164+
// export function detectEncodingByURI(uri: URI): string | null {
165+
// const filePath = FileUri.fsPath(uri);
166+
// const fd = fs.openSync(filePath, 'r');
167+
// const maxLength = 100;
168+
// let buffer = Buffer.allocUnsafe(maxLength);
169+
// const readLength = fs.readSync(fd, buffer, 0, maxLength, null);
170+
171+
// // Reset real length
172+
// buffer = buffer.slice(0, readLength);
173+
// fs.closeSync(fd);
174+
// return detectEncodingByBuffer(buffer);
175+
// }
176176

177177
export function getEncodingInfo(encoding: string | null): null | EncodingInfo {
178178
if (!encoding) {

packages/core/src/server/file-service/file-service-watcher.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
import debounce from 'lodash.debounce';
1313
import path from 'path';
1414
import { FileChangeCollection } from './file-change-collection';
15-
import { fse, watch } from '../node';
16-
import { ChangeEvent, FW } from '../node/extend/fs-watch';
15+
import { fsWatcher, fsExtra as fse } from '../node';
16+
// import { ChangeEvent, FW } from '../node/extend/fs-watch';
1717

1818
export interface WatcherOptions {
1919
excludesPattern: ParsedPattern[];
@@ -126,18 +126,19 @@ export class FWFileSystemWatcherServer implements FileSystemWatcherServer {
126126
...rawOptions,
127127
};
128128

129-
let watcher: FW | undefined = await watch(basePath, (events: ChangeEvent[]) => {
129+
const { watch, actions } = fsWatcher;
130+
let watcher = await watch(basePath, (events) => {
130131
for (const event of events) {
131-
if (event.action === watch.actions.CREATED) {
132+
if (event.action === actions.CREATED) {
132133
this.pushAdded(watcherId, this.resolvePath(event.directory, event.file!));
133134
}
134-
if (event.action === watch.actions.DELETED) {
135+
if (event.action === actions.DELETED) {
135136
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.file!));
136137
}
137-
if (event.action === watch.actions.MODIFIED) {
138+
if (event.action === actions.MODIFIED) {
138139
this.pushUpdated(watcherId, this.resolvePath(event.directory, event.file!));
139140
}
140-
if (event.action === watch.actions.RENAMED) {
141+
if (event.action === actions.RENAMED) {
141142
if (event.newDirectory) {
142143
this.pushDeleted(watcherId, this.resolvePath(event.directory, event.oldFile!));
143144
this.pushAdded(watcherId, this.resolvePath(event.newDirectory, event.newFile!));
@@ -153,7 +154,6 @@ export class FWFileSystemWatcherServer implements FileSystemWatcherServer {
153154
if (toDisposeWatcher.disposed) {
154155
this.debug('Stopping watching:', basePath);
155156
watcher.stop();
156-
watcher = undefined;
157157
this.options.info('Stopped watching:', basePath);
158158
return;
159159
}
@@ -163,7 +163,6 @@ export class FWFileSystemWatcherServer implements FileSystemWatcherServer {
163163
if (watcher) {
164164
this.debug('Stopping watching:', basePath);
165165
watcher.stop();
166-
watcher = undefined;
167166
this.options.info('Stopped watching:', basePath);
168167
}
169168
})

packages/core/src/server/file-service/file-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as path from 'path';
2828
import * as os from 'os';
2929
import { IDiskFileProvider, IFileService } from './base';
3030
import { FCService } from '../../connection';
31-
import { fse } from '../node';
31+
import { fsExtra as fse } from '../node';
3232
import { ServerConfig } from '../core/app';
3333
import { INodeLogger } from '../core/node-logger';
3434

packages/core/src/server/node/extend/fs-extra.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import path from 'path';
55

66
import { fs } from '../bfs';
77

8-
const fse = fsExtraFactory({
8+
export const fsExtra = fsExtraFactory({
99
fs,
1010
path,
1111
process,
1212
assert,
1313
buffer,
1414
});
15-
16-
export default fse;

packages/core/src/server/node/extend/fs-watch.ts renamed to packages/core/src/server/node/extend/fs-watcher.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import debounce from 'lodash.debounce';
1010
import * as path from 'path';
1111
import { fs } from '../bfs';
1212

13-
export const enum ActionType {
13+
const enum ActionType {
1414
CREATED = 0,
1515
DELETED = 1,
1616
MODIFIED = 2,
@@ -275,7 +275,7 @@ function call(cb: Function, args: any[]) {
275275
}
276276
}
277277

278-
export interface FW {
278+
interface FW {
279279
start: () => void;
280280
stop: () => void;
281281
}
@@ -286,7 +286,6 @@ interface FWFunction {
286286
eventCallback: (events: Array<ChangeEvent>) => void,
287287
options?: Partial<Options>
288288
): Promise<FW>;
289-
actions: Record<keyof typeof ActionType, number>;
290289
}
291290

292291
export const watch: FWFunction = (
@@ -381,7 +380,7 @@ export const watch: FWFunction = (
381380
});
382381
};
383382

384-
watch.actions = {
383+
export const actions = {
385384
CREATED: ActionType.CREATED,
386385
DELETED: ActionType.DELETED,
387386
MODIFIED: ActionType.MODIFIED,

packages/core/src/server/node/extend/write-file-atomic.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* 目前不考虑多线程的情况,因此只根据 filename 加锁即可
44
*/
55

6-
import fse from './fs-extra';
6+
import { fsExtra as fse } from './fs-extra';
77
import * as path from 'path';
88

99
const mutex = {
@@ -36,7 +36,11 @@ const mutex = {
3636
},
3737
};
3838

39-
const writeFileAtomic = async (filename: string, data: any, options?: any) => {
39+
const writeFileAtomic = async (
40+
filename: string,
41+
data: any,
42+
options?: Record<string, any> | string
43+
) => {
4044
const absoluteName = path.resolve(filename);
4145
await mutex.lock(absoluteName);
4246
try {

0 commit comments

Comments
 (0)