diff --git a/lib/feature-plugin.js b/lib/feature-plugin.js index 597e65c1..eb826dd7 100644 --- a/lib/feature-plugin.js +++ b/lib/feature-plugin.js @@ -171,6 +171,7 @@ export default function () { 'lazy-app', 'feature-meta', ); + const clientBasePath = path.join(process.cwd(), 'src', 'client'); const joinedMetas = metas.flat().join(); @@ -193,6 +194,13 @@ export default function () { const preprocessorMetaTsNames = preprocessorMetas.map((tsImport) => getTsName(tsImport), ); + const tsConfigEncoderPaths = encoderMetas.flatMap((tsImport) => [ + path.relative(clientBasePath, tsImport.replace(/\/meta$/, '')), + path.relative( + clientBasePath, + tsImport.replace(/shared\/meta$/, 'client'), + ), + ]); const featureMeta = [ autoGenComment, @@ -200,6 +208,13 @@ export default function () { encoderMetaTsNames.map( ([path, name]) => `import * as ${name}EncoderMeta from '${path}';`, ), + encoderMetaTsNames.map( + ([path, name]) => + `import * as ${name}EncoderEntry from '${path.replace( + /shared\/meta$/, + 'client', + )}';`, + ), `export type EncoderState =`, encoderMetaTsNames.map( ([_, name]) => @@ -212,10 +227,12 @@ export default function () { ), `;`, `export const encoderMap = {`, - encoderMetaTsNames.map(([_, name]) => ` ${name}: ${name}EncoderMeta,`), + encoderMetaTsNames.map( + ([_, name]) => + ` ${name}: { meta: ${name}EncoderMeta, ...${name}EncoderEntry },`, + ), `};`, `export type EncoderType = keyof typeof encoderMap`, - `export const encoders = [...Object.values(encoderMap)];`, // Processor stuff processorMetaTsNames.map( ([path, name]) => `import * as ${name}ProcessorMeta from '${path}';`, @@ -250,10 +267,29 @@ export default function () { .flat(Infinity) .join('\n'); - await fsp.writeFile( - path.join(featureMetaBasePath, 'index.ts'), - featureMeta, - ); + const lazyTsConfig = { + extends: '../../generic-tsconfig.json', + compilerOptions: { + lib: ['esnext', 'dom', 'dom.iterable'], + types: [], + }, + references: [ + { path: '../features-worker' }, + { path: '../shared' }, + { path: '../features/processors/resize/client' }, + ...tsConfigEncoderPaths.map((projectPath) => ({ + path: projectPath, + })), + ], + }; + + await Promise.all([ + fsp.writeFile( + path.join(process.cwd(), 'src', 'client', 'tsconfig.json'), + autoGenComment + JSON.stringify(lazyTsConfig, null, ' '), + ), + fsp.writeFile(path.join(featureMetaBasePath, 'index.ts'), featureMeta), + ]); } return { diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json deleted file mode 100644 index f671b5e3..00000000 --- a/src/client/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../generic-tsconfig.json", - "compilerOptions": { - "lib": ["esnext", "dom", "dom.iterable"], - "types": [] - }, - "references": [ - { "path": "../features-worker" }, - { "path": "../shared" }, - { "path": "../features/encoders/identity/shared" }, - { "path": "../features/encoders/browserGIF/shared" }, - { "path": "../features/encoders/browserJPEG/shared" }, - { "path": "../features/encoders/browserPNG/shared" }, - { "path": "../features/processors/resize/client" } - ] -} diff --git a/src/features/README.md b/src/features/README.md index 35563b67..df57d579 100644 --- a/src/features/README.md +++ b/src/features/README.md @@ -43,4 +43,4 @@ Encoders must have the following: And returns (a promise for) an `ArrayBuffer`. -Optionally it may include a method `featureTest`, which returns a boolean for support for this decoder. +Optionally it may include a method `featureTest`, which returns a boolean indicating support for this decoder. diff --git a/src/features/encoders/identity/shared/meta.ts b/src/features/encoders/identity/shared/meta.ts deleted file mode 100644 index d551c0e0..00000000 --- a/src/features/encoders/identity/shared/meta.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright 2020 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export interface EncodeOptions {} -export const label = 'Original image'; -export const defaultOptions: EncodeOptions = {}; diff --git a/src/features/encoders/identity/shared/missing-types.d.ts b/src/features/encoders/identity/shared/missing-types.d.ts deleted file mode 100644 index c729fd74..00000000 --- a/src/features/encoders/identity/shared/missing-types.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright 2020 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/// diff --git a/src/features/encoders/identity/shared/tsconfig.json b/src/features/encoders/identity/shared/tsconfig.json deleted file mode 100644 index bea39d16..00000000 --- a/src/features/encoders/identity/shared/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../../../../generic-tsconfig.json", - "compilerOptions": { - "lib": ["webworker", "esnext"] - }, - "references": [{ "path": "../../../" }] -}