@bolt-foundry/gambit 0.8.3 → 0.8.5-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -2
- package/README.md +79 -16
- package/esm/_dnt.polyfills.d.ts +17 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +122 -0
- package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts +322 -0
- package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.js +105 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts +14 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.js +34 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts +13 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.js +18 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts +10 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.js +17 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts +12 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.js +25 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts +9 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.js +13 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/copy.d.ts +117 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/copy.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/copy.js +313 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts +48 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.js +87 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts +49 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.js +102 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts +47 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.js +90 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts +49 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.js +61 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts +70 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.js +156 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/eol.d.ts +52 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/eol.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/eol.js +67 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/exists.d.ts +218 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/exists.js +271 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts +267 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.js +442 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/mod.d.ts +29 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/mod.js +29 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/move.d.ts +86 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/move.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/move.js +142 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/walk.d.ts +777 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/walk.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.22/walk.js +846 -0
- package/esm/deps/jsr.io/@std/json/1.0.2/types.d.ts +5 -0
- package/esm/deps/jsr.io/@std/json/1.0.2/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/json/1.0.2/types.js +3 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.js +21 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.js +320 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.js +753 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/mod.js +110 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/parse.js +25 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.js +283 -0
- package/esm/gambit/simulator-ui/dist/bundle.js +10639 -4629
- package/esm/gambit/simulator-ui/dist/bundle.js.map +4 -4
- package/esm/mod.d.ts +13 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +8 -2
- package/esm/src/cli_utils.d.ts +1 -0
- package/esm/src/cli_utils.d.ts.map +1 -1
- package/esm/src/cli_utils.js +13 -1
- package/esm/src/default_runtime.d.ts +46 -0
- package/esm/src/default_runtime.d.ts.map +1 -0
- package/esm/src/default_runtime.js +415 -0
- package/esm/src/durable_streams.js +26 -1
- package/esm/src/model_matchers.d.ts +10 -0
- package/esm/src/model_matchers.d.ts.map +1 -0
- package/esm/src/model_matchers.js +26 -0
- package/esm/src/openai_compat.d.ts +12 -1
- package/esm/src/openai_compat.d.ts.map +1 -1
- package/esm/src/openai_compat.js +53 -1
- package/esm/src/project_config.d.ts +47 -0
- package/esm/src/project_config.d.ts.map +1 -0
- package/esm/src/project_config.js +134 -0
- package/esm/src/providers/codex.d.ts +37 -0
- package/esm/src/providers/codex.d.ts.map +1 -0
- package/esm/src/providers/codex.js +810 -0
- package/esm/src/providers/google.d.ts +3 -1
- package/esm/src/providers/google.d.ts.map +1 -1
- package/esm/src/providers/google.js +82 -6
- package/esm/src/providers/ollama.d.ts +3 -1
- package/esm/src/providers/ollama.d.ts.map +1 -1
- package/esm/src/providers/ollama.js +238 -15
- package/esm/src/providers/openrouter.d.ts +6 -2
- package/esm/src/providers/openrouter.d.ts.map +1 -1
- package/esm/src/providers/openrouter.js +260 -23
- package/esm/src/providers/router.d.ts +19 -0
- package/esm/src/providers/router.d.ts.map +1 -0
- package/esm/src/providers/router.js +93 -0
- package/esm/src/server.d.ts +9 -0
- package/esm/src/server.d.ts.map +1 -1
- package/esm/src/server.js +3186 -652
- package/esm/src/server_feedback_grading_routes.d.ts +32 -0
- package/esm/src/server_feedback_grading_routes.d.ts.map +1 -0
- package/esm/src/server_feedback_grading_routes.js +305 -0
- package/esm/src/server_helpers.d.ts +4 -0
- package/esm/src/server_helpers.d.ts.map +1 -0
- package/esm/src/server_helpers.js +46 -0
- package/esm/src/server_session_store.d.ts +87 -0
- package/esm/src/server_session_store.d.ts.map +1 -0
- package/esm/src/server_session_store.js +873 -0
- package/esm/src/server_types.d.ts +110 -0
- package/esm/src/server_types.d.ts.map +1 -0
- package/esm/src/server_types.js +1 -0
- package/esm/src/server_ui_routes.d.ts +33 -0
- package/esm/src/server_ui_routes.d.ts.map +1 -0
- package/esm/src/server_ui_routes.js +135 -0
- package/esm/src/session_artifacts.d.ts +22 -0
- package/esm/src/session_artifacts.d.ts.map +1 -0
- package/esm/src/session_artifacts.js +243 -0
- package/esm/src/trace.d.ts.map +1 -1
- package/esm/src/trace.js +6 -3
- package/esm/src/workspace.d.ts +19 -0
- package/esm/src/workspace.d.ts.map +1 -0
- package/esm/src/workspace.js +164 -0
- package/esm/src/workspace_contract.d.ts +76 -0
- package/esm/src/workspace_contract.d.ts.map +1 -0
- package/esm/src/workspace_contract.js +74 -0
- package/package.json +2 -2
- package/script/_dnt.polyfills.d.ts +17 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +122 -0
- package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts +322 -0
- package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.js +108 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts +14 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.js +71 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts +13 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.js +21 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts +10 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.js +20 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts +12 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.js +28 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts +9 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.js +16 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/copy.d.ts +117 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/copy.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/copy.js +350 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts +48 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.js +124 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts +49 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.js +139 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts +47 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.js +127 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts +49 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.js +98 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts +70 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.js +193 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/eol.d.ts +52 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/eol.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/eol.js +105 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/exists.d.ts +218 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/exists.js +308 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts +267 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.js +479 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/mod.d.ts +29 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/mod.js +45 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/move.d.ts +86 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/move.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/move.js +179 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/walk.d.ts +777 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/walk.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.22/walk.js +883 -0
- package/script/deps/jsr.io/@std/json/1.0.2/types.d.ts +5 -0
- package/script/deps/jsr.io/@std/json/1.0.2/types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/json/1.0.2/types.js +4 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.js +37 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.js +323 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/_parser.js +781 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/mod.js +126 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/parse.js +28 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/toml/1.0.11/stringify.js +286 -0
- package/script/gambit/simulator-ui/dist/bundle.js +10639 -4629
- package/script/gambit/simulator-ui/dist/bundle.js.map +4 -4
- package/script/mod.d.ts +13 -3
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -5
- package/script/src/cli_utils.d.ts +1 -0
- package/script/src/cli_utils.d.ts.map +1 -1
- package/script/src/cli_utils.js +14 -1
- package/script/src/default_runtime.d.ts +46 -0
- package/script/src/default_runtime.d.ts.map +1 -0
- package/script/src/default_runtime.js +452 -0
- package/script/src/durable_streams.js +26 -1
- package/script/src/model_matchers.d.ts +10 -0
- package/script/src/model_matchers.d.ts.map +1 -0
- package/script/src/model_matchers.js +29 -0
- package/script/src/openai_compat.d.ts +12 -1
- package/script/src/openai_compat.d.ts.map +1 -1
- package/script/src/openai_compat.js +85 -0
- package/script/src/project_config.d.ts +47 -0
- package/script/src/project_config.d.ts.map +1 -0
- package/script/src/project_config.js +173 -0
- package/script/src/providers/codex.d.ts +37 -0
- package/script/src/providers/codex.d.ts.map +1 -0
- package/script/src/providers/codex.js +850 -0
- package/script/src/providers/google.d.ts +3 -1
- package/script/src/providers/google.d.ts.map +1 -1
- package/script/src/providers/google.js +82 -6
- package/script/src/providers/ollama.d.ts +3 -1
- package/script/src/providers/ollama.d.ts.map +1 -1
- package/script/src/providers/ollama.js +238 -15
- package/script/src/providers/openrouter.d.ts +6 -2
- package/script/src/providers/openrouter.d.ts.map +1 -1
- package/script/src/providers/openrouter.js +260 -23
- package/script/src/providers/router.d.ts +19 -0
- package/script/src/providers/router.d.ts.map +1 -0
- package/script/src/providers/router.js +96 -0
- package/script/src/server.d.ts +9 -0
- package/script/src/server.d.ts.map +1 -1
- package/script/src/server.js +3193 -659
- package/script/src/server_feedback_grading_routes.d.ts +32 -0
- package/script/src/server_feedback_grading_routes.d.ts.map +1 -0
- package/script/src/server_feedback_grading_routes.js +343 -0
- package/script/src/server_helpers.d.ts +4 -0
- package/script/src/server_helpers.d.ts.map +1 -0
- package/script/src/server_helpers.js +84 -0
- package/script/src/server_session_store.d.ts +87 -0
- package/script/src/server_session_store.d.ts.map +1 -0
- package/script/src/server_session_store.js +910 -0
- package/script/src/server_types.d.ts +110 -0
- package/script/src/server_types.d.ts.map +1 -0
- package/script/src/server_types.js +2 -0
- package/script/src/server_ui_routes.d.ts +33 -0
- package/script/src/server_ui_routes.d.ts.map +1 -0
- package/script/src/server_ui_routes.js +172 -0
- package/script/src/session_artifacts.d.ts +22 -0
- package/script/src/session_artifacts.d.ts.map +1 -0
- package/script/src/session_artifacts.js +279 -0
- package/script/src/trace.d.ts.map +1 -1
- package/script/src/trace.js +6 -3
- package/script/src/workspace.d.ts +19 -0
- package/script/src/workspace.d.ts.map +1 -0
- package/script/src/workspace.js +201 -0
- package/script/src/workspace_contract.d.ts +76 -0
- package/script/src/workspace_contract.d.ts.map +1 -0
- package/script/src/workspace_contract.js +82 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
3
|
+
import { basename } from "../../path/1.1.4/basename.js";
|
|
4
|
+
import { join } from "../../path/1.1.4/join.js";
|
|
5
|
+
import { resolve } from "../../path/1.1.4/resolve.js";
|
|
6
|
+
import { ensureDir, ensureDirSync } from "./ensure_dir.js";
|
|
7
|
+
import { getFileInfoType } from "./_get_file_info_type.js";
|
|
8
|
+
import { toPathString } from "./_to_path_string.js";
|
|
9
|
+
import { isSubdir } from "./_is_subdir.js";
|
|
10
|
+
import { isWindows } from "../../internal/1.0.12/os.js";
|
|
11
|
+
function assertIsDate(date, name) {
|
|
12
|
+
if (date === null) {
|
|
13
|
+
throw new Error(`${name} is unavailable`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function ensureValidCopy(src, dest, options) {
|
|
17
|
+
let destStat;
|
|
18
|
+
try {
|
|
19
|
+
destStat = await dntShim.Deno.lstat(dest);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
if (err instanceof dntShim.Deno.errors.NotFound) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
if (options.isFolder && !destStat.isDirectory) {
|
|
28
|
+
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'`);
|
|
29
|
+
}
|
|
30
|
+
if (!options.overwrite) {
|
|
31
|
+
throw new dntShim.Deno.errors.AlreadyExists(`'${dest}' already exists.`);
|
|
32
|
+
}
|
|
33
|
+
return destStat;
|
|
34
|
+
}
|
|
35
|
+
function ensureValidCopySync(src, dest, options) {
|
|
36
|
+
let destStat;
|
|
37
|
+
try {
|
|
38
|
+
destStat = dntShim.Deno.lstatSync(dest);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err instanceof dntShim.Deno.errors.NotFound) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
if (options.isFolder && !destStat.isDirectory) {
|
|
47
|
+
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'`);
|
|
48
|
+
}
|
|
49
|
+
if (!options.overwrite) {
|
|
50
|
+
throw new dntShim.Deno.errors.AlreadyExists(`'${dest}' already exists`);
|
|
51
|
+
}
|
|
52
|
+
return destStat;
|
|
53
|
+
}
|
|
54
|
+
/* copy file to dest */
|
|
55
|
+
async function copyFile(src, dest, options) {
|
|
56
|
+
await ensureValidCopy(src, dest, options);
|
|
57
|
+
await dntShim.Deno.copyFile(src, dest);
|
|
58
|
+
if (options.preserveTimestamps) {
|
|
59
|
+
const statInfo = await dntShim.Deno.stat(src);
|
|
60
|
+
assertIsDate(statInfo.atime, "statInfo.atime");
|
|
61
|
+
assertIsDate(statInfo.mtime, "statInfo.mtime");
|
|
62
|
+
await dntShim.Deno.utime(dest, statInfo.atime, statInfo.mtime);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/* copy file to dest synchronously */
|
|
66
|
+
function copyFileSync(src, dest, options) {
|
|
67
|
+
ensureValidCopySync(src, dest, options);
|
|
68
|
+
dntShim.Deno.copyFileSync(src, dest);
|
|
69
|
+
if (options.preserveTimestamps) {
|
|
70
|
+
const statInfo = dntShim.Deno.statSync(src);
|
|
71
|
+
assertIsDate(statInfo.atime, "statInfo.atime");
|
|
72
|
+
assertIsDate(statInfo.mtime, "statInfo.mtime");
|
|
73
|
+
dntShim.Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/* copy symlink to dest */
|
|
77
|
+
async function copySymLink(src, dest, options) {
|
|
78
|
+
await ensureValidCopy(src, dest, options);
|
|
79
|
+
const originSrcFilePath = await dntShim.Deno.readLink(src);
|
|
80
|
+
const type = getFileInfoType(await dntShim.Deno.lstat(src));
|
|
81
|
+
if (isWindows) {
|
|
82
|
+
await dntShim.Deno.symlink(originSrcFilePath, dest, {
|
|
83
|
+
type: type === "dir" ? "dir" : "file",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
await dntShim.Deno.symlink(originSrcFilePath, dest);
|
|
88
|
+
}
|
|
89
|
+
if (options.preserveTimestamps) {
|
|
90
|
+
const statInfo = await dntShim.Deno.lstat(src);
|
|
91
|
+
assertIsDate(statInfo.atime, "statInfo.atime");
|
|
92
|
+
assertIsDate(statInfo.mtime, "statInfo.mtime");
|
|
93
|
+
await dntShim.Deno.utime(dest, statInfo.atime, statInfo.mtime);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/* copy symlink to dest synchronously */
|
|
97
|
+
function copySymlinkSync(src, dest, options) {
|
|
98
|
+
ensureValidCopySync(src, dest, options);
|
|
99
|
+
const originSrcFilePath = dntShim.Deno.readLinkSync(src);
|
|
100
|
+
const type = getFileInfoType(dntShim.Deno.lstatSync(src));
|
|
101
|
+
if (isWindows) {
|
|
102
|
+
dntShim.Deno.symlinkSync(originSrcFilePath, dest, {
|
|
103
|
+
type: type === "dir" ? "dir" : "file",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
dntShim.Deno.symlinkSync(originSrcFilePath, dest);
|
|
108
|
+
}
|
|
109
|
+
if (options.preserveTimestamps) {
|
|
110
|
+
const statInfo = dntShim.Deno.lstatSync(src);
|
|
111
|
+
assertIsDate(statInfo.atime, "statInfo.atime");
|
|
112
|
+
assertIsDate(statInfo.mtime, "statInfo.mtime");
|
|
113
|
+
dntShim.Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/* copy folder from src to dest. */
|
|
117
|
+
async function copyDir(src, dest, options) {
|
|
118
|
+
const destStat = await ensureValidCopy(src, dest, {
|
|
119
|
+
...options,
|
|
120
|
+
isFolder: true,
|
|
121
|
+
});
|
|
122
|
+
if (!destStat) {
|
|
123
|
+
await ensureDir(dest);
|
|
124
|
+
}
|
|
125
|
+
if (options.preserveTimestamps) {
|
|
126
|
+
const srcStatInfo = await dntShim.Deno.stat(src);
|
|
127
|
+
assertIsDate(srcStatInfo.atime, "statInfo.atime");
|
|
128
|
+
assertIsDate(srcStatInfo.mtime, "statInfo.mtime");
|
|
129
|
+
await dntShim.Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime);
|
|
130
|
+
}
|
|
131
|
+
src = toPathString(src);
|
|
132
|
+
dest = toPathString(dest);
|
|
133
|
+
const promises = [];
|
|
134
|
+
for await (const entry of dntShim.Deno.readDir(src)) {
|
|
135
|
+
const srcPath = join(src, entry.name);
|
|
136
|
+
const destPath = join(dest, basename(srcPath));
|
|
137
|
+
if (entry.isSymlink) {
|
|
138
|
+
promises.push(copySymLink(srcPath, destPath, options));
|
|
139
|
+
}
|
|
140
|
+
else if (entry.isDirectory) {
|
|
141
|
+
promises.push(copyDir(srcPath, destPath, options));
|
|
142
|
+
}
|
|
143
|
+
else if (entry.isFile) {
|
|
144
|
+
promises.push(copyFile(srcPath, destPath, options));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
await Promise.all(promises);
|
|
148
|
+
}
|
|
149
|
+
/* copy folder from src to dest synchronously */
|
|
150
|
+
function copyDirSync(src, dest, options) {
|
|
151
|
+
const destStat = ensureValidCopySync(src, dest, {
|
|
152
|
+
...options,
|
|
153
|
+
isFolder: true,
|
|
154
|
+
});
|
|
155
|
+
if (!destStat) {
|
|
156
|
+
ensureDirSync(dest);
|
|
157
|
+
}
|
|
158
|
+
if (options.preserveTimestamps) {
|
|
159
|
+
const srcStatInfo = dntShim.Deno.statSync(src);
|
|
160
|
+
assertIsDate(srcStatInfo.atime, "statInfo.atime");
|
|
161
|
+
assertIsDate(srcStatInfo.mtime, "statInfo.mtime");
|
|
162
|
+
dntShim.Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime);
|
|
163
|
+
}
|
|
164
|
+
src = toPathString(src);
|
|
165
|
+
dest = toPathString(dest);
|
|
166
|
+
for (const entry of dntShim.Deno.readDirSync(src)) {
|
|
167
|
+
const srcPath = join(src, entry.name);
|
|
168
|
+
const destPath = join(dest, basename(srcPath));
|
|
169
|
+
if (entry.isSymlink) {
|
|
170
|
+
copySymlinkSync(srcPath, destPath, options);
|
|
171
|
+
}
|
|
172
|
+
else if (entry.isDirectory) {
|
|
173
|
+
copyDirSync(srcPath, destPath, options);
|
|
174
|
+
}
|
|
175
|
+
else if (entry.isFile) {
|
|
176
|
+
copyFileSync(srcPath, destPath, options);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Asynchronously copy a file or directory (along with its contents), like
|
|
182
|
+
* {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=c-cp-command#cp__cp_flagr | cp -r}.
|
|
183
|
+
*
|
|
184
|
+
* Both `src` and `dest` must both be a file or directory.
|
|
185
|
+
*
|
|
186
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
187
|
+
*
|
|
188
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
189
|
+
* for more information on Deno's permissions system.
|
|
190
|
+
*
|
|
191
|
+
* @param src The source file/directory path as a string or URL.
|
|
192
|
+
* @param dest The destination file/directory path as a string or URL.
|
|
193
|
+
* @param options Options for copying.
|
|
194
|
+
*
|
|
195
|
+
* @returns A promise that resolves once the copy operation completes.
|
|
196
|
+
*
|
|
197
|
+
* @example Basic usage
|
|
198
|
+
* ```ts ignore
|
|
199
|
+
* import { copy } from "@std/fs/copy";
|
|
200
|
+
*
|
|
201
|
+
* await copy("./foo", "./bar");
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* This will copy the file or directory at `./foo` to `./bar` without
|
|
205
|
+
* overwriting.
|
|
206
|
+
*
|
|
207
|
+
* @example Overwriting files/directories
|
|
208
|
+
* ```ts ignore
|
|
209
|
+
* import { copy } from "@std/fs/copy";
|
|
210
|
+
*
|
|
211
|
+
* await copy("./foo", "./bar", { overwrite: true });
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* This will copy the file or directory at `./foo` to `./bar` and overwrite
|
|
215
|
+
* any existing files or directories.
|
|
216
|
+
*
|
|
217
|
+
* @example Preserving timestamps
|
|
218
|
+
* ```ts ignore
|
|
219
|
+
* import { copy } from "@std/fs/copy";
|
|
220
|
+
*
|
|
221
|
+
* await copy("./foo", "./bar", { preserveTimestamps: true });
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* This will copy the file or directory at `./foo` to `./bar` and set the
|
|
225
|
+
* last modification and access times to the ones of the original source files.
|
|
226
|
+
*/
|
|
227
|
+
export async function copy(src, dest, options = {}) {
|
|
228
|
+
src = resolve(toPathString(src));
|
|
229
|
+
dest = resolve(toPathString(dest));
|
|
230
|
+
if (src === dest) {
|
|
231
|
+
throw new Error("Source and destination cannot be the same");
|
|
232
|
+
}
|
|
233
|
+
const srcStat = await dntShim.Deno.lstat(src);
|
|
234
|
+
if (srcStat.isDirectory && isSubdir(src, dest)) {
|
|
235
|
+
throw new Error(`Cannot copy '${src}' to a subdirectory of itself: '${dest}'`);
|
|
236
|
+
}
|
|
237
|
+
if (srcStat.isSymlink) {
|
|
238
|
+
await copySymLink(src, dest, options);
|
|
239
|
+
}
|
|
240
|
+
else if (srcStat.isDirectory) {
|
|
241
|
+
await copyDir(src, dest, options);
|
|
242
|
+
}
|
|
243
|
+
else if (srcStat.isFile) {
|
|
244
|
+
await copyFile(src, dest, options);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Synchronously copy a file or directory (along with its contents), like
|
|
249
|
+
* {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=c-cp-command#cp__cp_flagr | cp -r}.
|
|
250
|
+
*
|
|
251
|
+
* Both `src` and `dest` must both be a file or directory.
|
|
252
|
+
*
|
|
253
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
254
|
+
*
|
|
255
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
256
|
+
* for more information on Deno's permissions system.
|
|
257
|
+
*
|
|
258
|
+
* @param src The source file/directory path as a string or URL.
|
|
259
|
+
* @param dest The destination file/directory path as a string or URL.
|
|
260
|
+
* @param options Options for copying.
|
|
261
|
+
*
|
|
262
|
+
* @returns A void value that returns once the copy operation completes.
|
|
263
|
+
*
|
|
264
|
+
* @example Basic usage
|
|
265
|
+
* ```ts ignore
|
|
266
|
+
* import { copySync } from "@std/fs/copy";
|
|
267
|
+
*
|
|
268
|
+
* copySync("./foo", "./bar");
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* This will copy the file or directory at `./foo` to `./bar` without
|
|
272
|
+
* overwriting.
|
|
273
|
+
*
|
|
274
|
+
* @example Overwriting files/directories
|
|
275
|
+
* ```ts ignore
|
|
276
|
+
* import { copySync } from "@std/fs/copy";
|
|
277
|
+
*
|
|
278
|
+
* copySync("./foo", "./bar", { overwrite: true });
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* This will copy the file or directory at `./foo` to `./bar` and overwrite
|
|
282
|
+
* any existing files or directories.
|
|
283
|
+
*
|
|
284
|
+
* @example Preserving timestamps
|
|
285
|
+
* ```ts ignore
|
|
286
|
+
* import { copySync } from "@std/fs/copy";
|
|
287
|
+
*
|
|
288
|
+
* copySync("./foo", "./bar", { preserveTimestamps: true });
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* This will copy the file or directory at `./foo` to `./bar` and set the
|
|
292
|
+
* last modification and access times to the ones of the original source files.
|
|
293
|
+
*/
|
|
294
|
+
export function copySync(src, dest, options = {}) {
|
|
295
|
+
src = resolve(toPathString(src));
|
|
296
|
+
dest = resolve(toPathString(dest));
|
|
297
|
+
if (src === dest) {
|
|
298
|
+
throw new Error("Source and destination cannot be the same");
|
|
299
|
+
}
|
|
300
|
+
const srcStat = dntShim.Deno.lstatSync(src);
|
|
301
|
+
if (srcStat.isDirectory && isSubdir(src, dest)) {
|
|
302
|
+
throw new Error(`Cannot copy '${src}' to a subdirectory of itself: '${dest}'`);
|
|
303
|
+
}
|
|
304
|
+
if (srcStat.isSymlink) {
|
|
305
|
+
copySymlinkSync(src, dest, options);
|
|
306
|
+
}
|
|
307
|
+
else if (srcStat.isDirectory) {
|
|
308
|
+
copyDirSync(src, dest, options);
|
|
309
|
+
}
|
|
310
|
+
else if (srcStat.isFile) {
|
|
311
|
+
copyFileSync(src, dest, options);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously ensures that a directory is empty.
|
|
3
|
+
*
|
|
4
|
+
* If the directory does not exist, it is created. The directory itself is not
|
|
5
|
+
* deleted.
|
|
6
|
+
*
|
|
7
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
10
|
+
* for more information on Deno's permissions system.
|
|
11
|
+
*
|
|
12
|
+
* @param dir The path of the directory to empty, as a string or URL.
|
|
13
|
+
*
|
|
14
|
+
* @returns A void promise that resolves once the directory is empty.
|
|
15
|
+
*
|
|
16
|
+
* @example Usage
|
|
17
|
+
* ```ts ignore
|
|
18
|
+
* import { emptyDir } from "@std/fs/empty-dir";
|
|
19
|
+
*
|
|
20
|
+
* await emptyDir("./foo");
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function emptyDir(dir: string | URL): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Synchronously ensures that a directory is empty deletes the directory
|
|
26
|
+
* contents it is not empty.
|
|
27
|
+
*
|
|
28
|
+
* If the directory does not exist, it is created. The directory itself is not
|
|
29
|
+
* deleted.
|
|
30
|
+
*
|
|
31
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
32
|
+
*
|
|
33
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
34
|
+
* for more information on Deno's permissions system.
|
|
35
|
+
*
|
|
36
|
+
* @param dir The path of the directory to empty, as a string or URL.
|
|
37
|
+
*
|
|
38
|
+
* @returns A void value that returns once the directory is empty.
|
|
39
|
+
*
|
|
40
|
+
* @example Usage
|
|
41
|
+
* ```ts ignore
|
|
42
|
+
* import { emptyDirSync } from "@std/fs/empty-dir";
|
|
43
|
+
*
|
|
44
|
+
* emptyDirSync("./foo");
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function emptyDirSync(dir: string | URL): void;
|
|
48
|
+
//# sourceMappingURL=empty_dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty_dir.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fs/1.0.22/empty_dir.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,iBAkB/C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,QAmB7C"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
3
|
+
import { join } from "../../path/1.1.4/join.js";
|
|
4
|
+
import { toPathString } from "./_to_path_string.js";
|
|
5
|
+
/**
|
|
6
|
+
* Asynchronously ensures that a directory is empty.
|
|
7
|
+
*
|
|
8
|
+
* If the directory does not exist, it is created. The directory itself is not
|
|
9
|
+
* deleted.
|
|
10
|
+
*
|
|
11
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
14
|
+
* for more information on Deno's permissions system.
|
|
15
|
+
*
|
|
16
|
+
* @param dir The path of the directory to empty, as a string or URL.
|
|
17
|
+
*
|
|
18
|
+
* @returns A void promise that resolves once the directory is empty.
|
|
19
|
+
*
|
|
20
|
+
* @example Usage
|
|
21
|
+
* ```ts ignore
|
|
22
|
+
* import { emptyDir } from "@std/fs/empty-dir";
|
|
23
|
+
*
|
|
24
|
+
* await emptyDir("./foo");
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export async function emptyDir(dir) {
|
|
28
|
+
try {
|
|
29
|
+
const items = await Array.fromAsync(dntShim.Deno.readDir(dir));
|
|
30
|
+
await Promise.all(items.map((item) => {
|
|
31
|
+
if (item && item.name) {
|
|
32
|
+
const filepath = join(toPathString(dir), item.name);
|
|
33
|
+
return dntShim.Deno.remove(filepath, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (!(err instanceof dntShim.Deno.errors.NotFound)) {
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
// if not exist. then create it
|
|
42
|
+
await dntShim.Deno.mkdir(dir, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Synchronously ensures that a directory is empty deletes the directory
|
|
47
|
+
* contents it is not empty.
|
|
48
|
+
*
|
|
49
|
+
* If the directory does not exist, it is created. The directory itself is not
|
|
50
|
+
* deleted.
|
|
51
|
+
*
|
|
52
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
55
|
+
* for more information on Deno's permissions system.
|
|
56
|
+
*
|
|
57
|
+
* @param dir The path of the directory to empty, as a string or URL.
|
|
58
|
+
*
|
|
59
|
+
* @returns A void value that returns once the directory is empty.
|
|
60
|
+
*
|
|
61
|
+
* @example Usage
|
|
62
|
+
* ```ts ignore
|
|
63
|
+
* import { emptyDirSync } from "@std/fs/empty-dir";
|
|
64
|
+
*
|
|
65
|
+
* emptyDirSync("./foo");
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function emptyDirSync(dir) {
|
|
69
|
+
try {
|
|
70
|
+
const items = [...dntShim.Deno.readDirSync(dir)];
|
|
71
|
+
// If the directory exists, remove all entries inside it.
|
|
72
|
+
while (items.length) {
|
|
73
|
+
const item = items.shift();
|
|
74
|
+
if (item && item.name) {
|
|
75
|
+
const filepath = join(toPathString(dir), item.name);
|
|
76
|
+
dntShim.Deno.removeSync(filepath, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (!(err instanceof dntShim.Deno.errors.NotFound)) {
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
// if not exist. then create it
|
|
85
|
+
dntShim.Deno.mkdirSync(dir, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously ensures that the directory exists, like
|
|
3
|
+
* {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
|
|
4
|
+
*
|
|
5
|
+
* If the directory already exists, this function does nothing. If the directory
|
|
6
|
+
* does not exist, it is created.
|
|
7
|
+
*
|
|
8
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
11
|
+
* for more information on Deno's permissions system.
|
|
12
|
+
*
|
|
13
|
+
* @param dir The path of the directory to ensure, as a string or URL.
|
|
14
|
+
*
|
|
15
|
+
* @returns A promise that resolves once the directory exists.
|
|
16
|
+
*
|
|
17
|
+
* @example Usage
|
|
18
|
+
* ```ts ignore
|
|
19
|
+
* import { ensureDir } from "@std/fs/ensure-dir";
|
|
20
|
+
*
|
|
21
|
+
* await ensureDir("./bar");
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureDir(dir: string | URL): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Synchronously ensures that the directory exists, like
|
|
27
|
+
* {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
|
|
28
|
+
*
|
|
29
|
+
* If the directory already exists, this function does nothing. If the directory
|
|
30
|
+
* does not exist, it is created.
|
|
31
|
+
*
|
|
32
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
35
|
+
* for more information on Deno's permissions system.
|
|
36
|
+
*
|
|
37
|
+
* @param dir The path of the directory to ensure, as a string or URL.
|
|
38
|
+
*
|
|
39
|
+
* @returns A void value that returns once the directory exists.
|
|
40
|
+
*
|
|
41
|
+
* @example Usage
|
|
42
|
+
* ```ts ignore
|
|
43
|
+
* import { ensureDirSync } from "@std/fs/ensure-dir";
|
|
44
|
+
*
|
|
45
|
+
* ensureDirSync("./bar");
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function ensureDirSync(dir: string | URL): void;
|
|
49
|
+
//# sourceMappingURL=ensure_dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure_dir.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fs/1.0.22/ensure_dir.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,iBAuBhD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,QAuB9C"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
3
|
+
import { getFileInfoType } from "./_get_file_info_type.js";
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronously ensures that the directory exists, like
|
|
6
|
+
* {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
|
|
7
|
+
*
|
|
8
|
+
* If the directory already exists, this function does nothing. If the directory
|
|
9
|
+
* does not exist, it is created.
|
|
10
|
+
*
|
|
11
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
14
|
+
* for more information on Deno's permissions system.
|
|
15
|
+
*
|
|
16
|
+
* @param dir The path of the directory to ensure, as a string or URL.
|
|
17
|
+
*
|
|
18
|
+
* @returns A promise that resolves once the directory exists.
|
|
19
|
+
*
|
|
20
|
+
* @example Usage
|
|
21
|
+
* ```ts ignore
|
|
22
|
+
* import { ensureDir } from "@std/fs/ensure-dir";
|
|
23
|
+
*
|
|
24
|
+
* await ensureDir("./bar");
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export async function ensureDir(dir) {
|
|
28
|
+
try {
|
|
29
|
+
const fileInfo = await dntShim.Deno.stat(dir);
|
|
30
|
+
throwIfNotDirectory(fileInfo);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (!(err instanceof dntShim.Deno.errors.NotFound)) {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// The dir doesn't exist. Create it.
|
|
39
|
+
// This can be racy. So we catch AlreadyExists and check stat again.
|
|
40
|
+
try {
|
|
41
|
+
await dntShim.Deno.mkdir(dir, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
const fileInfo = await dntShim.Deno.stat(dir);
|
|
48
|
+
throwIfNotDirectory(fileInfo);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Synchronously ensures that the directory exists, like
|
|
53
|
+
* {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
|
|
54
|
+
*
|
|
55
|
+
* If the directory already exists, this function does nothing. If the directory
|
|
56
|
+
* does not exist, it is created.
|
|
57
|
+
*
|
|
58
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
61
|
+
* for more information on Deno's permissions system.
|
|
62
|
+
*
|
|
63
|
+
* @param dir The path of the directory to ensure, as a string or URL.
|
|
64
|
+
*
|
|
65
|
+
* @returns A void value that returns once the directory exists.
|
|
66
|
+
*
|
|
67
|
+
* @example Usage
|
|
68
|
+
* ```ts ignore
|
|
69
|
+
* import { ensureDirSync } from "@std/fs/ensure-dir";
|
|
70
|
+
*
|
|
71
|
+
* ensureDirSync("./bar");
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function ensureDirSync(dir) {
|
|
75
|
+
try {
|
|
76
|
+
const fileInfo = dntShim.Deno.statSync(dir);
|
|
77
|
+
throwIfNotDirectory(fileInfo);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (!(err instanceof dntShim.Deno.errors.NotFound)) {
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// The dir doesn't exist. Create it.
|
|
86
|
+
// This can be racy. So we catch AlreadyExists and check stat again.
|
|
87
|
+
try {
|
|
88
|
+
dntShim.Deno.mkdirSync(dir, { recursive: true });
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
const fileInfo = dntShim.Deno.statSync(dir);
|
|
95
|
+
throwIfNotDirectory(fileInfo);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function throwIfNotDirectory(fileInfo) {
|
|
99
|
+
if (!fileInfo.isDirectory) {
|
|
100
|
+
throw new Error(`Failed to ensure directory exists: expected 'dir', got '${getFileInfoType(fileInfo)}'`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously ensures that the file exists.
|
|
3
|
+
*
|
|
4
|
+
* If the file already exists, this function does nothing. If the parent
|
|
5
|
+
* directories for the file do not exist, they are created.
|
|
6
|
+
*
|
|
7
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
10
|
+
* for more information on Deno's permissions system.
|
|
11
|
+
*
|
|
12
|
+
* @param filePath The path of the file to ensure, as a string or URL.
|
|
13
|
+
*
|
|
14
|
+
* @returns A void promise that resolves once the file exists.
|
|
15
|
+
*
|
|
16
|
+
* @example Usage
|
|
17
|
+
* ```ts ignore
|
|
18
|
+
* import { ensureFile } from "@std/fs/ensure-file";
|
|
19
|
+
*
|
|
20
|
+
* await ensureFile("./folder/targetFile.dat");
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function ensureFile(filePath: string | URL): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Synchronously ensures that the file exists.
|
|
26
|
+
*
|
|
27
|
+
* If the file already exists, this function does nothing. If the parent
|
|
28
|
+
* directories for the file do not exist, they are created.
|
|
29
|
+
*
|
|
30
|
+
* Requires `--allow-read` and `--allow-write` permissions.
|
|
31
|
+
*
|
|
32
|
+
* @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
|
|
33
|
+
* for more information on Deno's permissions system.
|
|
34
|
+
*
|
|
35
|
+
* @param filePath The path of the file to ensure, as a string or URL.
|
|
36
|
+
*
|
|
37
|
+
* @returns A void value that returns once the file exists.
|
|
38
|
+
*
|
|
39
|
+
* @example Usage
|
|
40
|
+
* ```ts ignore
|
|
41
|
+
* import { ensureFileSync } from "@std/fs/ensure-file";
|
|
42
|
+
*
|
|
43
|
+
* ensureFileSync("./folder/targetFile.dat");
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function ensureFileSync(filePath: string | URL): void;
|
|
47
|
+
//# sourceMappingURL=ensure_file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure_file.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fs/1.0.22/ensure_file.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBtE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAsB3D"}
|