forked from external-repos/squoosh
wip
This commit is contained in:
@@ -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),
|
||||
]);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user