Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Dec 6, 2024
1 parent 503580b commit 2d6e1fe
Show file tree
Hide file tree
Showing 29 changed files with 141 additions and 139 deletions.
2 changes: 1 addition & 1 deletion src/docs/README.gen.md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const gen: Gen = ({origin_id}) => {
// TODO this is GitHub-specific
const root_link = `[${root_path}](/..)`;
const doc_files = search_fs(origin_dir);
const doc_paths: string[] = [];
const doc_paths: Array<string> = [];
for (const {path} of doc_files) {
if (path === output_file_name || !path.endsWith('.md')) {
continue;
Expand Down
20 changes: 10 additions & 10 deletions src/lib/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {z} from 'zod';
* The raw CLI ares are handled by `mri` - https://github.com/lukeed/mri
*/
export interface Args {
_?: string[];
_?: Array<string>;
help?: boolean;
[key: string]: Arg_Value;
}
Expand Down Expand Up @@ -65,19 +65,19 @@ export const parse_args = <
/**
* Serializes parsed `Args` for CLI commands.
*/
export const serialize_args = (args: Args): string[] => {
const result: string[] = [];
export const serialize_args = (args: Args): Array<string> => {
const result: Array<string> = [];
const add_value = (name: string, value: string | number | boolean | undefined): void => {
if (value === undefined) return;
result.push(name);
if (typeof value !== 'boolean') {
result.push(value + '');
}
};
let _: string[] | null = null;
let _: Array<string> | null = null;
for (const [key, value] of Object.entries(args)) {
if (key === '_') {
_ = value ? (value as any[]).map((v) => (v === undefined ? '' : v + '')) : [];
_ = value ? (value as Array<any>).map((v) => (v === undefined ? '' : v + '')) : [];
} else {
const name = `${key.length === 1 ? '-' : '--'}${key}`;
if (Array.isArray(value)) {
Expand Down Expand Up @@ -105,7 +105,7 @@ export const to_task_args = (argv = process.argv): {task_name: string; args: Arg
/**
* Gets the array of raw string args starting with the first `--`, if any.
*/
export const to_raw_rest_args = (argv = process.argv): string[] => {
export const to_raw_rest_args = (argv = process.argv): Array<string> => {
const forwarded_index = argv.indexOf('--');
return forwarded_index === -1 ? [] : argv.slice(forwarded_index);
};
Expand All @@ -118,16 +118,16 @@ export const to_raw_rest_args = (argv = process.argv): string[] => {
*/
export const to_forwarded_args = (
command: string,
raw_rest_args?: string[],
raw_rest_args?: Array<string>,
cache = to_forwarded_args_by_command(raw_rest_args),
): Args => cache[command] ?? {};

export const to_forwarded_args_by_command = (
raw_rest_args = to_raw_rest_args(),
): Record<string, Args | undefined> => {
// Parse each segment of `argv` separated by `--`.
const argvs: string[][] = [];
let arr: string[] | undefined;
const argvs: Array<Array<string>> = [];
let arr: Array<string> | undefined;
for (const arg of raw_rest_args) {
if (arg === '--') {
if (arr?.length) argvs.push(arr);
Expand Down Expand Up @@ -165,7 +165,7 @@ export const to_forwarded_args_by_command = (
return forwarded_args_by_command;
};

export const print_command_args = (serialized_args: string[]): string =>
export const print_command_args = (serialized_args: Array<string>): string =>
st('gray', '[') +
st('magenta', 'running command') +
st('gray', ']') +
Expand Down
6 changes: 3 additions & 3 deletions src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const find_cli = (
*/
export const spawn_cli = async (
name_or_cli: string | Cli,
args: string[] = [],
args: Array<string> = [],
log?: Logger,
options?: SpawnOptions,
): Promise<Spawn_Result | undefined> => {
Expand All @@ -63,7 +63,7 @@ export const spawn_cli = async (
*/
export const spawn_cli_process = (
name_or_cli: string | Cli,
args: string[] = [],
args: Array<string> = [],
log?: Logger,
options?: SpawnOptions,
): Spawned_Process | undefined => {
Expand All @@ -74,7 +74,7 @@ export const spawn_cli_process = (

export const resolve_cli = (
name_or_cli: string | Cli,
args: string[] = [],
args: Array<string> = [],
cwd: string | URL | undefined,
log?: Logger,
options?: SpawnOptions,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/esbuild_plugin_external_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export interface Esbuild_Plugin_External_Worker_Options {
dir?: string;
svelte_compile_options?: CompileOptions;
svelte_compile_module_options?: ModuleCompileOptions;
svelte_preprocessors?: PreprocessorGroup | PreprocessorGroup[];
svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
alias?: Record<string, string>;
base_url?: Parsed_Sveltekit_Config['base_url'];
assets_url?: Parsed_Sveltekit_Config['assets_url'];
public_prefix?: string;
private_prefix?: string;
env_dir?: string;
env_files?: string[];
env_files?: Array<string>;
ambient_env?: Record<string, string>;
log?: Logger;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/esbuild_plugin_svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Esbuild_Plugin_Svelte_Options {
dir?: string;
svelte_compile_options?: CompileOptions;
svelte_compile_module_options?: ModuleCompileOptions;
svelte_preprocessors?: PreprocessorGroup | PreprocessorGroup[];
svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
ts_transform_options?: esbuild.TransformOptions;
is_ts?: (filename: string) => boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/esbuild_plugin_sveltekit_shim_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Esbuild_Plugin_Sveltekit_Shim_Env_Options {
public_prefix?: string;
private_prefix?: string;
env_dir?: string;
env_files?: string[];
env_files?: Array<string>;
ambient_env?: Record<string, string>;
}

Expand Down
54 changes: 28 additions & 26 deletions src/lib/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const is_gen_path = (path: string): boolean => path.includes(GEN_FILE_PAT

export interface Gen_Result {
origin_id: Path_Id;
files: Gen_File[];
files: Array<Gen_File>;
}
export interface Gen_File {
id: Path_Id;
Expand All @@ -52,7 +52,7 @@ export interface Gen_Context {
log: Logger;
}
// TODO consider other return data - metadata? effects? non-file build artifacts?
export type Raw_Gen_Result = string | Raw_Gen_File | null | Raw_Gen_Result[];
export type Raw_Gen_Result = string | Raw_Gen_File | null | Array<Raw_Gen_Result>;
export interface Raw_Gen_File {
content: string;
// Defaults to file name without the `.gen`, and can be a relative path.
Expand All @@ -67,9 +67,9 @@ export const Gen_Config = z.object({
export type Gen_Config = z.infer<typeof Gen_Config>;

export interface Gen_Results {
results: Genfile_Module_Result[];
successes: Genfile_Module_Result_Success[];
failures: Genfile_Module_Result_Failure[];
results: Array<Genfile_Module_Result>;
successes: Array<Genfile_Module_Result_Success>;
failures: Array<Genfile_Module_Result_Failure>;
input_count: number;
output_count: number;
elapsed: number;
Expand All @@ -78,7 +78,7 @@ export type Genfile_Module_Result = Genfile_Module_Result_Success | Genfile_Modu
export interface Genfile_Module_Result_Success {
ok: true;
id: Path_Id;
files: Gen_File[];
files: Array<Gen_File>;
elapsed: number;
}
export interface Genfile_Module_Result_Failure {
Expand All @@ -96,7 +96,7 @@ export const to_gen_result = (origin_id: Path_Id, raw_result: Raw_Gen_Result): G
};
};

const to_gen_files = (origin_id: Path_Id, raw_result: Raw_Gen_Result): Gen_File[] => {
const to_gen_files = (origin_id: Path_Id, raw_result: Raw_Gen_Result): Array<Gen_File> => {
if (raw_result === null) {
return [];
} else if (typeof raw_result === 'string') {
Expand Down Expand Up @@ -147,7 +147,7 @@ export const to_output_file_name = (filename: string): string => {
`Invalid gen file name - only one additional extension is allowed to follow '${GEN_FILE_PATTERN}' in '${filename}'`,
);
}
const final_parts: string[] = [];
const final_parts: Array<string> = [];
const has_different_ext = gen_pattern_index === parts.length - 3;
const length = has_different_ext ? parts.length - 1 : parts.length;
for (let i = 0; i < length; i++) {
Expand All @@ -158,7 +158,7 @@ export const to_output_file_name = (filename: string): string => {
return final_parts.join('.');
};

const validate_gen_files = (files: Gen_File[]) => {
const validate_gen_files = (files: Array<Gen_File>) => {
const ids = new Set();
for (const file of files) {
if (ids.has(file.id)) {
Expand All @@ -182,7 +182,9 @@ export type Analyzed_Gen_Result =
has_changed: true;
};

export const analyze_gen_results = (gen_results: Gen_Results): Promise<Analyzed_Gen_Result[]> =>
export const analyze_gen_results = (
gen_results: Gen_Results,
): Promise<Array<Analyzed_Gen_Result>> =>
Promise.all(
gen_results.successes
.map((result) => result.files.map((file) => analyze_gen_result(file)))
Expand All @@ -209,7 +211,7 @@ export const analyze_gen_result = async (file: Gen_File): Promise<Analyzed_Gen_R

export const write_gen_results = async (
gen_results: Gen_Results,
analyzed_gen_results: Analyzed_Gen_Result[],
analyzed_gen_results: Array<Analyzed_Gen_Result>,
log: Logger,
): Promise<void> => {
await Promise.all(
Expand All @@ -236,38 +238,38 @@ export const write_gen_results = async (
};

export interface Found_Genfiles {
resolved_input_files: Resolved_Input_File[];
resolved_input_files_by_root_dir: Map<Path_Id, Resolved_Input_File[]>;
resolved_input_paths: Resolved_Input_Path[];
resolved_input_files: Array<Resolved_Input_File>;
resolved_input_files_by_root_dir: Map<Path_Id, Array<Resolved_Input_File>>;
resolved_input_paths: Array<Resolved_Input_Path>;
}

export type Find_Genfiles_Result = Result<{value: Found_Genfiles}, Find_Genfiles_Failure>;
export type Find_Genfiles_Failure =
| {
type: 'unmapped_input_paths';
unmapped_input_paths: Input_Path[];
resolved_input_paths: Resolved_Input_Path[];
reasons: string[];
unmapped_input_paths: Array<Input_Path>;
resolved_input_paths: Array<Resolved_Input_Path>;
reasons: Array<string>;
}
| {
type: 'input_directories_with_no_files';
input_directories_with_no_files: Input_Path[];
resolved_input_files: Resolved_Input_File[];
resolved_input_files_by_root_dir: Map<Path_Id, Resolved_Input_File[]>;
resolved_input_paths: Resolved_Input_Path[];
reasons: string[];
input_directories_with_no_files: Array<Input_Path>;
resolved_input_files: Array<Resolved_Input_File>;
resolved_input_files_by_root_dir: Map<Path_Id, Array<Resolved_Input_File>>;
resolved_input_paths: Array<Resolved_Input_Path>;
reasons: Array<string>;
};

/**
* Finds modules from input paths. (see `src/lib/input_path.ts` for more)
*/
export const find_genfiles = (
input_paths: Input_Path[],
root_dirs: Path_Id[],
input_paths: Array<Input_Path>,
root_dirs: Array<Path_Id>,
config: Gro_Config,
timings?: Timings,
): Find_Genfiles_Result => {
const extensions: string[] = [GEN_FILE_PATTERN];
const extensions: Array<string> = [GEN_FILE_PATTERN];

// Check which extension variation works - if it's a directory, prefer others first!
const timing_to_resolve_input_paths = timings?.start('resolve input paths');
Expand Down Expand Up @@ -334,7 +336,7 @@ export interface Genfile_Module {
export type Genfile_Module_Meta = Module_Meta<Genfile_Module>;

export interface Loaded_Genfiles {
modules: Genfile_Module_Meta[];
modules: Array<Genfile_Module_Meta>;
found_genfiles: Found_Genfiles;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export const github_fetch_commit_prs = async (
log?: Logger,
cache?: Fetch_Value_Cache,
api_version?: string,
): Promise<Github_Pull_Request[] | null> => {
): Promise<Array<Github_Pull_Request> | null> => {
const headers = api_version ? new Headers({'x-github-api-version': api_version}) : undefined;
const url = `https://api.github.com/repos/${owner}/${repo}/commits/${commit_sha}/pulls`;
const fetched = await fetch_value(url, {
request: {headers},
parse: (v: any[]) => v.map((p) => Github_Pull_Request.parse(p)),
parse: (v: Array<any>) => v.map((p) => Github_Pull_Request.parse(p)),
token,
cache,
return_early_from_cache: true,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/gro_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export interface Gro_Config extends Raw_Gro_Config {
* The root directories to search for tasks given implicit relative input paths.
* Defaults to `./src/lib`, then the cwd, then the Gro package dist.
*/
task_root_dirs: Path_Id[];
task_root_dirs: Array<Path_Id>;
/**
* When searching the filsystem for tasks and genfiles,
* directories and files are included if they pass all of these filters.
*/
search_filters: Path_Filter[];
search_filters: Array<Path_Filter>;
/**
* The CLI to use that's compatible with `node`.
*/
Expand All @@ -60,8 +60,8 @@ export interface Gro_Config extends Raw_Gro_Config {
export interface Raw_Gro_Config {
plugins?: Create_Config_Plugins;
map_package_json?: Map_Package_Json | null;
task_root_dirs?: string[];
search_filters?: Path_Filter | Path_Filter[] | null;
task_root_dirs?: Array<string>;
search_filters?: Path_Filter | Array<Path_Filter> | null;
js_cli?: string;
pm_cli?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gro_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const resolve_gro_module_path = (path = ''): string => {
export const spawn_with_loader = (
loader_path: string,
invoke_path: string,
argv: string[],
argv: Array<string>,
js_cli = JS_CLI_DEFAULT, // TODO source from config when possible
): Promise<Spawn_Result> => {
const args = [
Expand Down
6 changes: 3 additions & 3 deletions src/lib/gro_plugin_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface Task_Args extends Args {
}

export interface Gro_Plugin_Gen_Options {
input_paths?: string[];
root_dirs?: string[];
input_paths?: Array<string>;
root_dirs?: Array<string>;
flush_debounce_delay?: number;
}

Expand Down Expand Up @@ -46,7 +46,7 @@ export const gro_plugin_gen = ({
},
{delay: flush_debounce_delay},
);
const gen = (files: string[] = []) => spawn_cli('gro', ['gen', ...files]);
const gen = (files: Array<string> = []) => spawn_cli('gro', ['gen', ...files]);

let cleanup: Cleanup_Watch | undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/gro_plugin_moss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Task_Args extends Args {
}

export interface Gro_Plugin_Moss_Options {
include_classes?: string[] | Set<string> | null;
include_classes?: Array<string> | Set<string> | null;
outfile?: string;
filter_file?: File_Filter | null;
flush_debounce_delay?: number;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/gro_plugin_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Gro_Plugin_Server_Options {
/**
* same as esbuild's `entryPoints`
*/
entry_points?: string[];
entry_points?: Array<string>;
/**
* @default cwd
*/
Expand All @@ -51,7 +51,7 @@ export interface Gro_Plugin_Server_Options {
/**
* @default SvelteKit's `.env`, `.env.development`, and `.env.production`
*/
env_files?: string[];
env_files?: Array<string>;
/**
* @default process.env
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gro_plugin_sveltekit_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const gro_plugin_sveltekit_app = ({
// copy files to `static` before building, in such a way
// that's non-destructive to existing files and dirs and easy to clean up
const {assets_path} = default_sveltekit_config;
const cleanups: Cleanup[] = [
const cleanups: Array<Cleanup> = [
serialized_package_json
? create_temporarily(
join(assets_path, '.well-known/package.json'),
Expand Down
Loading

0 comments on commit 2d6e1fe

Please sign in to comment.