@atlaspack/fs 2.15.16 → 2.15.17-typescript-17c3d1dec.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/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { FilePath, FileSystem, FileOptions, ReaddirOptions, Encoding } from '@atlaspack/types-internal';
|
|
2
|
+
import type { Event, Options as WatcherOptions, AsyncSubscription } from '@parcel/watcher';
|
|
3
|
+
import { Readable, Writable } from 'stream';
|
|
4
|
+
import WorkerFarm, { Handle } from '@atlaspack/workers';
|
|
5
|
+
import EventEmitter from 'events';
|
|
6
|
+
type HandleFunction = (...args: Array<any>) => any;
|
|
7
|
+
type SerializedMemoryFS = {
|
|
8
|
+
id: number;
|
|
9
|
+
handle: any;
|
|
10
|
+
dirs: Map<FilePath, Directory>;
|
|
11
|
+
files: Map<FilePath, File>;
|
|
12
|
+
symlinks: Map<FilePath, FilePath>;
|
|
13
|
+
};
|
|
14
|
+
type WorkerEvent = {
|
|
15
|
+
type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink';
|
|
16
|
+
path: FilePath;
|
|
17
|
+
entry?: Entry;
|
|
18
|
+
target?: FilePath;
|
|
19
|
+
};
|
|
20
|
+
type ResolveFunction = () => unknown;
|
|
21
|
+
export declare class MemoryFS implements FileSystem {
|
|
22
|
+
dirs: Map<FilePath, Directory>;
|
|
23
|
+
files: Map<FilePath, File>;
|
|
24
|
+
symlinks: Map<FilePath, FilePath>;
|
|
25
|
+
watchers: Map<FilePath, Set<Watcher>>;
|
|
26
|
+
events: Array<Event>;
|
|
27
|
+
id: number;
|
|
28
|
+
handle: Handle;
|
|
29
|
+
farm: WorkerFarm;
|
|
30
|
+
_cwd: FilePath;
|
|
31
|
+
_eventQueue: Array<Event>;
|
|
32
|
+
_watcherTimer: number;
|
|
33
|
+
_numWorkerInstances: number;
|
|
34
|
+
_workerHandles: Array<Handle>;
|
|
35
|
+
_workerRegisterResolves: Array<ResolveFunction>;
|
|
36
|
+
_emitter: EventEmitter;
|
|
37
|
+
constructor(workerFarm: WorkerFarm);
|
|
38
|
+
static deserialize(opts: SerializedMemoryFS): MemoryFS | WorkerFS;
|
|
39
|
+
serialize(): SerializedMemoryFS;
|
|
40
|
+
decrementWorkerInstance(): void;
|
|
41
|
+
cwd(): FilePath;
|
|
42
|
+
chdir(dir: FilePath): void;
|
|
43
|
+
_normalizePath(filePath: FilePath, realpath?: boolean): FilePath;
|
|
44
|
+
writeFile(filePath: FilePath, contents: Buffer | string, options?: FileOptions | null): Promise<void>;
|
|
45
|
+
readFile(filePath: FilePath, encoding?: Encoding): Promise<any>;
|
|
46
|
+
readFileSync(filePath: FilePath, encoding?: Encoding): any;
|
|
47
|
+
copyFile(source: FilePath, destination: FilePath): Promise<void>;
|
|
48
|
+
statSync(filePath: FilePath): Stat;
|
|
49
|
+
stat(filePath: FilePath): Promise<Stat>;
|
|
50
|
+
readdirSync(dir: FilePath, opts?: ReaddirOptions): any;
|
|
51
|
+
readdir(dir: FilePath, opts?: ReaddirOptions): Promise<any>;
|
|
52
|
+
unlink(filePath: FilePath): Promise<void>;
|
|
53
|
+
mkdirp(dir: FilePath): Promise<void>;
|
|
54
|
+
rimraf(filePath: FilePath): Promise<void>;
|
|
55
|
+
ncp(source: FilePath, destination: FilePath): Promise<void>;
|
|
56
|
+
createReadStream(filePath: FilePath): ReadStream;
|
|
57
|
+
createWriteStream(filePath: FilePath, options?: FileOptions | null): WriteStream;
|
|
58
|
+
realpathSync(filePath: FilePath): FilePath;
|
|
59
|
+
realpath(filePath: FilePath): Promise<FilePath>;
|
|
60
|
+
symlink(target: FilePath, path: FilePath): Promise<void>;
|
|
61
|
+
existsSync(filePath: FilePath): boolean;
|
|
62
|
+
exists(filePath: FilePath): Promise<boolean>;
|
|
63
|
+
_triggerEvent(event: Event): void;
|
|
64
|
+
_registerWorker(handle: Handle): void;
|
|
65
|
+
_sendWorkerEvent(event: WorkerEvent): Promise<void>;
|
|
66
|
+
watch(dir: FilePath, fn: (err: Error | null | undefined, events: Array<Event>) => unknown, opts: WatcherOptions): Promise<AsyncSubscription>;
|
|
67
|
+
getEventsSince(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<Array<Event>>;
|
|
68
|
+
writeSnapshot(dir: FilePath, snapshot: FilePath): Promise<void>;
|
|
69
|
+
findAncestorFile(fileNames: Array<string>, fromDir: FilePath, root: FilePath): FilePath | null | undefined;
|
|
70
|
+
findNodeModule(moduleName: string, fromDir: FilePath): FilePath | null | undefined;
|
|
71
|
+
findFirstFile(filePaths: Array<FilePath>): FilePath | null | undefined;
|
|
72
|
+
}
|
|
73
|
+
declare class Watcher {
|
|
74
|
+
fn: (err: Error | null | undefined, events: Array<Event>) => unknown;
|
|
75
|
+
options: WatcherOptions;
|
|
76
|
+
constructor(fn: (err: Error | null | undefined, events: Array<Event>) => unknown, options: WatcherOptions);
|
|
77
|
+
trigger(events: Array<Event>): void;
|
|
78
|
+
}
|
|
79
|
+
export declare class FSError extends Error {
|
|
80
|
+
code: string;
|
|
81
|
+
path: FilePath;
|
|
82
|
+
constructor(code: string, path: FilePath, message: string);
|
|
83
|
+
}
|
|
84
|
+
declare class ReadStream extends Readable {
|
|
85
|
+
fs: FileSystem;
|
|
86
|
+
filePath: FilePath;
|
|
87
|
+
reading: boolean;
|
|
88
|
+
bytesRead: number;
|
|
89
|
+
constructor(fs: FileSystem, filePath: FilePath);
|
|
90
|
+
_read(): void;
|
|
91
|
+
}
|
|
92
|
+
declare class WriteStream extends Writable {
|
|
93
|
+
fs: FileSystem;
|
|
94
|
+
filePath: FilePath;
|
|
95
|
+
options: FileOptions | null | undefined;
|
|
96
|
+
buffer: Buffer;
|
|
97
|
+
constructor(fs: FileSystem, filePath: FilePath, options?: FileOptions | null);
|
|
98
|
+
_write(chunk: Buffer | string, encoding: any, callback: (error?: Error) => void): void;
|
|
99
|
+
_final(callback: (error?: Error) => void): void;
|
|
100
|
+
}
|
|
101
|
+
declare class Entry {
|
|
102
|
+
mode: number;
|
|
103
|
+
atime: number;
|
|
104
|
+
mtime: number;
|
|
105
|
+
ctime: number;
|
|
106
|
+
birthtime: number;
|
|
107
|
+
constructor(mode: number);
|
|
108
|
+
access(): void;
|
|
109
|
+
modify(mode: number): void;
|
|
110
|
+
getSize(): number;
|
|
111
|
+
stat(): Stat;
|
|
112
|
+
}
|
|
113
|
+
declare class Stat {
|
|
114
|
+
dev: number;
|
|
115
|
+
ino: number;
|
|
116
|
+
mode: number;
|
|
117
|
+
nlink: number;
|
|
118
|
+
uid: number;
|
|
119
|
+
gid: number;
|
|
120
|
+
rdev: number;
|
|
121
|
+
size: number;
|
|
122
|
+
blksize: number;
|
|
123
|
+
blocks: number;
|
|
124
|
+
atimeMs: number;
|
|
125
|
+
mtimeMs: number;
|
|
126
|
+
ctimeMs: number;
|
|
127
|
+
birthtimeMs: number;
|
|
128
|
+
atime: Date;
|
|
129
|
+
mtime: Date;
|
|
130
|
+
ctime: Date;
|
|
131
|
+
birthtime: Date;
|
|
132
|
+
constructor(entry: Entry);
|
|
133
|
+
isFile(): boolean;
|
|
134
|
+
isDirectory(): boolean;
|
|
135
|
+
isBlockDevice(): boolean;
|
|
136
|
+
isCharacterDevice(): boolean;
|
|
137
|
+
isSymbolicLink(): boolean;
|
|
138
|
+
isFIFO(): boolean;
|
|
139
|
+
isSocket(): boolean;
|
|
140
|
+
}
|
|
141
|
+
export declare class File extends Entry {
|
|
142
|
+
buffer: Buffer;
|
|
143
|
+
constructor(buffer: Buffer, mode: number);
|
|
144
|
+
read(): Buffer;
|
|
145
|
+
write(buffer: Buffer, mode: number): void;
|
|
146
|
+
getSize(): number;
|
|
147
|
+
}
|
|
148
|
+
declare class Directory extends Entry {
|
|
149
|
+
constructor();
|
|
150
|
+
}
|
|
151
|
+
export declare function makeShared(contents: Buffer | string): Buffer;
|
|
152
|
+
declare class WorkerFS extends MemoryFS {
|
|
153
|
+
id: number;
|
|
154
|
+
handleFn: HandleFunction;
|
|
155
|
+
constructor(id: number, handle: Handle);
|
|
156
|
+
static deserialize(opts: SerializedMemoryFS): MemoryFS;
|
|
157
|
+
serialize(): SerializedMemoryFS;
|
|
158
|
+
writeFile(filePath: FilePath, contents: Buffer | string, options?: FileOptions | null): Promise<void>;
|
|
159
|
+
unlink(filePath: FilePath): Promise<void>;
|
|
160
|
+
mkdirp(dir: FilePath): Promise<void>;
|
|
161
|
+
rimraf(filePath: FilePath): Promise<void>;
|
|
162
|
+
ncp(source: FilePath, destination: FilePath): Promise<void>;
|
|
163
|
+
symlink(target: FilePath, path: FilePath): Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
export {};
|
package/lib/MemoryFS.js
CHANGED
|
@@ -35,7 +35,7 @@ function _utils() {
|
|
|
35
35
|
}
|
|
36
36
|
var _package = _interopRequireDefault(require("../package.json"));
|
|
37
37
|
function _workers() {
|
|
38
|
-
const data =
|
|
38
|
+
const data = _interopRequireDefault(require("@atlaspack/workers"));
|
|
39
39
|
_workers = function () {
|
|
40
40
|
return data;
|
|
41
41
|
};
|
|
@@ -56,12 +56,14 @@ function _events() {
|
|
|
56
56
|
return data;
|
|
57
57
|
}
|
|
58
58
|
var _find = require("./find");
|
|
59
|
-
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); }
|
|
60
|
-
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; }
|
|
61
59
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
62
60
|
const instances = new Map();
|
|
63
61
|
let id = 0;
|
|
64
62
|
class MemoryFS {
|
|
63
|
+
// @ts-expect-error TS2564
|
|
64
|
+
|
|
65
|
+
// @ts-expect-error TS2564
|
|
66
|
+
|
|
65
67
|
_numWorkerInstances = 0;
|
|
66
68
|
_workerRegisterResolves = [];
|
|
67
69
|
_emitter = new (_events().default)();
|
|
@@ -100,7 +102,7 @@ class MemoryFS {
|
|
|
100
102
|
serialize() {
|
|
101
103
|
if (!this.handle) {
|
|
102
104
|
this.handle = this.farm.createReverseHandle((fn, args) => {
|
|
103
|
-
//
|
|
105
|
+
// @ts-expect-error TS7053
|
|
104
106
|
return this[fn](...args);
|
|
105
107
|
});
|
|
106
108
|
}
|
|
@@ -108,6 +110,7 @@ class MemoryFS {
|
|
|
108
110
|
// If a worker instance already exists, it will decrement this number
|
|
109
111
|
this._numWorkerInstances++;
|
|
110
112
|
return {
|
|
113
|
+
// @ts-expect-error TS2353
|
|
111
114
|
$$raw: false,
|
|
112
115
|
id: this.id,
|
|
113
116
|
handle: this.handle,
|
|
@@ -471,6 +474,8 @@ class MemoryFS {
|
|
|
471
474
|
// Batch events
|
|
472
475
|
this._eventQueue.push(event);
|
|
473
476
|
clearTimeout(this._watcherTimer);
|
|
477
|
+
|
|
478
|
+
// @ts-expect-error TS2322
|
|
474
479
|
this._watcherTimer = setTimeout(() => {
|
|
475
480
|
let events = this._eventQueue;
|
|
476
481
|
this._eventQueue = [];
|
|
@@ -496,7 +501,9 @@ class MemoryFS {
|
|
|
496
501
|
async _sendWorkerEvent(event) {
|
|
497
502
|
// Wait for worker instances to register their handles
|
|
498
503
|
while (this._workerHandles.length < this._numWorkerInstances) {
|
|
499
|
-
await new Promise(resolve =>
|
|
504
|
+
await new Promise(resolve =>
|
|
505
|
+
// @ts-expect-error TS2345
|
|
506
|
+
this._workerRegisterResolves.push(resolve));
|
|
500
507
|
}
|
|
501
508
|
await Promise.all(this._workerHandles.map(workerHandle => this.farm.workerApi.runHandle(workerHandle, [event])));
|
|
502
509
|
}
|
|
@@ -610,7 +617,9 @@ class WriteStream extends _stream().Writable {
|
|
|
610
617
|
callback();
|
|
611
618
|
}
|
|
612
619
|
_final(callback) {
|
|
613
|
-
this.fs.writeFile(this.filePath, this.buffer, this.options)
|
|
620
|
+
this.fs.writeFile(this.filePath, this.buffer, this.options)
|
|
621
|
+
// @ts-expect-error TS2345
|
|
622
|
+
.then(callback).catch(callback);
|
|
614
623
|
}
|
|
615
624
|
}
|
|
616
625
|
const S_IFREG = 0o100000;
|
|
@@ -743,7 +752,7 @@ function makeShared(contents) {
|
|
|
743
752
|
return contents;
|
|
744
753
|
}
|
|
745
754
|
let contentsBuffer = contents;
|
|
746
|
-
//
|
|
755
|
+
// @ts-expect-error TS2339
|
|
747
756
|
if (process.browser) {
|
|
748
757
|
// For the polyfilled buffer module, it's faster to always convert once so that the subsequent
|
|
749
758
|
// operations are fast (.byteLength and using .set instead of .write)
|
|
@@ -764,7 +773,7 @@ function makeShared(contents) {
|
|
|
764
773
|
class WorkerFS extends MemoryFS {
|
|
765
774
|
constructor(id, handle) {
|
|
766
775
|
// TODO Make this not a subclass
|
|
767
|
-
//
|
|
776
|
+
// @ts-expect-error TS2554
|
|
768
777
|
super();
|
|
769
778
|
this.id = id;
|
|
770
779
|
this.handleFn = (methodName, args) => _workers().default.getWorkerApi().runHandle(handle, [methodName, args]);
|
|
@@ -791,7 +800,7 @@ class WorkerFS extends MemoryFS {
|
|
|
791
800
|
return (0, _nullthrows().default)(instances.get(opts.id));
|
|
792
801
|
}
|
|
793
802
|
serialize() {
|
|
794
|
-
//
|
|
803
|
+
// @ts-expect-error TS2739
|
|
795
804
|
return {
|
|
796
805
|
id: this.id
|
|
797
806
|
};
|
package/lib/NodeFS.browser.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.NodeFS = void 0;
|
|
7
|
-
//
|
|
7
|
+
// @ts-expect-error TS2420
|
|
8
8
|
class NodeFS {
|
|
9
9
|
constructor() {
|
|
10
10
|
throw new Error("NodeFS isn't available in the browser");
|
package/lib/NodeFS.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ReadStream, Stats } from 'fs';
|
|
2
|
+
import type { Writable } from 'stream';
|
|
3
|
+
import type { FilePath, Encoding, FileOptions, FileSystem } from '@atlaspack/types-internal';
|
|
4
|
+
import type { Event, Options as WatcherOptions, AsyncSubscription } from '@parcel/watcher';
|
|
5
|
+
import watcher from '@parcel/watcher';
|
|
6
|
+
export declare class NodeFS implements FileSystem {
|
|
7
|
+
readFile: any;
|
|
8
|
+
copyFile: any;
|
|
9
|
+
stat: any;
|
|
10
|
+
readdir: any;
|
|
11
|
+
symlink: any;
|
|
12
|
+
unlink: any;
|
|
13
|
+
utimes: any;
|
|
14
|
+
ncp: any;
|
|
15
|
+
createReadStream: (path: string, options?: any) => ReadStream;
|
|
16
|
+
cwd: () => string;
|
|
17
|
+
chdir: (directory: string) => void;
|
|
18
|
+
statSync: (path: string) => Stats;
|
|
19
|
+
realpathSync: (path: string, cache?: any) => string;
|
|
20
|
+
existsSync: (path: string) => boolean;
|
|
21
|
+
readdirSync: any;
|
|
22
|
+
findAncestorFile: any;
|
|
23
|
+
findNodeModule: any;
|
|
24
|
+
findFirstFile: any;
|
|
25
|
+
watcher(): typeof watcher;
|
|
26
|
+
createWriteStream(filePath: string, options?: any): Writable;
|
|
27
|
+
writeFile(filePath: FilePath, contents: Buffer | string, options?: FileOptions | null): Promise<void>;
|
|
28
|
+
readFileSync(filePath: FilePath, encoding?: Encoding): any;
|
|
29
|
+
realpath(originalPath: string): Promise<string>;
|
|
30
|
+
exists(filePath: FilePath): Promise<boolean>;
|
|
31
|
+
watch(dir: FilePath, fn: (err: Error | null | undefined, events: Array<Event>) => unknown, opts: WatcherOptions): Promise<AsyncSubscription>;
|
|
32
|
+
getEventsSince(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<Array<Event>>;
|
|
33
|
+
writeSnapshot(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<void>;
|
|
34
|
+
static deserialize(): NodeFS;
|
|
35
|
+
serialize(): null;
|
|
36
|
+
mkdirp(filePath: FilePath): Promise<void>;
|
|
37
|
+
rimraf(filePath: FilePath): Promise<void>;
|
|
38
|
+
}
|
package/lib/NodeFS.js
CHANGED
|
@@ -86,6 +86,10 @@ var searchJS = _interopRequireWildcard(require("./find"));
|
|
|
86
86
|
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); }
|
|
87
87
|
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; }
|
|
88
88
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
89
|
+
// @ts-expect-error TS7016
|
|
90
|
+
|
|
91
|
+
// @ts-expect-error TS7016
|
|
92
|
+
|
|
89
93
|
// Most of this can go away once we only support Node 10+, which includes
|
|
90
94
|
// require('fs').promises
|
|
91
95
|
const realpath = (0, _util().promisify)(process.platform === 'win32' ? _gracefulFs().default.realpath : _gracefulFs().default.realpath.native);
|
|
@@ -93,8 +97,6 @@ const isPnP = process.versions.pnp != null;
|
|
|
93
97
|
function getWatchmanWatcher() {
|
|
94
98
|
// This is here to trick atlaspack into ignoring this require...
|
|
95
99
|
const packageName = ['@atlaspack', 'watcher-watchman-js'].join('/');
|
|
96
|
-
|
|
97
|
-
// $FlowFixMe
|
|
98
100
|
return require(packageName);
|
|
99
101
|
}
|
|
100
102
|
class NodeFS {
|
|
@@ -113,9 +115,15 @@ class NodeFS {
|
|
|
113
115
|
realpathSync = process.platform === 'win32' ? _gracefulFs().default.realpathSync : _gracefulFs().default.realpathSync.native;
|
|
114
116
|
existsSync = _gracefulFs().default.existsSync;
|
|
115
117
|
readdirSync = _gracefulFs().default.readdirSync;
|
|
116
|
-
findAncestorFile = isPnP ?
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
findAncestorFile = isPnP ?
|
|
119
|
+
// @ts-expect-error TS7019
|
|
120
|
+
(...args) => searchJS.findAncestorFile(this, ...args) : searchNative().findAncestorFile;
|
|
121
|
+
findNodeModule = isPnP ?
|
|
122
|
+
// @ts-expect-error TS7019
|
|
123
|
+
(...args) => searchJS.findNodeModule(this, ...args) : searchNative().findNodeModule;
|
|
124
|
+
findFirstFile = isPnP ?
|
|
125
|
+
// @ts-expect-error TS7019
|
|
126
|
+
(...args) => searchJS.findFirstFile(this, ...args) : searchNative().findFirstFile;
|
|
119
127
|
watcher() {
|
|
120
128
|
return (0, _featureFlags().getFeatureFlag)('useWatchmanWatcher') ? getWatchmanWatcher() : _watcher().default;
|
|
121
129
|
}
|
|
@@ -144,7 +152,9 @@ class NodeFS {
|
|
|
144
152
|
...options,
|
|
145
153
|
fs: {
|
|
146
154
|
..._gracefulFs().default,
|
|
155
|
+
// @ts-expect-error TS7006
|
|
147
156
|
close: (fd, cb) => {
|
|
157
|
+
// @ts-expect-error TS7006
|
|
148
158
|
_gracefulFs().default.close(fd, err => {
|
|
149
159
|
if (err) {
|
|
150
160
|
cb(err);
|
|
@@ -227,7 +237,6 @@ class NodeFS {
|
|
|
227
237
|
return;
|
|
228
238
|
}
|
|
229
239
|
if (stat.isDirectory()) {
|
|
230
|
-
// $FlowFixMe
|
|
231
240
|
await _fs().default.promises.rmdir(filePath, {
|
|
232
241
|
recursive: true
|
|
233
242
|
});
|
|
@@ -239,6 +248,8 @@ class NodeFS {
|
|
|
239
248
|
exports.NodeFS = NodeFS;
|
|
240
249
|
(0, _buildCache().registerSerializableClass)(`${_package.default.version}:NodeFS`, NodeFS);
|
|
241
250
|
let writeStreamCalls = 0;
|
|
251
|
+
|
|
252
|
+
// @ts-expect-error TS7034
|
|
242
253
|
let threadId;
|
|
243
254
|
try {
|
|
244
255
|
({
|
|
@@ -247,9 +258,13 @@ try {
|
|
|
247
258
|
} catch {
|
|
248
259
|
//
|
|
249
260
|
}
|
|
261
|
+
|
|
262
|
+
// @ts-expect-error TS7034
|
|
250
263
|
let useOsTmpDir;
|
|
251
264
|
function shouldUseOsTmpDir(filePath) {
|
|
265
|
+
// @ts-expect-error TS7005
|
|
252
266
|
if (useOsTmpDir != null) {
|
|
267
|
+
// @ts-expect-error TS7005
|
|
253
268
|
return useOsTmpDir;
|
|
254
269
|
}
|
|
255
270
|
try {
|
|
@@ -277,5 +292,7 @@ function getTempFilePath(filePath) {
|
|
|
277
292
|
if (shouldUseOsTmpDir(filePath)) {
|
|
278
293
|
tmpFilePath = _path().default.join((0, _os().tmpdir)(), _path().default.basename(filePath));
|
|
279
294
|
}
|
|
280
|
-
return tmpFilePath + '.' + process.pid + (
|
|
295
|
+
return tmpFilePath + '.' + process.pid + (
|
|
296
|
+
// @ts-expect-error TS7005
|
|
297
|
+
threadId != null ? '.' + threadId : '') + '.' + (writeStreamCalls++).toString(36);
|
|
281
298
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NodeFS } from './NodeFS';
|
|
2
|
+
import type { FilePath } from '@atlaspack/types-internal';
|
|
3
|
+
import type { Event, Options as WatcherOptions } from '@parcel/watcher';
|
|
4
|
+
export interface NodeVCSAwareFSOptions {
|
|
5
|
+
gitRepoPath: null | FilePath;
|
|
6
|
+
excludePatterns: Array<string>;
|
|
7
|
+
logEventDiff: null | ((watcherEvents: Event[], vcsEvents: Event[]) => void);
|
|
8
|
+
}
|
|
9
|
+
export type SerializedNodeVCSAwareFS = NodeVCSAwareFSOptions;
|
|
10
|
+
export declare class NodeVCSAwareFS extends NodeFS {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options: NodeVCSAwareFSOptions);
|
|
13
|
+
static deserialize(data: SerializedNodeVCSAwareFS): NodeVCSAwareFS;
|
|
14
|
+
serialize(): SerializedNodeVCSAwareFS;
|
|
15
|
+
setGitRepoPath(gitRepoPath: null | FilePath): void;
|
|
16
|
+
getEventsSince(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<Array<Event>>;
|
|
17
|
+
writeSnapshot(dir: FilePath, snapshot: FilePath, opts: WatcherOptions): Promise<void>;
|
|
18
|
+
}
|