mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat: remove --unstable flag requirement for npm: specifiers (#16473)
This commit makes "npm:" specifiers not require "--unstable" flag. At the moment some APIs used by Node polyfills still require "--unstable" which will be addressed in follow up PRs.
This commit is contained in:
parent
fd32f75da9
commit
53e974b276
10 changed files with 58 additions and 152 deletions
|
@ -276,8 +276,7 @@ impl Inner {
|
||||||
cache_setting,
|
cache_setting,
|
||||||
progress_bar,
|
progress_bar,
|
||||||
);
|
);
|
||||||
let npm_resolver =
|
let npm_resolver = NpmPackageResolver::new(npm_cache, api, false, None);
|
||||||
NpmPackageResolver::new(npm_cache, api, true, false, None);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
assets,
|
assets,
|
||||||
|
|
|
@ -68,7 +68,6 @@ impl NpmProcessState {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct NpmPackageResolver {
|
pub struct NpmPackageResolver {
|
||||||
unstable: bool,
|
|
||||||
no_npm: bool,
|
no_npm: bool,
|
||||||
inner: Arc<dyn InnerNpmPackageResolver>,
|
inner: Arc<dyn InnerNpmPackageResolver>,
|
||||||
local_node_modules_path: Option<PathBuf>,
|
local_node_modules_path: Option<PathBuf>,
|
||||||
|
@ -80,7 +79,6 @@ pub struct NpmPackageResolver {
|
||||||
impl std::fmt::Debug for NpmPackageResolver {
|
impl std::fmt::Debug for NpmPackageResolver {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("NpmPackageResolver")
|
f.debug_struct("NpmPackageResolver")
|
||||||
.field("unstable", &self.unstable)
|
|
||||||
.field("no_npm", &self.no_npm)
|
.field("no_npm", &self.no_npm)
|
||||||
.field("inner", &"<omitted>")
|
.field("inner", &"<omitted>")
|
||||||
.field("local_node_modules_path", &self.local_node_modules_path)
|
.field("local_node_modules_path", &self.local_node_modules_path)
|
||||||
|
@ -92,14 +90,12 @@ impl NpmPackageResolver {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
cache: NpmCache,
|
cache: NpmCache,
|
||||||
api: RealNpmRegistryApi,
|
api: RealNpmRegistryApi,
|
||||||
unstable: bool,
|
|
||||||
no_npm: bool,
|
no_npm: bool,
|
||||||
local_node_modules_path: Option<PathBuf>,
|
local_node_modules_path: Option<PathBuf>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_with_maybe_snapshot(
|
Self::new_with_maybe_snapshot(
|
||||||
cache,
|
cache,
|
||||||
api,
|
api,
|
||||||
unstable,
|
|
||||||
no_npm,
|
no_npm,
|
||||||
local_node_modules_path,
|
local_node_modules_path,
|
||||||
None,
|
None,
|
||||||
|
@ -142,7 +138,6 @@ impl NpmPackageResolver {
|
||||||
fn new_with_maybe_snapshot(
|
fn new_with_maybe_snapshot(
|
||||||
cache: NpmCache,
|
cache: NpmCache,
|
||||||
api: RealNpmRegistryApi,
|
api: RealNpmRegistryApi,
|
||||||
unstable: bool,
|
|
||||||
no_npm: bool,
|
no_npm: bool,
|
||||||
local_node_modules_path: Option<PathBuf>,
|
local_node_modules_path: Option<PathBuf>,
|
||||||
initial_snapshot: Option<NpmResolutionSnapshot>,
|
initial_snapshot: Option<NpmResolutionSnapshot>,
|
||||||
|
@ -170,7 +165,6 @@ impl NpmPackageResolver {
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
unstable,
|
|
||||||
no_npm,
|
no_npm,
|
||||||
inner,
|
inner,
|
||||||
local_node_modules_path,
|
local_node_modules_path,
|
||||||
|
@ -250,12 +244,6 @@ impl NpmPackageResolver {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.unstable {
|
|
||||||
bail!(
|
|
||||||
"Unstable use of npm specifiers. The --unstable flag must be provided."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.no_npm {
|
if self.no_npm {
|
||||||
let fmt_reqs = packages
|
let fmt_reqs = packages
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -315,7 +303,6 @@ impl NpmPackageResolver {
|
||||||
Self::new_with_maybe_snapshot(
|
Self::new_with_maybe_snapshot(
|
||||||
self.cache.clone(),
|
self.cache.clone(),
|
||||||
self.api.clone(),
|
self.api.clone(),
|
||||||
self.unstable,
|
|
||||||
self.no_npm,
|
self.no_npm,
|
||||||
self.local_node_modules_path.clone(),
|
self.local_node_modules_path.clone(),
|
||||||
Some(self.snapshot()),
|
Some(self.snapshot()),
|
||||||
|
|
|
@ -228,9 +228,6 @@ impl ProcState {
|
||||||
let mut npm_resolver = NpmPackageResolver::new(
|
let mut npm_resolver = NpmPackageResolver::new(
|
||||||
npm_cache.clone(),
|
npm_cache.clone(),
|
||||||
api,
|
api,
|
||||||
cli_options.unstable()
|
|
||||||
// don't do the unstable error when in the lsp
|
|
||||||
|| matches!(cli_options.sub_command(), DenoSubcommand::Lsp),
|
|
||||||
cli_options.no_npm(),
|
cli_options.no_npm(),
|
||||||
cli_options
|
cli_options
|
||||||
.resolve_local_node_modules_folder()
|
.resolve_local_node_modules_folder()
|
||||||
|
|
|
@ -8,7 +8,7 @@ use util::http_server;
|
||||||
// NOTE: See how to make test npm packages at ../testdata/npm/README.md
|
// NOTE: See how to make test npm packages at ../testdata/npm/README.md
|
||||||
|
|
||||||
itest!(esm_module {
|
itest!(esm_module {
|
||||||
args: "run --allow-read --allow-env --unstable npm/esm/main.js",
|
args: "run --allow-read --allow-env npm/esm/main.js",
|
||||||
output: "npm/esm/main.out",
|
output: "npm/esm/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -17,7 +17,6 @@ itest!(esm_module {
|
||||||
itest!(esm_module_eval {
|
itest!(esm_module_eval {
|
||||||
args_vec: vec![
|
args_vec: vec![
|
||||||
"eval",
|
"eval",
|
||||||
"--unstable",
|
|
||||||
"import chalk from 'npm:chalk@5'; console.log(chalk.green('chalk esm loads'));",
|
"import chalk from 'npm:chalk@5'; console.log(chalk.green('chalk esm loads'));",
|
||||||
],
|
],
|
||||||
output: "npm/esm/main.out",
|
output: "npm/esm/main.out",
|
||||||
|
@ -40,35 +39,35 @@ itest!(esm_import_cjs_default {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(cjs_with_deps {
|
itest!(cjs_with_deps {
|
||||||
args: "run --allow-read --allow-env --unstable npm/cjs_with_deps/main.js",
|
args: "run --allow-read --allow-env npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main.out",
|
output: "npm/cjs_with_deps/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(cjs_sub_path {
|
itest!(cjs_sub_path {
|
||||||
args: "run --allow-read --unstable npm/cjs_sub_path/main.js",
|
args: "run --allow-read npm/cjs_sub_path/main.js",
|
||||||
output: "npm/cjs_sub_path/main.out",
|
output: "npm/cjs_sub_path/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(cjs_local_global_decls {
|
itest!(cjs_local_global_decls {
|
||||||
args: "run --allow-read --unstable npm/cjs_local_global_decls/main.ts",
|
args: "run --allow-read npm/cjs_local_global_decls/main.ts",
|
||||||
output: "npm/cjs_local_global_decls/main.out",
|
output: "npm/cjs_local_global_decls/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(cjs_reexport_collision {
|
itest!(cjs_reexport_collision {
|
||||||
args: "run --unstable -A --quiet npm/cjs_reexport_collision/main.ts",
|
args: "run -A --quiet npm/cjs_reexport_collision/main.ts",
|
||||||
output: "npm/cjs_reexport_collision/main.out",
|
output: "npm/cjs_reexport_collision/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(cjs_this_in_exports {
|
itest!(cjs_this_in_exports {
|
||||||
args: "run --allow-read --unstable --quiet npm/cjs_this_in_exports/main.js",
|
args: "run --allow-read --quiet npm/cjs_this_in_exports/main.js",
|
||||||
output: "npm/cjs_this_in_exports/main.out",
|
output: "npm/cjs_this_in_exports/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -76,7 +75,7 @@ itest!(cjs_this_in_exports {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(translate_cjs_to_esm {
|
itest!(translate_cjs_to_esm {
|
||||||
args: "run --unstable -A --quiet npm/translate_cjs_to_esm/main.js",
|
args: "run -A --quiet npm/translate_cjs_to_esm/main.js",
|
||||||
output: "npm/translate_cjs_to_esm/main.out",
|
output: "npm/translate_cjs_to_esm/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -90,14 +89,14 @@ itest!(compare_globals {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(conditional_exports {
|
itest!(conditional_exports {
|
||||||
args: "run --allow-read --unstable npm/conditional_exports/main.js",
|
args: "run --allow-read npm/conditional_exports/main.js",
|
||||||
output: "npm/conditional_exports/main.out",
|
output: "npm/conditional_exports/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(dual_cjs_esm {
|
itest!(dual_cjs_esm {
|
||||||
args: "run --unstable -A --quiet npm/dual_cjs_esm/main.ts",
|
args: "run -A --quiet npm/dual_cjs_esm/main.ts",
|
||||||
output: "npm/dual_cjs_esm/main.out",
|
output: "npm/dual_cjs_esm/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -127,21 +126,21 @@ itest!(cjs_module_export_assignment_number {
|
||||||
// FIXME(bartlomieju): npm: specifiers are not handled in dynamic imports
|
// FIXME(bartlomieju): npm: specifiers are not handled in dynamic imports
|
||||||
// at the moment
|
// at the moment
|
||||||
// itest!(dynamic_import {
|
// itest!(dynamic_import {
|
||||||
// args: "run --allow-read --allow-env --unstable npm/dynamic_import/main.ts",
|
// args: "run --allow-read --allow-env npm/dynamic_import/main.ts",
|
||||||
// output: "npm/dynamic_import/main.out",
|
// output: "npm/dynamic_import/main.out",
|
||||||
// envs: env_vars(),
|
// envs: env_vars(),
|
||||||
// http_server: true,
|
// http_server: true,
|
||||||
// });
|
// });
|
||||||
|
|
||||||
itest!(env_var_re_export_dev {
|
itest!(env_var_re_export_dev {
|
||||||
args: "run --allow-read --allow-env --unstable --quiet npm/env_var_re_export/main.js",
|
args: "run --allow-read --allow-env --quiet npm/env_var_re_export/main.js",
|
||||||
output_str: Some("dev\n"),
|
output_str: Some("dev\n"),
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(env_var_re_export_prod {
|
itest!(env_var_re_export_prod {
|
||||||
args: "run --allow-read --allow-env --unstable --quiet npm/env_var_re_export/main.js",
|
args: "run --allow-read --allow-env --quiet npm/env_var_re_export/main.js",
|
||||||
output_str: Some("prod\n"),
|
output_str: Some("prod\n"),
|
||||||
envs: {
|
envs: {
|
||||||
let mut vars = env_vars();
|
let mut vars = env_vars();
|
||||||
|
@ -152,28 +151,21 @@ itest!(env_var_re_export_prod {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(cached_only {
|
itest!(cached_only {
|
||||||
args: "run --cached-only --unstable npm/cached_only/main.ts",
|
args: "run --cached-only npm/cached_only/main.ts",
|
||||||
output: "npm/cached_only/main.out",
|
output: "npm/cached_only/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(no_unstable {
|
|
||||||
args: "run npm/no_unstable/main.ts",
|
|
||||||
output: "npm/no_unstable/main.out",
|
|
||||||
envs: env_vars(),
|
|
||||||
exit_code: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
itest!(import_map {
|
itest!(import_map {
|
||||||
args: "run --allow-read --allow-env --unstable --import-map npm/import_map/import_map.json npm/import_map/main.js",
|
args: "run --allow-read --allow-env --import-map npm/import_map/import_map.json npm/import_map/main.js",
|
||||||
output: "npm/import_map/main.out",
|
output: "npm/import_map/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(lock_file {
|
itest!(lock_file {
|
||||||
args: "run --allow-read --allow-env --unstable --lock npm/lock_file/lock.json npm/lock_file/main.js",
|
args: "run --allow-read --allow-env --lock npm/lock_file/lock.json npm/lock_file/main.js",
|
||||||
output: "npm/lock_file/main.out",
|
output: "npm/lock_file/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -181,21 +173,21 @@ itest!(lock_file {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(sub_paths {
|
itest!(sub_paths {
|
||||||
args: "run --unstable -A --quiet npm/sub_paths/main.jsx",
|
args: "run -A --quiet npm/sub_paths/main.jsx",
|
||||||
output: "npm/sub_paths/main.out",
|
output: "npm/sub_paths/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(tarball_with_global_header {
|
itest!(tarball_with_global_header {
|
||||||
args: "run --unstable -A --quiet npm/tarball_with_global_header/main.js",
|
args: "run -A --quiet npm/tarball_with_global_header/main.js",
|
||||||
output: "npm/tarball_with_global_header/main.out",
|
output: "npm/tarball_with_global_header/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(nonexistent_file {
|
itest!(nonexistent_file {
|
||||||
args: "run --unstable -A --quiet npm/nonexistent_file/main.js",
|
args: "run -A --quiet npm/nonexistent_file/main.js",
|
||||||
output: "npm/nonexistent_file/main.out",
|
output: "npm/nonexistent_file/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -203,21 +195,21 @@ itest!(nonexistent_file {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(invalid_package_name {
|
itest!(invalid_package_name {
|
||||||
args: "run --unstable -A --quiet npm/invalid_package_name/main.js",
|
args: "run -A --quiet npm/invalid_package_name/main.js",
|
||||||
output: "npm/invalid_package_name/main.out",
|
output: "npm/invalid_package_name/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(require_json {
|
itest!(require_json {
|
||||||
args: "run --unstable -A --quiet npm/require_json/main.js",
|
args: "run -A --quiet npm/require_json/main.js",
|
||||||
output: "npm/require_json/main.out",
|
output: "npm/require_json/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(error_version_after_subpath {
|
itest!(error_version_after_subpath {
|
||||||
args: "run --unstable -A --quiet npm/error_version_after_subpath/main.js",
|
args: "run -A --quiet npm/error_version_after_subpath/main.js",
|
||||||
output: "npm/error_version_after_subpath/main.out",
|
output: "npm/error_version_after_subpath/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -225,14 +217,14 @@ itest!(error_version_after_subpath {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_cache {
|
itest!(deno_cache {
|
||||||
args: "cache --unstable --reload npm:chalk npm:mkdirp",
|
args: "cache --reload npm:chalk npm:mkdirp",
|
||||||
output: "npm/deno_cache.out",
|
output: "npm/deno_cache.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(check_all {
|
itest!(check_all {
|
||||||
args: "check --unstable --remote npm/check_errors/main.ts",
|
args: "check --remote npm/check_errors/main.ts",
|
||||||
output: "npm/check_errors/main_all.out",
|
output: "npm/check_errors/main_all.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -240,7 +232,7 @@ itest!(check_all {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(check_local {
|
itest!(check_local {
|
||||||
args: "check --unstable npm/check_errors/main.ts",
|
args: "check npm/check_errors/main.ts",
|
||||||
output: "npm/check_errors/main_local.out",
|
output: "npm/check_errors/main_local.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -248,7 +240,7 @@ itest!(check_local {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(types_ambient_module {
|
itest!(types_ambient_module {
|
||||||
args: "check --unstable --quiet npm/types_ambient_module/main.ts",
|
args: "check --quiet npm/types_ambient_module/main.ts",
|
||||||
output: "npm/types_ambient_module/main.out",
|
output: "npm/types_ambient_module/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -256,7 +248,7 @@ itest!(types_ambient_module {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(types_ambient_module_import_map {
|
itest!(types_ambient_module_import_map {
|
||||||
args: "check --unstable --quiet --import-map=npm/types_ambient_module/import_map.json npm/types_ambient_module/main_import_map.ts",
|
args: "check --quiet --import-map=npm/types_ambient_module/import_map.json npm/types_ambient_module/main_import_map.ts",
|
||||||
output: "npm/types_ambient_module/main_import_map.out",
|
output: "npm/types_ambient_module/main_import_map.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -270,7 +262,6 @@ fn parallel_downloading() {
|
||||||
vec![
|
vec![
|
||||||
"run",
|
"run",
|
||||||
"--allow-read",
|
"--allow-read",
|
||||||
"--unstable",
|
|
||||||
"--allow-env",
|
"--allow-env",
|
||||||
"npm/cjs_with_deps/main.js",
|
"npm/cjs_with_deps/main.js",
|
||||||
],
|
],
|
||||||
|
@ -291,7 +282,6 @@ fn cached_only_after_first_run() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("npm/cached_only_after_first_run/main1.ts")
|
.arg("npm/cached_only_after_first_run/main1.ts")
|
||||||
|
@ -311,7 +301,6 @@ fn cached_only_after_first_run() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--cached-only")
|
.arg("--cached-only")
|
||||||
|
@ -335,7 +324,6 @@ fn cached_only_after_first_run() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--cached-only")
|
.arg("--cached-only")
|
||||||
|
@ -364,7 +352,6 @@ fn reload_flag() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("npm/reload/main.ts")
|
.arg("npm/reload/main.ts")
|
||||||
|
@ -384,7 +371,6 @@ fn reload_flag() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--reload")
|
.arg("--reload")
|
||||||
|
@ -405,7 +391,6 @@ fn reload_flag() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--reload=npm:")
|
.arg("--reload=npm:")
|
||||||
|
@ -426,7 +411,6 @@ fn reload_flag() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--reload=npm:chalk")
|
.arg("--reload=npm:chalk")
|
||||||
|
@ -447,7 +431,6 @@ fn reload_flag() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--reload=npm:foobar")
|
.arg("--reload=npm:foobar")
|
||||||
|
@ -475,7 +458,6 @@ fn no_npm_after_first_run() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--no-npm")
|
.arg("--no-npm")
|
||||||
|
@ -499,7 +481,6 @@ fn no_npm_after_first_run() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("npm/no_npm_after_first_run/main1.ts")
|
.arg("npm/no_npm_after_first_run/main1.ts")
|
||||||
|
@ -519,7 +500,6 @@ fn no_npm_after_first_run() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--no-npm")
|
.arg("--no-npm")
|
||||||
|
@ -550,7 +530,6 @@ fn deno_run_cjs_module() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(deno_dir.path())
|
.current_dir(deno_dir.path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--allow-write")
|
.arg("--allow-write")
|
||||||
|
@ -567,49 +546,49 @@ fn deno_run_cjs_module() {
|
||||||
}
|
}
|
||||||
|
|
||||||
itest!(deno_run_cowsay {
|
itest!(deno_run_cowsay {
|
||||||
args: "run --unstable -A --quiet npm:cowsay@1.5.0 Hello",
|
args: "run -A --quiet npm:cowsay@1.5.0 Hello",
|
||||||
output: "npm/deno_run_cowsay.out",
|
output: "npm/deno_run_cowsay.out",
|
||||||
envs: env_vars_no_sync_download(),
|
envs: env_vars_no_sync_download(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_run_cowsay_explicit {
|
itest!(deno_run_cowsay_explicit {
|
||||||
args: "run --unstable -A --quiet npm:cowsay@1.5.0/cowsay Hello",
|
args: "run -A --quiet npm:cowsay@1.5.0/cowsay Hello",
|
||||||
output: "npm/deno_run_cowsay.out",
|
output: "npm/deno_run_cowsay.out",
|
||||||
envs: env_vars_no_sync_download(),
|
envs: env_vars_no_sync_download(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_run_cowthink {
|
itest!(deno_run_cowthink {
|
||||||
args: "run --unstable -A --quiet npm:cowsay@1.5.0/cowthink Hello",
|
args: "run -A --quiet npm:cowsay@1.5.0/cowthink Hello",
|
||||||
output: "npm/deno_run_cowthink.out",
|
output: "npm/deno_run_cowthink.out",
|
||||||
envs: env_vars_no_sync_download(),
|
envs: env_vars_no_sync_download(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_run_bin_esm {
|
itest!(deno_run_bin_esm {
|
||||||
args: "run --unstable -A --quiet npm:@denotest/bin/cli-esm this is a test",
|
args: "run -A --quiet npm:@denotest/bin/cli-esm this is a test",
|
||||||
output: "npm/deno_run_esm.out",
|
output: "npm/deno_run_esm.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_run_bin_no_ext {
|
itest!(deno_run_bin_no_ext {
|
||||||
args: "run --unstable -A --quiet npm:@denotest/bin/cli-no-ext this is a test",
|
args: "run -A --quiet npm:@denotest/bin/cli-no-ext this is a test",
|
||||||
output: "npm/deno_run_no_ext.out",
|
output: "npm/deno_run_no_ext.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_run_bin_cjs {
|
itest!(deno_run_bin_cjs {
|
||||||
args: "run --unstable -A --quiet npm:@denotest/bin/cli-cjs this is a test",
|
args: "run -A --quiet npm:@denotest/bin/cli-cjs this is a test",
|
||||||
output: "npm/deno_run_cjs.out",
|
output: "npm/deno_run_cjs.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_run_non_existent {
|
itest!(deno_run_non_existent {
|
||||||
args: "run --unstable npm:mkdirp@0.5.125",
|
args: "run npm:mkdirp@0.5.125",
|
||||||
output: "npm/deno_run_non_existent.out",
|
output: "npm/deno_run_non_existent.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -617,7 +596,7 @@ itest!(deno_run_non_existent {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(builtin_module_module {
|
itest!(builtin_module_module {
|
||||||
args: "run --allow-read --quiet --unstable npm/builtin_module_module/main.js",
|
args: "run --allow-read --quiet npm/builtin_module_module/main.js",
|
||||||
output: "npm/builtin_module_module/main.out",
|
output: "npm/builtin_module_module/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -625,7 +604,7 @@ itest!(builtin_module_module {
|
||||||
|
|
||||||
itest!(node_modules_dir_require_added_node_modules_folder {
|
itest!(node_modules_dir_require_added_node_modules_folder {
|
||||||
args:
|
args:
|
||||||
"run --unstable --node-modules-dir -A --quiet $TESTDATA/npm/require_added_nm_folder/main.js",
|
"run --node-modules-dir -A --quiet $TESTDATA/npm/require_added_nm_folder/main.js",
|
||||||
output: "npm/require_added_nm_folder/main.out",
|
output: "npm/require_added_nm_folder/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -634,7 +613,7 @@ itest!(node_modules_dir_require_added_node_modules_folder {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(node_modules_dir_with_deps {
|
itest!(node_modules_dir_with_deps {
|
||||||
args: "run --allow-read --allow-env --unstable --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js",
|
args: "run --allow-read --allow-env --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main.out",
|
output: "npm/cjs_with_deps/main.out",
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
|
@ -658,7 +637,6 @@ fn node_modules_dir_cache() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(deno_dir.path())
|
.current_dir(deno_dir.path())
|
||||||
.arg("cache")
|
.arg("cache")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--node-modules-dir")
|
.arg("--node-modules-dir")
|
||||||
.arg("--quiet")
|
.arg("--quiet")
|
||||||
.arg(util::testdata_path().join("npm/dual_cjs_esm/main.ts"))
|
.arg(util::testdata_path().join("npm/dual_cjs_esm/main.ts"))
|
||||||
|
@ -694,7 +672,6 @@ fn node_modules_dir_cache() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(deno_dir.path())
|
.current_dir(deno_dir.path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--node-modules-dir")
|
.arg("--node-modules-dir")
|
||||||
.arg("--quiet")
|
.arg("--quiet")
|
||||||
.arg("-A")
|
.arg("-A")
|
||||||
|
@ -734,7 +711,7 @@ fn ensure_registry_files_local() {
|
||||||
}
|
}
|
||||||
|
|
||||||
itest!(compile_errors {
|
itest!(compile_errors {
|
||||||
args: "compile -A --quiet --unstable npm/esm/main.js",
|
args: "compile -A --quiet npm/esm/main.js",
|
||||||
output_str: Some("error: npm specifiers have not yet been implemented for deno compile (https://github.com/denoland/deno/issues/15960). Found: npm:chalk@5\n"),
|
output_str: Some("error: npm specifiers have not yet been implemented for deno compile (https://github.com/denoland/deno/issues/15960). Found: npm:chalk@5\n"),
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -742,7 +719,7 @@ itest!(compile_errors {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_chalk_display {
|
itest!(info_chalk_display {
|
||||||
args: "info --quiet --unstable npm/cjs_with_deps/main.js",
|
args: "info --quiet npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main_info.out",
|
output: "npm/cjs_with_deps/main_info.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -750,7 +727,7 @@ itest!(info_chalk_display {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_chalk_display_node_modules_dir {
|
itest!(info_chalk_display_node_modules_dir {
|
||||||
args: "info --quiet --unstable --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js",
|
args: "info --quiet --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main_info.out",
|
output: "npm/cjs_with_deps/main_info.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -759,7 +736,7 @@ itest!(info_chalk_display_node_modules_dir {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_chalk_json {
|
itest!(info_chalk_json {
|
||||||
args: "info --quiet --unstable --json npm/cjs_with_deps/main.js",
|
args: "info --quiet --json npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main_info_json.out",
|
output: "npm/cjs_with_deps/main_info_json.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -767,7 +744,8 @@ itest!(info_chalk_json {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_chalk_json_node_modules_dir {
|
itest!(info_chalk_json_node_modules_dir {
|
||||||
args: "info --quiet --unstable --node-modules-dir --json $TESTDATA/npm/cjs_with_deps/main.js",
|
args:
|
||||||
|
"info --quiet --node-modules-dir --json $TESTDATA/npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main_info_json.out",
|
output: "npm/cjs_with_deps/main_info_json.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -776,7 +754,7 @@ itest!(info_chalk_json_node_modules_dir {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_cli_chalk_display {
|
itest!(info_cli_chalk_display {
|
||||||
args: "info --quiet --unstable npm:chalk@4",
|
args: "info --quiet npm:chalk@4",
|
||||||
output: "npm/info/chalk.out",
|
output: "npm/info/chalk.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -784,7 +762,7 @@ itest!(info_cli_chalk_display {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_cli_chalk_json {
|
itest!(info_cli_chalk_json {
|
||||||
args: "info --quiet --unstable --json npm:chalk@4",
|
args: "info --quiet --json npm:chalk@4",
|
||||||
output: "npm/info/chalk_json.out",
|
output: "npm/info/chalk_json.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -985,7 +963,6 @@ fn lock_file_missing_top_level_package() {
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||||
.current_dir(temp_dir.path())
|
.current_dir(temp_dir.path())
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--unstable")
|
|
||||||
.arg("--quiet")
|
.arg("--quiet")
|
||||||
.arg("--lock")
|
.arg("--lock")
|
||||||
.arg("deno.lock")
|
.arg("deno.lock")
|
||||||
|
@ -1214,7 +1191,7 @@ fn peer_deps_with_copied_folders_and_lockfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
itest!(info_peer_deps {
|
itest!(info_peer_deps {
|
||||||
args: "info --quiet --unstable npm/peer_deps_with_copied_folders/main.ts",
|
args: "info --quiet npm/peer_deps_with_copied_folders/main.ts",
|
||||||
output: "npm/peer_deps_with_copied_folders/main_info.out",
|
output: "npm/peer_deps_with_copied_folders/main_info.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
@ -1222,8 +1199,7 @@ itest!(info_peer_deps {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(info_peer_deps_json {
|
itest!(info_peer_deps_json {
|
||||||
args:
|
args: "info --quiet --json npm/peer_deps_with_copied_folders/main.ts",
|
||||||
"info --quiet --unstable --json npm/peer_deps_with_copied_folders/main.ts",
|
|
||||||
output: "npm/peer_deps_with_copied_folders/main_info_json.out",
|
output: "npm/peer_deps_with_copied_folders/main_info_json.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
envs: env_vars(),
|
envs: env_vars(),
|
||||||
|
|
1
cli/tests/testdata/npm/no_unstable/main.out
vendored
1
cli/tests/testdata/npm/no_unstable/main.out
vendored
|
@ -1 +0,0 @@
|
||||||
error: Unstable use of npm specifiers. The --unstable flag must be provided.
|
|
3
cli/tests/testdata/npm/no_unstable/main.ts
vendored
3
cli/tests/testdata/npm/no_unstable/main.ts
vendored
|
@ -1,3 +0,0 @@
|
||||||
import chalk from "npm:chalk@5";
|
|
||||||
|
|
||||||
console.log(chalk.green("hello"));
|
|
|
@ -74,10 +74,7 @@ pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| {
|
||||||
set
|
set
|
||||||
});
|
});
|
||||||
|
|
||||||
struct Unstable(pub bool);
|
|
||||||
|
|
||||||
pub fn init<P: NodePermissions + 'static>(
|
pub fn init<P: NodePermissions + 'static>(
|
||||||
unstable: bool,
|
|
||||||
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
||||||
) -> Extension {
|
) -> Extension {
|
||||||
Extension::builder()
|
Extension::builder()
|
||||||
|
@ -110,7 +107,6 @@ pub fn init<P: NodePermissions + 'static>(
|
||||||
op_require_package_imports_resolve::decl::<P>(),
|
op_require_package_imports_resolve::decl::<P>(),
|
||||||
])
|
])
|
||||||
.state(move |state| {
|
.state(move |state| {
|
||||||
state.put(Unstable(unstable));
|
|
||||||
if let Some(npm_resolver) = maybe_npm_resolver.clone() {
|
if let Some(npm_resolver) = maybe_npm_resolver.clone() {
|
||||||
state.put(npm_resolver);
|
state.put(npm_resolver);
|
||||||
}
|
}
|
||||||
|
@ -119,15 +115,6 @@ pub fn init<P: NodePermissions + 'static>(
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_unstable(state: &OpState) {
|
|
||||||
let unstable = state.borrow::<Unstable>();
|
|
||||||
|
|
||||||
if !unstable.0 {
|
|
||||||
eprintln!("Unstable API 'require'. The --unstable flag must be provided.",);
|
|
||||||
std::process::exit(70);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ensure_read_permission<P>(
|
fn ensure_read_permission<P>(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
file_path: &Path,
|
file_path: &Path,
|
||||||
|
@ -147,9 +134,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_require_init_paths(state: &mut OpState) -> Vec<String> {
|
pub fn op_require_init_paths() -> Vec<String> {
|
||||||
check_unstable(state);
|
|
||||||
|
|
||||||
// todo(dsherret): this code is node compat mode specific and
|
// todo(dsherret): this code is node compat mode specific and
|
||||||
// we probably don't want it for small mammal, so ignore it for now
|
// we probably don't want it for small mammal, so ignore it for now
|
||||||
|
|
||||||
|
@ -206,7 +191,6 @@ pub fn op_require_node_module_paths<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
// Guarantee that "from" is absolute.
|
// Guarantee that "from" is absolute.
|
||||||
let from = deno_core::resolve_path(&from)
|
let from = deno_core::resolve_path(&from)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -254,8 +238,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_proxy_path(state: &mut OpState, filename: String) -> String {
|
fn op_require_proxy_path(filename: String) -> String {
|
||||||
check_unstable(state);
|
|
||||||
// Allow a directory to be passed as the filename
|
// Allow a directory to be passed as the filename
|
||||||
let trailing_slash = if cfg!(windows) {
|
let trailing_slash = if cfg!(windows) {
|
||||||
filename.ends_with('\\')
|
filename.ends_with('\\')
|
||||||
|
@ -272,11 +255,7 @@ fn op_require_proxy_path(state: &mut OpState, filename: String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_is_request_relative(
|
fn op_require_is_request_relative(request: String) -> bool {
|
||||||
state: &mut OpState,
|
|
||||||
request: String,
|
|
||||||
) -> bool {
|
|
||||||
check_unstable(state);
|
|
||||||
if request.starts_with("./") || request.starts_with("../") || request == ".."
|
if request.starts_with("./") || request.starts_with("../") || request == ".."
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -301,7 +280,6 @@ fn op_require_resolve_deno_dir(
|
||||||
request: String,
|
request: String,
|
||||||
parent_filename: String,
|
parent_filename: String,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
check_unstable(state);
|
|
||||||
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
|
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
|
||||||
resolver
|
resolver
|
||||||
.resolve_package_folder_from_package(
|
.resolve_package_folder_from_package(
|
||||||
|
@ -315,19 +293,16 @@ fn op_require_resolve_deno_dir(
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_is_deno_dir_package(state: &mut OpState, path: String) -> bool {
|
fn op_require_is_deno_dir_package(state: &mut OpState, path: String) -> bool {
|
||||||
check_unstable(state);
|
|
||||||
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
|
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>();
|
||||||
resolver.in_npm_package(&PathBuf::from(path))
|
resolver.in_npm_package(&PathBuf::from(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_resolve_lookup_paths(
|
fn op_require_resolve_lookup_paths(
|
||||||
state: &mut OpState,
|
|
||||||
request: String,
|
request: String,
|
||||||
maybe_parent_paths: Option<Vec<String>>,
|
maybe_parent_paths: Option<Vec<String>>,
|
||||||
parent_filename: String,
|
parent_filename: String,
|
||||||
) -> Option<Vec<String>> {
|
) -> Option<Vec<String>> {
|
||||||
check_unstable(state);
|
|
||||||
if !request.starts_with('.')
|
if !request.starts_with('.')
|
||||||
|| (request.len() > 1
|
|| (request.len() > 1
|
||||||
&& !request.starts_with("..")
|
&& !request.starts_with("..")
|
||||||
|
@ -364,8 +339,7 @@ fn op_require_resolve_lookup_paths(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_is_absolute(state: &mut OpState, p: String) -> bool {
|
fn op_require_path_is_absolute(p: String) -> bool {
|
||||||
check_unstable(state);
|
|
||||||
PathBuf::from(p).is_absolute()
|
PathBuf::from(p).is_absolute()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +351,6 @@ fn op_require_stat<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
ensure_read_permission::<P>(state, &path)?;
|
ensure_read_permission::<P>(state, &path)?;
|
||||||
if let Ok(metadata) = std::fs::metadata(&path) {
|
if let Ok(metadata) = std::fs::metadata(&path) {
|
||||||
|
@ -399,7 +372,6 @@ fn op_require_real_path<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
let path = PathBuf::from(request);
|
let path = PathBuf::from(request);
|
||||||
ensure_read_permission::<P>(state, &path)?;
|
ensure_read_permission::<P>(state, &path)?;
|
||||||
let mut canonicalized_path = path.canonicalize()?;
|
let mut canonicalized_path = path.canonicalize()?;
|
||||||
|
@ -426,17 +398,12 @@ fn path_resolve(parts: Vec<String>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_resolve(state: &mut OpState, parts: Vec<String>) -> String {
|
fn op_require_path_resolve(parts: Vec<String>) -> String {
|
||||||
check_unstable(state);
|
|
||||||
path_resolve(parts)
|
path_resolve(parts)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_dirname(
|
fn op_require_path_dirname(request: String) -> Result<String, AnyError> {
|
||||||
state: &mut OpState,
|
|
||||||
request: String,
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
check_unstable(state);
|
|
||||||
let p = PathBuf::from(request);
|
let p = PathBuf::from(request);
|
||||||
if let Some(parent) = p.parent() {
|
if let Some(parent) = p.parent() {
|
||||||
Ok(parent.to_string_lossy().to_string())
|
Ok(parent.to_string_lossy().to_string())
|
||||||
|
@ -446,11 +413,7 @@ fn op_require_path_dirname(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_basename(
|
fn op_require_path_basename(request: String) -> Result<String, AnyError> {
|
||||||
state: &mut OpState,
|
|
||||||
request: String,
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
check_unstable(state);
|
|
||||||
let p = PathBuf::from(request);
|
let p = PathBuf::from(request);
|
||||||
if let Some(path) = p.file_name() {
|
if let Some(path) = p.file_name() {
|
||||||
Ok(path.to_string_lossy().to_string())
|
Ok(path.to_string_lossy().to_string())
|
||||||
|
@ -469,7 +432,6 @@ fn op_require_try_self_parent_path<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
if !has_parent {
|
if !has_parent {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
@ -495,7 +457,6 @@ fn op_require_try_self(
|
||||||
parent_path: Option<String>,
|
parent_path: Option<String>,
|
||||||
request: String,
|
request: String,
|
||||||
) -> Result<Option<String>, AnyError> {
|
) -> Result<Option<String>, AnyError> {
|
||||||
check_unstable(state);
|
|
||||||
if parent_path.is_none() {
|
if parent_path.is_none() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
@ -554,19 +515,13 @@ fn op_require_read_file<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
let file_path = PathBuf::from(file_path);
|
let file_path = PathBuf::from(file_path);
|
||||||
ensure_read_permission::<P>(state, &file_path)?;
|
ensure_read_permission::<P>(state, &file_path)?;
|
||||||
Ok(std::fs::read_to_string(file_path)?)
|
Ok(std::fs::read_to_string(file_path)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_require_as_file_path(
|
pub fn op_require_as_file_path(file_or_url: String) -> String {
|
||||||
state: &mut OpState,
|
|
||||||
file_or_url: String,
|
|
||||||
) -> String {
|
|
||||||
check_unstable(state);
|
|
||||||
|
|
||||||
if let Ok(url) = Url::parse(&file_or_url) {
|
if let Ok(url) = Url::parse(&file_or_url) {
|
||||||
if let Ok(p) = url.to_file_path() {
|
if let Ok(p) = url.to_file_path() {
|
||||||
return p.to_string_lossy().to_string();
|
return p.to_string_lossy().to_string();
|
||||||
|
@ -585,7 +540,6 @@ fn op_require_resolve_exports(
|
||||||
expansion: String,
|
expansion: String,
|
||||||
parent_path: String,
|
parent_path: String,
|
||||||
) -> Result<Option<String>, AnyError> {
|
) -> Result<Option<String>, AnyError> {
|
||||||
check_unstable(state);
|
|
||||||
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
|
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
|
||||||
|
|
||||||
let pkg_path = if resolver.in_npm_package(&PathBuf::from(&modules_path)) {
|
let pkg_path = if resolver.in_npm_package(&PathBuf::from(&modules_path)) {
|
||||||
|
@ -623,7 +577,6 @@ fn op_require_read_closest_package_json<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
ensure_read_permission::<P>(
|
ensure_read_permission::<P>(
|
||||||
state,
|
state,
|
||||||
PathBuf::from(&filename).parent().unwrap(),
|
PathBuf::from(&filename).parent().unwrap(),
|
||||||
|
@ -640,7 +593,6 @@ fn op_require_read_package_scope(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
package_json_path: String,
|
package_json_path: String,
|
||||||
) -> Option<PackageJson> {
|
) -> Option<PackageJson> {
|
||||||
check_unstable(state);
|
|
||||||
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
|
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
|
||||||
let package_json_path = PathBuf::from(package_json_path);
|
let package_json_path = PathBuf::from(package_json_path);
|
||||||
PackageJson::load(&*resolver, package_json_path).ok()
|
PackageJson::load(&*resolver, package_json_path).ok()
|
||||||
|
@ -655,7 +607,6 @@ fn op_require_package_imports_resolve<P>(
|
||||||
where
|
where
|
||||||
P: NodePermissions + 'static,
|
P: NodePermissions + 'static,
|
||||||
{
|
{
|
||||||
check_unstable(state);
|
|
||||||
let parent_path = PathBuf::from(&parent_filename);
|
let parent_path = PathBuf::from(&parent_filename);
|
||||||
ensure_read_permission::<P>(state, &parent_path)?;
|
ensure_read_permission::<P>(state, &parent_path)?;
|
||||||
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
|
let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone();
|
||||||
|
|
|
@ -194,7 +194,7 @@ mod not_docs {
|
||||||
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
||||||
false, // No --unstable.
|
false, // No --unstable.
|
||||||
),
|
),
|
||||||
deno_node::init::<Permissions>(false, None), // No --unstable.
|
deno_node::init::<Permissions>(None),
|
||||||
deno_ffi::init::<Permissions>(false),
|
deno_ffi::init::<Permissions>(false),
|
||||||
deno_net::init::<Permissions>(
|
deno_net::init::<Permissions>(
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
|
|
|
@ -432,7 +432,7 @@ impl WebWorker {
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
),
|
),
|
||||||
deno_napi::init::<Permissions>(unstable),
|
deno_napi::init::<Permissions>(unstable),
|
||||||
deno_node::init::<Permissions>(unstable, options.npm_resolver),
|
deno_node::init::<Permissions>(options.npm_resolver),
|
||||||
ops::os::init_for_worker(),
|
ops::os::init_for_worker(),
|
||||||
ops::permissions::init(),
|
ops::permissions::init(),
|
||||||
ops::process::init(),
|
ops::process::init(),
|
||||||
|
|
|
@ -229,7 +229,7 @@ impl MainWorker {
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
),
|
),
|
||||||
deno_napi::init::<Permissions>(unstable),
|
deno_napi::init::<Permissions>(unstable),
|
||||||
deno_node::init::<Permissions>(unstable, options.npm_resolver),
|
deno_node::init::<Permissions>(options.npm_resolver),
|
||||||
ops::os::init(exit_code.clone()),
|
ops::os::init(exit_code.clone()),
|
||||||
ops::permissions::init(),
|
ops::permissions::init(),
|
||||||
ops::process::init(),
|
ops::process::init(),
|
||||||
|
|
Loading…
Reference in a new issue