@@ -806,6 +806,7 @@ pub struct Flags {
806806 pub eszip : bool ,
807807 pub node_conditions : Vec < String > ,
808808 pub preload : Vec < String > ,
809+ pub require : Vec < String > ,
809810 pub tunnel : bool ,
810811}
811812
@@ -4159,6 +4160,7 @@ fn compile_args_without_check_args(app: Command) -> Command {
41594160 . arg ( ca_file_arg ( ) )
41604161 . arg ( unsafely_ignore_certificate_errors_arg ( ) )
41614162 . arg ( preload_arg ( ) )
4163+ . arg ( require_arg ( ) )
41624164 . arg ( min_dep_age_arg ( ) )
41634165}
41644166
@@ -4749,6 +4751,15 @@ fn preload_arg() -> Arg {
47494751 . value_hint ( ValueHint :: FilePath )
47504752}
47514753
4754+ fn require_arg ( ) -> Arg {
4755+ Arg :: new ( "require" )
4756+ . long ( "require" )
4757+ . value_name ( "FILE" )
4758+ . action ( ArgAction :: Append )
4759+ . help ( "A list of CommonJS modules that will be executed before the main module (even if it's not with a .cjs or .tjs extension)" )
4760+ . value_hint ( ValueHint :: FilePath )
4761+ }
4762+
47524763fn min_dep_age_arg ( ) -> Arg {
47534764 Arg :: new ( "minimum-dependency-age" )
47544765 . long ( "minimum-dependency-age" )
@@ -6511,6 +6522,7 @@ fn compile_args_without_check_parse(
65116522 ca_file_arg_parse ( flags, matches) ;
65126523 unsafely_ignore_certificate_errors_parse ( flags, matches) ;
65136524 preload_arg_parse ( flags, matches) ;
6525+ require_arg_parse ( flags, matches) ;
65146526 min_dep_age_arg_parse ( flags, matches) ;
65156527 Ok ( ( ) )
65166528}
@@ -6789,6 +6801,12 @@ fn preload_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
67896801 }
67906802}
67916803
6804+ fn require_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
6805+ if let Some ( require) = matches. remove_many :: < String > ( "require" ) {
6806+ flags. require = require. collect ( ) ;
6807+ }
6808+ }
6809+
67926810fn min_dep_age_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
67936811 flags. minimum_dependency_age = matches. remove_one ( "minimum-dependency-age" ) ;
67946812}
@@ -13464,6 +13482,53 @@ Usage: deno repl [OPTIONS] [-- [ARGS]...]\n"
1346413482 ) ;
1346513483 }
1346613484
13485+ #[ test]
13486+ fn require_flag_test ( ) {
13487+ let flags = flags_from_vec ( svec ! [
13488+ "deno" ,
13489+ "run" ,
13490+ "--require" ,
13491+ "require.js" ,
13492+ "main.ts"
13493+ ] )
13494+ . unwrap ( ) ;
13495+ assert_eq ! (
13496+ flags,
13497+ Flags {
13498+ subcommand: DenoSubcommand :: Run ( RunFlags {
13499+ script: "main.ts" . into( ) ,
13500+ ..Default :: default ( )
13501+ } ) ,
13502+ require: svec![ "require.js" ] ,
13503+ code_cache_enabled: true ,
13504+ ..Default :: default ( )
13505+ }
13506+ ) ;
13507+
13508+ let flags = flags_from_vec ( svec ! [
13509+ "deno" ,
13510+ "run" ,
13511+ "--require" ,
13512+ "r1.js" ,
13513+ "--require" ,
13514+ "./r2.js" ,
13515+ "main.ts"
13516+ ] )
13517+ . unwrap ( ) ;
13518+ assert_eq ! (
13519+ flags,
13520+ Flags {
13521+ subcommand: DenoSubcommand :: Run ( RunFlags {
13522+ script: "main.ts" . into( ) ,
13523+ ..Default :: default ( )
13524+ } ) ,
13525+ require: svec![ "r1.js" , "./r2.js" ] ,
13526+ code_cache_enabled: true ,
13527+ ..Default :: default ( )
13528+ }
13529+ ) ;
13530+ }
13531+
1346713532 #[ test]
1346813533 fn check_with_v8_flags ( ) {
1346913534 let flags =
0 commit comments