@oazmi/superbuild 0.1.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/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts +598 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.js +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts +617 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.js +671 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts +487 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.js +536 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts +266 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.js +318 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts +368 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.js +380 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts +711 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.js +1173 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts +171 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.js +308 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts +10 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.js +10 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts +168 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.js +236 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts +90 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.js +237 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts +213 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.js +363 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts +233 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.js +256 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts +1436 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.js +1730 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts +647 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.js +762 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts +538 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.js +626 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts +734 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.js +764 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts +137 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.js +234 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts +391 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.js +8 -0
- package/esm/deps.d.ts +56 -0
- package/esm/deps.d.ts.map +1 -0
- package/esm/deps.js +37 -0
- package/esm/esbuild/metafile.d.ts +90 -0
- package/esm/esbuild/metafile.d.ts.map +1 -0
- package/esm/esbuild/metafile.js +275 -0
- package/esm/esbuild/native.d.ts +95 -0
- package/esm/esbuild/native.d.ts.map +1 -0
- package/esm/esbuild/native.js +127 -0
- package/esm/esbuild/outputfile.d.ts +86 -0
- package/esm/esbuild/outputfile.d.ts.map +1 -0
- package/esm/esbuild/outputfile.js +221 -0
- package/esm/esbuild/strongtypes.d.ts +90 -0
- package/esm/esbuild/strongtypes.d.ts.map +1 -0
- package/esm/esbuild/strongtypes.js +8 -0
- package/esm/esbuild/typedefs.d.ts +121 -0
- package/esm/esbuild/typedefs.d.ts.map +1 -0
- package/esm/esbuild/typedefs.js +55 -0
- package/esm/esbuild/weaktypes.d.ts +46 -0
- package/esm/esbuild/weaktypes.d.ts.map +1 -0
- package/esm/esbuild/weaktypes.js +8 -0
- package/esm/funcdefs.d.ts +89 -0
- package/esm/funcdefs.d.ts.map +1 -0
- package/esm/funcdefs.js +145 -0
- package/esm/mod.d.ts +4 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +2 -0
- package/esm/package.json +3 -0
- package/esm/plugins/emissions_driver.d.ts +33 -0
- package/esm/plugins/emissions_driver.d.ts.map +1 -0
- package/esm/plugins/emissions_driver.js +260 -0
- package/esm/plugins/long_build.d.ts +138 -0
- package/esm/plugins/long_build.d.ts.map +1 -0
- package/esm/plugins/long_build.js +288 -0
- package/esm/plugins/native_replica.d.ts +48 -0
- package/esm/plugins/native_replica.d.ts.map +1 -0
- package/esm/plugins/native_replica.js +122 -0
- package/esm/super/build.d.ts +53 -0
- package/esm/super/build.d.ts.map +1 -0
- package/esm/super/build.js +39 -0
- package/esm/super/build_context.d.ts +83 -0
- package/esm/super/build_context.d.ts.map +1 -0
- package/esm/super/build_context.js +124 -0
- package/esm/super/mod.d.ts +12 -0
- package/esm/super/mod.d.ts.map +1 -0
- package/esm/super/mod.js +9 -0
- package/esm/super/plugin.d.ts +23 -0
- package/esm/super/plugin.d.ts.map +1 -0
- package/esm/super/plugin.js +31 -0
- package/esm/super/plugin_build.d.ts +38 -0
- package/esm/super/plugin_build.d.ts.map +1 -0
- package/esm/super/plugin_build.js +198 -0
- package/esm/super/typedefs.d.ts +323 -0
- package/esm/super/typedefs.d.ts.map +1 -0
- package/esm/super/typedefs.js +10 -0
- package/esm/typedefs.d.ts +21 -0
- package/esm/typedefs.d.ts.map +1 -0
- package/esm/typedefs.js +5 -0
- package/license.md +37 -0
- package/package.json +88 -0
- package/readme.md +181 -0
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
/** javascript runtime enums. */
|
|
2
|
+
export declare const enum RUNTIME {
|
|
3
|
+
/** deno runtime.
|
|
4
|
+
*
|
|
5
|
+
* since deno also supports `process` for node compatibility, you will want to check for deno runtime before checking for node runtime.
|
|
6
|
+
*/
|
|
7
|
+
DENO = 0,
|
|
8
|
+
/** bunjs runtime.
|
|
9
|
+
*
|
|
10
|
+
* since bun also supports `process` for node compatibility, you will want to check for bun runtime before checking for node runtime.
|
|
11
|
+
*/
|
|
12
|
+
BUN = 1,
|
|
13
|
+
/** nodejs runtime. */
|
|
14
|
+
NODE = 2,
|
|
15
|
+
/** chrome-extension runtime.
|
|
16
|
+
*
|
|
17
|
+
* since the `window` context is also available in chrome extensions, it is better to check for this runtime before checking for client-web-page runtime.
|
|
18
|
+
*/
|
|
19
|
+
CHROMIUM = 3,
|
|
20
|
+
/** firefox (or any non-chromium) extension runtime.
|
|
21
|
+
*
|
|
22
|
+
* since the `window` context is also available in chrome extensions, it is better to check for this runtime before checking for client-web-page runtime.
|
|
23
|
+
*/
|
|
24
|
+
EXTENSION = 4,
|
|
25
|
+
/** web-browser runtime. */
|
|
26
|
+
WEB = 5,
|
|
27
|
+
/** worker-script runtime. */
|
|
28
|
+
WORKER = 6,
|
|
29
|
+
/** the [txiki.js](https://github.com/saghul/txiki.js/) runtime, that's based on quickjs. */
|
|
30
|
+
TXIKI = 7
|
|
31
|
+
}
|
|
32
|
+
/** a map/record of runtime validation functions that determine if the current javascript environment matches a specific runtime.
|
|
33
|
+
*
|
|
34
|
+
* each key represents a runtime type defined by the {@link RUNTIME} enum,
|
|
35
|
+
* and each value is a function that returns a boolean indicating whether your current environment
|
|
36
|
+
* satisfies the global-object requirements of the given {@link RUNTIME}.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts ignore
|
|
40
|
+
* if (currentRuntimeValidationFnMap[RUNTIME.NODE]()) {
|
|
41
|
+
* // execute nodejs-specific logic
|
|
42
|
+
* console.log("current nodejs working directory is:", process.cwd())
|
|
43
|
+
* }
|
|
44
|
+
* if (currentRuntimeValidationFnMap[RUNTIME.DENO]()) {
|
|
45
|
+
* // execute deno-specific logic
|
|
46
|
+
* console.log("current deno working directory is:", Deno.cwd())
|
|
47
|
+
* }
|
|
48
|
+
* if (currentRuntimeValidationFnMap[RUNTIME.WEB]()) {
|
|
49
|
+
* // execute web-specific logic
|
|
50
|
+
* console.log("current webpage's url is:", globalThis.location?.href)
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const currentRuntimeValidationFnMap: Record<RUNTIME, (() => boolean)>;
|
|
55
|
+
/** this array declares the ordering in which your runtime environment is tested against,
|
|
56
|
+
* to {@link identifyCurrentRuntime | automatically identify} the current runtime.
|
|
57
|
+
*
|
|
58
|
+
* modifying this array (or re-ordering it) is useful in situations where you would like to expand support to a new runtime.
|
|
59
|
+
* do note that modifying this array will only affect the output of {@link identifyCurrentRuntime}, and nothing else.
|
|
60
|
+
*/
|
|
61
|
+
export declare const currentRuntimeIdentificationOrdering: Array<RUNTIME>;
|
|
62
|
+
/** identifies the current javascript runtime environment as a {@link RUNTIME} enum.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
67
|
+
*
|
|
68
|
+
* assertEquals(identifyCurrentRuntime(), RUNTIME.DENO)
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare const identifyCurrentRuntime: () => RUNTIME;
|
|
72
|
+
/** get the global-runtime-object of the given javascript environment {@link RUNTIME} enum.
|
|
73
|
+
*
|
|
74
|
+
* > [!note]
|
|
75
|
+
* > if you acquire the global-runtime-object of an environment that is not supported by your actual current environment,
|
|
76
|
+
* > then the returned value will be `undefined`.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
81
|
+
* import process from "node:process" // this works in deno 2.0
|
|
82
|
+
*
|
|
83
|
+
* assertEquals(getRuntime(RUNTIME.DENO), Deno)
|
|
84
|
+
* assertEquals(getRuntime(RUNTIME.NODE), process)
|
|
85
|
+
* assertEquals(getRuntime(identifyCurrentRuntime()), Deno)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare const getRuntime: (runtime_enum: RUNTIME) => any;
|
|
89
|
+
/** retrieves the current working directory or URL based on the specified {@link RUNTIME} enum.
|
|
90
|
+
*
|
|
91
|
+
* > [!note]
|
|
92
|
+
* > - the returned directory path may or may not end in a trailing slash.
|
|
93
|
+
* > this is intentional, as it is possible for the path to actually point towards a file.
|
|
94
|
+
* > (such as in the case of `chrome.runtime.getURL("")`)
|
|
95
|
+
* > - however, the returned path will always use posix separators (only forward slashes, no windows backslashes).
|
|
96
|
+
* > - if you try to query the working directory of a runtime enum that your current environment does not support,
|
|
97
|
+
* > then an error will be thrown, because you'll be accessing an `undefined` object.
|
|
98
|
+
*
|
|
99
|
+
* depending on the provided `runtime_enum`, the current working directory is defined as the following:
|
|
100
|
+
* - for `DENO`, `BUN`, and `NODE`: the result will be that of the runtime's `cwd()` method.
|
|
101
|
+
* - for `CHROMIUM` and `EXTENSION`: the result will be the url string obtained from `runtime.getURL("")`.
|
|
102
|
+
* - for `WEB` and `WORKER`: a url string will be returned that will vary based on the `current_path` flag (`true` by default):
|
|
103
|
+
* - if `current_path == false`: `location.origin` will be returned (i.e. the root of your webpage, which is your domain-name + subdomain-name).
|
|
104
|
+
* - if `current_path == true`: the directory path of `location.href` will be returned.
|
|
105
|
+
*
|
|
106
|
+
* @param runtime_enum the runtime enum indicating which runtime's working-directory/url-path to retrieve.
|
|
107
|
+
* @param current_path a boolean flag that, when true, returns the full `href` url of the runtime, rather than the root `origin`. defaults to `true`.
|
|
108
|
+
* @returns a posix string path of the working-directory/url-path of the specified runtime.
|
|
109
|
+
* @throws an error is thrown if the runtime associated with the provided enum is undefined, or if an invalid enum is provided.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
114
|
+
* import process from "node:process" // this works in deno 2.0
|
|
115
|
+
*
|
|
116
|
+
* assertEquals(getRuntimeCwd(RUNTIME.DENO), getRuntimeCwd(RUNTIME.NODE))
|
|
117
|
+
* assertEquals(getRuntimeCwd(RUNTIME.DENO), Deno.cwd().replaceAll(/\\\\?/g, "/"))
|
|
118
|
+
* assertEquals(getRuntimeCwd(RUNTIME.NODE), process.cwd().replaceAll(/\\\\?/g, "/"))
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare const getRuntimeCwd: (runtime_enum: RUNTIME, current_path?: boolean) => string;
|
|
122
|
+
/** retrieves the value of an environment variable on system runtimes
|
|
123
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
124
|
+
* otherwise an error gets thrown on all other environments, since they do not support environment variables.
|
|
125
|
+
*
|
|
126
|
+
* > [!tip]
|
|
127
|
+
* > - environment variables are case-insensitive.
|
|
128
|
+
* > - you will probably want to normalize path variables to posix path via {@link pathToPosixPath}.
|
|
129
|
+
* > - if `env_var = ""` (an empty string) then `undefined` will always be returned on system-runtime environments.
|
|
130
|
+
*
|
|
131
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for querying the environment variable.
|
|
132
|
+
* @param env_var the name of the environment variable to fetch.
|
|
133
|
+
* @returns the environment variable's value.
|
|
134
|
+
* @throws for js-workers, extensions, and web environments, an error gets thrown, as environment variables are not available.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
139
|
+
*
|
|
140
|
+
* const my_path_env_var = getEnvVariable(identifyCurrentRuntime(), "path")!
|
|
141
|
+
*
|
|
142
|
+
* assertEquals(typeof my_path_env_var, "string")
|
|
143
|
+
* assertEquals(my_path_env_var.length > 0, true)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare const getEnvVariable: (runtime_enum: RUNTIME, env_var: string) => string | undefined;
|
|
147
|
+
/** configuration options for the {@link execShellCommand} function. */
|
|
148
|
+
export interface ExecShellCommandConfig {
|
|
149
|
+
/** cli-arguments to pass to the process.
|
|
150
|
+
*
|
|
151
|
+
* @defaultValue `[]` (empty array)
|
|
152
|
+
*/
|
|
153
|
+
args: string[];
|
|
154
|
+
/** set the working directory of the process.
|
|
155
|
+
*
|
|
156
|
+
* if not specified, the `cwd` of the parent process is inherited.
|
|
157
|
+
*
|
|
158
|
+
* @defaultValue `undefined`
|
|
159
|
+
*/
|
|
160
|
+
cwd?: string | URL | undefined;
|
|
161
|
+
/** set the environment variables of the process.
|
|
162
|
+
*
|
|
163
|
+
* I don't know whether these get appended, or completely clear out the existing environment variables,
|
|
164
|
+
* so that the new process only gets a new slate of environment variables that are specified here.
|
|
165
|
+
*
|
|
166
|
+
* @defaultValue `undefined` (i.e. inherit environment variables from the current js-runtime)
|
|
167
|
+
*/
|
|
168
|
+
env?: Record<string, string | undefined>;
|
|
169
|
+
/** provide an optional abort signal to force close the process, by sending a "SIGTERM" os-signal to it.
|
|
170
|
+
*
|
|
171
|
+
* @defaultValue `undefined`
|
|
172
|
+
*/
|
|
173
|
+
signal?: AbortSignal;
|
|
174
|
+
}
|
|
175
|
+
/** the output of the executed shell command. */
|
|
176
|
+
export interface ExecShellCommandResult {
|
|
177
|
+
/** stdout contains the regular things logged into your terminal. */
|
|
178
|
+
stdout: string;
|
|
179
|
+
/** stderr contains the errors logged into your terminal.
|
|
180
|
+
* if this string is non-empty, it may indicate that some error occurred when your shell command/process was executed.
|
|
181
|
+
*/
|
|
182
|
+
stderr: string;
|
|
183
|
+
}
|
|
184
|
+
/** execute a shell/terminal command on system runtimes
|
|
185
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
186
|
+
* otherwise an error gets thrown on all other environments, since they do not support shell command execution.
|
|
187
|
+
*
|
|
188
|
+
* > [!note]
|
|
189
|
+
* > we don't use `Deno.Command` for deno here, because it does not default to your os's native preferred terminal,
|
|
190
|
+
* > and instead you will need to provide one yourself (such as "bash", "cmd", "shell", etc...).
|
|
191
|
+
* > which is why we use `node:child_process` for all three runtimes.
|
|
192
|
+
*
|
|
193
|
+
* TODO: add support for txiki.js. this is non-trivial, because, just like `Deno.command`,
|
|
194
|
+
* the `tjs.spawn` function only spawns processes, and not your default terminal.
|
|
195
|
+
* but that's not the only issue; spawning a terminal on txiki.js also hasn't quite worked consistiently for me.
|
|
196
|
+
* the problem lies in sending `stdin`, while also capturing `stdout` without the echoed `stdin`.
|
|
197
|
+
*
|
|
198
|
+
* TODO: add support for adding custom env-variables to the child shell process.
|
|
199
|
+
*
|
|
200
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for executing the shell command.
|
|
201
|
+
* @param command the shell command to execute.
|
|
202
|
+
* @param config optional configuration to apply onto the shell child-process.
|
|
203
|
+
* @returns a promise that is resolved when the child process that executed the command has closed.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { assertEquals, assertStringIncludes } from "jsr:@std/assert"
|
|
208
|
+
*
|
|
209
|
+
* {
|
|
210
|
+
* const { stdout, stderr } = await execShellCommand(identifyCurrentRuntime(), "echo Hello World!")
|
|
211
|
+
* assertStringIncludes(stdout, "Hello World!")
|
|
212
|
+
* assertEquals(stderr, "")
|
|
213
|
+
* }
|
|
214
|
+
*
|
|
215
|
+
* {
|
|
216
|
+
* const { stdout, stderr } = await execShellCommand(identifyCurrentRuntime(), "echo", { args: ["Hello", "World!"] })
|
|
217
|
+
* assertStringIncludes(stdout, "Hello World!")
|
|
218
|
+
* assertEquals(stderr, "")
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export declare const execShellCommand: (runtime_enum: RUNTIME, command: string, config?: Partial<ExecShellCommandConfig>) => Promise<ExecShellCommandResult>;
|
|
223
|
+
/** configuration options for the {@link spawnCommand} function. */
|
|
224
|
+
export interface SpawnCommandConfig extends ExecShellCommandConfig {
|
|
225
|
+
/** specify if the newly spawned process should be a child of the current js-runtime process.
|
|
226
|
+
*
|
|
227
|
+
* in theory, this would allow the spawned process to exist after the current process has exited.
|
|
228
|
+
* however, since we listen to the `stdout` and `stderr`s (i.e. pipe them), the current js-runtime will not exit,
|
|
229
|
+
* unless you provide an abort {@link signal} and trigger it once you're done with your js shenanigans.
|
|
230
|
+
*
|
|
231
|
+
* moreove, this option is not available for the `txiki.js` runtime.
|
|
232
|
+
*
|
|
233
|
+
* TODO: actually, I'm feeling too lazy to implement the logic for allowing the js-runtime to abort when {@link signal} is triggered,
|
|
234
|
+
* while allowing the spawned process to outlive (i.e. we shouldn't be closing it ourselves when the abort signal is fired).
|
|
235
|
+
*/
|
|
236
|
+
detached?: boolean;
|
|
237
|
+
}
|
|
238
|
+
/** the `stdout` and `stderr` outputs of the executed process, in binary format. */
|
|
239
|
+
export interface SpawnCommandResult {
|
|
240
|
+
/** stdout contains the regular things logged into your terminal. */
|
|
241
|
+
stdout: Uint8Array<ArrayBuffer>;
|
|
242
|
+
/** stderr contains the errors logged into your terminal.
|
|
243
|
+
* if this string is non-empty, it may indicate that some error occurred when your shell command/process was executed.
|
|
244
|
+
*/
|
|
245
|
+
stderr: Uint8Array<ArrayBuffer>;
|
|
246
|
+
}
|
|
247
|
+
/** execute an executable process (such as `deno`, `node`, `winget`, `apt`, `curl`, `cmd`, `./bin/main.exe`, etc...,
|
|
248
|
+
* but not including shell commands, such as `echo`, `ls`, `cp`, etc...), and then exit it.
|
|
249
|
+
*
|
|
250
|
+
* TODO: in the future, add a `spawnProcess` function which will keep the process alive after executing it,
|
|
251
|
+
* in addition to also permitting it to accept a user's `stdin`.
|
|
252
|
+
*
|
|
253
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for executing/spawning the subprocess.
|
|
254
|
+
* @param process_name the name of the process to spawn.
|
|
255
|
+
* this could be either something in your environment's PATH variable,
|
|
256
|
+
* or an executable in your current directory (which will require you to prepend a leading `"./"` or `"../"` in its path).
|
|
257
|
+
* @param config optional configuration to apply onto the child-process.
|
|
258
|
+
* @returns a promise that is resolved when the spawned child process exits that executed the command has closed.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* import { assertEquals, assertStringIncludes } from "jsr:@std/assert"
|
|
263
|
+
*
|
|
264
|
+
* const toText = (bytes: Uint8Array) => (new TextDecoder().decode(bytes))
|
|
265
|
+
*
|
|
266
|
+
* const runTestWithRuntime = async (runtime_enum: RUNTIME) => {
|
|
267
|
+
* {
|
|
268
|
+
* const { stdout, stderr } = await spawnCommand(runtime_enum, "deno", {
|
|
269
|
+
* args: ["eval", `console.log("child-process says hello!")`],
|
|
270
|
+
* })
|
|
271
|
+
* assertStringIncludes(toText(stdout), "child-process says hello!")
|
|
272
|
+
* assertEquals(toText(stderr), "")
|
|
273
|
+
* }
|
|
274
|
+
*
|
|
275
|
+
* if (Deno.build.os === "windows") {
|
|
276
|
+
* const { stdout, stderr } = await spawnCommand(runtime_enum, "ipconfig")
|
|
277
|
+
* assertStringIncludes(toText(stdout).toLowerCase(), "windows ip configuration")
|
|
278
|
+
* assertEquals(toText(stderr), "")
|
|
279
|
+
* }
|
|
280
|
+
*
|
|
281
|
+
* if (Deno.build.os === "linux" || Deno.build.os === "darwin") {
|
|
282
|
+
* // `echo` is apparently a process, and not a shell utility. (insert surprised pikachu face)
|
|
283
|
+
* const { stdout, stderr } = await spawnCommand(runtime_enum, "echo", { args: ["Hello", "World!"] })
|
|
284
|
+
* assertStringIncludes(toText(stdout), "Hello World!")
|
|
285
|
+
* assertEquals(toText(stderr), "")
|
|
286
|
+
* }
|
|
287
|
+
* }
|
|
288
|
+
*
|
|
289
|
+
* await runTestWithRuntime(identifyCurrentRuntime()) // deno runtime test
|
|
290
|
+
* await runTestWithRuntime(RUNTIME.NODE) // deno with node-compatibility runtime test
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
export declare const spawnCommand: (runtime_enum: RUNTIME, process_name: string, config?: Partial<SpawnCommandConfig>) => Promise<SpawnCommandResult>;
|
|
294
|
+
/** the system's operating system. */
|
|
295
|
+
export type SystemInfoPlatforms = "windows" | "darwin" | "linux" | "android" | "freebsd" | "netbsd" | "openbsd" | "haiku" | "aix" | "illumos" | "sunos" | "solaris";
|
|
296
|
+
/** the system's architecture (i.e. amd64, x86, arm, etc...). */
|
|
297
|
+
export type SystemInfoArch = "x86" | "x64" | "arm" | "arm64" | "mips" | "mips64" | "riscv32" | "riscv64" | "wasm32" | "wasm64" | "loong64" | "ppc64" | "s390x";
|
|
298
|
+
/** get information about the current system. */
|
|
299
|
+
export interface SystemInfo {
|
|
300
|
+
/** the system's operating system. */
|
|
301
|
+
platform: SystemInfoPlatforms;
|
|
302
|
+
/** the version string of the operating system. for instance `"10.0.19045"` for windows 10. */
|
|
303
|
+
/** the system's architecture (i.e. amd64, x86, arm, etc...). */
|
|
304
|
+
arch: SystemInfoArch;
|
|
305
|
+
/** the `globalThis.navigator.userAgent` string.
|
|
306
|
+
*
|
|
307
|
+
* for js-runtimes, it usually looks like: `${runtime_name}/${runtime_version}`. below are some examples:
|
|
308
|
+
* - js-runtimes: `"Node.js/23"`, `"Deno/2.5.6"`, `"Bun/1.3.3"`, `"txiki.js/24.12.0"`
|
|
309
|
+
* - chrome: `"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"`
|
|
310
|
+
* - firefox: `"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0"`
|
|
311
|
+
*/
|
|
312
|
+
userAgent: string;
|
|
313
|
+
}
|
|
314
|
+
/** get information about host system, such as its platform (os), architecture, and user-agent string.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
319
|
+
*
|
|
320
|
+
* const actual_system_info: SystemInfo = {
|
|
321
|
+
* platform: Deno.build.os.toLowerCase() as any,
|
|
322
|
+
* // deno writes the amd64 architecture as "x86_64", so we convert it to "x64" below.
|
|
323
|
+
* arch: Deno.build.arch.toLowerCase().replace("x86_", "x") as any,
|
|
324
|
+
* userAgent: navigator.userAgent,
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* assertEquals(getSystemInfo(RUNTIME.DENO), actual_system_info)
|
|
328
|
+
* assertEquals(getSystemInfo(RUNTIME.NODE), actual_system_info)
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export declare const getSystemInfo: (runtime_enum: RUNTIME) => SystemInfo;
|
|
332
|
+
/** configuration options for the {@link writeTextFile} and {@link writeFile} function. */
|
|
333
|
+
export interface WriteFileConfig {
|
|
334
|
+
/** when set to `true`, the new text will be appended to the file, instead of overwriting the previous contents.
|
|
335
|
+
*
|
|
336
|
+
* @defaultValue `false`
|
|
337
|
+
*/
|
|
338
|
+
append: boolean;
|
|
339
|
+
/** allow the creation of a new file if one does not already exist at the specified path.
|
|
340
|
+
* when set to `false`, and a file does not already exist at the specified path, then an error will be thrown,
|
|
341
|
+
* causing the write operation promise to be rejected.
|
|
342
|
+
*
|
|
343
|
+
* @defaultValue `true`
|
|
344
|
+
*/
|
|
345
|
+
create: boolean;
|
|
346
|
+
/** supply an optional unix r/w/x-permission mode to apply to the file **if** it is a new file.
|
|
347
|
+
* existing files won't have their permission mode changed, and this config option will be ignored.
|
|
348
|
+
*
|
|
349
|
+
* > [!note]
|
|
350
|
+
* > setting file chmod-permissions on windows does nothing!
|
|
351
|
+
* > (is that a limitation of deno? I don't know)
|
|
352
|
+
*
|
|
353
|
+
* - if you're unfamiliar with this, check out this stack-exchange answer: [link](https://unix.stackexchange.com/a/184005).
|
|
354
|
+
* - if you'd like to calculate the permission number, try this online permission calculator: [link](https://chmod-calculator.com/).
|
|
355
|
+
* - REMEMBER: the file permission number is in octal-representation!
|
|
356
|
+
* so for setting an "allow all" permission, which is denoted as "777", you would pass `0o777`.
|
|
357
|
+
*
|
|
358
|
+
* @defaultValue `0o644` (this is an assumption, since that's the linux default) (but node's docs mentions the default to be `0o666`)
|
|
359
|
+
*/
|
|
360
|
+
mode: number | undefined;
|
|
361
|
+
/** provide an optional abort signal to allow the cancellation of the file write operation.
|
|
362
|
+
*
|
|
363
|
+
* if the signal becomes aborted, the write file operation will be stopped and the promise returned will be rejected with an `AbortError`.
|
|
364
|
+
*
|
|
365
|
+
* @defaultValue `undefined`
|
|
366
|
+
*/
|
|
367
|
+
signal?: AbortSignal | undefined;
|
|
368
|
+
}
|
|
369
|
+
/** configuration options for the {@link readTextFile} and {@link readFile} functions. */
|
|
370
|
+
export interface ReadFileConfig {
|
|
371
|
+
/** provide an optional abort signal to allow the cancellation of the file reading operation.
|
|
372
|
+
*
|
|
373
|
+
* if the signal becomes aborted, the read file operation will be stopped and the promise returned will be rejected with an `AbortError`.
|
|
374
|
+
*
|
|
375
|
+
* @defaultValue `undefined`
|
|
376
|
+
*/
|
|
377
|
+
signal?: AbortSignal;
|
|
378
|
+
}
|
|
379
|
+
/** writes text data to a file on supported runtimes
|
|
380
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
381
|
+
* for unsupported runtimes, an error is thrown.
|
|
382
|
+
*
|
|
383
|
+
* TODO: in the future, I would like to create a unified cross-runtime filesystem class under `./crossfs.ts`,
|
|
384
|
+
* which would support read and write operations, along with memory (internal state) of the current working directory,
|
|
385
|
+
* in addition to a path resolver method that will rely on `./pathman.ts`'s `resolvePathFactory` function.
|
|
386
|
+
*
|
|
387
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for writing onto the filesystem.
|
|
388
|
+
* @param file_path the destination file path.
|
|
389
|
+
* @param text the string content to write.
|
|
390
|
+
* @param config provide optional configuration on how the writing should be performed.
|
|
391
|
+
* @throws an error is thrown if an unsupported runtime uses this function,
|
|
392
|
+
* or if `config.create` is `false`, and no pre-existing file resides at the specified `file_path`.
|
|
393
|
+
*/
|
|
394
|
+
export declare const writeTextFile: (runtime_enum: RUNTIME, file_path: string | URL, text: string, config?: Partial<WriteFileConfig>) => Promise<void>;
|
|
395
|
+
/** writes binary/buffer data to a file on supported runtimes
|
|
396
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
397
|
+
* for unsupported runtimes, an error is thrown.
|
|
398
|
+
*
|
|
399
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for writing onto the filesystem.
|
|
400
|
+
* @param file_path the destination file path.
|
|
401
|
+
* @param data the byte/buffer data to write to the file.
|
|
402
|
+
* @param config provide optional configuration on how the writing should be performed.
|
|
403
|
+
* @throws an error is thrown if an unsupported runtime uses this function,
|
|
404
|
+
* or if `config.create` is `false`, and no pre-existing file resides at the specified `file_path`.
|
|
405
|
+
*/
|
|
406
|
+
export declare const writeFile: (runtime_enum: RUNTIME, file_path: string | URL, data: ArrayBufferView, config?: Partial<WriteFileConfig>) => Promise<void>;
|
|
407
|
+
/** reads and returns text data from a file on supported runtimes
|
|
408
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
409
|
+
* for unsupported runtimes, an error is thrown.
|
|
410
|
+
*
|
|
411
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for reading the filesystem.
|
|
412
|
+
* @param file_path the source file path to read from.
|
|
413
|
+
* @param config provide optional configuration on how the reading should be performed.
|
|
414
|
+
* @throws an error is thrown if an unsupported runtime uses this function.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
* import { assertStringIncludes } from "jsr:@std/assert"
|
|
419
|
+
*
|
|
420
|
+
* const my_deno_json = await readTextFile(identifyCurrentRuntime(), new URL(import.meta.resolve("../deno.json")))
|
|
421
|
+
* assertStringIncludes(my_deno_json, `"name": "@oazmi/kitchensink"`)
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
export declare const readTextFile: (runtime_enum: RUNTIME, file_path: string | URL, config?: Partial<ReadFileConfig>) => Promise<string>;
|
|
425
|
+
/** reads and returns binary data from a file on supported runtimes
|
|
426
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
427
|
+
* for unsupported runtimes, an error is thrown.
|
|
428
|
+
*
|
|
429
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for reading the filesystem.
|
|
430
|
+
* @param file_path the source file path to read from.
|
|
431
|
+
* @param config provide optional configuration on how the reading should be performed.
|
|
432
|
+
* @throws an error is thrown if an unsupported runtime uses this function.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* import { assertInstanceOf, assertStringIncludes } from "jsr:@std/assert"
|
|
437
|
+
*
|
|
438
|
+
* const my_deno_json_bytes = await readFile(identifyCurrentRuntime(), new URL(import.meta.resolve("../deno.json")))
|
|
439
|
+
* assertInstanceOf(my_deno_json_bytes, Uint8Array)
|
|
440
|
+
*
|
|
441
|
+
* const my_deno_json = (new TextDecoder()).decode(my_deno_json_bytes)
|
|
442
|
+
* assertStringIncludes(my_deno_json, `"name": "@oazmi/kitchensink"`)
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
export declare const readFile: (runtime_enum: RUNTIME, file_path: string | URL, config?: Partial<ReadFileConfig>) => Promise<Uint8Array>;
|
|
446
|
+
/** provides metadata information about a filesystem entry (file, folder, or a symbolic link).
|
|
447
|
+
* this interface is returned by the {@link statEntry} and {@link lstatEntry} functions.
|
|
448
|
+
*
|
|
449
|
+
* > [!note]
|
|
450
|
+
* > only the fields that are common to windows, linux, and mac systems have been kept,
|
|
451
|
+
* > while the stat fields specific to only a subset of the common platforms have been omitted.
|
|
452
|
+
*/
|
|
453
|
+
export interface FsEntryInfo {
|
|
454
|
+
/** this field is `true` if this info corresponds to a regular file.
|
|
455
|
+
*
|
|
456
|
+
* mutually exclusive with respect to {@link isDirectory} and {@link isSymlink}.
|
|
457
|
+
*/
|
|
458
|
+
isFile: boolean;
|
|
459
|
+
/** this field is `true` if this info corresponds to a regular folder.
|
|
460
|
+
*
|
|
461
|
+
* mutually exclusive with respect to {@link isFile} and {@link isSymlink}.
|
|
462
|
+
*/
|
|
463
|
+
isDirectory: boolean;
|
|
464
|
+
/** this field is `true` if this info corresponds to a symbolic-link (symlink).
|
|
465
|
+
*
|
|
466
|
+
* mutually exclusive with respect to {@link isFile} and {@link isDirectory}.
|
|
467
|
+
*/
|
|
468
|
+
isSymlink: boolean;
|
|
469
|
+
/** the size of the file in bytes. (comes up as `0` for directories) */
|
|
470
|
+
size: number;
|
|
471
|
+
/** the last modification time of the file.
|
|
472
|
+
*
|
|
473
|
+
* this corresponds to the `mtime` field from `stat` on linux and mac, and `ftLastWriteTime` on windows.
|
|
474
|
+
* this may not be available on all platforms.
|
|
475
|
+
*/
|
|
476
|
+
mtime: Date;
|
|
477
|
+
/** the last access time of the file.
|
|
478
|
+
*
|
|
479
|
+
* this corresponds to the `atime` field from `stat` on unix, and `ftLastAccessTime` on windows.
|
|
480
|
+
* this may not be available on all platforms.
|
|
481
|
+
*/
|
|
482
|
+
atime: Date;
|
|
483
|
+
/** the creation time of the file.
|
|
484
|
+
*
|
|
485
|
+
* this corresponds to the `birthtime` field from `stat` on mac/bsd, and `ftCreationTime` on windows.
|
|
486
|
+
* this may not be available on all platforms.
|
|
487
|
+
*/
|
|
488
|
+
birthtime: Date;
|
|
489
|
+
/** the last change time of the file.
|
|
490
|
+
*
|
|
491
|
+
* this corresponds to the `ctime` field from `stat` on mac/bsd, and `ChangeTime` on windows.
|
|
492
|
+
* this may not be available on all platforms.
|
|
493
|
+
*/
|
|
494
|
+
ctime: Date;
|
|
495
|
+
/** id of the device containing the file. */
|
|
496
|
+
dev: number;
|
|
497
|
+
/** the underlying raw `st_mode` bits that contain the standard unix permissions for this file/directory. */
|
|
498
|
+
mode: number;
|
|
499
|
+
}
|
|
500
|
+
/** provides metadata information about a filesystem entry (file, folder) on supported runtimes
|
|
501
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
502
|
+
* any symbolic links encountered at the provided `path` will be followed, and the referenced path will instead be examined.
|
|
503
|
+
*
|
|
504
|
+
* if the provided `path` does not exist on the filesystem, then `undefined` will be returned.
|
|
505
|
+
*
|
|
506
|
+
* > [!note]
|
|
507
|
+
* > only the fields that are common to windows, linux, and mac systems have been kept,
|
|
508
|
+
* > while the stat fields specific to only a subset of the common platforms have been omitted.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* import { assertEquals, assertInstanceOf, assertObjectMatch } from "jsr:@std/assert"
|
|
513
|
+
*
|
|
514
|
+
* const
|
|
515
|
+
* time_fields: (keyof FsEntryInfo)[] = ["mtime", "atime", "birthtime", "ctime"],
|
|
516
|
+
* numeric_fields: (keyof FsEntryInfo)[] = ["size", "dev", "mode"]
|
|
517
|
+
*
|
|
518
|
+
* const my_deno_json_stats = (await statEntry(identifyCurrentRuntime(), new URL(import.meta.resolve("../deno.json"))))!
|
|
519
|
+
*
|
|
520
|
+
* assertObjectMatch(my_deno_json_stats, {
|
|
521
|
+
* isFile: true,
|
|
522
|
+
* isDirectory: false,
|
|
523
|
+
* isSymlink: false,
|
|
524
|
+
* })
|
|
525
|
+
*
|
|
526
|
+
* time_fields.forEach((prop) => {
|
|
527
|
+
* assertInstanceOf(my_deno_json_stats[prop], Date)
|
|
528
|
+
* })
|
|
529
|
+
*
|
|
530
|
+
* numeric_fields.forEach((prop: keyof FsEntryInfo) => {
|
|
531
|
+
* assertEquals(typeof my_deno_json_stats[prop], "number")
|
|
532
|
+
* })
|
|
533
|
+
*
|
|
534
|
+
* // unlike node and deno, non-existing paths do not error, and instead `undefined` is returned.
|
|
535
|
+
* const non_existing_path_stat = await statEntry(identifyCurrentRuntime(), new URL(import.meta.resolve("../hello/world/file.txt")))
|
|
536
|
+
* assertEquals(non_existing_path_stat, undefined)
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
export declare const statEntry: (runtime_enum: RUNTIME, path: string | URL) => Promise<FsEntryInfo | undefined>;
|
|
540
|
+
/** similar to {@link statEntry}, but any symbolic links encountered at the provided `path` will not be followed,
|
|
541
|
+
* and instead you will receive the stats of the symbolic link itself.
|
|
542
|
+
*
|
|
543
|
+
* read the documentation comments of {@link statEntry} for usage details.
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
export declare const lstatEntry: (runtime_enum: RUNTIME, path: string | URL) => Promise<FsEntryInfo | undefined>;
|
|
547
|
+
/** creates a nested directory if it does not already exist. only supported on system runtime
|
|
548
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
549
|
+
*
|
|
550
|
+
* @throws an error is thrown if something other than a folder already existed at the provided path.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* import { assertEquals, assertObjectMatch } from "jsr:@std/assert"
|
|
555
|
+
*
|
|
556
|
+
* const
|
|
557
|
+
* runtime_id = identifyCurrentRuntime(),
|
|
558
|
+
* my_dir = new URL(import.meta.resolve("../temp/a/b/c/")),
|
|
559
|
+
* my_dir2 = new URL(import.meta.resolve("../temp/a/"))
|
|
560
|
+
*
|
|
561
|
+
* await ensureDir(runtime_id, my_dir)
|
|
562
|
+
*
|
|
563
|
+
* // the directory now exists
|
|
564
|
+
* assertObjectMatch((await statEntry(runtime_id, my_dir))!, {
|
|
565
|
+
* isFile: false,
|
|
566
|
+
* isDirectory: true,
|
|
567
|
+
* isSymlink: false,
|
|
568
|
+
* })
|
|
569
|
+
*
|
|
570
|
+
* // deleting the base directory (recursively)
|
|
571
|
+
* assertEquals(await removeEntry(runtime_id, my_dir2, { recursive: true }), true)
|
|
572
|
+
*
|
|
573
|
+
* // the directory no longer exists
|
|
574
|
+
* assertEquals(await statEntry(runtime_id, my_dir), undefined)
|
|
575
|
+
* assertEquals(await statEntry(runtime_id, my_dir2), undefined)
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
export declare const ensureDir: (runtime_enum: RUNTIME, dir_path: string | URL) => Promise<void>;
|
|
579
|
+
/** ensures that the file exists on system-bound runtimes
|
|
580
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
581
|
+
*
|
|
582
|
+
* if the file already exists, this function does nothing.
|
|
583
|
+
* if the parent directories for the file do not exist yet, they are created recursively.
|
|
584
|
+
*
|
|
585
|
+
* @throws an error is thrown if something other than a file already existed at the provided path,
|
|
586
|
+
* or if creating the parent directory had failed.
|
|
587
|
+
*/
|
|
588
|
+
export declare const ensureFile: (runtime_enum: RUNTIME, file_path: string | URL) => Promise<void>;
|
|
589
|
+
/** optional configuration options for deleting a filesystem entry (file, folder or symlink), used by the {@link removeEntry} function.
|
|
590
|
+
*
|
|
591
|
+
* by explicitly specifying one of `isFile`, `isDirectory`, or `isSymlink` fields to be either `true` or `false`,
|
|
592
|
+
* you can control which _type_s of filesystem-entries to delete, and which _type_s to ignore.
|
|
593
|
+
* the type of the entry is first identified via {@link statEntry} (which also tells us if it already exists or not).
|
|
594
|
+
*
|
|
595
|
+
* so, for instance:
|
|
596
|
+
* - if `config.isFile` is set to `true`, but the `path` corresponds to either a symlink or a folder, then they will **not** be deleted.
|
|
597
|
+
* - if `config.isFile` is set to `false`, but the `path` corresponds to a file, then the file will **not** be deleted.
|
|
598
|
+
* - if `config.isFile` is set to `true`, and the `path` corresponds to a file, then the file will **be** deleted.
|
|
599
|
+
* - if `config.isFile` is set to `false`, and the `path` corresponds to either a symlink or a folder, then that entry will **be** deleted.
|
|
600
|
+
*/
|
|
601
|
+
export interface RemoveEntryConfig extends Pick<FsEntryInfo, "isDirectory" | "isFile" | "isSymlink"> {
|
|
602
|
+
/** specify if a non-empty directory can be deleted recursively.
|
|
603
|
+
* without this option enabled, removing a non-empty folder will throw an error.
|
|
604
|
+
*
|
|
605
|
+
* > [!warning]
|
|
606
|
+
* > the `recursive` option is always enabled for {@link RUNTIME.TXIKI | `txiki.js`}.
|
|
607
|
+
* > (at least until I implement some way of scanning for child files)
|
|
608
|
+
*
|
|
609
|
+
* @defaultValue `false` (removing non-empty directories will not work and throw an error)
|
|
610
|
+
*/
|
|
611
|
+
recursive: boolean;
|
|
612
|
+
}
|
|
613
|
+
/** deletes a filesystem-entry (file, folder, symlink) at the provided `path`, on system-bound runtimes
|
|
614
|
+
* (i.e. {@link RUNTIME.DENO}, {@link RUNTIME.BUN}, or {@link RUNTIME.NODE}, {@link RUNTIME.TXIKI}).
|
|
615
|
+
* the return value dictates if anything was deleted.
|
|
616
|
+
*
|
|
617
|
+
* > [!note]
|
|
618
|
+
* > trying to remove a non-existing entry will not throw an error.
|
|
619
|
+
*
|
|
620
|
+
* > [!warning]
|
|
621
|
+
* > the `recursive` option is always enabled for {@link RUNTIME.TXIKI | `txiki.js`}.
|
|
622
|
+
*
|
|
623
|
+
* @param runtime_enum the runtime enum indicating which runtime should be used for reading the filesystem.
|
|
624
|
+
* @param path the path to the filesystem entity that is to be deleted.
|
|
625
|
+
* @param config provide optional configuration on what _type_s of filesystem-entries should be deleted,
|
|
626
|
+
* and if folder type entries should be deleted `recursive`ly (i.e. delete child entries as well).
|
|
627
|
+
* see the {@link RemoveEntryConfig} interface for more details.
|
|
628
|
+
* @returns `true` if an entry (or a folder tree's entries) was deleted, otherwise `false` is returned when nothing is deleted.
|
|
629
|
+
*/
|
|
630
|
+
export declare const removeEntry: (runtime_enum: RUNTIME, path: string | URL, config?: Partial<RemoveEntryConfig>) => Promise<boolean>;
|
|
631
|
+
/** provides information about the nature of a filesystem entry
|
|
632
|
+
* (file, folder, or a symbolic link) scanned by the {@link readDir} function.
|
|
633
|
+
*/
|
|
634
|
+
export interface FsEntryRecord extends Pick<FsEntryInfo, "isDirectory" | "isFile" | "isSymlink"> {
|
|
635
|
+
/** the name of the filesystem entry, **without** any trailing slashes, nor any leading dot-slashes;
|
|
636
|
+
* not even when the entry is a sub-directory (i.e. you will have to check the `isDirectory` flag to distinguish files from folders).
|
|
637
|
+
*
|
|
638
|
+
* all names are all relative to the directory that you scan.
|
|
639
|
+
*/
|
|
640
|
+
name: string;
|
|
641
|
+
}
|
|
642
|
+
/** read a directory's immediate child entries (files, folders, and symbolic links).
|
|
643
|
+
* this operation is not recursive, and so, subdirectories will not be traversed.
|
|
644
|
+
*
|
|
645
|
+
* @throws an error is thrown if the directory does not exist, or if it is a file/symbolic-link.
|
|
646
|
+
*
|
|
647
|
+
* > [!note]
|
|
648
|
+
* > each directory entry's name is stripped off of any trailing slash, and any leading dot-slash.
|
|
649
|
+
* > this means, you will not be able to distinguish files from folders and symbolic links based on their
|
|
650
|
+
* > {@link FsEntryRecord.name | name} alone, and instead, you will have to rely on the `isXYZ` flags.
|
|
651
|
+
*
|
|
652
|
+
* TODO: what about symbolic links? should I follow them until I hit a "real" entry?
|
|
653
|
+
* TODO: should I also give an option for recursive traversal? I think it might lead to more complexity,
|
|
654
|
+
* but at the same time, it'll be faster since we won't have to double check the any subdir `dir_path`'s existence via `statEntry`.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* import { assertEquals, assertObjectMatch } from "jsr:@std/assert"
|
|
659
|
+
*
|
|
660
|
+
* const
|
|
661
|
+
* runtime_id = identifyCurrentRuntime(),
|
|
662
|
+
* base_dir = new URL(import.meta.resolve("../temp/a/")),
|
|
663
|
+
* my_dir = new URL(import.meta.resolve("../temp/a/b/c/")),
|
|
664
|
+
* my_file1 = new URL(import.meta.resolve("../temp/a/b/x.txt")),
|
|
665
|
+
* my_file2 = new URL(import.meta.resolve("../temp/a/y.txt")),
|
|
666
|
+
* my_file3 = new URL(import.meta.resolve("../temp/a/z.txt"))
|
|
667
|
+
*
|
|
668
|
+
* await ensureDir(runtime_id, my_dir)
|
|
669
|
+
* await ensureFile(runtime_id, my_file1)
|
|
670
|
+
* await ensureFile(runtime_id, my_file2)
|
|
671
|
+
* await ensureFile(runtime_id, my_file3)
|
|
672
|
+
*
|
|
673
|
+
* // the directories and files should now exist.
|
|
674
|
+
* // so now, we'll iterate over them.
|
|
675
|
+
* const entries: Record<string, FsEntryRecord> = {}
|
|
676
|
+
* for await (const entry of readDir(runtime_id, base_dir)) {
|
|
677
|
+
* entries[entry.name] = entry
|
|
678
|
+
* }
|
|
679
|
+
*
|
|
680
|
+
* assertEquals(Object.keys(entries).length, 3)
|
|
681
|
+
*
|
|
682
|
+
* assertObjectMatch(entries["b"], {
|
|
683
|
+
* name: "b",
|
|
684
|
+
* isFile: false,
|
|
685
|
+
* isDirectory: true,
|
|
686
|
+
* isSymlink: false,
|
|
687
|
+
* })
|
|
688
|
+
*
|
|
689
|
+
* assertObjectMatch(entries["y.txt"], {
|
|
690
|
+
* name: "y.txt",
|
|
691
|
+
* isFile: true,
|
|
692
|
+
* isDirectory: false,
|
|
693
|
+
* isSymlink: false,
|
|
694
|
+
* })
|
|
695
|
+
*
|
|
696
|
+
* assertObjectMatch(entries["z.txt"], {
|
|
697
|
+
* name: "z.txt",
|
|
698
|
+
* isFile: true,
|
|
699
|
+
* isDirectory: false,
|
|
700
|
+
* isSymlink: false,
|
|
701
|
+
* })
|
|
702
|
+
*
|
|
703
|
+
* // deleting the base directory (recursively)
|
|
704
|
+
* assertEquals(await removeEntry(runtime_id, base_dir, { recursive: true }), true)
|
|
705
|
+
*
|
|
706
|
+
* // the directory no longer exists
|
|
707
|
+
* assertEquals(await statEntry(runtime_id, base_dir), undefined)
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
export declare function readDir(runtime_enum: RUNTIME, dir_path: string | URL): AsyncIterable<FsEntryRecord>;
|
|
711
|
+
//# sourceMappingURL=crossenv.d.ts.map
|