@ryanatkn/gro 0.122.0 → 0.123.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -122,7 +122,7 @@ lint run eslint
122
122
  publish bump version, publish to npm, and git push
123
123
  reinstall refreshes package-lock.json with the latest and cleanest deps
124
124
  release publish and deploy
125
- resolve run `gro gen`, update `package.json`, and optionally `npm i` to sync up
125
+ resolve diagnostic that logs resolved filesystem info for the given input paths
126
126
  run execute a file with the loader, like `node` but works for TypeScript
127
127
  sync run `gro gen`, update `package.json`, and optionally `npm i` to sync up
128
128
  test run tests with uvu
@@ -19,7 +19,7 @@ What is a `Task`? See [`task.md`](./task.md).
19
19
  - [publish](../publish.task.ts) - bump version, publish to npm, and git push
20
20
  - [reinstall](../reinstall.task.ts) - refreshes package-lock.json with the latest and cleanest deps
21
21
  - [release](../release.task.ts) - publish and deploy
22
- - [resolve](../resolve.task.ts) - diagnostic that logs the info resolved from the filesystem for the given input paths
22
+ - [resolve](../resolve.task.ts) - diagnostic that logs resolved filesystem info for the given input paths
23
23
  - [run](../run.task.ts) - execute a file with the loader, like `node` but works for TypeScript
24
24
  - [sync](../sync.task.ts) - run `gro gen`, update `package.json`, and optionally `npm i` to sync up
25
25
  - [test](../test.task.ts) - run tests with uvu
@@ -134,6 +134,10 @@ export const resolve_input_files = (resolved_input_paths, search = search_fs) =>
134
134
  const resolved_input_files = [];
135
135
  // Add all input paths initially, and remove each when resolved to a file.
136
136
  const existing_path_ids = new Set();
137
+ let remaining = resolved_input_paths.slice();
138
+ const handle_found = (input_path, id) => {
139
+ remaining = remaining.filter((r) => !(r.id === id || r.input_path === input_path || r.input_path === id));
140
+ };
137
141
  // TODO parallelize but would need to de-dupe and retain order
138
142
  for (const resolved_input_path of resolved_input_paths) {
139
143
  const { input_path, id, is_directory } = resolved_input_path;
@@ -151,6 +155,7 @@ export const resolve_input_files = (resolved_input_paths, search = search_fs) =>
151
155
  existing_path_ids.add(path_id);
152
156
  path_ids.push(path_id);
153
157
  }
158
+ handle_found(input_path, path_id);
154
159
  }
155
160
  if (!path_ids.length)
156
161
  continue;
@@ -165,11 +170,14 @@ export const resolve_input_files = (resolved_input_paths, search = search_fs) =>
165
170
  resolved_input_files_for_input_path.push(resolved_input_file);
166
171
  }
167
172
  }
168
- else if (!existing_path_ids.has(id)) {
169
- // Handle input paths that resolve to files.
170
- existing_path_ids.add(id);
171
- const resolved_input_file = { id, input_path, resolved_input_path };
172
- resolved_input_files.push(resolved_input_file);
173
+ else {
174
+ if (!existing_path_ids.has(id)) {
175
+ // Handle input paths that resolve to files.
176
+ existing_path_ids.add(id);
177
+ const resolved_input_file = { id, input_path, resolved_input_path };
178
+ resolved_input_files.push(resolved_input_file);
179
+ }
180
+ handle_found(input_path, id);
173
181
  }
174
182
  }
175
183
  return {
@@ -184,6 +192,6 @@ export const resolve_input_files = (resolved_input_paths, search = search_fs) =>
184
192
  }
185
193
  return map;
186
194
  }, new Map()),
187
- input_directories_with_no_files: Array.from(new Set(resolved_input_paths.map((p) => p.input_path)).difference(new Set(resolved_input_files.map((f) => [f.input_path, f.id]).flat()))),
195
+ input_directories_with_no_files: remaining.map((r) => r.input_path),
188
196
  };
189
197
  };
@@ -92,25 +92,30 @@ test('get_possible_paths implied to be a directory by trailing slash', () => {
92
92
  });
93
93
  test('resolve_input_files', async () => {
94
94
  const test_files = {
95
- 'fake/test1.ext.ts': [{ id: '', path: 'fake/test1.ext.ts', is_directory: false }],
96
- 'fake/test2.ext.ts': [{ id: '', path: 'fake/test2.ext.ts', is_directory: false }],
95
+ 'fake/test1.ext.ts': [
96
+ { id: 'fake/test1.ext.ts', path: 'fake/test1.ext.ts', is_directory: false },
97
+ ],
98
+ 'fake/test2.ext.ts': [
99
+ { id: 'fake/test2.ext.ts', path: 'fake/test2.ext.ts', is_directory: false },
100
+ ],
97
101
  'fake/test3': [
98
- { id: '', path: 'fake/test3', is_directory: true },
99
- { id: '', path: 'a.ts', is_directory: false },
100
- { id: '', path: 'b.ts', is_directory: false },
102
+ { id: 'fake/test3', path: 'fake/test3', is_directory: true },
103
+ { id: 'a.ts', path: 'a.ts', is_directory: false },
104
+ { id: 'b.ts', path: 'b.ts', is_directory: false },
101
105
  ],
102
106
  // duplicate
103
107
  'fake/': [
104
- { id: '', path: 'fake/test3', is_directory: true },
105
- { id: '', path: 'test3/a.ts', is_directory: false },
108
+ { id: 'fake/test3', path: 'fake/test3', is_directory: true },
109
+ { id: 'test3/a.ts', path: 'test3/a.ts', is_directory: false },
106
110
  ],
107
111
  // duplicate and not
108
112
  fake: [
109
- { id: '', path: 'fake/test3', is_directory: true },
110
- { id: '', path: 'test3/a.ts', is_directory: false },
111
- { id: '', path: 'test3/c.ts', is_directory: false },
113
+ { id: 'fake/test3', path: 'fake/test3', is_directory: true },
114
+ { id: 'test3/a.ts', path: 'test3/a.ts', is_directory: false },
115
+ { id: 'test3/c.ts', path: 'test3/c.ts', is_directory: false },
112
116
  ],
113
- 'fake/nomatches': [{ id: '', path: 'fake/nomatches', is_directory: true }],
117
+ 'fake/nomatches': [{ id: 'fake/nomatches', path: 'fake/nomatches', is_directory: true }],
118
+ fake2: [{ id: 'test.ext.ts', path: 'test.ext.ts', is_directory: false }],
114
119
  };
115
120
  const a = {
116
121
  id: 'fake/test1.ext.ts',
@@ -142,13 +147,41 @@ test('resolve_input_files', async () => {
142
147
  input_path: 'fake/nomatches',
143
148
  root_dir: process.cwd(),
144
149
  };
145
- const result = resolve_input_files([a, b, c, d, e], (id) => test_files[id]);
150
+ // These two have the same id from different directory input paths.
151
+ const f = {
152
+ id: 'fake2',
153
+ is_directory: true,
154
+ input_path: 'fake2',
155
+ root_dir: process.cwd(),
156
+ };
157
+ const g = {
158
+ id: 'fake2',
159
+ is_directory: true,
160
+ input_path: './fake2/',
161
+ root_dir: process.cwd(),
162
+ };
163
+ // These two have the same id from different file input paths.
164
+ const h = {
165
+ id: 'fake3/test.ext.ts',
166
+ is_directory: false,
167
+ input_path: 'fake3/test.ext.ts',
168
+ root_dir: process.cwd(),
169
+ };
170
+ const i = {
171
+ id: 'fake3/test.ext.ts',
172
+ is_directory: false,
173
+ input_path: 'fake3/test',
174
+ root_dir: process.cwd(),
175
+ };
176
+ const result = resolve_input_files([a, b, c, d, e, f, g, h, i], (dir) => test_files[dir]);
146
177
  const resolved_input_files = [
147
178
  { id: a.id, input_path: a.input_path, resolved_input_path: a },
148
179
  { id: b.id, input_path: b.input_path, resolved_input_path: b },
149
180
  { id: 'fake/test3/a.ts', input_path: c.input_path, resolved_input_path: c },
150
181
  { id: 'fake/test3/b.ts', input_path: c.input_path, resolved_input_path: c },
151
182
  { id: 'fake/test3/c.ts', input_path: d.input_path, resolved_input_path: d },
183
+ { id: 'fake2/test.ext.ts', input_path: f.input_path, resolved_input_path: f },
184
+ { id: 'fake3/test.ext.ts', input_path: h.input_path, resolved_input_path: h },
152
185
  ];
153
186
  assert.equal(result, {
154
187
  resolved_input_files,
@@ -156,11 +189,13 @@ test('resolve_input_files', async () => {
156
189
  [
157
190
  process.cwd(),
158
191
  [
159
- { id: 'fake/test1.ext.ts', input_path: 'fake/test1.ext.ts', resolved_input_path: a },
160
- { id: 'fake/test2.ext.ts', input_path: 'fake/test2', resolved_input_path: b },
161
- { id: 'fake/test3/a.ts', input_path: 'fake/test3', resolved_input_path: c },
162
- { id: 'fake/test3/b.ts', input_path: 'fake/test3', resolved_input_path: c },
163
- { id: 'fake/test3/c.ts', input_path: 'fake', resolved_input_path: d },
192
+ { id: 'fake/test1.ext.ts', input_path: a.input_path, resolved_input_path: a },
193
+ { id: 'fake/test2.ext.ts', input_path: b.input_path, resolved_input_path: b },
194
+ { id: 'fake/test3/a.ts', input_path: c.input_path, resolved_input_path: c },
195
+ { id: 'fake/test3/b.ts', input_path: c.input_path, resolved_input_path: c },
196
+ { id: 'fake/test3/c.ts', input_path: d.input_path, resolved_input_path: d },
197
+ { id: 'fake2/test.ext.ts', input_path: f.input_path, resolved_input_path: f },
198
+ { id: 'fake3/test.ext.ts', input_path: h.input_path, resolved_input_path: h },
164
199
  ],
165
200
  ],
166
201
  ]),
package/dist/package.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // generated by src/lib/package.gen.ts
2
2
  export const package_json = {
3
3
  name: '@ryanatkn/gro',
4
- version: '0.122.0',
4
+ version: '0.123.0',
5
5
  description: 'task runner and toolkit extending SvelteKit',
6
6
  motto: 'generate, run, optimize',
7
7
  icon: '🌰',
@@ -58,8 +58,8 @@ export const package_json = {
58
58
  '@sveltejs/vite-plugin-svelte': '^3.1.1',
59
59
  '@types/fs-extra': '^11.0.4',
60
60
  '@types/node': '^20.14.8',
61
- '@typescript-eslint/eslint-plugin': '^7.13.1',
62
- '@typescript-eslint/parser': '^7.13.1',
61
+ '@typescript-eslint/eslint-plugin': '^7.14.1',
62
+ '@typescript-eslint/parser': '^7.14.1',
63
63
  esbuild: '^0.20.2',
64
64
  eslint: '^8.57.0',
65
65
  'eslint-plugin-svelte': '^2.41.0',
@@ -256,7 +256,7 @@ export const package_json = {
256
256
  };
257
257
  export const src_json = {
258
258
  name: '@ryanatkn/gro',
259
- version: '0.122.0',
259
+ version: '0.123.0',
260
260
  modules: {
261
261
  '.': {
262
262
  path: 'index.ts',
@@ -7,7 +7,7 @@ export const Args = z
7
7
  })
8
8
  .strict();
9
9
  export const task = {
10
- summary: 'diagnostic that logs the info resolved from the filesystem for the given input paths',
10
+ summary: 'diagnostic that logs resolved filesystem info for the given input paths',
11
11
  Args,
12
12
  run: async ({ args, config, log }) => {
13
13
  const { _ } = args;
package/dist/task.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare const TASK_FILE_SUFFIX_TS = ".task.ts";
26
26
  export declare const TASK_FILE_SUFFIX_JS = ".task.js";
27
27
  export declare const TASK_FILE_SUFFIXES: string[];
28
28
  export declare const is_task_path: (path: string) => boolean;
29
- export declare const to_task_name: (id: Path_Id, task_root_dir: Path_Id) => string;
29
+ export declare const to_task_name: (id: Path_Id, task_root_dir: Path_Id, input_path: Input_Path, root_path: Path_Id) => string;
30
30
  /**
31
31
  * This is used by tasks to signal a known failure.
32
32
  * It's useful for cleaning up logging because
@@ -84,5 +84,5 @@ export type Load_Tasks_Result = Result<{
84
84
  value: Loaded_Tasks;
85
85
  }, Load_Tasks_Failure>;
86
86
  export type Load_Tasks_Failure = Load_Modules_Failure<Task_Module_Meta>;
87
- export declare const load_tasks: (found_tasks: Found_Tasks) => Promise<Load_Tasks_Result>;
87
+ export declare const load_tasks: (found_tasks: Found_Tasks, root_path?: Path_Id) => Promise<Load_Tasks_Result>;
88
88
  export declare const validate_task_module: (mod: Record<string, any>) => mod is Task_Module;
package/dist/task.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { strip_end, strip_start } from '@ryanatkn/belt/string.js';
2
2
  import { red } from 'kleur/colors';
3
+ import { isAbsolute, join, relative } from 'node:path';
3
4
  import { resolve_input_files, resolve_input_paths, } from './input_path.js';
4
5
  import { print_path } from './paths.js';
5
6
  import { search_fs } from './search_fs.js';
@@ -8,13 +9,16 @@ export const TASK_FILE_SUFFIX_TS = '.task.ts';
8
9
  export const TASK_FILE_SUFFIX_JS = '.task.js';
9
10
  export const TASK_FILE_SUFFIXES = [TASK_FILE_SUFFIX_TS, TASK_FILE_SUFFIX_JS]; // TODO from `Gro_Config`, but needs to be used everywhere the constants are
10
11
  export const is_task_path = (path) => path.endsWith(TASK_FILE_SUFFIX_TS) || path.endsWith(TASK_FILE_SUFFIX_JS);
11
- export const to_task_name = (id, task_root_dir) => {
12
+ export const to_task_name = (id, task_root_dir, input_path, root_path) => {
12
13
  let task_name = id.startsWith(task_root_dir)
13
14
  ? strip_start(strip_start(id, task_root_dir), '/')
14
15
  : id;
15
16
  for (const suffix of TASK_FILE_SUFFIXES) {
16
17
  task_name = strip_end(task_name, suffix);
17
18
  }
19
+ if (isAbsolute(input_path)) {
20
+ return relative(root_path, join(input_path, task_name));
21
+ }
18
22
  return task_name;
19
23
  };
20
24
  /**
@@ -76,11 +80,11 @@ export const find_tasks = (input_paths, task_root_dirs, config, timings) => {
76
80
  },
77
81
  };
78
82
  };
79
- export const load_tasks = async (found_tasks) => {
83
+ export const load_tasks = async (found_tasks, root_path = process.cwd()) => {
80
84
  const loaded_modules = await load_modules(found_tasks.resolved_input_files, validate_task_module, (resolved_input_file, mod) => ({
81
85
  id: resolved_input_file.id,
82
86
  mod,
83
- name: to_task_name(resolved_input_file.id, resolved_input_file.resolved_input_path.root_dir),
87
+ name: to_task_name(resolved_input_file.id, resolved_input_file.resolved_input_path.root_dir, resolved_input_file.resolved_input_path.input_path, root_path),
84
88
  }));
85
89
  if (!loaded_modules.ok) {
86
90
  return loaded_modules;
package/dist/task.test.js CHANGED
@@ -12,12 +12,15 @@ test('is_task_path basic behavior', () => {
12
12
  assert.ok(!is_task_path('bar/baz/foo.ts'));
13
13
  });
14
14
  test('to_task_name basic behavior', () => {
15
- assert.is(to_task_name('foo.task.ts', process.cwd()), 'foo');
16
- assert.is(to_task_name('bar/baz/foo.task.ts', process.cwd()), 'bar/baz/foo');
17
- assert.is(to_task_name('a/b/c/foo.task.ts', 'a/b/c'), 'foo');
18
- assert.is(to_task_name('a/b/c/foo.task.ts', 'a'), 'b/c/foo');
19
- assert.is(to_task_name('a/b/c/foo.task.ts', 'a/b'), 'c/foo');
20
- assert.is(to_task_name(resolve('a/b'), resolve('b')), resolve('a/b'), 'falls back to the id when unresolved');
15
+ assert.is(to_task_name('foo.task.ts', process.cwd(), '', ''), 'foo');
16
+ assert.is(to_task_name('bar/baz/foo.task.ts', process.cwd(), '', ''), 'bar/baz/foo');
17
+ assert.is(to_task_name('a/b/c/foo.task.ts', 'a/b/c', '', ''), 'foo');
18
+ assert.is(to_task_name('a/b/c/foo.task.ts', 'a', '', ''), 'b/c/foo');
19
+ assert.is(to_task_name('a/b/c/foo.task.ts', 'a/b', '', ''), 'c/foo');
20
+ assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b/d'), '../c/foo');
21
+ assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b'), 'c/foo');
22
+ assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b/c'), 'foo');
23
+ assert.is(to_task_name(resolve('a/b'), resolve('b'), '', ''), resolve('a/b'), 'falls back to the id when unresolved');
21
24
  });
22
25
  // TODO if we import directly, svelte-package generates types in `src/fixtures`
23
26
  const test_task_module = await import('../fixtures/' + 'test_task_module.task_fixture'); // eslint-disable-line no-useless-concat
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.122.0",
3
+ "version": "0.123.0",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "motto": "generate, run, optimize",
6
6
  "icon": "🌰",
@@ -73,8 +73,8 @@
73
73
  "@sveltejs/vite-plugin-svelte": "^3.1.1",
74
74
  "@types/fs-extra": "^11.0.4",
75
75
  "@types/node": "^20.14.8",
76
- "@typescript-eslint/eslint-plugin": "^7.13.1",
77
- "@typescript-eslint/parser": "^7.13.1",
76
+ "@typescript-eslint/eslint-plugin": "^7.14.1",
77
+ "@typescript-eslint/parser": "^7.14.1",
78
78
  "esbuild": "^0.20.2",
79
79
  "eslint": "^8.57.0",
80
80
  "eslint-plugin-svelte": "^2.41.0",