1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

Compare commits

...

7 commits

Author SHA1 Message Date
ZYSzys
3ad5069437
Merge e250b23b73 into 0d3d4f5466 2025-01-20 23:27:15 +01:00
David Sherret
0d3d4f5466
fix(install/global): remove importMap field from specified config file (#27744)
Closes https://github.com/denoland/deno/issues/27734
2025-01-20 16:50:34 -05:00
zhangyongsheng.dev__dcar
e250b23b73 fix(ext/node): deno test 2025-01-15 16:52:37 +08:00
zhangyongsheng.dev__dcar
27adf4c797 fix: [build] cleanup! 2025-01-15 16:51:12 +08:00
zhangyongsheng.dev__dcar
485877eaeb fix: [build] cleanup! 2025-01-15 16:51:12 +08:00
zhangyongsheng.dev__dcar
8d195e4d97 fix(ext/node): test 2025-01-15 16:51:12 +08:00
zhangyongsheng.dev__dcar
a75cd2a9d6 fix(ext/node): add FileHandle#datasync & FileHandle#sync 2025-01-15 16:51:12 +08:00
14 changed files with 150 additions and 10 deletions

View file

@ -115,10 +115,16 @@ exec deno {} "$@"
Ok(()) Ok(())
} }
fn get_installer_root() -> Result<PathBuf, io::Error> { fn get_installer_root() -> Result<PathBuf, AnyError> {
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") { if let Some(env_dir) = env::var_os("DENO_INSTALL_ROOT") {
if !env_dir.is_empty() { if !env_dir.is_empty() {
return canonicalize_path_maybe_not_exists(&PathBuf::from(env_dir)); let env_dir = PathBuf::from(env_dir);
return canonicalize_path_maybe_not_exists(&env_dir).with_context(|| {
format!(
"Canonicalizing DENO_INSTALL_ROOT ('{}').",
env_dir.display()
)
});
} }
} }
// Note: on Windows, the $HOME environment variable may be set by users or by // Note: on Windows, the $HOME environment variable may be set by users or by
@ -587,11 +593,22 @@ async fn resolve_shim_data(
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json"); let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
executable_args.push("--config".to_string()); executable_args.push("--config".to_string());
executable_args.push(copy_path.to_str().unwrap().to_string()); executable_args.push(copy_path.to_str().unwrap().to_string());
extra_files.push(( let mut config_text = fs::read_to_string(config_path)
copy_path, .with_context(|| format!("error reading {config_path}"))?;
fs::read_to_string(config_path) // always remove the import map field because when someone specifies `--import-map` we
.with_context(|| format!("error reading {config_path}"))?, // don't want that file to be attempted to be loaded and when they don't specify that
)); // (which is just something we haven't implemented yet)
if let Some(new_text) = remove_import_map_field_from_text(&config_text) {
if flags.import_map_path.is_none() {
log::warn!(
"{} \"importMap\" field in the specified config file we be ignored. Use the --import-map flag instead.",
crate::colors::yellow("Warning"),
);
}
config_text = new_text;
}
extra_files.push((copy_path, config_text));
} else { } else {
executable_args.push("--no-config".to_string()); executable_args.push("--no-config".to_string());
} }
@ -631,6 +648,16 @@ async fn resolve_shim_data(
}) })
} }
fn remove_import_map_field_from_text(config_text: &str) -> Option<String> {
let value =
jsonc_parser::cst::CstRootNode::parse(config_text, &Default::default())
.ok()?;
let root_value = value.object_value()?;
let import_map_value = root_value.get("importMap")?;
import_map_value.remove();
Some(value.to_string())
}
fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf { fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf {
// use a dot file to prevent the file from showing up in some // use a dot file to prevent the file from showing up in some
// users shell auto-complete since this directory is on the PATH // users shell auto-complete since this directory is on the PATH
@ -1585,4 +1612,17 @@ mod tests {
assert!(!file_path.exists()); assert!(!file_path.exists());
} }
} }
#[test]
fn test_remove_import_map_field_from_text() {
assert_eq!(
remove_import_map_field_from_text(
r#"{
"importMap": "./value.json"
}"#,
)
.unwrap(),
"{}"
);
}
} }

View file

@ -5,6 +5,7 @@
import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts"; import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts";
import { FsFile } from "ext:deno_fs/30_fs.js"; import { FsFile } from "ext:deno_fs/30_fs.js";
import { promisify } from "ext:deno_node/internal/util.mjs";
export function fdatasync( export function fdatasync(
fd: number, fd: number,
@ -19,3 +20,7 @@ export function fdatasync(
export function fdatasyncSync(fd: number) { export function fdatasyncSync(fd: number) {
new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncDataSync(); new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncDataSync();
} }
export const fdatasyncPromise = promisify(fdatasync) as (
fd: number,
) => Promise<void>;

View file

@ -5,6 +5,7 @@
import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts"; import { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts";
import { FsFile } from "ext:deno_fs/30_fs.js"; import { FsFile } from "ext:deno_fs/30_fs.js";
import { promisify } from "ext:deno_node/internal/util.mjs";
export function fsync( export function fsync(
fd: number, fd: number,
@ -19,3 +20,5 @@ export function fsync(
export function fsyncSync(fd: number) { export function fsyncSync(fd: number) {
new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncSync(); new FsFile(fd, Symbol.for("Deno.internal.FsFile")).syncSync();
} }
export const fsyncPromise = promisify(fsync) as (fd: number) => Promise<void>;

View file

@ -16,6 +16,8 @@ import {
import { ftruncatePromise } from "ext:deno_node/_fs/_fs_ftruncate.ts"; import { ftruncatePromise } from "ext:deno_node/_fs/_fs_ftruncate.ts";
export type { BigIntStats, Stats } from "ext:deno_node/_fs/_fs_stat.ts"; export type { BigIntStats, Stats } from "ext:deno_node/_fs/_fs_stat.ts";
import { writevPromise, WriteVResult } from "ext:deno_node/_fs/_fs_writev.ts"; import { writevPromise, WriteVResult } from "ext:deno_node/_fs/_fs_writev.ts";
import { fdatasyncPromise } from "ext:deno_node/_fs/_fs_fdatasync.ts";
import { fsyncPromise } from "ext:deno_node/_fs/_fs_fsync.ts";
interface WriteResult { interface WriteResult {
bytesWritten: number; bytesWritten: number;
@ -158,6 +160,14 @@ export class FileHandle extends EventEmitter {
return promises.chmod(this.#path, mode); return promises.chmod(this.#path, mode);
} }
datasync(): Promise<void> {
return fsCall(fdatasyncPromise, this);
}
sync(): Promise<void> {
return fsCall(fsyncPromise, this);
}
utimes( utimes(
atime: number | string | Date, atime: number | string | Date,
mtime: number | string | Date, mtime: number | string | Date,

View file

@ -2,6 +2,7 @@
"ignore": { "ignore": {
"common": ["index.js", "internet.js"], "common": ["index.js", "internet.js"],
"fixtures": [ "fixtures": [
"baz.js",
"child-process-spawn-node.js", "child-process-spawn-node.js",
"echo.js", "echo.js",
"elipses.txt", "elipses.txt",
@ -480,6 +481,7 @@
"test-fs-opendir.js", "test-fs-opendir.js",
"test-fs-promises-exists.js", "test-fs-promises-exists.js",
"test-fs-promises-file-handle-stat.js", "test-fs-promises-file-handle-stat.js",
"test-fs-promises-file-handle-sync.js",
"test-fs-promises-file-handle-write.js", "test-fs-promises-file-handle-write.js",
"test-fs-promises-readfile-empty.js", "test-fs-promises-readfile-empty.js",
"test-fs-promises-readfile-with-fd.js", "test-fs-promises-readfile-with-fd.js",

View file

@ -1,7 +1,7 @@
<!-- deno-fmt-ignore-file --> <!-- deno-fmt-ignore-file -->
# Remaining Node Tests # Remaining Node Tests
1152 tests out of 3681 have been ported from Node 20.11.1 (31.30% ported, 69.22% remaining). 1154 tests out of 3681 have been ported from Node 20.11.1 (31.35% ported, 69.19% remaining).
NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tests/node_compat/runner` dir instead. NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tests/node_compat/runner` dir instead.
@ -673,7 +673,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
- [parallel/test-fs-promises-file-handle-read.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-read.js) - [parallel/test-fs-promises-file-handle-read.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-read.js)
- [parallel/test-fs-promises-file-handle-readFile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-readFile.js) - [parallel/test-fs-promises-file-handle-readFile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-readFile.js)
- [parallel/test-fs-promises-file-handle-stream.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-stream.js) - [parallel/test-fs-promises-file-handle-stream.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-stream.js)
- [parallel/test-fs-promises-file-handle-sync.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-sync.js)
- [parallel/test-fs-promises-file-handle-truncate.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-truncate.js) - [parallel/test-fs-promises-file-handle-truncate.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-truncate.js)
- [parallel/test-fs-promises-file-handle-writeFile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-writeFile.js) - [parallel/test-fs-promises-file-handle-writeFile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-writeFile.js)
- [parallel/test-fs-promises-readfile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-readfile.js) - [parallel/test-fs-promises-readfile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-readfile.js)

View file

@ -0,0 +1,8 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
module.exports = 'perhaps I work';

View file

@ -0,0 +1,42 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { access, copyFile, open } = require('fs').promises;
async function validate() {
tmpdir.refresh();
const dest = tmpdir.resolve('baz.js');
await assert.rejects(
copyFile(fixtures.path('baz.js'), dest, 'r'),
{
code: 'ERR_INVALID_ARG_TYPE',
}
);
await copyFile(fixtures.path('baz.js'), dest);
await assert.rejects(
access(dest, 'r'),
{ code: 'ERR_INVALID_ARG_TYPE', message: /mode/ }
);
await access(dest);
const handle = await open(dest, 'r+');
await handle.datasync();
await handle.sync();
const buf = Buffer.from('hello world');
await handle.write(buf);
const ret = await handle.read(Buffer.alloc(11), 0, 11, 0);
assert.strictEqual(ret.bytesRead, 11);
assert.deepStrictEqual(ret.buffer, buf);
await handle.close();
}
validate();

View file

@ -0,0 +1,5 @@
{
"tempDir": true,
"args": "install -g --root ./folder --config deno.json main.ts --name my-cli",
"output": "install.out"
}

View file

@ -0,0 +1,3 @@
{
"importMap": "./import_map.json"
}

View file

@ -0,0 +1,2 @@
{
}

View file

@ -0,0 +1,3 @@
Warning "importMap" field in the specified config file we be ignored. Use the --import-map flag instead.
✅ Successfully installed my-cli
[WILDCARD]

View file

@ -0,0 +1 @@
console.log(1);

View file

@ -300,3 +300,20 @@ Deno.test({
await fileHandle.close(); await fileHandle.close();
}, },
}); });
Deno.test({
name:
"[node/fs filehandle.sync] Request that all data for the open file descriptor is flushed to the storage device",
async fn() {
const fileHandle = await fs.open(testData, "r+");
await fileHandle.datasync();
await fileHandle.sync();
const buf = Buffer.from("hello world");
await fileHandle.write(buf);
const ret = await fileHandle.read(Buffer.alloc(11), 0, 11, 0);
assertEquals(ret.bytesRead, 11);
assertEquals(ret.buffer, buf);
await fileHandle.close();
},
});