This commit is contained in:
Jake Archibald
2020-09-25 13:04:39 +01:00
parent 4d8efcea66
commit f96ae9bdee
12 changed files with 1458 additions and 8 deletions

View File

@@ -62,22 +62,61 @@ export default function () {
if (previousWorkerContent === workerFile) return;
previousWorkerContent = workerFile;
const tsConfig = {
const tsConfigReferences = tsImports.map((tsImport) => ({
path: path.dirname(tsImport),
}));
const workerTsConfig = {
extends: '../../../generic-tsconfig.json',
compilerOptions: {
lib: ['webworker', 'esnext'],
},
references: tsImports.map((tsImport) => ({
path: path.dirname(tsImport),
references: tsConfigReferences,
};
const bridgeTsConfig = {
extends: '../../../../generic-tsconfig.json',
compilerOptions: {
lib: ['esnext', 'dom', 'dom.iterable'],
types: [],
},
include: ['../../../client/lazy-app/util.ts', '**/*.ts'],
references: tsConfigReferences.map((ref) => ({
path: path.join('..', ref.path),
})),
};
const bridgeMeta = [
`// This file is autogenerated by lib/image-worker-plugin.js`,
tsNames.map(([path, name]) => `import type ${name} from '../${path}';`),
`export const methodNames = ${JSON.stringify(
tsNames.map(([_, name]) => name),
null,
' ',
)} as const;`,
`export interface BridgeMethods {`,
tsNames.map(([_, name]) => [
` ${name}(`,
` signal: AbortSignal,`,
` ...args: Parameters<typeof ${name}>`,
` ): Promise<ReturnType<typeof ${name}>>;`,
]),
`}`,
]
.flat(Infinity)
.join('\n');
await Promise.all([
fsp.writeFile(
path.join(base, 'tsconfig.json'),
JSON.stringify(tsConfig, null, ' '),
JSON.stringify(workerTsConfig, null, ' '),
),
fsp.writeFile(
path.join(base, 'bridge', 'tsconfig.json'),
JSON.stringify(bridgeTsConfig, null, ' '),
),
fsp.writeFile(path.join(base, 'index.ts'), workerFile),
fsp.writeFile(path.join(base, 'bridge', 'meta.ts'), bridgeMeta),
]);
},
};