@atlaspack/fs 2.15.16-typescript-5b4d3ad41.0 → 2.15.16
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/CHANGELOG.md +11 -0
- package/index.d.ts +34 -0
- package/lib/MemoryFS.js +9 -18
- package/lib/NodeFS.browser.js +1 -1
- package/lib/NodeFS.js +7 -24
- package/lib/NodeVCSAwareFS.js +6 -16
- package/lib/OverlayFS.js +2 -4
- package/lib/types.d.ts +0 -0
- package/package.json +16 -16
- package/src/{MemoryFS.ts → MemoryFS.js} +36 -50
- package/src/{NodeFS.browser.ts → NodeFS.browser.js} +2 -1
- package/src/{NodeFS.ts → NodeFS.js} +17 -26
- package/src/{NodeVCSAwareFS.ts → NodeVCSAwareFS.js} +13 -17
- package/src/{OverlayFS.ts → OverlayFS.js} +25 -28
- package/src/{find.ts → find.js} +7 -6
- package/src/{index.ts → index.js} +2 -1
- package/test/{OverlayFS.test.ts → OverlayFS.test.js} +6 -4
- package/LICENSE +0 -201
- package/lib/MemoryFS.d.ts +0 -165
- package/lib/NodeFS.browser.d.ts +0 -4
- package/lib/NodeFS.d.ts +0 -38
- package/lib/NodeVCSAwareFS.d.ts +0 -18
- package/lib/OverlayFS.d.ts +0 -50
- package/lib/find.d.ts +0 -4
- package/lib/index.d.ts +0 -7
- package/tsconfig.json +0 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
import type {ReadStream, Stats} from 'fs';
|
|
2
3
|
import type {Writable} from 'stream';
|
|
3
4
|
import type {
|
|
@@ -12,10 +13,8 @@ import type {
|
|
|
12
13
|
AsyncSubscription,
|
|
13
14
|
} from '@parcel/watcher';
|
|
14
15
|
|
|
15
|
-
// @ts-expect-error TS7016
|
|
16
16
|
import fs from 'graceful-fs';
|
|
17
17
|
import nativeFS from 'fs';
|
|
18
|
-
// @ts-expect-error TS7016
|
|
19
18
|
import ncp from 'ncp';
|
|
20
19
|
import path from 'path';
|
|
21
20
|
import {tmpdir} from 'os';
|
|
@@ -41,6 +40,7 @@ function getWatchmanWatcher(): typeof watcher {
|
|
|
41
40
|
// This is here to trick atlaspack into ignoring this require...
|
|
42
41
|
const packageName = ['@atlaspack', 'watcher-watchman-js'].join('/');
|
|
43
42
|
|
|
43
|
+
// $FlowFixMe
|
|
44
44
|
return require(packageName);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -62,18 +62,15 @@ export class NodeFS implements FileSystem {
|
|
|
62
62
|
realpathSync: (path: string, cache?: any) => string =
|
|
63
63
|
process.platform === 'win32' ? fs.realpathSync : fs.realpathSync.native;
|
|
64
64
|
existsSync: (path: string) => boolean = fs.existsSync;
|
|
65
|
-
readdirSync: any = fs.readdirSync
|
|
65
|
+
readdirSync: any = (fs.readdirSync: any);
|
|
66
66
|
findAncestorFile: any = isPnP
|
|
67
|
-
?
|
|
68
|
-
(...args) => searchJS.findAncestorFile(this, ...args)
|
|
67
|
+
? (...args) => searchJS.findAncestorFile(this, ...args)
|
|
69
68
|
: searchNative.findAncestorFile;
|
|
70
69
|
findNodeModule: any = isPnP
|
|
71
|
-
?
|
|
72
|
-
(...args) => searchJS.findNodeModule(this, ...args)
|
|
70
|
+
? (...args) => searchJS.findNodeModule(this, ...args)
|
|
73
71
|
: searchNative.findNodeModule;
|
|
74
72
|
findFirstFile: any = isPnP
|
|
75
|
-
?
|
|
76
|
-
(...args) => searchJS.findFirstFile(this, ...args)
|
|
73
|
+
? (...args) => searchJS.findFirstFile(this, ...args)
|
|
77
74
|
: searchNative.findFirstFile;
|
|
78
75
|
|
|
79
76
|
watcher(): typeof watcher {
|
|
@@ -82,7 +79,7 @@ export class NodeFS implements FileSystem {
|
|
|
82
79
|
: watcher;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
createWriteStream(filePath: string, options
|
|
82
|
+
createWriteStream(filePath: string, options: any): Writable {
|
|
86
83
|
// Make createWriteStream atomic
|
|
87
84
|
let tmpFilePath = getTempFilePath(filePath);
|
|
88
85
|
let failed = false;
|
|
@@ -91,7 +88,7 @@ export class NodeFS implements FileSystem {
|
|
|
91
88
|
if (!failed) {
|
|
92
89
|
try {
|
|
93
90
|
await fs.promises.rename(tmpFilePath, filePath);
|
|
94
|
-
} catch (e
|
|
91
|
+
} catch (e) {
|
|
95
92
|
// This is adapted from fs-write-stream-atomic. Apparently
|
|
96
93
|
// Windows doesn't like renaming when the target already exists.
|
|
97
94
|
if (
|
|
@@ -120,9 +117,7 @@ export class NodeFS implements FileSystem {
|
|
|
120
117
|
...options,
|
|
121
118
|
fs: {
|
|
122
119
|
...fs,
|
|
123
|
-
// @ts-expect-error TS7006
|
|
124
120
|
close: (fd, cb) => {
|
|
125
|
-
// @ts-expect-error TS7006
|
|
126
121
|
fs.close(fd, (err) => {
|
|
127
122
|
if (err) {
|
|
128
123
|
cb(err);
|
|
@@ -141,7 +136,7 @@ export class NodeFS implements FileSystem {
|
|
|
141
136
|
failed = true;
|
|
142
137
|
try {
|
|
143
138
|
fs.unlinkSync(tmpFilePath);
|
|
144
|
-
} catch (_err
|
|
139
|
+
} catch (_err) {
|
|
145
140
|
// ignore
|
|
146
141
|
}
|
|
147
142
|
});
|
|
@@ -152,7 +147,7 @@ export class NodeFS implements FileSystem {
|
|
|
152
147
|
async writeFile(
|
|
153
148
|
filePath: FilePath,
|
|
154
149
|
contents: Buffer | string,
|
|
155
|
-
options
|
|
150
|
+
options: ?FileOptions,
|
|
156
151
|
): Promise<void> {
|
|
157
152
|
let tmpFilePath = getTempFilePath(filePath);
|
|
158
153
|
await fs.promises.writeFile(tmpFilePath, contents, options);
|
|
@@ -169,7 +164,7 @@ export class NodeFS implements FileSystem {
|
|
|
169
164
|
async realpath(originalPath: string): Promise<string> {
|
|
170
165
|
try {
|
|
171
166
|
return await realpath(originalPath, 'utf8');
|
|
172
|
-
} catch (e
|
|
167
|
+
} catch (e) {
|
|
173
168
|
// do nothing
|
|
174
169
|
}
|
|
175
170
|
|
|
@@ -177,14 +172,14 @@ export class NodeFS implements FileSystem {
|
|
|
177
172
|
}
|
|
178
173
|
|
|
179
174
|
exists(filePath: FilePath): Promise<boolean> {
|
|
180
|
-
return new Promise((resolve
|
|
175
|
+
return new Promise((resolve) => {
|
|
181
176
|
fs.exists(filePath, resolve);
|
|
182
177
|
});
|
|
183
178
|
}
|
|
184
179
|
|
|
185
180
|
watch(
|
|
186
181
|
dir: FilePath,
|
|
187
|
-
fn: (err: Error
|
|
182
|
+
fn: (err: ?Error, events: Array<Event>) => mixed,
|
|
188
183
|
opts: WatcherOptions,
|
|
189
184
|
): Promise<AsyncSubscription> {
|
|
190
185
|
return this.watcher().subscribe(dir, fn, opts);
|
|
@@ -229,11 +224,12 @@ export class NodeFS implements FileSystem {
|
|
|
229
224
|
let stat;
|
|
230
225
|
try {
|
|
231
226
|
stat = await this.stat(filePath);
|
|
232
|
-
} catch (err
|
|
227
|
+
} catch (err) {
|
|
233
228
|
return;
|
|
234
229
|
}
|
|
235
230
|
|
|
236
231
|
if (stat.isDirectory()) {
|
|
232
|
+
// $FlowFixMe
|
|
237
233
|
await nativeFS.promises.rmdir(filePath, {recursive: true});
|
|
238
234
|
} else {
|
|
239
235
|
await nativeFS.promises.unlink(filePath);
|
|
@@ -245,7 +241,6 @@ registerSerializableClass(`${packageJSON.version}:NodeFS`, NodeFS);
|
|
|
245
241
|
|
|
246
242
|
let writeStreamCalls = 0;
|
|
247
243
|
|
|
248
|
-
// @ts-expect-error TS7034
|
|
249
244
|
let threadId;
|
|
250
245
|
try {
|
|
251
246
|
({threadId} = require('worker_threads'));
|
|
@@ -253,13 +248,10 @@ try {
|
|
|
253
248
|
//
|
|
254
249
|
}
|
|
255
250
|
|
|
256
|
-
// @ts-expect-error TS7034
|
|
257
251
|
let useOsTmpDir;
|
|
258
252
|
|
|
259
|
-
function shouldUseOsTmpDir(filePath
|
|
260
|
-
// @ts-expect-error TS7005
|
|
253
|
+
function shouldUseOsTmpDir(filePath) {
|
|
261
254
|
if (useOsTmpDir != null) {
|
|
262
|
-
// @ts-expect-error TS7005
|
|
263
255
|
return useOsTmpDir;
|
|
264
256
|
}
|
|
265
257
|
try {
|
|
@@ -273,7 +265,7 @@ function shouldUseOsTmpDir(filePath: FilePath) {
|
|
|
273
265
|
// Check the tmpdir is on the same partition as the target directory.
|
|
274
266
|
// This is required to ensure renaming is an atomic operation.
|
|
275
267
|
useOsTmpDir = tmpDirStats.dev === filePathStats.dev;
|
|
276
|
-
} catch (e
|
|
268
|
+
} catch (e) {
|
|
277
269
|
// We don't have read/write access to the OS tmp directory
|
|
278
270
|
useOsTmpDir = false;
|
|
279
271
|
}
|
|
@@ -296,7 +288,6 @@ function getTempFilePath(filePath: FilePath) {
|
|
|
296
288
|
tmpFilePath +
|
|
297
289
|
'.' +
|
|
298
290
|
process.pid +
|
|
299
|
-
// @ts-expect-error TS7005
|
|
300
291
|
(threadId != null ? '.' + threadId : '') +
|
|
301
292
|
'.' +
|
|
302
293
|
(writeStreamCalls++).toString(36)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import path from 'path';
|
|
2
4
|
import {NodeFS} from './NodeFS';
|
|
3
5
|
import {getVcsStateSnapshot, getEventsSince} from '@atlaspack/rust';
|
|
@@ -7,6 +9,7 @@ import {registerSerializableClass} from '@atlaspack/build-cache';
|
|
|
7
9
|
import logger, {instrumentAsync} from '@atlaspack/logger';
|
|
8
10
|
import {getFeatureFlagValue} from '@atlaspack/feature-flags';
|
|
9
11
|
|
|
12
|
+
// $FlowFixMe
|
|
10
13
|
import packageJSON from '../package.json';
|
|
11
14
|
|
|
12
15
|
export interface NodeVCSAwareFSOptions {
|
|
@@ -40,6 +43,7 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
40
43
|
this.#gitRepoPath = options.gitRepoPath;
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
// $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
|
|
43
47
|
static deserialize(data: SerializedNodeVCSAwareFS): NodeVCSAwareFS {
|
|
44
48
|
const fs = new NodeVCSAwareFS({
|
|
45
49
|
excludePatterns: data.excludePatterns,
|
|
@@ -49,7 +53,7 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
49
53
|
return fs;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
//
|
|
56
|
+
// $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
|
|
53
57
|
serialize(): SerializedNodeVCSAwareFS {
|
|
54
58
|
return {
|
|
55
59
|
excludePatterns: this.#excludePatterns,
|
|
@@ -81,22 +85,18 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
81
85
|
return JSON.parse(snapshotFileContent);
|
|
82
86
|
},
|
|
83
87
|
);
|
|
84
|
-
let watcherEventsSince
|
|
88
|
+
let watcherEventsSince = [];
|
|
85
89
|
|
|
86
90
|
const vcsEventsSince =
|
|
87
91
|
vcsState != null
|
|
88
|
-
?
|
|
89
|
-
(
|
|
92
|
+
? (
|
|
90
93
|
await instrumentAsync('NodeVCSAwareFS::rust.getEventsSince', () =>
|
|
91
|
-
// @ts-expect-error TS2739
|
|
92
94
|
getEventsSince(gitRepoPath, vcsState, null),
|
|
93
95
|
)
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
.
|
|
97
|
-
|
|
98
|
-
type: e.changeType,
|
|
99
|
-
}))
|
|
96
|
+
).map((e) => ({
|
|
97
|
+
path: e.path,
|
|
98
|
+
type: e.changeType,
|
|
99
|
+
}))
|
|
100
100
|
: null;
|
|
101
101
|
|
|
102
102
|
if (getFeatureFlagValue('vcsMode') !== 'NEW' && vcsEventsSince != null) {
|
|
@@ -107,7 +107,6 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
107
107
|
this.#logEventDiff?.(watcherEventsSince, vcsEventsSince);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
// @ts-expect-error TS2345
|
|
111
110
|
if (['NEW_AND_CHECK', 'NEW'].includes(getFeatureFlagValue('vcsMode'))) {
|
|
112
111
|
if (vcsEventsSince == null) {
|
|
113
112
|
logger.error({
|
|
@@ -160,7 +159,6 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
160
159
|
try {
|
|
161
160
|
vcsState = await instrumentAsync(
|
|
162
161
|
'NodeVCSAwareFS::getVcsStateSnapshot',
|
|
163
|
-
// @ts-expect-error TS2322
|
|
164
162
|
() => getVcsStateSnapshot(gitRepoPath, this.#excludePatterns),
|
|
165
163
|
);
|
|
166
164
|
|
|
@@ -169,13 +167,11 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
169
167
|
message: 'Expose VCS timing metrics',
|
|
170
168
|
meta: {
|
|
171
169
|
trackableEvent: 'vcs_timing_metrics',
|
|
172
|
-
// @ts-expect-error TS2339
|
|
173
170
|
dirtyFilesExecutionTime: vcsState?.dirtyFilesExecutionTime,
|
|
174
|
-
// @ts-expect-error TS2339
|
|
175
171
|
yarnStatesExecutionTime: vcsState?.yarnStatesExecutionTime,
|
|
176
172
|
},
|
|
177
173
|
});
|
|
178
|
-
} catch (err
|
|
174
|
+
} catch (err) {
|
|
179
175
|
logger.error({
|
|
180
176
|
origin: '@atlaspack/fs',
|
|
181
177
|
message: `Failed to get VCS state snapshot: ${err.message}`,
|
|
@@ -189,7 +185,7 @@ export class NodeVCSAwareFS extends NodeFS {
|
|
|
189
185
|
const snapshotContents = {
|
|
190
186
|
vcsState,
|
|
191
187
|
nativeSnapshotPath,
|
|
192
|
-
}
|
|
188
|
+
};
|
|
193
189
|
await this.writeFile(snapshot, JSON.stringify(snapshotContents));
|
|
194
190
|
}
|
|
195
191
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import type {Readable, Writable} from 'stream';
|
|
2
4
|
import type {
|
|
3
5
|
FilePath,
|
|
@@ -44,12 +46,12 @@ export class OverlayFS implements FileSystem {
|
|
|
44
46
|
return fs;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
serialize(): {
|
|
48
|
-
$$raw: boolean
|
|
49
|
-
readable: FileSystem
|
|
50
|
-
writable: FileSystem
|
|
51
|
-
deleted: Set<FilePath
|
|
52
|
-
} {
|
|
49
|
+
serialize(): {|
|
|
50
|
+
$$raw: boolean,
|
|
51
|
+
readable: FileSystem,
|
|
52
|
+
writable: FileSystem,
|
|
53
|
+
deleted: Set<FilePath>,
|
|
54
|
+
|} {
|
|
53
55
|
return {
|
|
54
56
|
$$raw: false,
|
|
55
57
|
writable: this.writable,
|
|
@@ -106,7 +108,7 @@ export class OverlayFS implements FileSystem {
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
|
-
} catch (e
|
|
111
|
+
} catch (e) {
|
|
110
112
|
if (e.code === 'ENOENT') {
|
|
111
113
|
return false;
|
|
112
114
|
}
|
|
@@ -139,7 +141,7 @@ export class OverlayFS implements FileSystem {
|
|
|
139
141
|
async writeFile(
|
|
140
142
|
filePath: FilePath,
|
|
141
143
|
contents: string | Buffer,
|
|
142
|
-
options
|
|
144
|
+
options: ?FileOptions,
|
|
143
145
|
): Promise<void> {
|
|
144
146
|
filePath = await this._copyPathForWrite(filePath);
|
|
145
147
|
await this.writable.writeFile(filePath, contents, options);
|
|
@@ -210,7 +212,7 @@ export class OverlayFS implements FileSystem {
|
|
|
210
212
|
|
|
211
213
|
try {
|
|
212
214
|
await this.writable.unlink(filePath);
|
|
213
|
-
} catch (e
|
|
215
|
+
} catch (e) {
|
|
214
216
|
if (e.code === 'ENOENT' && !this.readable.existsSync(filePath)) {
|
|
215
217
|
throw e;
|
|
216
218
|
}
|
|
@@ -237,7 +239,7 @@ export class OverlayFS implements FileSystem {
|
|
|
237
239
|
async rimraf(filePath: FilePath): Promise<void> {
|
|
238
240
|
try {
|
|
239
241
|
await this.unlink(filePath);
|
|
240
|
-
} catch (e
|
|
242
|
+
} catch (e) {
|
|
241
243
|
// noop
|
|
242
244
|
}
|
|
243
245
|
}
|
|
@@ -248,7 +250,7 @@ export class OverlayFS implements FileSystem {
|
|
|
248
250
|
return this.writable.ncp(source, destination);
|
|
249
251
|
}
|
|
250
252
|
|
|
251
|
-
createReadStream(filePath: FilePath, opts?: FileOptions
|
|
253
|
+
createReadStream(filePath: FilePath, opts?: ?FileOptions): Readable {
|
|
252
254
|
filePath = this._deletedThrows(filePath);
|
|
253
255
|
if (this.writable.existsSync(filePath)) {
|
|
254
256
|
return this.writable.createReadStream(filePath, opts);
|
|
@@ -257,7 +259,7 @@ export class OverlayFS implements FileSystem {
|
|
|
257
259
|
return this.readable.createReadStream(filePath, opts);
|
|
258
260
|
}
|
|
259
261
|
|
|
260
|
-
createWriteStream(path: FilePath, opts?: FileOptions
|
|
262
|
+
createWriteStream(path: FilePath, opts?: ?FileOptions): Writable {
|
|
261
263
|
path = this._normalizePath(path);
|
|
262
264
|
this.deleted.delete(path);
|
|
263
265
|
return this.writable.createWriteStream(path, opts);
|
|
@@ -279,10 +281,10 @@ export class OverlayFS implements FileSystem {
|
|
|
279
281
|
readFileSync(filePath: FilePath, encoding?: Encoding): any {
|
|
280
282
|
filePath = this.realpathSync(filePath);
|
|
281
283
|
try {
|
|
282
|
-
//
|
|
284
|
+
// $FlowFixMe[incompatible-call]
|
|
283
285
|
return this.writable.readFileSync(filePath, encoding);
|
|
284
|
-
} catch (err
|
|
285
|
-
//
|
|
286
|
+
} catch (err) {
|
|
287
|
+
// $FlowFixMe[incompatible-call]
|
|
286
288
|
return this.readable.readFileSync(filePath, encoding);
|
|
287
289
|
}
|
|
288
290
|
}
|
|
@@ -291,7 +293,7 @@ export class OverlayFS implements FileSystem {
|
|
|
291
293
|
filePath = this._normalizePath(filePath);
|
|
292
294
|
try {
|
|
293
295
|
return this.writable.statSync(filePath);
|
|
294
|
-
} catch (e
|
|
296
|
+
} catch (e) {
|
|
295
297
|
if (e.code === 'ENOENT' && this.existsSync(filePath)) {
|
|
296
298
|
return this.readable.statSync(filePath);
|
|
297
299
|
}
|
|
@@ -319,7 +321,7 @@ export class OverlayFS implements FileSystem {
|
|
|
319
321
|
|
|
320
322
|
try {
|
|
321
323
|
filePath = this.realpathSync(filePath);
|
|
322
|
-
} catch (err
|
|
324
|
+
} catch (err) {
|
|
323
325
|
if (err.code !== 'ENOENT') throw err;
|
|
324
326
|
}
|
|
325
327
|
|
|
@@ -341,8 +343,7 @@ export class OverlayFS implements FileSystem {
|
|
|
341
343
|
let entries = new Map();
|
|
342
344
|
|
|
343
345
|
try {
|
|
344
|
-
|
|
345
|
-
for (let entry of this.writable.readdirSync(dir, opts)) {
|
|
346
|
+
for (let entry: any of this.writable.readdirSync(dir, opts)) {
|
|
346
347
|
let filePath = path.join(dir, entry.name ?? entry);
|
|
347
348
|
if (this.deleted.has(filePath)) continue;
|
|
348
349
|
entries.set(filePath, entry);
|
|
@@ -352,8 +353,7 @@ export class OverlayFS implements FileSystem {
|
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
try {
|
|
355
|
-
|
|
356
|
-
for (let entry of this.readable.readdirSync(dir, opts)) {
|
|
356
|
+
for (let entry: any of this.readable.readdirSync(dir, opts)) {
|
|
357
357
|
let filePath = path.join(dir, entry.name ?? entry);
|
|
358
358
|
if (this.deleted.has(filePath)) continue;
|
|
359
359
|
if (entries.has(filePath)) continue;
|
|
@@ -368,7 +368,7 @@ export class OverlayFS implements FileSystem {
|
|
|
368
368
|
|
|
369
369
|
async watch(
|
|
370
370
|
dir: FilePath,
|
|
371
|
-
fn: (err: Error
|
|
371
|
+
fn: (err: ?Error, events: Array<Event>) => mixed,
|
|
372
372
|
opts: WatcherOptions,
|
|
373
373
|
): Promise<AsyncSubscription> {
|
|
374
374
|
let writableSubscription = await this.writable.watch(dir, fn, opts);
|
|
@@ -411,18 +411,15 @@ export class OverlayFS implements FileSystem {
|
|
|
411
411
|
fileNames: Array<string>,
|
|
412
412
|
fromDir: FilePath,
|
|
413
413
|
root: FilePath,
|
|
414
|
-
): FilePath
|
|
414
|
+
): ?FilePath {
|
|
415
415
|
return findAncestorFile(this, fileNames, fromDir, root);
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
-
findNodeModule(
|
|
419
|
-
moduleName: string,
|
|
420
|
-
fromDir: FilePath,
|
|
421
|
-
): FilePath | null | undefined {
|
|
418
|
+
findNodeModule(moduleName: string, fromDir: FilePath): ?FilePath {
|
|
422
419
|
return findNodeModule(this, moduleName, fromDir);
|
|
423
420
|
}
|
|
424
421
|
|
|
425
|
-
findFirstFile(filePaths: Array<FilePath>): FilePath
|
|
422
|
+
findFirstFile(filePaths: Array<FilePath>): ?FilePath {
|
|
426
423
|
return findFirstFile(this, filePaths);
|
|
427
424
|
}
|
|
428
425
|
}
|
package/src/{find.ts → find.js}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
import type {FilePath, FileSystem} from '@atlaspack/types-internal';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
|
|
@@ -5,7 +6,7 @@ export function findNodeModule(
|
|
|
5
6
|
fs: FileSystem,
|
|
6
7
|
moduleName: string,
|
|
7
8
|
dir: FilePath,
|
|
8
|
-
): FilePath
|
|
9
|
+
): ?FilePath {
|
|
9
10
|
let {root} = path.parse(dir);
|
|
10
11
|
while (dir !== root) {
|
|
11
12
|
// Skip node_modules directories
|
|
@@ -19,7 +20,7 @@ export function findNodeModule(
|
|
|
19
20
|
if (stats.isDirectory()) {
|
|
20
21
|
return moduleDir;
|
|
21
22
|
}
|
|
22
|
-
} catch (err
|
|
23
|
+
} catch (err) {
|
|
23
24
|
// ignore
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -35,7 +36,7 @@ export function findAncestorFile(
|
|
|
35
36
|
fileNames: Array<string>,
|
|
36
37
|
dir: FilePath,
|
|
37
38
|
root: FilePath,
|
|
38
|
-
): FilePath
|
|
39
|
+
): ?FilePath {
|
|
39
40
|
let {root: pathRoot} = path.parse(dir);
|
|
40
41
|
// eslint-disable-next-line no-constant-condition
|
|
41
42
|
while (true) {
|
|
@@ -49,7 +50,7 @@ export function findAncestorFile(
|
|
|
49
50
|
if (fs.statSync(filePath).isFile()) {
|
|
50
51
|
return filePath;
|
|
51
52
|
}
|
|
52
|
-
} catch (err
|
|
53
|
+
} catch (err) {
|
|
53
54
|
// ignore
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -67,13 +68,13 @@ export function findAncestorFile(
|
|
|
67
68
|
export function findFirstFile(
|
|
68
69
|
fs: FileSystem,
|
|
69
70
|
filePaths: Array<FilePath>,
|
|
70
|
-
): FilePath
|
|
71
|
+
): ?FilePath {
|
|
71
72
|
for (let filePath of filePaths) {
|
|
72
73
|
try {
|
|
73
74
|
if (fs.statSync(filePath).isFile()) {
|
|
74
75
|
return filePath;
|
|
75
76
|
}
|
|
76
|
-
} catch (err
|
|
77
|
+
} catch (err) {
|
|
77
78
|
// ignore
|
|
78
79
|
}
|
|
79
80
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow strict-local
|
|
1
2
|
import type {
|
|
2
3
|
FilePath,
|
|
3
4
|
FileSystem,
|
|
@@ -16,7 +17,7 @@ export * from './NodeVCSAwareFS';
|
|
|
16
17
|
|
|
17
18
|
export type {FileSystem, FileOptions};
|
|
18
19
|
|
|
19
|
-
const pipeline: (
|
|
20
|
+
const pipeline: (Readable, Writable) => Promise<void> = promisify(
|
|
20
21
|
stream.pipeline,
|
|
21
22
|
);
|
|
22
23
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import {OverlayFS} from '../src/OverlayFS';
|
|
2
|
-
import {fsFixture} from '@atlaspack/test-utils';
|
|
4
|
+
import {fsFixture} from '@atlaspack/test-utils/src/fsFixture';
|
|
3
5
|
import {MemoryFS} from '../src/MemoryFS';
|
|
4
6
|
import WorkerFarm from '@atlaspack/workers';
|
|
5
7
|
import {WORKER_PATH} from '@atlaspack/core';
|
|
@@ -8,9 +10,9 @@ import assert from 'assert';
|
|
|
8
10
|
import path from 'path';
|
|
9
11
|
|
|
10
12
|
describe('OverlayFS', () => {
|
|
11
|
-
let underlayFS
|
|
12
|
-
let fs
|
|
13
|
-
let workerFarm
|
|
13
|
+
let underlayFS;
|
|
14
|
+
let fs;
|
|
15
|
+
let workerFarm;
|
|
14
16
|
|
|
15
17
|
beforeEach(() => {
|
|
16
18
|
workerFarm = new WorkerFarm({
|