@atlaspack/fs 2.15.16 → 2.15.17-typescript-5ad950d33.0
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/LICENSE +201 -0
- package/lib/MemoryFS.d.ts +165 -0
- package/lib/MemoryFS.js +18 -9
- package/lib/NodeFS.browser.d.ts +4 -0
- package/lib/NodeFS.browser.js +1 -1
- package/lib/NodeFS.d.ts +38 -0
- package/lib/NodeFS.js +24 -7
- package/lib/NodeVCSAwareFS.d.ts +18 -0
- package/lib/NodeVCSAwareFS.js +16 -6
- package/lib/OverlayFS.d.ts +50 -0
- package/lib/OverlayFS.js +4 -2
- package/lib/find.d.ts +4 -0
- package/lib/index.d.ts +7 -0
- package/package.json +16 -16
- package/src/{MemoryFS.js → MemoryFS.ts} +50 -36
- package/src/{NodeFS.browser.js → NodeFS.browser.ts} +1 -2
- package/src/{NodeFS.js → NodeFS.ts} +26 -17
- package/src/{NodeVCSAwareFS.js → NodeVCSAwareFS.ts} +17 -13
- package/src/{OverlayFS.js → OverlayFS.ts} +28 -25
- package/src/{find.js → find.ts} +6 -7
- package/src/{index.js → index.ts} +1 -2
- package/test/{OverlayFS.test.js → OverlayFS.test.ts} +4 -6
- package/tsconfig.json +4 -0
- package/index.d.ts +0 -34
- package/lib/types.d.ts +0 -0
package/lib/NodeVCSAwareFS.js
CHANGED
|
@@ -44,7 +44,6 @@ var _package = _interopRequireDefault(require("../package.json"));
|
|
|
44
44
|
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); }
|
|
45
45
|
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; }
|
|
46
46
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
|
-
// $FlowFixMe
|
|
48
47
|
class NodeVCSAwareFS extends _NodeFS.NodeFS {
|
|
49
48
|
/**
|
|
50
49
|
* These files are excluded from 'dirty file' tracking even if they are
|
|
@@ -66,8 +65,6 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
|
|
|
66
65
|
this.#logEventDiff = options.logEventDiff;
|
|
67
66
|
this.#gitRepoPath = options.gitRepoPath;
|
|
68
67
|
}
|
|
69
|
-
|
|
70
|
-
// $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
|
|
71
68
|
static deserialize(data) {
|
|
72
69
|
const fs = new NodeVCSAwareFS({
|
|
73
70
|
excludePatterns: data.excludePatterns,
|
|
@@ -77,7 +74,7 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
|
|
|
77
74
|
return fs;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
//
|
|
77
|
+
// @ts-expect-error TS2416
|
|
81
78
|
serialize() {
|
|
82
79
|
return {
|
|
83
80
|
excludePatterns: this.#excludePatterns,
|
|
@@ -103,7 +100,14 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
|
|
|
103
100
|
return JSON.parse(snapshotFileContent);
|
|
104
101
|
});
|
|
105
102
|
let watcherEventsSince = [];
|
|
106
|
-
const vcsEventsSince = vcsState != null ?
|
|
103
|
+
const vcsEventsSince = vcsState != null ?
|
|
104
|
+
// @ts-expect-error TS2571
|
|
105
|
+
(await (0, _logger().instrumentAsync)('NodeVCSAwareFS::rust.getEventsSince', () =>
|
|
106
|
+
// @ts-expect-error TS2739
|
|
107
|
+
(0, _rust().getEventsSince)(gitRepoPath, vcsState, null))
|
|
108
|
+
|
|
109
|
+
// @ts-expect-error TS7006
|
|
110
|
+
).map(e => ({
|
|
107
111
|
path: e.path,
|
|
108
112
|
type: e.changeType
|
|
109
113
|
})) : null;
|
|
@@ -112,6 +116,8 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
|
|
|
112
116
|
watcherEventsSince = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::watchman.getEventsSince', () => this.watcher().getEventsSince(dir, nativeSnapshotPath, opts));
|
|
113
117
|
(_this$logEventDiff = this.#logEventDiff) === null || _this$logEventDiff === void 0 || _this$logEventDiff.call(this, watcherEventsSince, vcsEventsSince);
|
|
114
118
|
}
|
|
119
|
+
|
|
120
|
+
// @ts-expect-error TS2345
|
|
115
121
|
if (['NEW_AND_CHECK', 'NEW'].includes((0, _featureFlags().getFeatureFlagValue)('vcsMode'))) {
|
|
116
122
|
if (vcsEventsSince == null) {
|
|
117
123
|
_logger().default.error({
|
|
@@ -145,13 +151,17 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
|
|
|
145
151
|
let vcsState = null;
|
|
146
152
|
try {
|
|
147
153
|
var _vcsState, _vcsState2;
|
|
148
|
-
vcsState = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot',
|
|
154
|
+
vcsState = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot',
|
|
155
|
+
// @ts-expect-error TS2322
|
|
156
|
+
() => (0, _rust().getVcsStateSnapshot)(gitRepoPath, this.#excludePatterns));
|
|
149
157
|
_logger().default.verbose({
|
|
150
158
|
origin: '@atlaspack/fs',
|
|
151
159
|
message: 'Expose VCS timing metrics',
|
|
152
160
|
meta: {
|
|
153
161
|
trackableEvent: 'vcs_timing_metrics',
|
|
162
|
+
// @ts-expect-error TS2339
|
|
154
163
|
dirtyFilesExecutionTime: (_vcsState = vcsState) === null || _vcsState === void 0 ? void 0 : _vcsState.dirtyFilesExecutionTime,
|
|
164
|
+
// @ts-expect-error TS2339
|
|
155
165
|
yarnStatesExecutionTime: (_vcsState2 = vcsState) === null || _vcsState2 === void 0 ? void 0 : _vcsState2.yarnStatesExecutionTime
|
|
156
166
|
}
|
|
157
167
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { FilePath, Encoding, FileOptions, FileSystem, ReaddirOptions, FileStats } from '@atlaspack/types-internal';
|
|
3
|
+
import type { Event, Options as WatcherOptions, AsyncSubscription } from '@parcel/watcher';
|
|
4
|
+
import WorkerFarm from '@atlaspack/workers';
|
|
5
|
+
export declare class OverlayFS implements FileSystem {
|
|
6
|
+
deleted: Set<FilePath>;
|
|
7
|
+
writable: FileSystem;
|
|
8
|
+
readable: FileSystem;
|
|
9
|
+
_cwd: FilePath;
|
|
10
|
+
constructor(workerFarmOrFS: WorkerFarm | FileSystem, readable: FileSystem);
|
|
11
|
+
static deserialize(opts: any): OverlayFS;
|
|
12
|
+
serialize(): {
|
|
13
|
+
$$raw: boolean;
|
|
14
|
+
readable: FileSystem;
|
|
15
|
+
writable: FileSystem;
|
|
16
|
+
deleted: Set<FilePath>;
|
|
17
|
+
};
|
|
18
|
+
_deletedThrows(filePath: FilePath): FilePath;
|
|
19
|
+
_checkExists(filePath: FilePath): FilePath;
|
|
20
|
+
_isSymlink(filePath: FilePath): boolean;
|
|
21
|
+
_copyPathForWrite(filePath: FilePath): Promise<FilePath>;
|
|
22
|
+
_normalizePath(filePath: FilePath): FilePath;
|
|
23
|
+
readFile(filePath: FilePath, encoding?: Encoding): Promise<any>;
|
|
24
|
+
writeFile(filePath: FilePath, contents: string | Buffer, options?: FileOptions | null): Promise<void>;
|
|
25
|
+
copyFile(source: FilePath, destination: FilePath): Promise<void>;
|
|
26
|
+
stat(filePath: FilePath): Promise<FileStats>;
|
|
27
|
+
symlink(target: FilePath, filePath: FilePath): Promise<void>;
|
|
28
|
+
unlink(filePath: FilePath): Promise<void>;
|
|
29
|
+
mkdirp(dir: FilePath): Promise<void>;
|
|
30
|
+
rimraf(filePath: FilePath): Promise<void>;
|
|
31
|
+
ncp(source: FilePath, destination: FilePath): Promise<void>;
|
|
32
|
+
createReadStream(filePath: FilePath, opts?: FileOptions | null): Readable;
|
|
33
|
+
createWriteStream(path: FilePath, opts?: FileOptions | null): Writable;
|
|
34
|
+
cwd(): FilePath;
|
|
35
|
+
chdir(path: FilePath): void;
|
|
36
|
+
realpath(filePath: FilePath): Promise<FilePath>;
|
|
37
|
+
readFileSync(filePath: FilePath, encoding?: Encoding): any;
|
|
38
|
+
statSync(filePath: FilePath): FileStats;
|
|
39
|
+
realpathSync(filePath: FilePath): FilePath;
|
|
40
|
+
exists(filePath: FilePath): Promise<boolean>;
|
|
41
|
+
existsSync(filePath: FilePath): boolean;
|
|
42
|
+
readdir(path: FilePath, opts?: ReaddirOptions): Promise<any>;
|
|
43
|
+
readdirSync(dir: FilePath, opts?: ReaddirOptions): any;
|
|
44
|
+
watch(dir: FilePath, fn: (err: Error | null | undefined, events: Array<Event>) => unknown, opts: WatcherOptions): Promise<AsyncSubscription>;
|
|
45
|
+
getEventsSince(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<Array<Event>>;
|
|
46
|
+
writeSnapshot(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<void>;
|
|
47
|
+
findAncestorFile(fileNames: Array<string>, fromDir: FilePath, root: FilePath): FilePath | null | undefined;
|
|
48
|
+
findNodeModule(moduleName: string, fromDir: FilePath): FilePath | null | undefined;
|
|
49
|
+
findFirstFile(filePaths: Array<FilePath>): FilePath | null | undefined;
|
|
50
|
+
}
|
package/lib/OverlayFS.js
CHANGED
|
@@ -252,10 +252,10 @@ class OverlayFS {
|
|
|
252
252
|
readFileSync(filePath, encoding) {
|
|
253
253
|
filePath = this.realpathSync(filePath);
|
|
254
254
|
try {
|
|
255
|
-
//
|
|
255
|
+
// @ts-expect-error TS2345
|
|
256
256
|
return this.writable.readFileSync(filePath, encoding);
|
|
257
257
|
} catch (err) {
|
|
258
|
-
//
|
|
258
|
+
// @ts-expect-error TS2345
|
|
259
259
|
return this.readable.readFileSync(filePath, encoding);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
@@ -304,6 +304,7 @@ class OverlayFS {
|
|
|
304
304
|
// Read from both filesystems and merge the results
|
|
305
305
|
let entries = new Map();
|
|
306
306
|
try {
|
|
307
|
+
// @ts-expect-error TS2769
|
|
307
308
|
for (let entry of this.writable.readdirSync(dir, opts)) {
|
|
308
309
|
let filePath = _path().default.join(dir, entry.name ?? entry);
|
|
309
310
|
if (this.deleted.has(filePath)) continue;
|
|
@@ -313,6 +314,7 @@ class OverlayFS {
|
|
|
313
314
|
// noop
|
|
314
315
|
}
|
|
315
316
|
try {
|
|
317
|
+
// @ts-expect-error TS2769
|
|
316
318
|
for (let entry of this.readable.readdirSync(dir, opts)) {
|
|
317
319
|
let filePath = _path().default.join(dir, entry.name ?? entry);
|
|
318
320
|
if (this.deleted.has(filePath)) continue;
|
package/lib/find.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FilePath, FileSystem } from '@atlaspack/types-internal';
|
|
2
|
+
export declare function findNodeModule(fs: FileSystem, moduleName: string, dir: FilePath): FilePath | null | undefined;
|
|
3
|
+
export declare function findAncestorFile(fs: FileSystem, fileNames: Array<string>, dir: FilePath, root: FilePath): FilePath | null | undefined;
|
|
4
|
+
export declare function findFirstFile(fs: FileSystem, filePaths: Array<FilePath>): FilePath | null | undefined;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FilePath, FileSystem, FileOptions } from '@atlaspack/types-internal';
|
|
2
|
+
export * from './NodeFS';
|
|
3
|
+
export * from './MemoryFS';
|
|
4
|
+
export * from './OverlayFS';
|
|
5
|
+
export * from './NodeVCSAwareFS';
|
|
6
|
+
export type { FileSystem, FileOptions };
|
|
7
|
+
export declare function ncp(sourceFS: FileSystem, source: FilePath, destinationFS: FileSystem, destination: FilePath, filter?: (filePath: FilePath) => boolean): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/fs",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.17-typescript-5ad950d33.0",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"source": "src/index.
|
|
15
|
-
"types": "index.d.ts",
|
|
13
|
+
"main": "./lib/index.js",
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">= 16.0.0"
|
|
18
18
|
},
|
|
@@ -48,19 +48,18 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
|
-
"
|
|
52
|
-
"check-ts": "tsc --noEmit index.d.ts"
|
|
51
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
53
52
|
},
|
|
54
53
|
"dependencies": {
|
|
55
|
-
"@atlaspack/build-cache": "2.13.
|
|
56
|
-
"@atlaspack/feature-flags": "2.20.0",
|
|
57
|
-
"@atlaspack/logger": "2.14.
|
|
58
|
-
"@atlaspack/rust": "3.4.
|
|
59
|
-
"@atlaspack/types-internal": "2.16.0",
|
|
60
|
-
"@atlaspack/utils": "2.17.
|
|
54
|
+
"@atlaspack/build-cache": "2.13.4-typescript-5ad950d33.0",
|
|
55
|
+
"@atlaspack/feature-flags": "2.20.1-typescript-5ad950d33.0",
|
|
56
|
+
"@atlaspack/logger": "2.14.14-typescript-5ad950d33.0",
|
|
57
|
+
"@atlaspack/rust": "3.4.2-typescript-5ad950d33.0",
|
|
58
|
+
"@atlaspack/types-internal": "2.16.1-typescript-5ad950d33.0",
|
|
59
|
+
"@atlaspack/utils": "2.17.4-typescript-5ad950d33.0",
|
|
60
|
+
"@atlaspack/watcher-watchman-js": "2.14.22-typescript-5ad950d33.0",
|
|
61
|
+
"@atlaspack/workers": "2.14.22-typescript-5ad950d33.0",
|
|
61
62
|
"@parcel/watcher": "^2.0.7",
|
|
62
|
-
"@atlaspack/workers": "2.14.21",
|
|
63
|
-
"@atlaspack/watcher-watchman-js": "2.14.21",
|
|
64
63
|
"graceful-fs": "^4.2.4",
|
|
65
64
|
"ncp": "^2.0.0",
|
|
66
65
|
"nullthrows": "^1.1.1",
|
|
@@ -70,5 +69,6 @@
|
|
|
70
69
|
"@atlaspack/fs": "./lib/browser.js",
|
|
71
70
|
"./src/NodeFS.js": "./src/NodeFS.browser.js"
|
|
72
71
|
},
|
|
73
|
-
"type": "commonjs"
|
|
74
|
-
|
|
72
|
+
"type": "commonjs",
|
|
73
|
+
"gitHead": "5ad950d33a5f2255ebeb10c04a2e84c346e2de85"
|
|
74
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
FilePath,
|
|
5
3
|
FileSystem,
|
|
@@ -28,22 +26,21 @@ let id = 0;
|
|
|
28
26
|
|
|
29
27
|
type HandleFunction = (...args: Array<any>) => any;
|
|
30
28
|
type SerializedMemoryFS = {
|
|
31
|
-
id: number
|
|
32
|
-
handle: any
|
|
33
|
-
dirs: Map<FilePath, Directory
|
|
34
|
-
files: Map<FilePath, File
|
|
35
|
-
symlinks: Map<FilePath, FilePath
|
|
36
|
-
...
|
|
29
|
+
id: number;
|
|
30
|
+
handle: any;
|
|
31
|
+
dirs: Map<FilePath, Directory>;
|
|
32
|
+
files: Map<FilePath, File>;
|
|
33
|
+
symlinks: Map<FilePath, FilePath>;
|
|
37
34
|
};
|
|
38
35
|
|
|
39
|
-
type WorkerEvent = {
|
|
40
|
-
type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink'
|
|
41
|
-
path: FilePath
|
|
42
|
-
entry?: Entry
|
|
43
|
-
target?: FilePath
|
|
44
|
-
|
|
36
|
+
type WorkerEvent = {
|
|
37
|
+
type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink';
|
|
38
|
+
path: FilePath;
|
|
39
|
+
entry?: Entry;
|
|
40
|
+
target?: FilePath;
|
|
41
|
+
};
|
|
45
42
|
|
|
46
|
-
type ResolveFunction = () =>
|
|
43
|
+
type ResolveFunction = () => unknown;
|
|
47
44
|
|
|
48
45
|
export class MemoryFS implements FileSystem {
|
|
49
46
|
dirs: Map<FilePath, Directory>;
|
|
@@ -52,11 +49,13 @@ export class MemoryFS implements FileSystem {
|
|
|
52
49
|
watchers: Map<FilePath, Set<Watcher>>;
|
|
53
50
|
events: Array<Event>;
|
|
54
51
|
id: number;
|
|
52
|
+
// @ts-expect-error TS2564
|
|
55
53
|
handle: Handle;
|
|
56
54
|
farm: WorkerFarm;
|
|
57
55
|
_cwd: FilePath;
|
|
58
56
|
_eventQueue: Array<Event>;
|
|
59
|
-
|
|
57
|
+
// @ts-expect-error TS2564
|
|
58
|
+
_watcherTimer: number;
|
|
60
59
|
_numWorkerInstances: number = 0;
|
|
61
60
|
_workerHandles: Array<Handle>;
|
|
62
61
|
_workerRegisterResolves: Array<ResolveFunction> = [];
|
|
@@ -103,8 +102,8 @@ export class MemoryFS implements FileSystem {
|
|
|
103
102
|
serialize(): SerializedMemoryFS {
|
|
104
103
|
if (!this.handle) {
|
|
105
104
|
this.handle = this.farm.createReverseHandle(
|
|
106
|
-
(fn: string, args: Array<
|
|
107
|
-
//
|
|
105
|
+
(fn: string, args: Array<unknown>) => {
|
|
106
|
+
// @ts-expect-error TS7053
|
|
108
107
|
return this[fn](...args);
|
|
109
108
|
},
|
|
110
109
|
);
|
|
@@ -114,6 +113,7 @@ export class MemoryFS implements FileSystem {
|
|
|
114
113
|
this._numWorkerInstances++;
|
|
115
114
|
|
|
116
115
|
return {
|
|
116
|
+
// @ts-expect-error TS2353
|
|
117
117
|
$$raw: false,
|
|
118
118
|
id: this.id,
|
|
119
119
|
handle: this.handle,
|
|
@@ -166,7 +166,7 @@ export class MemoryFS implements FileSystem {
|
|
|
166
166
|
async writeFile(
|
|
167
167
|
filePath: FilePath,
|
|
168
168
|
contents: Buffer | string,
|
|
169
|
-
options?:
|
|
169
|
+
options?: FileOptions | null,
|
|
170
170
|
) {
|
|
171
171
|
filePath = this._normalizePath(filePath);
|
|
172
172
|
if (this.dirs.has(filePath)) {
|
|
@@ -256,7 +256,7 @@ export class MemoryFS implements FileSystem {
|
|
|
256
256
|
dir += path.sep;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
let res = [];
|
|
259
|
+
let res: Array<Dirent | any | string> = [];
|
|
260
260
|
for (let [filePath, entry] of this.dirs) {
|
|
261
261
|
if (filePath === dir) {
|
|
262
262
|
continue;
|
|
@@ -496,7 +496,10 @@ export class MemoryFS implements FileSystem {
|
|
|
496
496
|
return new ReadStream(this, filePath);
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
createWriteStream(
|
|
499
|
+
createWriteStream(
|
|
500
|
+
filePath: FilePath,
|
|
501
|
+
options?: FileOptions | null,
|
|
502
|
+
): WriteStream {
|
|
500
503
|
this.mkdirp(path.dirname(filePath));
|
|
501
504
|
return new WriteStream(this, filePath, options);
|
|
502
505
|
}
|
|
@@ -541,6 +544,7 @@ export class MemoryFS implements FileSystem {
|
|
|
541
544
|
this._eventQueue.push(event);
|
|
542
545
|
clearTimeout(this._watcherTimer);
|
|
543
546
|
|
|
547
|
+
// @ts-expect-error TS2322
|
|
544
548
|
this._watcherTimer = setTimeout(() => {
|
|
545
549
|
let events = this._eventQueue;
|
|
546
550
|
this._eventQueue = [];
|
|
@@ -572,8 +576,10 @@ export class MemoryFS implements FileSystem {
|
|
|
572
576
|
async _sendWorkerEvent(event: WorkerEvent) {
|
|
573
577
|
// Wait for worker instances to register their handles
|
|
574
578
|
while (this._workerHandles.length < this._numWorkerInstances) {
|
|
575
|
-
await new Promise(
|
|
576
|
-
|
|
579
|
+
await new Promise(
|
|
580
|
+
(resolve: (result: Promise<undefined> | undefined) => void) =>
|
|
581
|
+
// @ts-expect-error TS2345
|
|
582
|
+
this._workerRegisterResolves.push(resolve),
|
|
577
583
|
);
|
|
578
584
|
}
|
|
579
585
|
|
|
@@ -586,7 +592,7 @@ export class MemoryFS implements FileSystem {
|
|
|
586
592
|
|
|
587
593
|
watch(
|
|
588
594
|
dir: FilePath,
|
|
589
|
-
fn: (err:
|
|
595
|
+
fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
|
|
590
596
|
opts: WatcherOptions,
|
|
591
597
|
): Promise<AsyncSubscription> {
|
|
592
598
|
dir = this._normalizePath(dir);
|
|
@@ -640,25 +646,28 @@ export class MemoryFS implements FileSystem {
|
|
|
640
646
|
fileNames: Array<string>,
|
|
641
647
|
fromDir: FilePath,
|
|
642
648
|
root: FilePath,
|
|
643
|
-
):
|
|
649
|
+
): FilePath | null | undefined {
|
|
644
650
|
return findAncestorFile(this, fileNames, fromDir, root);
|
|
645
651
|
}
|
|
646
652
|
|
|
647
|
-
findNodeModule(
|
|
653
|
+
findNodeModule(
|
|
654
|
+
moduleName: string,
|
|
655
|
+
fromDir: FilePath,
|
|
656
|
+
): FilePath | null | undefined {
|
|
648
657
|
return findNodeModule(this, moduleName, fromDir);
|
|
649
658
|
}
|
|
650
659
|
|
|
651
|
-
findFirstFile(filePaths: Array<FilePath>):
|
|
660
|
+
findFirstFile(filePaths: Array<FilePath>): FilePath | null | undefined {
|
|
652
661
|
return findFirstFile(this, filePaths);
|
|
653
662
|
}
|
|
654
663
|
}
|
|
655
664
|
|
|
656
665
|
class Watcher {
|
|
657
|
-
fn: (err:
|
|
666
|
+
fn: (err: Error | null | undefined, events: Array<Event>) => unknown;
|
|
658
667
|
options: WatcherOptions;
|
|
659
668
|
|
|
660
669
|
constructor(
|
|
661
|
-
fn: (err:
|
|
670
|
+
fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
|
|
662
671
|
options: WatcherOptions,
|
|
663
672
|
) {
|
|
664
673
|
this.fn = fn;
|
|
@@ -726,10 +735,14 @@ class ReadStream extends Readable {
|
|
|
726
735
|
class WriteStream extends Writable {
|
|
727
736
|
fs: FileSystem;
|
|
728
737
|
filePath: FilePath;
|
|
729
|
-
options:
|
|
738
|
+
options: FileOptions | null | undefined;
|
|
730
739
|
buffer: Buffer;
|
|
731
740
|
|
|
732
|
-
constructor(
|
|
741
|
+
constructor(
|
|
742
|
+
fs: FileSystem,
|
|
743
|
+
filePath: FilePath,
|
|
744
|
+
options?: FileOptions | null,
|
|
745
|
+
) {
|
|
733
746
|
super({emitClose: true, autoDestroy: true});
|
|
734
747
|
this.fs = fs;
|
|
735
748
|
this.filePath = filePath;
|
|
@@ -750,6 +763,7 @@ class WriteStream extends Writable {
|
|
|
750
763
|
_final(callback: (error?: Error) => void) {
|
|
751
764
|
this.fs
|
|
752
765
|
.writeFile(this.filePath, this.buffer, this.options)
|
|
766
|
+
// @ts-expect-error TS2345
|
|
753
767
|
.then(callback)
|
|
754
768
|
.catch(callback);
|
|
755
769
|
}
|
|
@@ -935,7 +949,7 @@ export function makeShared(contents: Buffer | string): Buffer {
|
|
|
935
949
|
}
|
|
936
950
|
|
|
937
951
|
let contentsBuffer: Buffer | string = contents;
|
|
938
|
-
//
|
|
952
|
+
// @ts-expect-error TS2339
|
|
939
953
|
if (process.browser) {
|
|
940
954
|
// For the polyfilled buffer module, it's faster to always convert once so that the subsequent
|
|
941
955
|
// operations are fast (.byteLength and using .set instead of .write)
|
|
@@ -965,10 +979,10 @@ class WorkerFS extends MemoryFS {
|
|
|
965
979
|
|
|
966
980
|
constructor(id: number, handle: Handle) {
|
|
967
981
|
// TODO Make this not a subclass
|
|
968
|
-
//
|
|
982
|
+
// @ts-expect-error TS2554
|
|
969
983
|
super();
|
|
970
984
|
this.id = id;
|
|
971
|
-
this.handleFn = (methodName, args) =>
|
|
985
|
+
this.handleFn = (methodName: any, args: any) =>
|
|
972
986
|
WorkerFarm.getWorkerApi().runHandle(handle, [methodName, args]);
|
|
973
987
|
|
|
974
988
|
this.handleFn('_registerWorker', [
|
|
@@ -998,7 +1012,7 @@ class WorkerFS extends MemoryFS {
|
|
|
998
1012
|
}
|
|
999
1013
|
|
|
1000
1014
|
serialize(): SerializedMemoryFS {
|
|
1001
|
-
//
|
|
1015
|
+
// @ts-expect-error TS2739
|
|
1002
1016
|
return {
|
|
1003
1017
|
id: this.id,
|
|
1004
1018
|
};
|
|
@@ -1007,7 +1021,7 @@ class WorkerFS extends MemoryFS {
|
|
|
1007
1021
|
writeFile(
|
|
1008
1022
|
filePath: FilePath,
|
|
1009
1023
|
contents: Buffer | string,
|
|
1010
|
-
options
|
|
1024
|
+
options?: FileOptions | null,
|
|
1011
1025
|
): Promise<void> {
|
|
1012
1026
|
super.writeFile(filePath, contents, options);
|
|
1013
1027
|
let buffer = makeShared(contents);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {FileSystem} from '@atlaspack/types-internal';
|
|
3
2
|
|
|
4
|
-
//
|
|
3
|
+
// @ts-expect-error TS2420
|
|
5
4
|
export class NodeFS implements FileSystem {
|
|
6
5
|
constructor() {
|
|
7
6
|
throw new Error("NodeFS isn't available in the browser");
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {ReadStream, Stats} from 'fs';
|
|
3
2
|
import type {Writable} from 'stream';
|
|
4
3
|
import type {
|
|
@@ -13,8 +12,10 @@ import type {
|
|
|
13
12
|
AsyncSubscription,
|
|
14
13
|
} from '@parcel/watcher';
|
|
15
14
|
|
|
15
|
+
// @ts-expect-error TS7016
|
|
16
16
|
import fs from 'graceful-fs';
|
|
17
17
|
import nativeFS from 'fs';
|
|
18
|
+
// @ts-expect-error TS7016
|
|
18
19
|
import ncp from 'ncp';
|
|
19
20
|
import path from 'path';
|
|
20
21
|
import {tmpdir} from 'os';
|
|
@@ -40,7 +41,6 @@ function getWatchmanWatcher(): typeof watcher {
|
|
|
40
41
|
// This is here to trick atlaspack into ignoring this require...
|
|
41
42
|
const packageName = ['@atlaspack', 'watcher-watchman-js'].join('/');
|
|
42
43
|
|
|
43
|
-
// $FlowFixMe
|
|
44
44
|
return require(packageName);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -62,15 +62,18 @@ 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 =
|
|
65
|
+
readdirSync: any = fs.readdirSync as any;
|
|
66
66
|
findAncestorFile: any = isPnP
|
|
67
|
-
?
|
|
67
|
+
? // @ts-expect-error TS7019
|
|
68
|
+
(...args) => searchJS.findAncestorFile(this, ...args)
|
|
68
69
|
: searchNative.findAncestorFile;
|
|
69
70
|
findNodeModule: any = isPnP
|
|
70
|
-
?
|
|
71
|
+
? // @ts-expect-error TS7019
|
|
72
|
+
(...args) => searchJS.findNodeModule(this, ...args)
|
|
71
73
|
: searchNative.findNodeModule;
|
|
72
74
|
findFirstFile: any = isPnP
|
|
73
|
-
?
|
|
75
|
+
? // @ts-expect-error TS7019
|
|
76
|
+
(...args) => searchJS.findFirstFile(this, ...args)
|
|
74
77
|
: searchNative.findFirstFile;
|
|
75
78
|
|
|
76
79
|
watcher(): typeof watcher {
|
|
@@ -79,7 +82,7 @@ export class NodeFS implements FileSystem {
|
|
|
79
82
|
: watcher;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
createWriteStream(filePath: string, options
|
|
85
|
+
createWriteStream(filePath: string, options?: any): Writable {
|
|
83
86
|
// Make createWriteStream atomic
|
|
84
87
|
let tmpFilePath = getTempFilePath(filePath);
|
|
85
88
|
let failed = false;
|
|
@@ -88,7 +91,7 @@ export class NodeFS implements FileSystem {
|
|
|
88
91
|
if (!failed) {
|
|
89
92
|
try {
|
|
90
93
|
await fs.promises.rename(tmpFilePath, filePath);
|
|
91
|
-
} catch (e) {
|
|
94
|
+
} catch (e: any) {
|
|
92
95
|
// This is adapted from fs-write-stream-atomic. Apparently
|
|
93
96
|
// Windows doesn't like renaming when the target already exists.
|
|
94
97
|
if (
|
|
@@ -117,7 +120,9 @@ export class NodeFS implements FileSystem {
|
|
|
117
120
|
...options,
|
|
118
121
|
fs: {
|
|
119
122
|
...fs,
|
|
123
|
+
// @ts-expect-error TS7006
|
|
120
124
|
close: (fd, cb) => {
|
|
125
|
+
// @ts-expect-error TS7006
|
|
121
126
|
fs.close(fd, (err) => {
|
|
122
127
|
if (err) {
|
|
123
128
|
cb(err);
|
|
@@ -136,7 +141,7 @@ export class NodeFS implements FileSystem {
|
|
|
136
141
|
failed = true;
|
|
137
142
|
try {
|
|
138
143
|
fs.unlinkSync(tmpFilePath);
|
|
139
|
-
} catch (_err) {
|
|
144
|
+
} catch (_err: any) {
|
|
140
145
|
// ignore
|
|
141
146
|
}
|
|
142
147
|
});
|
|
@@ -147,7 +152,7 @@ export class NodeFS implements FileSystem {
|
|
|
147
152
|
async writeFile(
|
|
148
153
|
filePath: FilePath,
|
|
149
154
|
contents: Buffer | string,
|
|
150
|
-
options
|
|
155
|
+
options?: FileOptions | null,
|
|
151
156
|
): Promise<void> {
|
|
152
157
|
let tmpFilePath = getTempFilePath(filePath);
|
|
153
158
|
await fs.promises.writeFile(tmpFilePath, contents, options);
|
|
@@ -164,7 +169,7 @@ export class NodeFS implements FileSystem {
|
|
|
164
169
|
async realpath(originalPath: string): Promise<string> {
|
|
165
170
|
try {
|
|
166
171
|
return await realpath(originalPath, 'utf8');
|
|
167
|
-
} catch (e) {
|
|
172
|
+
} catch (e: any) {
|
|
168
173
|
// do nothing
|
|
169
174
|
}
|
|
170
175
|
|
|
@@ -172,14 +177,14 @@ export class NodeFS implements FileSystem {
|
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
exists(filePath: FilePath): Promise<boolean> {
|
|
175
|
-
return new Promise((resolve) => {
|
|
180
|
+
return new Promise((resolve: (result: Promise<never>) => void) => {
|
|
176
181
|
fs.exists(filePath, resolve);
|
|
177
182
|
});
|
|
178
183
|
}
|
|
179
184
|
|
|
180
185
|
watch(
|
|
181
186
|
dir: FilePath,
|
|
182
|
-
fn: (err:
|
|
187
|
+
fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
|
|
183
188
|
opts: WatcherOptions,
|
|
184
189
|
): Promise<AsyncSubscription> {
|
|
185
190
|
return this.watcher().subscribe(dir, fn, opts);
|
|
@@ -224,12 +229,11 @@ export class NodeFS implements FileSystem {
|
|
|
224
229
|
let stat;
|
|
225
230
|
try {
|
|
226
231
|
stat = await this.stat(filePath);
|
|
227
|
-
} catch (err) {
|
|
232
|
+
} catch (err: any) {
|
|
228
233
|
return;
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
if (stat.isDirectory()) {
|
|
232
|
-
// $FlowFixMe
|
|
233
237
|
await nativeFS.promises.rmdir(filePath, {recursive: true});
|
|
234
238
|
} else {
|
|
235
239
|
await nativeFS.promises.unlink(filePath);
|
|
@@ -241,6 +245,7 @@ registerSerializableClass(`${packageJSON.version}:NodeFS`, NodeFS);
|
|
|
241
245
|
|
|
242
246
|
let writeStreamCalls = 0;
|
|
243
247
|
|
|
248
|
+
// @ts-expect-error TS7034
|
|
244
249
|
let threadId;
|
|
245
250
|
try {
|
|
246
251
|
({threadId} = require('worker_threads'));
|
|
@@ -248,10 +253,13 @@ try {
|
|
|
248
253
|
//
|
|
249
254
|
}
|
|
250
255
|
|
|
256
|
+
// @ts-expect-error TS7034
|
|
251
257
|
let useOsTmpDir;
|
|
252
258
|
|
|
253
|
-
function shouldUseOsTmpDir(filePath) {
|
|
259
|
+
function shouldUseOsTmpDir(filePath: FilePath) {
|
|
260
|
+
// @ts-expect-error TS7005
|
|
254
261
|
if (useOsTmpDir != null) {
|
|
262
|
+
// @ts-expect-error TS7005
|
|
255
263
|
return useOsTmpDir;
|
|
256
264
|
}
|
|
257
265
|
try {
|
|
@@ -265,7 +273,7 @@ function shouldUseOsTmpDir(filePath) {
|
|
|
265
273
|
// Check the tmpdir is on the same partition as the target directory.
|
|
266
274
|
// This is required to ensure renaming is an atomic operation.
|
|
267
275
|
useOsTmpDir = tmpDirStats.dev === filePathStats.dev;
|
|
268
|
-
} catch (e) {
|
|
276
|
+
} catch (e: any) {
|
|
269
277
|
// We don't have read/write access to the OS tmp directory
|
|
270
278
|
useOsTmpDir = false;
|
|
271
279
|
}
|
|
@@ -288,6 +296,7 @@ function getTempFilePath(filePath: FilePath) {
|
|
|
288
296
|
tmpFilePath +
|
|
289
297
|
'.' +
|
|
290
298
|
process.pid +
|
|
299
|
+
// @ts-expect-error TS7005
|
|
291
300
|
(threadId != null ? '.' + threadId : '') +
|
|
292
301
|
'.' +
|
|
293
302
|
(writeStreamCalls++).toString(36)
|