@ryanatkn/gro 0.129.8 → 0.129.9

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.
@@ -1,46 +0,0 @@
1
- import {suite} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
-
4
- import {is_external_module} from './module.js';
5
-
6
- /* test__is_external_module */
7
- const test__is_external_module = suite('is_external_module');
8
-
9
- test__is_external_module('internal browser module patterns', () => {
10
- assert.is(is_external_module('./foo'), false);
11
- assert.is(is_external_module('./foo.js'), false);
12
- assert.is(is_external_module('../foo'), false);
13
- assert.is(is_external_module('../foo.js'), false);
14
- assert.is(is_external_module('../../../foo'), false);
15
- assert.is(is_external_module('../../../foo.js'), false);
16
- assert.is(is_external_module('/foo'), false);
17
- assert.is(is_external_module('/foo.js'), false);
18
- assert.is(is_external_module('src/foo'), false);
19
- assert.is(is_external_module('src/foo.js'), false);
20
- assert.is(is_external_module('$lib/foo'), false);
21
- assert.is(is_external_module('$lib/foo.js'), false);
22
- assert.is(is_external_module('./foo/bar/baz'), false);
23
- assert.is(is_external_module('./foo/bar/baz.js'), false);
24
- assert.is(is_external_module('../foo/bar/baz'), false);
25
- assert.is(is_external_module('../foo/bar/baz.js'), false);
26
- assert.is(is_external_module('../../../foo/bar/baz'), false);
27
- assert.is(is_external_module('../../../foo/bar/baz.js'), false);
28
- assert.is(is_external_module('/foo/bar/baz'), false);
29
- assert.is(is_external_module('/foo/bar/baz.js'), false);
30
- assert.is(is_external_module('src/foo/bar/baz'), false);
31
- assert.is(is_external_module('src/foo/bar/baz.js'), false);
32
- assert.is(is_external_module('$lib/foo/bar/baz'), false);
33
- assert.is(is_external_module('$lib/foo/bar/baz.js'), false);
34
- });
35
-
36
- test__is_external_module('external browser module patterns', () => {
37
- assert.is(is_external_module('foo'), true);
38
- assert.is(is_external_module('foo.js'), true);
39
- assert.is(is_external_module('foo/bar/baz'), true);
40
- assert.is(is_external_module('foo/bar/baz.js'), true);
41
- assert.is(is_external_module('@foo/bar/baz'), true);
42
- assert.is(is_external_module('@foo/bar/baz.js'), true);
43
- });
44
-
45
- test__is_external_module.run();
46
- /* test__is_external_module */
@@ -1,63 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {resolve} from 'node:path';
4
-
5
- import {load_module} from './modules.js';
6
-
7
- // TODO if we import directly, svelte-package generates types in `src/fixtures`
8
- /* eslint-disable no-useless-concat */
9
- const mod_test1 = await import('../fixtures/' + 'test1.foo.js');
10
-
11
- test('load_module basic behavior', async () => {
12
- const id = resolve('src/fixtures/test1.foo.js');
13
- let validated_mod;
14
- const result = await load_module(id, (mod): mod is any => {
15
- validated_mod = mod;
16
- return true;
17
- });
18
- assert.ok(result.ok);
19
- assert.is(result.id, id);
20
- assert.is(result.mod, validated_mod);
21
- assert.is(result.mod, mod_test1);
22
- });
23
-
24
- test('load_module without validation', async () => {
25
- const id = resolve('src/fixtures/test1.foo.js');
26
- const result = await load_module(id);
27
- assert.ok(result.ok);
28
- assert.is(result.id, id);
29
- assert.is(result.mod, mod_test1);
30
- });
31
-
32
- test('load_module fails validation', async () => {
33
- const id = resolve('src/fixtures/test1.foo.js');
34
- let validated_mod;
35
- const test_validation = (mod: Record<string, any>) => {
36
- validated_mod = mod;
37
- return false;
38
- };
39
- const result = await load_module(id, test_validation as any);
40
- assert.ok(!result.ok);
41
- if (result.type === 'failed_validation') {
42
- assert.is(result.validation, test_validation.name);
43
- assert.is(result.id, id);
44
- assert.is(result.mod, validated_mod);
45
- assert.is(result.mod, mod_test1);
46
- } else {
47
- throw Error('Should be invalid');
48
- }
49
- });
50
-
51
- test('load_module fails to import', async () => {
52
- const id = resolve('foo/test/failure');
53
- const result = await load_module(id);
54
- assert.ok(!result.ok);
55
- if (result.type === 'failed_import') {
56
- assert.is(result.id, id);
57
- assert.ok(result.error instanceof Error);
58
- } else {
59
- throw Error('Should fail to import');
60
- }
61
- });
62
-
63
- test.run();
@@ -1,101 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
-
4
- import {
5
- Package_Json,
6
- load_package_json,
7
- parse_repo_url,
8
- serialize_package_json,
9
- to_package_exports,
10
- } from './package_json.js';
11
-
12
- test('load_package_json', () => {
13
- const package_json = load_package_json();
14
- assert.ok(package_json);
15
- const parsed = Package_Json.parse(package_json);
16
- assert.ok(parsed);
17
- serialize_package_json(package_json);
18
- });
19
-
20
- test('load_package_json with cache', () => {
21
- const cache = {};
22
- const package_json1 = load_package_json(undefined, cache);
23
- assert.ok(package_json1);
24
- assert.is(Object.keys(cache).length, 1);
25
- const package_json2 = load_package_json(undefined, cache);
26
- assert.is(Object.keys(cache).length, 1);
27
- assert.is(package_json1, package_json2);
28
- });
29
-
30
- test('Package_Json.parse', () => {
31
- Package_Json.parse({name: 'abc', version: '123'});
32
- });
33
-
34
- test('Package_Json.parse fails with bad data', () => {
35
- let err;
36
- try {
37
- Package_Json.parse({version: '123'});
38
- } catch (_err) {
39
- err = _err;
40
- }
41
- assert.ok(err);
42
- });
43
-
44
- test('serialize_package_json', () => {
45
- serialize_package_json({name: 'abc', version: '123'});
46
- });
47
-
48
- test('serialize_package_json fails with bad data', () => {
49
- let err;
50
- try {
51
- serialize_package_json({version: '123'} as any);
52
- } catch (_err) {
53
- err = _err;
54
- }
55
- assert.ok(err);
56
- });
57
-
58
- test('to_package_exports', () => {
59
- assert.equal(to_package_exports(['a/b.ts']), {
60
- './package.json': './package.json',
61
- './a/b.js': {
62
- default: './dist/a/b.js',
63
- types: './dist/a/b.d.ts',
64
- },
65
- });
66
- assert.equal(
67
- to_package_exports([
68
- 'a/b/Some_Test_Svelte.svelte',
69
- 'a/b/some_test_ts.ts',
70
- 'a/b/some_test_json.json',
71
- 'index.ts',
72
- ]),
73
- {
74
- '.': {
75
- default: './dist/index.js',
76
- types: './dist/index.d.ts',
77
- },
78
- './package.json': './package.json',
79
- './a/b/some_test_json.json': {
80
- default: './dist/a/b/some_test_json.json',
81
- },
82
- './a/b/Some_Test_Svelte.svelte': {
83
- svelte: './dist/a/b/Some_Test_Svelte.svelte',
84
- default: './dist/a/b/Some_Test_Svelte.svelte',
85
- types: './dist/a/b/Some_Test_Svelte.svelte.d.ts',
86
- },
87
- './a/b/some_test_ts.js': {
88
- default: './dist/a/b/some_test_ts.js',
89
- types: './dist/a/b/some_test_ts.d.ts',
90
- },
91
- },
92
- );
93
- });
94
-
95
- test('parse_repo_url', () => {
96
- const parsed = parse_repo_url(load_package_json());
97
- assert.is(parsed?.owner, 'ryanatkn');
98
- assert.is(parsed?.repo, 'gro');
99
- });
100
-
101
- test.run();
@@ -1,77 +0,0 @@
1
- import {suite} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {resolve, join} from 'node:path';
4
-
5
- import {
6
- create_paths,
7
- paths,
8
- gro_paths,
9
- is_gro_id,
10
- to_root_path,
11
- path_id_to_base_path,
12
- base_path_to_path_id,
13
- } from './paths.js';
14
-
15
- /* test__create_paths */
16
- const test__create_paths = suite('create_paths');
17
-
18
- test__create_paths('basic behavior', () => {
19
- const root = resolve('../fake');
20
- const p = create_paths(root);
21
- assert.is(p.root, join(root, '/'));
22
- assert.is(p.source, join(root, 'src/'));
23
- });
24
-
25
- test__create_paths('paths object has the same identity as the gro_paths object', () => {
26
- assert.is(paths, gro_paths); // because we're testing inside the Gro project
27
- });
28
-
29
- test__create_paths.run();
30
- /* test__create_paths */
31
-
32
- /* test__is_gro_id */
33
- const test__is_gro_id = suite('is_gro_id');
34
-
35
- test__is_gro_id('basic behavior', () => {
36
- assert.ok(is_gro_id(resolve(paths.source)));
37
- assert.ok(!is_gro_id(resolve('../fake/src')));
38
- });
39
-
40
- test__is_gro_id.run();
41
- /* test__is_gro_id */
42
-
43
- /* test__to_root_path */
44
- const test__to_root_path = suite('to_root_path');
45
-
46
- test__to_root_path('basic behavior', () => {
47
- assert.is(to_root_path(resolve('foo/bar')), 'foo/bar');
48
- assert.is(to_root_path(resolve('./')), './');
49
- assert.is(to_root_path(resolve('./')), './');
50
- });
51
-
52
- test__to_root_path.run();
53
- /* test__to_root_path */
54
-
55
- /* test__path_id_to_base_path */
56
- const test__path_id_to_base_path = suite('path_id_to_base_path');
57
-
58
- test__path_id_to_base_path('basic behavior', () => {
59
- assert.is(path_id_to_base_path(resolve('src/foo/bar/baz.ts')), 'foo/bar/baz.ts');
60
- });
61
-
62
- test__path_id_to_base_path.run();
63
- /* test__path_id_to_base_path */
64
-
65
- /* test__base_path_to_path_id */
66
- const test__base_path_to_path_id = suite('base_path_to_path_id');
67
-
68
- test__base_path_to_path_id('basic behavior', () => {
69
- assert.is(base_path_to_path_id('foo/bar/baz.ts'), resolve('src/foo/bar/baz.ts'));
70
- });
71
-
72
- test__base_path_to_path_id('does not change extension', () => {
73
- assert.is(base_path_to_path_id('foo/bar/baz.js'), resolve('src/foo/bar/baz.js'));
74
- });
75
-
76
- test__base_path_to_path_id.run();
77
- /* test__base_path_to_path_id */
@@ -1,57 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
-
4
- import {replace_plugin} from './plugin.js';
5
-
6
- test('replace_plugin', () => {
7
- const a = {name: 'a'};
8
- const b = {name: 'b'};
9
- const c = {name: 'c'};
10
- const plugins = [a, b, c];
11
- const a2 = {name: 'a'};
12
- const b2 = {name: 'b'};
13
- const c2 = {name: 'c'};
14
- let p = plugins;
15
- p = replace_plugin(p, a2);
16
- assert.is(p[0], a2);
17
- assert.is(p[1], b);
18
- assert.is(p[2], c);
19
- p = replace_plugin(p, b2);
20
- assert.is(p[0], a2);
21
- assert.is(p[1], b2);
22
- assert.is(p[2], c);
23
- // allows duplicate names in the array
24
- p = replace_plugin(p, c2, 'a');
25
- assert.is(p[0], c2);
26
- assert.is(p[1], b2);
27
- assert.is(p[2], c);
28
- p = replace_plugin(p, a2, 'c');
29
- assert.is(p[0], a2);
30
- assert.is(p[1], b2);
31
- assert.is(p[2], c);
32
- p = replace_plugin(p, c2);
33
- assert.is(p[0], a2);
34
- assert.is(p[1], b2);
35
- assert.is(p[2], c2);
36
- });
37
-
38
- test('replace_plugin without an array', () => {
39
- const a = {name: 'a'};
40
- const a2 = {name: 'a'};
41
- const p = replace_plugin(a, a2);
42
- assert.is(p[0], a2);
43
- });
44
-
45
- test('replace_plugin throws if it cannot find the given name', () => {
46
- const a = {name: 'a'};
47
- const plugins = [a];
48
- let err;
49
- try {
50
- replace_plugin(plugins, {name: 'b'});
51
- } catch (_err) {
52
- err = _err;
53
- }
54
- if (!err) assert.unreachable('should have failed');
55
- });
56
-
57
- test.run();
@@ -1,31 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
-
4
- import {resolve_node_specifier} from './resolve_node_specifier.js';
5
- import {paths} from './paths.js';
6
-
7
- test('resolves a JS specifier', () => {
8
- assert.is(
9
- resolve_node_specifier('@ryanatkn/fuz/tome.js'),
10
- paths.root + 'node_modules/@ryanatkn/fuz/dist/tome.js',
11
- );
12
- });
13
-
14
- test('resolves a Svelte specifier', () => {
15
- assert.is(
16
- resolve_node_specifier('@ryanatkn/fuz/Library.svelte'),
17
- paths.root + 'node_modules/@ryanatkn/fuz/dist/Library.svelte',
18
- );
19
- });
20
-
21
- test('throws for a specifier that does not exist', () => {
22
- let err;
23
- try {
24
- resolve_node_specifier('@ryanatkn/fuz/this_does_not_exist');
25
- } catch (_err) {
26
- err = _err;
27
- }
28
- assert.ok(err);
29
- });
30
-
31
- test.run();
@@ -1,76 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {join} from 'node:path';
4
-
5
- import {resolve_specifier} from './resolve_specifier.js';
6
- import {paths} from './paths.js';
7
-
8
- const dir = paths.source + 'fixtures/';
9
-
10
- test('resolves a specifier to a file that exists with an unknown file extension', () => {
11
- assert.equal(resolve_specifier(join(dir, 'test_file.other.ext'), dir), {
12
- specifier: './test_file.other.ext',
13
- path_id: join(dir, 'test_file.other.ext'),
14
- namespace: undefined,
15
- });
16
- });
17
-
18
- test('resolves a ts specifier', () => {
19
- assert.equal(resolve_specifier(join(dir, 'test_ts.ts'), dir), {
20
- specifier: './test_ts.js',
21
- path_id: join(dir, 'test_ts.ts'),
22
- namespace: 'sveltekit_local_imports_ts',
23
- });
24
- });
25
-
26
- test('resolves relative ts specifiers', () => {
27
- assert.equal(resolve_specifier('./test_ts.ts', dir), {
28
- specifier: './test_ts.js',
29
- path_id: join(dir, 'test_ts.ts'),
30
- namespace: 'sveltekit_local_imports_ts',
31
- });
32
- assert.equal(resolve_specifier('./a/b/test_ts.ts', dir), {
33
- specifier: './a/b/test_ts.js',
34
- path_id: join(dir, 'a/b/test_ts.ts'),
35
- namespace: 'sveltekit_local_imports_ts',
36
- });
37
- assert.equal(resolve_specifier('../../test_ts.ts', dir), {
38
- specifier: '../../test_ts.js',
39
- path_id: join(dir, '../../test_ts.ts'),
40
- namespace: 'sveltekit_local_imports_ts',
41
- });
42
- });
43
-
44
- test('resolves an extensionless specifier', () => {
45
- assert.equal(resolve_specifier(join(dir, 'test_ts'), dir), {
46
- specifier: './test_ts.js',
47
- path_id: join(dir, 'test_ts.ts'),
48
- namespace: 'sveltekit_local_imports_ts',
49
- });
50
- });
51
-
52
- test('resolves a js specifier', () => {
53
- assert.equal(resolve_specifier(join(dir, 'test_js.js'), dir), {
54
- specifier: './test_js.js',
55
- path_id: join(dir, 'test_js.js'),
56
- namespace: 'sveltekit_local_imports_js',
57
- });
58
- });
59
-
60
- test('resolves a js specifier as ts for a file that does not exist', () => {
61
- assert.equal(resolve_specifier(join(dir, 'test_missing.js'), dir), {
62
- specifier: './test_missing.js',
63
- path_id: join(dir, 'test_missing.ts'),
64
- namespace: 'sveltekit_local_imports_ts',
65
- });
66
- });
67
-
68
- test('resolves an extensionless specifier for a file that does not exist', () => {
69
- assert.equal(resolve_specifier(join(dir, 'test_missing'), dir), {
70
- specifier: './test_missing.js',
71
- path_id: join(dir, 'test_missing.ts'),
72
- namespace: 'sveltekit_local_imports_ts',
73
- });
74
- });
75
-
76
- test.run();
@@ -1,196 +0,0 @@
1
- import {suite} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {resolve, join} from 'node:path';
4
- import {Logger} from '@ryanatkn/belt/log.js';
5
- import {Timings} from '@ryanatkn/belt/timings.js';
6
-
7
- import type {Genfile_Module_Meta} from './gen.js';
8
- import {run_gen} from './run_gen.js';
9
- import {load_config} from './config.js';
10
-
11
- const log = new Logger('test__gen'); // TODO test logger?
12
-
13
- /* test__gen */
14
- const test__gen = suite('gen');
15
-
16
- test__gen('basic behavior', async () => {
17
- const path_id_a = resolve('src/foo.gen.ts');
18
- const path_id_bc = resolve('src/bar/bc');
19
- let file_a: undefined | {filename: string; content: string};
20
- let file_b: undefined | {filename: string; content: string};
21
- let file_c1: undefined | {filename: string; content: string};
22
- let file_c2: undefined | {filename: string; content: string};
23
- const mod_a: Genfile_Module_Meta = {
24
- id: path_id_a,
25
- mod: {
26
- gen: (ctx) => {
27
- assert.is(ctx.origin_id, path_id_a);
28
- if (file_a) throw Error('Already generated file_a');
29
- file_a = {
30
- filename: 'foo.ts',
31
- content: 'file_a',
32
- };
33
- return file_a.content; // here we return the shorthand version
34
- },
35
- },
36
- };
37
- const mod_b: Genfile_Module_Meta = {
38
- id: join(path_id_bc, 'mod_b.gen.ts'),
39
- mod: {
40
- gen: (ctx) => {
41
- assert.is(ctx.origin_id, mod_b.id);
42
- if (file_b) throw Error('Already generated file_b');
43
- file_b = {
44
- filename: 'output_b.ts',
45
- content: 'file_b',
46
- };
47
- return file_b;
48
- },
49
- },
50
- };
51
- const mod_c: Genfile_Module_Meta = {
52
- id: join(path_id_bc, 'mod_c.gen.ts'),
53
- mod: {
54
- gen: (ctx) => {
55
- assert.is(ctx.origin_id, mod_c.id);
56
- if (file_c1) throw Error('Already generated file_c1');
57
- if (file_c2) throw Error('Already generated file_c2');
58
- file_c1 = {
59
- filename: 'output_c1.ts',
60
- content: 'file_c1',
61
- };
62
- file_c2 = {
63
- filename: 'output_c2.ts',
64
- content: 'file_c2',
65
- };
66
- return [file_c1, file_c2];
67
- },
68
- },
69
- };
70
- const gen_modules_by_input_path = [mod_a, mod_b, mod_c];
71
- const gen_results = await run_gen(
72
- gen_modules_by_input_path,
73
- await load_config(),
74
- log,
75
- new Timings(),
76
- (content, opts) =>
77
- Promise.resolve(opts.filepath!.endsWith('output_b.ts') ? `${content}/*FORMATTED*/` : content),
78
- );
79
- assert.is(gen_results.input_count, 3);
80
- assert.is(gen_results.output_count, 4);
81
- assert.is(gen_results.successes.length, 3);
82
- assert.is(gen_results.failures.length, 0);
83
- assert.is(gen_results.results.length, 3);
84
- assert.is(gen_results.results[0], gen_results.successes[0]);
85
- assert.is(gen_results.results[1], gen_results.successes[1]);
86
- assert.is(gen_results.results[2], gen_results.successes[2]);
87
-
88
- const result_a = gen_results.results[0];
89
- assert.ok(result_a.ok);
90
- assert.ok(file_a);
91
- assert.equal(result_a.files, [
92
- {
93
- content: file_a.content,
94
- id: join(mod_a.id, '../', file_a.filename),
95
- origin_id: mod_a.id,
96
- format: true,
97
- },
98
- ]);
99
-
100
- const result_b = gen_results.results[1];
101
- assert.ok(result_b.ok);
102
- assert.ok(file_b);
103
- assert.equal(result_b.files, [
104
- {
105
- content: `${file_b.content}/*FORMATTED*/`,
106
- id: join(mod_b.id, '../', file_b.filename),
107
- origin_id: mod_b.id,
108
- format: true,
109
- },
110
- ]);
111
- const result_c = gen_results.results[2];
112
- assert.ok(result_c.ok);
113
- assert.ok(file_c1);
114
- assert.ok(file_c2);
115
- assert.equal(result_c.files, [
116
- {
117
- content: file_c1.content,
118
- id: join(mod_c.id, '../', file_c1.filename),
119
- origin_id: mod_c.id,
120
- format: true,
121
- },
122
- {
123
- content: file_c2.content,
124
- id: join(mod_c.id, '../', file_c2.filename),
125
- origin_id: mod_c.id,
126
- format: true,
127
- },
128
- ]);
129
- });
130
-
131
- test__gen('failing gen function', async () => {
132
- const path_id_a = resolve('src/foo.gen.ts');
133
- const path_idB = resolve('src/bar/baz');
134
- let file_b: undefined | {filename: string; content: string}; // no file_a because it's never generated
135
- let genError; // this error should be passed through to the result
136
- // This is the failing gen module.
137
- // It's ordered first to test that its failure doesn't cascade.
138
- const mod_a: Genfile_Module_Meta = {
139
- id: path_id_a,
140
- mod: {
141
- gen: () => {
142
- genError = Error('This fails for testing');
143
- throw genError;
144
- },
145
- },
146
- };
147
- const mod_b: Genfile_Module_Meta = {
148
- id: join(path_idB, 'mod_b.gen.ts'),
149
- mod: {
150
- gen: (ctx) => {
151
- assert.is(ctx.origin_id, mod_b.id);
152
- if (file_b) throw Error('Already generated file_b');
153
- file_b = {
154
- filename: 'output_b.ts',
155
- content: 'file_b',
156
- };
157
- return file_b;
158
- },
159
- },
160
- };
161
- const gen_modules_by_input_path: Genfile_Module_Meta[] = [mod_a, mod_b];
162
- const gen_results = await run_gen(
163
- gen_modules_by_input_path,
164
- await load_config(),
165
- log,
166
- new Timings(),
167
- );
168
- assert.is(gen_results.input_count, 2);
169
- assert.is(gen_results.output_count, 1);
170
- assert.is(gen_results.successes.length, 1);
171
- assert.is(gen_results.failures.length, 1);
172
- assert.is(gen_results.results.length, 2);
173
- assert.is(gen_results.results[0], gen_results.failures[0]);
174
- assert.is(gen_results.results[1], gen_results.successes[0]);
175
-
176
- const result_a = gen_results.results[0];
177
- assert.ok(result_a);
178
- assert.ok(!result_a.ok);
179
- assert.ok(result_a.reason);
180
- assert.ok(result_a.error);
181
-
182
- const result_b = gen_results.results[1];
183
- assert.ok(result_b.ok);
184
- assert.ok(file_b);
185
- assert.equal(result_b.files, [
186
- {
187
- content: file_b.content,
188
- id: join(mod_b.id, '../', file_b.filename),
189
- origin_id: mod_b.id,
190
- format: true,
191
- },
192
- ]);
193
- });
194
-
195
- test__gen.run();
196
- /* test__gen */