@openwebf/webf 0.23.10 → 0.24.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/dist/commands.js +135 -7
- package/dist/generator.js +37 -36
- package/dist/module.js +43 -14
- package/dist/peerDeps.js +27 -0
- package/dist/react.js +10 -18
- package/dist/vue.js +138 -132
- package/package.json +1 -1
- package/src/commands.ts +153 -7
- package/src/generator.ts +38 -37
- package/src/module.ts +53 -21
- package/src/peerDeps.ts +21 -0
- package/src/react.ts +10 -18
- package/src/vue.ts +157 -142
- package/templates/react.component.tsx.tpl +2 -2
- package/templates/react.index.ts.tpl +2 -1
- package/templates/react.package.json.tpl +4 -5
- package/templates/react.tsconfig.json.tpl +8 -1
- package/templates/react.tsup.config.ts.tpl +1 -1
- package/templates/vue.component.partial.tpl +4 -4
- package/templates/vue.components.d.ts.tpl +24 -9
- package/templates/vue.package.json.tpl +4 -2
- package/test/commands.test.ts +77 -12
- package/test/generator.test.ts +17 -10
- package/test/peerDeps.test.ts +30 -0
- package/test/react-consts.test.ts +9 -3
- package/test/standard-props.test.ts +14 -14
- package/test/templates.test.ts +17 -0
- package/test/vue.test.ts +36 -11
- package/dist/constants.js +0 -242
|
@@ -8,8 +8,8 @@ export type <%= className %>Props = {
|
|
|
8
8
|
<% } %>
|
|
9
9
|
<% }); %>
|
|
10
10
|
'id'?: string;
|
|
11
|
-
'class'?:
|
|
12
|
-
'style'?:
|
|
11
|
+
'class'?: ClassValue;
|
|
12
|
+
'style'?: StyleValue;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface <%= className %>Element {
|
|
@@ -21,7 +21,7 @@ export interface <%= className %>Element {
|
|
|
21
21
|
<%= propName %>: <%= generateReturnType(prop.type) %>;
|
|
22
22
|
<% } %>
|
|
23
23
|
<% }); %>
|
|
24
|
-
<% _.forEach(
|
|
24
|
+
<% _.forEach(methods?.methods, function(method, index) { %>
|
|
25
25
|
<%= generateMethodDeclaration(method) %>
|
|
26
26
|
<% }); %>
|
|
27
27
|
}
|
|
@@ -29,6 +29,6 @@ export interface <%= className %>Element {
|
|
|
29
29
|
export type <%= className %>Events = {
|
|
30
30
|
<% _.forEach(events?.props, function(prop, index) { %>
|
|
31
31
|
<% var propName = prop.name; %>
|
|
32
|
-
<%= propName
|
|
32
|
+
<%= propName %>: <%= generateEventHandlerType(prop.type) %>;
|
|
33
33
|
<% }); %>
|
|
34
34
|
}
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
// Based on the Vue 3 documentation for defining custom elements:
|
|
5
5
|
// https://vuejs.org/guide/extras/web-components
|
|
6
|
-
import { EmitFn, PublicProps,
|
|
6
|
+
import type { EmitFn, PublicProps, StyleValue, ClassValue } from 'vue';
|
|
7
|
+
import '@openwebf/vue-core-ui';
|
|
7
8
|
|
|
8
|
-
<%=
|
|
9
|
+
<%= typeAliases %>
|
|
9
10
|
|
|
10
11
|
type EventMap = {
|
|
11
12
|
[event: string]: Event
|
|
@@ -13,29 +14,29 @@ type EventMap = {
|
|
|
13
14
|
|
|
14
15
|
// This maps an EventMap to the format that Vue's $emit type expects.
|
|
15
16
|
type VueEmit<T extends EventMap> = EmitFn<{
|
|
16
|
-
[K in keyof T]: (event: T[K]) => void
|
|
17
|
+
[K in keyof T]: (event: NonNullable<T[K]>) => void
|
|
17
18
|
}>
|
|
18
19
|
|
|
19
20
|
// Vue 3 event listener properties for template usage
|
|
20
21
|
type VueEventListeners<T extends EventMap> = {
|
|
21
|
-
[K in keyof T as `on${Capitalize<string & K>}`]?: (event: T[K]) => any
|
|
22
|
+
[K in keyof T as `on${Capitalize<string & K>}`]?: (event: NonNullable<T[K]>) => any
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
<%= consts %>
|
|
25
26
|
<%= enums %>
|
|
27
|
+
<%= dependencies %>
|
|
26
28
|
|
|
27
29
|
type DefineCustomElement<
|
|
28
30
|
ElementType,
|
|
31
|
+
Props,
|
|
29
32
|
Events extends EventMap = {},
|
|
30
|
-
SelectedAttributes extends keyof ElementType = keyof ElementType
|
|
31
33
|
> = new () => ElementType & VueEventListeners<Events> & {
|
|
32
34
|
// Use $props to define the properties exposed to template type checking. Vue
|
|
33
35
|
// specifically reads prop definitions from the `$props` type. Note that we
|
|
34
|
-
// combine the element's props with
|
|
35
|
-
// props.
|
|
36
|
+
// combine the element's props with Vue's special props.
|
|
36
37
|
/** @deprecated Do not use the $props property on a Custom Element ref,
|
|
37
38
|
this is for template prop types only. */
|
|
38
|
-
$props:
|
|
39
|
+
$props: Props & PublicProps & VueEventListeners<Events>
|
|
39
40
|
|
|
40
41
|
// Use $emit to specifically define event types. Vue specifically reads event
|
|
41
42
|
// types from the `$emit` type. Note that `$emit` expects a particular format
|
|
@@ -47,13 +48,27 @@ type DefineCustomElement<
|
|
|
47
48
|
|
|
48
49
|
<%= components %>
|
|
49
50
|
|
|
50
|
-
declare
|
|
51
|
+
declare const flutterAttached: (typeof import('@openwebf/vue-core-ui')) extends { flutterAttached: infer T } ? T : any;
|
|
52
|
+
|
|
53
|
+
declare module '@vue/runtime-core' {
|
|
54
|
+
interface GlobalDirectives {
|
|
55
|
+
vFlutterAttached: typeof flutterAttached;
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
interface GlobalComponents {
|
|
52
59
|
<% componentMetas.forEach(comp => { %>
|
|
53
60
|
'<%= comp.tagName %>': DefineCustomElement<
|
|
61
|
+
<%= comp.className %>Element,
|
|
54
62
|
<%= comp.className %>Props,
|
|
55
63
|
<%= comp.className %>Events
|
|
56
64
|
>
|
|
57
65
|
<% }) %>
|
|
58
66
|
}
|
|
59
67
|
}
|
|
68
|
+
|
|
69
|
+
// Some tooling (older IDE integrations) look for global directive/component typing
|
|
70
|
+
// augmentations on the `vue` module name instead of `@vue/runtime-core`.
|
|
71
|
+
declare module 'vue' {
|
|
72
|
+
interface GlobalDirectives extends import('@vue/runtime-core').GlobalDirectives {}
|
|
73
|
+
interface GlobalComponents extends import('@vue/runtime-core').GlobalComponents {}
|
|
74
|
+
}
|
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
"description": "<%= description %>",
|
|
5
5
|
"main": "",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
-
"files": ["index.d.ts"],
|
|
7
|
+
"files": ["index.d.ts", "README.md"],
|
|
8
8
|
"keywords": [],
|
|
9
9
|
"author": "",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"vue": "^3.0.0"
|
|
12
|
+
"vue": "^3.0.0",
|
|
13
|
+
"@openwebf/vue-core-ui": "^0.24.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
16
|
+
"@openwebf/vue-core-ui": "^0.24.0",
|
|
15
17
|
"vue": "^3.0.0"
|
|
16
18
|
}
|
|
17
19
|
}
|
package/test/commands.test.ts
CHANGED
|
@@ -230,8 +230,8 @@ describe('Commands', () => {
|
|
|
230
230
|
|
|
231
231
|
expect(mockSpawnSync).toHaveBeenCalledWith(
|
|
232
232
|
expect.stringMatching(/npm(\.cmd)?/),
|
|
233
|
-
['install'],
|
|
234
|
-
{ cwd: target, stdio: 'inherit' }
|
|
233
|
+
['install', '--production=false'],
|
|
234
|
+
expect.objectContaining({ cwd: target, stdio: 'inherit' })
|
|
235
235
|
);
|
|
236
236
|
});
|
|
237
237
|
});
|
|
@@ -283,18 +283,11 @@ describe('Commands', () => {
|
|
|
283
283
|
|
|
284
284
|
await generateCommand(target, options);
|
|
285
285
|
|
|
286
|
-
// Should install
|
|
286
|
+
// Should install dependencies (including devDependencies) from package.json
|
|
287
287
|
expect(mockSpawnSync).toHaveBeenCalledWith(
|
|
288
288
|
expect.stringMatching(/npm(\.cmd)?/),
|
|
289
|
-
['install', '
|
|
290
|
-
{ cwd: target, stdio: 'inherit' }
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
// Should install Vue 3 as dev dependency
|
|
294
|
-
expect(mockSpawnSync).toHaveBeenCalledWith(
|
|
295
|
-
expect.stringMatching(/npm(\.cmd)?/),
|
|
296
|
-
['install', 'vue', '-D'],
|
|
297
|
-
{ cwd: target, stdio: 'inherit' }
|
|
289
|
+
['install', '--production=false'],
|
|
290
|
+
expect.objectContaining({ cwd: target, stdio: 'inherit' })
|
|
298
291
|
);
|
|
299
292
|
});
|
|
300
293
|
});
|
|
@@ -463,6 +456,78 @@ describe('Commands', () => {
|
|
|
463
456
|
}));
|
|
464
457
|
});
|
|
465
458
|
|
|
459
|
+
it('should copy Flutter README.md into generated React package root', async () => {
|
|
460
|
+
const options = {
|
|
461
|
+
flutterPackageSrc: '/flutter/src',
|
|
462
|
+
framework: 'react',
|
|
463
|
+
packageName: 'test-package'
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// Mock TypeScript validation
|
|
467
|
+
mockTypeScriptValidation('/flutter/src');
|
|
468
|
+
|
|
469
|
+
const originalExistsSync = mockFs.existsSync as jest.Mock;
|
|
470
|
+
mockFs.existsSync = jest.fn().mockImplementation((filePath: any) => {
|
|
471
|
+
const pathStr = filePath.toString();
|
|
472
|
+
if (pathStr === '/flutter/src/README.md') return true;
|
|
473
|
+
if (pathStr === path.join(path.resolve('/dist'), 'README.md')) return false;
|
|
474
|
+
return originalExistsSync(filePath);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
const originalReadFileSync = mockFs.readFileSync as jest.Mock;
|
|
478
|
+
mockFs.readFileSync = jest.fn().mockImplementation((filePath: any, encoding?: any) => {
|
|
479
|
+
const pathStr = filePath.toString();
|
|
480
|
+
if (pathStr === '/flutter/src/README.md') {
|
|
481
|
+
return '# Flutter README\n\nHello';
|
|
482
|
+
}
|
|
483
|
+
return originalReadFileSync(filePath, encoding);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
await generateCommand('/dist', options);
|
|
487
|
+
|
|
488
|
+
expect(mockFs.writeFileSync).toHaveBeenCalledWith(
|
|
489
|
+
path.join(path.resolve('/dist'), 'README.md'),
|
|
490
|
+
'# Flutter README\n\nHello',
|
|
491
|
+
'utf-8'
|
|
492
|
+
);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('should copy Flutter README.md into generated Vue package root', async () => {
|
|
496
|
+
const options = {
|
|
497
|
+
flutterPackageSrc: '/flutter/src',
|
|
498
|
+
framework: 'vue',
|
|
499
|
+
packageName: 'test-package'
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// Mock TypeScript validation
|
|
503
|
+
mockTypeScriptValidation('/flutter/src');
|
|
504
|
+
|
|
505
|
+
const originalExistsSync = mockFs.existsSync as jest.Mock;
|
|
506
|
+
mockFs.existsSync = jest.fn().mockImplementation((filePath: any) => {
|
|
507
|
+
const pathStr = filePath.toString();
|
|
508
|
+
if (pathStr === '/flutter/src/README.md') return true;
|
|
509
|
+
if (pathStr === path.join(path.resolve('/dist'), 'README.md')) return false;
|
|
510
|
+
return originalExistsSync(filePath);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
const originalReadFileSync = mockFs.readFileSync as jest.Mock;
|
|
514
|
+
mockFs.readFileSync = jest.fn().mockImplementation((filePath: any, encoding?: any) => {
|
|
515
|
+
const pathStr = filePath.toString();
|
|
516
|
+
if (pathStr === '/flutter/src/README.md') {
|
|
517
|
+
return '# Flutter README\n\nHello';
|
|
518
|
+
}
|
|
519
|
+
return originalReadFileSync(filePath, encoding);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
await generateCommand('/dist', options);
|
|
523
|
+
|
|
524
|
+
expect(mockFs.writeFileSync).toHaveBeenCalledWith(
|
|
525
|
+
path.join(path.resolve('/dist'), 'README.md'),
|
|
526
|
+
'# Flutter README\n\nHello',
|
|
527
|
+
'utf-8'
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
|
|
466
531
|
it('should generate an aggregated README in dist from markdown docs', async () => {
|
|
467
532
|
const options = {
|
|
468
533
|
flutterPackageSrc: '/flutter/src',
|
package/test/generator.test.ts
CHANGED
|
@@ -233,19 +233,13 @@ describe('Generator', () => {
|
|
|
233
233
|
command: 'test command'
|
|
234
234
|
});
|
|
235
235
|
|
|
236
|
-
//
|
|
236
|
+
// Dart codegen does not write a root index.d.ts; it copies .d.ts files alongside generated Dart bindings.
|
|
237
237
|
const writeFileCalls = mockFs.writeFileSync.mock.calls;
|
|
238
238
|
const indexDtsCall = writeFileCalls.find(call =>
|
|
239
239
|
call[0].toString().endsWith('index.d.ts')
|
|
240
240
|
);
|
|
241
241
|
|
|
242
|
-
expect(indexDtsCall).
|
|
243
|
-
expect(indexDtsCall![1]).toContain('/// <reference path="./global.d.ts" />');
|
|
244
|
-
expect(indexDtsCall![1]).toContain('/// <reference path="./components/button.d.ts" />');
|
|
245
|
-
expect(indexDtsCall![1]).toContain('/// <reference path="./widgets/card.d.ts" />');
|
|
246
|
-
expect(indexDtsCall![1]).toContain("export * from './components/button';");
|
|
247
|
-
expect(indexDtsCall![1]).toContain("export * from './widgets/card';");
|
|
248
|
-
expect(indexDtsCall![1]).toContain('TypeScript Definitions');
|
|
242
|
+
expect(indexDtsCall).toBeUndefined();
|
|
249
243
|
});
|
|
250
244
|
|
|
251
245
|
it('should copy original .d.ts files to output directory', async () => {
|
|
@@ -301,6 +295,19 @@ describe('Generator', () => {
|
|
|
301
295
|
expect(mockFs.writeFileSync).toHaveBeenCalled();
|
|
302
296
|
});
|
|
303
297
|
|
|
298
|
+
it('should always generate src/types.ts for React output', async () => {
|
|
299
|
+
await reactGen({
|
|
300
|
+
source: '/test/source',
|
|
301
|
+
target: '/test/target',
|
|
302
|
+
command: 'test command'
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
const writeCalls = mockFs.writeFileSync.mock.calls;
|
|
306
|
+
const typesCall = writeCalls.find(call => /[\\/]src[\\/]types\.ts$/.test(call[0].toString()));
|
|
307
|
+
expect(typesCall).toBeDefined();
|
|
308
|
+
expect(typesCall![1]).toContain('export {};');
|
|
309
|
+
});
|
|
310
|
+
|
|
304
311
|
it('should use the exact target directory specified', async () => {
|
|
305
312
|
await reactGen({
|
|
306
313
|
source: '/test/source',
|
|
@@ -478,8 +485,8 @@ describe('Generator', () => {
|
|
|
478
485
|
// First file fails (no writes), second file succeeds (1 dart + 1 .d.ts), plus index.d.ts = 3 total
|
|
479
486
|
// But since the error happens in dartGen, the .d.ts copy might not happen
|
|
480
487
|
const writeCalls = mockFs.writeFileSync.mock.calls;
|
|
481
|
-
// Should have at least written the successful
|
|
482
|
-
expect(writeCalls.length).toBeGreaterThanOrEqual(
|
|
488
|
+
// Should have at least written the successful Dart bindings file
|
|
489
|
+
expect(writeCalls.length).toBeGreaterThanOrEqual(1);
|
|
483
490
|
});
|
|
484
491
|
});
|
|
485
492
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import { getPackageTypesFileFromDir, isPackageTypesReady } from '../src/peerDeps';
|
|
5
|
+
|
|
6
|
+
function makeTempDir(prefix: string): string {
|
|
7
|
+
return fs.mkdtempSync(path.join(process.cwd(), 'test', prefix));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('peerDeps', () => {
|
|
11
|
+
it('treats package as not ready when declared types file is missing', () => {
|
|
12
|
+
const dir = makeTempDir('peerDeps-');
|
|
13
|
+
const distDir = path.join(dir, 'dist');
|
|
14
|
+
try {
|
|
15
|
+
fs.mkdirSync(distDir, { recursive: true });
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
path.join(dir, 'package.json'),
|
|
18
|
+
JSON.stringify({ name: '@openwebf/react-core-ui', types: 'dist/index.d.ts' }, null, 2)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(getPackageTypesFileFromDir(dir)).toBe(path.join(dir, 'dist', 'index.d.ts'));
|
|
22
|
+
expect(isPackageTypesReady(dir)).toBe(false);
|
|
23
|
+
|
|
24
|
+
fs.writeFileSync(path.join(distDir, 'index.d.ts'), 'export {};');
|
|
25
|
+
expect(isPackageTypesReady(dir)).toBe(true);
|
|
26
|
+
} finally {
|
|
27
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { generateReactComponent } from '../src/react';
|
|
2
2
|
import { IDLBlob } from '../src/IDLBlob';
|
|
3
|
-
import { ConstObject, EnumObject, EnumMemberObject } from '../src/declaration';
|
|
3
|
+
import { ClassObject, ClassObjectKind, ConstObject, EnumObject, EnumMemberObject } from '../src/declaration';
|
|
4
4
|
|
|
5
5
|
describe('React generator - declare const support', () => {
|
|
6
6
|
it('emits export declare const for constants from typings', () => {
|
|
7
7
|
const blob = new IDLBlob('/test/source', '/test/target', 'ConstOnly', 'test', '');
|
|
8
|
+
const properties = new ClassObject();
|
|
9
|
+
properties.name = 'TestComponentProperties';
|
|
10
|
+
properties.kind = ClassObjectKind.interface;
|
|
8
11
|
const constObj = new ConstObject();
|
|
9
12
|
constObj.name = 'WEBF_CUPERTINO_SYMBOL';
|
|
10
13
|
constObj.type = 'unique symbol';
|
|
11
14
|
|
|
12
|
-
blob.objects = [constObj as any];
|
|
15
|
+
blob.objects = [properties, constObj as any];
|
|
13
16
|
|
|
14
17
|
const output = generateReactComponent(blob);
|
|
15
18
|
expect(output).toContain('export declare const WEBF_CUPERTINO_SYMBOL: unique symbol;');
|
|
@@ -17,12 +20,15 @@ describe('React generator - declare const support', () => {
|
|
|
17
20
|
|
|
18
21
|
it('emits export declare enum for enums from typings', () => {
|
|
19
22
|
const blob = new IDLBlob('/test/source', '/test/target', 'EnumOnly', 'test', '');
|
|
23
|
+
const properties = new ClassObject();
|
|
24
|
+
properties.name = 'TestComponentProperties';
|
|
25
|
+
properties.kind = ClassObjectKind.interface;
|
|
20
26
|
const eo = new EnumObject();
|
|
21
27
|
eo.name = 'CupertinoColors';
|
|
22
28
|
const m1 = new EnumMemberObject(); m1.name = "'red'"; m1.initializer = '0x0f';
|
|
23
29
|
const m2 = new EnumMemberObject(); m2.name = "'bbb'"; m2.initializer = '0x00';
|
|
24
30
|
eo.members = [m1, m2];
|
|
25
|
-
blob.objects = [eo as any];
|
|
31
|
+
blob.objects = [properties, eo as any];
|
|
26
32
|
|
|
27
33
|
const output = generateReactComponent(blob);
|
|
28
34
|
expect(output).toContain("export enum CupertinoColors { 'red' = 0x0f, 'bbb' = 0x00 }");
|
|
@@ -49,13 +49,13 @@ describe('Standard HTML Props Generation', () => {
|
|
|
49
49
|
const propsContent = result.substring(propsStart, propsEnd);
|
|
50
50
|
|
|
51
51
|
// Verify order: custom props, event handlers, then standard HTML props
|
|
52
|
-
const labelIndex = propsContent.
|
|
53
|
-
const variantIndex = propsContent.
|
|
54
|
-
const onClickIndex = propsContent.
|
|
55
|
-
const idIndex = propsContent.
|
|
56
|
-
const styleIndex = propsContent.
|
|
57
|
-
const childrenIndex = propsContent.
|
|
58
|
-
const classNameIndex = propsContent.
|
|
52
|
+
const labelIndex = propsContent.search(/\n\s*label\??:\s*/);
|
|
53
|
+
const variantIndex = propsContent.search(/\n\s*variant\??:\s*/);
|
|
54
|
+
const onClickIndex = propsContent.search(/\n\s*onClick\??:\s*/);
|
|
55
|
+
const idIndex = propsContent.search(/\n\s*id\??:\s*/);
|
|
56
|
+
const styleIndex = propsContent.search(/\n\s*style\??:\s*/);
|
|
57
|
+
const childrenIndex = propsContent.search(/\n\s*children\??:\s*/);
|
|
58
|
+
const classNameIndex = propsContent.search(/\n\s*className\??:\s*/);
|
|
59
59
|
|
|
60
60
|
// All props should exist
|
|
61
61
|
expect(labelIndex).toBeGreaterThan(-1);
|
|
@@ -131,8 +131,8 @@ describe('Standard HTML Props Generation', () => {
|
|
|
131
131
|
|
|
132
132
|
// Standard HTML props
|
|
133
133
|
expect(propsContent).toContain("'id'?: string;");
|
|
134
|
-
expect(propsContent).toContain("'class'?:
|
|
135
|
-
expect(propsContent).toContain("'style'?:
|
|
134
|
+
expect(propsContent).toContain("'class'?: ClassValue;");
|
|
135
|
+
expect(propsContent).toContain("'style'?: StyleValue;");
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it('should handle Vue style prop with both string and object types', () => {
|
|
@@ -145,8 +145,8 @@ describe('Standard HTML Props Generation', () => {
|
|
|
145
145
|
|
|
146
146
|
const result = generateVueTypings([blob]);
|
|
147
147
|
|
|
148
|
-
// Vue style prop should accept
|
|
149
|
-
expect(result).toMatch(/'style'\?:
|
|
148
|
+
// Vue style prop should accept Vue's supported style value forms
|
|
149
|
+
expect(result).toMatch(/'style'\?: StyleValue;/);
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
152
|
|
|
@@ -176,15 +176,15 @@ describe('Standard HTML Props Generation', () => {
|
|
|
176
176
|
|
|
177
177
|
// Both should have style prop (with appropriate types)
|
|
178
178
|
expect(reactResult).toContain('style?: React.CSSProperties;');
|
|
179
|
-
expect(vueResult).toContain("'style'?:
|
|
179
|
+
expect(vueResult).toContain("'style'?: StyleValue;");
|
|
180
180
|
|
|
181
181
|
// React has className, Vue has class
|
|
182
182
|
expect(reactResult).toContain('className?: string;');
|
|
183
|
-
expect(vueResult).toContain("'class'?:
|
|
183
|
+
expect(vueResult).toContain("'class'?: ClassValue;");
|
|
184
184
|
|
|
185
185
|
// React has children, Vue uses slots (not in props)
|
|
186
186
|
expect(reactResult).toContain('children?: React.ReactNode;');
|
|
187
187
|
expect(vueResult).not.toContain('children');
|
|
188
188
|
});
|
|
189
189
|
});
|
|
190
|
-
});
|
|
190
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
describe('Templates', () => {
|
|
5
|
+
it('react tsconfig template pins React type resolution to root @types', () => {
|
|
6
|
+
const templatePath = path.resolve(__dirname, '../templates/react.tsconfig.json.tpl');
|
|
7
|
+
const template = fs.readFileSync(templatePath, 'utf8');
|
|
8
|
+
|
|
9
|
+
expect(template).toContain('"baseUrl": "."');
|
|
10
|
+
expect(template).toContain('"paths"');
|
|
11
|
+
expect(template).toContain('"react": ["./node_modules/@types/react/index.d.ts"]');
|
|
12
|
+
expect(template).toContain('"react-dom": ["./node_modules/@types/react-dom/index.d.ts"]');
|
|
13
|
+
expect(template).toContain('"react/jsx-runtime": ["./node_modules/@types/react/jsx-runtime.d.ts"]');
|
|
14
|
+
expect(template).toContain('"react/jsx-dev-runtime": ["./node_modules/@types/react/jsx-dev-runtime.d.ts"]');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
package/test/vue.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateVueTypings } from '../src/vue';
|
|
2
2
|
import { IDLBlob } from '../src/IDLBlob';
|
|
3
|
-
import { ClassObject, ClassObjectKind, PropsDeclaration, ConstObject } from '../src/declaration';
|
|
3
|
+
import { ClassObject, ClassObjectKind, PropsDeclaration, ConstObject, TypeAliasObject } from '../src/declaration';
|
|
4
4
|
|
|
5
5
|
describe('Vue Generator', () => {
|
|
6
6
|
describe('generateVueTypings', () => {
|
|
@@ -16,13 +16,16 @@ describe('Vue Generator', () => {
|
|
|
16
16
|
|
|
17
17
|
// Should include standard HTML props in Props type
|
|
18
18
|
expect(result).toContain("'id'?: string;");
|
|
19
|
-
expect(result).toContain("'class'?:
|
|
20
|
-
expect(result).toContain("'style'?:
|
|
19
|
+
expect(result).toContain("'class'?: ClassValue;");
|
|
20
|
+
expect(result).toContain("'style'?: StyleValue;");
|
|
21
21
|
|
|
22
22
|
// Should generate proper type exports
|
|
23
23
|
expect(result).toContain('export type TestComponentProps = {');
|
|
24
24
|
expect(result).toContain('export interface TestComponentElement {');
|
|
25
25
|
expect(result).toContain('export type TestComponentEvents = {');
|
|
26
|
+
|
|
27
|
+
// Should not rely on a non-existent internal __webfTypes import
|
|
28
|
+
expect(result).not.toContain('__webfTypes');
|
|
26
29
|
});
|
|
27
30
|
|
|
28
31
|
it('should include standard HTML props along with custom properties', () => {
|
|
@@ -58,8 +61,8 @@ describe('Vue Generator', () => {
|
|
|
58
61
|
|
|
59
62
|
// And still include standard HTML props
|
|
60
63
|
expect(result).toContain("'id'?: string;");
|
|
61
|
-
expect(result).toContain("'class'?:
|
|
62
|
-
expect(result).toContain("'style'?:
|
|
64
|
+
expect(result).toContain("'class'?: ClassValue;");
|
|
65
|
+
expect(result).toContain("'style'?: StyleValue;");
|
|
63
66
|
});
|
|
64
67
|
|
|
65
68
|
it('should generate proper Vue component declarations', () => {
|
|
@@ -73,11 +76,20 @@ describe('Vue Generator', () => {
|
|
|
73
76
|
const result = generateVueTypings([blob]);
|
|
74
77
|
|
|
75
78
|
// Should generate proper component declarations
|
|
76
|
-
expect(result).toContain("declare module 'vue' {");
|
|
79
|
+
expect(result).toContain("declare module '@vue/runtime-core' {");
|
|
80
|
+
expect(result).toContain("interface GlobalDirectives {");
|
|
81
|
+
expect(result).toContain('vFlutterAttached: typeof flutterAttached;');
|
|
77
82
|
expect(result).toContain("interface GlobalComponents {");
|
|
78
|
-
expect(result).toContain("'
|
|
83
|
+
expect(result).toContain("'webf-list-view': DefineCustomElement<");
|
|
84
|
+
expect(result).not.toContain("'web-f-list-view': DefineCustomElement<");
|
|
85
|
+
expect(result).toContain("WebFListViewElement,");
|
|
79
86
|
expect(result).toContain("WebFListViewProps,");
|
|
80
87
|
expect(result).toContain("WebFListViewEvents");
|
|
88
|
+
|
|
89
|
+
// Compatibility module for older tooling
|
|
90
|
+
expect(result).toContain("declare module 'vue' {");
|
|
91
|
+
expect(result).toContain("interface GlobalDirectives extends import('@vue/runtime-core').GlobalDirectives {}");
|
|
92
|
+
expect(result).toContain("interface GlobalComponents extends import('@vue/runtime-core').GlobalComponents {}");
|
|
81
93
|
});
|
|
82
94
|
|
|
83
95
|
it('should handle multiple components', () => {
|
|
@@ -145,13 +157,13 @@ describe('Vue Generator', () => {
|
|
|
145
157
|
|
|
146
158
|
// Should include event types
|
|
147
159
|
expect(result).toContain('export type TestComponentEvents = {');
|
|
148
|
-
expect(result).toContain('close
|
|
149
|
-
expect(result).toContain('refresh
|
|
160
|
+
expect(result).toContain('close: Event;');
|
|
161
|
+
expect(result).toContain('refresh: CustomEvent;');
|
|
150
162
|
|
|
151
163
|
// Props should still have standard HTML props
|
|
152
164
|
expect(result).toContain("'id'?: string;");
|
|
153
|
-
expect(result).toContain("'class'?:
|
|
154
|
-
expect(result).toContain("'style'?:
|
|
165
|
+
expect(result).toContain("'class'?: ClassValue;");
|
|
166
|
+
expect(result).toContain("'style'?: StyleValue;");
|
|
155
167
|
});
|
|
156
168
|
|
|
157
169
|
it('should include declare const variables as exported declarations', () => {
|
|
@@ -168,6 +180,19 @@ describe('Vue Generator', () => {
|
|
|
168
180
|
expect(result).toContain('export declare const WEBF_UNIQUE: unique symbol;');
|
|
169
181
|
});
|
|
170
182
|
|
|
183
|
+
it('should include type aliases as exported declarations', () => {
|
|
184
|
+
const blob = new IDLBlob('/test/source', '/test/target', 'TypeAliasOnly', 'test', '');
|
|
185
|
+
|
|
186
|
+
const typeAlias = new TypeAliasObject();
|
|
187
|
+
typeAlias.name = 'MyAlias';
|
|
188
|
+
typeAlias.type = 'string | number';
|
|
189
|
+
|
|
190
|
+
blob.objects = [typeAlias as any];
|
|
191
|
+
|
|
192
|
+
const result = generateVueTypings([blob]);
|
|
193
|
+
expect(result).toContain('export type MyAlias = string | number;');
|
|
194
|
+
});
|
|
195
|
+
|
|
171
196
|
it('should include declare enum as exported declaration', () => {
|
|
172
197
|
const blob = new IDLBlob('/test/source', '/test/target', 'EnumOnly', 'test', '');
|
|
173
198
|
// Build a minimal faux EnumObject via analyzer by simulating ast is heavy; create a shape
|