Skip to content

Commit 3a29249

Browse files
authored
Merge pull request #1087 from joshunrau/runtime-core-ts
rewrite runtime-core in TypeScript with intermediate build step
2 parents 295aff6 + 9e623a7 commit 3a29249

File tree

27 files changed

+109
-158
lines changed

27 files changed

+109
-158
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ apps/outreach/src/content/docs/en/runtime-core-docs/
6262
# docker dbs
6363
mongo/
6464
sqlite/
65+
66+
# runtime core intermediate build
67+
packages/runtime-core/lib/

apps/outreach/astro.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default defineConfig({
6262
},
6363
plugins: [
6464
starlightTypeDocPlugin({
65-
entryPoints: [path.resolve(runtimeCoreRoot, 'src/index.d.ts')],
65+
entryPoints: [path.resolve(runtimeCoreRoot, 'lib/index.d.ts')],
6666
locale: 'en',
6767
output: 'runtime-core-docs',
6868
sidebar: {

packages/instrument-bundler/src/__tests__/repositories/interactive/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { defineInstrument } from '/runtime/v1/@opendatacapture/runtime-core';
22
import { createRoot } from '/runtime/v1/[email protected]/client';
33
import { z } from '/runtime/v1/[email protected]';
44

5+
const { sum } = await import('/runtime/v1/[email protected]');
6+
57
import './styles.css';
68
import '/runtime/v1/[email protected]/normalize.css';
79

@@ -18,7 +20,7 @@ export default defineInstrument({
1820
root.render(
1921
<div>
2022
<h1>Interactive Task</h1>
21-
<button onClick={() => done({})}>Done</button>
23+
<button onClick={() => done({ value: sum([1, 2, 3]) })}>Done</button>
2224
</div>
2325
);
2426
}

packages/instrument-bundler/src/__tests__/transform.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import { transformImports } from '../transform.js';
44

55
describe('transformImports', () => {
66
it('should transform a default import', () => {
7-
expect(transformImports("import React from 'react';")).toBe("const { default: React } = await import('react');");
7+
expect(transformImports("import React from 'react';")).toBe("const { default: React } = await __import('react');");
88
});
99
it('should transform named imports', () => {
1010
expect(transformImports("import { useEffect, useState } from 'react';")).toBe(
11-
"const { useEffect, useState } = await import('react');"
11+
"const { useEffect, useState } = await __import('react');"
1212
);
1313
});
1414
it('should transform named and default imports from the same source', () => {
1515
expect(transformImports("import React, { useState } from 'react';")).toBe(
16-
"const { useState, default: React } = await import('react');"
16+
"const { useState, default: React } = await __import('react');"
1717
);
1818
});
1919
it('should transform a namespace import', () => {
20-
expect(transformImports("import * as React from 'react';")).toBe("const React = await import('react');");
20+
expect(transformImports("import * as React from 'react';")).toBe("const React = await __import('react');");
2121
});
2222
it('should transform named and default imports from the same source', () => {
2323
expect(transformImports("import _ from 'lodash'; import { useEffect, useState } from 'react';")).toBe(
24-
"const { default: _ } = await import('lodash'); const { useEffect, useState } = await import('react');"
24+
"const { default: _ } = await __import('lodash'); const { useEffect, useState } = await __import('react');"
2525
);
2626
});
2727
});

packages/runtime-core/config/api-extractor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3-
"mainEntryPointFilePath": "<projectFolder>/src/index.d.ts",
3+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
44
"bundledPackages": ["@douglasneuroinformatics/libui-form-types"],
55
"apiReport": {
66
"enabled": false

packages/runtime-core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"./package.json": "./package.json"
1313
},
1414
"scripts": {
15-
"build": "rm -rf dist && pnpm build:js && pnpm build:ts",
16-
"build:js": "pnpm exec esbuild --bundle --format=esm --outfile=dist/index.js --platform=browser src/index.js",
17-
"build:ts": "api-extractor run -c config/api-extractor.json",
15+
"build": "rm -rf dist lib && pnpm build:lib && pnpm build:dist",
16+
"build:dist": "pnpm exec esbuild --bundle --format=esm --outfile=dist/index.js --platform=browser lib/index.js && api-extractor run -c config/api-extractor.json",
17+
"build:lib": "tsc -b tsconfig.build.json",
1818
"format": "prettier --write src",
1919
"lint": "tsc --noEmit && eslint --fix src"
2020
},

packages/runtime-core/src/__tests__/define.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { z } from 'zod';
33

44
import { defineInstrument } from '../define.js';
55

6-
import type { DiscriminatedInstrument } from '../define.d.ts';
7-
import type { FormInstrument } from '../types/instrument.form.d.ts';
8-
import type { InteractiveInstrument } from '../types/instrument.interactive.d.ts';
6+
import type { DiscriminatedInstrument } from '../define.js';
7+
import type { FormInstrument } from '../types/instrument.form.js';
8+
import type { InteractiveInstrument } from '../types/instrument.interactive.js';
99

1010
expectTypeOf<DiscriminatedInstrument<'FORM', 'en', { foo: string }>>().toMatchTypeOf<
1111
FormInstrument<{ foo: string }, 'en'>

packages/runtime-core/src/define.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { z } from 'zod';
22

3-
import type { InstrumentKind, InstrumentLanguage } from './types/instrument.base.d.ts';
4-
import type { FormInstrument } from './types/instrument.form.d.ts';
5-
import type { InteractiveInstrument } from './types/instrument.interactive.d.ts';
3+
import type { InstrumentKind, InstrumentLanguage } from './types/instrument.base.js';
4+
import type { FormInstrument } from './types/instrument.form.js';
5+
import type { InteractiveInstrument } from './types/instrument.interactive.js';
66

77
/** @public */
88
// prettier-ignore
9-
type DiscriminatedInstrument<
9+
export type DiscriminatedInstrument<
1010
TKind extends InstrumentKind,
1111
TLanguage extends InstrumentLanguage,
1212
TData
@@ -21,7 +21,7 @@ type DiscriminatedInstrument<
2121
: never;
2222

2323
/** @public */
24-
type InstrumentDef<
24+
export type InstrumentDef<
2525
TKind extends InstrumentKind,
2626
TLanguage extends InstrumentLanguage,
2727
TSchema extends z.ZodTypeAny
@@ -35,8 +35,12 @@ type InstrumentDef<
3535
};
3636

3737
/** @public */
38-
export declare function defineInstrument<
38+
export function defineInstrument<
3939
TKind extends InstrumentKind,
4040
TLanguage extends InstrumentLanguage,
4141
TSchema extends z.ZodTypeAny
42-
>(def: InstrumentDef<TKind, TLanguage, TSchema>): DiscriminatedInstrument<TKind, TLanguage, z.TypeOf<TSchema>>;
42+
>(def: InstrumentDef<TKind, TLanguage, TSchema>) {
43+
return Object.assign(def, {
44+
__runtimeVersion: 1
45+
}) as unknown as DiscriminatedInstrument<TKind, TLanguage, z.TypeOf<TSchema>>;
46+
}

packages/runtime-core/src/i18n.d.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)