Files
Ruben Fiszel 0317d5891c feat: add powershell common parameters support (#8683)
* feat: add powershell common parameters support (-Verbose, -Debug, -ErrorAction, -WhatIf)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add powershell common params to script editor test panel

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: detect CmdletBinding from code instead of schema in script editor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: ignore commented-out CmdletBinding in powershell detection

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use preference variables for -Verbose/-Debug instead of CLI args

Verbose/Debug output goes to PowerShell stream 4/5 which isn't captured
by the 2>&1 redirect. Setting $VerbosePreference/$DebugPreference in the
wrapper scope propagates to child scripts and output flows through the
host to stderr, which Windmill captures as logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use *>&1 to capture all powershell streams including verbose/debug

The previous 2>&1 only captured error stream. Verbose (stream 4) and
debug (stream 5) output was silently lost. Using *>&1 redirects all
streams to success stream so they flow through Tee-Object into logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use targeted stream redirects (4>&1 5>&1 2>&1) instead of *>&1

*>&1 breaks $PSCmdlet.ShouldProcess() by redirecting internal streams.
Only redirect verbose (4), debug (5), and error (2) to success stream.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: revert to 2>&1 redirect — stream 4/5 redirects break powershell

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use 4>&1 5>&1 for verbose/debug capture, remove WhatIf support

Stream 4/5 redirects capture verbose/debug in the pipeline. WhatIf is
removed because $PSCmdlet.ShouldProcess() doesn't work when scripts
are invoked through Windmill's wrapper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: redirect verbose/debug to files to keep result pipeline clean

Verbose (4) and debug (5) streams are redirected to separate log files
during script execution, then output via Write-Host after the script
completes. This keeps them out of the Tee-Object pipeline (used for
result extraction) while still showing them in the job logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: output verbose/debug to stderr via Console.Error for log capture

Write-Host goes to stdout which gets mixed with result output and
truncated by OSS log threshold. Using [Console]::Error.WriteLine()
writes to stderr which Windmill captures separately as logs, with
VERBOSE:/DEBUG: prefixes for clarity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: redirect script output to file only, send verbose/debug to stdout

The OSS log storage has a 9KB threshold. Previously, Tee-Object sent
the full JSON result to both stdout (logs) and the pipe file, eating
the log budget. Now script output goes only to the pipe file (> $pipe),
and only verbose/debug messages go to stdout for the log viewer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: preserve original Tee-Object behavior, append verbose/debug after

Keep the original wrapper behavior (Tee-Object to stdout + pipe file).
Only add 4>verbose.log 5>debug.log to capture those streams, and
output them at the end of logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: inject preference vars into main.ps1 instead of CLI args

Passing -Verbose/-Debug as CLI args causes PowerShell module loading
to emit verbose noise. Instead, inject $VerbosePreference/$DebugPreference
inside main.ps1's try block so they only affect user code. Stream 4/5
are still redirected to files in the wrapper for log output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: restore common param toggles from previous job args on Run Again

Extract _wm_ps_* keys from loaded args and initialize the toggle
states in PowerShellCommonParams. Also strip them from main args
so they don't appear as unknown schema form inputs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: show active common param badges when section is collapsed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: inject ErrorAction as preference variable instead of CLI arg

-ErrorAction as a CLI arg only affects the caller, not the script's
internal error handling. Setting $ErrorActionPreference inside main.ps1
correctly overrides the default 'Stop' behavior for the user's code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: ensure full backward compatibility with existing powershell scripts

- Only filter common param names when [CmdletBinding()] is present
  (without it, $Verbose etc. are regular user-defined parameters)
- Only add 4>verbose.log 5>debug.log and log output lines when common
  params are actually enabled — original wrapper is unchanged otherwise

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: lighter styling for common params section

Replaced heavy Section component with a subtle inline chevron toggle
labeled "Common parameters". Smaller text, secondary color, indented
options. Badges still show when collapsed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: rename section to CmdletBinding parameters

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add ..Default::default() to windmill-parser-r (new parser from main)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: missing comma in graphql parser test + merge main

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add missing commas before ..Default::default() in parser tests

Merge from main brought test constructors with formatting issues
from the original automated script (missing comma between last field
and ..Default::default()).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: restore comment markers in nu parser test that script broke

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address PR review — ignore commented CmdletBinding, clear stale params

1. Parser: strip comment lines before detecting [CmdletBinding()] to
   avoid false positives from commented-out attributes
2. RunForm: always assign psCommonParams (not just when non-empty) so
   stale settings from a previous run don't leak into later runs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 13:03:22 +00:00

908 lines
29 KiB
Rust

#[cfg(test)]
mod tests {
use serde_json::json;
use windmill_parser::{Arg, MainArgSignature, ObjectProperty, ObjectType, Typ};
use windmill_parser_ts::{parse_deno_signature, parse_expr_for_imports, parse_relative_imports};
#[test]
fn test_imports_basic() {
let code = r#"
import { foo } from "bar";
import type { foo } from "bar2";
import { type foo, bar } from "bar3";
import { bar, type foo } from "bar7";
import { type foo, type bar } from "bar4";
import * as foo from "bar5";
import foo from "bar6";
export * from "bar8";
export { foo } from "bar9";
export { type foo } from "bar10";
export { foo, type bar } from "bar11";
export { type foo, type bar } from "bar12";
export { type foo, bar } from "bar13";
export { bar, type foo } from "bar14";
export type { foo } from "bar15";
"#;
let imports = parse_expr_for_imports(code, true).unwrap();
assert_eq!(
imports,
["bar", "bar11", "bar13", "bar14", "bar3", "bar5", "bar6", "bar7", "bar8", "bar9"]
);
}
#[test]
fn test_parse_empty_main_signature() {
let code = r#"
export async function main() {
return "Hello World";
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_basic_types() {
let code = r#"
export async function main(
str_param: string,
num_param: number,
bool_param: boolean,
any_param: any
) {
return { str_param, num_param, bool_param, any_param };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
name: "str_param".to_string(),
otyp: None,
typ: Typ::Str(None),
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "num_param".to_string(),
otyp: None,
typ: Typ::Float,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "bool_param".to_string(),
otyp: None,
typ: Typ::Bool,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "any_param".to_string(),
otyp: None,
typ: Typ::Unknown,
default: None,
has_default: false,
oidx: None,
},
],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_with_defaults() {
let code = r#"
export async function main(
name: string = "World",
count: number = 42,
enabled: boolean = true
) {
return { name, count, enabled };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
name: "name".to_string(),
otyp: None,
typ: Typ::Str(None),
default: Some(json!("World")),
has_default: true,
oidx: None,
},
Arg {
name: "count".to_string(),
otyp: None,
typ: Typ::Float,
default: Some(json!(42)),
has_default: true,
oidx: None,
},
Arg {
name: "enabled".to_string(),
otyp: None,
typ: Typ::Bool,
default: Some(json!(true)),
has_default: true,
oidx: None,
},
],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_array_types() {
let code = r#"
export async function main(
strings: string[],
numbers: number[],
items: any[]
) {
return { strings, numbers, items };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
name: "strings".to_string(),
otyp: None,
typ: Typ::List(Box::new(Typ::Str(None))),
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "numbers".to_string(),
otyp: None,
typ: Typ::List(Box::new(Typ::Float)),
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "items".to_string(),
otyp: None,
typ: Typ::List(Box::new(Typ::Unknown)),
default: None,
has_default: false,
oidx: None,
},
],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_resource_types() {
let code = r#"
type Postgresql = Resource;
export async function main(
database: Postgresql
) {
return { database };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "database".to_string(),
otyp: None,
typ: Typ::Resource("postgresql".to_string()),
default: None,
has_default: false,
oidx: None,
},],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_array_resource_types() {
let code = r#"
type Postgresql = Foo;
export async function main(
database: Postgresql[]
) {
return { database };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "database".to_string(),
otyp: None,
typ: Typ::List(Box::new(Typ::Resource("postgresql".to_string()))),
default: None,
has_default: false,
oidx: None,
},],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_interface_object() {
let code = r#"
interface UserConfig {
name: string;
age: number;
active?: boolean;
}
export async function main(config: UserConfig) {
return config;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "config".to_string(),
otyp: None,
typ: Typ::Object(ObjectType::new(
Some("user_config".to_string()),
Some(vec![
ObjectProperty::new("name".to_string(), Box::new(Typ::Str(None))),
ObjectProperty::new("age".to_string(), Box::new(Typ::Float)),
ObjectProperty::new("active".to_string(), Box::new(Typ::Bool)),
])
)),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_array_of_objects() {
let code = r#"
interface Item {
id: string;
value: number;
}
export async function main(items: Item[]) {
return items;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "items".to_string(),
otyp: None,
typ: Typ::List(Box::new(Typ::Object(ObjectType::new(
Some("item".to_string()),
Some(vec![
ObjectProperty::new("id".to_string(), Box::new(Typ::Str(None))),
ObjectProperty::new("value".to_string(), Box::new(Typ::Float)),
])
)))),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_nested_objects() {
let code = r#"
interface Address {
street: string;
city: string;
}
interface Person {
name: string;
address: Address;
}
export async function main(person: Person) {
return person;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "person".to_string(),
otyp: None,
typ: Typ::Object(ObjectType::new(
Some("person".to_string()),
Some(vec![
ObjectProperty::new("name".to_string(), Box::new(Typ::Str(None))),
ObjectProperty::new(
"address".to_string(),
Box::new(Typ::Object(ObjectType::new(
Some("address".to_string()),
Some(vec![
ObjectProperty::new(
"street".to_string(),
Box::new(Typ::Str(None))
),
ObjectProperty::new(
"city".to_string(),
Box::new(Typ::Str(None))
),
])
)))
),
])
)),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_builtin_types() {
let code = r#"
export async function main(
date_param: Date,
base64_param: Base64,
email_param: Email,
sql_param: Sql
) {
return { date_param, base64_param, email_param, sql_param };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
name: "date_param".to_string(),
otyp: None,
typ: Typ::Datetime,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "base64_param".to_string(),
otyp: None,
typ: Typ::Bytes,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "email_param".to_string(),
otyp: None,
typ: Typ::Email,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "sql_param".to_string(),
otyp: None,
typ: Typ::Sql,
default: None,
has_default: false,
oidx: None,
},
],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_optional_parameters() {
let code = r#"
export async function main(
required: string,
optional?: number,
with_default: boolean = false
) {
return { required, optional, with_default };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
name: "required".to_string(),
otyp: None,
typ: Typ::Str(None),
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "optional".to_string(),
otyp: None,
typ: Typ::Float,
default: None,
has_default: true,
oidx: None,
},
Arg {
name: "with_default".to_string(),
otyp: None,
typ: Typ::Bool,
default: Some(json!(false)),
has_default: true,
oidx: None,
},
],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_complex_interface() {
let code = r#"
interface Config {
timeout: number;
retries: number;
}
export async function main(
config: Config,
tags: string[]
) {
return { config, tags };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(sig.args.len(), 2);
assert_eq!(sig.args[0].name, "config");
assert_eq!(sig.args[0].has_default, false);
assert!(matches!(sig.args[0].typ, Typ::Object(_)));
assert_eq!(sig.args[1].name, "tags");
assert_eq!(sig.args[1].has_default, false);
assert!(matches!(sig.args[1].typ, Typ::List(_)));
}
#[test]
fn test_parse_no_main_function() {
let code = r#"
function helper() {
return "helper";
}
const value = 42;
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![],
auto_kind: Some("lib".to_string()),
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_custom_entrypoint() {
let code = r#"
export async function customMain(param: string) {
return param;
}
"#;
let sig = parse_deno_signature(code, false, false, Some("customMain".to_string())).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "param".to_string(),
otyp: None,
typ: Typ::Str(None),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_dyn_select() {
let code = r#"
export async function main(
selector: DynSelect_my_options
) {
return selector;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "selector".to_string(),
otyp: None,
typ: Typ::DynSelect("my_options".to_string()),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_dyn_multiselect() {
let code = r#"
export async function main(
selector: DynMultiselect_my_options
) {
return selector;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "selector".to_string(),
otyp: None,
typ: Typ::DynMultiselect("my_options".to_string()),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_union_array_type() {
let code = r#"
export async function main(
items: string | string[],
numbers: number[] | number,
plain: string
) {
return { items, numbers, plain };
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![
Arg {
name: "items".to_string(),
otyp: Some("string | string[]".to_string()),
typ: Typ::Unknown,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "numbers".to_string(),
otyp: Some("number[] | number".to_string()),
typ: Typ::Unknown,
default: None,
has_default: false,
oidx: None,
},
Arg {
name: "plain".to_string(),
otyp: None,
typ: Typ::Str(None),
default: None,
has_default: false,
oidx: None,
},
],
auto_kind: None,
has_preprocessor: Some(false),
..Default::default()
}
);
}
#[test]
fn test_parse_invalid_typescript() {
let code = r#"
this is not valid typescript code {
"#;
let result = parse_deno_signature(code, false, false, None);
assert!(result.is_err());
}
#[test]
fn test_parse_with_preprocessor() {
let code = r#"
export async function preprocessor() {
return "preprocessed";
}
export async function main(param: string) {
return param;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "param".to_string(),
otyp: None,
typ: Typ::Str(None),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(true),
..Default::default()
}
);
}
#[test]
fn test_parse_with_preprocessor_reexport() {
// Test case for issue #6894: preprocessor re-export should be detected
let code = r#"
export { preprocessor } from "./extract_user_info_from_jwt_token";
export async function main(param: string) {
return param;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(
sig,
MainArgSignature {
star_args: false,
star_kwargs: false,
args: vec![Arg {
name: "param".to_string(),
otyp: None,
typ: Typ::Str(None),
default: None,
has_default: false,
oidx: None,
}],
auto_kind: None,
has_preprocessor: Some(true),
..Default::default()
}
);
}
#[test]
fn test_parse_with_preprocessor_reexport_renamed() {
// Test case for renamed re-exports
let code = r#"
export { preprocessor as preprocessor } from "./other";
export async function main(param: string) {
return param;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(sig.has_preprocessor, Some(true));
}
#[test]
fn test_parse_with_preprocessor_among_other_exports() {
// Test case where preprocessor is one of many exports
let code = r#"
export { foo, preprocessor, bar } from "./utils";
export async function main(param: string) {
return param;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(sig.has_preprocessor, Some(true));
}
#[test]
fn test_parse_without_preprocessor_other_exports() {
// Test case where there are exports but no preprocessor
let code = r#"
export { foo, bar } from "./utils";
export async function main(param: string) {
return param;
}
"#;
let sig = parse_deno_signature(code, false, false, None).unwrap();
assert_eq!(sig.has_preprocessor, Some(false));
}
// ==========================================================================
// Tests for parse_relative_imports
// ==========================================================================
#[test]
fn test_relative_imports_dot() {
let code = r#"
import { helper } from "./helper";
export async function main() { return helper(); }
"#;
let result = parse_relative_imports(code, "f/folder/script").unwrap();
assert_eq!(result, vec!["f/folder/helper"]);
}
#[test]
fn test_relative_imports_double_dot() {
let code = r#"
import { utils } from "../utils/helper";
export async function main() { return utils(); }
"#;
let result = parse_relative_imports(code, "f/folder/subfolder/script").unwrap();
assert_eq!(result, vec!["f/folder/utils/helper"]);
}
#[test]
fn test_relative_imports_absolute_path() {
let code = r#"
import { shared } from "/f/shared/utils";
export async function main() { return shared(); }
"#;
let result = parse_relative_imports(code, "f/folder/script").unwrap();
assert_eq!(result, vec!["f/shared/utils"]);
}
#[test]
fn test_relative_imports_mixed() {
let code = r#"
import { helper } from "./helper";
import { utils } from "../utils";
import { shared } from "/f/shared/lib";
import lodash from "lodash";
export async function main() { return helper() + utils() + shared(); }
"#;
let result = parse_relative_imports(code, "f/folder/script").unwrap();
// Should only include relative imports, not external packages like lodash
assert_eq!(result, vec!["f/folder/helper", "f/shared/lib", "f/utils"]);
}
#[test]
fn test_relative_imports_with_ts_extension() {
let code = r#"
import { helper } from "./helper.ts";
export async function main() { return helper(); }
"#;
let result = parse_relative_imports(code, "f/folder/script").unwrap();
assert_eq!(result, vec!["f/folder/helper"]);
}
#[test]
fn test_relative_imports_external_only() {
let code = r#"
import lodash from "lodash";
import { something } from "@scope/package";
export async function main() { return lodash.map([]); }
"#;
let result = parse_relative_imports(code, "f/folder/script").unwrap();
assert!(result.is_empty());
}
#[test]
fn test_relative_imports_deeply_nested() {
let code = r#"
import { a } from "../../a";
import { b } from "../../../b";
export async function main() { return a() + b(); }
"#;
let result = parse_relative_imports(code, "f/one/two/three/script").unwrap();
assert_eq!(result, vec!["f/b", "f/one/a"]);
}
}